Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » JFace Databinding for editable viewer(Using both Viewer input and ObservableValueEditingSupport)
JFace Databinding for editable viewer [message #896963] Fri, 20 July 2012 14:51
Simon Scholz is currently offline Simon ScholzFriend
Messages: 73
Registered: April 2012
Location: Germany
Member
Hi,

I am implementing something like the following code demonstrates:

        IViewerObservableValue observableWidget= ViewerProperties.input()
                .observe(this.tableViewer);

        IObservableValue observableMapEntry = Observables.observeMapEntry(
                this.writableMap, key);

        UpdateValueStrategy modelToTarget= new UpdateValueStrategy();
        modelToTarget.setConverter(new MyModelConverter);

        UpdateValueStrategy targetToModel= new UpdateValueStrategy();
        targetToModel.setConverter(new MyTargetConverter);

        this.dataBindingContext.bindValue(observableWidget,
                            observableMapEntry, targetToModel, modelToTarget);




The observableMapEntry variable from the writableMap contains an object with the input data for the viewer.
The input data is converted in the MyModelConverter class like this:

    @Override
    public Object convert(Object fromObject) {
        List<ITableRowItem> viewerInput = new ArrayList<ITableRowItem>();
        // ... fill viewerInput List
        return Properties.selfList(ITableRowItem.class).observe(viewerInput);
    }


After I bind the IObservableValues with the DataBindingContext the viewer is filled correctly with the model data.

Now when the Binding of the single values, which are stored inside a Map in the TableRowItem, which should be editable inside the TableViewer, comes into play it becomes difficult.

In order to solve this I derived from the ObservableValueEditingSupport:

public class TableItemEditingSupport extends ObservableValueEditingSupport {

    private ComboBoxViewerCellEditor viewerCellEditor;

// the TableRowItem itself contains a Map, which holds the data for each column of the TableViewer
    private final MapKey key;

// values which are offered in the ComboBoxViewerCellEditor 
    private final ComputedList comboInput;

    /**
     * Constructor.
     * 
     * @param viewer
     *            {@link ColumnViewer}
     * @param databindingContext
     *            {@link DataBindingContext}
     * @param comboInput
     *            {@link ComputedList} which will be used as input for the
     *            {@link CellEditor}
     * @param attributeName
     *            which should be changed in the {@link ITableRowItem}
     */
    public TableItemEditingSupport(ColumnViewer viewer,
            DataBindingContext databindingContext, ComputedList comboInput,
            MapKey key) {
        super(viewer, databindingContext);
        this.comboInput = comboInput;
        this.key = key;
    }

    @Override
    protected IObservableValue doCreateCellEditorObservable(
            CellEditor cellEditor) {
        return ViewersObservables.observeSingleSelection(this.viewerCellEditor
                .getViewer());
    }

    @Override
    protected IObservableValue doCreateElementObservable(Object element,
            ViewerCell cell) {
        if (element instanceof ITableRowItem) {
            IObservableValue observeMapEntry = Observables.observeMapEntry(
                    ((ITableRowItem) element).getAttributesMap(),
                    this.key);
            observeMapEntry.addValueChangeListener(new IValueChangeListener() {

                @Override
                public void handleValueChange(ValueChangeEvent event) {
                    ColumnViewer viewer = getViewer();
                    if (viewer != null && !viewer.getControl().isDisposed()) {
                        System.out.println("Changed value with CellEditor");

                        // here I try to change the Input of the Viewer and hoped that the input binding, which is described above is used. Unfortunately the model with the viewers input is not updated.
                        Object input = viewer.getInput();
                        viewer.setInput(input);
                    }
                }
            });
            return observeMapEntry;
        }
        return null;
    }

    @Override
    protected CellEditor getCellEditor(Object element) {
        if (element instanceof ITableRowItem) {

            viewerCellEditor = new ComboBoxViewerCellEditor(
                    (Composite) getViewer().getControl());
            viewerCellEditor
                    .setContenProvider(new ObservableListContentProvider());
            viewerCellEditor.setLabelProvider(new ComboLabelProvider());
            viewerCellEditor.setInput(this.comboInput);

            Value value = ((ITableRowItem) element)
                    .getValue(attributeName);

            viewerCellEditor.setValue(value
                        .getInternalString());
            

            return viewerCellEditor;
        }
        return null;
    }


Now when I add this ObservableValueEditingSupport class to my Table like this...
     viewerColumn.setEditingSupport(new TableItemEditingSupport(this.tableViewer,
                    this.dataBindingContext, computedValueList,
                    key));


... I can edit the values with that EditingSupport, but the model, which holds the input data of the viewer is not updated, even though I have tried to addValueChangeListener(see code comments of the TableItemEditingSupport), which sets the new input.
The TableRowItem-Model is updated correctly, but how do I update the model, which holds the input data(see first code block of this post)?

Can anyone offer me a hint, how I can connect the model, which holds the input data of the TableViewer, to the EditingSupport, which changes the TableRowItem model?

If you need further information or something is unclear, I will offer the missing information to you.

Thanks in advance.

Best regards,

Simon

[Updated on: Fri, 20 July 2012 15:01]

Report message to a moderator

Previous Topic:Running a 3.x RCP application with Eclipse 4.2
Next Topic:NoClassDefFoundError
Goto Forum:
  


Current Time: Wed Feb 28 17:26:37 GMT 2024

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

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

Back to the top