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.motorolamobility.preflighting.ui.handlers.AnalyzeApkHandler.java

License:Apache License

public Object execute(ExecutionEvent event) throws ExecutionException {

    IWorkbench workbench = PlatformUI.getWorkbench();
    if ((workbench != null) && !workbench.isClosing()) {
        IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
        if (window != null) {
            ISelection selection = null;
            if (initialSelection != null) {
                selection = initialSelection;
            } else {
                selection = window.getSelectionService().getSelection();
            }/*from  w  ww  . j a  v a 2 s. c  o  m*/

            if (selection instanceof IStructuredSelection) {
                IStructuredSelection sselection = (IStructuredSelection) selection;
                Iterator<?> it = sselection.iterator();
                String sdkPath = AndroidUtils.getSDKPathByPreference();
                if (monitor != null) {
                    monitor.setTaskName(PreflightingUiNLS.ApplicationValidation_monitorTaskName);
                    monitor.beginTask(PreflightingUiNLS.ApplicationValidation_monitorTaskName,
                            sselection.size() + 1);
                    monitor.worked(1);
                }

                ArrayList<PreFlightJob> jobList = new ArrayList<PreFlightJob>();
                boolean isHelpExecution = false;

                IPreferenceStore preferenceStore = PreflightingUIPlugin.getDefault().getPreferenceStore();

                boolean showMessageDialog = true;
                if (preferenceStore.contains(
                        PreflightingUIPlugin.SHOW_BACKWARD_DIALOG + PreflightingUIPlugin.TOGGLE_DIALOG)) {
                    showMessageDialog = MessageDialogWithToggle.ALWAYS.equals(preferenceStore.getString(
                            PreflightingUIPlugin.SHOW_BACKWARD_DIALOG + PreflightingUIPlugin.TOGGLE_DIALOG));
                }

                if (showMessageDialog && (!preferenceStore.contains(PreflightingUIPlugin.OUTPUT_LIMIT_VALUE))
                        && preferenceStore.contains(PreflightingUIPlugin.COMMAND_LINE_PREFERENCE_KEY)
                        && (!(preferenceStore.getString(PreflightingUIPlugin.COMMAND_LINE_PREFERENCE_KEY))
                                .equals(PreflightingUIPlugin.DEFAULT_BACKWARD_COMMANDLINE))) {
                    String commandLine = PreflightingUIPlugin.getDefault().getPreferenceStore()
                            .getString(PreflightingUIPlugin.COMMAND_LINE_PREFERENCE_KEY);
                    MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoQuestion(
                            PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                            PreflightingUiNLS.AnalyzeApkHandler_BackwardMsg_Title,
                            NLS.bind(PreflightingUiNLS.AnalyzeApkHandler_BackwardMsg_Message, commandLine),
                            PreflightingUiNLS.AnalyzeApkHandler_Do_Not_Show_Again, false, preferenceStore,
                            PreflightingUIPlugin.SHOW_BACKWARD_DIALOG + PreflightingUIPlugin.TOGGLE_DIALOG);

                    int returnCode = dialog.getReturnCode();
                    if (returnCode == IDialogConstants.YES_ID) {
                        EclipseUtils.openPreference(
                                PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                                PreflightingUIPlugin.COMMAND_LINE_PREFERENCE_PAGE);
                    }
                }

                String userParamsStr = preferenceStore
                        .getString(PreflightingUIPlugin.COMMAND_LINE_PREFERENCE_KEY);

                downgradeErrors = preferenceStore
                        .contains(PreflightingUIPlugin.ECLIPSE_PROBLEM_TO_WARNING_VALUE)
                                ? preferenceStore
                                        .getBoolean(PreflightingUIPlugin.ECLIPSE_PROBLEM_TO_WARNING_VALUE)
                                : true;

                //we look for a help parameter: -help or -list-checkers
                //in such case we execute app validator only once, 
                //since all executions will have the same output
                if (userParamsStr.length() > 0) {
                    String regex = "((?!(\\s+" + "-" + ")).)*"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                    Pattern pat = Pattern.compile(regex);
                    Matcher matcher = pat.matcher(userParamsStr);
                    while (matcher.find()) {
                        String parameterValues = userParamsStr.substring(matcher.start(), matcher.end());
                        if (parameterValues.equals("-" //$NON-NLS-1$
                                + ApplicationParameterInterpreter.PARAM_HELP) || parameterValues.equals(
                                        "-" //$NON-NLS-1$
                                                + ApplicationParameterInterpreter.PARAM_LIST_CHECKERS)) {
                            isHelpExecution = true;
                        }
                    }
                }
                while (it.hasNext()) {
                    IResource analyzedResource = null;
                    Object resource = it.next();
                    String path = null;
                    if (resource instanceof IFile) {
                        IFile apkfile = (IFile) resource;
                        analyzedResource = apkfile;
                        if (apkfile.getFileExtension().equals("apk") && apkfile.exists() //$NON-NLS-1$
                                && apkfile.getLocation().toFile().canRead()) {
                            /*
                             * For each apk, execute all verifications passaing the two needed parameters
                             */
                            path = apkfile.getLocation().toOSString();
                        } else {
                            MessageDialog.openError(window.getShell(),
                                    PreflightingUiNLS.AnalyzeApkHandler_ErrorTitle,
                                    PreflightingUiNLS.AnalyzeApkHandler_ApkFileErrorMessage);
                        }
                    } else if (resource instanceof File) {
                        File apkfile = (File) resource;

                        if (apkfile.getName().endsWith(".apk") && apkfile.exists() //$NON-NLS-1$
                                && apkfile.canRead()) {
                            /*
                             * For each apk, execute all verifications passaing the two needed parameters
                             */
                            path = apkfile.getAbsolutePath();
                        } else {
                            MessageDialog.openError(window.getShell(),
                                    PreflightingUiNLS.AnalyzeApkHandler_ErrorTitle,
                                    PreflightingUiNLS.AnalyzeApkHandler_ApkFileErrorMessage);
                        }
                        enableMarkers = false;
                    } else if (resource instanceof IProject) {
                        IProject project = (IProject) resource;
                        analyzedResource = project;
                        path = project.getLocation().toOSString();
                    } else if (resource instanceof IAdaptable) {
                        IAdaptable adaptable = (IAdaptable) resource;
                        IProject project = (IProject) adaptable.getAdapter(IProject.class);
                        analyzedResource = project;

                        if (project != null) {
                            path = project.getLocation().toOSString();
                        }
                    }

                    if (path != null) {
                        PreFlightJob job = new PreFlightJob(path, sdkPath, analyzedResource);
                        jobList.add(job);
                        if (isHelpExecution) {
                            //app validator is executed only once for help commands
                            break;
                        }
                    }
                }

                if (enableMarkers) {
                    // Show and activate problems view
                    Runnable showProblemsView = new Runnable() {
                        public void run() {
                            try {
                                PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
                                        .showView(PROBLEMS_VIEW_ID);
                            } catch (PartInitException e) {
                                PreflightingLogger.error("Error showing problems view."); //$NON-NLS-1$
                            }

                        }
                    };

                    Display.getDefault().asyncExec(showProblemsView);
                }
                //show console for external apks
                else {
                    showApkConsole();
                }

                ParentJob parentJob = new ParentJob(
                        PreflightingUiNLS.AnalyzeApkHandler_PreflightingToolNameMessage, jobList);
                parentJob.setUser(true);
                parentJob.schedule();

                try {
                    if (monitor != null) {
                        monitor.done();
                    }
                } catch (Exception e) {
                    //Do nothing
                }
            }
        }
    }

    return null;
}

From source file:com.mulgasoft.emacsplus.commands.ToggleLineHighlight.java

License:Open Source License

/**
 * @see com.mulgasoft.emacsplus.commands.EmacsPlusNoEditHandler#transform(ITextEditor, IDocument, ITextSelection, ExecutionEvent)
 *///from  w w w .j av  a  2 s  .c o  m
@Override
protected int transform(ITextEditor editor, IDocument document, ITextSelection currentSelection,
        ExecutionEvent event) throws BadLocationException {
    IPreferenceStore store = EditorsUI.getPreferenceStore();
    if (store != null) {
        store.setValue(EDITOR_CURRENT_LINE, !store.getBoolean(EDITOR_CURRENT_LINE));
    }
    return NO_OFFSET;
}

From source file:com.mulgasoft.emacsplus.commands.YankPopHandler.java

License:Open Source License

private static boolean getPreference(String key) {
    boolean result = false;
    IPreferenceStore store = EmacsPlusActivator.getDefault().getPreferenceStore();
    if (store != null) {
        result = store.getBoolean(key);
    }// w ww . j  av a2s. c o m
    return result;
}

From source file:com.mulgasoft.emacsplus.KillRing.java

License:Open Source License

/**
 * Initialize the kill ring with settings from the preference store 
 *///from   w w w .j a v  a 2s .c  o m
private static synchronized void initialize() {
    if (ring == null) {
        Boolean clipword = false;
        Boolean clipsexp = true;
        int ringsize = LARGE_RING_SIZE;
        IPreferenceStore store = EmacsPlusActivator.getDefault().getPreferenceStore();
        if (store != null) {
            ringsize = store.getInt(KILL_RING_MAX.getPref());
            clipword = store.getBoolean(DELETE_WORD_TO_CLIPBOARD.getPref());
            clipsexp = store.getBoolean(DELETE_SEXP_TO_CLIPBOARD.getPref());
        }
        ring = new KillRing(ringsize);
        ring.setClipFeature(DELETE_WORD_TO_CLIPBOARD, clipword);
        ring.setClipFeature(DELETE_SEXP_TO_CLIPBOARD, clipsexp);

        getPreferenceStore().addPropertyChangeListener(new IPropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent event) {
                String prop = event.getProperty();
                if (REPLACE_TEXT_TO_KILLRING.getPref().equals(prop)) {
                    KillRing.getInstance().setSelectionReplace((Boolean) event.getNewValue());
                } else if (DELETE_WORD_TO_CLIPBOARD.getPref().equals(prop)) {
                    KillRing.getInstance().setClipFeature(DELETE_WORD_TO_CLIPBOARD,
                            (Boolean) event.getNewValue());
                } else if (DELETE_SEXP_TO_CLIPBOARD.getPref().equals(prop)) {
                    KillRing.getInstance().setClipFeature(DELETE_SEXP_TO_CLIPBOARD,
                            (Boolean) event.getNewValue());
                } else if (KILL_RING_MAX.getPref().equals(prop)) {
                    KillRing.getInstance().setSize((Integer) event.getNewValue());
                }
            }
        });

    }
}

From source file:com.mulgasoft.emacsplus.preferences.PrefVars.java

License:Open Source License

/**
 * Get the current value of the preference from the preference store
 * /*  ww  w  .j  a v  a2s.c  o  m*/
 * @return the Object representing the value
 */
public Object getValue() {
    Object result = null;
    IPreferenceStore store = getPreferenceStore();
    switch (type) {
    case BOOLEAN:
        result = store.getBoolean(getPref());
        break;
    case STRING:
        result = store.getString(getPref());
        break;
    case INTEGER:
        result = store.getInt(getPref());
        break;
    default:
        break;
    }
    return result;
}

From source file:com.nanosic.tc32eclipse.core.preferences.TC32PathsPreferences.java

License:Open Source License

/**
 * Check the value of the no startup path scan flag.
 * <p>/*from  www.  jav a2 s .c o m*/
 * This flag is set in the preferences to indicate, that the plugin should not - at plugin
 * startup - scan the system paths.
 * </p>
 * <p>
 * Even with the flag set the Plugin will still search each system path once to fill the
 * persistent cache.
 * </p>
 * 
 * @return <code>true</code> if the system paths should not be searched.
 */
public static boolean noStartupPathScan() {
    IPreferenceStore store = getPreferenceStore();
    return store.getBoolean(KEY_NOSTARTUPSCAN);
}

From source file:com.nextep.designer.p2.preferences.LicensePreferencePage.java

License:Open Source License

public LicensePreferencePage() {
    setPreferenceStore(P2Plugin.getDefault().getPreferenceStore());

    // Initialize the default value of auto-update preference
    IPreferenceStore prefs = getPreferenceStore();
    prefs.setDefault(PreferenceConstants.P_AUTO_UPDATE_NEXTEP, true);
    if (prefs.contains(PreferenceConstants.P_AUTO_UPDATE_NEXTEP)) {
        autoUpdate = prefs.getBoolean(PreferenceConstants.P_AUTO_UPDATE_NEXTEP);
    } else {//from  ww w  .j  a v  a  2  s .  c  om
        autoUpdate = prefs.getDefaultBoolean(PreferenceConstants.P_AUTO_UPDATE_NEXTEP);
    }
}

From source file:com.nextep.designer.sqlgen.ui.editors.StringAutoIndentStrategy.java

License:Open Source License

private void javaStringIndentAfterNewLine(IDocument document, DocumentCommand command)
        throws BadLocationException {

    ITypedRegion partition = TextUtilities.getPartition(document, fPartitioning, command.offset, true);
    int offset = partition.getOffset();
    int length = partition.getLength();

    if (command.offset == offset + length
            && document.getChar(offset + length - 1) == parser.getStringDelimiter())
        return;//from  ww  w. ja va 2  s. co m

    String indentation = getLineIndentation(document, command.offset);
    String delimiter = TextUtilities.getDefaultLineDelimiter(document);

    IRegion line = document.getLineInformationOfOffset(offset);
    String string = document.get(line.getOffset(), offset - line.getOffset());
    if (string.trim().length() != 0)
        indentation += String.valueOf("\t\t"); //$NON-NLS-1$

    IPreferenceStore preferenceStore = Activator.getDefault().getPreferenceStore();
    if (isLineDelimiter(document, command.text))
        command.text = strDelimiter + " " + parser.getStringConcatenator() + command.text + indentation //$NON-NLS-1$
                + strDelimiter; //$NON-NLS-2$
    else if (command.text.length() > 1 && preferenceStore.getBoolean(PreferenceConstants.EDITOR_ESCAPE_STRINGS))
        command.text = getModifiedText(command.text, indentation, delimiter);
}

From source file:com.nextep.designer.sqlgen.ui.editors.StringAutoIndentStrategy.java

License:Open Source License

public void customizeDocumentCommand(IDocument document, DocumentCommand command) {
    try {// w  ww .ja v a2  s.c  o  m
        if (command.text == null)
            return;

        IPreferenceStore preferenceStore = Activator.getDefault().getPreferenceStore();

        if (preferenceStore.getBoolean(PreferenceConstants.EDITOR_WRAP_STRINGS) && isSmartMode()) {
            javaStringIndentAfterNewLine(document, command);
        }

    } catch (BadLocationException e) {
    }
}

From source file:com.nokia.carbide.cdt.builder.test.BuilderPrefConstantsTest.java

License:Open Source License

/**
 * Test PREF_USE_BUILIN_X86_VARS/*  www . j a v  a  2s  .c o m*/
 */
public void testUseBuiltInX86VarsPref() throws Exception {
    // check default
    IPreferenceStore store = CarbideBuilderPlugin.getDefault().getPreferenceStore();
    boolean flag = store.getDefaultBoolean(BuilderPreferenceConstants.PREF_USE_BUILIN_X86_VARS);
    assertTrue("Default for use built-in x86 vars should be true.", flag);

    // check current setting read/write. Flip the switch
    flag = store.getBoolean(BuilderPreferenceConstants.PREF_USE_BUILIN_X86_VARS);
    store.setValue(BuilderPreferenceConstants.PREF_USE_BUILIN_X86_VARS, !flag);
    boolean newFlag = store.getBoolean(BuilderPreferenceConstants.PREF_USE_BUILIN_X86_VARS);
    assertEquals(!flag, newFlag);

    // set it back
    store.setValue(BuilderPreferenceConstants.PREF_USE_BUILIN_X86_VARS, flag);
    assertEquals(flag, store.getBoolean(BuilderPreferenceConstants.PREF_USE_BUILIN_X86_VARS));
}