Skip to main content



      Home
Home » Modeling » EMF » property descriptor with choice of values plus user entered values
property descriptor with choice of values plus user entered values [message #1061508] Sat, 01 June 2013 08:11 Go to next message
Eclipse UserFriend
I'm trying to create a property descriptor that provides a combo box with a choice of values but I also want the user to be able to type in any value even if it is not already in the list. I have overridden the getChoiceOfValues method so I now have a combo box with a list to choose from but I can't enter custom values. How can I do this?

Thanks.
Greg
Re: property descriptor with choice of values plus user entered values [message #1061518 is a reply to message #1061508] Sat, 01 June 2013 13:24 Go to previous messageGo to next message
Eclipse UserFriend
Greg,

That's not supported out of the box:
http://wiki.eclipse.org/EMF/Recipes#Recipe:_Create_your_own_property_editor_in_a_generated_application
On 01/06/2013 2:11 PM, Greg Mising name wrote:
> I'm trying to create a property descriptor that provides a combo box
> with a choice of values but I also want the user to be able to type in
> any value even if it is not already in the list. I have overridden
> the getChoiceOfValues method so I now have a combo box with a list to
> choose from but I can't enter custom values. How can I do this?
>
> Thanks.
> Greg
Re: property descriptor with choice of values plus user entered values [message #1061666 is a reply to message #1061518] Mon, 03 June 2013 08:29 Go to previous messageGo to next message
Eclipse UserFriend
Thanks Ed. I have followed the recipe that you referred to but I am still having problems adding the user entered value to the list. In the code below I am overriding the doGetValue method of the cell editor and trying to update the list by adding the user entered value if it's not already in the list. When I try entering a new value it still just sets the property to null, adding a blank entry to the list. Any thoughts on where I'm going wrong here? Thanks.

public class DWAdapterFactoryContentProvider extends AdapterFactoryContentProvider {

	public DWAdapterFactoryContentProvider(AdapterFactory adapterFactory) {
		super(adapterFactory);
	}
	
	@Override
	protected IPropertySource createPropertySource(Object object, IItemPropertySource itemPropertySource) {
		return new PropertySource(object, itemPropertySource) {
			@Override
			 protected IPropertyDescriptor createPropertyDescriptor(IItemPropertyDescriptor itemPropertyDescriptor)
			  {
			    return new PropertyDescriptor(object, itemPropertyDescriptor) {
			    	@Override
			    	public CellEditor createPropertyEditor(Composite composite) {
			    		Object genericFeature = itemPropertyDescriptor.getFeature(object);
			    		if ( genericFeature instanceof EStructuralFeature )
			    	    {
			    	      final EStructuralFeature feature = (EStructuralFeature)genericFeature;
			    	      if ( feature == DynamicWarehousePackage.eINSTANCE.getLevelReference_Role() ||
			    	    	   feature == DynamicWarehousePackage.eINSTANCE.getDimensionReference_Role() ) {
			    	    	  return new ExtendedComboBoxCellEditor( composite, 
			    	    			  new ArrayList<Object>( itemPropertyDescriptor.getChoiceOfValues(object) ), 
			    	    			  getEditLabelProvider(), true, SWT.NONE ) {
			    	    		  
			    	    		  CCombo control;
			    	    		  
			    	    		  @Override
			    	    		  protected Control createControl(Composite parent) {
			    	    			 control = (CCombo) super.createControl(parent); 
			    	    			 return control;
			    	    		  }
			    	    		  
			    	    		  @Override
			    	    		  public Object doGetValue() {
			    	    			  String newValue = control.getText();
			    	    			  Object selectedValue = super.doGetValue();
			    	    			  if ( selectedValue == null && newValue != null ) {
			    	    				  String[] list = new String[getItems().length + 1];
			    	    				  list[0] = newValue;
			    	    				  for ( int i = 0; i < getItems().length; i++ ) {
			    	    					  list[i + 1] = getItems()[i];
			    	    				  }
			    	    				  setItems( list );
			    	    				  return super.doGetValue();
			    	    			  }
			    	    			  return selectedValue;
			    	    		  }
			    	    	  };
			    	      }
			    	    }
			    		
			    		return super.createPropertyEditor(composite);
			    	}
			    };
			  }
		};
	}

}
Re: property descriptor with choice of values plus user entered values [message #1061676 is a reply to message #1061666] Mon, 03 June 2013 09:04 Go to previous message
Eclipse UserFriend
Greg,

Comments below.

On 03/06/2013 2:29 PM, Greg Mising name wrote:
> Thanks Ed. I have followed the recipe that you referred to but I am
> still having problems adding the user entered value to the list.
Mostly this comes down to JFace things...
> In the code below I am overriding the doGetValue method of the cell
> editor and trying to update the list by adding the user entered value
> if it's not already in the list. When I try entering a new value it
> still just sets the property to null, adding a blank entry to the
> list. Any thoughts on where I'm going wrong here? Thanks.
>
>
> public class DWAdapterFactoryContentProvider extends
> AdapterFactoryContentProvider {
>
> public DWAdapterFactoryContentProvider(AdapterFactory
> adapterFactory) {
> super(adapterFactory);
> }
>
> @Override
> protected IPropertySource createPropertySource(Object object,
> IItemPropertySource itemPropertySource) {
> return new PropertySource(object, itemPropertySource) {
> @Override
> protected IPropertyDescriptor
> createPropertyDescriptor(IItemPropertyDescriptor itemPropertyDescriptor)
> {
> return new PropertyDescriptor(object,
> itemPropertyDescriptor) {
> @Override
> public CellEditor createPropertyEditor(Composite
> composite) {
> Object genericFeature =
> itemPropertyDescriptor.getFeature(object);
> if ( genericFeature instanceof
> EStructuralFeature )
> {
> final EStructuralFeature feature =
> (EStructuralFeature)genericFeature;
> if ( feature ==
> DynamicWarehousePackage.eINSTANCE.getLevelReference_Role() ||
> feature ==
> DynamicWarehousePackage.eINSTANCE.getDimensionReference_Role() ) {
> return new ExtendedComboBoxCellEditor(
> composite, new
> ArrayList<Object>( itemPropertyDescriptor.getChoiceOfValues(object) ),
> getEditLabelProvider(), true,
> SWT.NONE ) {
I don't think this widget can do what you want... You'll need to use
some JFace/SWT thing that actually supports both a drop down and an
entry field.
> CCombo control;
> @Override
> protected Control
> createControl(Composite parent) {
> control = (CCombo)
> super.createControl(parent); return control;
> }
> @Override
> public Object doGetValue() {
> String newValue =
> control.getText();
> Object selectedValue =
> super.doGetValue();
So this is trying to add the current value of the feature to the choices
of values. The rests of the choices come from the property descriptor
itself?
> if ( selectedValue == null && newValue != null ) {
> String[] list = new
> String[getItems().length + 1];
> list[0] = newValue;
> for ( int i = 0; i <
> getItems().length; i++ ) {
> list[i + 1] =
> getItems()[i];
> }
> setItems( list );
> return super.doGetValue();
> }
> return selectedValue;
> }
> };
> }
> }
>
> return super.createPropertyEditor(composite);
> }
> };
> }
> };
> }
>
> }

Start by doing just the basic JFace/SWT things, i.e., a widget that can
possibly behave how you want, and then look at using it as a custom EMF
property editor.
Previous Topic:Standalone Java Application
Next Topic:[CDO] CDOTransaction or CDOXATransaction participating in XA transaction
Goto Forum:
  


Current Time: Mon Jul 14 18:00:40 EDT 2025

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

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

Back to the top