简体   繁体   English

SWT,TreeViewer,带ComboBox的CellEditor

[英]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); 在TreeViewer中为treeColumn使用EditingSupport时,有什么方法可以在View中反映更改,而不是更改模型,然后使用getViewer()。update(element,null);

Detail: I want to achieve the following functionality: Show a tree View with |Object| 详细信息:我想实现以下功能:使用| 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. 我正在使用TreeViewer,在其中有一列启用了EditingSupport的列。 Whenever I select a value from the ComboBox and click somewhere else (lostFocus kind of ) the Value sets to default. 每当我从ComboBox中选择一个值,然后单击其他位置(lostFocus类)时,该值就会设置为默认值。 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); 我已经知道在调用SetValue()之后再次调用TreeLabelProvider(使用调试点)有什么方法可以反映视图中的更改而不是更改模型并使用getViewer()。update(element,null );

Some FYIs : Package Object contains multiple versions 一些FYI:包对象包含多个版本

ContentProvider does the job to fetch the object ContentProvider完成获取对象的工作

LabelProvider gets all the Versions from the package(String[]) and shows the first one. LabelProvider从package(String [])获取所有版本,并显示第一个。


//Code to Create the UI // blah //创建UI的代码//等等

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 OperationEditingSupport类

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 当我单击column2的单元格时,我会看到组合框,但是当我选择某项并将焦点移到其他位置时,它再次显示默认值

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. 在调试时,我发现:它再次调用标签Provider,该标签将获取包的所有版本,然后显示第一个,因此我看不到任何更改。

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. 将以下代码添加到SetValue()方法即可解决该问题。

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 );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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