Problem due to commit 4364ec2 (EmfService.isisObjectAlive) [message #1720316] |
Sat, 16 January 2016 21:11 |
Hernan Gonzalez Messages: 188 Registered: October 2010 Location: Buenos Aires, Argentina |
Senior Member |
|
|
I recently merged latest Graphiti master tree (2015-12-22) with my own sources, and experienced a problem in my graphical editor.
After a good deal of researching, I found that the culprit was in commit 4364ec2 (2015-10-15), specifically in the modification of EmfService.isisObjectAlive method, that was proposed here
https://bugs.eclipse.org/bugs/show_bug.cgi?id=423018#c11
"If it has no side effect elsewhere"... Well, for me, it had.
I had a method that dynamically adds/removes a child GA, from a parent. This occurs in the context of some XXXCustomFeature.execute() call, and it's followed by a layoutPictogramElement() and an editor refresh
The problem is that now the "remove" does not work. It basically does this:
Ellipse circle = null;
for (GraphicsAlgorithm ga : parentGa.getGraphicsAlgorithmChildren()) {
if (ga instanceof Ellipse) {
circle = (Ellipse) ga;
break;
}
}
if (circle != null)
parentGa.getGraphicsAlgorithmChildren().remove(circle);
But the removed GA is still shown. The problem is fixed if I revert to the old version, and consider an EObject "not alive" if its eResource is null.
public boolean isObjectAlive(EObject obj) {
return obj != null && obj.eResource() != null;
}
I'm not sure of the internals, and what is exactly the concept of "Alive Object". I see that when I add the GA the method is not called, and when I delete it it's called twice (4 times if I return "alive"), I copy below the stacktraces.
Regards
Hernan
--------------
Thread [main] (Suspended (breakpoint at line 38 in EmfService))
owns: GFWorkspaceCommandStackImpl (id=113)
EmfService.isObjectAlive(EObject) line: 38
AnchorContainerDelegate(PictogramElementDelegate).isRefreshPossible(PictogramElement) line: 1203
AnchorContainerDelegate(PictogramElementDelegate).refreshFigureForEditPart() line: 356
ShapeEditPart.refreshVisuals() line: 704
ShapeEditPart(AbstractEditPart).refresh() line: 725
ShapeEditPart(AbstractGraphicalEditPart).refresh() line: 644
ShapeEditPart.refresh() line: 596
AnchorContainerDelegate(PictogramElementDelegate).refreshEditPartsForModelChildrenAndSourceConnections(EditPart) line: 319
ContainerShapeEditPart(ShapeEditPart).refreshChildren() line: 685
ContainerShapeEditPart(AbstractEditPart).refresh() line: 726
ContainerShapeEditPart(AbstractGraphicalEditPart).refresh() line: 644
ContainerShapeEditPart(ShapeEditPart).refresh() line: 596
AnchorContainerDelegate(PictogramElementDelegate).refreshEditPartsForModelChildrenAndSourceConnections(EditPart) line: 319
DiagramEditPart(ShapeEditPart).refreshChildren() line: 685
DiagramEditPart(AbstractEditPart).refresh() line: 726
DiagramEditPart(AbstractGraphicalEditPart).refresh() line: 644
DiagramEditPart(ShapeEditPart).refresh() line: 596
DiagramEditPart.refresh() line: 189
...
Thread [main] (Suspended (breakpoint at line 38 in EmfService))
owns: EMFOperationTransaction (id=631)
owns: GFWorkspaceCommandStackImpl (id=113)
EmfService.isObjectAlive(EObject) line: 38
DiagramChangeListener.resourceSetChanged(ResourceSetChangeEvent) line: 116
TransactionalEditingDomainImpl$1.run() line: 781
TransactionalEditingDomainImpl.runExclusive(Runnable) line: 328
TransactionalEditingDomainImpl.postcommit(InternalTransaction) line: 771
TransactionalEditingDomainImpl.deactivate(InternalTransaction) line: 543
EMFOperationTransaction(TransactionImpl).close() line: 712
EMFOperationTransaction(TransactionImpl).commit() line: 474
EMFCommandOperation(AbstractEMFOperation).execute(IProgressMonitor, IAdaptable) line: 155
DefaultOperationHistory.execute(IUndoableOperation, IProgressMonitor, IAdaptable) line: 516
GFWorkspaceCommandStackImpl(WorkspaceCommandStackImpl).doExecute(Command, Map<?,?>) line: 208
GFWorkspaceCommandStackImpl(AbstractTransactionalCommandStack).execute(Command, Map<?,?>) line: 165
GFWorkspaceCommandStackImpl.execute(Command, Map<?,?>) line: 96
GFCommandStack.execute(Command) line: 138
CustomAction.executeOnCommandStack(ICommand) line: 65
CustomAction.run() line: 60
CustomAction(Action).runWithEvent(Event) line: 473
ActionContributionItem.handleWidgetSelection(Event, boolean) line: 595
...
|
|
|
|
|
Re: Problem due to commit 4364ec2 (EmfService.isisObjectAlive) [message #1724625 is a reply to message #1720439] |
Wed, 24 February 2016 21:46 |
|
I'm having the same issue. For me it's a ChopBoxAnchor that is causing an NPE in DiagramChangeListener.resourceSetChanged(ResourceSetChangeEvent event). The anchor is removed from its parent (a ContainerShape) and its eContainer is null, therefore the eResource is null. This causes an NPE in DiagramChangeListener.calculateActiveContainerPe(EObject affectedElement) because its parent is null.
|
|
|
Re: Problem due to commit 4364ec2 (EmfService.isisObjectAlive) [message #1724756 is a reply to message #1724625] |
Thu, 25 February 2016 18:03 |
|
Not sure if this will help anyone else, but I was able to cobble together a kludgy workaround for my use case (deleting a ChopboxAnchor) by overriding DiagramChangeListener in my DiagramBehavior implementation:
DiagramChangeListener diagramChangeListener;
@Override
protected void registerDiagramResourceSetListener() {
diagramChangeListener = new DiagramChangeListener(this) {
public NotificationFilter getFilter() {
return new NotificationFilter.Custom() {
@Override
public boolean matches(Notification notification) {
Object notifier = notification.getNotifier();
if (notifier instanceof ChopboxAnchor) {
ChopboxAnchor anchor = (ChopboxAnchor) notifier;
if (anchor.getParent()==null)
return false;
}
return !notification.isTouch();
}
};
}
};
TransactionalEditingDomain eDomain = getEditingDomain();
eDomain.addResourceSetListener(diagramChangeListener);
}
protected void unregisterDiagramResourceSetListener() {
if (diagramChangeListener != null) {
diagramChangeListener.stopListening();
TransactionalEditingDomain editingDomain = getEditingDomain();
if (editingDomain != null) {
editingDomain.removeResourceSetListener(diagramChangeListener);
}
}
}
|
|
|
|
Powered by
FUDForum. Page generated in 0.03876 seconds