wiki:CustomizeProperties

Version 1 (modified by jdamerow, 16 years ago) (diff)

--

Customize properties

<back

This section is about customizing properties on the basis of an example.

What I want: My element A has a property of type B. B is something like a file so it has a property "path" of type String. I want a file chooser to choose the file. The path of the file should be stored in the path property of the property B of element A.

What to do:

  • Write a class like the following. This is the file choose itself.
    public class FileChooserCellEditor extends DialogCellEditor {
    
       private Composite parent;
    	
       public FileChooserCellEditor(Composite parent) {
    	super(parent);
    	this.parent = parent;
       }
    
       protected Object openDialogBox(Control cellEditorWindow) {
    	FileDialog dialog = new FileDialog(parent.getShell(), SWT.OPEN);
    	return dialog.open();
       }
    }
    
    
  • Write a property descriptor for all your properties:
    public class ExhibitionPropertyDescriptor extends
    		EMFCompositeSourcePropertyDescriptor {
    
       IItemPropertyDescriptor itemPropertyDescriptor;
    	
       public ExhibitionPropertyDescriptor(Object object,
    		IItemPropertyDescriptor itemPropertyDescriptor, String category) {
    	super(object, itemPropertyDescriptor, category);
    	this.itemPropertyDescriptor = itemPropertyDescriptor;
       }
    
       /* here you can instanciate whatever you want to be 
          opened when the user clicks on the button in the property field
       */
       protected CellEditor doCreateEditor(Composite composite) {
    	if (itemPropertyDescriptor instanceof ImagePropertyDescriptor) {
    	   return new FileChooserCellEditor(composite);
    	}
    	return super.doCreateEditor(composite);
       }
    }