Example usage for java.util.prefs Preferences get

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

Introduction

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

Prototype

public abstract String get(String key, String def);

Source Link

Document

Returns the value associated with the specified key in this preference node.

Usage

From source file:com.github.fritaly.dualcommander.UserPreferences.java

public synchronized void init(Preferences preferences) {
    assertNotInitialized();//from w w w.j a  v  a 2 s  .c om

    Validate.notNull(preferences, "The given preferences is null");

    this.showHidden = preferences.getBoolean(PROPERTY_SHOW_HIDDEN, false);
    this.editFileCommand = preferences.get(PROPERTY_EDIT_FILE_COMMAND, "edit");
    this.viewFileCommand = preferences.get(PROPERTY_VIEW_FILE_COMMAND, "open");

    // The user preferences can be initialized only once
    this.initialized = true;

    if (logger.isInfoEnabled()) {
        logger.info("Initialized user preferences");
    }
}

From source file:org.pentaho.reporting.ui.datasources.jdbc.connection.JdbcConnectionDefinitionManager.java

/**
 * package-local visibility for testing purposes
 *///ww  w .j  a  v a 2s  . c  om
JdbcConnectionDefinitionManager(final Preferences externalPreferences, final String node) {
    userPreferences = externalPreferences;
    // Load the list of JNDI Sources
    try {
        final String[] childNodeNames = userPreferences.childrenNames();
        for (int i = 0; i < childNodeNames.length; i++) {
            final String name = childNodeNames[i];
            final Preferences p = userPreferences.node(name);
            final String type = p.get("type", null);
            if (type == null) {
                p.removeNode();
            } else if (type.equals("local")) {
                final Properties props = new Properties();
                if (p.nodeExists("properties")) {
                    final Preferences preferences = p.node("properties");
                    final String[] strings = preferences.keys();
                    for (int j = 0; j < strings.length; j++) {
                        final String string = strings[j];
                        final String value = preferences.get(string, null);
                        if (value != null) {
                            props.setProperty(string, value);
                        } else {
                            props.remove(string);
                        }
                    }
                }

                final DriverConnectionDefinition driverConnection = new DriverConnectionDefinition(name,
                        p.get(DRIVER_KEY, null), p.get(URL_KEY, null), p.get(USERNAME_KEY, null),
                        p.get(PASSWORD_KEY, null), p.get(HOSTNAME_KEY, null), p.get(DATABASE_NAME_KEY, null),
                        p.get(DATABASE_TYPE_KEY, null), p.get(PORT_KEY, null), props);

                connectionDefinitions.put(name, driverConnection);
            } else if (type.equals("jndi")) {
                final JndiConnectionDefinition connectionDefinition = new JndiConnectionDefinition(name,
                        p.get(JNDI_LOCATION, null), p.get(DATABASE_TYPE_KEY, null), p.get(USERNAME_KEY, null),
                        p.get(PASSWORD_KEY, null));
                connectionDefinitions.put(name, connectionDefinition);
            } else {
                p.removeNode();
            }
        }
    } catch (BackingStoreException e) {
        // The system preferences system is not working - log this as a message and use defaults
        log.warn("Could not access the user prefererences while loading the "
                + "JNDI connection information - using default JNDI connection entries", e);
    } catch (final Exception e) {
        log.warn("Configuration information was invalid.", e);
    }

    // If the connectionDefinitions is empty, add any default entries
    if (connectionDefinitions.isEmpty() && DATASOURCE_PREFERENCES_NODE.equals(node)) {
        if (userPreferences.getBoolean("sample-data-created", false) == true) {
            // only create the sample connections once, if we work on a totally fresh config.
            return;
        }
        updateSourceList(SAMPLE_DATA_JNDI_SOURCE);
        updateSourceList(SAMPLE_DATA_DRIVER_SOURCE);
        updateSourceList(SAMPLE_DATA_MEMORY_SOURCE);
        updateSourceList(LOCAL_SAMPLE_DATA_DRIVER_SOURCE);
        updateSourceList(MYSQL_SAMPLE_DATA_DRIVER_SOURCE);
        userPreferences.putBoolean("sample-data-created", true);
        try {
            userPreferences.flush();
        } catch (BackingStoreException e) {
            // ignored ..
        }
    }
}

From source file:com.jidesoft.spring.richclient.docking.JideApplicationLifecycleAdvisor.java

@Override
public void onWindowOpened(ApplicationWindow arg0) {
    super.onWindowOpened(arg0);
    if (PreferenceRegistry.instance().getPreferenceValue("general.tipOfTheDay").equals("yes")) {
        GraphicUtils.showTipOfTheDay();/*  www .j  a va 2s. c o m*/
    }

    // automatic version checking
    // get preference
    String pval = PreferenceRegistry.instance().getPreferenceValue("updates.autoCheckForNewVersion");
    if (pval == null || pval.equals("")) {
        // if preference is null, ask user if they want to activate version
        // checking
        //TODO:I18N
        final MessageDialog dlg = new MessageDialog("Automatic version check",
                "As of version 1.0.4 JOverseer comes with a mechanism to automatically check for new versions on the web site.\r\n Note that if you choose yes, JOverseer will try to connect to the internet every time upon start-up to check for a new version.\n Do you wish to activate this check?") {
            @Override
            protected Object[] getCommandGroupMembers() {
                return new Object[] { new ActionCommand("actionYes") {
                    @Override
                    protected void doExecuteCommand() {
                        PreferenceRegistry.instance().setPreferenceValue("updates.autoCheckForNewVersion",
                                "yes");
                        getDialog().dispose();
                    }
                }, new ActionCommand("actionNo") {
                    @Override
                    protected void doExecuteCommand() {
                        PreferenceRegistry.instance().setPreferenceValue("updates.autoCheckForNewVersion",
                                "no");
                        getDialog().dispose();
                    }
                } };
            }
        };
        dlg.showDialog();
    }
    // get preference value and do version checking if needed
    pval = PreferenceRegistry.instance().getPreferenceValue("updates.autoCheckForNewVersion");
    if (pval.equals("yes")) {
        // check once every week
        Preferences prefs = Preferences.userNodeForPackage(JOverseerJIDEClient.class);

        pval = prefs.get("lastVersionCheckDate", null);
        Date dt = null;
        try {
            dt = new SimpleDateFormat().parse(pval);
        } catch (Exception exc) {
            // do nothing
        }
        Calendar c = Calendar.getInstance();
        c.setTime(new Date());
        c.add(Calendar.DATE, -7);
        Date dateMinusOneWeek = c.getTime();
        if (dt == null || dateMinusOneWeek.after(dt)) {

            DefaultApplicationDescriptor descriptor = (DefaultApplicationDescriptor) Application.instance()
                    .getApplicationContext().getBean("applicationDescriptor");
            ThreepartVersion current = new ThreepartVersion(descriptor.getVersion());

            try {
                if (UpdateChecker
                        .getLatestVersion(PreferenceRegistry.instance().getPreferenceValue("updates.RSSFeed"))
                        .isLaterThan(current)) {
                    new com.middleearthgames.updater.UpdateInfo(UpdateChecker
                            .getWhatsNew(PreferenceRegistry.instance().getPreferenceValue("updates.RSSFeed")));
                }
                String str = new SimpleDateFormat().format(new Date());
                prefs.put("lastVersionCheckDate", str);
            } catch (Exception exc) {
                // do nothing
            }
        }
    }
}

From source file:de.thomasbolz.renamer.RenamerGUI.java

/**
 * Retrieves the source directory from the preferences, if not available use the user's home directory
 *
 * @return/* w  w  w .  j  ava  2  s  . co  m*/
 */
private String getSourceDirectoryFromPrefs() {
    final Preferences preferences = getPreferences();
    return preferences.get(SRC_DIR, System.getProperty("user.home"));
}

From source file:de.thomasbolz.renamer.RenamerGUI.java

/**
 * Retrieves the target directory from the preferences, if not available use the user's home directory
 *
 * @return//from ww  w  .j  a  va  2 s .  c  o  m
 */
private String getTargetDirectoryFromPrefs() {
    final Preferences preferences = getPreferences();
    return preferences.get(TARGET_DIR, System.getProperty("user.home"));
}

From source file:com.vaadin.integration.maven.wscdn.CvalChecker.java

private CvalInfo getCachedLicenseInfo(String productName) {
    Preferences p = Preferences.userNodeForPackage(CvalInfo.class);
    String json = p.get(productName, "");
    if (!json.isEmpty()) {
        try {//from   w w  w  .j  a v  a 2 s  .  c  o  m
            CvalInfo info = parseJson(json);
            if (info != null) {
                return info;
            }
        } catch (RuntimeException e) {
            try {
                p.clear();
            } catch (BackingStoreException ex) {
                Logger.getLogger(CvalChecker.class.getName()).log(Level.SEVERE, null, ex);
            }
            throw e;
        }
    }
    return null;
}

From source file:com.github.fritaly.dualcommander.TabbedPane.java

public void init(Preferences preferences) {
    Validate.notNull(preferences, "The given preferences is null");

    final int tabCount = preferences.getInt("tab.count", 1);

    for (int i = 0; i < tabCount; i++) {
        final File directory = new File(preferences.get(String.format("tab.%d.directory", i), "."));

        if (directory.exists()) {
            // Ensure the directory exists. Create a new tab
            addBrowserTab(directory);//from   w w  w.ja  va 2  s  .c  om
        } else {
            logger.warn(String.format("The directory '%s' doesn't exist", directory.getAbsolutePath()));
        }
    }

    // Ensure the tabbed pane has at least one tab
    if (getTabCount() == 0) {
        addBrowserTab();
    }
}

From source file:reaper.model.Project.java

public String projectPath() {
    Preferences prefs = Preferences.userNodeForPackage(Reaper.class);
    String path = prefs.get(PreferenceKeys.GALLERY_PATH.getKey(),
            (String) PreferenceKeys.GALLERY_PATH.getKey());
    if (!path.endsWith("/")) {
        path += "/";
    }// w w  w.  j a  v  a2 s .co m
    path += name + "/";
    return path;
}

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

/**
 *
 * @param e/*ww  w  .  java2 s  .  co  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:com.example.app.profile.ui.user.UserValueEditor.java

@Override
public void setValue(@Nullable User value) {
    super.setValue(value);

    if (isInited()) {
        User currentUser = _userDAO.getAssertedCurrentUser();

        _userPictureEditor.setValue(//ww  w  .  j av  a 2  s .  c o m
                Optional.ofNullable(value).map(User::getImage).map(FileEntityFileItem::new).orElse(null));

        if (value != null && value.getPreferredContactMethod() == ContactMethod.PhoneSms)
            _contactMethodSelector.setValue(Collections.singleton(LABEL_SEND_NOTIFICATION_TO_PHONESMS()));

        final Preferences userPref = Preferences.userRoot().node(User.LOGIN_PREF_NODE);
        final String uri = userPref != null ? userPref.get(User.LOGIN_PREF_NODE_LANDING_PAGE, null) : null;
        for (Link l : _links) {
            if (l != null && l.getURIAsString().equals(uri)) {
                _loginLandingPage.setValue(l);
                break;
            }
        }
        _contactMethodSelector.setVisible(Objects.equals(currentUser.getId(),
                Optional.ofNullable(getValue()).map(User::getId).orElse(0)));
        //This field is available when the current user is the user being edited
        // AND only to the user who has a particular membership under the Profile.
        _loginLandingPage.setVisible(
                Objects.equals(currentUser.getId(), Optional.ofNullable(getValue()).map(User::getId).orElse(0))
                        && _profileDAO.getMembershipsForUser(getValue(), null, getSession().getTimeZone())
                                .stream().map(Membership::getMembershipType)
                                .anyMatch(membershipType -> membershipType.equals(_mtp.companyAdmin())));
    }
}