Mercurial > projects > dwt-samples
comparison jface/snippets/Snippet004HideSelection.d @ 89:cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
author | Bill Baxter <bill@billbaxter.com> |
---|---|
date | Mon, 19 May 2008 23:42:48 +0900 |
parents | |
children | 42c3056512ba |
comparison
equal
deleted
inserted
replaced
88:9ed020f0c2a5 | 89:cbba80cceb7a |
---|---|
1 /******************************************************************************* | |
2 * Copyright (c) 2006 Tom Schindl and others. | |
3 * All rights reserved. This program and the accompanying materials | |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * Tom Schindl - initial API and implementation | |
10 * Port to the D programming language: | |
11 * wbaxter at gmail dot com | |
12 *******************************************************************************/ | |
13 | |
14 module jface.snippets.Snippet004HideSelection; | |
15 | |
16 import dwtx.jface.viewers.IStructuredContentProvider; | |
17 import dwtx.jface.viewers.LabelProvider; | |
18 import dwtx.jface.viewers.StructuredSelection; | |
19 import dwtx.jface.viewers.TableViewer; | |
20 import dwtx.jface.viewers.Viewer; | |
21 import dwt.DWT; | |
22 import dwt.events.MouseAdapter; | |
23 import dwt.events.MouseEvent; | |
24 import dwt.graphics.Point; | |
25 import dwt.layout.FillLayout; | |
26 import dwt.widgets.Display; | |
27 import dwt.widgets.Shell; | |
28 | |
29 import dwt.dwthelper.utils; | |
30 | |
31 import tango.util.Convert; | |
32 import tango.util.collection.ArraySeq; | |
33 | |
34 /** | |
35 * Snippet that hides the selection when nothing is selected. | |
36 * | |
37 * @author Tom Schindl <tom.schindl@bestsolution.at> | |
38 * | |
39 */ | |
40 public class Snippet004HideSelection { | |
41 alias ArraySeq!(MyModel) MyModelArray; | |
42 private class MyContentProvider : IStructuredContentProvider { | |
43 | |
44 /* (non-Javadoc) | |
45 * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object) | |
46 */ | |
47 public Object[] getElements(Object inputElement) { | |
48 return (cast(MyModelArray)inputElement).toArray; | |
49 } | |
50 | |
51 /* (non-Javadoc) | |
52 * @see org.eclipse.jface.viewers.IContentProvider#dispose() | |
53 */ | |
54 public void dispose() { | |
55 | |
56 } | |
57 | |
58 /* (non-Javadoc) | |
59 * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object) | |
60 */ | |
61 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { | |
62 | |
63 } | |
64 } | |
65 | |
66 public class MyModel { | |
67 public int counter; | |
68 | |
69 public this(int counter) { | |
70 this.counter = counter; | |
71 } | |
72 | |
73 public String toString() { | |
74 return "Item " ~ to!(char[])(this.counter); | |
75 } | |
76 } | |
77 | |
78 public this(Shell shell) { | |
79 final TableViewer v = new TableViewer(shell,DWT.BORDER|DWT.FULL_SELECTION); | |
80 v.setLabelProvider(new LabelProvider()); | |
81 v.setContentProvider(new MyContentProvider()); | |
82 MyModelArray model = createModel(); | |
83 v.setInput(model); | |
84 v.getTable().setLinesVisible(true); | |
85 v.getTable().addMouseListener(new class(v) MouseAdapter { | |
86 private TableViewer v; | |
87 this(TableViewer v_) { | |
88 this.v = v_; | |
89 } | |
90 | |
91 /* (non-Javadoc) | |
92 * @see org.eclipse.swt.events.MouseAdapter#mouseDown(org.eclipse.swt.events.MouseEvent) | |
93 */ | |
94 public void mouseDown(MouseEvent e) { | |
95 if( v.getTable().getItem(new Point(e.x,e.y)) is null ) { | |
96 v.setSelection(new StructuredSelection()); | |
97 } | |
98 } | |
99 | |
100 }); | |
101 } | |
102 | |
103 private MyModelArray createModel() { | |
104 MyModelArray elements = new MyModelArray; | |
105 elements.capacity = 10; | |
106 for( int i = 0; i < 10; i++ ) { | |
107 elements ~= new MyModel(i); | |
108 } | |
109 | |
110 return elements; | |
111 } | |
112 | |
113 } | |
114 | |
115 static void main() { | |
116 Display display = new Display (); | |
117 Shell shell = new Shell(display); | |
118 shell.setLayout(new FillLayout()); | |
119 new Snippet004HideSelection(shell); | |
120 shell.open (); | |
121 | |
122 while (!shell.isDisposed ()) { | |
123 if (!display.readAndDispatch ()) display.sleep (); | |
124 } | |
125 | |
126 display.dispose (); | |
127 | |
128 } | |
129 |