简体   繁体   中英

SWT , TreeViewer , CellEditor with ComboBox

While using EditingSupport for a treeColumn in a TreeViewer, Is there any way i can just reflect the Changes in the View instead of changing the model and then using getViewer().update(element,null);

Detail: I want to achieve the following functionality: Show a tree View with |Object| (ComboBox)property| Upon selection and clicking on the button i want to show user the summary of changes and then upon clicking confirm i want to apply those changes to the model (Object)

I am using a TreeViewer, Within that i have a column with EditingSupport Enabled. Whenever I select a value from the ComboBox and click somewhere else (lostFocus kind of ) the Value sets to default. I have figured out that after SetValue() is called the TreeLabelProvider is again called(using debug points) Is there any way i can just reflect the Changes in the View instead of changing the model and using getViewer().update(element,null);

Some FYIs : Package Object contains multiple versions

ContentProvider does the job to fetch the object

LabelProvider gets all the Versions from the package(String[]) and shows the first one.


//Code to Create the UI // blah

TreeViewerColumn column2 = new TreeViewerColumn(treeViewer, SWT.LEFT);
        column2.getColumn().setText("Version");
        column2.getColumn().setWidth(130);
        treeViewer.setLabelProvider(new PackageUpdateTreeLabelProvider());
        EditingSupport exampleEditingSupport = new OperationEditingSupport(
                column2.getViewer());
        column2.setEditingSupport(exampleEditingSupport);

OperationEditingSupport Class

private class OperationEditingSupport extends EditingSupport {
        private ComboBoxCellEditor cellEditor = null;

        private OperationEditingSupport(ColumnViewer viewer) {
            super(viewer);

            cellEditor = new ComboBoxCellEditor(
                    ((TreeViewer) viewer).getTree(), new String[] {},
                    SWT.READ_ONLY);

        }

        @Override
        protected CellEditor getCellEditor(Object element) {
            // TODO Auto-generated method stub

            if (element instanceof IPackageInfo) {
                IPackageInfo pkg = (IPackageInfo) element;
                cellEditor.setItems(PackageMgrUtil.getInstance().getVersions(
                        (IdmPackage) pkg, false, true));
                return cellEditor;
            }
            return null;
        }

        @Override
        protected boolean canEdit(Object element) {

            return true;
        }

        @Override
        protected Object getValue(Object element) {
            // TODO Auto-generated method stub

            return 0;
        }

        @Override
        protected void setValue(Object element, Object value) {

            /* only set new value if it differs from old one */

        }


    }
***************************************************

When i click on the cell of column2 i get the combo box but when i select something and move the focus somewhere else.It again shows the default Value

on debuging i found that : it agains calls the label Provider which fetches all the Version of the package and then shows the first one hence I can not see any change.

what i want is that it should keep the selection intact without changing the underlying object.

thanks for the help.

Figured it out. following code added to the SetValue() method solves it.

m_tree = (Tree)getViewer.getControl();
TreeItem[] ti = m_tree.getSelection();
            CCombo c = ((CCombo)cellEditor.getControl());
            String str = c.getItem(c.getSelectionIndex());
            ti[0].setText(1, str );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM