Hi there.
I have a problem which was often discussed in this newsgroup, but I
couldn't manage, sorry. I use GEF 3.1 for a diagram editor which can
create nested nodes and connections that can connect arbitrary nodes
as shown in the example attachment, situation a.
I'd like to filter out, for example, the inner node X in the diagram
and I want also filter out the connection y. This is shown in
situation b. in the attachement.
Unfortunately it results something like in situation c. with a
dangling connection but the node is filtered out correctly.
The code I use is the following in the edit part of the node.
I have a propertyChange method which listens for specific events.
When changing the visibility property of the node, the
refreshSourceConncetions() and refreshNodes() are called.
public void propertyChange(PropertyChangeEvent evt) {
String prop = evt.getPropertyName();
if (ModelElement.VISIBILITY_PROP.equals(prop)) {
refreshChildren();
refreshSourceConnections();
} else if (NodeContainer.ZOOMED_PROP.equals(prop)) {
refreshChildren();
refreshSourceConnections();
refreshVisuals();
} else if (Node.SIZE_PROP.equals(prop) ||
Node.LOCATION_PROP.equals(prop)) {
refreshVisuals();
} else if (Node.NAME_PROP.equals(prop)) {
....
}
}
I have overridden the getModelChildren() and the
getModelSourceConnections() which provide now a filtered list of all
visible nodes and visible source connections respectively.
Somehow like this:
protected List getModelChildren() {
FilteredArrayList list = new
FilteredArrayList(
(ArrayList)getCastedObjectModel().getChildren());
list.setFilter(new ModelElementVisibilityFilter());
return list;
}
protected List getModelSourceConnections() {
FilteredArrayList list = new
FilteredArrayList(
(ArrayList)getCastedModel().getSourceConnections());
list.setFilter(new ModelElementVisibilityFilter());
return list;
}
The used classes which provide the filter service work correctly and
the visible properties of the corresponding connections and nodes
are set properly (ie. to false) before calling the methods
refreshChildren() and refreshConnections().
The filtering of the nodes works, in contrast to connections which
dangle somehow after the filter operation. When debugging GEF, it
looks as if the edit parts of the connection are thrown away in the
refreshSourceConnections() method, but somehow there are still some
remaining artifacts of them.
What's wrong?
thanx & regards
Silvio
------------------------------------------------------------------------