Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » update on nested GA
update on nested GA [message #806355] Fri, 24 February 2012 21:50 Go to next message
Josef Pohl is currently offline Josef PohlFriend
Messages: 82
Registered: January 2012
Member
Hi there,

I have a GA that is nested inside of a containerShape that is shows up depending on whether or not a certain boolean element is true or not. Once I have done an update to the business object what is the best way to force the containing GA to re-render to show the change?

Is there a way to
1. Remove and dispose of the GA (and the associated shape) from the Container and force the Container to re-render?
2. Add in a GA (and shape) into the Container and also for the Container to re-render?


Thanks as always,
Joe
Re: update on nested GA [message #807989 is a reply to message #806355] Mon, 27 February 2012 09:07 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Hi Joe,

you should simply remove the no longer needed GA(s) and PE(s) from within
your update feature. Potentially a re-layout should be triggered afterwards.

Michael
Re: update on nested GA [message #809331 is a reply to message #807989] Tue, 28 February 2012 18:56 Go to previous messageGo to next message
Josef Pohl is currently offline Josef PohlFriend
Messages: 82
Registered: January 2012
Member
Hi there,

When I do an update and then later save I get an error about the pictogram link not being part of a resource set. I presume this is because I have, in my Add Feature,
the following code
link(shape, addedClass);

Is there a good way to remove these links?
Here is the code I use to control the update. (needsDiamondRemoved is set in updateNeeded.)
	else if (shape.getGraphicsAlgorithm() instanceof Polygon){
		Polygon poly = (Polygon) shape.getGraphicsAlgorithm();
		PictogramElement pge = poly.getPictogramElement();
         	if(needsDiamondRemoved){
			if(Graphiti.getPeService().getPropertyValue(pge, "shape-type").equals("diamond")){
			     shapeToRemove = index;
			     poly = null;
			     shape.setGraphicsAlgorithm(null);
		             //Graphiti.getPeService().deletePictogramElement(pge);
			     needsDiamondRemoved = false;
			  }
		}
					
	}


and later....
	if(shapeToRemove > -1){
		cs.getChildren().remove(shapeToRemove);
		return true;
	}


Also is there a good way to call a refresh (or re-layout) on the screen so the user does not have to hit the update context icon?

Thanks,
Joe
Re: update on nested GA [message #809761 is a reply to message #809331] Wed, 29 February 2012 08:22 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
I didn't fully understand the coding you quoted, but from a first glance I
would assume that yxou should delete the graphics algorithm instead of just
deleting its reference with shape.setGraphicsAlgorithm(null);

Michael
Re: update on nested GA [message #810114 is a reply to message #809761] Wed, 29 February 2012 18:06 Go to previous messageGo to next message
Josef Pohl is currently offline Josef PohlFriend
Messages: 82
Registered: January 2012
Member
Hi Michael,
Sorry, I guess the code was a little out of context. It represent the code in the update method of my UpdateStrategyFeature class.

I thought, and please correct me if I am wrong, that I was deleting the GA by setting poly = null, poly being the GA associated with the shape.
The hierarchy is like this:
ContainerShape
|
|--> GA (parallelogram)
|
|--> Shape
|--> GA (diamond) (link(shape, businessObject))
| ...other Shapes

This is the error that I am getting:
!MESSAGE The following resources could not be saved:
URI: platform:/resource/egsc_test3/src/diagrams/Test26.diagram, cause: 
org.eclipse.emf.ecore.resource.Resource$IOWrappedException: The object 'org.eclipse.graphiti.mm.pictograms.impl.PictogramLinkImpl@19ebfd1' is not contained in a resource.
	at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.endSave(XMLSaveImpl.java:307)
	at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.save(XMLSaveImpl.java:271)
	at org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doSave(XMLResourceImpl.java:333)
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(ResourceImpl.java:1423)
...


I get it on a save after an update. Not during the update itself.

I updated the code to try to remove the link. (See below. I have gone through several iterations on this. This is the latest version.)

I have noted that if I remove the line
link(shape, addedClass);

from the add feature, where shape is the PE for the diamond I am trying to remove and addedClass is the BO, then everything works OK. No error on the save.

So, in reference to the code below, is there another way I should be deleting the GA?
Is there another way to access and delete that link explicitly?

Thanks as always for all your help,
Joe
	public boolean update(IUpdateContext context) {		
		String description = null;
		int shapeToRemove = -1;
		PictogramElement pE = context.getPictogramElement();
		Object bo = getBusinessObjectForPictogramElement(pE);
		boolean tbdBO = false;
		if(bo instanceof Strategy) {
			Strategy strategy = (Strategy) bo;
			description = strategy.getDescription();
		}
		
		int index = 0;
		if(pE instanceof ContainerShape) {
			ContainerShape cs = (ContainerShape) pE;
			for(Shape shape : cs.getChildren()) {
				if(shape.getGraphicsAlgorithm() instanceof MultiText && needsTextUpdate){
					MultiText text = (MultiText) shape.getGraphicsAlgorithm();
					text.setValue(description);
					needsTextUpdate = false;
					return true;
				}
				else if (shape.getGraphicsAlgorithm() instanceof Polygon){
					Polygon poly = (Polygon) shape.getGraphicsAlgorithm();
					if(needsDiamondRemoved){
					  if(Graphiti.getPeService().
                                              getPropertyValue(shape, "shape-type").
                                              equals("diamond")){
							shapeToRemove = index;
							PictogramLink l = shape.getLink();
							shape.setLink(null);
							l = null;
							//shape.setGraphicsAlgorithm(null);
							
							poly = null;
							//Graphiti.getPeService().deletePictogramElement(pge);
							needsDiamondRemoved = false;
						}
					}
					
				}
				index +=1;
			}
			if(shapeToRemove > -1){

				Shape s = cs.getChildren().get(shapeToRemove);
				
				cs.getChildren().remove(shapeToRemove);
				//PictogramLink l = s.getLink();
				//s.setLink(null);
				//l = null;
				s = null;
				return true;
			}
		}
		
		return false;
	}
Re: update on nested GA [message #813443 is a reply to message #810114] Mon, 05 March 2012 09:14 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
No, by that you simply remove the GA from the shape, it is parentless
afterwards. You should call ECoreUtil.delete instead.

Michael
Re: update on nested GA [message #814611 is a reply to message #813443] Tue, 06 March 2012 17:10 Go to previous message
Josef Pohl is currently offline Josef PohlFriend
Messages: 82
Registered: January 2012
Member
Thanks Michael,
Calling ECoreUtil.delete on the Pictogram link did the trick.

I appreciate your help!

Joe
Previous Topic:Resource leaks in Graphiti?
Next Topic:hyper text links in a MultiText GA
Goto Forum:
  


Current Time: Fri Apr 19 13:52:05 GMT 2024

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

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

Back to the top