Example usage for java.util.prefs Preferences removeNode

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

Introduction

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

Prototype

public abstract void removeNode() throws BackingStoreException;

Source Link

Document

Removes this preference node and all of its descendants, invalidating any preferences contained in the removed nodes.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    boolean exists = Preferences.userRoot().nodeExists("/yourValue"); // false

    Preferences.userRoot().node("/yourValue");

    exists = Preferences.userRoot().nodeExists("/yourValue"); // true

    Preferences prefs = Preferences.userRoot().node("/yourValue");
    prefs.removeNode();

    // exists = prefs.nodeExists("/yourValue");

    exists = prefs.nodeExists(""); // false
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    boolean exists = Preferences.userRoot().nodeExists("/yourValue");
    if (!exists) {
        Preferences prefs = Preferences.userRoot().node("/yourValue");
        prefs.removeNode();
        // prefs.removeNode();
    }// w  w  w  .  j  ava2s  . c o m
    Preferences prefs = Preferences.userRoot().node("/yourValue/child");
    exists = Preferences.userRoot().nodeExists("/yourValue");
    exists = Preferences.userRoot().nodeExists("/yourValue/child");

    Preferences.userRoot().node("/yourValue").removeNode();

    exists = Preferences.userRoot().nodeExists("/yourValue");
    exists = Preferences.userRoot().nodeExists("/yourValue/child");
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    boolean exists = Preferences.userRoot().nodeExists("/yourValue"); // false
    if (!exists) {
        Preferences prefs = Preferences.userRoot().node("/yourValue");
        prefs.removeNode();
        // prefs.removeNode();
    }/*from   w w  w .  ja v a 2 s  . co  m*/
    Preferences prefs = Preferences.userRoot().node("/yourValue/child");
    exists = Preferences.userRoot().nodeExists("/yourValue"); // true
    exists = Preferences.userRoot().nodeExists("/yourValue/child"); // true

    Preferences.userRoot().node("/yourValue").removeNode();

    exists = Preferences.userRoot().nodeExists("/yourValue"); // false
    exists = Preferences.userRoot().nodeExists("/yourValue/child"); // false
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Preferences prefs = Preferences.userNodeForPackage(String.class);

    prefs.addNodeChangeListener(new NodeChangeListener() {
        public void childAdded(NodeChangeEvent evt) {
            Preferences parent = evt.getParent();
            Preferences child = evt.getChild();
        }/*w  w  w .  j  a v a2  s .c  o  m*/

        public void childRemoved(NodeChangeEvent evt) {
            Preferences parent = evt.getParent();
            Preferences child = evt.getChild();
        }
    });
    Preferences child = prefs.node("new node");
    child.removeNode();
    prefs.removeNode();
}

From source file:de.tbuchloh.kiskis.KisKis.java

private static void resetPreferences() {
    try {//from w  w  w  .j  a v a2s . com
        final Preferences p = Preferences.userNodeForPackage(KisKis.class);
        p.removeNode();
        p.flush();

        if (PREF_FILE.exists()) {
            PREF_FILE.delete();
        }
        System.out.println("All preferences for package '" + KisKis.class.getPackage().getName()
                + "' were removed!\nYou can restart the application now!");
    } catch (final BackingStoreException e) {
        throw new Error(e);
    }
}

From source file:de.tbuchloh.kiskis.gui.common.Application.java

/**
 * @param prefs//from w w  w. j a  v  a 2s  . c om
 *            is the location to store the program information
 * @param list
 *            is a list of Program objects
 */
public static void storePrograms(final Preferences prefs, final Collection list) {
    Preferences n = prefs.node(Settings.K_URL_ALLPROGS_NODE);
    try {
        n.removeNode();
    } catch (final BackingStoreException e) {
        throw new Error(e);
    }

    n = prefs.node(Settings.K_URL_ALLPROGS_NODE);
    int cnt = 0;
    for (final Iterator i = list.iterator(); i.hasNext();) {
        final Program p = (Program) i.next();
        final Preferences child = n.node(String.valueOf(cnt++));
        child.put(Settings.K_URL_PROG_PREFIX, p.getUrlRegex());
        child.put(Settings.K_URL_PROG_CMD, p.getCommand());
        LOG.debug("storing " + p); //$NON-NLS-1$
    }
    try {
        n.flush();
    } catch (final BackingStoreException e1) {
        throw new Error(e1);
    }
}

From source file:de.tbuchloh.kiskis.util.Settings.java

public static Preferences initPreferences() {
    final Preferences n = Preferences.userNodeForPackage(Settings.class);
    final String newVersion = BuildProperties.getVersion();
    final String previousVersion = n.get(K_PROGRAM_VERSION, newVersion);

    if (LOG.isDebugEnabled()) {
        LOG.debug(String.format("oldVersion=%1$s, newVersion=%2$s", previousVersion, newVersion));
    }/*  w  w  w  .  jav a 2 s  .c  om*/

    if (!VersionTools.isCompatible(previousVersion, newVersion)) {
        LOG.debug("Versions not compatible! Recreating preference node for version=" + newVersion);
        try {
            n.removeNode();
        } catch (final BackingStoreException e) {
            LOG.error("Could not remove preference node", e);
        }

        final Preferences newN = Preferences.userNodeForPackage(Settings.class);
        newN.put(K_PROGRAM_VERSION, newVersion);
        return newN;
    }

    LOG.debug("Preferences seem to be compatible");
    return n;
}

From source file:org.pdfsam.ui.DefaultStageService.java

public void clear() {
    Preferences prefs = Preferences.userRoot().node(STAGE_PATH);
    try {//from w ww.  ja  va 2  s.  c o  m
        prefs.removeNode();
        prefs.flush();
    } catch (BackingStoreException e) {
        LOG.error("Unable to clear stage status", e);
    }
}

From source file:org.pdfsam.news.DefaultNewsService.java

public void clear() {
    Preferences prefs = Preferences.userRoot().node(NEWS_PATH);
    try {//from  w  ww .j  a  v  a  2s . com
        prefs.removeNode();
        prefs.flush();
    } catch (BackingStoreException e) {
        LOG.error("Unable to clear latest news store", e);
    }
}

From source file:org.pdfsam.ui.StatefullPreferencesStageService.java

void clearStageStatus() {
    Preferences prefs = Preferences.userRoot().node(STAGE_PATH);
    try {/*from   www  .  j  a v  a2  s. c o m*/
        prefs.removeNode();
        prefs.flush();
    } catch (BackingStoreException e) {
        LOG.error("Unable to clear stage status", e);
    }
}