Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
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 Go to next message
Laurent Le Moux is currently offline Laurent Le MouxFriend
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 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
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 Go to previous messageGo to next message
Laurent Le Moux is currently offline Laurent Le MouxFriend
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 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
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/
Re: Switch between editable and readonly for an EMF property [message #1139047 is a reply to message #1138912] Tue, 15 October 2013 13:55 Go to previous messageGo to next message
Laurent Le Moux is currently offline Laurent Le MouxFriend
Messages: 184
Registered: September 2011
Senior Member
Thanks for the tip. I'll have to investigate this because I found no way in XXAdapterFactory#getAdapter to access my "home made" XXItemPropertyDescriptor#setSettable.
Re: Switch between editable and readonly for an EMF property [message #1140271 is a reply to message #1139047] Wed, 16 October 2013 08:38 Go to previous message
Laurent Le Moux is currently offline Laurent Le MouxFriend
Messages: 184
Registered: September 2011
Senior Member
Hi Ed,

Just a short message to let you know your advice was the right one (and a good approach for my use case).
In createPropertyEditor(Composite composite), I simply forward the call (with return super.createPropertyEditor(composite)), except when the user tries to edit a diagram element in an editor which is not the "defining" one. Then, I return null.
It could not be easier...

Regards,

Laurent
Previous Topic:EMF 2.9 memory improvements
Next Topic:xcore derived list of objects
Goto Forum:
  


Current Time: Wed Apr 24 17:25:18 GMT 2024

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

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

Back to the top