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

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

Introduction

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

Prototype

boolean getBoolean(String name);

Source Link

Document

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

Usage

From source file:com.aptana.ide.logging.LoggingPreferences.java

License:Open Source License

/**
 * Loads wrapping.// www  .  j a  v a2 s. c om
 */
private void loadWrapping() {
    IPreferenceStore store = getPreferenceStore();
    wrapping = store.getBoolean(WRAPPING_KEY);
}

From source file:com.aptana.ide.rcp.IDEApplication.java

License:Open Source License

/**
 * Return true if a valid workspace path has been set and false otherwise.
 * Prompt for and set the path if possible and required.
 * /*from ww w .  j a  va  2 s  .c o  m*/
 * @return true if a valid instance location has been set and false
 *         otherwise
 */
private boolean checkInstanceLocation(Shell shell) {
    // -data @none was specified but an ide requires workspace
    Location instanceLoc = Platform.getInstanceLocation();
    if (instanceLoc == null) {
        MessageDialog.openError(shell, IDEWorkbenchMessages.IDEApplication_workspaceMandatoryTitle,
                IDEWorkbenchMessages.IDEApplication_workspaceMandatoryMessage);
        return false;
    }

    // -data "/valid/path", workspace already set
    if (instanceLoc.isSet()) {
        // make sure the meta data version is compatible (or the user has
        // chosen to overwrite it).
        if (!checkValidWorkspace(shell, instanceLoc.getURL())) {
            return false;
        }

        // at this point its valid, so try to lock it and update the
        // metadata version information if successful
        try {
            if (instanceLoc.lock()) {
                writeWorkspaceVersion();
                return true;
            }

            // we failed to create the directory.  
            // Two possibilities:
            // 1. directory is already in use
            // 2. directory could not be created
            File workspaceDirectory = new File(instanceLoc.getURL().getFile());
            if (workspaceDirectory.exists()) {
                MessageDialog.openError(shell, IDEWorkbenchMessages.IDEApplication_workspaceCannotLockTitle,
                        IDEWorkbenchMessages.IDEApplication_workspaceCannotLockMessage);
            } else {
                MessageDialog.openError(shell, IDEWorkbenchMessages.IDEApplication_workspaceCannotBeSetTitle,
                        IDEWorkbenchMessages.IDEApplication_workspaceCannotBeSetMessage);
            }
        } catch (IOException e) {
            IDEWorkbenchPlugin.log("Could not obtain lock for workspace location", //$NON-NLS-1$
                    e);
            MessageDialog.openError(shell, IDEWorkbenchMessages.InternalError, e.getMessage());
        }
        return false;
    }

    IPreferenceStore store = new ScopedPreferenceStore(new ConfigurationScope(),
            IDEWorkbenchPlugin.IDE_WORKBENCH);

    boolean handledSHOW_WORKSPACE_SELECTION_DIALOG = store
            .getBoolean(OVERRIDE_SHOW_WORKSPACE_SELECTION_DIALOG_DEFAULT);
    if (!handledSHOW_WORKSPACE_SELECTION_DIALOG) {
        // We start with not asking the user for the workspace
        store.setValue(IDE.Preferences.SHOW_WORKSPACE_SELECTION_DIALOG, false);
        store.setValue(OVERRIDE_SHOW_WORKSPACE_SELECTION_DIALOG_DEFAULT, true);
    }

    // -data @noDefault or -data not specified, prompt and set
    ChooseWorkspaceData launchData = new ChooseWorkspaceData(instanceLoc.getDefault());

    boolean force = false;
    while (true) {

        URL workspaceUrl = promptForWorkspace(shell, launchData, force);
        if (workspaceUrl == null) {
            return false;
        }

        // if there is an error with the first selection, then force the
        // dialog to open to give the user a chance to correct
        force = true;

        try {
            // the operation will fail if the url is not a valid
            // instance data area, so other checking is unneeded
            if (instanceLoc.set(workspaceUrl, true)) {
                launchData.writePersistedData();
                writeWorkspaceVersion();
                return true;
            }
        } catch (IOException e) {
            MessageDialog.openError(shell, IDEWorkbenchMessages.IDEApplication_workspaceCannotBeSetTitle,
                    IDEWorkbenchMessages.IDEApplication_workspaceCannotBeSetMessage);
            return false;
        }

        // by this point it has been determined that the workspace is
        // already in use -- force the user to choose again
        MessageDialog.openError(shell, IDEWorkbenchMessages.IDEApplication_workspaceInUseTitle,
                IDEWorkbenchMessages.IDEApplication_workspaceInUseMessage);
    }
}

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

License:Open Source License

private void refreshFromLocal() {
    String[] commandLineArgs = Platform.getCommandLineArgs();
    IPreferenceStore store = IDEWorkbenchPlugin.getDefault().getPreferenceStore();
    boolean refresh = store.getBoolean(IDEInternalPreferences.REFRESH_WORKSPACE_ON_STARTUP);
    if (!refresh) {
        return;/*from   www  .  j a v  a 2s .  c om*/
    }

    // Do not refresh if it was already done by core on startup.
    for (int i = 0; i < commandLineArgs.length; i++) {
        if (commandLineArgs[i].equalsIgnoreCase("-refresh")) { //$NON-NLS-1$
            return;
        }
    }

    final IContainer root = ResourcesPlugin.getWorkspace().getRoot();
    Job job = new WorkspaceJob(IDEWorkbenchMessages.Workspace_refreshing) {
        public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
            root.refreshLocal(IResource.DEPTH_INFINITE, monitor);
            return Status.OK_STATUS;
        }
    };
    job.setRule(root);
    job.schedule();
}

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

License:Open Source License

public boolean preWindowShellClose() {
    if (getWorkbench().getWorkbenchWindowCount() > 1) {
        return true;
    }/*ww w.j av a  2  s . c o m*/
    // the user has asked to close the last window, while will cause the
    // workbench to close in due course - prompt the user for confirmation
    IPreferenceStore store = IDEWorkbenchPlugin.getDefault().getPreferenceStore();
    boolean promptOnExit = store.getBoolean(IDEInternalPreferences.EXIT_PROMPT_ON_CLOSE_LAST_WINDOW);

    if (promptOnExit) {
        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(
                getWindowConfigurer().getWindow().getShell(),
                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);
            IDEWorkbenchPlugin.getDefault().savePluginPreferences();
        }
    }

    return true;
}

From source file:com.aptana.ide.scripting.ScriptingEngine.java

License:Open Source License

/**
 * perspectiveActivated/*w  w  w  .j  ava 2 s . co  m*/
 * 
 * @param page
 * @param perspective
 */
private boolean perspectiveActivated(IWorkbenchPage page, IPerspectiveDescriptor perspective) {
    boolean result = false;

    if (supportedPerspectives.containsKey(perspective.getId())) {
        IPreferenceStore store = ScriptingPlugin.getDefault().getPreferenceStore();
        if (store.getBoolean(IPreferenceConstants.SCRIPTING_SERVER_START_AUTOMATICALLY)) {
            init();
            result = true;
        }
    }

    return result;
}

From source file:com.aptana.ide.search.epl.Compatibility.java

License:Open Source License

/**
 * @return/*from   ww  w  .  j a  v a  2 s . c  o m*/
 */
public static boolean isTableLimited() {
    IPreferenceStore store = SearchPlugin.getDefault().getPreferenceStore();
    return store.getBoolean(Compatibility.ORG_ECLIPSE_SEARCH_LIMIT_TABLE);
}

From source file:com.aptana.ide.update.eclipse36.P2Eclipse36PluginManager.java

License:Open Source License

/**
 * @see com.aptana.ide.update.manager.IPluginManager#checkForUpdates(boolean)
 *///from   w  ww .jav  a 2  s .c  om
public void checkForUpdates(boolean immediate) {
    if (!immediate) {
        AutomaticUpdatePlugin.getDefault().getScheduler().earlyStartup();
        return;
    }
    // Force the P2 automatic update check pref to be turned on, and force a
    // reschedule of the update check
    IPreferenceStore prefs = AutomaticUpdatePlugin.getDefault().getPreferenceStore();
    // Grab existing values
    boolean wasEnabled = prefs.getBoolean(PreferenceConstants.PREF_AUTO_UPDATE_ENABLED);
    String oldSchedule = prefs.getString(PreferenceConstants.PREF_AUTO_UPDATE_SCHEDULE);
    // Force new ones temporarily
    prefs.setValue(PreferenceConstants.PREF_AUTO_UPDATE_ENABLED, true);
    prefs.setValue(PreferenceConstants.PREF_AUTO_UPDATE_SCHEDULE, PreferenceConstants.PREF_UPDATE_ON_STARTUP);
    AutomaticUpdatePlugin.getDefault().savePreferences();
    // now check for updates
    AutomaticUpdatePlugin.getDefault().getScheduler().earlyStartup();
    // Now revert prefs
    prefs.setValue(PreferenceConstants.PREF_AUTO_UPDATE_ENABLED, wasEnabled);
    prefs.setValue(PreferenceConstants.PREF_AUTO_UPDATE_SCHEDULE, oldSchedule);
    AutomaticUpdatePlugin.getDefault().savePreferences();
}

From source file:com.aptana.ide.update.ui.SchedulerStartup.java

License:Open Source License

private void scheduleCheckForAnnouncements() {
    // Escape mechanism
    boolean doNotCheckForReleaseMessage = Boolean.getBoolean("DO_NOT_CHECK_FOR_NEWS_MESSAGE"); //$NON-NLS-1$
    if (doNotCheckForReleaseMessage) {
        return;/*from w  w  w .ja  va2  s. c  o  m*/
    }
    final IPreferenceStore prefs = UpdateUIActivator.getDefault().getPreferenceStore();
    boolean b_neverShow = prefs.getBoolean(IPreferenceConstants.NEVER_SHOW_ANNOUNCEMENTS);
    if (b_neverShow) {
        return;
    }

    String announcementURLPrefix = prefs.getString(IPreferenceConstants.ANNOUNCEMENT_URL_PREFIX);
    final String announceBaseURL = System.getProperty("ANNOUNCEMENT_URL_OVERRIDE", //$NON-NLS-1$
            announcementURLPrefix + "announce.php"); //$NON-NLS-1$
    Job job = new Job("Check for new announcement") { //$NON-NLS-1$

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            try {
                // For the announcements we want to pass the version of
                // studio and
                getAnnouncement(new URL(announceBaseURL + getParamsString()));
            } catch (MalformedURLException e) {
                logError(e);
            }

            return Status.OK_STATUS;
        }

        private void getAnnouncement(final URL url) {
            URLConnection urlConnection = null;
            try {
                urlConnection = url.openConnection();
            } catch (IOException ioe) {
                logError(ioe);
            }
            if (urlConnection instanceof HttpURLConnection) {
                HttpURLConnection httpURLConnection = (HttpURLConnection) urlConnection;
                try {
                    httpURLConnection.setConnectTimeout(1000);
                    httpURLConnection.setUseCaches(false);
                    httpURLConnection.addRequestProperty("Cache-Control", "no-cache"); //$NON-NLS-1$ //$NON-NLS-2$
                    httpURLConnection.setRequestMethod("HEAD"); //$NON-NLS-1$

                    if (httpURLConnection.getResponseCode() == HttpURLConnection.HTTP_OK) {
                        // Check for lastModified?
                        boolean showMessage = true;
                        long lastModified = httpURLConnection.getLastModified();
                        if (lastModified == 0) {
                            // unknown
                        } else {
                            boolean neverShowThisAgain = prefs
                                    .getBoolean(IPreferenceConstants.NEVER_SHOW_THIS_ANNOUNCEMENT);
                            if (neverShowThisAgain) {
                                long lastLastModified = prefs.getLong(
                                        IPreferenceConstants.NEVER_SHOW_THIS_ANNOUNCEMENT_LAST_LAST_MODIFIED);
                                if (lastModified <= lastLastModified) {
                                    showMessage = false;
                                }
                            }
                        }
                        prefs.setValue(IPreferenceConstants.NEVER_SHOW_THIS_ANNOUNCEMENT_LAST_LAST_MODIFIED,
                                lastModified);

                        String strHeight = httpURLConnection.getHeaderField(HEADER_HEIGHT);
                        String strWidth = httpURLConnection.getHeaderField(HEADER_WIDTH);

                        final int height = (strHeight != null) ? Integer.parseInt(strHeight) : 300;
                        final int width = (strWidth != null) ? Integer.parseInt(strWidth) : 300;

                        if (showMessage) {
                            UIJob uiJob = new UIJob("Show Aptana Announcement") { //$NON-NLS-1$
                                @Override
                                public IStatus runInUIThread(IProgressMonitor monitor) {
                                    IWorkbenchPage page = CoreUIPlugin.getActivePage();
                                    if (page != null) {
                                        BrowserDialog dialog = new BrowserDialog(CoreUIUtils.getActiveShell(),
                                                url.toString(), height, width);
                                        dialog.open();
                                    }

                                    return Status.OK_STATUS;
                                }
                            };
                            uiJob.setSystem(true);
                            uiJob.setRule(MutexJobRule.getInstance());
                            uiJob.schedule();
                        }
                    }
                } catch (IOException e) {
                    logError(e);
                } finally {
                    // cleanup
                    httpURLConnection.disconnect();
                }
            }
        }
    };
    job.setSystem(true);
    job.schedule();
}

From source file:com.aptana.ide.views.outline.UnifiedOutlinePage.java

License:Open Source License

/**
 * @see org.eclipse.ui.part.Page#setActionBars(org.eclipse.ui.IActionBars)
 *///from w  ww .j  a v  a  2  s . com
public void setActionBars(IActionBars actionBars) {
    // add split action
    if (this._outlines.size() > 0) {
        SplitOutlinesAction splitAction = new SplitOutlinesAction(this);

        splitAction.setEnabled(this._composite.isReparentable());
        this._splitItem = new ActionContributionItem(splitAction);
        actionBars.getToolBarManager().add(this._splitItem);
    }
    this._actionBars = actionBars;
    // add sort action
    SortAction sortAction = new SortAction(this);
    IPreferenceStore store = UnifiedEditorsPlugin.getDefault().getPreferenceStore();
    boolean sort = store.getBoolean(IPreferenceConstants.SORT_OUTLINE_ALPHABETICALLY);
    sortAction.setChecked(sort);
    if (sort) {
        getTreeViewer().setSorter(SortAction.SORTER);
    }
    this._sortItem = new ActionContributionItem(sortAction);
    actionBars.getToolBarManager().add(this._sortItem);

    // add hide private members action
    this._hidePrivateAction = new HidePrivateAction(this);
    this._hidePrivateItem = new ActionContributionItem(this._hidePrivateAction);
    actionBars.getToolBarManager().add(this._hidePrivateItem);

    // add collapse all action
    CollapseAction collapseAction = new CollapseAction(this);
    this._collapseItem = new ActionContributionItem(collapseAction);
    actionBars.getToolBarManager().add(this._collapseItem);

    Action expandAction = new Action(Messages.UnifiedOutlinePage_ExpandAll) {
        public void run() {
            getTreeViewer().expandAll();
        }
    };
    expandAction.setImageDescriptor(UnifiedEditorsPlugin.getImageDescriptor("icons/expandall.gif")); //$NON-NLS-1$
    expandAction.setToolTipText(Messages.UnifiedOutlinePage_CollapseAll);
    this._expandItem = new ActionContributionItem(expandAction);
    actionBars.getToolBarManager().add(this._expandItem);

    super.setActionBars(actionBars);
}

From source file:com.aptana.ide.views.outline.UnifiedOutlinePage.java

License:Open Source License

/**
 * Contibutes actions to quick outline menu.
 * //ww w .  j  a  va  2 s. c o m
 * @param manager
 *            - menu manager.
 */
public void contributeToQuickOutlineMenu(IMenuManager manager) {
    // add split action
    if (this._outlines.size() > 0) {
        SplitOutlinesAction splitAction = new SplitOutlinesAction(this);

        splitAction.setEnabled(this._composite.isReparentable());
        this._splitItem = new ActionContributionItem(splitAction);
        manager.add(this._splitItem);
    }
    // add sort action
    SortAction sortAction = new SortAction(this);
    IPreferenceStore store = UnifiedEditorsPlugin.getDefault().getPreferenceStore();
    boolean sort = store.getBoolean(IPreferenceConstants.SORT_OUTLINE_ALPHABETICALLY);
    sortAction.setChecked(sort);
    if (sort) {
        getTreeViewer().setSorter(SortAction.SORTER);
    }
    this._sortItem = new ActionContributionItem(sortAction);
    manager.add(this._sortItem);

    // add hide private members action
    this._hidePrivateAction = new HidePrivateAction(this);
    this._hidePrivateItem = new ActionContributionItem(this._hidePrivateAction);
    manager.add(this._hidePrivateItem);

    // add collapse all action
    CollapseAction collapseAction = new CollapseAction(this);
    this._collapseItem = new ActionContributionItem(collapseAction);
    manager.add(this._collapseItem);

    Action expandAction = new Action(Messages.UnifiedOutlinePage_ExpandAll) {
        public void run() {
            getTreeViewer().expandAll();
        }
    };
    expandAction.setImageDescriptor(UnifiedEditorsPlugin.getImageDescriptor("icons/expandall.gif")); //$NON-NLS-1$
    expandAction.setToolTipText(Messages.UnifiedOutlinePage_CollapseAll);
    this._expandItem = new ActionContributionItem(expandAction);
    manager.add(this._expandItem);
}