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:
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.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);
}
}