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:org.osate.ui.wizards.AadlProjectWizard.java

License:Open Source License

/**
 * Do the work after everything is specified. <!-- begin-user-doc --> <!--
 * end-user-doc -->/*from  w  w  w  .  j a va 2  s.  c o m*/
 * 
 * @generated NOT
 */
public boolean performFinish() {
    createNewProject();
    if (newProject == null)
        return false;
    updatePerspective();
    selectAndReveal(newProject);
    final IProject p = getNewProject();
    final IFolder defModDir = p.getFolder(WorkspacePlugin.DEFAULT_MODEL_DIR);
    final IFolder xmlPack = defModDir.getFolder(WorkspacePlugin.AADL_PACKAGES_DIR);
    final IFolder xmlPSet = defModDir.getFolder(WorkspacePlugin.PROPERTY_SETS_DIR);
    final IFolder defSrcDir = p.getFolder(WorkspacePlugin.DEFAULT_SOURCE_DIR);
    final IFolder srcPack = defSrcDir.getFolder(WorkspacePlugin.AADL_PACKAGES_DIR);
    final 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) {
        MessageDialog.openError(getShell(), "Creation Problems",
                MessageFormat.format("Problem creating folder", e.getStackTrace().toString()));
    }
    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);
    try {
        ps.save();
    } catch (IOException e1) {
        MessageDialog.openError(getShell(), "Save Problem", //$NON-NLS-1$
                MessageFormat.format("Problem saving Preference Store", e1.getStackTrace().toString()));
    }
    try {
        p.refreshLocal(1, null);
    } catch (CoreException e2) {
        MessageDialog.openError(getShell(), "Refresh Problems Problems", //$NON-NLS-1$
                MessageFormat.format(
                        "Resource changes are disallowed during certain types of resource change event notification",
                        e2.getStackTrace().toString()));
    }
    try {
        if (!p.hasNature(XtextProjectHelper.NATURE_ID)) {
            IProjectDescription desc = p.getDescription();
            String[] oldNatures = desc.getNatureIds();
            String[] newNatures = new String[oldNatures.length + 1];
            System.arraycopy(oldNatures, 0, newNatures, 0, oldNatures.length);
            newNatures[oldNatures.length] = XtextProjectHelper.NATURE_ID;
            desc.setNatureIds(newNatures);
            p.setDescription(desc, null);
        }
    } catch (CoreException e) {
        OsateCorePlugin.log(e);
    }
    AadlNature.addNature(p, null);
    return true;
}

From source file:org.pwsafe.passwordsafeswt.util.UserPreferences.java

License:Open Source License

/**
 * Loads preferences from a properties file.
 * /*  ww w.  j  a va  2s .  c  o  m*/
 * @throws IOException if there are problems loading the preferences file
 */
private void loadPreferences() throws IOException {
    // props = new Properties();
    String userFile = getPreferencesFilename();
    if (log.isDebugEnabled())
        log.debug("Loading from [" + userFile + "]");
    File prefsFile = new File(userFile);
    if (!prefsFile.exists()) {
        File prefsDir = new File(System.getProperty("user.home") + File.separator + PROPS_DIR);
        if (!prefsDir.exists()) {
            prefsDir.mkdir();
        }
    }

    prefStore = new PreferenceStore(getPreferencesFilename());
    JFacePreferences.setPreferenceStore(prefStore);
    new JpwPreferenceInitializer().initializeDefaultPreferences();

    if (prefsFile.exists()) {
        prefStore.load();
    }
    // TODO: Check what happens if no file exists?

    if (log.isDebugEnabled())
        log.debug("Loaded " + prefStore + " preference settings from file");
}

From source file:org.wso2.andes.management.ui.views.NavigationView.java

License:Apache License

/**
 * This is a callback that will allow us to create the viewer and initialize
 * it./*  w  ww.  ja v a  2s  .  c  o  m*/
 */
public void createPartControl(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout gridLayout = new GridLayout();
    gridLayout.marginHeight = 2;
    gridLayout.marginWidth = 2;
    gridLayout.horizontalSpacing = 0;
    gridLayout.verticalSpacing = 2;
    composite.setLayout(gridLayout);

    createTreeViewer(composite);
    _serversRootNode = new TreeObject(NAVIGATION_ROOT, "ROOT");

    _treeViewer.setInput(_serversRootNode);
    // set viewer as selection event provider for MBeanView
    getSite().setSelectionProvider(_treeViewer);

    // Start worker thread to refresh tree for added or removed objects
    (new Thread(new Worker())).start();

    createConfigFile();
    _preferences = new PreferenceStore(INI_FILENAME);

    try {
        _preferences.load();
    } catch (IOException ex) {
        System.out.println(ex);
    }

    // load the list of servers already added from file
    List<String> serversList = getServerListFromFile();
    if (serversList != null) {
        for (String serverAddress : serversList) {
            String[] server = serverAddress.split(":");
            ManagedServer managedServer = new ManagedServer(server[0], Integer.parseInt(server[1]),
                    "org.wso2.andes");
            TreeObject serverNode = new TreeObject(serverAddress, NODE_TYPE_SERVER);
            serverNode.setManagedObject(managedServer);
            _serversRootNode.addChild(serverNode);
        }
    }

    _treeViewer.refresh();

}

From source file:org.wso2.andes.management.ui.views.type.QueueTypeTabControl.java

License:Apache License

private void loadAttributePreferences() {
    _preferences = new PreferenceStore(INI_FILENAME);
    List<String> attributesList = new ArrayList<String>();

    //ensure the name is present, and first
    attributesList.add(ManagedQueue.ATTR_NAME);

    //add any others from the file
    try {/*from w ww  .jav  a  2 s .c om*/
        _preferences.load();

        String selectedAttributes = _preferences.getString(INI_QUEUE_ATTRIBUES);
        if (selectedAttributes.length() != 0) {
            String[] attributes = selectedAttributes.split(",");
            for (String attr : attributes) {
                if (attr.equals(ManagedQueue.ATTR_NAME)) {
                    //the Name attribute is already present
                    continue;
                }

                attributesList.add(attr);
            }
        }
    } catch (IOException e) {
        ViewUtility.popupErrorMessage("Error",
                "Unable to load previous attribute selections, defaulting to Name only");
        System.err.println(e);
    }

    _selectedAttributes = attributesList;
}

From source file:tarlog.encoder.tool.eclipse.preferences.EncoderToolPreferencePage.java

License:Apache License

public EncoderToolPreferencePage(String string) throws IOException {
    this(new PreferenceStore(string));
}

From source file:tarlog.encoder.tool.ui.EncoderUI.java

License:Apache License

private void initEncodersStore() {
    try {/*  ww w  .ja v  a  2s .  c  o m*/
        IPreferenceStore preferenceStore;
        if (standalone) {
            PreferenceStore store = new PreferenceStore(EncoderTool.ENCODER_PROPERTIES);
            store.load();
            preferenceStore = store;
        } else {
            preferenceStore = Activator.getDefault().getPreferenceStore();
        }
        propertiesStore = new PropertiesStore(preferenceStore, false);
    } catch (MalformedURLException e) {
        Utils.showException(shell, e);
    } catch (IOException e) {
        Utils.showException(shell, e);
    }
}