Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » TreeViewerEditor: Multi select / column width?(Resizing a treeviews column to the entire views width?)
TreeViewerEditor: Multi select / column width? [message #755509] Tue, 08 November 2011 11:47 Go to next message
Missing name Missing name is currently offline Missing name Missing name
Messages: 6
Registered: November 2011
Junior Member
Hi,

I am a view which displays a tree (treeview). I am trying to make the nodes editable to change the text of the nodes on double click.
I found TreeViewerEditor as JFace solution for achieving that, however TreeViewerEditor introduced 2 new problems to me I can't figure out.

1) I have to make use of TreeViewerColumn as well which forces me to give a column width in pixel. My view has only one column, so it shall be as wide as the view is

2) For some reason, TreeViewerEditor does not allow me to see multi selection (but it is yet performed). Due to the above problem I have plenty of space which is not used by the TreeViewerColumn and what is shown as single-line select in the TreeViewerColumn is shown as multi-line select in the underlying TreeView (see attached screenshot)- how do I fix that?

Hier is the code for the view creation
public class BookmarkView extends ViewPart {

	private TreeViewer viewer;

	@Override
	public void createPartControl(Composite parent) {
		
		viewer = new TreeViewer(parent, SWT.MULTI |  SWT.H_SCROLL | SWT.V_SCROLL);
		
		int operations = DND.DROP_LINK;
		Transfer[] transferTypes = new Transfer[] { TextTransfer.getInstance(),
				ResourceTransfer.getInstance() };

		TreeModel model = new TreeModel();
		viewer.addDropSupport(operations, transferTypes, new TreeDropListener(
				viewer, model));
		viewer.addDragSupport(operations, transferTypes, new TreeDragListener(
				viewer));
		viewer.setContentProvider(new TreeContentProvider());
		viewer.setLabelProvider(new TreeLabelProvider());
		viewer.setInput(model.getModelRoot());
		

		ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(
				viewer) {
			protected boolean isEditorActivationEvent(
					ColumnViewerEditorActivationEvent event) {
				return event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL
						|| event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION
						|| (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && event.keyCode == SWT.CR)
						|| event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;
			}
		};

		TreeViewerFocusCellManager focusCellManager = new TreeViewerFocusCellManager(
				viewer, new FocusCellOwnerDrawHighlighter(viewer));
		
		TreeViewerEditor.create(viewer, focusCellManager, actSupport,
				ColumnViewerEditor.TABBING_HORIZONTAL
						| ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR
						| ColumnViewerEditor.TABBING_VERTICAL
						| ColumnViewerEditor.KEYBOARD_ACTIVATION);

		final TextCellEditor textCellEditor = new TextCellEditor(
				viewer.getTree());

		
		TreeViewerColumn column = new TreeViewerColumn(viewer, SWT.MULTI);
		column.getColumn().setWidth(100); //<------- Requires fixed pixel value?????
		column.getColumn().setMoveable(true);
//		column.getColumn().setText("Name");
		column.setLabelProvider(new TreeLabelProvider());
		column.setEditingSupport(new EditingSupport(viewer) {
			protected boolean canEdit(Object element) {
				return true;
			}

			protected CellEditor getCellEditor(Object element) {
				return textCellEditor;
			}

			protected Object getValue(Object element) {
				if (element instanceof TreeNode) {
					return ((TreeNode) element).getText();
				}
				return element.toString();
			}

			protected void setValue(Object element, Object value) {
				if (element instanceof BookmarkNode) {
					((BookmarkNode) element).setText(String.valueOf(value));
				}
				viewer.update(element, null);
			}
		});
		
  • Attachment: bild.jpg
    (Size: 24.59KB, Downloaded 111 times)
Re: TreeViewerEditor: Multi select / column width? [message #755596 is a reply to message #755509] Tue, 08 November 2011 16:47 Go to previous message
Missing name Missing name is currently offline Missing name Missing name
Messages: 6
Registered: November 2011
Junior Member
I think my problem is related to these lines:

TreeViewerEditor.create(viewer, focusCellManager, actSupport,
				ColumnViewerEditor.TABBING_HORIZONTAL
						| ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR
						| ColumnViewerEditor.TABBING_VERTICAL
						| ColumnViewerEditor.KEYBOARD_ACTIVATION);

		final TextCellEditor textCellEditor = new TextCellEditor(
				viewer.getTree());
		

		TreeViewerColumn column = new TreeViewerColumn(viewer, SWT.MULTI | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL);
		column.getColumn().setWidth(100);
		column.getColumn().setMoveable(true);
		column.setLabelProvider(new TreeLabelProvider());
		column.setEditingSupport(new EditingSupport(viewer) {/*.....*/}


For making my nodes in my tree editable to change their names I have to redefine TreeViewerColumn to add a "EditingSupport". But things like multi select and use the entire width available get lost by creating a new column. Any ideas?
Previous Topic:Eclipse Jface Wizard
Next Topic:[Databinding] JSR-303 support for JFace Databinding Validators
Goto Forum:
  


Current Time: Wed Jul 30 13:33:40 EDT 2014

Powered by FUDForum. Page generated in 0.01624 seconds