java.util.prefs.NodeChangeListener Java Examples

The following examples show how to use java.util.prefs.NodeChangeListener. 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: PreferencesImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void removeNodeChangeListener(NodeChangeListener ncl) {
    try {
        super.removeNodeChangeListener(ncl);
    } catch (IllegalArgumentException e) {
        // ignore, see #143581
    }
}
 
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: ProxyPreferences.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private ProxyPreferences(ProxyPreferences parent, MemoryPreferences memoryPref, Preferences delegate) {
    this.parent = parent;
    this.delegateRoot = memoryPref;
    this.delegate = delegate == null ? memoryPref.getPreferences() : delegate;
    weakPrefListener = WeakListeners.create(PreferenceChangeListener.class, this, delegate);
    this.delegate.addPreferenceChangeListener(weakPrefListener);
    weakNodeListener = WeakListeners.create(NodeChangeListener.class, this, delegate);
    this.delegate.addNodeChangeListener(weakNodeListener);
}
 
Example #6
Source File: TestPreferences.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public void removeNodeChangeListener(NodeChangeListener nl) {
    throw new UnsupportedOperationException("Not supported yet.");
}
 
Example #7
Source File: InMemoryPreferenceNode.java    From netbeans-mmd-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public void removeNodeChangeListener(NodeChangeListener ncl) {
  this.nodeChangeListeners.remove(ncl);
}
 
Example #8
Source File: InMemoryPreferenceNode.java    From netbeans-mmd-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public void addNodeChangeListener(NodeChangeListener ncl) {
  this.nodeChangeListeners.add(ncl);
}
 
Example #9
Source File: PropertiesPreferences.java    From netbeans-mmd-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public void removeNodeChangeListener(@Nonnull final NodeChangeListener ncl) {
}
 
Example #10
Source File: PropertiesPreferences.java    From netbeans-mmd-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public void addNodeChangeListener(@Nonnull final NodeChangeListener ncl) {
}
 
Example #11
Source File: MountedPreferences.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void 	removeNodeChangeListener(NodeChangeListener ncl) {
  synchronized(nclSet) {
    super.removeNodeChangeListener(ncl);
    nclSet.remove(ncl);
  }
}
 
Example #12
Source File: MountedPreferences.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void 	addNodeChangeListener(NodeChangeListener ncl) {
  synchronized(nclSet) {
    super.addNodeChangeListener(ncl);
    nclSet.add(ncl);
  }
}
 
Example #13
Source File: ProxyPreferences.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public void removeNodeChangeListener(NodeChangeListener ncl) {
    synchronized (this) {
        nodeListeners.remove(ncl);
    }
}
 
Example #14
Source File: ProxyPreferences.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public void addNodeChangeListener(NodeChangeListener ncl) {
    synchronized (this) {
        nodeListeners.add(ncl);
    }
}
 
Example #15
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 #16
Source File: ProxyPreferencesImpl.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public void removeNodeChangeListener(NodeChangeListener ncl) {
    synchronized (tree.treeLock()) {
        nodeListeners.remove(ncl);
    }
}
 
Example #17
Source File: ProxyPreferencesImpl.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public void addNodeChangeListener(NodeChangeListener ncl) {
    synchronized (tree.treeLock()) {
        nodeListeners.add(ncl);
    }
}
 
Example #18
Source File: TestPreferences.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public void addNodeChangeListener(NodeChangeListener nl) {
    throw new UnsupportedOperationException("Not supported yet.");
}
 
Example #19
Source File: DummyPreferences.java    From snap-desktop with GNU General Public License v3.0 2 votes vote down vote up
@Override
public void addNodeChangeListener(NodeChangeListener ncl) {

}
 
Example #20
Source File: DummyPreferences.java    From snap-desktop with GNU General Public License v3.0 2 votes vote down vote up
@Override
public void removeNodeChangeListener(NodeChangeListener ncl) {

}
 
Example #21
Source File: HistoryComboBoxModelTest.java    From snap-desktop with GNU General Public License v3.0 2 votes vote down vote up
@Override
public void addNodeChangeListener(NodeChangeListener ncl) {

}
 
Example #22
Source File: HistoryComboBoxModelTest.java    From snap-desktop with GNU General Public License v3.0 2 votes vote down vote up
@Override
public void removeNodeChangeListener(NodeChangeListener ncl) {

}