How to open a custom dialog for a property in a Custom Property Tab? [message #150923] |
Mon, 17 September 2007 06:07 |
Eclipse User |
|
|
|
Originally posted by: michael.dev.NOSPAM.gmx.de
Hello All,
GMF 2 uses a Custom Property Tab named Core by default that uses a
AdvancedPropertySection and a DecoratingLabelProvider. I could not
figure out how to extend this mechanism to allow a property to open a
custom dialog. All samples I found refer to a different architecture.
Can anyone please show me how to make it possible for a property to open
a custom dialog. It would be great if you can provide a small code
sample but any hint could help. I do not like to use the Standard
Property Tab "Advanced" because it shows unwanted additional properties.
Thanks in advance.
Michael
|
|
|
|
Re: How to open a custom dialog for a property in a Custom Property Tab? [message #171708 is a reply to message #170864] |
Wed, 06 February 2008 21:49 |
Eclipse User |
|
|
|
Originally posted by: vinsarwate.rediffmail.com
One of my colleague gave me this idea and it might help you as well -
1. In generated diagram editor code, see
XXXPropertySection.getPropertySource(Object) method. This method returns
instances of PropertySource for each object.
2. Change this method to return extend PropertySource instance.
3. Override createPropertyDescriptor() of this extended PropertySource
class and return your own extended version of PropertyDescriptor.
4. In this extended version of PropertyDescriptor, override
createPropertyEditor(Composite) to return your own CellEditor.
Hope this helps.
Vinay
|
|
|
Re: How to open a custom dialog for a property in a Custom Property Tab? [message #171873 is a reply to message #170864] |
Fri, 08 February 2008 12:05 |
Eclipse User |
|
|
|
Originally posted by: marsha.rohrer.swisscom.com
Hi,
You have to write a customized PropertySource which returns your
customized PropertyDescriptror:
public class CustomizedPropertySource extends PropertySource {
public CustomizedPropertySource(Object object,
IItemPropertySource itemPropertySource) {
super(object, itemPropertySource);
}
protected IPropertyDescriptor createPropertyDescriptor(
IItemPropertyDescriptor itemPropertyDescriptor) {
return new CustomizedPropertyDescriptor(object,
itemPropertyDescriptor);
}
}
In your property descriptor you check if the needed property is treated
and open your dialog:
public class CustomizedPropertyDescriptor extends PropertyDescriptor {
public CustomizedPropertyDescriptor(Object object,
IItemPropertyDescriptor itemPropertyDescriptor) {
super(object, itemPropertyDescriptor);
}
public CellEditor createPropertyEditor(Composite composite) {
CellEditor result = super.createPropertyEditor(composite);
if (result == null)
return result;
EClassifier eType = ((EStructuralFeature) itemPropertyDescriptor
.getFeature(object)).getEType();
if (object instanceof Activity) {
if (eType instanceof EDataType) {
EDataType eDataType = (EDataType) eType;
if (eDataType.getInstanceClass() == String.class) {
result = new ExtendedDialogCellEditor(composite,
getEditLabelProvider()) {
protected Object openDialogBox(Control cellEditorWindow) {
//create an new activity dialog instance
ActivitySelectionDialog dialog = new ActivitySelectionDialog(
cellEditorWindow.getShell(),
cellEditorWindow.getParent());
dialog.create();
if (dialog.open() == Window.OK) {
Object dialogResult = dialog.getResult()[0];
if (dialogResult instanceof ActivityFunctionWrapper) {
ActivityFunctionWrapper wrap = (ActivityFunctionWrapper)
dialogResult;
String res = wrap.getActivity()
.getActivityName()
+ ":"
+ wrap.getFunction()
.getFunctionName();
return res;
}
return null;
}
return null;
}
};
}
}
}
if (object instanceof Flow) {
if (eType instanceof EDataType) {
EDataType eDataType = (EDataType) eType;
if (eDataType.getInstanceClass() == String.class) {
result = new ExtendedDialogCellEditor(composite,
getEditLabelProvider()) {
protected Object openDialogBox(Control cellEditorWindow) {
//create a flow dialog instance
FlowSelectionDialog dialog = new FlowSelectionDialog(
cellEditorWindow.getShell());
dialog.create();
if (dialog.open() == Window.OK) {
Object dialogResult = dialog.getResult()[0];
if (dialogResult instanceof FlowReference) {
FlowReference flow = (FlowReference) dialogResult;
String res = flow.getFlowName() + ":"
+ flow.getVersion();
return res;
}
return null;
}
return null;
}
};
}
}
}
return result;
}
}
In your generated project you can find XXXPropertySection.java which
actually returns a PropertySource. Change that code to return your custom
PropertySource and then the dialog should open.
|
|
|
Powered by
FUDForum. Page generated in 0.02839 seconds