annotate jface/snippets/Snippet026TreeViewerTabEditing.d @ 137:96a2d0b35360

jface snippets 014, 026, 043, 047
author yidabu <yidabu@gmail.com>
date Wed, 06 Aug 2008 10:03:06 +0800
parents
children 2b4e94cafb85
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
137
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
1 /*******************************************************************************
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
2 * Copyright (c) 2006 Tom Schindl and others.
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
3 * All rights reserved. This program and the accompanying materials
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
4 * are made available under the terms of the Eclipse Public License v1.0
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
5 * which accompanies this distribution, and is available at
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
6 * http://www.eclipse.org/legal/epl-v10.html
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
7 *
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
8 * Contributors:
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
9 * Tom Schindl - initial API and implementation
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
10 * Port to the D programming language:
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
11 * yidabu at gmail dot com ( D China http://www.d-programming-language-china.org/ )
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
12 *******************************************************************************/
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
13
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
14 module jface.snippets.Snippet026TreeViewerTabEditing;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
15
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
16
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
17 import dwtx.jface.viewers.CellEditor;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
18 import dwtx.jface.viewers.ColumnLabelProvider;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
19 import dwtx.jface.viewers.ColumnViewerEditor;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
20 import dwtx.jface.viewers.ColumnViewer;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
21 import dwtx.jface.viewers.ColumnViewerEditorActivationStrategy;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
22 import dwtx.jface.viewers.EditingSupport;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
23 import dwtx.jface.viewers.ColumnViewerEditorActivationEvent;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
24 import dwtx.jface.viewers.FocusCellOwnerDrawHighlighter;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
25 import dwtx.jface.viewers.ITreeContentProvider;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
26 import dwtx.jface.viewers.TextCellEditor;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
27 import dwtx.jface.viewers.TreePath;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
28 import dwtx.jface.viewers.TreeViewerFocusCellManager;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
29 import dwtx.jface.viewers.TreeViewerEditor;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
30 import dwtx.jface.viewers.TreeViewer;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
31 import dwtx.jface.viewers.TreeViewerColumn;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
32 import dwtx.jface.viewers.Viewer;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
33 import dwt.DWT;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
34 import dwt.events.SelectionEvent;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
35 import dwt.events.SelectionListener;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
36 import dwt.layout.FillLayout;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
37 import dwt.widgets.Button;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
38 import dwt.widgets.Display;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
39 import dwt.widgets.Shell;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
40
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
41 import dwt.dwthelper.utils;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
42
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
43 import tango.util.Convert;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
44 import tango.util.container.LinkedList;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
45
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
46
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
47 void main(String[] args) {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
48 Display display = new Display();
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
49 Shell shell = new Shell(display);
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
50 shell.setLayout(new FillLayout());
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
51 new Snippet026TreeViewerTabEditing(shell);
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
52 shell.open();
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
53
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
54 while (!shell.isDisposed()) {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
55 if (!display.readAndDispatch())
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
56 display.sleep();
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
57 }
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
58
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
59 display.dispose();
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
60 }
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
61
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
62 /**
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
63 * A simple TreeViewer to demonstrate usage
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
64 *
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
65 * @author Tom Schindl <tom.schindl@bestsolution.at>
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
66 *
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
67 */
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
68 public class Snippet026TreeViewerTabEditing {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
69 alias LinkedList!(MyModel) ArrayList;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
70 public this(Shell shell) {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
71 Button b = new Button(shell,DWT.PUSH);
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
72 b.setText("Remove column");
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
73 final TreeViewer v = new TreeViewer(shell, DWT.BORDER
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
74 | DWT.FULL_SELECTION);
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
75 v.getTree().setLinesVisible(true);
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
76 v.getTree().setHeaderVisible(true);
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
77 b.addSelectionListener(new class(v) SelectionListener {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
78 TreeViewer v;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
79 this(TreeViewer v_)
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
80 {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
81 this.v = v_;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
82 }
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
83 public void widgetDefaultSelected(SelectionEvent e) {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
84
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
85 }
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
86
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
87 public void widgetSelected(SelectionEvent e) {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
88 v.getTree().getColumn(1).dispose();
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
89 }
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
90
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
91 });
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
92
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
93 TreeViewerFocusCellManager focusCellManager = new TreeViewerFocusCellManager(v,new FocusCellOwnerDrawHighlighter(v));
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
94 ColumnViewerEditorActivationStrategy actSupport = new class(v) ColumnViewerEditorActivationStrategy {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
95 this(ColumnViewer v_)
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
96 {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
97 super(v_);
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
98 }
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
99 protected bool isEditorActivationEvent(
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
100 ColumnViewerEditorActivationEvent event) {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
101 return event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
102 || event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
103 || (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && event.keyCode == DWT.CR)
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
104 || event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
105 }
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
106 };
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
107
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
108 TreeViewerEditor.create(v, focusCellManager, actSupport, ColumnViewerEditor.TABBING_HORIZONTAL
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
109 | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
110 | ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEYBOARD_ACTIVATION);
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
111
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
112 final TextCellEditor textCellEditor = new TextCellEditor(v.getTree());
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
113
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
114 TreeViewerColumn column = new TreeViewerColumn(v, DWT.NONE);
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
115 column.getColumn().setWidth(200);
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
116 column.getColumn().setMoveable(true);
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
117 column.getColumn().setText("Column 1");
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
118 column.setLabelProvider(new class() ColumnLabelProvider {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
119
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
120 public String getText(Object element) {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
121 return "Column 1 => " ~ element.toString();
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
122 }
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
123
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
124 });
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
125 column.setEditingSupport(new class(v) EditingSupport {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
126 this(ColumnViewer v_)
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
127 {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
128 super(v_);
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
129 }
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
130 protected bool canEdit(Object element) {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
131 return false;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
132 }
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
133
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
134 protected CellEditor getCellEditor(Object element) {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
135 return textCellEditor;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
136 }
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
137
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
138 protected Object getValue(Object element) {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
139 return stringcast( (to!(String)((cast(MyModel) element).counter)) );
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
140 }
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
141
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
142 protected void setValue(Object element, Object value) {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
143 (cast(MyModel) element).counter = Integer.parseInt(value.toString());
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
144 v.update(element, null);
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
145 }
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
146 });
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
147
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
148 column = new TreeViewerColumn(v, DWT.NONE);
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
149 column.getColumn().setWidth(200);
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
150 column.getColumn().setMoveable(true);
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
151 column.getColumn().setText("Column 2");
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
152 column.setLabelProvider(new class() ColumnLabelProvider {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
153
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
154 public String getText(Object element) {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
155 return "Column 2 => " ~ element.toString();
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
156 }
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
157
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
158 });
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
159 column.setEditingSupport(new class(v) EditingSupport {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
160 this(ColumnViewer v_)
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
161 {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
162 super(v_);
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
163 }
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
164 protected bool canEdit(Object element) {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
165 return true;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
166 }
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
167
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
168 protected CellEditor getCellEditor(Object element) {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
169 return textCellEditor;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
170 }
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
171
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
172 protected Object getValue(Object element) {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
173 return stringcast( to!(String)((cast(MyModel) element).counter) );
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
174 }
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
175
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
176 protected void setValue(Object element, Object value) {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
177 (cast(MyModel) element).counter = Integer.parseInt(value.toString());
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
178 v.update(element, null);
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
179 }
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
180 });
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
181
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
182 column = new TreeViewerColumn(v, DWT.NONE);
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
183 column.getColumn().setWidth(200);
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
184 column.getColumn().setMoveable(true);
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
185 column.getColumn().setText("Column 3");
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
186 column.setLabelProvider(new class() ColumnLabelProvider {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
187 public String getText(Object element) {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
188 return "Column 3 => " ~ element.toString();
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
189 }
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
190
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
191 });
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
192 column.setEditingSupport(new class(v) EditingSupport {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
193 this(ColumnViewer v_)
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
194 {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
195 super(v_);
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
196 }
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
197 protected bool canEdit(Object element) {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
198 return true;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
199 }
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
200
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
201 protected CellEditor getCellEditor(Object element) {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
202 return textCellEditor;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
203 }
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
204
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
205 protected Object getValue(Object element) {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
206 return stringcast( to!(String)((cast(MyModel) element).counter) );
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
207 }
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
208
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
209 protected void setValue(Object element, Object value) {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
210 (cast(MyModel) element).counter = Integer.parseInt(value.toString());
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
211 v.update(element, null);
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
212 }
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
213 });
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
214
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
215 v.setContentProvider(new MyContentProvider());
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
216
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
217 v.setInput(createModel());
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
218 }
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
219
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
220 private MyModel createModel() {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
221
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
222 MyModel root = new MyModel(0, null);
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
223 root.counter = 0;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
224
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
225 MyModel tmp;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
226 MyModel subItem;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
227 for (int i = 1; i < 10; i++) {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
228 tmp = new MyModel(i, root);
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
229 root.child.add(tmp);
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
230 for (int j = 1; j < i; j++) {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
231 subItem = new MyModel(j, tmp);
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
232 subItem.child.add(new MyModel(j * 100, subItem));
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
233 tmp.child.add(subItem);
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
234 }
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
235 }
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
236
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
237 return root;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
238 }
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
239
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
240 private class MyContentProvider : ITreeContentProvider {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
241
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
242 public Object[] getElements(Object inputElement) {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
243 return (cast(MyModel) inputElement).child.toArray();
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
244 }
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
245
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
246 public void dispose() {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
247 }
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
248
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
249 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
250 }
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
251
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
252 public Object[] getChildren(Object parentElement) {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
253 return getElements(parentElement);
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
254 }
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
255
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
256 public Object getParent(Object element) {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
257 if (element is null) {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
258 return null;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
259 }
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
260 return (cast(MyModel) element).parent;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
261 }
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
262
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
263 public bool hasChildren(Object element) {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
264 return (cast(MyModel) element).child.size() > 0;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
265 }
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
266
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
267 }
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
268
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
269 public class MyModel {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
270 public MyModel parent;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
271
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
272 public ArrayList child;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
273
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
274 public int counter;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
275
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
276 public this(int counter, MyModel parent) {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
277 this.parent = parent;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
278 this.counter = counter;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
279 child = new ArrayList();
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
280 }
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
281
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
282 public String toString() {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
283 String rv = "Item ";
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
284 if (parent !is null) {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
285 rv = parent.toString() ~ ".";
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
286 }
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
287
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
288 rv ~= to!(String)(counter);
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
289
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
290 return rv;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
291 }
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
292 }
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
293
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
294 }