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:IOMdlTestGenerics.java

License:Apache License

public IOMdlTestGenerics() {
    super();//  w  w w. j  a v  a  2s  .com

    // Change default for the parse on resource change preference to
    // "always"
    IPreferenceStore store = CorePlugin.getDefault().getPreferenceStore();
    store.setValue(BridgePointPreferencesStore.EXPORT_GRAPHICS, "always"); //$NON-NLS-1$
}

From source file:ag.ion.noa4e.internal.ui.preferences.LocalOfficeApplicationPreferencesPage.java

License:Open Source License

/**
 * Notifies that the OK button of this page's container has been pressed. 
 * /*  w w w. j a va  2 s  .  c  o  m*/
 * @return false to abort the container's OK processing and true to allow 
 * the OK to happen
 * 
 * @author Joerg Sigle
 * @author Gerry Weirich
 * @author Andreas Brker
 * @author Markus Krger
 *
 * Adopted for Elexis by Joerg Sigle 02/2012, adding comments and monitoring output,
 * and reproducing the functionality of changes made by Gerry Weirich in 06/2007
 * for his NOAText plugin 1.4.1 to a file obtained from an older version of the ag.ion noa library.
 * 
 * Changes required because of different preference store layout in Elexis:
 * There are corresponding changes in:
 * LocalOfficeApplicationsPreferencesPage.java
 *   PREFS_PREVENT_TERMINATION
 *   initPreferenceValues()
 *   performOk()
 * NOAUIPlugin.java                     
 *   PREFERENCE_OFFICE_HOME
 *   PREFERENCE_PREVENT_TERMINATION            
 *   internalStartApplication().
 */
public boolean performOk() {
    System.out.println("LocalOfficeApplicationPreferencesPage: performOK() begin - Adopted to Elexis by GW/JS");
    System.out.println(
            "LocalOfficeApplicationPreferencesPage: performOk(): allocating preferenceStore = new SettingsPreferenceStore(Hub.localCfg)");
    System.out.println(
            "LocalOfficeApplicationPreferencesPage: performOk(): instead of using = NOAUIPlugin.getDefault().getPreferenceStore()");

    System.out.println(
            "LocalOfficeApplicationPreferencesPage: performOk(): Transferring settings from configuration dialog into internal storage...");

    IPreferenceStore preferenceStore = new SettingsPreferenceStore(CoreHub.localCfg);
    preferenceStore.setValue(PREFS_PREVENT_TERMINATION, buttonPreventTermination.getSelection());

    //When we read the two timeout settings, use try/catch so that data that can't be interpreted as integer numbers doesn't cause any harm.
    //The trim() is needed before parseInt(), otherwise an leading space will cause failure. 
    //See corresponding code in initPreferenceValues() and performOk().
    System.out.println(
            "LocalOfficeApplicationPreferencesPage: performOk(): ToDo: refactor to move repeatedly used constants into single places or even out of the code.");

    Integer timeoutBootstrapConnect = timeoutBootstrapConnectDefault; //Start by establishing a valid default setting
    try {
        timeoutBootstrapConnect = Integer.parseInt(textTimeoutBootstrapConnect.getText().trim()); //20130310js timeout made configurable for the loop found in bootstrap*.jar that would originally stop a connection attempt after 500 tries
    } catch (Throwable throwable) {
        //do not consume
    }
    if (timeoutBootstrapConnect < timeoutBootstrapConnectMin) {
        timeoutBootstrapConnect = timeoutBootstrapConnectMin;
    }
    ;
    if (timeoutBootstrapConnect > timeoutBootstrapConnectMax) {
        timeoutBootstrapConnect = timeoutBootstrapConnectMax;
    }
    ;
    preferenceStore.setValue(PREFS_TIMEOUT_BOOTSTRAP_CONNECT, timeoutBootstrapConnect.toString());
    //I also write back the possibly clamped value into the dialog immediately, cause this method might have been called by Apply rather than by OK:
    textTimeoutBootstrapConnect.setText(timeoutBootstrapConnect.toString());

    Integer timeoutThreadedWatchdog = timeoutThreadedWatchdogDefault; //Start by establishing a valid default setting
    try {
        timeoutThreadedWatchdog = Integer.parseInt(textTimeoutThreadedWatchdog.getText().trim()); //20130310js timeout made configurable for the threaded watchdog timer added in 1.4.x by js
    } catch (Throwable throwable) {
        //do not consume
    }
    if (timeoutThreadedWatchdog < timeoutThreadedWatchdogMin) {
        timeoutThreadedWatchdog = timeoutThreadedWatchdogMin;
    }
    ;
    if (timeoutThreadedWatchdog > timeoutThreadedWatchdogMax) {
        timeoutThreadedWatchdog = timeoutThreadedWatchdogMax;
    }
    ;
    preferenceStore.setValue(PREFS_TIMEOUT_THREADED_WATCHDOG, timeoutThreadedWatchdog.toString());
    //I also write back the possibly clamped value into the dialog immediately, cause this method might have been called by Apply rather than by OK:
    textTimeoutThreadedWatchdog.setText(timeoutThreadedWatchdog.toString());

    ///20130420js: noatext_jsl 1.4.9 -> 1.4.10: Adopt configurability of meaningful temporary filename from omnivore_js 1.4.4 begin
    for (int i = 0; i < PREFERENCE_cotf_elements.length; i++) {
        for (int j = 0; j < PREFERENCE_cotf_parameters.length; j++) {
            //Specifically, textCotfOption[0][0] and [0][2] will NOT have been created for theconstant1 element. Therefore, don't try to set anything to its content!
            if (textCotfOption[i][j] != null) {
                //Intermediate string variable:
                //check whether it's a valid integer.
                //   if yes: clamp it to the range [1..nNOAText_jslPREF_cotf_element_digits_max] 
                //   If no: re-use what's already in the preferenceStore. Should that not be an integer either, then remove the content alltogether.
                //FIXME: Sadly, any auto produced changes are only visible when the dialog is re-opened the next time.
                //FIXME: The same checking and limiting mechanism could be used upon the initialization of the dialog content after it is created. 
                String s = textCotfOption[i][j].getText().trim();
                if (!PREFERENCE_cotf_elements[i].contains("constant")
                        && (PREFERENCE_cotf_parameters[j].contains("num_digits"))) {
                    try {
                        Integer v1 = Integer.parseInt(s);
                        Integer v2 = v1;
                        if (v1 > nNOAText_jslPREF_cotf_element_digits_max) {
                            v2 = nNOAText_jslPREF_cotf_element_digits_max;
                        } else {
                            if (v1 < 1) {
                                v2 = 1;
                            }
                            if (v2 != v1) {
                                s = v2.toString().trim();
                            }
                        }
                    } catch (Throwable throwable) {
                        s = getCotfOption(i, j);
                        try {
                            Integer v3 = Integer.parseInt(s);
                        } catch (Throwable throwable2) {
                            s = "";
                        }
                    }

                }
                System.out.println("LocalOfficeApplicationPreferencesPage: performOk(): About to setValue("
                        + PREFERENCE_BRANCH + PREFERENCE_COTF + PREFERENCE_cotf_elements[i] + "_"
                        + PREFERENCE_cotf_parameters[j] + ", textCotfOption[" + i + "][" + j
                        + "].toString().trim()  ); which is <" + s + ">");
                preferenceStore.setValue(PREFERENCE_BRANCH + PREFERENCE_COTF + PREFERENCE_cotf_elements[i] + "_"
                        + PREFERENCE_cotf_parameters[j], s);
            }
        }
    }

    //IPreferenceStore preferenceStore = NOAUIPlugin.getDefault().getPreferenceStore();
    //preferenceStore.setValue(NOAUIPlugin.PREFERENCE_PREVENT_TERMINATION,
    //    buttonPreventTermination.getSelection());

    String oldPath = preferenceStore.getString(PreferenceConstants.P_OOBASEDIR);
    preferenceStore.setValue(PreferenceConstants.P_OOBASEDIR, textHome.getText());

    //String oldPath = preferenceStore.getString(NOAUIPlugin.PREFERENCE_OFFICE_HOME);
    //preferenceStore.setValue(NOAUIPlugin.PREFERENCE_OFFICE_HOME, textHome.getText());

    System.out.println(
            "LocalOfficeApplicationPreferencesPage: performOk(): Please note: There is a reference to NOAUIPlugin.getDefault()...");
    System.out.println(
            "LocalOfficeApplicationPreferencesPage: performOk(): still left in this code; I (js) don't know whether this might be null and hence not work.");

    super.performOk();
    if (oldPath.length() != 0 || !oldPath.equals(textHome.getText())) {
        if (EditorCorePlugin.getDefault().getManagedLocalOfficeApplication().isActive()) {
            if (MessageDialog.openQuestion(getShell(),
                    Messages.LocalOfficeApplicationPreferencesPage_dialog_restart_workbench_title,
                    Messages.LocalOfficeApplicationPreferencesPage_dialog_restart_workbench_message))
                NOAUIPlugin.getDefault().getWorkbench().restart();
        }
    }

    System.out.println("LocalOfficeApplicationPreferencesPage: performOk() return true");
    return true;
}

From source file:ag.ion.noa4e.ui.NOAUIPlugin.java

License:Open Source License

/**
 * Internal method in order to start the office application.
 * /*from   w w  w. jav a2s  .  c  o m*/
 * @param shell shell to be used
 * @param officeApplication office application to be used
 * 
 * @return status information
 * 
 * @author Joerg Sigle
 * @date 24.06.2012
 * @date 20.02.2012 00:57
 *
 * @author Andreas Brker
 * @date 28.06.2006
 * 
 * Adopted for Elexis by Joerg Sigle 02/2012, adding the following line.
 * Changes required because of different preference store layout in Elexis.
 * There are corresponding changes in:
 * LocalOfficeApplicationsPreferencesPage.java
 *   PREFS_PREVENT_TERMINATION
 *   initPreferenceValues()
 *   performOk()
 * NOAUIPlugin.java                     
 *   PREFERENCE_OFFICE_HOME
 *   PREFERENCE_PREVENT_TERMINATION            
 *   internalStartApplication().
 */
private static IStatus internalStartApplication(final Shell shell, IOfficeApplication officeApplication) {

    System.out.println("NOAUIPlugin: internalStartApplication() begin");

    if (officeApplication.isActive()) {
        System.out.println(
                "NOAUIPlugin: internalStartApplication(): officeApplication.isActive(), so returning immediately.");
        return Status.OK_STATUS;
    }

    System.out.println(
            "NOAUIPlugin: internalStartApplication(): !officeApplication.isActive(), so starting it up...");

    boolean configurationChanged = false;
    boolean canStart = false;
    String home = null;

    HashMap configuration = new HashMap(1);

    //My warning in the following line referred to the original noa4e code:
    //System.out.println("NOAUIPlugin: internalStartApplication(): getting officeHome (WARNING: probably from the wrong source)...");
    System.out.println("NOAUIPlugin: internalStartApplication(): getting officeHome...");
    System.out.println(
            "NOAUIPlugin: internalStartApplication(): Using js mod adopted for Elexis, reproducing prior GW adoptions, P_OOBASEDIR via ...(Hub.localCfg)");

    //JS modified this:
    //The original code tries to access a preference store which is not used in Elexis,
    //according to GWs mods in (back then:) LocalOfficeApplicationPreferencesPage.java
    //Unsuitable original line, removed:
    //String officeHome = getDefault().getPreferenceStore().getString(PREFERENCE_OFFICE_HOME);
    //Newly inserted lines:
    IPreferenceStore preferenceStore = new SettingsPreferenceStore(CoreHub.localCfg);
    String officeHome = preferenceStore.getString(PreferenceConstants.P_OOBASEDIR);

    if (officeHome == null)
        System.out.println("NOAUIPlugin: internalStartApplication(): WARNING: officeHome==null");
    else
        System.out.println("NOAUIPlugin: internalStartApplication(): officeHome=" + officeHome);

    if (officeHome.length() != 0) {
        File file = new File(officeHome);
        if (file.canRead()) {

            System.out.println(
                    "NOAUIPlugin: internalStartApplication(): Check: officeHome is a valid path. Setting canStart to true.");

            configuration.put(IOfficeApplication.APPLICATION_HOME_KEY, officeHome);
            canStart = true;
        } else {
            System.out.println(
                    "NOAUIPlugin: internalStartApplication(): WARNING: officeHome is NOT a valid path. Leaving canStart at false.");

            MessageDialog.openWarning(shell, Messages.NOAUIPlugin_dialog_warning_invalid_path_title,
                    Messages.NOAUIPlugin_dialog_warning_invalid_path_message);
        }
    }

    System.out.println("NOAUIPlugin: internalStartApplication(): canStart=" + canStart);

    if (!canStart) {
        System.out.println(
                "NOAUIPlugin: internalStartApplication(): canStart==false; trying to auto locate available office suite installations...");

        configurationChanged = true;
        ILazyApplicationInfo[] applicationInfos = null;
        boolean configurationCompleted = false;
        try {
            ProgressMonitorDialog progressMonitorDialog = new ProgressMonitorDialog(shell);
            FindApplicationInfosOperation findApplicationInfosOperation = new FindApplicationInfosOperation();
            progressMonitorDialog.run(true, true, findApplicationInfosOperation);
            applicationInfos = findApplicationInfosOperation.getApplicationsInfos();
            if (applicationInfos.length == 1) {
                if (applicationInfos[0].getMajorVersion() == 2 || (applicationInfos[0].getMajorVersion() == 1
                        && applicationInfos[0].getMinorVersion() == 9)) {
                    configuration.put(IOfficeApplication.APPLICATION_HOME_KEY, applicationInfos[0].getHome());
                    configurationCompleted = true;
                }
            }
        } catch (Throwable throwable) {
            System.out.println(
                    "NOAUIPlugin: internalStartApplication(): canStart==false; cannot auto locate an office suite installation. So we must search manually...");
            //we must search manually
        }

        System.out.println(
                "NOAUIPlugin: internalStartApplication(): configurationCompleted=" + configurationCompleted);

        if (!configurationCompleted) {
            LocalApplicationWizard localApplicationWizard = new LocalApplicationWizard(applicationInfos);
            if (home != null && home.length() != 0)
                localApplicationWizard.setHomePath(home);
            WizardDialog wizardDialog = new WizardDialog(shell, localApplicationWizard);
            if (wizardDialog.open() == Window.CANCEL)
                return Status.CANCEL_STATUS;

            configuration.put(IOfficeApplication.APPLICATION_HOME_KEY,
                    localApplicationWizard.getSelectedHomePath());
        }
    }

    System.out.println(
            "NOAUIPlugin: internalStartApplication(): the office suite configuration should now be valid:");
    if (officeApplication == null)
        System.out.println("NOAUIPlugin: internalStartApplication(): officeApplication==null");
    else
        System.out.println(
                "NOAUIPlugin: internalStartApplication(): officeApplication=" + officeApplication.toString());
    if (configuration == null)
        System.out.println("NOAUIPlugin: internalStartApplication(): configuration==null");
    else
        System.out
                .println("NOAUIPlugin: internalStartApplication(): configuration=" + configuration.toString());
    if (shell == null)
        System.out.println("NOAUIPlugin: internalStartApplication(): shell==null");
    else
        System.out.println("NOAUIPlugin: internalStartApplication(): shell=" + shell.toString());
    System.out.println(
            "NOAUIPlugin: internalStartApplication(): Finally trying activateOfficeApplication(officeApplication, configuration, shell):");

    IStatus status = activateOfficeApplication(officeApplication, configuration, shell);
    if (configurationChanged) {
        System.out.println(
                "NOAUIPlugin: internalStartApplication(): Configuration of PREFERENCE_OFFICE_HOME changed.");
        System.out.println("NOAUIPlugin: internalStartApplication(): Storing the new configuration.");
        System.out.println(
                "NOAUIPlugin: internalStartApplication(): Using js mod adopted for Elexis, reproducing prior GW adoptions, P_OOBASEDIR via ...(Hub.localCfg)");

        //JS modified this:
        //The original code tries to access a preference store which is not used in Elexis,
        //according to GWs mods in (back then:) LocalOfficeApplicationPreferencesPage.java
        //Unsuitable original line, removed:
        //getDefault().getPluginPreferences().setValue(PREFERENCE_OFFICE_HOME,
        //                                             configuration.get(IOfficeApplication.APPLICATION_HOME_KEY).toString());
        //Newly inserted line:
        preferenceStore.setValue(PreferenceConstants.P_OOBASEDIR,
                configuration.get(IOfficeApplication.APPLICATION_HOME_KEY).toString());
    }

    System.out.println("NOAUIPlugin: internalStartApplication() end, returning status");
    return status;
}

From source file:ar.com.tadp.xml.rinzo.jdt.preferences.ClassAttribute.java

License:Open Source License

public static void saveToPreference(List<ClassAttribute> list) {
    IPreferenceStore store = RinzoJDTPlugin.getDefault().getPreferenceStore();
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < list.size(); i++) {
        ClassAttribute attrInfo = list.get(i);
        sb.append(attrInfo.getTargetTag());
        sb.append(FileUtils.TAB);/*from  w w w. java 2  s .  c  o m*/
        sb.append(attrInfo.getAttributeName());
        sb.append(FileUtils.TAB);
        sb.append(attrInfo.getExtending());
        sb.append("\n");
    }
    store.setValue(RinzoJDTPlugin.PREF_CLASSNAME_ATTRS, sb.toString());
}

From source file:ar.com.tadp.xml.rinzo.jdt.preferences.ClassElement.java

License:Open Source License

public static void saveToPreference(List<ClassElement> list) {
    IPreferenceStore store = RinzoJDTPlugin.getDefault().getPreferenceStore();
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < list.size(); i++) {
        ClassElement element = list.get(i);
        sb.append(element.getDisplayName());
        sb.append(FileUtils.TAB);// www  .ja va2 s .c  o  m
        sb.append(element.getExtending());
        sb.append("\n");
    }
    store.setValue(RinzoJDTPlugin.PREF_CLASSNAME_ELEMENTS, sb.toString());
}

From source file:at.spardat.xma.gui.projectw.XMAProjectCreationWizzard.java

License:Open Source License

private void adjustSrcBinDirSettings() {
    if (srcBinSrcName != null)
        return;/*ww  w.ja  va2s.  c  o m*/
    IPreferenceStore store = PreferenceConstants.getPreferenceStore();
    srcBinFolderInNewProject = store.getBoolean(PreferenceConstants.SRCBIN_FOLDERS_IN_NEWPROJ);
    srcBinSrcName = store.getString(PreferenceConstants.SRCBIN_SRCNAME);
    srcBinBinName = store.getString(PreferenceConstants.SRCBIN_BINNAME);
    store.setValue(PreferenceConstants.SRCBIN_FOLDERS_IN_NEWPROJ, true);
    store.setValue(PreferenceConstants.SRCBIN_SRCNAME, "src");
    store.setValue(PreferenceConstants.SRCBIN_BINNAME, "classes");
}

From source file:at.spardat.xma.gui.projectw.XMAProjectCreationWizzard.java

License:Open Source License

private void restoreOriginalSrcBinDirSettings() {
    if (srcBinSrcName == null)
        return;//from  ww  w . ja va2s.  c o m
    IPreferenceStore store = PreferenceConstants.getPreferenceStore();
    store.setValue(PreferenceConstants.SRCBIN_FOLDERS_IN_NEWPROJ, srcBinFolderInNewProject);
    store.setValue(PreferenceConstants.SRCBIN_SRCNAME, srcBinSrcName);
    store.setValue(PreferenceConstants.SRCBIN_BINNAME, srcBinBinName);
    srcBinSrcName = srcBinBinName = null;
}

From source file:bndtools.editor.contents.ExportPatternsListPart.java

License:Open Source License

@Override
protected void doAddClauses(Collection<? extends ExportedPackage> pkgs, int index, boolean select) {
    Map<String, File> missingPkgInfoDirs;
    try {/*from w w w.  j a  v a2 s. c o m*/
        missingPkgInfoDirs = findSourcePackagesWithoutPackageInfo(pkgs);
    } catch (Exception e) {
        ErrorDialog.openError(getManagedForm().getForm().getShell(), "Error", null, new Status(IStatus.ERROR,
                Plugin.PLUGIN_ID, 0, "Error finding source package for exported 1packages.", e));
        missingPkgInfoDirs = Collections.emptyMap();
    }
    Collection<File> generatePkgInfoDirs = new ArrayList<File>(missingPkgInfoDirs.size());

    IPreferenceStore store = Plugin.getDefault().getPreferenceStore();
    boolean noAskPackageInfo = store.getBoolean(Plugin.PREF_NOASK_PACKAGEINFO);

    if (noAskPackageInfo || missingPkgInfoDirs.isEmpty()) {
        generatePkgInfoDirs.addAll(missingPkgInfoDirs.values());
    } else {
        PackageInfoDialog dlg = new PackageInfoDialog(getSection().getShell(), missingPkgInfoDirs);
        if (dlg.open() == Window.CANCEL)
            return;
        store.setValue(Plugin.PREF_NOASK_PACKAGEINFO, dlg.isDontAsk());
        generatePkgInfoDirs.addAll(dlg.getSelectedPackageDirs());
    }

    try {
        generatePackageInfos(generatePkgInfoDirs);
    } catch (CoreException e) {
        ErrorDialog.openError(getManagedForm().getForm().getShell(), "Error", null,
                new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Error generated packageinfo files.", e));
    }

    // Actually add the new exports
    super.doAddClauses(pkgs, index, select);
}

From source file:ca.uvic.chisel.javasketch.ui.internal.preferences.SketchPluginPreferenceInitializer.java

License:Open Source License

@Override
public void initializeDefaultPreferences() {
    IPreferenceStore store = SketchPlugin.getDefault().getPreferenceStore();
    store.setDefault(ISketchPluginPreferences.COMPACT_LOOPS_PREFERENCE, true);
    store.setDefault(ISketchPluginPreferences.DISPLAY_GROUPS_PREFERENCE, true);
    store.setDefault(SketchUI.PREFERENCE_FILTER_PACKAGE_EXPLORER, true);
    //in previous versions, the package explorer filter was off by default
    //we want to turn it on.
    store.setDefault("preference.packageExplore.update", false);
    if (!store.getBoolean("preference.packageExplore.update")) {
        store.setValue("preference.packageExplore.update", true);
        store.setValue(SketchUI.PREFERENCE_FILTER_PACKAGE_EXPLORER, true);
    }/*from   w w w  .j a v  a2s . c  om*/

}

From source file:ca.uvic.chisel.javasketch.ui.internal.presentation.commands.ToggleCompactLoopsHandler.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    //just set the preference
    IPreferenceStore store = SketchPlugin.getDefault().getPreferenceStore();
    boolean compactGroups = store.getBoolean(ISketchPluginPreferences.COMPACT_LOOPS_PREFERENCE);
    store.setValue(ISketchPluginPreferences.COMPACT_LOOPS_PREFERENCE, !compactGroups);
    return null;/*from   ww  w. jav a2  s  . c o  m*/
}