Error adding/removing AsynchChildren
Javier Ortiz <[email protected]>
| Newsgroups | gmane.comp.java.netbeans.modules.openide.devel |
|---|---|
| Message-ID | <CAP3=pbNtz=tyLfycgqRKfPCdC7-qbJYAjPMQxqOc64f7d8MO3g@mail.gmail.com> |
I have ChildFactory fueled by a Lookup to provide the elements to display.
It works fine, but as I add/remove items from the list I get this type of
error:
SEVERE [org.openide.util.RequestProcessor]: Error in RequestProcessor
org.openide.nodes.AsynchChildren
java.lang.AssertionError: map.size()=3 entries.size()=2
Is there a way to prevent this? I tried avoiding to make the refresh
immediate but didn't help.
Here's the ChildFactory if it helps:
public class PlayerChildFactory extends ChildFactory.Detachable<RPObject>
implements LookupListener {
private static final Logger LOG
= Logger.getLogger(PlayerChildFactory.class.getSimpleName());
protected final InstanceContent context = new InstanceContent();
protected final Lookup localLookup = new AbstractLookup(getContext());
private Lookup.Result<RPObject> result;
@Override
protected void addNotify() {
result = getLocalLookup().lookupResult(RPObject.class);
result.addLookupListener(this);
}
@Override
protected void removeNotify() {
result.removeLookupListener(this);
result = null;
}
@Override
protected boolean createKeys(List<RPObject> toPopulate) {
for (RPObject rs : result.allInstances()) {
toPopulate.add(rs);
}
return true;
}
@Override
protected Node createNodeForKey(RPObject w) {
try {
return new PlayerNode(w);
} catch (IntrospectionException ex) {
Exceptions.printStackTrace(ex);
AbstractNode node = new AbstractNode(Children.LEAF);
node.setDisplayName(Tool.extractName(w));
return node;
}
}
@Override
public void resultChanged(LookupEvent ev) {
refresh(true);
}
/**
* @return the context
*/
public InstanceContent getContext() {
return context;
}
/**
* @return the localLookup
*/
public Lookup getLocalLookup() {
return localLookup;
}}
You can see this question in Stackoverflow
<http://stackoverflow.com/questions/36583438/error-adding-removing-asynchchildren>.