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

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

Introduction

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

Prototype

void putValue(String name, String value);

Source Link

Document

Sets the current value of the preference with the given name to the given string value without sending a property change.

Usage

From source file:de.loskutov.eclipseskins.preferences.SkinsPreferencePage.java

License:Open Source License

private void setValue(IPreferenceStore store, String key, boolean value) {
    boolean hasValue = store.contains(key);
    store.setValue(key, value);// w w w  .j a v  a 2  s  . c o  m
    if (!hasValue || !value) {
        /*
         * if default value is the same as given argument, then store
         * doesn't set it and later we can't recognize if the value was
         * customized by user... So we set it first to opposite value,
         * and then to the desired one.
         */
        if (!hasValue) {
            store.setValue(key, !value);
            store.setValue(key, value);
        }
        // this set an string value as WORKAROUND
        store.putValue(key, "" + value);
    }
}

From source file:de.tobject.findbugs.FindbugsPlugin.java

License:Open Source License

/**
 * Save current UserPreferences for given project or workspace.
 *
 * @param project//from   w w  w.j  av  a 2s.c  om
 *            the project or null for workspace
 * @throws CoreException
 */
public static void saveUserPreferences(IProject project, final UserPreferences userPrefs) throws CoreException {

    FileOutput userPrefsOutput = new FileOutput() {
        @Override
        public void writeFile(OutputStream os) throws IOException {
            userPrefs.write(os);
        }

        @Override
        public String getTaskDescription() {
            return "writing user preferences";
        }
    };

    if (project != null) {
        // Make the new user preferences current for the project
        project.setSessionProperty(SESSION_PROPERTY_USERPREFS, userPrefs);
        IFile userPrefsFile = getUserPreferencesFile(project);
        ensureReadWrite(userPrefsFile);
        IO.writeFile(userPrefsFile, userPrefsOutput, null);
        if (project.getFile(DEPRECATED_PREFS_PATH).equals(userPrefsFile)) {
            String message = "Found old style FindBugs preferences for project '" + project.getName()
                    + "'. This preferences are not at the default location: '" + DEFAULT_PREFS_PATH + "'."
                    + " Please move '" + DEPRECATED_PREFS_PATH + "' to '" + DEFAULT_PREFS_PATH + "'.";
            getDefault().logWarning(message);
        }
    } else {
        // write the workspace preferences to the eclipse preference store
        ByteArrayOutputStream bos = new ByteArrayOutputStream(10000);
        try {
            userPrefs.write(bos);
        } catch (IOException e) {
            getDefault().logException(e, "Failed to write user preferences");
            return;
        }
        Properties props = new Properties();
        try {
            props.load(new ByteArrayInputStream(bos.toByteArray()));
        } catch (IOException e) {
            getDefault().logException(e, "Failed to save user preferences");
            return;
        }
        IPreferenceStore store = getDefault().getPreferenceStore();
        // Reset any existing custom group entries
        resetStore(store, UserPreferences.KEY_PLUGIN);
        resetStore(store, UserPreferences.KEY_EXCLUDE_BUGS);
        resetStore(store, UserPreferences.KEY_EXCLUDE_FILTER);
        resetStore(store, UserPreferences.KEY_INCLUDE_FILTER);
        for (Entry<Object, Object> entry : props.entrySet()) {
            store.putValue((String) entry.getKey(), (String) entry.getValue());
        }
        if (store instanceof IPersistentPreferenceStore) {
            IPersistentPreferenceStore store2 = (IPersistentPreferenceStore) store;
            try {
                store2.save();
            } catch (IOException e) {
                getDefault().logException(e, "Failed to save user preferences");
            }
        }
    }
}

From source file:eu.hydrologis.jgrass.beegisutils.BeegisUtilsPlugin.java

License:Open Source License

/**
 * Utility method for file dialogs to set the last folder.
 * /*from   ww  w. java2s  .c om*/
 * @param folderPath the folder path. If the path is a file path, the parent folder is saved.
 */
public void setLastFolderChosen(String folderPath) {
    File fiel = new File(folderPath);
    if (!fiel.isDirectory()) {
        folderPath = fiel.getParent();
    }
    IPreferenceStore store = getPreferenceStore();
    store.putValue(BEEGIS_LAST_CHOSEN_FOLDER, folderPath);
}

From source file:eu.numberfour.n4js.ui.preferences.AbstractN4JSPreferencePage.java

License:Open Source License

/** copied from OptionsConfigurationBlock */
private void useProjectSpecificSettings(boolean enable) {
    boolean hasProjectSpecificOption = disabledProjectSettings == null;
    if (enable != hasProjectSpecificOption && project != null) {
        IPreferenceStore preferenceStore = preferenceStoreAccessImpl.getWritablePreferenceStore(getProject());
        if (enable) {
            for (Triple<String, String, DESCR_TYPE> compiler : components) {
                for (CompilerProperties prop : CompilerProperties.values()) {
                    String curr = prop.getKey(compiler.getFirst());
                    String val = disabledProjectSettings.get(curr);
                    preferenceStore.putValue(curr, val);
                }//from w w w  .  ja  v a 2 s  .  c  om
            }
            disabledProjectSettings = null;
            getPreferenceStore().setValue(IS_PROJECT_SPECIFIC, true);
            try {
                getProject().setPersistentProperty(new QualifiedName(qualifiedName(), IS_PROJECT_SPECIFIC),
                        String.valueOf(true));
            } catch (CoreException e) {
                e.printStackTrace();
            }
        } else {
            disabledProjectSettings = Maps.newHashMap();
            for (Triple<String, String, DESCR_TYPE> compiler : components) {
                for (CompilerProperties prop : CompilerProperties.values()) {
                    String curr = prop.getKey(compiler.getFirst());
                    String oldSetting = preferenceStore.getString(curr);
                    disabledProjectSettings.put(curr, oldSetting);
                    preferenceStore.setToDefault(curr);
                }
            }
            getPreferenceStore().setToDefault(IS_PROJECT_SPECIFIC);
            try {
                getProject().setPersistentProperty(new QualifiedName(qualifiedName(), IS_PROJECT_SPECIFIC),
                        String.valueOf(false));
            } catch (CoreException e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:eu.udig.jconsole.JConsolePlugin.java

License:Open Source License

public void setLastOpenFolder(String path) {
    IPreferenceStore preferenceStore = getPreferenceStore();
    preferenceStore.putValue(LAST_FOLDER_KEY, path);
}

From source file:ext.org.eclipse.jdt.internal.ui.text.java.CompletionProposalComputerRegistry.java

License:Open Source License

private void updateUninstalledComputerCount() {
    IPreferenceStore preferenceStore = PreferenceConstants.getPreferenceStore();
    fIsFirstTimeCheckForUninstalledComputers = !preferenceStore.contains(NUM_COMPUTERS_PREF_KEY);
    int lastNumberOfComputers = preferenceStore.getInt(NUM_COMPUTERS_PREF_KEY);
    int currNumber = fDescriptors.size();
    fHasUninstalledComputers = lastNumberOfComputers > currNumber;
    preferenceStore.putValue(NUM_COMPUTERS_PREF_KEY, Integer.toString(currNumber));
    JavaPlugin.flushInstanceScope();/*from  w w w.jav  a  2s .  c o  m*/
}

From source file:ext.org.eclipse.jdt.internal.ui.text.java.CompletionProposalComputerRegistry.java

License:Open Source License

private void preventDuplicateCategories(IPreferenceStore store, Set<String> disabled,
        CompletionProposalCategory allProposals, CompletionProposalCategory typeProposals,
        CompletionProposalCategory allButTypeProposals) {
    boolean adjusted = false;
    if (allProposals == null || !allProposals.isIncluded())
        return;/* w w w.j a v  a 2 s  .c om*/

    if (allButTypeProposals != null && allButTypeProposals.isIncluded()) {
        allButTypeProposals.setIncluded(false);
        disabled.add(allButTypeProposals.getId());
        adjusted = true;
    }
    if (typeProposals != null && typeProposals.isIncluded()) {
        typeProposals.setIncluded(false);
        disabled.add(typeProposals.getId());
        adjusted = true;
    }

    if (adjusted) {
        StringBuffer buf = new StringBuffer(50 * disabled.size());
        Iterator<String> iter = disabled.iterator();
        while (iter.hasNext()) {
            buf.append(iter.next());
            buf.append('\0');
        }
        store.putValue(PreferenceConstants.CODEASSIST_EXCLUDED_CATEGORIES, buf.toString());
    }
}

From source file:gov.nasa.arc.spife.tests.europa.TestClient.java

License:Open Source License

@Before
public void setUp() throws Exception {
    //super.setUp();
    EuropaServerManager.setPreferences(EuropaPlugin.PREF_STORE_PREFERENCES);
    IPreferenceStore preferenceStore = EuropaPlugin.getDefault().getPreferenceStore();
    preferenceStore.putValue("gov.nasa.arc.spife.europa.host", "localhost");
    preferenceStore.putValue("gov.nasa.arc.spife.europa.junit.host", "localhost");
    preferenceStore.setValue("gov.nasa.arc.spife.europa.port", EuropaPreferences.getEuropaPort());
    preferenceStore.setValue("gov.nasa.arc.spife.europa.junit.port", EuropaPreferences.getEuropaPort());
    preferenceStore.setValue("gov.nasa.arc.spife.europa.junit.modelname", "MER2");

    host = EuropaPreferences.getEuropaHost();
    port = EuropaPreferences.getEuropaPort();
    Bundle bundle = EuropaPlugin.getDefault().getBundle();

    EuropaServerManager.createDirInStateArea("europa-test");
    EuropaServerManager.copyFileToStateArea("data/test/MER2-initial-state.nddl",
            "europa-test" + File.separator + "MER2-initial-state.nddl", bundle);
    EuropaServerManager.copyFileToStateArea("data/test/MER2-model.nddl",
            "europa-test" + File.separator + "MER2-model.nddl", bundle);
    EuropaServerManager.copyFileToStateArea("data/test/NDDL.cfg", "europa-test" + File.separator + "NDDL.cfg",
            bundle);/*www.  j a  v a  2 s  .com*/
    EuropaServerManager.copyFileToStateArea("data/test/SolverConfig.xml",
            "europa-test" + File.separator + "SolverConfig.xml", bundle);
    EuropaServerManager.copyFileToStateArea("data/test/TestEuropaServerManager.xml",
            "europa-test" + File.separator + "TestEuropaServerManager.xml", bundle);

    String absolutePath = EuropaServerManager.localStatePath().append("europa-test").toOSString();
    Map<String, String> replacements = new TreeMap<String, String>();
    replacements.put("\\$", absolutePath);

    String testEuropaServerManager = EuropaServerManager.localStatePath().append("europa-test")
            .append("TestEuropaServerManager.xml").toString();
    EuropaServerManager.startServerManager(testEuropaServerManager, replacements, true, bundle);
    System.out.println("Testing with URL: " + host + ":" + port);
    trace.info("Testing with URL: " + host + ":" + port);
}

From source file:net.atos.optimus.m2m.engine.ui.prefs.TransformationsPreferencesImex.java

License:Open Source License

static void exportPreferences() {
    Properties properties = new Properties();

    ExtensionPointTransformationDataSource manager = ExtensionPointTransformationDataSource.instance();

    for (TransformationReference reference : manager.getAll()) {
        properties.put(reference.getId(),
                PreferencesTransformationMask.INSTANCE.isTransformationEnabled(reference.getId()));
    }/*from   w w w. j  a  v a  2  s  .  c o m*/
    IPreferenceStore preferenceStore = Activator.getDefault().getPreferenceStore();
    FileDialog dialog = new FileDialog(new Shell(Display.getDefault()));
    String pathName = preferenceStore.getString(EXPORT_PREF);
    if (pathName != null && pathName.length() > 1)
        dialog.setFilterPath(pathName);
    dialog.setFileName("OptimusEnginePreferences-" + System.currentTimeMillis() + ".properties");
    dialog.setText(
            "Please select where to write the preferences (Selecting existing file will overwrite it)...");

    String result = dialog.open();
    if (result == null)
        return;

    String newPathName = dialog.getFilterPath();
    String newfileName = dialog.getFileName();

    if (!newPathName.equals(pathName))
        preferenceStore.putValue(EXPORT_PREF, newPathName);

    String fullpath = newPathName + File.separator + newfileName;

    FileOutputStream fos = null;
    try {
        File file = new File(fullpath);
        file.createNewFile();
        fos = new FileOutputStream(file);
        properties.store(fos, null);
        Activator.getDefault().getLog().log(new Status(IStatus.INFO, Activator.PLUGIN_ID,
                "Preferences exported successfully at " + fullpath));
        fos.close();
    } catch (IOException e1) {
        e1.printStackTrace();
    } finally {
        if (fos != null)
            try {
                fos.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
    }
}

From source file:net.atos.optimus.m2m.engine.ui.prefs.TransformationsPreferencesImex.java

License:Open Source License

static void importPreferences() {
    IPreferenceStore preferenceStore = Activator.getDefault().getPreferenceStore();

    FileDialog dialog = new FileDialog(new Shell(Display.getDefault()));
    String pathName = preferenceStore.getString(IMPORT_PATH_PREF);
    String fileName = preferenceStore.getString(IMPORT_NAME_PREF);

    dialog.setText("Please select file containing the preferences to import");
    dialog.setFilterExtensions(new String[] { "*.properties" });
    dialog.setFilterPath(pathName);// ww w.j av  a 2 s  .c om
    dialog.setFileName(fileName);
    dialog.open();

    String newFileName = dialog.getFileName();
    String newPathName = dialog.getFilterPath();
    String fullPath = newPathName + File.separator + newFileName;

    if (!newFileName.equals(fileName))
        preferenceStore.putValue(IMPORT_NAME_PREF, newFileName);
    if (!newPathName.equals(pathName))
        preferenceStore.putValue(IMPORT_NAME_PREF, newPathName);

    File file = new File(fullPath);

    if (!file.exists() || file.isDirectory()) {
        // LOG MESSAGE
        return;
    }
    Properties properties = new Properties();
    FileInputStream fis;
    try {
        fis = new FileInputStream(file);
        properties.load(fis);
        fis.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

    String keyPattern = Activator.PLUGIN_ID + ".disabled.";

    for (Object key : properties.keySet()) {
        String keyAsString = String.valueOf(key);
        if (keyAsString.startsWith(keyPattern)) {
            String id = keyAsString.substring(keyPattern.length());
            PreferencesTransformationMask.INSTANCE.setTransformationEnabled(id,
                    Boolean.parseBoolean(properties.getProperty(keyAsString)));
        }
    }
}