annotate jface/snippets/Snippet043NoColumnTreeViewerKeyboardEditing.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 dwtx.jface.snippets.Snippet043NoColumnTreeViewerKeyboardEditing;
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 import dwtx.jface.viewers.CellEditor;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
17 import dwtx.jface.viewers.ColumnViewerEditor;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
18 import dwtx.jface.viewers.ColumnViewer;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
19 import dwtx.jface.viewers.ColumnViewerEditorActivationStrategy;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
20 import dwtx.jface.viewers.ColumnViewerEditorActivationEvent;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
21 import dwtx.jface.viewers.FocusCellOwnerDrawHighlighter;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
22 import dwtx.jface.viewers.ICellModifier;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
23 import dwtx.jface.viewers.ITreeContentProvider;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
24 import dwtx.jface.viewers.TextCellEditor;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
25 import dwtx.jface.viewers.TreePath;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
26 import dwtx.jface.viewers.TreeViewerFocusCellManager;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
27 import dwtx.jface.viewers.TreeViewerEditor;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
28 import dwtx.jface.viewers.TreeViewer;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
29 import dwtx.jface.viewers.Viewer;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
30 import dwt.DWT;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
31 import dwt.events.SelectionEvent;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
32 import dwt.events.SelectionListener;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
33 import dwt.layout.FillLayout;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
34 import dwt.widgets.Button;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
35 import dwt.widgets.Display;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
36 import dwt.widgets.Item;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
37 import dwt.widgets.Shell;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
38
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
39 import dwt.dwthelper.utils;
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 tango.util.Convert;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
42 import tango.util.container.LinkedList;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
43
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
44
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
45 void main(String[] args) {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
46 Display display = new Display();
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
47 Shell shell = new Shell(display);
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
48 shell.setLayout(new FillLayout());
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
49 new Snippet043NoColumnTreeViewerKeyboardEditing(shell);
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
50 shell.open();
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
51
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
52 while (!shell.isDisposed()) {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
53 if (!display.readAndDispatch())
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
54 display.sleep();
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
55 }
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
56
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
57 display.dispose();
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
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 * Demonstrates how to use keyboard-editing support in a TreeViewer with no column
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 * @author Tom Schindl <tom.schindl@bestsolution.at>
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 */
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
66 public class Snippet043NoColumnTreeViewerKeyboardEditing {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
67 alias LinkedList!(MyModel) ArrayList;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
68 public this(Shell shell) {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
69 Button b = new Button(shell, DWT.PUSH);
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
70 b.setText("BBB");
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
71 final TreeViewer v = new TreeViewer(shell, DWT.BORDER
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
72 | DWT.FULL_SELECTION);
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
73 b.addSelectionListener(new class(v) SelectionListener {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
74 TreeViewer v;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
75 this(TreeViewer v_)
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
76 {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
77 this.v = v_;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
78 }
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
79
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
80 public void widgetDefaultSelected(SelectionEvent e) {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
81
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
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
84 public void widgetSelected(SelectionEvent e) {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
85 MyModel root = cast(MyModel) v.getInput();
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
86 TreePath path = new TreePath([ root, root.child.get(1),
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
87 (cast(MyModel) root.child.get(1)).child.get(0)] );
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
88 v.editElement(path, 0);
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 v.setCellEditors([ new TextCellEditor(v.getTree()) ]);
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
94 v.setColumnProperties(["col1"]);
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
95 v.setCellModifier(new class(v) ICellModifier {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
96 TreeViewer v;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
97 this(TreeViewer 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 this.v = v_;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
100 }
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
101 public bool canModify(Object element, String property) {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
102 return true;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
103 }
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
104
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
105 public Object getValue(Object element, String property) {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
106 return stringcast( to!(String)((cast(MyModel) element).counter) ~ "" );
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
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
109 public void modify(Object element, String property, Object value) {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
110 element = (cast(Item) element).getData();
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
111 (cast(MyModel) element).counter = Integer.parseInt(value.toString());
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
112 v.update(element, null);
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
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
115 });
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
116
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
117 TreeViewerFocusCellManager focusCellManager = new TreeViewerFocusCellManager(
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
118 v, new FocusCellOwnerDrawHighlighter(v));
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
119 ColumnViewerEditorActivationStrategy actSupport = new class(v) ColumnViewerEditorActivationStrategy {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
120 this(ColumnViewer v)
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
121 {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
122 super(v);
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 protected bool isEditorActivationEvent(
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
125 ColumnViewerEditorActivationEvent event) {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
126 return event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
127 || event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
128 || (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && event.keyCode == DWT.CR)
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
129 || event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
130 }
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
131 };
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 TreeViewerEditor.create(v, focusCellManager, actSupport,
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
134 ColumnViewerEditor.TABBING_HORIZONTAL
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
135 | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
136 | ColumnViewerEditor.TABBING_VERTICAL
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
137 | ColumnViewerEditor.KEYBOARD_ACTIVATION);
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
138
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
139 v.setContentProvider(new MyContentProvider());
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 v.setInput(createModel());
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
142 }
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
143
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
144 private MyModel createModel() {
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 MyModel root = new MyModel(0, null);
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
147 root.counter = 0;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
148
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
149 MyModel tmp;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
150 MyModel subItem;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
151 for (int i = 1; i < 10; i++) {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
152 tmp = new MyModel(i, root);
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
153 root.child.add(tmp);
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
154 for (int j = 1; j < i; j++) {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
155 subItem = new MyModel(j, tmp);
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
156 subItem.child.add(new MyModel(j * 100, subItem));
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
157 tmp.child.add(subItem);
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 }
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
160
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
161 return root;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
162 }
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
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
165
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
166 private class MyContentProvider : ITreeContentProvider {
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 public Object[] getElements(Object inputElement) {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
169 return (cast(MyModel) inputElement).child.toArray();
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 public void dispose() {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
173 }
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 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
176 }
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
177
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
178 public Object[] getChildren(Object parentElement) {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
179 return getElements(parentElement);
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 public Object getParent(Object element) {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
183 if (element is null) {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
184 return null;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
185 }
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
186 return (cast(MyModel) element).parent;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
187 }
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
188
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
189 public bool hasChildren(Object element) {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
190 return (cast(MyModel) element).child.size() > 0;
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
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
193 }
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 public class MyModel {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
196 public MyModel parent;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
197
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
198 public ArrayList child;
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 public int counter;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
201
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
202 public this(int counter_, MyModel parent_) {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
203 this.parent = parent_;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
204 this.counter = counter_;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
205 child = new ArrayList();
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
206 }
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 public String toString() {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
209 String rv = "Item ";
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
210 if (parent !is null) {
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
211 rv = parent.toString() ~ ".";
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 rv ~= to!(String)(counter);
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
215
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
216 return rv;
96a2d0b35360 jface snippets 014, 026, 043, 047
yidabu <yidabu@gmail.com>
parents:
diff changeset
217 }
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 }