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