Home » Modeling » EMF » Switch between editable and readonly for an EMF property(Best way to achieve this at runtime ?)
Switch between editable and readonly for an EMF property [message #1137042] |
Mon, 14 October 2013 08:16 |
Laurent Le Moux Messages: 184 Registered: September 2011 |
Senior Member |
|
|
Hi all,
I have two different Graphiti editors. Both display a same object in their diagram.
When selecting this object, I want it to be editable when one editor is active and readonly when I switch to the other editor.
To achieve this, I modified for the object the corresponding XXItemProvider as follow :
public List<IItemPropertyDescriptor> getPropertyDescriptors(Object object) {
// Force the reset of the ItemPropertyDescriptors for each object selection.
if (itemPropertyDescriptors != null)
itemPropertyDescriptors.clear();
super.getPropertyDescriptors(object);
addNamePropertyDescriptor(object);
return itemPropertyDescriptors;
}
protected void addNamePropertyDescriptor(Object object) {
// Make the object property editable or readonly depending on the active editor.
boolean isSettable = true;
String edType = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
.getActiveEditor().getClass().getSimpleName();
if (edType.compareTo("ServiceGraphitiEditor") != 0)
isSettable = false;
itemPropertyDescriptors.add
(createItemPropertyDescriptor
(((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(),
getResourceLocator(),
getString("_UI_Operation_Name_feature"),
getString("_UI_PropertyDescriptor_description", "_UI_Operation_Name_feature", "_UI_Operation_type"),
ServicePackage.Literals.OPERATION__NAME,
isSettable,
false,
false,
ItemPropertyDescriptor.GENERIC_VALUE_IMAGE,
null,
null));
}
I compare the active editor name with the one I'm interested in without using 'instanceof' in order not to import my Graphiti project and create a circular dependency.
I also have to "flush" the ItemPropertyDescriptor list at each object selection to be able to switch back and forth between the editable and readonly states.
All this is not very satisfying. I would have prefered to change the isSettable attribute of the ItemPropertyDescriptor somehow in AdapterFactory#getAdapter in the project using the generated emf.edit plugin.
Is their a way to do this ? I found no "changeSettable"-like method in ItemPropertyDescriptor.
Kind regards,
Laurent
|
|
|
Re: Switch between editable and readonly for an EMF property [message #1138363 is a reply to message #1137042] |
Tue, 15 October 2013 04:00 |
Ed Merks Messages: 33145 Registered: July 2009 |
Senior Member |
|
|
Laurent,
Comments below.
On 14/10/2013 10:17 AM, Laurent Le Moux wrote:
> Hi all,
>
> I have two different Graphiti editors. Both display a same object in
> their diagram.
Actually the same in-memory instance?
> When selecting this object, I want it to be editable when one editor
> is active and readonly when I switch to the other editor.
>
> To achieve this, I modified for the object the corresponding
> XXItemProvider as follow :
>
>
> public List<IItemPropertyDescriptor> getPropertyDescriptors(Object
> object) {
Are the two editors even sharing the same item provider?
> // Force the reset of the ItemPropertyDescriptors for each object
> selection.
> if (itemPropertyDescriptors != null)
> itemPropertyDescriptors.clear();
> super.getPropertyDescriptors(object);
> addNamePropertyDescriptor(object);
> return itemPropertyDescriptors;
> }
>
>
>
> protected void addNamePropertyDescriptor(Object object) {
> // Make the object property editable or readonly depending on
> the active editor.
> boolean isSettable = true;
> String edType =
> PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
> .getActiveEditor().getClass().getSimpleName();
> if (edType.compareTo("ServiceGraphitiEditor") != 0)
> isSettable = false;
>
> itemPropertyDescriptors.add
> (createItemPropertyDescriptor
> (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(),
> getResourceLocator(),
> getString("_UI_Operation_Name_feature"),
> getString("_UI_PropertyDescriptor_description",
> "_UI_Operation_Name_feature", "_UI_Operation_type"),
> ServicePackage.Literals.OPERATION__NAME,
> isSettable,
> false,
> false,
> ItemPropertyDescriptor.GENERIC_VALUE_IMAGE,
> null,
> null));
> }
>
>
> I compare the active editor name with the one I'm interested in
> without using 'instanceof' in order not to import my Graphiti project
> and create a circular dependency.
>
> I also have to "flush" the ItemPropertyDescriptor list at each object
> selection to be able to switch back and forth between the editable and
> readonly states.
Because the item providers are shared across the two editors?
>
> All this is not very satisfying. I would have prefered to change the
> isSettable attribute of the ItemPropertyDescriptor somehow in
> AdapterFactory#getAdapter in the project using the generated emf.edit
> plugin.
That's always possible if you have a specialized class you use for that.
>
> Is their a way to do this ? I found no "changeSettable"-like method in
> ItemPropertyDescriptor.
Just implement your own.
But in the end, this looks very messy. Normally if I want different
editors or even views within an editor to show things differently, I use
different item provider implementations, so the editor itself would have
a specialized item provider adapter factory with a specialized item
provider that overrides addNamePropertyDescriptor to return a read only
one...
>
> Kind regards,
>
> Laurent
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: Switch between editable and readonly for an EMF property [message #1138713 is a reply to message #1138363] |
Tue, 15 October 2013 09:20 |
Laurent Le Moux Messages: 184 Registered: September 2011 |
Senior Member |
|
|
Hi Ed,
Thank you for answering me again. I still have a lot of things to learn about EMF and Eclipse...
To answer your questions :
- The object displayed in both editors is the same memory instance.
- The two editors are sharing the same item provider (and I defined only one XXAdpaterFactory for both diagrams).
I now understand I have to override ItemProviderAdapter#createItemPropertyDescriptor to return an object extending ItemPropertyDescriptor that will provide some kind of 'setSettable' method. Then, I'll have to find how to access my object again from XXAdapter#getAdapter...
That said, I undestand why it looks messy to you. If I were implementing different editors based on distinct underlying models, I agree I should provide the implementation you described.
But, I consider my underlying model as a whole (even if I split it over several ecore files). From there, my editors are just different views of this model.
The displayed object is the same and - up to now - I also didn't feel the need to display its properties in a different way.
The only thing is, in my use case, it makes no real sense to allow the object modification outside its definition scope, that is in another view than the one where the object was created. Moreover, I want to ensure my global underlying model consistency.
So, in editors were the object is only used / referenced, it should be readonly. Whereas, in the editor where it has been created, it should be editable.
The consequence for the user is, of course, that he needs to double click on the object to open its defining diagram and get aware of its "creation context" before he decides to change something.
This prevent from "blindly" modifying an object from any available view.
Does this use case sound so strange to you ? If not (anymore), what about having EMF generator providing an ItemPropertyDescriptor#setSettable ?
Regards,
Laurent
|
|
|
Re: Switch between editable and readonly for an EMF property [message #1138912 is a reply to message #1138713] |
Tue, 15 October 2013 12:04 |
Ed Merks Messages: 33145 Registered: July 2009 |
Senior Member |
|
|
Laurent,
I see. I wonder if the editor could do this more generally by
specializing
org.eclipse.emf.edit.ui.provider.PropertyDescriptor.createPropertyEditor(Composite)
using the same technique as in
http://wiki.eclipse.org/EMF/Recipes#Recipe:_Create_your_own_property_editor_in_a_generated_application.
Then the editor could disable editing of properties in a more global
though editor-specific fashion... Not sure if that helps...
On 15/10/2013 11:20 AM, Laurent Le Moux wrote:
> Hi Ed,
>
> Thank you for answering me again. I still have a lot of things to
> learn about EMF and Eclipse...
>
> To answer your questions :
> - The object displayed in both editors is the same memory instance.
> - The two editors are sharing the same item provider (and I defined
> only one XXAdpaterFactory for both diagrams).
>
> I now understand I have to override
> ItemProviderAdapter#createItemPropertyDescriptor to return an object
> extending ItemPropertyDescriptor that will provide some kind of
> 'setSettable' method. Then, I'll have to find how to access my object
> again from XXAdapter#getAdapter...
>
> That said, I undestand why it looks messy to you. If I were
> implementing different editors based on distinct underlying models, I
> agree I should provide the implementation you described.
>
> But, I consider my underlying model as a whole (even if I split it
> over several ecore files). From there, my editors are just different
> views of this model.
> The displayed object is the same and - up to now - I also didn't feel
> the need to display its properties in a different way.
>
> The only thing is, in my use case, it makes no real sense to allow the
> object modification outside its definition scope, that is in another
> view than the one where the object was created. Moreover, I want to
> ensure my global underlying model consistency.
>
> So, in editors were the object is only used / referenced, it should be
> readonly. Whereas, in the editor where it has been created, it should
> be editable.
> The consequence for the user is, of course, that he needs to double
> click on the object to open its defining diagram and get aware of its
> "creation context" before he decides to change something.
> This prevent from "blindly" modifying an object from any available view.
>
> Does this use case sound so strange to you ? If not (anymore), what
> about having EMF generator providing an
> ItemPropertyDescriptor#setSettable ?
>
> Regards,
>
> Laurent
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
| | |
Goto Forum:
Current Time: Mon May 06 03:22:07 GMT 2024
Powered by FUDForum. Page generated in 0.03947 seconds
|