Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to reliably remove Connection figures, whose EditParts are orphans, on removal of respective model object?
    primarykey
    data
    text
    <p>Assume the following simplified EMF model structure:</p> <pre><code> Graph / \ Node Edge </code></pre> <p>In my GEF editor, the <code>EditPart</code>s are organized as follows.</p> <p><strong>GraphEditPart</strong> (Figure = FreeformLayer) excerpt</p> <pre><code>@Override protected List&lt;EObject&gt; getModelChildren() { List&lt;EObject&gt; childrenList = new ArrayList&lt;EObject&gt;(); Graph graph = (Graph) getModel(); childrenList.addAll(graph.getNodes()); return childrenList; } </code></pre> <p><strong>NodeEditPart</strong> (Figure = extending <code>Figure</code>) excerpt (<em>also showing how <code>Edges</code> for which a <code>Node</code>is source or target are got</em>)</p> <pre><code>@Override protected List&lt;Edge&gt; getModelSourceConnections() { Node node = (Node) getModel(); Graph graph = node.getGraph(); String nodeId = node.getId(); List&lt;Edge&gt; sourceList = new ArrayList&lt;Edge&gt;(); if (graph != null) sourceList.addAll(graph.getOutEdges(nodeId)); return sourceList; } @Override protected List&lt;Edge&gt; getModelTargetConnections() { // Same principle as getModelSourceConnections } </code></pre> <p><strong>Editor class</strong> excerpt (in case it matters)</p> <pre><code>@Override protected void initializeGraphicalViewer() { super.initializeGraphicalViewer(); GraphicalViewer viewer = getGraphicalViewer(); viewer.setContents(graph); ScalableFreeformRootEditPart root = (ScalableFreeformRootEditPart) viewer.getRootEditPart(); ConnectionLayer connLayer = (ConnectionLayer) root.getLayer(LayerConstants.CONNECTION_LAYER); GraphicalEditPart contentEditPart = (GraphicalEditPart) root.getContents(); ShortestPathConnectionRouter shortestPathConnectionRouter = new ShortestPathConnectionRouter(contentEditPart.getFigure()); connLayer.setConnectionRouter(shortestPathConnectionRouter); } </code></pre> <p>All <code>EditPart</code>s have their own adapter (extending <code>org.eclipse.emf.ecore.util.EContentAdapter</code> or implementing <code>org.eclipse.emf.common.notify.Adapter</code>).</p> <p>This results in an <code>EditPart</code> structure, where <code>NodeEditPart</code>s are children of the <code>GraphEditPart</code>, and <strong><code>EdgeEditPart</code>s are orphans</strong>, i.e., they have no <code>parent</code>. Consequentially, I've had difficulties refreshing figures whenever <code>Edge</code>s got added or deleted. </p> <p>I've managed to make the update work when I <em>added</em> an <code>Edge</code> by doing an expensive iteration in the <code>GraphAdapter</code> (which is notified as a newly created <code>Edge</code> must be registered on the <code>Graph</code> (<code>newEdge.setGraph(graph)</code>):</p> <pre><code>if (notification.getOldValue() == null &amp;&amp; notification.getNewValue() instanceof Edge) { for (Object ep : getChildren()) { if (ep instanceof NodeEditPart) { // There are in fact other EditParts as well Graph graph = (Graph) getModel(); NodeEditPart nep = (NodeEditPart) ep; Node n = (Node) nep.getModel(); if (graph.getOutEdges(n.getSId()).contains(notification.getNewValue()) || graph.getInEdges(n.getSId()).contains(notification.getNewValue())) nep.refresh(); } </code></pre> <p>[<strong>Note:</strong> If - by the way - you can think of any better way of doing this, feel free to hit me up with your solution!]</p> <h1>Problem</h1> <p>I am unable to reliably remove the <code>Edge</code> figure from the editor when deleting the <code>Edge</code> model object! Sometimes it works, sometimes it doesn't.</p> <p>I guess the unreliability might have to do with the fact that <strong>(a)</strong> my real life model has three layers of abstraction, and <strong>(b)</strong> that different EMF <code>Adapter</code>s don't always recognize changes in the same temporal order (?).</p> <p><code>execute()</code> from <code>EdgeDeleteCommand</code> simply calls <code>edge.setGraph(null)</code>, which triggers EMF to clean up after itself (i.e., model elements that aren't connected to the graph are removed from the model).</p> <p>How can I reliably remove <code>Edge</code>s' figures when deleting the respective model object, when the respective <code>EditPart</code> is an orphan?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload