3

I have a TreeViewer which has two columns: ProximityClustersColumn: which has names as String, selectionColumn: which has checkbox as shown in the figure TreeViewer

I have two questions:

  1. On clicking the selection column's checkbox, the corresponding name of ProximityClustersColumn should become editable. For eg: When I click on the checkbox corresponding to "Studium organisieren-Formelles", the cell "Studium organisieren-Formelles" should become editable.

  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, i.e "Infos für Studis" and "Finanzielles im Studium", along with their respective checkboxes. 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.

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.

My LabelProvider extends ColumnLabelProvider and implements ITableLabelProvider. My ContentProvider implements ITreeContentProvider.

Is there any reason why EditingSupport will fail?

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);
      }
}
anjalli
  • 53
  • 6

3 Answers3

0

I think I need more information to answer it completely. First of all is that Treeviewer or Tableviewer. To me it looks like 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. 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?

Dileep K V
  • 53
  • 7
  • Hi I have edited my question and figure to make it more clear. It is a treeviewer, with its label provider extending ITableLabelProvider. By editable, I mean I should be able to rename the names. – anjalli Apr 20 '16 at 17:14
0

I think EditingSupport will be useful for you.

You can create your concrete EditingSupport class and assign it to your column. It has method "canEdit" through which you can control the editing dynamically.

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.

  • I have tried Editing support and assigned to my column, but it doesnt work. "canEdit" button is not called at all. – anjalli Apr 25 '16 at 13:13
  • "canEdit" button ?? I think you mistyped it. have you tried to put breakpoints?. will have to see the code for further help. – Keyur Mahajan Apr 25 '16 at 13:35
  • Sorry for the typo. Yes I have posted the code above. I tried with breakpoints and the tree viewer is not clickable, it does not go beyond the line : super(columnViewer); in my ProximityClustersEditingSupport constructor – anjalli Apr 25 '16 at 13:52
  • @anjalli. What i can see is you have created new TextCellEditor() in getCellEditor method. Although you have already created editor in the constructor itself using tree as your parent. so just return editor in the same method. Right now there is no parent to texteditor as you are creating simple new instance of it. – Keyur Mahajan Apr 25 '16 at 15:14
  • I have overlooked that. I have mentioned as "editor" yet there is no result. Now the debug occurs until this.editor = new TextCellEditor(treeViewer.getTree()) and terminates. Here is the code how I have included the editing support in treeviewer column: proximityClustersColumn.setEditingSupport(new ProximityClustersEditingSupport(proximityClustersColumn.getViewer(), viewer)); – anjalli Apr 25 '16 at 16:18
  • I hope you know that canEdit method will only be called when you select particular column cell. Do you able to edit the value in the cell now? – Keyur Mahajan Apr 25 '16 at 17:32
  • Yes, I know what canEdit means. The problem is: I have used a treeviewer with labelprovider that extends ColumnLabelProvider and implements ITableLabelProvider. I guess this is the reason why editing is not supported and a workaround is crucial. – anjalli Apr 25 '16 at 20:00
  • ok. I had implemented almost similar feature in a Table a year ago. I had table with labelprovider which extended LabelProvider and implements ITableLabelProvider and used EditingSupport. I dont understand what is going wrong in your case. – Keyur Mahajan Apr 26 '16 at 04:07
0

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. This one example solved all tree related issues i had in my implementation.

LathaPatil
  • 143
  • 1
  • 3
  • 9