Example usage for org.eclipse.jface.preference PreferenceStore PreferenceStore

List of usage examples for org.eclipse.jface.preference PreferenceStore PreferenceStore

Introduction

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

Prototype

public PreferenceStore(String filename) 

Source Link

Document

Creates an empty preference store that loads from and saves to the a file.

Usage

From source file:com.android.sdkstats.SdkStatsService.java

License:Apache License

/**
 * Returns the DDMS {@link PreferenceStore}.
 *//*w  ww  . j a  va 2s .com*/
public static synchronized PreferenceStore getPreferenceStore() {
    if (sPrefStore == null) {
        // get the location of the preferences
        String homeDir = null;
        try {
            homeDir = AndroidLocation.getFolder();
        } catch (AndroidLocationException e1) {
            // pass, we'll do a dummy store since homeDir is null
        }

        if (homeDir != null) {
            String rcFileName = homeDir + "ddms.cfg"; //$NON-NLS-1$

            // also look for an old pref file in the previous location
            String oldPrefPath = System.getProperty("user.home") //$NON-NLS-1$
                    + File.separator + ".ddmsrc"; //$NON-NLS-1$
            File oldPrefFile = new File(oldPrefPath);
            if (oldPrefFile.isFile()) {
                try {
                    PreferenceStore oldStore = new PreferenceStore(oldPrefPath);
                    oldStore.load();

                    oldStore.save(new FileOutputStream(rcFileName), "");
                    oldPrefFile.delete();

                    PreferenceStore newStore = new PreferenceStore(rcFileName);
                    newStore.load();
                    sPrefStore = newStore;
                } catch (IOException e) {
                    // create a new empty store.
                    sPrefStore = new PreferenceStore(rcFileName);
                }
            } else {
                sPrefStore = new PreferenceStore(rcFileName);

                try {
                    sPrefStore.load();
                } catch (IOException e) {
                    System.err.println("Error Loading Preferences");
                }
            }
        } else {
            sPrefStore = new PreferenceStore();
        }
    }

    return sPrefStore;
}

From source file:com.archimatetool.editor.preferences.ColoursFontsPreferencePage.java

License:Open Source License

/**
 * @throws IOException//  w w w . ja v  a2s . c o  m
 * Import a User color scheme
 */
private void importUserColors() throws IOException {
    FileDialog dialog = new FileDialog(getShell(), SWT.OPEN);
    dialog.setText(Messages.ColoursFontsPreferencePage_4);

    if (!PlatformUtils.isMac()) { // Single file filtering in the Open dialog doesn't work on Mac
        dialog.setFilterExtensions(new String[] { "ArchiColours.prefs", "*.prefs", "*.*" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        dialog.setFileName("ArchiColours.prefs"); //$NON-NLS-1$
    } else {
        dialog.setFilterExtensions(new String[] { "*.prefs", "*.*" }); //$NON-NLS-1$ //$NON-NLS-2$
    }

    String path = dialog.open();
    if (path == null) {
        return;
    }

    PreferenceStore store = new PreferenceStore(path);
    store.load();

    // Fill Colors
    for (Entry<Object, Color> entry : fColorsCache.entrySet()) {
        String key = DEFAULT_FILL_COLOR_PREFIX + getColorKey(entry.getKey());
        String value = store.getString(key);

        if (StringUtils.isSet(value)) {
            setColor(entry.getKey(), ColorFactory.convertStringToRGB(value));
        }
    }

    // Element Line Color
    String key = DEFAULT_ELEMENT_LINE_COLOR;
    String value = store.getString(key);
    if (StringUtils.isSet(value)) {
        setColor(key, ColorFactory.convertStringToRGB(value));
    }

    // Connection Line Color
    key = DEFAULT_CONNECTION_LINE_COLOR;
    value = store.getString(key);
    if (StringUtils.isSet(value)) {
        setColor(key, ColorFactory.convertStringToRGB(value));
    }
}

From source file:com.archimatetool.editor.preferences.ColoursFontsPreferencePage.java

License:Open Source License

/**
 * @throws IOException/*  w w  w .j  ava2 s  .com*/
 * Export a user color scheme
 */
private void exportUserColors() throws IOException {
    FileDialog dialog = new FileDialog(getShell(), SWT.SAVE);
    dialog.setText(Messages.ColoursFontsPreferencePage_5);
    dialog.setFileName("ArchiColours.prefs"); //$NON-NLS-1$
    String path = dialog.open();
    if (path == null) {
        return;
    }

    // Make sure the file does not already exist
    File file = new File(path);
    if (file.exists()) {
        boolean result = MessageDialog.openQuestion(getShell(), Messages.ColoursFontsPreferencePage_15,
                NLS.bind(Messages.ColoursFontsPreferencePage_16, file));
        if (!result) {
            return;
        }
    }

    PreferenceStore store = new PreferenceStore(path);
    saveColors(store);
    store.save();
}

From source file:com.mindquarry.desktop.client.MindClient.java

License:Open Source License

public MindClient() throws IOException {
    super(null);//  w ww  .  j  a v a 2s.c  o m
    ensureSettingsFolderExists();
    createLock();

    EventBus.registerListener(this);
    // initialize preferences
    prefFile = new File(PREF_FILE);
    store = new PreferenceStore(prefFile.getAbsolutePath());
    HttpUtilities.setStore(store);
}

From source file:com.mindquarry.desktop.minutes.editor.action.EditPreferencesAction.java

License:Open Source License

/**
 * @see org.eclipse.jface.action.Action#run()
 *//*  ww  w  . java2s. c om*/
@Override
public void run() {
    PreferenceManager mgr = PreferenceUtilities.getDefaultPreferenceManager();
    FilteredPreferenceDialog dlg = new FilteredPreferenceDialog(null, mgr);
    dlg.setPreferenceStore(new PreferenceStore("minutes-editor.properties")); //$NON-NLS-1$
    dlg.open();
}

From source file:com.nokia.sdt.sourcegen.SourceGenUtils.java

License:Open Source License

private static IPreferenceStore getPreferenceStore() {
    if (cachedPreferenceStore == null) {
        IPreferenceStore preferenceStore = null;
        AbstractUIPlugin plugin = UIModelPlugin.getDefault();
        if (plugin != null)
            preferenceStore = plugin.getPreferenceStore();
        if (preferenceStore == null) {
            try {
                // fake it for unit tests
                File tempFile = File.createTempFile("prefstore", "dat");
                tempFile.deleteOnExit();
                preferenceStore = new PreferenceStore(tempFile.getAbsolutePath());
            } catch (IOException e) {
            }//from   w  ww.  j  av  a  2  s . c  om
        }
        cachedPreferenceStore = preferenceStore;
    }
    return cachedPreferenceStore;
}

From source file:com.python.pydev.analysis.system_info_builder.SynchSystemModulesManagerTest.java

License:Open Source License

private PreferenceStore createPreferenceStore() {
    return new PreferenceStore(new File(baseDir, "preferenceStore").toString());
}

From source file:com.rockwellcollins.atc.sysml2aadl.Importer.java

License:Open Source License

private IProject getOrCreateProject(AadlPackage ap, String name) throws Exception {
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    IProject p = root.getProject(name);/*w w  w.j  a v a 2 s  . c o m*/
    if (p.exists()) {
        return p;
    }
    p.create(null);
    p.open(null);

    IFolder defModDir = p.getFolder(WorkspacePlugin.DEFAULT_MODEL_DIR);
    IFolder xmlPack = defModDir.getFolder(WorkspacePlugin.AADL_PACKAGES_DIR);
    IFolder xmlPSet = defModDir.getFolder(WorkspacePlugin.PROPERTY_SETS_DIR);
    IFolder defSrcDir = p.getFolder(WorkspacePlugin.DEFAULT_SOURCE_DIR);
    IFolder srcPack = defSrcDir.getFolder(WorkspacePlugin.AADL_PACKAGES_DIR);
    IFolder srcPSet = defSrcDir.getFolder(WorkspacePlugin.PROPERTY_SETS_DIR);

    try {
        CoreUtility.createFolder(xmlPack, true, true, null);
        CoreUtility.createFolder(xmlPSet, true, true, null);
        CoreUtility.createFolder(srcPack, true, true, null);
        CoreUtility.createFolder(srcPSet, true, true, null);
    } catch (CoreException e) {
        e.printStackTrace();
    }

    String filepath = p.getFile(WorkspacePlugin.AADLPATH_FILENAME).getRawLocation().toString();

    PreferenceStore ps = new PreferenceStore(filepath);
    ps.setValue(WorkspacePlugin.PROJECT_SOURCE_DIR, WorkspacePlugin.DEFAULT_SOURCE_DIR);
    ps.setValue(WorkspacePlugin.PROJECT_MODEL_DIR, WorkspacePlugin.DEFAULT_MODEL_DIR);
    ps.save();

    p.refreshLocal(1, null);
    AadlNature.addNature(p, null);
    addXtextNature(p);
    addPluginResourcesDependency(p);
    return p;
}

From source file:com.rohanclan.snippets.SnippetsPlugin.java

License:Open Source License

/**
 * This method is called upon plug-in activation
 *//*w ww  .  j  av  a 2  s . com*/
public void start(BundleContext context) throws Exception {
    super.start(context);

    propertyStore = new PreferenceStore(getDefault().getStateLocation().toString() + "/properties.ini");

    prefmanager = new PreferenceManager();
    propmanager = new PropertyManager();

    //load the images and default preferences 
    PluginImages.init();
    prefmanager.init();
    propmanager.initializeDefaultValues();
}

From source file:de.hasait.eclipse.ccg.properties.CcgProjectConfiguration.java

License:Apache License

private CcgProjectConfiguration(final String filename) {
    super();/*w  w  w .jav  a2 s  .c  om*/
    _preferenceStore = new PreferenceStore(filename);
    _preferenceStore.setDefault(OUTPUT_FOLDER_PATH_KEY, OUTPUT_FOLDER_PATH_DEFAULT_VALUE);
    _preferenceStore.setDefault(SOURCE_FOLDER_PATHS_KEY, SOURCE_FOLDER_PATHS_DEFAULT_VALUE);
    _preferenceStore.setDefault(GENERATOR_FOLDER_PATHS_KEY, GENERATOR_FOLDER_PATHS_DEFAULT_VALUE);
    try {
        _preferenceStore.load();
    } catch (IOException e) {
        // ignore
    }
}