property descriptor with choice of values plus user entered values [message #1061508] |
Sat, 01 June 2013 08:11  |
Eclipse User |
|
|
|
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 #1061676 is a reply to message #1061666] |
Mon, 03 June 2013 09:04  |
Eclipse User |
|
|
|
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.
|
|
|
Powered by
FUDForum. Page generated in 0.04993 seconds