Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Modify gmf Property sheet(How Can I modify the property sheet?)
Modify gmf Property sheet [message #550809] Wed, 04 August 2010 12:13 Go to next message
Pablo Nieto is currently offline Pablo Nieto
Messages: 31
Registered: August 2010
Location: Cuenca, Spain
Member
Hello I´m making a gmf editor and I want to modify the property sheet. I Would like to add a text editor (3 dot button ...) , for label editing, instead of the normal editor, because in those labels I will introduce source code.

Does anyone how to do this?

Tanks, Pablo Nieto
Re: Modify gmf Property sheet [message #551057 is a reply to message #550809] Thu, 05 August 2010 05:04 Go to previous messageGo to next message
Robert Wloch is currently offline Robert Wloch
Messages: 109
Registered: July 2009
Senior Member
Hi Pablo,

The property sheets are filled using you generated EMF edit plugin. Have a look at the providers and how the return PropertyDescriptors. You'll want to return your own PropertyDescriptor that overrides the createPropertyEditor() method to return an editor that extends ExtendedDialogCellEditor.

Rob
Re: Modify gmf Property sheet [message #551081 is a reply to message #551057] Thu, 05 August 2010 07:29 Go to previous messageGo to next message
Pablo Nieto is currently offline Pablo Nieto
Messages: 31
Registered: August 2010
Location: Cuenca, Spain
Member
Hello Rob,
Where can I find the createPropertyEditor() method?

I have been looking at my generated source code, and I have not found that method. I´m quite new in gmf and I´m a bit lost.


Thanks
Re: Modify gmf Property sheet [message #551156 is a reply to message #551081] Thu, 05 August 2010 13:06 Go to previous messageGo to next message
Robert Wloch is currently offline Robert Wloch
Messages: 109
Registered: July 2009
Senior Member
Hi Pablo,

Pablo Nieto wrote on Thu, 05 August 2010 03:29
Hello Rob,
Where can I find the createPropertyEditor() method?



This ain't simple, so don't worry. It took me 3 weeks to figure that all out. Smile

Its default implementation is in org.eclipse.emf.edit.ui.provider.PropertyDescriptor.

To override it, open the XXXItemProvider class in your domain model's edit plugin. There you'll find this method:
	public List<IItemPropertyDescriptor> getPropertyDescriptors(Object object) {
		if (itemPropertyDescriptors == null) {
			super.getPropertyDescriptors(object);

			add<LabelFeatureName>PropertyDescriptor(object);
			...
		}
		return itemPropertyDescriptors;
	}


The add<LabelFeatureName>PropertyDescriptor() method is in the same ItemProvider class further below. If you look at it, you'll find that it adds an ItemPropertyDescriptor to a list using a generic createItemPropertyDescriptor() method. You need to remove the call of that createIPD() method and create your own instead:

itemPropertyDescriptors.add(new MyLabelItemPropertyDescriptor(...);


The implementation of MyLabelItemPropertyDescriptor could look something like this:
public class MyLabelItemPropertyDescriptor extends ItemPropertyDescriptor {
	public MyLabelItemPropertyDescriptor(AdapterFactory adapterFactory, ResourceLocator resourceLocator,
			String displayName, String description, EStructuralFeature feature, boolean isSettable, String category) {
		super(adapterFactory, resourceLocator, displayName, description, feature, isSettable, false, true, null,
				category, null);
	}

	@Override
	protected Collection<?> getComboBoxObjects(Object object) {
		EObject eObject = (EObject) object;
		if (<YourDomain>Package.Literals.<DOMAIN_CLASS>__<LABEL_FEATURE>.equals(feature)) {
			...
			return <result>;
		}
		return super.getComboBoxObjects(object);
	}

	@Override
	public Object getPropertyValue(Object object) {
		EObject eObject = (EObject) object;
		if (<YourDomain>Package.Literals.<DOMAIN_CLASS>__<LABEL_FEATURE>.equals(feature)) {
			...
			return createPropertyValueWrapper(...);
		}
		return super.getPropertyValue(object);
	}

	@Override
	public void setPropertyValue(Object object, Object value) {
		...
	}

	@Override
	protected Object createPropertyValueWrapper(Object object, Object propertyValue) {
		...
	}

}


Now you have your own ItemPropertyDescriptor. In you generated gmf diagram there is a package called "sheet" and it contains a XXXPropertySection class. That class has a method getPropertySource() and it is responsible for returning a PropertySource for a model object. It needs to be changed to this:
	/**
	 * @generated NOT
	 */
	public IPropertySource getPropertySource(Object object) {
		if (object instanceof IPropertySource) {
			return (IPropertySource) object;
		}
		AdapterFactory af = getAdapterFactory(object);
		if (af != null) {
			if (object instanceof <LabelFeatureContainingDomainElement>) {
				IItemPropertySource ips = (IItemPropertySource) af.adapt(object, IItemPropertySource.class);
				return new MyLabelPropertySource(object, ips);
			}
			IItemPropertySource ips = (IItemPropertySource) af.adapt(object, IItemPropertySource.class);
			if (ips != null) {
				return new PropertySource(object, ips);
			}
		}
		if (object instanceof IAdaptable) {
			return (IPropertySource) ((IAdaptable) object).getAdapter(IPropertySource.class);
		}
		return null;
	}


Don't forget the @generated NOT in the javadoc comment of the method! The getPropertySource() method will create a MyLabelPropertySource class. This one is simple:

public class MyLabelPropertySource extends PropertySource {
	public MyLabelPropertySource(Object object, IItemPropertySource itemPropertySource) {
		super(object, itemPropertySource);
	}

	@Override
	protected IPropertyDescriptor createPropertyDescriptor(IItemPropertyDescriptor itemPropertyDescriptor) {
		if (itemPropertyDescriptor instanceof MyLabelItemPropertyDescriptor) {
			return new MyLabelPropertyDescriptor(object, itemPropertyDescriptor);
		}
		return super.createPropertyDescriptor(itemPropertyDescriptor);
	}
}


It checks if a property descriptor for the earlier defined MyLabelItemPropertyDescriptor is required. If so, then it creates an instance of MyLabelPropertyDescriptor. The latter is extending org.eclipse.emf.edit.ui.provider.PropertyDescriptor and will override createPropertyEditor(), finally:

public class MyLabelPropertyDescriptor extends PropertyDescriptor {
	@Override
	public CellEditor createPropertyEditor(Composite composite) {
		ILabelProvider editLabelProvider = getEditLabelProvider();
		return new ExtendedDialogCellEditor(composite, editLabelProvider) {
			@Override
			protected void updateContents(Object object) {
				...
			}

			@Override
			protected Object openDialogBox(Control cellEditorWindow) {
				...
			}

			@Override
			protected void doSetValue(Object value) {
				...
			}

		};
	}
});


You probably need to implement all of those @override annotated methods. I used anonymous inner classes, but you might want to create real classes instead.

Take my pardon for any errors in the above snippets, but it's quite a lot as you see.

Quote:

I have been looking at my generated source code, and I have not found that method. I´m quite new in gmf and I´m a bit lost.



Quote:

Thanks



Rob
Re: Modify gmf Property sheet [message #551393 is a reply to message #551156] Fri, 06 August 2010 09:23 Go to previous messageGo to next message
Pablo Nieto is currently offline Pablo Nieto
Messages: 31
Registered: August 2010
Location: Cuenca, Spain
Member
Thank you very much, Rob. I didn´t know that all this code existed.

I´ve been looking my code, and I have modified this a little. But now, I have two more questions:

- Which of those @override annotated methods do I need to modify, for adding a text editor?
I have been looking, and I don´t know which ones I have to modify and which not. I think that some of these methods don´t have to be modified, for example, getProperty and setPropertyMethods.
am I right?
This is because the property will be the same, the only thing that it changes is the way of editing.

-The second Question is:
How I call this editor?

Sorry if I am tedious, but I´m trying yet understanding all this code.

Thanks again, Pablo Nieto




Re: Modify gmf Property sheet [message #551667 is a reply to message #551393] Mon, 09 August 2010 05:46 Go to previous messageGo to next message
Robert Wloch is currently offline Robert Wloch
Messages: 109
Registered: July 2009
Senior Member
Hi Pablo,

comments below...

Pablo Nieto wrote on Fri, 06 August 2010 05:23
Thank you very much, Rob. I didn´t know that all this code existed.

I´ve been looking my code, and I have modified this a little. But now, I have two more questions:

- Which of those @override annotated methods do I need to modify, for adding a text editor?


You need to implement at least the 3 override methods of ExtendedDialogCellEditor in the MyLabelPropertyDescriptor#createPropertyEditor(Composite composite) method.

Don't forget to hook the MyLabelPropertySource in order to return an instance of MyLabelPropertyDescriptor. If you don't do this, your property sheet won't change to show the "..." button.
Quote:

I have been looking, and I don´t know which ones I have to modify and which not. I think that some of these methods don´t have to be modified, for example, getProperty and setPropertyMethods.
am I right?


Right, you might not need them, but you never know.

Quote:

This is because the property will be the same, the only thing that it changes is the way of editing.

-The second Question is:
How I call this editor?


The ExtendedDialogCellEditor will provide a text label and a button "...". Clicking that button will show the dialog that you specify in your ExtendedDialogCellEditor#openDialogBox() implementation.

Quote:

Sorry if I am tedious, but I´m trying yet understanding all this code.

Thanks again, Pablo Nieto


Don't worry, as I said: It is quite complex. Smile

Rob
Re: Modify gmf Property sheet [message #551719 is a reply to message #551667] Mon, 09 August 2010 10:26 Go to previous messageGo to next message
Pablo Nieto is currently offline Pablo Nieto
Messages: 31
Registered: August 2010
Location: Cuenca, Spain
Member
Hello Rob thak you very much for answering.
I have made more modifications in my code, but in the final step appears a lot of errors.

This is MyLabelPropertyDescriptor Class:


public class OnEntryPropertyDescriptor extends PropertyDescriptor{

public OnEntryPropertyDescriptor(Object object, IItemPropertyDescriptor itemPropertyDescriptor) throws IntrospectionException{
super(itemPropertyDescriptor.getDisplayName(object),object.g etClass());
}
//I don´t kwow if this constructor will work or not.
@Override
public CellEditor createPropertyEditor(Composite composite){
//The method createPropertyEditor (Composite) of typeOnEntryPropertyDescriptor must overload or implement a method of supertype
ILabelProvider editLabelProvider;
editLabelProvider= getEditLabelProvider();
// getEditLabelProvider() method doesn´t Exist
return new ExtendedDialogCellEditor(composite)
//ExtendedDialogCellEditor class doesn´t exist (can´t ber resolved as a type)
{
@Override
protected void updateContents(Object object){
...
}
@Override
protected Object openDialogBox(Control cellEditorWindow){
...
}
@Override
protected void doSetValue(Object value){
...
}
};
super.createPropertyEditor(composite);
}


}

now, what do I have to do? How can I resolve these problems?

more or less, the other implemented classes don´t produce any error.

Thanks a lot again, Pablo
Re: Modify gmf Property sheet [message #551860 is a reply to message #551719] Mon, 09 August 2010 19:54 Go to previous messageGo to next message
Robert Wloch is currently offline Robert Wloch
Messages: 109
Registered: July 2009
Senior Member
Quote:

public class OnEntryPropertyDescriptor extends PropertyDescriptor{


Is the import pointing to org.eclipse.emf.edit.ui.provider.PropertyDescriptor? Did you add the plugin org.eclipse.emf.edit.ui as dependency to your manifest (if it's not there already)?

Quote:

public OnEntryPropertyDescriptor(Object object, IItemPropertyDescriptor itemPropertyDescriptor) throws IntrospectionException{
super(itemPropertyDescriptor.getDisplayName(object),object.g etClass());
}
//I don´t kwow if this constructor will work or not.

Me neither. Mine just delegated to super: super(object, itemPropertyDescriptor);
Quote:

@Override
public CellEditor createPropertyEditor(Composite composite){
//The method createPropertyEditor (Composite) of typeOnEntryPropertyDescriptor must overload or implement a method of supertype


This warning is an indication for a wrong import of PropertyDescriptor!
Quote:

ILabelProvider editLabelProvider;
editLabelProvider= getEditLabelProvider();
// getEditLabelProvider() method doesn´t Exist


This error is an indication for a wrong import of PropertyDescriptor, too!
Quote:

return new ExtendedDialogCellEditor(composite)
//ExtendedDialogCellEditor class doesn´t exist (can´t ber resolved as a type)


The class in my Galileo Eclipse installation is: org.eclipse.emf.common.ui.celleditor.ExtendedDialogCellEdito r
This error is an indication for a wrong import or a missing plugin dependency to org.eclipse.emf.common.ui!

I figured this all out for Eclipse 3.5 (Galileo) and haven't tried it with 3.6 (Helios) yet. There's a chance that classes were moved or API had changed. Maybe Ed Merks can comment on this?

Rob


Re: Modify gmf Property sheet [message #551986 is a reply to message #551860] Tue, 10 August 2010 12:16 Go to previous messageGo to next message
Pablo Nieto is currently offline Pablo Nieto
Messages: 31
Registered: August 2010
Location: Cuenca, Spain
Member
Hello Rob, thanks again.

I have corrected my code. You were right i´ve imported a wrong package, because they have the same name, but different paths.

Now in my editor appears de ... button but when I click it, nothing happens. I think that it is because the openDialogBox() method is wrong. How can I make to appear the editor? What methods do I have to use?

After this, is anythig more to do?

Thanks again, Pablo


Re: Modify gmf Property sheet [message #552163 is a reply to message #551986] Wed, 11 August 2010 07:05 Go to previous messageGo to next message
Robert Wloch is currently offline Robert Wloch
Messages: 109
Registered: July 2009
Senior Member
If you could post your implementation of createCellEditor() and your ExtendedDialogCellEditor it would be easier for me to help you get the dialog displayed. It's very hard to tell why it doesn't show up without seeing some code.

Rob
Re: Modify gmf Property sheet [message #552167 is a reply to message #552163] Wed, 11 August 2010 07:20 Go to previous messageGo to next message
Pablo Nieto is currently offline Pablo Nieto
Messages: 31
Registered: August 2010
Location: Cuenca, Spain
Member
I didn´t incude any code because I don´t know how make it to appear. My openDialogBox method is empty.
I´ve been seing some implementations on the internet but I don´t understand how to make that.

Do I have to make a new class for the specific editor dialog?

thanks, Pablo
Re: Modify gmf Property sheet [message #552225 is a reply to message #552167] Wed, 11 August 2010 11:00 Go to previous messageGo to next message
Pablo Nieto is currently offline Pablo Nieto
Messages: 31
Registered: August 2010
Location: Cuenca, Spain
Member
Hi Rob, I´ve created a new class for defining my "own editor", and I have made it to appear. Very Happy

This editor has a text area and a comboBox. Now, how can I save in a gmf editor label, the text that has been intoduced in the text area?

I save this text in a field, using the textEditor´s getText() method, but outside my "own editor", I don´t know how to manage this.

By other side, i have to do the inverse procedure, get the saved text and put it in my "own editor" when I open it.

Thanks again, Pablo

Re: Modify gmf Property sheet [message #552281 is a reply to message #552167] Wed, 11 August 2010 15:01 Go to previous messageGo to next message
Robert Wloch is currently offline Robert Wloch
Messages: 109
Registered: July 2009
Senior Member
Check these links for examples of SWT Dialogs:
http://www.java2s.com/Code/Java/SWT-JFace-Eclipse/Howtocreat eyourowndialogclasses.htm
http://www.java2s.com/Code/Java/SWT-JFace-Eclipse/Dialog.htm
Re: Modify gmf Property sheet [message #552284 is a reply to message #552225] Wed, 11 August 2010 15:08 Go to previous messageGo to next message
Robert Wloch is currently offline Robert Wloch
Messages: 109
Registered: July 2009
Senior Member
Hi Pablo,

this is quite simple: The return value of the method "protected Object openDialogBox(Control cellEditorWindow)" is the value that will be set to your model elements feature automagically. So, all you need to do is return your dialog's text value there.

Rob
Re: Modify gmf Property sheet [message #552500 is a reply to message #552284] Thu, 12 August 2010 11:53 Go to previous messageGo to next message
Pablo Nieto is currently offline Pablo Nieto
Messages: 31
Registered: August 2010
Location: Cuenca, Spain
Member
Hello Rob

I have noticed that it was quite easy Laughing but I have a new problem (i´m becoming crazy), this is the code:

protected Object openDialogBox(Control cellEditorWindow) {
EditorDialog dialog = //My own Editor
new EditorDialog(cellEditorWindow.getShell(),"OnExit");
return dialog.Code;

};

If I do this, dialog.Code is equal to null, because threads aren´t Synchronized. After that I´ve created a new method in my 'own Editor' called Synchronize:

public void synchronize(Shell parent)
{
padre=parent;
if(this.textSetted==false)
{
try {
System.out.println("SynchronizeWait");
parent.wait();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
else
{
System.out.println("SynchronizeNotify");
parent.notifyAll();

}
}

After that, I´ve modified the openDialogBox method as you can see below:

protected Object openDialogBox(Control cellEditorWindow) {
EditorDialog dialog = new EditorDialog(cellEditorWindow.getShell(),"OnExit");
dialog.synchronize(cellEditorWindow.getShell());
System.out.println(dialog.Code); //notify test
return dialog.Code;

}

Now, the Cell editor thread gets suspended, the notify method is invoked, but nothing happens. The parent thread (cellEditorWindow.getShell) continues waiting instead of to continue.

I´ve debugged the code, but I don´t know why it happens.

Do you know why? Do you Know any other way to do this?

Thanks a lot, Pablo.
Re: Modify gmf Property sheet [message #552537 is a reply to message #552500] Thu, 12 August 2010 14:58 Go to previous messageGo to next message
Robert Wloch is currently offline Robert Wloch
Messages: 109
Registered: July 2009
Senior Member
Hi Pablo,

I think letting your Shell wait is not a good idea at all.

A better approach would be to have some kind of performOk() method that takes the text value from the dialog when OK is pressed and stores it in a variable of EditorDialog. To access that variable use a method like "getTextValue()".

From your openDialogBox(Control cellEditorWindow) code I assume that your EditorDialog's constructor also opens the dialog?
If so, then it is not good. Instead, have the constructor just create the EditorDialog class and not more. But also provide a method called "open()" or "show()" in EditorDialog. That method should not return until the user has pressed OK.

Then your openDialogBox(Control cellEditorWindow) should look like that:
protected Object openDialogBox(Control cellEditorWindow) {
EditorDialog dialog = new EditorDialog(cellEditorWindow.getShell(),"OnExit");
dialog.open();
System.out.println(dialog.getTextValue()); //show text value
return dialog.getTextValue();
}


Rob
Re: Modify gmf Property sheet [message #552735 is a reply to message #552537] Fri, 13 August 2010 10:26 Go to previous messageGo to next message
Pablo Nieto is currently offline Pablo Nieto
Messages: 31
Registered: August 2010
Location: Cuenca, Spain
Member
Hello Rob.

This is the way I do (The same as you told me):

protected Object openDialogBox(Control cellEditorWindow) {
dialog = new EditorDialog(cellEditorWindow.getShell(),"OnExit");
dialog.open();
System.out.println(dialog.getTextValue());
return dialog.getTextValue();
}

In my own editor class:

public void open()
{
this.sShellEditor.open();
}

//This method is called when Ok button is pressed.
public void performOk(){

Code=this.textAreaCodigo.getText();
this.sShellEditor.close();

}

Now the problem is that when my own editor is shown, the dialog.code field is equal to null, so the openDialogbox method returns null.
However, when I press the Ok button nothing happens, because the openDialogBox() method has finished.
Is there any way to make the openDialogBox method to wait?
I´ve done that with a while loop, but it produces an infinite loop.

Thanks again, Pablo
Re: Modify gmf Property sheet [message #554111 is a reply to message #552735] Fri, 20 August 2010 08:25 Go to previous messageGo to next message
Pablo Nieto is currently offline Pablo Nieto
Messages: 31
Registered: August 2010
Location: Cuenca, Spain
Member
Hi, Do you have any solution?

thanks, Pablo.
Re: Modify gmf Property sheet [message #716413 is a reply to message #551057] Wed, 17 August 2011 11:06 Go to previous messageGo to next message
vinny503 Missing name is currently offline vinny503 Missing name
Messages: 156
Registered: August 2011
Senior Member
Hi

I am newbei to GMF...
If I want to add new parameters dynamically to the property window for a
specific node in gmf..How it can be done....
Please help me regarding this...I am stuck at this stage...

thanks,
Vinay
Re: Modify gmf Property sheet [message #716415 is a reply to message #551057] Wed, 17 August 2011 11:12 Go to previous messageGo to next message
vinny503 Missing name is currently offline vinny503 Missing name
Messages: 156
Registered: August 2011
Senior Member
Hi

I am newbei to GMF...
If I want to add new parameters dynamically to the property window for a
specific node in gmf..How it can be done....
Please help me regarding this...I am stuck at this stage...

thanks,
Vinay
Re: Modify gmf Property sheet [message #716711 is a reply to message #716415] Thu, 18 August 2011 07:45 Go to previous messageGo to next message
Ralph Gerbig is currently offline Ralph Gerbig
Messages: 697
Registered: November 2009
Senior Member
Hi vinny503,

it would be useful to open a own thread for your question instead of answering to unrelated threads. Your current behaviour pollutes the threads and results if some uses a search to search for a certain topic.

Thans,

Ralph
Re: Modify gmf Property sheet [message #717021 is a reply to message #716711] Fri, 19 August 2011 05:26 Go to previous messageGo to next message
vinny503 Missing name is currently offline vinny503 Missing name
Messages: 156
Registered: August 2011
Senior Member
Hi

I am sorry for that....I will open a new thread.

Regards,
Vinay
Re: Modify gmf Property sheet [message #720848 is a reply to message #552735] Wed, 31 August 2011 10:58 Go to previous messageGo to next message
vinny503 Missing name is currently offline vinny503 Missing name
Messages: 156
Registered: August 2011
Senior Member
Hi

I am newbei to GMF...
The parameters that are displayed on the property window in GMF is in Aphabetical order....
How can I modify this to display them in my own format...

Thanks,
Vinny
Re: Modify gmf Property sheet [message #721637 is a reply to message #720848] Fri, 02 September 2011 11:44 Go to previous messageGo to next message
pavithra Missing name is currently offline pavithra Missing name
Messages: 12
Registered: May 2011
Junior Member
Thanks Robert Wloch , You saved my day. It works!!

I had some confusions about labelItemPropertyDescriptor and labelPropertyDescriptor. But finally got it.
Re: Modify gmf Property sheet [message #732167 is a reply to message #721637] Tue, 04 October 2011 06:32 Go to previous messageGo to next message
vinny503 Missing name is currently offline vinny503 Missing name
Messages: 156
Registered: August 2011
Senior Member
Hi Pavithra,

Do you know any idea on how to highlight some of the parameters on the property window ?

Thanks,
Vinay
Re: Modify gmf Property sheet [message #732264 is a reply to message #721637] Tue, 04 October 2011 11:06 Go to previous message
vinny503 Missing name is currently offline vinny503 Missing name
Messages: 156
Registered: August 2011
Senior Member
Hi Pavithra,

Can you please provide the following methods Implemented...
getComboBoxObjects()
getPropertyValue()
setPropertyValue()
createPropertyValueWrapper()

Thanks,
Vinay
Previous Topic:[SOLVED] How to make properties non editable
Next Topic:Help with specific layout
Goto Forum:
  


Current Time: Tue Sep 30 10:27:39 GMT 2014

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

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