Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Quick CreateElement question
Quick CreateElement question [message #154646] Wed, 10 October 2007 10:34 Go to next message
Eclipse UserFriend
Originally posted by: trommas.yahoo.com

I create an element in an action like this (this gives an "empty" element):

IElementType type = UemlbaseElementTypes.ClassNode_2002;

ViewAndElementDescriptor viewDescriptor =
new ViewAndElementDescriptor(new CreateElementRequestAdapter(
new CreateElementRequest(type)),Node.class, (
(IHintedType) type).getSemanticHint(),
selectedElement.getDiagramPreferencesHint());

Is there any way to "grab" the newly created element (so I can set it's
properties), or to choose what object is to be created?

(like: ClassNodeImpl dummy = new ClassNodeImpl();
dummy.setName("dummy");
...new CreateElementRequestAdapter(new CreateElementRequest(dummy,
type))...

- I've tried this, no work :(


Thanks,

Tomas
Re: Quick CreateElement question [message #154703 is a reply to message #154646] Wed, 10 October 2007 16:11 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: trommas.yahoo.com

I've simplified it a bit:

CreateElementRequest eReq = new CreateElementRequest
(UemlbaseElementTypes.ClassNode_2002);

ViewAndElementDescriptor viewDescriptor = new ViewAndElementDescriptor(
new CreateElementRequestAdapter(eReq), Node.class,((IHintedType)
type).getSemanticHint(), prefs);

This gives me an empty element, what I would like is to run something like:

ClassNode dummy = new ClassNodeImpl();
dummy.setName("dummy");

CreateElementRequest eReq = new CreateElementRequest (dummy,
UemlbaseElementTypes.ClassNode_2002);

Strange that it doesn't work...


Thanks,

Tomas

Tomas Zijdemans wrote:
> I create an element in an action like this (this gives an "empty" element):
>
> IElementType type = UemlbaseElementTypes.ClassNode_2002;
>
> ViewAndElementDescriptor viewDescriptor =
> new ViewAndElementDescriptor(new CreateElementRequestAdapter(
> new CreateElementRequest(type)),Node.class, (
> (IHintedType) type).getSemanticHint(),
> selectedElement.getDiagramPreferencesHint());
>
> Is there any way to "grab" the newly created element (so I can set it's
> properties), or to choose what object is to be created?
>
> (like: ClassNodeImpl dummy = new ClassNodeImpl();
> dummy.setName("dummy");
> ...new CreateElementRequestAdapter(new CreateElementRequest(dummy,
> type))...
>
> - I've tried this, no work :(
>
>
> Thanks,
>
> Tomas
Re: Quick CreateElement question [message #154715 is a reply to message #154703] Wed, 10 October 2007 17:05 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: bmoros.um.es

Hi Tomas,

you can get the reference of the model element created by means of a
CreateElementRequest as follows:

IAdaptable viewAdapter = (IAdaptable) ((List)
request.getNewObject()).get(0);

View view = (View) viewAdapter.getAdapter(View.class);

if (view != null) {

ModelElement element = (ModelElement) view.getElement();

...

}

Once you get the reference to the model element you should change its
attributes by means of creating a SetRequest and executing the command:

this.getDiagramEditDomain().getDiagramCommandStack().execute (new
ICommandProxy(new SetValueCommand(setRequest)));


IHIH

Bego
Re: Quick CreateElement question [message #154869 is a reply to message #154715] Thu, 11 October 2007 14:00 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: trommas.yahoo.com

Thanks for helping, but the view variable is always null (the if test
always fails), any ideas?

Thanks,

Tomas

Begoña Moros wrote:
> Hi Tomas,
>
> you can get the reference of the model element created by means of a
> CreateElementRequest as follows:
>
> IAdaptable viewAdapter = (IAdaptable) ((List)
> request.getNewObject()).get(0);
>
> View view = (View) viewAdapter.getAdapter(View.class);
>
> if (view != null) {
>
> ModelElement element = (ModelElement) view.getElement();
>
> ...
>
> }
>
> Once you get the reference to the model element you should change its
> attributes by means of creating a SetRequest and executing the command:
>
> this.getDiagramEditDomain().getDiagramCommandStack().execute (new
> ICommandProxy(new SetValueCommand(setRequest)));
>
>
> IHIH
>
> Begoña
>
> "Tomas Zijdemans" <trommas@yahoo.com> escribió en el mensaje
> news:feitj7$l00$2@build.eclipse.org...
>> I've simplified it a bit:
>>
>> CreateElementRequest eReq = new CreateElementRequest
>> (UemlbaseElementTypes.ClassNode_2002);
>>
>> ViewAndElementDescriptor viewDescriptor = new ViewAndElementDescriptor(
>> new CreateElementRequestAdapter(eReq), Node.class,((IHintedType)
>> type).getSemanticHint(), prefs);
>>
>> This gives me an empty element, what I would like is to run something
>> like:
>>
>> ClassNode dummy = new ClassNodeImpl();
>> dummy.setName("dummy");
>>
>> CreateElementRequest eReq = new CreateElementRequest (dummy,
>> UemlbaseElementTypes.ClassNode_2002);
>>
>> Strange that it doesn't work...
>>
>>
>> Thanks,
>>
>> Tomas
>>
>> Tomas Zijdemans wrote:
>>> I create an element in an action like this (this gives an "empty"
>>> element):
>>>
>>> IElementType type = UemlbaseElementTypes.ClassNode_2002;
>>>
>>> ViewAndElementDescriptor viewDescriptor =
>>> new ViewAndElementDescriptor(new CreateElementRequestAdapter(
>>> new CreateElementRequest(type)),Node.class, (
>>> (IHintedType) type).getSemanticHint(),
>>> selectedElement.getDiagramPreferencesHint());
>>>
>>> Is there any way to "grab" the newly created element (so I can set it's
>>> properties), or to choose what object is to be created?
>>>
>>> (like: ClassNodeImpl dummy = new ClassNodeImpl();
>>> dummy.setName("dummy");
>>> ...new CreateElementRequestAdapter(new CreateElementRequest(dummy,
>>> type))...
>>>
>>> - I've tried this, no work :(
>>>
>>>
>>> Thanks,
>>>
>>> Tomas
>
>
Re: Quick CreateElement question [message #154872 is a reply to message #154869] Thu, 11 October 2007 14:41 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: trommas.yahoo.com

I resolved it by using "CreateViewRequest topicRequest =
CreateViewRequestFactory.getCreateShapeRequest.." instead :)

But could anyone tell me how to use setRequests? Or point me to an example


Thanks,

Tomas


Tomas Zijdemans wrote:
> Thanks for helping, but the view variable is always null (the if test
> always fails), any ideas?
>
> Thanks,
>
> Tomas
>
> Begoña Moros wrote:
>> Hi Tomas,
>>
>> you can get the reference of the model element created by means of a
>> CreateElementRequest as follows:
>>
>> IAdaptable viewAdapter = (IAdaptable) ((List)
>> request.getNewObject()).get(0);
>>
>> View view = (View) viewAdapter.getAdapter(View.class);
>>
>> if (view != null) {
>>
>> ModelElement element = (ModelElement) view.getElement();
>>
>> ...
>>
>> }
>>
>> Once you get the reference to the model element you should change its
>> attributes by means of creating a SetRequest and executing the command:
>>
>> this.getDiagramEditDomain().getDiagramCommandStack().execute (new
>> ICommandProxy(new SetValueCommand(setRequest)));
>>
>>
>> IHIH
>>
>> Begoña
>>
>> "Tomas Zijdemans" <trommas@yahoo.com> escribió en el mensaje
>> news:feitj7$l00$2@build.eclipse.org...
>>> I've simplified it a bit:
>>>
>>> CreateElementRequest eReq = new CreateElementRequest
>>> (UemlbaseElementTypes.ClassNode_2002);
>>>
>>> ViewAndElementDescriptor viewDescriptor = new ViewAndElementDescriptor(
>>> new CreateElementRequestAdapter(eReq), Node.class,((IHintedType)
>>> type).getSemanticHint(), prefs);
>>>
>>> This gives me an empty element, what I would like is to run something
>>> like:
>>>
>>> ClassNode dummy = new ClassNodeImpl();
>>> dummy.setName("dummy");
>>>
>>> CreateElementRequest eReq = new CreateElementRequest (dummy,
>>> UemlbaseElementTypes.ClassNode_2002);
>>>
>>> Strange that it doesn't work...
>>>
>>>
>>> Thanks,
>>>
>>> Tomas
>>>
>>> Tomas Zijdemans wrote:
>>>> I create an element in an action like this (this gives an "empty"
>>>> element):
>>>>
>>>> IElementType type = UemlbaseElementTypes.ClassNode_2002;
>>>>
>>>> ViewAndElementDescriptor viewDescriptor =
>>>> new ViewAndElementDescriptor(new CreateElementRequestAdapter(
>>>> new CreateElementRequest(type)),Node.class, (
>>>> (IHintedType) type).getSemanticHint(),
>>>> selectedElement.getDiagramPreferencesHint());
>>>>
>>>> Is there any way to "grab" the newly created element (so I can set
>>>> it's properties), or to choose what object is to be created?
>>>>
>>>> (like: ClassNodeImpl dummy = new ClassNodeImpl();
>>>> dummy.setName("dummy");
>>>> ...new CreateElementRequestAdapter(new
>>>> CreateElementRequest(dummy, type))...
>>>>
>>>> - I've tried this, no work :(
>>>>
>>>>
>>>> Thanks,
>>>>
>>>> Tomas
>>
>>
Re: Quick CreateElement question [message #154876 is a reply to message #154869] Thu, 11 October 2007 14:50 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: bmoros.um.es

Tomas,

are you sure you are creating the request in the right way? I do that as
follows:

IElementType type = XXXElementTypes.ModelElement_1001;
CreateViewRequest request =
CreateViewRequestFactory.getCreateShapeRequest(
type,
this.getDiagramPreferencesHint());
After that I do what I sent to you in the last post and it works.

Best regards,

Bego
Re: Quick CreateElement question [message #154885 is a reply to message #154876] Thu, 11 October 2007 17:13 Go to previous message
Eclipse UserFriend
Originally posted by: trommas.yahoo.com

The way I did it earlier didn't work. But everything is fine now. I
struggle to unravel SetReqest.

I guess I should instantiate the SetRequest class with the EObject,
stuctural feature, and Object.

But stuctural features are edges/connections aren't they?

Could you give me an example from your case Begoña?


Thanks,

Tomas

Begoña Moros wrote:
> Tomas,
>
> are you sure you are creating the request in the right way? I do that as
> follows:
>
> IElementType type = XXXElementTypes.ModelElement_1001;
> CreateViewRequest request =
> CreateViewRequestFactory.getCreateShapeRequest(
> type,
> this.getDiagramPreferencesHint());
> After that I do what I sent to you in the last post and it works.
>
> Best regards,
>
> Begoña
>
> "Tomas Zijdemans" <trommas@yahoo.com> escribió en el mensaje
> news:fela9c$1pb$1@build.eclipse.org...
>> Thanks for helping, but the view variable is always null (the if test
>> always fails), any ideas?
>>
>> Thanks,
>>
>> Tomas
>>
>> Begoña Moros wrote:
>>> Hi Tomas,
>>>
>>> you can get the reference of the model element created by means of a
>>> CreateElementRequest as follows:
>>>
>>> IAdaptable viewAdapter = (IAdaptable) ((List)
>>> request.getNewObject()).get(0);
>>>
>>> View view = (View) viewAdapter.getAdapter(View.class);
>>>
>>> if (view != null) {
>>>
>>> ModelElement element = (ModelElement) view.getElement();
>>>
>>> ...
>>>
>>> }
>>>
>>> Once you get the reference to the model element you should change its
>>> attributes by means of creating a SetRequest and executing the command:
>>>
>>> this.getDiagramEditDomain().getDiagramCommandStack().execute (new
>>> ICommandProxy(new SetValueCommand(setRequest)));
>>>
>>>
>>> IHIH
>>>
>>> Begoña
>>>
>>> "Tomas Zijdemans" <trommas@yahoo.com> escribió en el mensaje
>>> news:feitj7$l00$2@build.eclipse.org...
>>>> I've simplified it a bit:
>>>>
>>>> CreateElementRequest eReq = new CreateElementRequest
>>>> (UemlbaseElementTypes.ClassNode_2002);
>>>>
>>>> ViewAndElementDescriptor viewDescriptor = new ViewAndElementDescriptor(
>>>> new CreateElementRequestAdapter(eReq), Node.class,((IHintedType)
>>>> type).getSemanticHint(), prefs);
>>>>
>>>> This gives me an empty element, what I would like is to run something
>>>> like:
>>>>
>>>> ClassNode dummy = new ClassNodeImpl();
>>>> dummy.setName("dummy");
>>>>
>>>> CreateElementRequest eReq = new CreateElementRequest (dummy,
>>>> UemlbaseElementTypes.ClassNode_2002);
>>>>
>>>> Strange that it doesn't work...
>>>>
>>>>
>>>> Thanks,
>>>>
>>>> Tomas
>>>>
>>>> Tomas Zijdemans wrote:
>>>>> I create an element in an action like this (this gives an "empty"
>>>>> element):
>>>>>
>>>>> IElementType type = UemlbaseElementTypes.ClassNode_2002;
>>>>>
>>>>> ViewAndElementDescriptor viewDescriptor =
>>>>> new ViewAndElementDescriptor(new CreateElementRequestAdapter(
>>>>> new CreateElementRequest(type)),Node.class, (
>>>>> (IHintedType) type).getSemanticHint(),
>>>>> selectedElement.getDiagramPreferencesHint());
>>>>>
>>>>> Is there any way to "grab" the newly created element (so I can set it's
>>>>> properties), or to choose what object is to be created?
>>>>>
>>>>> (like: ClassNodeImpl dummy = new ClassNodeImpl();
>>>>> dummy.setName("dummy");
>>>>> ...new CreateElementRequestAdapter(new CreateElementRequest(dummy,
>>>>> type))...
>>>>>
>>>>> - I've tried this, no work :(
>>>>>
>>>>>
>>>>> Thanks,
>>>>>
>>>>> Tomas
>
Previous Topic:Customize the Editor Context Menu?
Next Topic:Swing componets DND on the Editor
Goto Forum:
  


Current Time: Sat Nov 02 18:37:25 GMT 2024

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

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

Back to the top