Home » Modeling » GMF (Graphical Modeling Framework) » Modify gmf Property sheet(How Can I modify the property sheet?)
| | |
Re: Modify gmf Property sheet [message #551156 is a reply to message #551081] |
Thu, 05 August 2010 13:06 |
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.
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.
|
Rob
|
|
|
Re: Modify gmf Property sheet [message #551393 is a reply to message #551156] |
Fri, 06 August 2010 09:23 |
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 |
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.
Rob
|
|
| | | | | |
Re: Modify gmf Property sheet [message #552225 is a reply to message #552167] |
Wed, 11 August 2010 11:00 |
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.
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 #552500 is a reply to message #552284] |
Thu, 12 August 2010 11:53 |
Pablo Nieto Messages: 31 Registered: August 2010 Location: Cuenca, Spain |
Member |
|
|
Hello Rob
I have noticed that it was quite easy 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.
|
|
| | | | | | | | | | | |
Goto Forum:
Current Time: Wed Sep 25 23:34:26 GMT 2024
Powered by FUDForum. Page generated in 0.06429 seconds
|