Home » Modeling » GMF (Graphical Modeling Framework) » How to programmaticly change an EMF attribute value outside an edit part
How to programmaticly change an EMF attribute value outside an edit part [message #517611] |
Mon, 01 March 2010 14:29 |
Marco Messages: 27 Registered: July 2009 |
Junior Member |
|
|
Hello GMF-Experts,
I would like to change the value of an EMF attribute YYY programmaticly.
I already tried it the following way (inside the edit part of the model
element, intended to modify):
getEditingDomain().getCommandStack().execute(
SetCommand.create(getEditingDomain(),
((ShapeImpl) getModel()).getElement(),
XXXPackage.eINSTANCE.getYYY(),
"new value of attribute"));
It works fine, but the problem is, I need to have a reference to my
EditPart.
Is there any way to change an EMF attribute value outside an edit part,
without having a reference on it? The attribute YYY should be changed in
the element, which is currently selected in the diagram editor.
It would be very kind, if you had any advice for me. Thank you very much!
Regards,
Marco
|
|
|
Re: How to programmaticly change an EMF attribute value outside an edit part [message #517616 is a reply to message #517611] |
Mon, 01 March 2010 14:38 |
Ed Merks Messages: 33142 Registered: July 2009 |
Senior Member |
|
|
Marco,
Comments below.
Marco wrote:
> Hello GMF-Experts,
>
> I would like to change the value of an EMF attribute YYY programmaticly.
>
> I already tried it the following way (inside the edit part of the
> model element, intended to modify):
>
> getEditingDomain().getCommandStack().execute(
> SetCommand.create(getEditingDomain(),
> ((ShapeImpl) getModel()).getElement(),
> XXXPackage.eINSTANCE.getYYY(),
> "new value of attribute"));
>
> It works fine, but the problem is, I need to have a reference to my
> EditPart.
Where's the reference to the edit part?
AdapterFactoryEditingDomain.getEditingDomainFor(...) probably helps if
you're referring to the getEditingDomain() call.
>
> Is there any way to change an EMF attribute value outside an edit
> part, without having a reference on it? The attribute YYY should be
> changed in the element, which is currently selected in the diagram
> editor.
>
> It would be very kind, if you had any advice for me. Thank you very much!
>
> Regards,
> Marco
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: How to programmaticly change an EMF attribute value outside an edit part [message #517639 is a reply to message #517616] |
Mon, 01 March 2010 15:09 |
Marco Messages: 27 Registered: July 2009 |
Junior Member |
|
|
Hello Ed,
thank you for your advice. But how can I get a reference to the EObject,
which belongs to the currently selected element in the diagram editor?
Regards,
Marco
Ed Merks schrieb:
> Marco,
>
> Comments below.
>
> Marco wrote:
>> Hello GMF-Experts,
>>
>> I would like to change the value of an EMF attribute YYY programmaticly.
>>
>> I already tried it the following way (inside the edit part of the
>> model element, intended to modify):
>>
>> getEditingDomain().getCommandStack().execute(
>> SetCommand.create(getEditingDomain(),
>> ((ShapeImpl) getModel()).getElement(),
>> XXXPackage.eINSTANCE.getYYY(),
>> "new value of attribute"));
>>
>> It works fine, but the problem is, I need to have a reference to my
>> EditPart.
> Where's the reference to the edit part?
> AdapterFactoryEditingDomain.getEditingDomainFor(...) probably helps if
> you're referring to the getEditingDomain() call.
>>
>> Is there any way to change an EMF attribute value outside an edit
>> part, without having a reference on it? The attribute YYY should be
>> changed in the element, which is currently selected in the diagram
>> editor.
>>
>> It would be very kind, if you had any advice for me. Thank you very much!
>>
>> Regards,
>> Marco
|
|
|
Re: How to programmaticly change an EMF attribute value outside an edit part [message #517652 is a reply to message #517639] |
Mon, 01 March 2010 10:56 |
Ed Merks Messages: 33142 Registered: July 2009 |
Senior Member |
|
|
Marco,
I can't answer a question like this without context. Obviously one
needs to start from somewhere with something, but I don't know where you
are nor what you've got your hands on at that point. Typically Actions
will be passed the selection upon which they operate and hence directly
have access to the object that's needed.
Marco wrote:
> Hello Ed,
>
> thank you for your advice. But how can I get a reference to the
> EObject, which belongs to the currently selected element in the
> diagram editor?
>
> Regards,
> Marco
>
>
> Ed Merks schrieb:
>> Marco,
>>
>> Comments below.
>>
>> Marco wrote:
>>> Hello GMF-Experts,
>>>
>>> I would like to change the value of an EMF attribute YYY
>>> programmaticly.
>>>
>>> I already tried it the following way (inside the edit part of the
>>> model element, intended to modify):
>>>
>>> getEditingDomain().getCommandStack().execute(
>>> SetCommand.create(getEditingDomain(),
>>> ((ShapeImpl) getModel()).getElement(),
>>> XXXPackage.eINSTANCE.getYYY(),
>>> "new value of attribute"));
>>>
>>> It works fine, but the problem is, I need to have a reference to my
>>> EditPart.
>> Where's the reference to the edit part?
>> AdapterFactoryEditingDomain.getEditingDomainFor(...) probably helps
>> if you're referring to the getEditingDomain() call.
>>>
>>> Is there any way to change an EMF attribute value outside an edit
>>> part, without having a reference on it? The attribute YYY should be
>>> changed in the element, which is currently selected in the diagram
>>> editor.
>>>
>>> It would be very kind, if you had any advice for me. Thank you very
>>> much!
>>>
>>> Regards,
>>> Marco
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: How to programmaticly change an EMF attribute value outside an edit part [message #517664 is a reply to message #517652] |
Mon, 01 March 2010 11:16 |
Marco Messages: 27 Registered: July 2009 |
Junior Member |
|
|
Hello Ed,
I will try to precise my use case:
1. When the user selects an element in the diagram editor, its
EMF-Attributes should be loaded and visualized in a "Custom View" (like
in the Properties view).
2. When the user performs a special action in that "Custom View", then
some of the EMF-Attributes of the currently selected element in the
diagram view should be changed (like I already mentioned in my first post).
The "Custom View", from which the change-operation is trigerred, has no
explicit reference to the EObject or the EditPart. I'm searching for a
way, to globaly access the desired element through the workbench.
Can you give me any advice, please?
Kind regards,
Marco
Ed Merks schrieb:
> Marco,
>
> I can't answer a question like this without context. Obviously one
> needs to start from somewhere with something, but I don't know where you
> are nor what you've got your hands on at that point. Typically Actions
> will be passed the selection upon which they operate and hence directly
> have access to the object that's needed.
>
>
> Marco wrote:
>> Hello Ed,
>>
>> thank you for your advice. But how can I get a reference to the
>> EObject, which belongs to the currently selected element in the
>> diagram editor?
>>
>> Regards,
>> Marco
>>
>>
>> Ed Merks schrieb:
>>> Marco,
>>>
>>> Comments below.
>>>
>>> Marco wrote:
>>>> Hello GMF-Experts,
>>>>
>>>> I would like to change the value of an EMF attribute YYY
>>>> programmaticly.
>>>>
>>>> I already tried it the following way (inside the edit part of the
>>>> model element, intended to modify):
>>>>
>>>> getEditingDomain().getCommandStack().execute(
>>>> SetCommand.create(getEditingDomain(),
>>>> ((ShapeImpl) getModel()).getElement(),
>>>> XXXPackage.eINSTANCE.getYYY(),
>>>> "new value of attribute"));
>>>>
>>>> It works fine, but the problem is, I need to have a reference to my
>>>> EditPart.
>>> Where's the reference to the edit part?
>>> AdapterFactoryEditingDomain.getEditingDomainFor(...) probably helps
>>> if you're referring to the getEditingDomain() call.
>>>>
>>>> Is there any way to change an EMF attribute value outside an edit
>>>> part, without having a reference on it? The attribute YYY should be
>>>> changed in the element, which is currently selected in the diagram
>>>> editor.
>>>>
>>>> It would be very kind, if you had any advice for me. Thank you very
>>>> much!
>>>>
>>>> Regards,
>>>> Marco
|
|
|
Re: How to programmaticly change an EMF attribute value outside an edit part [message #517687 is a reply to message #517664] |
Mon, 01 March 2010 17:25 |
Ed Merks Messages: 33142 Registered: July 2009 |
Senior Member |
|
|
Marco,
Comments below.
Marco wrote:
> Hello Ed,
>
> I will try to precise my use case:
>
> 1. When the user selects an element in the diagram editor, its
> EMF-Attributes should be loaded and visualized in a "Custom View"
> (like in the Properties view).
So the selection of the editor should be used as input to the view.
>
>
> 2. When the user performs a special action in that "Custom View", then
> some of the EMF-Attributes of the currently selected element in the
> diagram view should be changed (like I already mentioned in my first
> post).
So you know the input to the view and that these actions work on that.
>
> The "Custom View", from which the change-operation is trigerred, has
> no explicit reference to the EObject or the EditPart.
How then does it show attributes of something?
> I'm searching for a way, to globaly access the desired element through
> the workbench.
I don't think there is a general way to do that. I suspect your not on
the right track
>
> Can you give me any advice, please?
What else in the IDE is similar to what you're trying to do?
>
> Kind regards,
> Marco
>
>
> Ed Merks schrieb:
>> Marco,
>>
>> I can't answer a question like this without context. Obviously one
>> needs to start from somewhere with something, but I don't know where
>> you are nor what you've got your hands on at that point. Typically
>> Actions will be passed the selection upon which they operate and
>> hence directly have access to the object that's needed.
>>
>>
>> Marco wrote:
>>> Hello Ed,
>>>
>>> thank you for your advice. But how can I get a reference to the
>>> EObject, which belongs to the currently selected element in the
>>> diagram editor?
>>>
>>> Regards,
>>> Marco
>>>
>>>
>>> Ed Merks schrieb:
>>>> Marco,
>>>>
>>>> Comments below.
>>>>
>>>> Marco wrote:
>>>>> Hello GMF-Experts,
>>>>>
>>>>> I would like to change the value of an EMF attribute YYY
>>>>> programmaticly.
>>>>>
>>>>> I already tried it the following way (inside the edit part of the
>>>>> model element, intended to modify):
>>>>>
>>>>> getEditingDomain().getCommandStack().execute(
>>>>> SetCommand.create(getEditingDomain(),
>>>>> ((ShapeImpl) getModel()).getElement(),
>>>>> XXXPackage.eINSTANCE.getYYY(),
>>>>> "new value of attribute"));
>>>>>
>>>>> It works fine, but the problem is, I need to have a reference to
>>>>> my EditPart.
>>>> Where's the reference to the edit part?
>>>> AdapterFactoryEditingDomain.getEditingDomainFor(...) probably helps
>>>> if you're referring to the getEditingDomain() call.
>>>>>
>>>>> Is there any way to change an EMF attribute value outside an edit
>>>>> part, without having a reference on it? The attribute YYY should
>>>>> be changed in the element, which is currently selected in the
>>>>> diagram editor.
>>>>>
>>>>> It would be very kind, if you had any advice for me. Thank you
>>>>> very much!
>>>>>
>>>>> Regards,
>>>>> Marco
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
| | | | | | |
Re: [Solved] How to programmaticly change an EMF attribute value outside an edit part [message #517863 is a reply to message #517839] |
Tue, 02 March 2010 11:35 |
Ed Merks Messages: 33142 Registered: July 2009 |
Senior Member |
|
|
Marco,
Shape inherits from Node which inherits from View which declares the
getElement method. Neither Shape nor ShapeImpl directly declare/define
the getElement method; in both cases it's inherited from View or
ViewImpl. So this can't be the real reason...
Marco wrote:
> Because Shape does not declare a getElement() method.
>
> Ed Merks schrieb:
>> Marco,
>>
>> I wonder why you cast to ShapeImpl rather than to Shape?
>>
>>
>> Marco wrote:
>>> Thank you for all your replys. That was exactly the solution I was
>>> searching for.
>>>
>>> Here is a little example scenario:
>>>
>>>
>>> // Get active editor in workbench
>>> IEditorPart activeEditor = PlatformUI.getWorkbench()
>>> .getActiveWorkbenchWindow().getActivePage().getActiveEditor( );
>>>
>>> // Check, if active editor is a diagram editor
>>> if (activeEditor instanceof DiagramEditor) {
>>>
>>> // Get selected edit part in active editor
>>> List<EditPart> selectedEditParts = ((DiagramEditor) activeEditor)
>>> .getDiagramGraphicalViewer().getSelectedEditParts();
>>>
>>> // Get the primary selected edit part in selection
>>> EditPart editPart = selectedEditParts.get(0);
>>>
>>> // Only handle Image2EditParts
>>> if (editPart instanceof Image2EditPart) {
>>> Image2EditPart image2EditPart = (Image2EditPart) editPart;
>>>
>>> /*
>>> * Change the value of the property 'file' of the selected
>>> * Image2EditPart to 'bla'
>>> */
>>> image2EditPart.getEditingDomain().getCommandStack().execute(
>>> SetCommand.create(image2EditPart.getEditingDomain(),
>>> ((ShapeImpl) image2EditPart.getModel())
>>> .getElement(),
>>> GadModelPackage.eINSTANCE.getImage_File(),
>>> "bla"));
>>> }
>>> }
>>>
>>> Best regards,
>>> Marco
>>>
>>>
>>> Sven Krause schrieb:
>>>> Hi Marco,
>>>>
>>>> xyzDiagramEditor.getDiagramGraphicalViewer().getSelection() or
>>>> xyzDiagramEditor.getDiagramGraphicalViewer().getSelectedEdit Parts()
>>>> does the trick.
>>>>
>>>> Sven
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Goto Forum:
Current Time: Sun Apr 28 02:42:03 GMT 2024
Powered by FUDForum. Page generated in 0.04424 seconds
|