31
|
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
|
32
|
14 module org.eclipse.jface.snippets.viewers.Snippet004HideSelection;
|
31
|
15
|
32
|
16 import org.eclipse.jface.viewers.IStructuredContentProvider;
|
|
17 import org.eclipse.jface.viewers.LabelProvider;
|
|
18 import org.eclipse.jface.viewers.StructuredSelection;
|
|
19 import org.eclipse.jface.viewers.TableViewer;
|
|
20 import org.eclipse.jface.viewers.Viewer;
|
|
21 import org.eclipse.swt.SWT;
|
|
22 import org.eclipse.swt.events.MouseAdapter;
|
|
23 import org.eclipse.swt.events.MouseEvent;
|
|
24 import org.eclipse.swt.graphics.Point;
|
|
25 import org.eclipse.swt.layout.FillLayout;
|
|
26 import org.eclipse.swt.widgets.Display;
|
|
27 import org.eclipse.swt.widgets.Shell;
|
31
|
28
|
32
|
29 import java.lang.all;
|
|
30 import java.util.ArrayList;
|
31
|
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) {
|
32
|
78 final TableViewer v = new TableViewer(shell,SWT.BORDER|SWT.FULL_SELECTION);
|
31
|
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
|