Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Update/refresh automatically feature
Update/refresh automatically feature [message #1090494] Tue, 20 August 2013 04:03 Go to next message
Andrej K is currently offline Andrej K
Messages: 26
Registered: March 2013
Location: germany
Junior Member
Hello!

i have an Graphiti editor as RCP. The mean application provide the information to my graphiti editor and "say" what he need to show.
I can load, place and connect elements automatically. Now i need functionality which can refresh/update the shown information in elements which are already placed. (like color, size of elements inside, text...)
I can find and read information of element which i exactly want to update/refresh, but if i want to change him, i get this error:
java.lang.IllegalStateException: Cannot modify resource set without a write transaction

Here how i try to do this:
I have an method in the RCP where i call the graphiti feature to update the exact (elementIdInsideEditor) element:

public static void updateXXX(...) {
		
	Diagram diagram = ((MyEditor) myEditor).getDiagramTypeProvider().getDiagram();
	EList<Shape> diagramChildren= diagram.getChildren();
	PictogramElement pe = diagramChildren.get(elementIdInsideEditor).getGraphicsAlgorithm().getPictogramElement();
	
	UpdateContext updateContext = new UpdateContext(pe);
	updateContext.putProperty(... , ...);
	
	IUpdateFeature iUpdateFeature = ((MyEditor) myEditor)
						.getDiagramTypeProvider()
						.getFeatureProvider()
						.getUpdateFeature(updateContext);
	
	if(iUpdateFeature.canUpdate(updateContext))
		iUpdateFeature.update(updateContext);
}

I get from "canUpdate" true and can call my "update feature", there i can reed the informations of my PictogrammElement(pe) but if i want to change something, i get the error

public boolean update(IUpdateContext context) {
	PictogramElement pe = context.getPictogramElement();
	Object bo = getBusinessObjectForPictogramElement(pe);

	if (bo instanceof SketchElement) {//wenn es ein sketchelement ist
		SketchElement sElement = (SketchElement)bo;
 		  
 		if(pe instanceof ContainerShape){
			ContainerShape cs = (ContainerShape) pe;
			for (Shape shape : cs.getChildren()) {
				if(shape.getGraphicsAlgorithm() instanceof Rectangle){
					Rectangle rect = (Rectangle)shape.getGraphicsAlgorithm();  
					rect.setBackground(manageColor(myColor)); 	//!!
					rect.setX(10);					//!!
				}
			}
 		}
 	}
	return true;
}


setBackground or setX doesn't work
I'm wondering why it is not possible, the code is similar for automatically place, connect or drag and drop from an independent Tree-view

can somebody give me a hint why it doesn't work?

Regards Andrej




-------
Topic can be closed...
how it always happens, you try a long time, ask somebody and directly after this you found a solution
here is a hint:

http://stackoverflow.com/questions/17592810/automatic-update-of-graphiti-diagrams-in-case-of-changes-in-the-datamodel

[Updated on: Tue, 20 August 2013 04:52]

Report message to a moderator

Re: Update/refresh automatically feature [message #1092932 is a reply to message #1090494] Fri, 23 August 2013 06:47 Go to previous message
Felix Velasco is currently offline Felix Velasco
Messages: 43
Registered: July 2009
Member
You need a write transaction to modify the model.
Try substituting this:
if(iUpdateFeature.canUpdate(updateContext))
		iUpdateFeature.update(updateContext);

for this:
TransactionalEditingDomain ted = TransactionUtil.getEditingDomain(diagram);
ted.getCommandStack().execute(new RecordingCommand(editingDomain) {

			@Override
			protected void doExecute() {
				if(iUpdateFeature.canUpdate(updateContext))
					iUpdateFeature.update(updateContext);
			}
		});
Previous Topic:DiagramEditor refresh behaviour
Next Topic:rolling back model changes
Goto Forum:
  


Current Time: Fri Jul 25 09:44:39 EDT 2014

Powered by FUDForum. Page generated in 0.01533 seconds