Java 类java.util.prefs.NodeChangeListener 实例源码

项目:incubator-netbeans    文件:ProxyPreferencesImpl.java   
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);
                }
            }
        }
    }
}
项目:cross-preferences    文件:PreferencesTestSupport.java   
protected ScheduledFuture<?> testNodeAdded(final NodeChangeListener listener,
                                           final Preferences parent, final String childName, final int count) {
    final ArgumentCaptor<NodeChangeEvent> captor = ArgumentCaptor.forClass(NodeChangeEvent.class);

    final Runnable task = new Runnable() {
        @Override public void run() {
            verify(listener, times(count)).childAdded(captor.capture());
            final NodeChangeEvent event = captor.getValue();

            assertEquals(event.getParent(), parent);
            assertEquals(event.getChild().name(), childName);
        }
    };

    return schedule(task);
}
项目:cross-preferences    文件:PreferencesTestSupport.java   
protected ScheduledFuture<?> testNodeRemoved(final NodeChangeListener listener,
                                             final Preferences parent, final String childName, final int count) {
    final ArgumentCaptor<NodeChangeEvent> captor = ArgumentCaptor.forClass(NodeChangeEvent.class);

    final Runnable task = new Runnable() {
        @Override public void run() {
            verify(listener, times(count)).childRemoved(captor.capture());
            final NodeChangeEvent event = captor.getValue();

            assertEquals(event.getParent(), parent);
            assertEquals(event.getChild().name(), childName);
        }
    };

    return schedule(task);

}
项目:cross-preferences    文件:PreferencesAcceptanceTest.java   
@Test(dataProvider = "chroot", groups = {"prefs", "hierarchy", "notifications"},
        dependsOnGroups = "factory", timeOut = 1000L)
public void shouldTriggerNodeAdded(Preferences prefs) throws Exception {
    final Preferences watched = prefs.node("watched");
    final NodeChangeListener listener = nodeListener(watched);
    final Preferences n1 = watched.node("n1");
    testNodeAdded(listener, watched, n1.name(), 1).get();
    watched.node("n1"); // not a new node, so the invocation count should stay the same
    prefs.node("n0");   // shouldn't trigger anything for our listener, as it's a parent event
    testNodeAdded(listener, watched, n1.name(), 1).get();

    final Preferences n2 = watched.node("n2");
    testNodeAdded(listener, watched, n2.name(), 2).get();

    watched.node("n3/nested");
    testNodeAdded(listener, watched, "n3", 3).get();
}
项目:cross-preferences    文件:PreferencesAcceptanceTest.java   
@Test(dataProvider = "chroot", groups = {"prefs", "hierarchy", "notifications"},
        dependsOnMethods = "shouldTriggerNodeAdded", timeOut = 1000L)
public void shouldTriggerNodeRemoved(Preferences prefs) throws Exception {
    final Preferences watched = prefs.node("watched");
    final NodeChangeListener listener = nodeListener(watched);

    watched.node("n1").removeNode();
    testNodeRemoved(listener, watched, "n1", 1).get();

    watched.node("n2").removeNode();
    testNodeRemoved(listener, watched, "n2", 2).get();

    watched.node("n3/nested").removeNode();
    testNodeRemoved(listener, watched, "n2", 2).get();

    watched.node("n3").removeNode();
    testNodeRemoved(listener, watched, "n3", 3).get();
}
项目:In-the-Box-Fork    文件:AbstractPreferencesTest.java   
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "addNodeChangeListener",
    args = {java.util.prefs.NodeChangeListener.class}
)
public void testAddNodeChangeListener() throws BackingStoreException {
    MockNodeChangeListener mncl = new MockNodeChangeListener();
    parent.addNodeChangeListener(mncl);
    pref.node("test");
    pref.flush();
    parent.flush();
    assertFalse(mncl.isAdded());
    assertFalse(mncl.isRemoved());
    pref.removeNode();
    parent.flush();
    assertFalse(mncl.isAdded());
    assertTrue(mncl.isRemoved());
    parent.node("new node");
    parent.flush();
    assertTrue(mncl.isAdded());
    assertTrue(mncl.isRemoved());
}
项目:In-the-Box-Fork    文件:AbstractPreferencesTest.java   
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "removeNodeChangeListener",
    args = {java.util.prefs.NodeChangeListener.class}
)
public void testRemoveNodeChangeListener() throws BackingStoreException {
    MockNodeChangeListener mncl = new MockNodeChangeListener();
    parent.addNodeChangeListener(mncl);
    pref.node("test");
    pref.flush();
    parent.flush();
    assertFalse(mncl.isAdded());
    assertFalse(mncl.isRemoved());
    parent.removeNodeChangeListener(mncl);
    pref.removeNode();
    parent.flush();
    assertFalse(mncl.isAdded());
    assertFalse(mncl.isRemoved());
    parent.node("new node");
    parent.flush();
    assertFalse(mncl.isAdded());
    assertFalse(mncl.isRemoved());
}
项目:incubator-netbeans    文件:PreferencesImpl.java   
@Override
public void removeNodeChangeListener(NodeChangeListener ncl) {
    try {
        super.removeNodeChangeListener(ncl);
    } catch (IllegalArgumentException e) {
        // ignore, see #143581
    }
}
项目:incubator-netbeans    文件:ProxyPreferencesImpl.java   
@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);
}
项目:incubator-netbeans    文件:ProxyPreferences.java   
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);
}
项目:cross-preferences    文件:PreferencesAcceptanceTest.java   
@Test(dataProvider = "chroot", groups = {"prefs", "concurrency"},
        dependsOnGroups = {"hierarchy", "kv"}, invocationCount = 5, threadPoolSize = 3, timeOut = 3000L)
public void concurrencyTest(Preferences prefs) throws Exception {

    final Preferences child = prefs.node(UUID.randomUUID().toString());
    final String key = UUID.randomUUID().toString();

    final NodeChangeListener nodeListener = nodeListener(child);
    final PreferenceChangeListener prefListener = prefListener(child);

    prefs.putInt(key, 12);
    final Preferences grandson = child.node("grandson");
    ScheduledFuture<?> nodeAdded = testNodeAdded(nodeListener, child, grandson.name(), 1);

    child.putBoolean(key, true);
    ScheduledFuture<?> prefSet = testPrefChange(prefListener, child, key, "true", 1);
    assertEquals(prefs.getInt(key, 0), 12);
    assertTrue(child.getBoolean(key, false));

    grandson.removeNode();
    ScheduledFuture<?> nodeRemoved = testNodeRemoved(nodeListener, child, grandson.name(), 1);

    prefSet.get();

    child.remove(key);
    child.removeNode();

    assertEquals(prefs.getInt(key, 0), 12);

    nodeAdded.get();
    nodeRemoved.get();
    testPrefChange(prefListener, child, key, null, 2).get();

}
项目:cross-preferences    文件:CrossPreferencesAcceptanceTest.java   
@Test(dataProvider = "chroot", groups = {"prefs", "backing-store"}, dependsOnGroups = {"hierarchy", "kv"})
    public void shouldSyncNodeChanges(Preferences prefs) throws Exception {
        assertFalse(prefs.nodeExists("x"));
        assertFalse(childExistsInBackingStore(prefs, "x"));

        final Preferences x = prefs.node("x");
//        prefs.flush();
        assertTrue(childExistsInBackingStore(prefs, "x"));

        final NodeChangeListener listener = nodeListener(x);
        createInBackingStore(x, "y");
        assertTrue(childExistsInBackingStore(x, "y"));

        final ScheduledFuture<?> nodeAdded = testNodeAdded(listener, x, "y", 1);
//        prefs.sync();
        assertTrue(x.nodeExists("y"));
        nodeAdded.get();

        assertTrue(x.nodeExists("y"));
        assertTrue(childExistsInBackingStore(x, "y"));
        removeChildFromBackingStore(x, "y");
        assertFalse(childExistsInBackingStore(x, "y"));

        final ScheduledFuture<?> nodeRemoved = testNodeRemoved(listener, x, "y", 1);
//        prefs.sync();
        assertFalse(x.nodeExists("y"));
        nodeRemoved.get();

        x.removeNode();
//        prefs.flush();
        assertFalse(childExistsInBackingStore(prefs, "x"));
    }
项目:incubator-netbeans    文件:ProxyPreferencesImpl.java   
@Override
public void addNodeChangeListener(NodeChangeListener ncl) {
    synchronized (tree.treeLock()) {
        nodeListeners.add(ncl);
    }
}
项目:incubator-netbeans    文件:ProxyPreferencesImpl.java   
@Override
public void removeNodeChangeListener(NodeChangeListener ncl) {
    synchronized (tree.treeLock()) {
        nodeListeners.remove(ncl);
    }
}
项目:incubator-netbeans    文件:ProxyPreferencesImpl.java   
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;
    }
}
项目:incubator-netbeans    文件:ProxyPreferences.java   
@Override
public void addNodeChangeListener(NodeChangeListener ncl) {
    synchronized (this) {
        nodeListeners.add(ncl);
    }
}
项目:incubator-netbeans    文件:ProxyPreferences.java   
@Override
public void removeNodeChangeListener(NodeChangeListener ncl) {
    synchronized (this) {
        nodeListeners.remove(ncl);
    }
}
项目:netbeans-mmd-plugin    文件:PropertiesPreferences.java   
@Override
public void addNodeChangeListener(@Nonnull final NodeChangeListener ncl) {
}
项目:netbeans-mmd-plugin    文件:PropertiesPreferences.java   
@Override
public void removeNodeChangeListener(@Nonnull final NodeChangeListener ncl) {
}
项目:netbeans-mmd-plugin    文件:InMemoryPreferenceNode.java   
@Override public void addNodeChangeListener(NodeChangeListener ncl) {
  this.nodeChangeListeners.add(ncl);
}
项目:netbeans-mmd-plugin    文件:InMemoryPreferenceNode.java   
@Override public void removeNodeChangeListener(NodeChangeListener ncl) {
  this.nodeChangeListeners.remove(ncl);
}
项目:PanBox    文件:PreferencesRegistryWrapper.java   
@Override
public void addNodeChangeListener( NodeChangeListener ncl )
{
    throw new UnsupportedOperationException( "Method 'addNodeChangeListener' has not been implemented yet." );
}
项目:PanBox    文件:PreferencesRegistryWrapper.java   
@Override
public void removeNodeChangeListener( NodeChangeListener ncl )
{
    throw new UnsupportedOperationException( "Method 'removeNodeChangeListener' has not been implemented yet." );
}
项目:cross-preferences    文件:PreferencesTestSupport.java   
protected NodeChangeListener nodeListener(Preferences prefs) {
    final NodeChangeListener listener = mock(NodeChangeListener.class);
    prefs.addNodeChangeListener(listener);
    return listener;
}
项目:greenpepper3    文件:Preferences.java   
@Override
public void addNodeChangeListener(NodeChangeListener arg0){ /* TODO Auto-generated method stub */ }
项目:greenpepper3    文件:Preferences.java   
@Override
public void removeNodeChangeListener(NodeChangeListener arg0){ /* TODO Auto-generated method stub */ }
项目:Geokuk    文件:MyPreferences.java   
@Override
public void addNodeChangeListener(NodeChangeListener aArg0) {
  pref.addNodeChangeListener(aArg0);
}
项目:Geokuk    文件:MyPreferences.java   
@Override
public void removeNodeChangeListener(NodeChangeListener aArg0) {
  pref.removeNodeChangeListener(aArg0);
}
项目:itchy    文件:AutoFlushPreferences.java   
@Override
public void addNodeChangeListener( NodeChangeListener ncl )
{
    this.wrapped.addNodeChangeListener(ncl);
}
项目:itchy    文件:AutoFlushPreferences.java   
@Override
public void removeNodeChangeListener( NodeChangeListener ncl )
{
    this.wrapped.removeNodeChangeListener(ncl);
}
项目:In-the-Box-Fork    文件:PreferencesTest.java   
@Override
public void addNodeChangeListener(NodeChangeListener ncl) {

}
项目:In-the-Box-Fork    文件:PreferencesTest.java   
@Override
public void removeNodeChangeListener(NodeChangeListener ncl) {

}
项目:cn1    文件:PreferencesTest.java   
@Override
public void addNodeChangeListener(NodeChangeListener ncl) {

}
项目:cn1    文件:PreferencesTest.java   
@Override
public void removeNodeChangeListener(NodeChangeListener ncl) {

}
项目:snap-desktop    文件:DummyPreferences.java   
@Override
public void addNodeChangeListener(NodeChangeListener ncl) {

}
项目:snap-desktop    文件:DummyPreferences.java   
@Override
public void removeNodeChangeListener(NodeChangeListener ncl) {

}
项目:snap-desktop    文件:HistoryComboBoxModelTest.java   
@Override
public void addNodeChangeListener(NodeChangeListener ncl) {

}
项目:snap-desktop    文件:HistoryComboBoxModelTest.java   
@Override
public void removeNodeChangeListener(NodeChangeListener ncl) {

}
项目:freeVM    文件:PreferencesTest.java   
public void addNodeChangeListener(NodeChangeListener ncl) {

        }
项目:freeVM    文件:PreferencesTest.java   
public void removeNodeChangeListener(NodeChangeListener ncl) {

        }