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.android.ide.eclipse.ddms.DdmsPlugin.java

License:Apache License

@Override
public void start(BundleContext context) throws Exception {
    super.start(context);

    final Display display = getDisplay();

    // get the eclipse store
    final IPreferenceStore eclipseStore = getPreferenceStore();

    AndroidDebugBridge.addDeviceChangeListener(this);

    DdmUiPreferences.setStore(eclipseStore);

    //DdmUiPreferences.displayCharts();

    // set the consoles.
    mDdmsConsole = new MessageConsole("DDMS", null); //$NON-NLS-1$
    ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[] { mDdmsConsole });

    final MessageConsoleStream consoleStream = mDdmsConsole.newMessageStream();
    final MessageConsoleStream errorConsoleStream = mDdmsConsole.newMessageStream();
    mRed = new Color(display, 0xFF, 0x00, 0x00);

    // because this can be run, in some cases, by a non UI thread, and because
    // changing the console properties update the UI, we need to make this change
    // in the UI thread.
    display.asyncExec(new Runnable() {
        @Override/*from w w w.  ja va2 s.  c  om*/
        public void run() {
            errorConsoleStream.setColor(mRed);
        }
    });

    // set up the ddms log to use the ddms console.
    Log.setLogOutput(new ILogOutput() {
        @Override
        public void printLog(LogLevel logLevel, String tag, String message) {
            if (logLevel.getPriority() >= LogLevel.ERROR.getPriority()) {
                printToStream(errorConsoleStream, tag, message);
                showConsoleView(mDdmsConsole);
            } else {
                printToStream(consoleStream, tag, message);
            }
        }

        @Override
        public void printAndPromptLog(final LogLevel logLevel, final String tag, final String message) {
            printLog(logLevel, tag, message);
            // dialog box only run in UI thread..
            display.asyncExec(new Runnable() {
                @Override
                public void run() {
                    Shell shell = display.getActiveShell();
                    if (logLevel == LogLevel.ERROR) {
                        MessageDialog.openError(shell, tag, message);
                    } else {
                        MessageDialog.openWarning(shell, tag, message);
                    }
                }
            });
        }

    });

    // set up the ddms console to use this objects
    DdmConsole.setConsole(new IDdmConsole() {
        @Override
        public void printErrorToConsole(String message) {
            printToStream(errorConsoleStream, null, message);
            showConsoleView(mDdmsConsole);
        }

        @Override
        public void printErrorToConsole(String[] messages) {
            for (String m : messages) {
                printToStream(errorConsoleStream, null, m);
            }
            showConsoleView(mDdmsConsole);
        }

        @Override
        public void printToConsole(String message) {
            printToStream(consoleStream, null, message);
        }

        @Override
        public void printToConsole(String[] messages) {
            for (String m : messages) {
                printToStream(consoleStream, null, m);
            }
        }
    });

    // set the listener for the preference change
    eclipseStore.addPropertyChangeListener(new IPropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent event) {
            // get the name of the property that changed.
            String property = event.getProperty();

            if (PreferenceInitializer.ATTR_DEBUG_PORT_BASE.equals(property)) {
                DdmPreferences
                        .setDebugPortBase(eclipseStore.getInt(PreferenceInitializer.ATTR_DEBUG_PORT_BASE));
            } else if (PreferenceInitializer.ATTR_SELECTED_DEBUG_PORT.equals(property)) {
                DdmPreferences.setSelectedDebugPort(
                        eclipseStore.getInt(PreferenceInitializer.ATTR_SELECTED_DEBUG_PORT));
            } else if (PreferenceInitializer.ATTR_THREAD_INTERVAL.equals(property)) {
                DdmUiPreferences.setThreadRefreshInterval(
                        eclipseStore.getInt(PreferenceInitializer.ATTR_THREAD_INTERVAL));
            } else if (PreferenceInitializer.ATTR_LOG_LEVEL.equals(property)) {
                DdmPreferences.setLogLevel(eclipseStore.getString(PreferenceInitializer.ATTR_LOG_LEVEL));
            } else if (PreferenceInitializer.ATTR_TIME_OUT.equals(property)) {
                DdmPreferences.setTimeOut(eclipseStore.getInt(PreferenceInitializer.ATTR_TIME_OUT));
            } else if (PreferenceInitializer.ATTR_USE_ADBHOST.equals(property)) {
                DdmPreferences.setUseAdbHost(eclipseStore.getBoolean(PreferenceInitializer.ATTR_USE_ADBHOST));
            } else if (PreferenceInitializer.ATTR_ADBHOST_VALUE.equals(property)) {
                DdmPreferences
                        .setAdbHostValue(eclipseStore.getString(PreferenceInitializer.ATTR_ADBHOST_VALUE));
            }
        }
    });

    // do some last initializations

    // set the preferences.
    PreferenceInitializer.setupPreferences();

    // this class is set as the main source revealer and will look at all the implementations
    // of the extension point. see #reveal(String, String, int)
    StackTracePanel.setSourceRevealer(this);

    /*
     * Load the extension point implementations.
     * The first step is to load the IConfigurationElement representing the implementations.
     * The 2nd step is to use these objects to instantiate the implementation classes.
     *
     * Because the 2nd step will trigger loading the plug-ins providing the implementations,
     * and those plug-ins could access DDMS classes (like ADT), this 2nd step should be done
     * in a Job to ensure that DDMS is loaded, so that the other plug-ins can load.
     *
     * Both steps could be done in the 2nd step but some of DDMS UI rely on knowing if there
     * is an implementation or not (DeviceView), so we do the first steps in start() and, in
     * some case, record it.
     *
     */

    // get the IConfigurationElement for the debuggerConnector right away.
    final IConfigurationElement[] dcce = findConfigElements("com.android.ide.eclipse.ddms.debuggerConnector"); //$NON-NLS-1$
    mHasDebuggerConnectors = dcce.length > 0;

    // get the other configElements and instantiante them in a Job.
    new Job(Messages.DdmsPlugin_DDMS_Post_Create_Init) {
        @Override
        protected IStatus run(IProgressMonitor monitor) {
            try {
                // init the lib
                AndroidDebugBridge.init(true /* debugger support */);

                // get the available adb locators
                IConfigurationElement[] elements = findConfigElements(
                        "com.android.ide.eclipse.ddms.toolsLocator"); //$NON-NLS-1$

                IToolsLocator[] locators = instantiateToolsLocators(elements);

                for (IToolsLocator locator : locators) {
                    try {
                        String adbLocation = locator.getAdbLocation();
                        String traceviewLocation = locator.getTraceViewLocation();
                        String hprofConvLocation = locator.getHprofConvLocation();
                        if (adbLocation != null && traceviewLocation != null && hprofConvLocation != null) {
                            // checks if the location is valid.
                            if (setToolsLocation(adbLocation, hprofConvLocation, traceviewLocation)) {

                                AndroidDebugBridge.createBridge(sAdbLocation, true /* forceNewBridge */);

                                // no need to look at the other locators.
                                break;
                            }
                        }
                    } catch (Throwable t) {
                        // ignore, we'll just not use this implementation.
                    }
                }

                // get the available debugger connectors
                mDebuggerConnectors = instantiateDebuggerConnectors(dcce);

                // get the available Traceview Launchers.
                elements = findConfigElements("com.android.ide.eclipse.ddms.traceviewLauncher"); //$NON-NLS-1$
                mTraceviewLaunchers = instantiateTraceviewLauncher(elements);

                return Status.OK_STATUS;
            } catch (CoreException e) {
                return e.getStatus();
            }
        }
    }.schedule();
}

From source file:com.android.ide.eclipse.ddms.preferences.PreferenceInitializer.java

License:Apache License

/**
 * Initializes the preferences of ddmlib and ddmuilib with values from the eclipse store.
 *//*www.j av a 2  s .c om*/
public synchronized static void setupPreferences() {
    IPreferenceStore store = DdmsPlugin.getDefault().getPreferenceStore();

    DdmPreferences.setDebugPortBase(store.getInt(ATTR_DEBUG_PORT_BASE));
    DdmPreferences.setSelectedDebugPort(store.getInt(ATTR_SELECTED_DEBUG_PORT));
    DdmPreferences.setLogLevel(store.getString(ATTR_LOG_LEVEL));
    DdmPreferences.setInitialThreadUpdate(store.getBoolean(ATTR_DEFAULT_THREAD_UPDATE));
    DdmPreferences.setInitialHeapUpdate(store.getBoolean(ATTR_DEFAULT_HEAP_UPDATE));
    DdmPreferences.setProfilerBufferSizeMb(store.getInt(ATTR_PROFILER_BUFSIZE_MB));
    DdmUiPreferences.setThreadRefreshInterval(store.getInt(ATTR_THREAD_INTERVAL));
    DdmPreferences.setTimeOut(store.getInt(ATTR_TIME_OUT));
    DdmPreferences.setUseAdbHost(store.getBoolean(ATTR_USE_ADBHOST));
    DdmPreferences.setAdbHostValue(store.getString(ATTR_ADBHOST_VALUE));
}

From source file:com.android.ide.eclipse.ddms.views.LogCatView.java

License:Apache License

private void onDoubleClick(LogCatMessage m) {
    String msg = m.getMessage();//from  ww  w  .j  ava 2  s .  c o  m
    if (!mStackTraceParser.isValidExceptionTrace(msg)) {
        return;
    }

    IPreferenceStore store = DdmsPlugin.getDefault().getPreferenceStore();
    String perspectiveId = null;
    if (store.getBoolean(PreferenceInitializer.ATTR_SWITCH_PERSPECTIVE)) {
        perspectiveId = store.getString(PreferenceInitializer.ATTR_PERSPECTIVE_ID);
    }

    String fileName = mStackTraceParser.getFileName(msg);
    int lineNumber = mStackTraceParser.getLineNumber(msg);
    String methodName = mStackTraceParser.getMethodName(msg);
    JavaSourceRevealer.revealMethod(methodName, fileName, lineNumber, perspectiveId);
}

From source file:com.android.ide.eclipse.ddms.views.OldLogCatView.java

License:Apache License

void switchPerspective() {
    IPreferenceStore store = DdmsPlugin.getDefault().getPreferenceStore();
    if (store.getBoolean(PreferenceInitializer.ATTR_SWITCH_PERSPECTIVE)) {
        IWorkbench workbench = PlatformUI.getWorkbench();
        IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
        IPerspectiveRegistry perspectiveRegistry = workbench.getPerspectiveRegistry();
        String perspectiveId = store.getString(PreferenceInitializer.ATTR_PERSPECTIVE_ID);
        if (perspectiveId != null && perspectiveId.length() > 0
                && perspectiveRegistry.findPerspectiveWithId(perspectiveId) != null) {
            try {
                workbench.showPerspective(perspectiveId, window);
            } catch (WorkbenchException e) {
                e.printStackTrace();//  ww w .j a  v  a  2  s .c  o m
            }
        }
    }
}

From source file:com.aptana.editor.common.AbstractThemeableEditor.java

License:Open Source License

private boolean isLineNumberVisible() {
    IPreferenceStore store = getPreferenceStore();
    return (store != null)
            ? store.getBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER)
            : false;//from ww w.  j a  va 2  s. c om
}

From source file:com.aptana.editor.common.AbstractThemeableEditor.java

License:Open Source License

/**
 * Returns true if the editor's preferences are set to fold.
 * //w w  w  . j  ava2s.c  o m
 * @return True, if folding is on; False, in case it's off.
 */
public boolean isFoldingEnabled() {
    IPreferenceStore store = getPreferenceStore();
    return store != null && store.getBoolean(IPreferenceConstants.EDITOR_ENABLE_FOLDING);
}

From source file:com.aptana.editor.common.AbstractThemeableEditor.java

License:Open Source License

/**
 * Returns true if the editor's preferences are set to mark element occurrences.
 * /*from  ww w  . j  av a 2s  .com*/
 * @return True, if mark occurrences is on; False, in case it's off.
 */
public boolean isMarkingOccurrences() {
    IPreferenceStore store = getPreferenceStore();
    return store != null && store.getBoolean(IPreferenceConstants.EDITOR_MARK_OCCURRENCES);
}

From source file:com.aptana.editor.findbar.impl.FindBarConfiguration.java

License:Open Source License

/**
 * Toggles the setting for the given preferences key.
 *//*from  w  w w .  ja  va  2s  .c  o m*/
public void toggle(String preferencesKey) {
    IPreferenceStore preferenceStore = getPreferenceStore();
    boolean b = !preferenceStore.getBoolean(preferencesKey);
    if (preferencesKey.equals(IPreferencesConstants.REGULAR_EXPRESSION_IN_FIND_BAR)) {
        setRegularExpression(b);
    } else if (preferencesKey.equals(IPreferencesConstants.WHOLE_WORD_IN_FIND_BAR)) {
        setWholeWord(b);
    } else if (preferencesKey.equals(IPreferencesConstants.CASE_SENSITIVE_IN_FIND_BAR)) {
        setCaseSensitive(b);
    } else {
        preferenceStore.setValue(preferencesKey, b);
    }
}

From source file:com.aptana.editor.findbar.impl.FindBarDecorator.java

License:Open Source License

/**
 * Updates the find bar action (sets it as the Aptana find bar or restores the original one).
 *//* w  ww.  j  av a 2  s.co  m*/
private void updateFindBarAction() {
    IPreferenceStore preferenceStore = FindBarPlugin.getDefault().getPreferenceStore();
    boolean useCustomFindBar = preferenceStore.getBoolean(IPreferencesConstants.USE_CUSTOM_FIND_BAR);
    if (useCustomFindBar) {
        // Replaces the actual find with our find.
        textEditor.setAction(ITextEditorActionConstants.FIND, new ShowFindBarAction(textEditor));
    } else {
        // Restore the original find action.
        textEditor.setAction(ITextEditorActionConstants.FIND, fOriginalFindBarAction);
    }

}

From source file:com.aptana.editor.findbar.impl.FindBarOption.java

License:Open Source License

/**
 * Creates a menu item for this option (for a pop-up menu).
 *//*  ww  w. ja v  a  2  s  .  c  o m*/
public MenuItem createMenuItem(Menu menu) {
    if (!createMenuItem) {
        return null;
    }
    final ToolItem toolItem = (ToolItem) getToolItemFromDecorator();
    MenuItem item;
    if (isCheckable()) {
        item = new MenuItem(menu, SWT.CHECK);
        if (!StringUtil.isEmpty(preferencesKey)) {
            IPreferenceStore preferenceStore = FindBarPlugin.getDefault().getPreferenceStore();
            item.setSelection(preferenceStore.getBoolean(preferencesKey));
        } else {
            item.setSelection(toolItem.getSelection());
        }
    } else {
        item = new MenuItem(menu, SWT.PUSH);
    }
    item.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            if (isCheckable() && !StringUtil.isEmpty(preferencesKey)) {
                FindBarDecorator.findBarConfiguration.toggle(preferencesKey);
            } else {
                execute();
            }
        }
    });
    item.setImage(FindBarPlugin.getImage(this.image));
    item.setText("  " + toolItem.getToolTipText()); //$NON-NLS-1$
    return item;
}