Mercurial > projects > dwt2
comparison org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/ViewersObservables.d @ 78:0a55d2d5a946
Added file for databinding
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Tue, 14 Apr 2009 11:35:29 +0200 |
parents | |
children | 6be48cf9f95c |
comparison
equal
deleted
inserted
replaced
76:f05e6e8b2f2d | 78:0a55d2d5a946 |
---|---|
1 /******************************************************************************* | |
2 * Copyright (c) 2006, 2008 IBM Corporation 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 * IBM Corporation - initial API and implementation | |
10 * Matthew Hall - bug 206839 | |
11 * Matthew Hall - bug 124684 | |
12 *******************************************************************************/ | |
13 | |
14 module org.eclipse.jface.databinding.viewers.ViewersObservables; | |
15 | |
16 import java.lang.all; | |
17 | |
18 import org.eclipse.core.databinding.observable.list.IObservableList; | |
19 import org.eclipse.core.databinding.observable.set.IObservableSet; | |
20 import org.eclipse.core.databinding.observable.value.IObservableValue; | |
21 import org.eclipse.jface.databinding.swt.SWTObservables; | |
22 import org.eclipse.jface.internal.databinding.viewers.CheckableCheckedElementsObservableSet; | |
23 import org.eclipse.jface.internal.databinding.viewers.CheckboxViewerCheckedElementsObservableSet; | |
24 import org.eclipse.jface.internal.databinding.viewers.SelectionProviderMultipleSelectionObservableList; | |
25 import org.eclipse.jface.internal.databinding.viewers.SelectionProviderSingleSelectionObservableValue; | |
26 import org.eclipse.jface.internal.databinding.viewers.ViewerInputObservableValue; | |
27 import org.eclipse.jface.internal.databinding.viewers.ViewerMultipleSelectionObservableList; | |
28 import org.eclipse.jface.internal.databinding.viewers.ViewerSingleSelectionObservableValue; | |
29 import org.eclipse.jface.viewers.CheckboxTableViewer; | |
30 import org.eclipse.jface.viewers.CheckboxTreeViewer; | |
31 import org.eclipse.jface.viewers.ICheckable; | |
32 import org.eclipse.jface.viewers.ISelectionProvider; | |
33 import org.eclipse.jface.viewers.IStructuredSelection; | |
34 import org.eclipse.jface.viewers.Viewer; | |
35 import org.eclipse.swt.widgets.Display; | |
36 | |
37 /** | |
38 * Factory methods for creating observables for JFace viewers | |
39 * | |
40 * @since 1.1 | |
41 */ | |
42 public class ViewersObservables { | |
43 | |
44 /** | |
45 * Returns an observable value that tracks the current selection of the | |
46 * given selection provider. If the selection provider provides selections | |
47 * of type {@link IStructuredSelection}, the observable value will be the | |
48 * first element of the structured selection as returned by | |
49 * {@link IStructuredSelection#getFirstElement()}. | |
50 * | |
51 * @param selectionProvider | |
52 * @return the observable value tracking the (single) selection of the given | |
53 * selection provider | |
54 */ | |
55 public static IObservableValue observeSingleSelection( | |
56 ISelectionProvider selectionProvider) { | |
57 if (null !is cast(Viewer)selectionProvider) { | |
58 return observeSingleSelection(cast(Viewer) selectionProvider); | |
59 } | |
60 return new SelectionProviderSingleSelectionObservableValue( | |
61 SWTObservables.getRealm(Display.getDefault()), | |
62 selectionProvider); | |
63 } | |
64 | |
65 /** | |
66 * Returns an observable list that tracks the current selection of the | |
67 * given selection provider. Assumes that the selection provider provides | |
68 * selections of type {@link IStructuredSelection}. Note that the | |
69 * observable list will not honor the full contract of | |
70 * <code>java.util.List</code> in that it may delete or reorder elements | |
71 * based on what the selection provider returns from | |
72 * {@link ISelectionProvider#getSelection()} after having called | |
73 * {@link ISelectionProvider#setSelection(org.eclipse.jface.viewers.ISelection)} | |
74 * based on the requested change to the observable list. The affected | |
75 * methods are <code>add</code>, <code>addAll</code>, and | |
76 * <code>set</code>. | |
77 * | |
78 * @param selectionProvider | |
79 * @return the observable value tracking the (multi) selection of the given | |
80 * selection provider | |
81 * | |
82 * @since 1.2 | |
83 */ | |
84 public static IObservableList observeMultiSelection( | |
85 ISelectionProvider selectionProvider) { | |
86 if (null !is cast(Viewer)selectionProvider) { | |
87 return observeMultiSelection(cast(Viewer) selectionProvider); | |
88 } | |
89 return new SelectionProviderMultipleSelectionObservableList( | |
90 SWTObservables.getRealm(Display.getDefault()), | |
91 selectionProvider, Object.classinfo); | |
92 } | |
93 | |
94 /** | |
95 * Returns an observable value that tracks the current selection of the | |
96 * given viewer. If the viewer provides selections of type | |
97 * {@link IStructuredSelection}, the observable value will be the first | |
98 * element of the structured selection as returned by | |
99 * {@link IStructuredSelection#getFirstElement()}. | |
100 * | |
101 * @param viewer | |
102 * the viewer | |
103 * @return the observable value tracking the (single) selection of the given | |
104 * viewer | |
105 * @since 1.2 | |
106 */ | |
107 public static IViewerObservableValue observeSingleSelection(Viewer viewer) { | |
108 return new ViewerSingleSelectionObservableValue( | |
109 SWTObservables.getRealm(Display.getDefault()), | |
110 viewer); | |
111 } | |
112 | |
113 /** | |
114 * Returns an observable list that tracks the current selection of the | |
115 * given viewer. Assumes that the viewer provides | |
116 * selections of type {@link IStructuredSelection}. Note that the | |
117 * observable list will not honor the full contract of | |
118 * <code>java.util.List</code> in that it may delete or reorder elements | |
119 * based on what the viewer returns from | |
120 * {@link ISelectionProvider#getSelection()} after having called | |
121 * {@link ISelectionProvider#setSelection(org.eclipse.jface.viewers.ISelection)} | |
122 * based on the requested change to the observable list. The affected | |
123 * methods are <code>add</code>, <code>addAll</code>, and | |
124 * <code>set</code>. | |
125 * | |
126 * @param viewer | |
127 * @return the observable value tracking the (multi) selection of the given | |
128 * selection provider | |
129 * | |
130 * @since 1.2 | |
131 */ | |
132 public static IViewerObservableList observeMultiSelection( | |
133 Viewer viewer) { | |
134 return new ViewerMultipleSelectionObservableList( | |
135 SWTObservables.getRealm(Display.getDefault()), | |
136 viewer, Object.classinfo); | |
137 } | |
138 | |
139 /** | |
140 * Returns an observable value that tracks the input of the given viewer. | |
141 * <p> | |
142 * The returned observer is blind to changes in the viewer's input unless | |
143 * its {@link IObservableValue#setValue(Object)} method is called directly. | |
144 * | |
145 * @param viewer | |
146 * the viewer to observe | |
147 * @return an observable value tracking the input of the given viewer | |
148 * @since 1.2 | |
149 */ | |
150 public static IObservableValue observeInput(Viewer viewer) { | |
151 return new ViewerInputObservableValue(SWTObservables.getRealm(viewer | |
152 .getControl().getDisplay()), viewer); | |
153 } | |
154 | |
155 /** | |
156 * Returns an observable set that tracks the checked elements of the given | |
157 * <code>ICheckable</code>. | |
158 * | |
159 * @param checkable | |
160 * {@link ICheckable} containing the checked elements to track | |
161 * @param elementType | |
162 * element type of the returned set | |
163 * @return an observable set tracking the checked elements of the given | |
164 * checkable. | |
165 * @since 1.2 | |
166 */ | |
167 public static IObservableSet observeCheckedElements(ICheckable checkable, | |
168 Object elementType) { | |
169 if (null !is cast(CheckboxTableViewer)checkable) { | |
170 return observeCheckedElements(cast(CheckboxTableViewer) checkable, | |
171 elementType); | |
172 } | |
173 if (null !is cast(CheckboxTreeViewer)checkable) { | |
174 return observeCheckedElements(cast(CheckboxTreeViewer) checkable, | |
175 elementType); | |
176 } | |
177 return new CheckableCheckedElementsObservableSet(SWTObservables | |
178 .getRealm(Display.getDefault()), checkable, elementType); | |
179 } | |
180 | |
181 /** | |
182 * Returns an observable set that tracks the checked elements of the given | |
183 * viewer. Assumes that the viewer implements {@link ICheckable}. | |
184 * | |
185 * @param viewer | |
186 * {@link CheckboxTableViewer} containing the checked elements to | |
187 * track. | |
188 * @param elementType | |
189 * element type of the returned set | |
190 * @return an observable set that tracks the checked elements of the given | |
191 * viewer. | |
192 * @since 1.2 | |
193 */ | |
194 public static IViewerObservableSet observeCheckedElements( | |
195 CheckboxTableViewer viewer, Object elementType) { | |
196 return new CheckboxViewerCheckedElementsObservableSet(SWTObservables | |
197 .getRealm(viewer.getControl().getDisplay()), viewer, | |
198 elementType); | |
199 } | |
200 | |
201 /** | |
202 * Returns an observable set that tracks the checked elements of the given | |
203 * viewer. Assumes that the viewer implements {@link ICheckable}. | |
204 * | |
205 * @param viewer | |
206 * {@link CheckboxTreeViewer} containing the checked elements to | |
207 * track. | |
208 * @param elementType | |
209 * element type of the returned set | |
210 * @return an observable set that tracks the checked elements of the given | |
211 * viewer. | |
212 * @since 1.2 | |
213 */ | |
214 public static IViewerObservableSet observeCheckedElements( | |
215 CheckboxTreeViewer viewer, Object elementType) { | |
216 return new CheckboxViewerCheckedElementsObservableSet(SWTObservables | |
217 .getRealm(viewer.getControl().getDisplay()), viewer, | |
218 elementType); | |
219 } | |
220 } |