Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » set attribute on creation of node
set attribute on creation of node [message #479951] Thu, 13 August 2009 08:34 Go to next message
Gary is currently offline GaryFriend
Messages: 125
Registered: July 2009
Senior Member
Hi all,
I need to set an atribute on the creation of a node
eg.
if node A... attribute ON/OFF = ON
if node B... attribute ON/OFF = OFF

A is always ON and B is always OFF!

I know that I need to do this in the nodes create command but I'm not sure
of the best way to do it.

- how do I access the nodes attribute and set it?

Just a brief example should help,
Thanks in advance,
Gary
Re: set attribute on creation of node [message #479958 is a reply to message #479951] Thu, 13 August 2009 09:02 Go to previous messageGo to next message
Peter Lang is currently offline Peter LangFriend
Messages: 153
Registered: July 2009
Senior Member
> - how do I access the nodes attribute and set it?
You should be able to set the attribute in your
XxxCreateCommand.doConfigure method.
Just call newElement.setYyy(...) there.

Regards, Peter
Re: set attribute on creation of node [message #480022 is a reply to message #479958] Thu, 13 August 2009 13:50 Go to previous messageGo to next message
Gary is currently offline GaryFriend
Messages: 125
Registered: July 2009
Senior Member
Hi, I've realised that it is more complex than I first thought:

- I have a two nodes (A,B) that reference the same class (ClassName)
(seams as if the create command is for an instance of the class type since
the create command for node A has the name ...ClassNameCreateCommand
and the create command for node B has the name ...ClassNameCreateCommand2

-In these create command methods there is nothing called
XxxCreateCommand.doConfigure as you mentioned!

Am I looking in the right place?
(Xxx.diagram.edit.commands > ClassNameCreateCommand)

Thanks in advance,
Gary
Re: set attribute on creation of node [message #480023 is a reply to message #480022] Thu, 13 August 2009 13:59 Go to previous messageGo to next message
Peter Lang is currently offline Peter LangFriend
Messages: 153
Registered: July 2009
Senior Member
Hi Gary,

> -In these create command methods there is nothing called
> XxxCreateCommand.doConfigure as you mentioned!

> Am I looking in the right place?
> (Xxx.diagram.edit.commands > ClassNameCreateCommand)
Yes, you are looking in the right place.
If you use a GMF version prior to 2.2, then the doConfigure method does
not exist. In this case, you can modify doExecuteWithResult.

You get your new element by "getNewElement()", cast it to Xxx.

Regards, Peter
Re: set attribute on creation of node [message #480030 is a reply to message #480023] Thu, 13 August 2009 14:11 Go to previous messageGo to next message
Gary is currently offline GaryFriend
Messages: 125
Registered: July 2009
Senior Member
hi, the only methods in my create command are:

public ClassNameCreateCommand(CreateElementRequest req){ *** }

protected EObject getElementToEdit() { *** }

protected EClass getEClassToEdit() { *** }

_____________________________________________________

do I need to create my own method?

Thanks,
Gary
Re: set attribute on creation of node [message #480044 is a reply to message #480023] Thu, 13 August 2009 14:24 Go to previous messageGo to next message
Gary is currently offline GaryFriend
Messages: 125
Registered: July 2009
Senior Member
my entire create command =
____________________________________________________________ _______________

public class SwitchReferenceCreateCommand extends CreateElementCommand {

public SwitchReferenceCreateCommand(CreateElementRequest req) {
super(req);
}

protected EObject getElementToEdit() {
EObject container = ((CreateElementRequest) getRequest())
.getContainer();
if (container instanceof View) {
container = ((View) container).getElement();
}
return container;
}

protected EClass getEClassToEdit() {
return ViewManagement.ViewManagementPackage.eINSTANCE
.getSwitch();
}

}
____________________________________________________________ _______________

As you can see there is no reference to the methods you suggested,
I'm not sure where I'm going wrong,
thanks,
Gary
Re: set attribute on creation of node [message #480045 is a reply to message #480044] Thu, 13 August 2009 14:45 Go to previous messageGo to next message
Peter Lang is currently offline Peter LangFriend
Messages: 153
Registered: July 2009
Senior Member
> public class SwitchReferenceCreateCommand extends CreateElementCommand {

> As you can see there is no reference to the methods you suggested,
> I'm not sure where I'm going wrong,

Not sure about when this method is generated. You can override it anyway:

@Override
protected CommandResult doExecuteWithResult(IProgressMonitor monitor,
IAdaptable info) throws ExecutionException {
CommandResult result = super.doExecuteWithResult(monitor, info);
((SwitchReference)getNewElement()).setXxx();
return result;
}


Or, maybe better:

@Override
protected EObject doDefaultElementCreation() {
SwitchReference newSwitchReference =
(SwitchReference)super.doDefaultElementCreation();
// newSwitchReference.setXxx();
return newSwitchReference;
}
Re: set attribute on creation of node [message #480055 is a reply to message #480045] Thu, 13 August 2009 15:31 Go to previous messageGo to next message
Gary is currently offline GaryFriend
Messages: 125
Registered: July 2009
Senior Member
Thanks for your help, that works great!
Re: set attribute on creation of node [message #480569 is a reply to message #479951] Mon, 17 August 2009 16:31 Go to previous messageGo to next message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Gary,

You can:
- create two node mappings one for node A, another for node B
- create two constraints for each of these mappings saying A => attribute
ON/OFF = ON, B => attribute ON/OFF = OFF
- create two FeatureSequenceInitializers for each A/B node mapping setting
attribute ON/OFF to ON/OFF on creation

See Ecore diagram editor example, link mappings for containment/non containment
references for more details.
-----------------
Alex Shatalin
Re: set attribute on creation of node [message #480719 is a reply to message #480569] Tue, 18 August 2009 10:05 Go to previous messageGo to next message
Gary is currently offline GaryFriend
Messages: 125
Registered: July 2009
Senior Member
Hi, Thanks for this info, do you have a link to the example you mentioned?
I can't find it, and I've never used OCL constraints before, also never
used Feature Seq Initializers before so I could do with as much help as I
can get.

Thanks,
Gary
Re: set attribute on creation of node [message #480775 is a reply to message #480719] Tue, 18 August 2009 12:53 Go to previous messageGo to next message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Gary,

See http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.gmf/exa mples/org.eclipse.gmf.ecore.editor/?root=Modeling_Project

-----------------
Alex Shatalin
Re: set attribute on creation of node [message #480975 is a reply to message #480775] Wed, 19 August 2009 08:48 Go to previous message
Gary is currently offline GaryFriend
Messages: 125
Registered: July 2009
Senior Member
Thanks for that Alex, this is a much tidyer way of setting an attribute,
since you don't need to add code after generation!

Thank you all for your help and advice!
Previous Topic:How to automatically create a default node after generating a new diagram
Next Topic:Double EditPart.java files
Goto Forum:
  


Current Time: Sun Apr 14 02:49:39 GMT 2024

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

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

Back to the top