简体   繁体   English

JFace - 如何根据同一行中另一列的复选框值在 TreeViewer 中只编辑一列?

[英]JFace - How can I make only one column editable in TreeViewer based on checkbox value from another column in the same row?

I have a TreeViewer which has two columns: ProximityClustersColumn : which has names as String, selectionColumn: which has checkbox as shown in the figure TreeViewer我有一个TreeViewer ,它有两列: ProximityClustersColumn :它的名称为 String, selectionColumn :它具有如图TreeViewer所示的复选框

I have two questions:我有两个问题:

  1. On clicking the selection column's checkbox, the corresponding name of ProximityClustersColumn should become editable.单击选择列的复选框后, ProximityClustersColumn的相应名称ProximityClustersColumn为可编辑状态。 For eg: When I click on the checkbox corresponding to "Studium organisieren-Formelles", the cell "Studium organisieren-Formelles" should become editable.例如:当我点击“Studium Organisieren-Formelles”对应的复选框时,单元格“Studium Organisieren-Formelles”应该可以编辑。

  2. Also, as seen in the figure, a check must be made such that only one value in the group, whose checkbox is checked becomes editable.此外,如图所示,必须进行检查,以便组中只有一个值,其复选框被选中成为可编辑的。 In other words, for each group, only one category name can be checked and that corresponding name should be editable.换句话说,对于每一组,只能检查一个类别名称,并且对应的名称应该是可编辑的。 For eg: If you look at the second group, there are two proximity Cluster names, ie "Infos für Studis" and "Finanzielles im Studium", along with their respective checkboxes.例如:如果您查看第二组,则有两个邻近集群名称,即“Infos für Studis”和“Finanzielles im Studium”,以及它们各自的复选框。 Now, I can choose one among the two names, by selecting the corresponding checkbox.现在,我可以通过选择相应的复选框在两个名称中选择一个。 Suppose, I click on the checkbox corresponding to "Infos für Studis", only that cell should become editable.假设,我点击了与“Infos für Studis”对应的复选框,只有那个单元格应该可以编辑。

The main idea is that : I should be able to select only one name from each group and edit it.主要思想是:我应该只能从每个组中选择一个名称并进行编辑。

I have tried EditingSupport as suggested by @keyur, but the "canEdit" method is not called at all.我已经按照@keyur 的建议尝试了 EditingSupport,但根本没有调用“canEdit”方法。

My LabelProvider extends ColumnLabelProvider and implements ITableLabelProvider.我的 LabelProvider 扩展了 ColumnLabelProvider 并实现了 ITableLabelProvider。 My ContentProvider implements ITreeContentProvider.我的 ContentProvider 实现了 ITreeContentProvider。

Is there any reason why EditingSupport will fail? EditingSupport 会失败有什么原因吗?

public class ProximityClustersEditingSupport extends EditingSupport{
    private TreeViewer viewer;
    private CellEditor editor;

      public ProximityClustersEditingSupport(ColumnViewer columnViewer, TreeViewer treeViewer) {
        super(columnViewer);
        this.viewer = treeViewer;
        this.editor = new TextCellEditor(treeViewer.getTree());
      }

      @Override
      protected CellEditor getCellEditor(Object element) {
        return new TextCellEditor();
      }

      @Override
      protected boolean canEdit(Object element) {
        return true;
      }

      @Override
      protected Object getValue(Object element) {
          if(element instanceof ProbeSort)
                return ((ProximityClusters)element).proximityClusterNames;
                return element;
      }

      @Override
      protected void setValue(Object element, Object value) {
          if (element instanceof ProbeSort)
            {
                 ((ProximityClusters)element).setProximityClusterNames(String.valueOf(value));
            }
            viewer.update(element, null);
      }
}

I think I need more information to answer it completely.我想我需要更多信息才能完整回答。 First of all is that Treeviewer or Tableviewer.首先是 Treeviewer 或 Tableviewer。 To me it looks like TableViewer.对我来说它看起来像 TableViewer。

  1. What is the expected behavior of the cell when you mean editable.当您的意思是可编辑时,单元格的预期行为是什么。 Those cells which are not editable should have disable type foreground colored text and the one which is editable can have normal foreground color say black.那些不可编辑的单元格应该有禁用类型的前景色文本,可编辑的可以有正常的前景色,比如黑色。 Only when user changes to focus (if tab is supported) or by clicking on the cell it is better to show the editable text where user can select the text and change/edit it.仅当用户更改焦点(如果支持选项卡)或单击单元格时,最好显示可编辑文本,用户可以在其中选择文本并更改/编辑它。 And pressing Enter key or Tab Key program can accept the change.并按 Enter 键或 Tab Key 程序可以接受更改。 Is that what you are looking for?这就是你要找的吗?

  2. I guess I didnt get the question.我想我没有得到这个问题。 Can you give example from the above figure.你能举出上图中的例子吗? Like what is group?比如什么是群?

I think EditingSupport will be useful for you.我认为EditingSupport对你有用。

You can create your concrete EditingSupport class and assign it to your column.您可以创建具体的 EditingSupport 类并将其分配给您的列。 It has method "canEdit" through which you can control the editing dynamically.它具有“canEdit”方法,您可以通过该方法动态控制编辑。

So what you have to do is to store the boolean flag in the model from checkbox status or read the check box status directly and return false/true value , which will enable/disable editing.因此,您需要做的是将布尔标志从复选框状态存储在模型中,或者直接读取复选框状态并返回 false/true 值,这将启用/禁用编辑。

The program in the link shows all possible Tree viewer related implementations. 链接中的程序显示了所有可能的与树查看器相关的实现。 Copy paste the program into a new java class and run as java application.将程序复制粘贴到一个新的 java 类中并作为 java 应用程序运行。 This one example solved all tree related issues i had in my implementation.这个例子解决了我在实现中遇到的所有与树相关的问题。

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

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