Mercurial > projects > dwt2
comparison org.eclipse.jface.snippets/EclipseJfaceSnippets/org/eclipse/jface/snippets/viewers/Snippet004HideSelection.d @ 31:5d87d4191adf
Added JFace Snippets sources
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 23 Mar 2009 11:16:06 +0100 |
parents | |
children | c4b36186a9bc |
comparison
equal
deleted
inserted
replaced
30:93b0e7382fd5 | 31:5d87d4191adf |
---|---|
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 snippets.viewers.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 import dwtx.dwtxhelper.Collection; | |
31 | |
32 import tango.util.Convert; | |
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 private class MyContentProvider : IStructuredContentProvider { | |
42 | |
43 /* (non-Javadoc) | |
44 * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object) | |
45 */ | |
46 public Object[] getElements(Object inputElement) { | |
47 return (cast(ArrayList)inputElement).toArray; | |
48 } | |
49 | |
50 /* (non-Javadoc) | |
51 * @see org.eclipse.jface.viewers.IContentProvider#dispose() | |
52 */ | |
53 public void dispose() { | |
54 | |
55 } | |
56 | |
57 /* (non-Javadoc) | |
58 * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object) | |
59 */ | |
60 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { | |
61 | |
62 } | |
63 } | |
64 | |
65 public class MyModel { | |
66 public int counter; | |
67 | |
68 public this(int counter) { | |
69 this.counter = counter; | |
70 } | |
71 | |
72 public String toString() { | |
73 return "Item " ~ to!(char[])(this.counter); | |
74 } | |
75 } | |
76 | |
77 public this(Shell shell) { | |
78 final TableViewer v = new TableViewer(shell,DWT.BORDER|DWT.FULL_SELECTION); | |
79 v.setLabelProvider(new LabelProvider()); | |
80 v.setContentProvider(new MyContentProvider()); | |
81 ArrayList model = createModel(); | |
82 v.setInput(model); | |
83 v.getTable().setLinesVisible(true); | |
84 v.getTable().addMouseListener(new class(v) MouseAdapter { | |
85 private TableViewer v; | |
86 this(TableViewer v_) { | |
87 this.v = v_; | |
88 } | |
89 | |
90 /* (non-Javadoc) | |
91 * @see org.eclipse.swt.events.MouseAdapter#mouseDown(org.eclipse.swt.events.MouseEvent) | |
92 */ | |
93 public void mouseDown(MouseEvent e) { | |
94 if( v.getTable().getItem(new Point(e.x,e.y)) is null ) { | |
95 v.setSelection(new StructuredSelection()); | |
96 } | |
97 } | |
98 | |
99 }); | |
100 } | |
101 | |
102 private ArrayList createModel() { | |
103 ArrayList elements = new ArrayList(10); | |
104 for( int i = 0; i < 10; i++ ) { | |
105 elements.add( new MyModel(i)); | |
106 } | |
107 | |
108 return elements; | |
109 } | |
110 | |
111 } | |
112 | |
113 static void main() { | |
114 Display display = new Display (); | |
115 Shell shell = new Shell(display); | |
116 shell.setLayout(new FillLayout()); | |
117 new Snippet004HideSelection(shell); | |
118 shell.open (); | |
119 | |
120 while (!shell.isDisposed ()) { | |
121 if (!display.readAndDispatch ()) display.sleep (); | |
122 } | |
123 | |
124 display.dispose (); | |
125 | |
126 } | |
127 |