Example usage for org.eclipse.jface.preference IPreferenceStore setValue

List of usage examples for org.eclipse.jface.preference IPreferenceStore setValue

Introduction

In this page you can find the example usage for org.eclipse.jface.preference IPreferenceStore setValue.

Prototype

void setValue(String name, boolean value);

Source Link

Document

Sets the current value of the boolean-valued preference with the given name.

Usage

From source file:com.aptana.portal.ui.dispatch.actionControllers.PreferenceActionController.java

License:Open Source License

/**
 * Set a preference value.<br>/*  w w w . ja va 2 s. c o m*/
 * We expect an array that contains a Map which hold the preferences key and it's value.
 * 
 * @param arguments
 *            An array that holds a Map
 * @return A JSON status for the action.
 */
@SuppressWarnings("unchecked")
@ControllerAction
public Object setPreferenceValue(Object arguments) {
    Object check = checkArguments(arguments);
    if (check != null) {
        return check;
    }
    IPreferenceStore preferenceStore = PortalUIPlugin.getDefault().getPreferenceStore();
    try {
        Map<String, String> map = (Map<String, String>) ((Object[]) arguments)[0];
        preferenceStore.setValue(map.get(KEY), Boolean.parseBoolean(map.get(VALUE)));
    } catch (Throwable t) {
        IdeLog.logError(PortalUIPlugin.getDefault(), t);
        return IBrowserNotificationConstants.JSON_ERROR;
    }
    return IBrowserNotificationConstants.JSON_OK;
}

From source file:com.aptana.portal.ui.dispatch.configurationProcessors.InstallerConfigurationProcessor.java

License:Open Source License

/**
 * Cache the installed application location and version in the preferences.
 * /*from w w  w  .jav a 2s  .c o  m*/
 * @param installDir
 *            - The directory the application was installed to.
 * @param versionedFileLocation
 *            - Can be the URL that we grabbed the installer from, or any other string that contains a version
 *            information in a form of x.y.z.
 * @param appName
 *            - The application name (e.g. xampp)
 */
@SuppressWarnings("unchecked")
public void cacheVersion(String installDir, String versionedFileLocation, String appName)

{
    IPreferenceStore preferenceStore = PortalUIPlugin.getDefault().getPreferenceStore();
    String versions = preferenceStore.getString(IPortalPreferences.CACHED_VERSIONS_PROPERTY_NAME);
    Map<String, Map<String, String>> versionsMap = null;
    if (versions == null || versions.equals(StringUtil.EMPTY)) {
        versionsMap = new HashMap<String, Map<String, String>>();
    } else {
        versionsMap = (Map<String, Map<String, String>>) JSON.parse(versions);
    }
    Map<String, String> appVersionMap = new HashMap<String, String>();
    Version version = VersionUtil.parseVersion(versionedFileLocation);
    if (version != null) {
        appVersionMap.put(IPortalPreferences.CACHED_VERSION_PROPERTY, version.toString());
        appVersionMap.put(IPortalPreferences.CACHED_LOCATION_PROPERTY, installDir);
        versionsMap.put(appName.toLowerCase(), appVersionMap);
        preferenceStore.setValue(IPortalPreferences.CACHED_VERSIONS_PROPERTY_NAME, JSON.toString(versionsMap));
    } else {
        IdeLog.logError(PortalUIPlugin.getDefault(), MessageFormat.format(
                "Could not cache the location and version for {0}. Install dir: {1}, versionedFileLocation: {2}", //$NON-NLS-1$
                appName, installDir, versionedFileLocation), new Exception());
    }
}

From source file:com.aptana.radrails.rcp.IDEWorkbenchAdvisor.java

License:Open Source License

public boolean preShutdown() {
    try {/*from  ww  w . ja v a 2s  .c o m*/
        IPreferenceStore store = IdePlugin.getDefault().getPreferenceStore();
        IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
        ArrayList openFiles = getOpenEditors(windows);
        String fileList = StringUtils.join(PREFERENCE_FILE_DELIMETER,
                (String[]) openFiles.toArray(new String[0]));
        store.setValue(PREFERENCE_OPEN_FILES, fileList);
    } catch (Exception ex) {
        IdeLog.logError(IdePlugin.getDefault(), Messages.ApplicationWorkbenchAdvisor_ErrorPreShutdown, ex);
    }

    Display.getCurrent().removeListener(SWT.Settings, settingsChangeListener);
    return super.preShutdown();
}

From source file:com.aptana.rcp.dialogs.IDEStartupPreferencePage.java

License:Open Source License

/**
 * The user has pressed Ok. Store/apply this page's values appropriately.
 *///w ww .j  av a  2s .  co  m
public boolean performOk() {
    IPreferenceStore store = getIDEPreferenceStore();

    // store the refresh workspace on startup setting
    store.setValue(IDEInternalPreferences.REFRESH_WORKSPACE_ON_STARTUP, refreshButton.getSelection());

    // TODO: This should get the value from the configuration preference
    //       area, but dj said we shouldn't use it yet; some final details are
    //       being worked out. Hopefully it will be available soon, at which time
    //       the entire recentWorkspaces.xml file can be removed. But until then,
    //       this preference reads/writes the file each time.
    ChooseWorkspaceData.setShowDialogValue(launchPromptButton.getSelection());

    // store the exit prompt on last window close setting
    store.setValue(IDEInternalPreferences.EXIT_PROMPT_ON_CLOSE_LAST_WINDOW, exitPromptButton.getSelection());

    return super.performOk();
}

From source file:com.aptana.rcp.IDEWorkbenchAdvisor.java

License:Open Source License

/**
 * @see org.eclipse.ui.application.WorkbenchAdvisor#postStartup()
 *//*from w  ww. j  a  v a2  s  . co m*/
public void postStartup() {
    PlatformUtil.expandEnvironmentStrings(PlatformUtil.DESKTOP_DIRECTORY);
    try {
        refreshFromLocal();
        activateProxyService();
        ((Workbench) PlatformUI.getWorkbench()).registerService(ISelectionConversionService.class,
                new IDESelectionConversionService());

        initializeSettingsChangeListener();
        Display.getCurrent().addListener(SWT.Settings, settingsChangeListener);
    } finally {// Resume background jobs after we startup
        Job.getJobManager().resume();
    }

    initPreferences();

    // Force Automatic Updates
    IEclipsePreferences prefs = EclipseUtil.configurationScope().getNode(IdePlugin.PLUGIN_ID);
    boolean alreadyForcedAutomaticUpdate = prefs.getBoolean(FORCED_AUTOMATIC_UPDATE, false);
    if (!alreadyForcedAutomaticUpdate) {
        IPreferenceStore automaticUpdatePluginPreferenceStore = AutomaticUpdatePlugin.getDefault()
                .getPreferenceStore();
        automaticUpdatePluginPreferenceStore.setValue(PreferenceConstants.PREF_AUTO_UPDATE_ENABLED, true);
        automaticUpdatePluginPreferenceStore.setValue(PreferenceConstants.PREF_AUTO_UPDATE_SCHEDULE,
                PreferenceConstants.PREF_UPDATE_ON_STARTUP);
        // Store a pref key to remember that we've already forced the
        // Automatic Update
        prefs.putBoolean(FORCED_AUTOMATIC_UPDATE, true);
        try {
            prefs.flush();
        } catch (BackingStoreException e) {
            IdeLog.logError(IdePlugin.getDefault(), e);
        }
    }

    // Process command line args if any
    if (args != null && args.length > 0) {
        CommandlineArgumentsHandler.processCommandLineArgs(args);
    }
    LauncherServer.startServer();

    new InstallCommandLineExecutableJob().schedule();
}

From source file:com.aptana.rcp.IDEWorkbenchWindowAdvisor.java

License:Open Source License

/**
 * Asks the user whether the workbench should really be closed. Only asks if the preference is enabled.
 * //from   w  w w  .  j a  v a  2  s  .c  o  m
 * @param parentShell
 *            the parent shell to use for the confirmation dialog
 * @return <code>true</code> if OK to exit, <code>false</code> if the user canceled
 * @since 3.6
 */
static boolean promptOnExit(Shell parentShell) {
    IPreferenceStore store = IDEWorkbenchPlugin.getDefault().getPreferenceStore();
    boolean promptOnExit = store.getBoolean(IDEInternalPreferences.EXIT_PROMPT_ON_CLOSE_LAST_WINDOW);

    if (promptOnExit) {
        if (parentShell == null) {
            IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
            if (workbenchWindow != null) {
                parentShell = workbenchWindow.getShell();
            }
        }
        if (parentShell != null) {
            parentShell.setMinimized(false);
            parentShell.forceActive();
        }

        String message;

        String productName = null;
        IProduct product = Platform.getProduct();
        if (product != null) {
            productName = product.getName();
        }
        if (productName == null) {
            message = IDEWorkbenchMessages.PromptOnExitDialog_message0;
        } else {
            message = NLS.bind(IDEWorkbenchMessages.PromptOnExitDialog_message1, productName);
        }

        MessageDialogWithToggle dlg = MessageDialogWithToggle.openOkCancelConfirm(parentShell,
                IDEWorkbenchMessages.PromptOnExitDialog_shellTitle, message,
                IDEWorkbenchMessages.PromptOnExitDialog_choice, false, null, null);
        if (dlg.getReturnCode() != IDialogConstants.OK_ID) {
            return false;
        }
        if (dlg.getToggleState()) {
            store.setValue(IDEInternalPreferences.EXIT_PROMPT_ON_CLOSE_LAST_WINDOW, false);
        }
    }

    return true;
}

From source file:com.aptana.rcp.IDEWorkbenchWindowAdvisor.java

License:Open Source License

/**
 * @see org.eclipse.ui.application.WorkbenchAdvisor#preWindowOpen
 *///from w  w  w  . j  a v  a2  s  . c  o m
public void preWindowOpen() {
    IWorkbenchWindowConfigurer configurer = getWindowConfigurer();

    // register to handle file transfer drag/drop operations (supports
    // Windows shell)
    configurer.addEditorAreaTransfer(FileTransfer.getInstance());

    // show the shortcut bar and progress indicator, which are hidden by
    // default
    configurer.setShowPerspectiveBar(true);
    configurer.setShowFastViewBars(true);
    configurer.setShowProgressIndicator(true);

    configurer.setInitialSize(INITIAL_WINDOW_SIZE);

    // add the drag and drop support for the editor area
    configurer.addEditorAreaTransfer(EditorInputTransfer.getInstance());
    configurer.addEditorAreaTransfer(ResourceTransfer.getInstance());
    configurer.addEditorAreaTransfer(FileTransfer.getInstance());
    configurer.addEditorAreaTransfer(MarkerTransfer.getInstance());
    configurer.configureEditorAreaDropListener(new EditorAreaDropAdapter2(configurer.getWindow()));

    hookTitleUpdateListeners(configurer);

    final IPreferenceStore store = IDEWorkbenchPlugin.getDefault().getPreferenceStore();

    // Get the current setting
    boolean showToolbar = store.getBoolean(SHOW_COOLBAR);
    boolean showPerspectiveBar = store.getBoolean(SHOW_PERSPECTIVEBAR);

    final WorkbenchWindow workbenchWindow = (WorkbenchWindow) configurer.getWindow();
    if (!showToolbar) {
        // Hide coolbar
        workbenchWindow.setCoolBarVisible(false);
    }
    if (!showPerspectiveBar) {
        // Hide perspective bar
        workbenchWindow.setPerspectiveBarVisible(false);
    }

    // Add listener to monitor when the user shows/hides the toolbar
    workbenchWindow.addPropertyChangeListener(new IPropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent event) {
            Object newValue = event.getNewValue();
            if (event.getProperty().equals(WorkbenchWindow.PROP_COOLBAR_VISIBLE)) {
                if (newValue instanceof Boolean) {
                    // store coolbar show/hide state
                    // this also affects new windows opened in this session
                    store.setValue(SHOW_COOLBAR, ((Boolean) newValue).booleanValue());
                    if (!isToolbarProgrammaticSet) {
                        store.setValue(TOOLBAR_MANUALLY_ADJUSTED, true);
                    }
                }
            }
            if (event.getProperty().equals(WorkbenchWindow.PROP_PERSPECTIVEBAR_VISIBLE)) {
                if (newValue instanceof Boolean) {
                    // store perspective bar show/hide state
                    // this also affects new windows opened in this session
                    store.setValue(SHOW_PERSPECTIVEBAR, ((Boolean) newValue).booleanValue());
                    if (!isToolbarProgrammaticSet) {
                        store.setValue(TOOLBAR_MANUALLY_ADJUSTED, true);
                    }
                }
            }
        }
    });

    workbenchWindow.addPerspectiveListener(new IPerspectiveListener() {

        private boolean resetting;

        public void perspectiveActivated(IWorkbenchPage page, IPerspectiveDescriptor perspective) {
            // only control the toolbar state on perspective basis when user has not modified it manually
            if (!store.getBoolean(TOOLBAR_MANUALLY_ADJUSTED)) {
                boolean showToolbar = true;
                isToolbarProgrammaticSet = true;
                workbenchWindow.setCoolBarVisible(showToolbar);
                workbenchWindow.setPerspectiveBarVisible(showToolbar);
                isToolbarProgrammaticSet = false;
            }

            String id = perspective.getId();
            boolean isAptanaPerspective = id.equals(WEB_PERSPECTIVE_ID);
            if (isAptanaPerspective) {
                if (resetting) {
                    // user resets the perspective, so applies the default customization for Web/Rails perspective
                    store.setValue(MessageFormat.format("{0}:{1}", id, PERSPECTIVE_MANUALLY_ADJUSTED), false); //$NON-NLS-1$
                    customizePerspective(page);
                } else if (!store
                        .getBoolean(MessageFormat.format("{0}:{1}", id, PERSPECTIVE_MANUALLY_ADJUSTED))) //$NON-NLS-1$
                {
                    customizePerspective(page);
                }
            }
        }

        public void perspectiveChanged(IWorkbenchPage page, IPerspectiveDescriptor perspective,
                String changeId) {
            String id = perspective.getId();
            boolean isAptanaPerspective = id.equals(WEB_PERSPECTIVE_ID);
            if (isAptanaPerspective) {
                if (changeId.equals(IWorkbenchPage.CHANGE_RESET)) {
                    store.setValue(
                            MessageFormat.format("{0}:{1}", perspective.getId(), PERSPECTIVE_MANUALLY_ADJUSTED), //$NON-NLS-1$
                            true);
                    resetting = true;
                } else if (changeId.equals(IWorkbenchPage.CHANGE_RESET_COMPLETE)) {
                    resetting = false;
                }
            }
        }
    });
}

From source file:com.aptana.terminal.EarlyStartup.java

License:Open Source License

/**
 * createWorkbenchJob//ww w  .java 2 s  . co m
 * 
 * @return
 */
private WorkbenchJob createWorkbenchJob() {
    return new WorkbenchJob("Terminal Perspective Listener") //$NON-NLS-1$
    {
        private void addPerspectiveListeners() {
            IWorkbench workbench = PlatformUI.getWorkbench();

            // add our perspective listener to each workbench window
            for (IWorkbenchWindow workbenchWindow : workbench.getWorkbenchWindows()) {
                workbenchWindow.addPerspectiveListener(_perspectiveListener);
            }
        }

        private void addWindowListener() {
            IWorkbench workbench = PlatformUI.getWorkbench();

            workbench.addWindowListener(_windowListener);
        }

        public IStatus runInUIThread(IProgressMonitor monitor) {
            // listen for window and perspective changes
            addWindowListener();
            addPerspectiveListeners();

            IPreferenceStore prefs = TerminalPlugin.getDefault().getPreferenceStore();
            boolean firstRun = prefs.getBoolean(IPreferenceConstants.FIRST_RUN);

            if (firstRun) {
                // possibly open a terminal editor
                IWorkbench workbench = PlatformUI.getWorkbench();

                // potentially open a terminal editor in each workbench window
                for (IWorkbenchWindow workbenchWindow : workbench.getWorkbenchWindows()) {
                    IWorkbenchPage workbenchPage = workbenchWindow.getActivePage();
                    String perspectiveId = workbenchPage.getPerspective().getId();

                    // only open a terminal editor if the Rails perspective is the active perspective
                    if (WEB_PERSPECTIVE_ID.equals(perspectiveId)) {
                        EarlyStartup.this.openTerminalEditor(workbenchWindow);
                    }
                }

                // set firstRun to false
                prefs.setValue(IPreferenceConstants.FIRST_RUN, false);
            }

            return Status.OK_STATUS;
        }
    };
}

From source file:com.aptana.theme.preferences.ThemePreferencePage.java

License:Open Source License

private void setFont(String fontId, FontData[] data) {
    String fdString = PreferenceConverter.getStoredRepresentation(data);
    // Only set new values if they're different from existing!
    Font existing = JFaceResources.getFont(fontId);
    String existingString = ""; //$NON-NLS-1$
    if (!existing.isDisposed()) {
        existingString = PreferenceConverter.getStoredRepresentation(existing.getFontData());
    }//from   w ww.  ja v a 2  s.c  o  m
    if (!existingString.equals(fdString)) {
        // put in registry...
        JFaceResources.getFontRegistry().put(fontId, data);
        // Save to prefs...
        ITheme currentTheme = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme();
        String key = ThemeElementHelper.createPreferenceKey(currentTheme, fontId);
        IPreferenceStore store = WorkbenchPlugin.getDefault().getPreferenceStore();
        store.setValue(key, fdString);
    }
}

From source file:com.aptana.ui.dialogs.SaveAndLaunchPromptDialog.java

License:Open Source License

protected void okPressed() {
    IPreferenceStore store = DebugUIPlugin.getDefault().getPreferenceStore();
    String val = (savePref.getSelection() ? MessageDialogWithToggle.ALWAYS : MessageDialogWithToggle.PROMPT);
    store.setValue(IInternalDebugUIConstants.PREF_SAVE_DIRTY_EDITORS_BEFORE_LAUNCH, val);
    super.okPressed();
}