Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Update diagram after business object has been deleted
Update diagram after business object has been deleted [message #1130528] Wed, 09 October 2013 17:12 Go to next message
Laurent Le Moux is currently offline Laurent Le MouxFriend
Messages: 184
Registered: September 2011
Senior Member
Hi all,

I stored my Graphiti diagrams and associated business objects (BO) in CDO.
I now need to update a diagram for a given picture element (PE) when the corresponding BO has been deleted from CDO.

I just want to remove the PE from the diagram.
So I defined an update feature that tries to reuse DefaultRemoveFeature#remove as follow :

	@Override
	public IUpdateFeature getUpdateFeature(IUpdateContext context) {
	   PictogramElement pictogramElement = context.getPictogramElement();
	   if (pictogramElement instanceof ContainerShape) {
	       Object bo = getBusinessObjectForPictogramElement(pictogramElement);
	       if (bo instanceof Operation) {
	           return new OperationUpdateFeature(this);
	       } else if (CDOUtil.isStaleObject(bo))
	    	   return new StaleObjectUpdateFeature(this);
	   }
	   return super.getUpdateFeature(context);
	}


and

public class StaleObjectUpdateFeature extends AbstractUpdateFeature {

	public StaleObjectUpdateFeature(IFeatureProvider fp) {
		super(fp);
	}

	@Override
	public boolean canUpdate(IUpdateContext context) {
		return true;
	}

	@Override
	public IReason updateNeeded(IUpdateContext context) {
		return Reason.createTrueReason("Object deleted from the repository");
	}

	@Override
	public boolean update(IUpdateContext context) {		
		new DefaultRemoveFeature(this.getFeatureProvider()).remove(new RemoveContext(context.getPictogramElement()));
		return true;
	}
}


But I get the following exception :
!ENTRY org.eclipse.graphiti.ui 4 0 2013-10-09 18:49:22.789
!MESSAGE GFCommandStack.execute(Command) org.eclipse.emf.cdo.util.ObjectNotFoundException: Object OID489 not found
!STACK 0
org.eclipse.emf.cdo.util.ObjectNotFoundException: Object OID489 not found
	at org.eclipse.emf.cdo.view.CDOStaleReferencePolicy$2$1.invoke(CDOStaleReferencePolicy.java:101)
	at com.sun.proxy.$Proxy15.hashCode(Unknown Source)
	at java.util.HashMap.hash(Unknown Source)
	at java.util.HashMap.getEntry(Unknown Source)
	at java.util.HashMap.containsKey(Unknown Source)
	at java.util.HashSet.contains(Unknown Source)
	at org.eclipse.emf.ecore.util.EcoreUtil$UsageCrossReferencer.crossReference(EcoreUtil.java:2585)
	at org.eclipse.emf.ecore.util.EcoreUtil$CrossReferencer.handleCrossReference(EcoreUtil.java:1744)
	at org.eclipse.emf.ecore.util.EcoreUtil$CrossReferencer.crossReference(EcoreUtil.java:1716)
	at org.eclipse.emf.ecore.util.EcoreUtil$UsageCrossReferencer.findAllUsage(EcoreUtil.java:2610)
	at org.eclipse.emf.ecore.util.EcoreUtil$UsageCrossReferencer.findAll(EcoreUtil.java:2693)
	at org.eclipse.emf.ecore.util.EcoreUtil.delete(EcoreUtil.java:3303)
	at org.eclipse.graphiti.internal.services.impl.PeServiceImpl.deletePictogramElement(PeServiceImpl.java:347)
	at org.eclipse.graphiti.features.impl.DefaultRemoveFeature.remove(DefaultRemoveFeature.java:83)
	at org.eclipse.graphiti.features.impl.DefaultRemoveFeature.removeAllConnections(DefaultRemoveFeature.java:136)
	at org.eclipse.graphiti.features.impl.DefaultRemoveFeature.removeAllConnections(DefaultRemoveFeature.java:114)
	at org.eclipse.graphiti.features.impl.DefaultRemoveFeature.remove(DefaultRemoveFeature.java:76)
	at myappsmodeler.graphiti.StaleObjectUpdateFeature.update(StaleObjectUpdateFeature.java:29)


I seems that the remove action needs somehow to access the now invalid BO reference which causes the exception.
Is there a way to prevent this from happening ?

Kind regards,

Laurent
Re: Update diagram after business object has been deleted [message #1131420 is a reply to message #1130528] Thu, 10 October 2013 13:52 Go to previous messageGo to next message
Laurent Le Moux is currently offline Laurent Le MouxFriend
Messages: 184
Registered: September 2011
Senior Member
Hi again,

Some news about my problem. I decided to 'reset' the link between the PE and the invalid BO (the CDO Stale object).

	@Override
	public boolean update(IUpdateContext context) {
		checkLinksForCDOStaleObjects(context.getPictogramElement());
		new DefaultRemoveFeature(this.getFeatureProvider()).remove(new RemoveContext(context.getPictogramElement()));
		return true;
	}

	/*
	 * Recursively navigate trough the container shape tree to look for and 'reset' links involving a CDO stale object.
	 * There should be no such object in a diagram link... 
	 */
	private void checkLinksForCDOStaleObjects(PictogramElement pe) {
		if (pe.getLink() != null) {
			System.out.println("Inspecting link " + pe.getLink() + " for " + pe);
			EList<EObject> l = pe.getLink().getBusinessObjects();
			for (EObject o : l)
				if (o instanceof CDOStaleObject) {
					System.out.println("Found stale object " + ((CDOStaleObject)o).cdoID() + " for " + pe);
					PictogramLink link = PictogramsFactory.eINSTANCE.createPictogramLink();
					link.setPictogramElement(pe);
					pe.setLink(link);
					System.out.println("Built new link " + pe.getLink() + " for " + pe + " with no bo : "
							+ pe.getLink().getBusinessObjects());
					break;
				}			
		}
		if (pe instanceof ContainerShape) {
			EList<Shape> l = ((ContainerShape)pe).getChildren();
			for (Shape s : l)
				checkLinksForCDOStaleObjects(s);
		}
	}


I now successfully remove my PE from the diagram with the following traces :
Inspecting link PictogramLink@OID1432 for ContainerShape@OID1429
Found stale object OID1391 for ContainerShape@OID1429
Built new link PictogramLink@oid1[NEW] for ContainerShape@OID1429[DIRTY] with no bo : []
Inspecting link PictogramLink@OID1439 for Shape@OID1437
Found stale object OID1391 for Shape@OID1437
Built new link PictogramLink@oid2[NEW] for Shape@OID1437[DIRTY] with no bo : []


My editor is then dirty and a new exception is thrown when saving.
Looking at CDO content, everything has been commited and looks fine.
But the container shape link is now a CDO stale object...

!SESSION 2013-10-10 15:16:20.013 -----------------------------------------------
eclipse.buildId=unknown
java.version=1.6.0_11
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=win32, ARCH=x86, WS=win32, NL=fr_FR
Framework arguments:  -product MyAppsModeler.product
Command-line arguments:  -product MyAppsModeler.product -data D:\Mes documents\workspace/../runtime-MyAppsModeler.product -dev file:D:/Mes documents/workspace/.metadata/.plugins/org.eclipse.pde.core/MyAppsModeler.product/dev.properties -os win32 -ws win32 -arch x86 -consoleLog

!ENTRY org.eclipse.emf.transaction 4 45 2013-10-10 15:17:42.251
!MESSAGE Uncaught exception during post-commit listener notifications
!STACK 0
org.eclipse.emf.cdo.util.ObjectNotFoundException: Object OID1432 not found
	at org.eclipse.emf.cdo.view.CDOStaleReferencePolicy$2$1.invoke(CDOStaleReferencePolicy.java:101)
	at $Proxy16.getBusinessObjects(Unknown Source)
	at org.eclipse.graphiti.features.impl.AbstractFeatureProvider.getAllPictogramElementsForBusinessObject(AbstractFeatureProvider.java:478)
	at org.eclipse.graphiti.notification.DefaultNotificationService.calculateLinkedPictogramElements(DefaultNotificationService.java:78)
	at org.eclipse.graphiti.notification.DefaultNotificationService.calculateRelatedPictogramElements(DefaultNotificationService.java:103)
	at org.eclipse.graphiti.ui.internal.editor.DomainModelChangeListener.resourceSetChanged(DomainModelChangeListener.java:101)
	at org.eclipse.emf.transaction.impl.TransactionalEditingDomainImpl$1.run(TransactionalEditingDomainImpl.java:781)
	at org.eclipse.emf.transaction.impl.TransactionalEditingDomainImpl.runExclusive(TransactionalEditingDomainImpl.java:328)
	at org.eclipse.emf.transaction.impl.TransactionalEditingDomainImpl.postcommit(TransactionalEditingDomainImpl.java:771)
	at org.eclipse.emf.transaction.impl.TransactionalEditingDomainImpl.deactivate(TransactionalEditingDomainImpl.java:543)
	at org.eclipse.emf.transaction.impl.TransactionImpl.close(TransactionImpl.java:712)
	at org.eclipse.emf.transaction.impl.TransactionImpl.commit(TransactionImpl.java:474)
	at org.eclipse.emf.transaction.impl.TransactionalEditingDomainImpl.runExclusive(TransactionalEditingDomainImpl.java:333)
	at org.eclipse.graphiti.ui.internal.services.impl.EmfService$1.run(EmfService.java:279)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2345)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2327)
	at org.eclipse.graphiti.ui.internal.services.impl.EmfService.save(EmfService.java:286)
	at org.eclipse.graphiti.ui.editor.DefaultPersistencyBehavior.save(DefaultPersistencyBehavior.java:281)
	at myappsmodeler.graphiti.GraphitiEditor$GraphitiDiagramBehavior$2.save(GraphitiEditor.java:131)
	at org.eclipse.graphiti.ui.editor.DefaultPersistencyBehavior$1.run(DefaultPersistencyBehavior.java:250)
	at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)


Any idea why the container shape link is still around and it is considered as invalid ?
Re: Update diagram after business object has been deleted [message #1132501 is a reply to message #1131420] Fri, 11 October 2013 07:29 Go to previous message
Laurent Le Moux is currently offline Laurent Le MouxFriend
Messages: 184
Registered: September 2011
Senior Member
Hi all,

I found what the problem was. The pictogram link corresponding to a stale object was still referenced at the diagram object level.
Some additionnal cleaning as follow was necessary :

	@Override
	public boolean update(IUpdateContext context) {
		checkLinksForCDOStaleObjects(context.getPictogramElement());
		
		new DefaultRemoveFeature(this.getFeatureProvider()).remove(new RemoveContext(context.getPictogramElement()));
		
		// Also remove links to CDO stale objects at diagram level
		EList<PictogramLink> links = getDiagram().getPictogramLinks();
		EList<PictogramLink> deletedLinks = new BasicEList<PictogramLink>();
		for (PictogramLink link : links) {
			EList<EObject> bos = link.getBusinessObjects();
			for (EObject bo : bos)
				if (bo instanceof CDOStaleObject) {
					deletedLinks.add(link);
					break;
				}
		}
		links.removeAll(deletedLinks);
		return true;
	}


Kind regards.
Previous Topic:Getting width of text
Next Topic:How to avoid linking of diagram to the model object to be part of the command stack
Goto Forum:
  


Current Time: Fri Apr 19 22:11:18 GMT 2024

Powered by FUDForum. Page generated in 0.03244 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top