Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » change attributes during runtime in transactional context
change attributes during runtime in transactional context [message #1052067] Mon, 29 April 2013 15:13 Go to next message
Phil H is currently offline Phil HFriend
Messages: 267
Registered: November 2012
Senior Member
Hi there,

When I add an element to my diagram, I want to give this element an initial name.
First I tried the following code:

if (this.resolveSemanticElement() instanceof Feature) {
  Feature featureNode = (Feature) this.resolveSemanticElement();
  if (featureNode.getName() == null) {
    featureNode.setName("Feature");
  }
}


By executing this code, the desired attribute changed, but I get always this execption:

java.lang.IllegalStateException: Cannot modify resource set without a write transaction
......


So I tried the following code (which works in another context), since it seems to be a problem with trancactions:

if (this.resolveSemanticElement() instanceof Feature) {
  Feature featureNode = (Feature) this.resolveSemanticElement();
  if (featureNode.getName() == null) {
    TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) this).getEditingDomain();
    SetRequest setRequestX = new SetRequest(editingDomain, featureNode,PldPackage.eINSTANCE.getFeature_Name(), "Feature");
    SetValueCommand setX = new SetValueCommand(setRequestX);
    try {
      setX.execute(null, null);
    } catch (ExecutionException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
}


But then I get the following error:

java.lang.IllegalStateException: Cannot activate read/write transaction in read-only transaction context


What is going wrong?
Re: change attributes during runtime in transactional context [message #1052577 is a reply to message #1052067] Tue, 30 April 2013 08:57 Go to previous messageGo to next message
Ralph Gerbig is currently offline Ralph GerbigFriend
Messages: 702
Registered: November 2009
Senior Member
Hi,

you need to do something getEditDomain()/getEditingDomain() depending on your command and then .getCommandStack().execute(command). In your case it looks like you are trying to set a value of a semantic model element so getEditingDomain() should do the trick.

Ralph
Re: change attributes during runtime in transactional context [message #1052680 is a reply to message #1052577] Tue, 30 April 2013 11:53 Go to previous messageGo to next message
Phil H is currently offline Phil HFriend
Messages: 267
Registered: November 2012
Senior Member
Thanks for your hint!! In case I'm tryng to change value of a semantic model element.

I tried the following code:

getEditDomain().getCommandStack().execute(new ICommandProxy(setName));


But then I get an exception:

org.eclipse.core.commands.ExecutionException: While executing the operation, an exception occurred
......


I think it's because of using EditDomain instead of EditingDomain. But when I try to use

getEditingDomain().getCommandStack().execute(new ICommandProxy(setName));


eclipse tells me that the method execute(Command) in the type CommandStack is not applicable for the arguments (ICommandProxy. I'm unsure now what Command I have to use..
Re: change attributes during runtime in transactional context [message #1052763 is a reply to message #1052680] Tue, 30 April 2013 13:53 Go to previous messageGo to next message
Ralph Gerbig is currently offline Ralph GerbigFriend
Messages: 702
Registered: November 2009
Senior Member
Hi,

did you try without ICommandProxy.

Cheers,

Ralph
Re: change attributes during runtime in transactional context [message #1052906 is a reply to message #1052763] Wed, 01 May 2013 09:14 Go to previous messageGo to next message
Phil H is currently offline Phil HFriend
Messages: 267
Registered: November 2012
Senior Member
Yep, got "The method execute(Command) in the type CommandStack is not applicable for the arguments (SetValueCommand)"

But I dont't know how to use normal Command for this case..The documentation is really poor..
Re: change attributes during runtime in transactional context [message #1053255 is a reply to message #1052906] Fri, 03 May 2013 12:05 Go to previous message
Ralph Gerbig is currently offline Ralph GerbigFriend
Messages: 702
Registered: November 2009
Senior Member
Hi,

I did not notice that you are using a GMF command. Try to use the EMF version SetCommand.create(...). This will work.

Ralph
Previous Topic:Problem with diagram initialization
Next Topic:Additional nodes on subdiagram.
Goto Forum:
  


Current Time: Thu Mar 28 08:57:33 GMT 2024

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

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

Back to the top