java.util.prefs.NodeChangeEvent Java Examples

The following examples show how to use java.util.prefs.NodeChangeEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ProxyPreferencesImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void fireNodeEvents(List<EventBag<NodeChangeListener, NodeChangeEvent>> events) {
    if (noEvents) {
        return;
    }
    
    for(EventBag<NodeChangeListener, NodeChangeEvent> bag : events) {
        for(NodeChangeEvent event : bag.getEvents()) {
            for(NodeChangeListener l : bag.getListeners()) {
                try {
                    if ((event instanceof NodeChangeEventExt) && ((NodeChangeEventExt) event).isRemovalEvent()) {
                        l.childRemoved(event);
                    } else {
                        l.childAdded(event);
                    }
                } catch (Throwable t) {
                    LOG.log(Level.WARNING, null, t);
                }
            }
        }
    }
}
 
Example #2
Source File: MountedPreferences.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected void notifyNCL(NodeChangeEvent evt, boolean bAdded) {
  synchronized(nclSet) {
    
    for(Iterator<NodeChangeListener> it = nclSet.iterator(); it.hasNext(); ) {
      NodeChangeListener ncl = it.next();
      try {
        if(bAdded) {
          ncl.childAdded(evt);
        } else {
          ncl.childRemoved(evt);
        }
      } catch (Exception e) {
        Activator.log.warn("Failed to notify " + ncl);
      }
    }
  }
}
 
Example #3
Source File: MountedPreferences.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Mount the specified preference node as child to this node.
 *
 * @param prefs Preferences node to mount
 * @param name child name to mount the specified node as.
 *             This will override any previous child with the same
 *             name.
 */
public void mount(Preferences prefs, String name) {
  synchronized(mounts) {
    int ix;
    if(-1 != (ix = name.indexOf("/"))) {
      String n1 = name.substring(0, ix);
      String n2 = name.substring(ix+1);

      // this cast is OK since childSpi always return MountedPreferences
      ((MountedPreferences)node(n1)).mount(prefs, n2);
      NodeChangeEvent evt = new NodeChangeEvent(this, prefs);
      notifyNCL(evt, true);
    } else {
      mounts.put(name, prefs);
    }
  }
}
 
Example #4
Source File: ProxyPreferencesImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void sync() throws BackingStoreException {
    ArrayList<EventBag<PreferenceChangeListener, PreferenceChangeEvent>> prefEvents = new ArrayList<EventBag<PreferenceChangeListener, PreferenceChangeEvent>>();
    ArrayList<EventBag<NodeChangeListener, NodeChangeEvent>> nodeEvents = new ArrayList<EventBag<NodeChangeListener, NodeChangeEvent>>();

    synchronized (tree.treeLock()) {
        _sync(prefEvents, nodeEvents);
    }

    fireNodeEvents(nodeEvents);
    firePrefEvents(prefEvents);
}
 
Example #5
Source File: MountedPreferences.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Unmount a child node from this node.
 *
 * @param name name of node to unmount. If the node does not
 *             exists, does nothing.
 */
public void unmount(String name) {
  synchronized(mounts) {
    Preferences prefs = mounts.get(name);
    mounts.remove(name);
    if(prefs != null) {
      NodeChangeEvent evt = new NodeChangeEvent(this, prefs);
      notifyNCL(evt, false);
    }
  }
}
 
Example #6
Source File: ProxyPreferencesImpl.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private ProxyPreferencesImpl node(String pathName, boolean create, List<EventBag<NodeChangeListener, NodeChangeEvent>> events) {
    if (pathName.length() > 0 && pathName.charAt(0) == '/') { //NOI18N
        // absolute path, if this is not the root then find the root
        // and pass the call to it
        if (parent != null) {
            Preferences root = this;
            while (root.parent() != null) {
                root = root.parent();
            }
            return ((ProxyPreferencesImpl) root).node(pathName, create, events);
        } else {
            // this is the root, change the pathName to a relative path and proceed
            pathName = pathName.substring(1);
        }
    }

    if (pathName.length() > 0) {
        String childName;
        String pathFromChild;

        int idx = pathName.indexOf('/'); //NOI18N
        if (idx != -1) {
            childName = pathName.substring(0, idx);
            pathFromChild = pathName.substring(idx + 1);
        } else {
            childName = pathName;
            pathFromChild = null;
        }

        ProxyPreferencesImpl child = children.get(childName);
        if (child == null) {
            if (removedChildren.contains(childName) && !create) {
                // this child has been removed
                return null;
            }
            
            Preferences childDelegate = null;
            try {
                if (delegate != null && delegate.nodeExists(childName)) {
                    childDelegate = delegate.node(childName);
                }
            } catch (BackingStoreException bse) {
                // ignore
            }

            if (childDelegate != null || create) {
                child = tree.get(this, childName, childDelegate);
                children.put(childName, child);
                removedChildren.remove(childName);

                // fire event if we really created the new child node
                if (childDelegate == null) {
                    EventBag<NodeChangeListener, NodeChangeEvent> bag = new EventBag<NodeChangeListener, NodeChangeEvent>();
                    bag.addListeners(nodeListeners);
                    bag.addEvent(new NodeChangeEventExt(this, child, false));
                    events.add(bag);
                }
            } else {
                // childDelegate == null && !create
                return null;
            }
        } else {
            assert !child.removed;
        }

        return pathFromChild != null ? child.node(pathFromChild, create, events) : child;
    } else {
        return this;
    }
}
 
Example #7
Source File: FormattingPanelController.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void childAdded(NodeChangeEvent evt) {
    try { callback.call(); } catch (Exception e) { /* ignore */ }
}
 
Example #8
Source File: FormattingPanelController.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void childRemoved(NodeChangeEvent evt) {
    try { callback.call(); } catch (Exception e) { /* ignore */ }
}
 
Example #9
Source File: OnSaveTabPanelController.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void childAdded(NodeChangeEvent evt) {
    try { callback.call(); } catch (Exception e) { /* ignore */ }
}
 
Example #10
Source File: OnSaveTabPanelController.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void childRemoved(NodeChangeEvent evt) {
    try { callback.call(); } catch (Exception e) { /* ignore */ }
}
 
Example #11
Source File: CodeCompletionOptionsPanelController.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void childAdded(NodeChangeEvent evt) {
    try { callback.call(); } catch (Exception e) { /* ignore */ }
}
 
Example #12
Source File: CodeCompletionOptionsPanelController.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void childRemoved(NodeChangeEvent evt) {
    try { callback.call(); } catch (Exception e) { /* ignore */ }
}