Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Initail position of a node & palette changed at runtime
Initail position of a node & palette changed at runtime [message #697040] Fri, 15 July 2011 11:33 Go to next message
Mauro P. is currently offline Mauro P.Friend
Messages: 27
Registered: April 2011
Junior Member
Hi all.

I've got 2 problem with my editor.

First i would like to set initial position of a node in the diagram when the diagram is created and when the diagram is refreshed.
User must still be abele to move and resize nodes

I'v tryed diffrent solution like:

h**p://wiki.eclipse.org/Graphical_Modeling_Framework/Tips#Setting_Initial_Position_of_a_Node

and other post on the eclipse forum, but always without achive my goal.

When i try to set the node constraint, i still get the "cannot write in Read Only Transaction" also using editingDomain and command.

I need a hint on how solve this.


My second question ia about plaette. Is possible to change it at runtime? i need to hide/unide tool at runtime.

Tanks in advance.
Mauro P.
Re: Initail position of a node & palette changed at runtime [message #697043 is a reply to message #697040] Fri, 15 July 2011 11:48 Go to previous messageGo to next message
Mauro P. is currently offline Mauro P.Friend
Messages: 27
Registered: April 2011
Junior Member
this is my code:

@Override
public void activate() {
	super.activate();
	
	AbstractEMFOperation emfOp = new AbstractEMFOperation(getEditingDomain(), "Location setting") {
		@Override
		protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
			Location lc = (Location) ((Node) getModel()).getLayoutConstraint();
			int x=10;
			int y=10;
			//TODO: ---here the logic to calculate node position
			lc.setX(x);
			lc.setY(y);
			return Status.OK_STATUS;
		}
	};

	try {
		OperationHistoryFactory.getOperationHistory().execute(emfOp, null, null);
	} catch (ExecutionException e) {
		e.printStackTrace();
	}
}


this the printStackTrace

Caused by: java.lang.IllegalStateException: Cannot activate read/write transaction in read-only transaction context
at org.eclipse.emf.transaction.impl.TransactionalEditingDomainImpl.acquire(TransactionalEditingDomainImpl.java:561)
at org.eclipse.emf.transaction.impl.TransactionalEditingDomainImpl.activate(TransactionalEditingDomainImpl.java:493)
at org.eclipse.emf.transaction.impl.TransactionImpl.start(TransactionImpl.java:204)
at org.eclipse.emf.transaction.impl.TransactionalEditingDomainImpl.startTransaction(TransactionalEditingDomainImpl.java:409)
at org.eclipse.emf.workspace.AbstractEMFOperation.createTransaction(AbstractEMFOperation.java:617)
at org.eclipse.emf.workspace.AbstractEMFOperation.execute(AbstractEMFOperation.java:147)
at org.eclipse.core.commands.operations.DefaultOperationHistory.execute(DefaultOperationHistory.java:511)
... 44 more


After some test, i've noticed that the above code works perfectly the first time the nodes are created, it start to throw exception when i call the refresh method on XXXDiagramEditPart.
Because i need to set node position after a Diagram.refresh() is there a way to solve this?

[Updated on: Fri, 15 July 2011 12:11]

Report message to a moderator

Re: Initail position of a node & palette changed at runtime [message #700167 is a reply to message #697043] Fri, 22 July 2011 23:25 Go to previous message
Mauro P. is currently offline Mauro P.Friend
Messages: 27
Registered: April 2011
Junior Member
For who will have the same problem and he/she will still need an easy solution, i've found it.
The big mistake is trying to set the LayoutConstraint on the node...
you should set the constraint on the parent of the node like this(I will post my few and easy line of code):

        //here we are in the EditPart of the node we want set the initial position
        
        @Override
	public void activate() {
		super.activate();
		
                //The new rectangle rapresenting the new position and size of the node
                //size to -1 means "use preferredSize"
		Rectangle r = new Rectangle(0, 0, -1, -1);
                ((GraphicalEditPart) getParent()).setLayoutConstraint(this, getFigure(), r);	
	}


That is my code. has you can see no need to use command to do that, like suggest in other posts or tutorial.
You need to set the object constraint only on the parent (the diagram EditPart)

Hope this could help someone.
Previous Topic:GMF : Unhandled event loop exception error
Next Topic:how to add custom properties inside standard Advanced proerty tab
Goto Forum:
  


Current Time: Mon Dec 22 01:22:48 GMT 2014

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

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