javajfacetreeviewer

How to get the Keyboard curser focus to edit the label text, when we double click on CheckboxTreeViewer selected item


public class MyLabelProvider extends LabelProvider {

    @Override
    public Image getImage(Object element) {
        return createImage(imagePath);
    }

    @Override
    public String getText(Object element) {
        return MessageFormat.format((String)element); // CheckBOxTreeViewer, AA, BBB //and etc.
    }

    @Override
    public void dispose() {

    }

}


public class MyContentProvider implements ITreeContentProvider, IViewerListener {

    private CheckboxTreeViewer viewer;
  @Override
    public void inputChanged(Viewer viewer, Object oldInput, Object NewInput) {

    }

    @Override
    public Object[] getElements(Object inputElement) {
    }

    @Override
    public Object[] getChildren(Object parentElement) {
    }
    @Override
    public Object getParent(Object element) {
    }
    @Override
    public boolean hasChildren(Object element) {
    }
    @Override
    public void refreshOnlyContent(Object element) {
    }
    @Override
    public void refreshOnlyLabels() {
    }
    @Override
    public void refreshEverything(Object element) {
    }

    @Override
    public void dispose() {
    }
}


public class MyClass {

@PostConstruct
    public void postConstruct(Composite composite) {

CheckboxTreeViewer   treeViewer = new CheckboxTreeViewer(Composite);

MyContentProvider contentProvider = new MyContentProvider ();

treeViewer.setContentProvider(contentProvider);

IViewerListener  viewerListener = contentProvider;

treeViewer.setLabelProvider(new MyLabelProvider ());

treeViewer.addDoubleClickListener(new IDoubleClickListener() {

 @Override
public void doubleClick(DoubleClickEvent event) {

      //editor cursor focus code
  }
});

}
}

How to edit CheckboxTreeViewer label text.

In this project example label texts are CheckBOxTreeViewer, AA, BBB and etc.

How to get the Keyboard cursor focus inorder to edit the label text, when we double click on CheckboxTreeViewer item. CheckboxTreeViewer Image


Solution

  • Edition is not like in AWT/Swing.

    you need to use on the treeViewer:

    If you want the edition on double click:

    TreeViewerEditor.create(treeViewer, new ColumnViewerEditorActivationStrategy(treeViewer){
        protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {  
            return event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION;
        }
    

    You can check this very interesting article as well: http://ramkulkarni.com/blog/in-place-editing-in-eclipse-treeviewer/