Example usage for java.util.prefs Preferences node

List of usage examples for java.util.prefs Preferences node

Introduction

In this page you can find the example usage for java.util.prefs Preferences node.

Prototype

public abstract Preferences node(String pathName);

Source Link

Document

Returns the named preference node in the same tree as this node, creating it and any of its ancestors if they do not already exist.

Usage

From source file:org.kuali.test.ui.base.BaseTable.java

private int getColumnWidth(int col) {
    int retval = getConfig().getColumnWidths()[col];
    Preferences proot = Preferences.userRoot();
    Preferences node = proot.node(Constants.PREFS_TABLE_NODE);

    String key = getColumnPreferenceKey(col, "width");

    if (StringUtils.isNotBlank(key)) {
        retval = node.getInt(key, retval);
    }/* w  w  w  .j  av  a2  s .  c  o  m*/

    return retval;
}

From source file:org.kuali.test.ui.base.BaseTable.java

/**
 *
 *///  ww w  . j  av a 2s .  c o m
public void saveTablePreferences() {
    TableConfiguration config = (TableConfiguration) getConfig();
    Preferences proot = Preferences.userRoot();
    Preferences node = proot.node(Constants.PREFS_TABLE_NODE);

    for (int i = 0; i < config.getPropertyNames().length; ++i) {
        String key = getColumnPreferenceKey(i, "width");

        if (StringUtils.isNotBlank(key)) {
            node.putInt(key, getColumnModel().getColumn(i).getPreferredWidth());
        }
    }
}

From source file:org.settings4j.connector.PreferencesConnector.java

/**
 * Resolve the given path and key against the given Preferences.
 *
 * @param path the preferences path (placeholder part before '/')
 * @param key the preferences key (placeholder part after '/')
 * @param preferences the Preferences to resolve against
 * @return the value for the placeholder, or <code>null</code> if none found
 *///from   w ww  .j  a  v  a 2  s . c o  m
protected String getPreferenceValue(final String path, final String key, final Preferences preferences) {
    if (path != null) {
        // Do not create the node if it does not exist...
        try {
            if (preferences.nodeExists(path)) {
                return preferences.node(path).get(key, null);
            }
            return null;
        } catch (final BackingStoreException e) {
            throw new RuntimeException("Cannot access specified node path [" + path + "]", e);
        }
    }
    return preferences.get(key, null);
}

From source file:org.keyboardplaying.xtt.configuration.PreferencesHelper.java

/** Creates a new instance. */
public PreferencesHelper() {
    Preferences prefRoot = Preferences.userRoot();
    try {/*from w w  w. j a v a 2  s  .c o  m*/
        initialized = prefRoot.nodeExists(NODE);
    } catch (BackingStoreException e) {
        LOG.error("The preferences store could not be loaded. Preferences will not be saved.", e);
        initialized = false;
    }
    preferences = prefRoot.node(NODE);
}

From source file:com.tag.FramePreferences.java

private Preferences getPreferences() {
    Preferences prefs = Preferences.userNodeForPackage(getClass());
    String pathName = getPathName();
    return (pathName == null) ? prefs : prefs.node(pathName);
}

From source file:org.apache.cayenne.modeler.util.CayenneController.java

/**
 * Returns preference for this component view.
 *///from   w  w w  .  j  a  va 2  s  .c  o m
protected Preferences getViewPreferences() {

    if (getApplication().getProject() == null) {
        return getApplication().getPreferencesNode(getView().getClass(), "");
    }

    Preferences pref = getApplication().getMainPreferenceForProject();
    String pathToProject = pref.absolutePath();
    String path = pathToProject + "/" + getView().getClass().getName().replace(".", "/");

    return pref.node(path);
}

From source file:haven.Utils.java

static synchronized Preferences prefs() {
    if (prefs == null) {
        Preferences node = Preferences.userNodeForPackage(Utils.class);
        if (Config.prefspec != null)
            node = node.node(Config.prefspec);
        prefs = node;//from   www  . jav a2 s .  c  om
    }
    return (prefs);
}

From source file:org.kuali.test.ui.components.panels.FileTestPanel.java

/**
 *
 * @param e//from   w  w w .j  a v a  2 s  .  c o  m
 */
@Override
protected void handleUnprocessedActionEvent(ActionEvent e) {
    if (Constants.FILE_SEARCH_ACTION.equals(e.getActionCommand())) {
        Preferences proot = Preferences.userRoot();
        Preferences node = proot.node(Constants.PREFS_FILES_NODE);

        String lastDir = node.get(Constants.PREFS_LAST_FILE_TEST_DIR, System.getProperty("user.home"));

        JFileChooser chooser = new JFileChooser(lastDir);
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

        chooser.setFileFilter(new FileFilter() {
            @Override
            public boolean accept(File f) {
                return (f.isDirectory() && f.exists());
            }

            @Override
            public String getDescription() {
                return "file inquiry directory";
            }
        });

        int returnVal = chooser.showOpenDialog(getMainframe());
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File f = chooser.getSelectedFile();
            fileDirectory.setText(f.getPath());
            node.put(Constants.PREFS_LAST_FILE_TEST_DIR, f.getPath());
        }
    } else if (Constants.FILE_EXISTS.equals(e.getActionCommand())) {
        getFileCheckCondition(Constants.FILE_DOES_NOT_EXIST).setSelected(false);
        getFileCheckCondition(Constants.FILE_SIZE_GREATER_THAN_ZERO).setEnabled(true);
        getFileCheckCondition(Constants.FILE_CREATED_TODAY).setEnabled(true);
        getFileCheckCondition(Constants.FILE_CREATED_YESTERDAY).setEnabled(true);
        containingText.setEnabled(true);
    } else if (Constants.FILE_DOES_NOT_EXIST.equals(e.getActionCommand())) {
        getFileCheckCondition(Constants.FILE_EXISTS).setSelected(false);
        getFileCheckCondition(Constants.FILE_SIZE_GREATER_THAN_ZERO).setSelected(false);
        getFileCheckCondition(Constants.FILE_SIZE_GREATER_THAN_ZERO).setEnabled(false);
        getFileCheckCondition(Constants.FILE_CREATED_TODAY).setSelected(false);
        getFileCheckCondition(Constants.FILE_CREATED_TODAY).setEnabled(false);
        getFileCheckCondition(Constants.FILE_CREATED_YESTERDAY).setSelected(false);
        getFileCheckCondition(Constants.FILE_CREATED_YESTERDAY).setEnabled(false);
        containingText.setText("");
        containingText.setEnabled(false);
    } else if (Constants.FILE_CREATED_TODAY.equals(e.getActionCommand())) {
        getFileCheckCondition(Constants.FILE_CREATED_YESTERDAY).setSelected(false);
    } else if (Constants.FILE_CREATED_YESTERDAY.equals(e.getActionCommand())) {
        getFileCheckCondition(Constants.FILE_CREATED_TODAY).setSelected(false);
    }
}

From source file:org.apache.cayenne.modeler.CodeTemplateManager.java

/**
 * Updates custom templates from preferences.
 *//*from   ww  w . j a v  a 2 s.c  om*/
public void updateCustomTemplates(Preferences preference) {
    String[] keys = null;
    try {
        keys = preference.childrenNames();
    } catch (BackingStoreException e) {
        logger.warn("Error reading preferences");
    }
    this.customTemplates = new HashMap<>(keys.length, 1);

    for (int j = 0; j < keys.length; j++) {
        FSPath path = new FSPath(preference.node(keys[j]));
        customTemplates.put(keys[j], path.getPath());
    }
}

From source file:de.fhg.igd.mapviewer.server.wms.wizard.pages.BasicConfigurationWithWMSListPage.java

@Override
public void createComponent() {
    super.createComponent();

    Button storeWMS = new Button(getComposite(), SWT.PUSH);
    storeWMS.setText(Messages.WMSListConfigurationPage_2);

    // add new WMS to list and refresh
    storeWMS.addSelectionListener(new SelectionAdapter() {

        @Override/*  www.  ja  va2 s . c o  m*/
        public void widgetSelected(SelectionEvent e) {
            // store WMS i UI list
            map.put(getServiceName(), getServiceURL());
            getListForUI(listUI);
            comboViewer.refresh();
        }
    });

    // free line
    new Text(getComposite(), SWT.NONE).setEditable(false);
    new Text(getComposite(), SWT.NONE).setEditable(false);
    new Text(getComposite(), SWT.NONE).setEditable(false);
    new Text(getComposite(), SWT.NONE).setEditable(false);
    new Text(getComposite(), SWT.NONE).setEditable(false);

    // add text and combo viewer
    Text text = new Text(getComposite(), SWT.NONE);
    text.setEditable(false);
    text.setText(Messages.WMSListConfigurationPage_0);

    // get a list of all WMS

    // get all WMS, storing as WMS Map Server
    Preferences PREF_SERVERS = new WMSMapServer().getPreferences();

    String[] prefs = null;
    try {
        prefs = PREF_SERVERS.childrenNames();

        // put all in map
        for (String current : prefs) {

            Preferences child = PREF_SERVERS.node(current);
            map.put(current, child.get("baseUrl", "baseUrl"));
        }

    } catch (BackingStoreException e) {
        log.warn(Messages.WMSListConfigurationPage_1, e); // $NON-NLS-1$
    }

    // get all WMS, storing as extension points
    IConfigurationElement[] allER = Platform.getExtensionRegistry()
            .getConfigurationElementsFor("de.fhg.igd.mapviewer.server.MapServer");

    for (IConfigurationElement current : allER) {
        String name = "";
        String url = "";

        // name is stored directly as attribute
        name = current.getAttribute("name");

        // url is stored as child
        for (IConfigurationElement child : current.getChildren()) {
            if (child.getAttribute("name").equals("baseUrl")) {
                url = child.getAttribute("value");
            }
        }
        // store everything into map
        if (name != null && !name.isEmpty() && url != null && !url.isEmpty()) {
            map.put(name, url);
        }
    }

    // show stored WMS as DropDown
    comboViewer = new ComboViewer(getComposite(), SWT.DROP_DOWN | SWT.BORDER | SWT.READ_ONLY);
    comboViewer.setContentProvider(new ArrayContentProvider());
    getListForUI(listUI);
    comboViewer.setInput(listUI);
    comboViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            if (selection.size() > 0) {
                String currentSelection = (String) selection.getFirstElement();
                name.setStringValue(currentSelection);
                location.setStringValue(map.get(currentSelection));
            }
        }
    });
}