78
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2008 Matthew Hall 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 * Matthew Hall - initial API and implementation (bug 124684)
|
|
10 ******************************************************************************/
|
|
11
|
|
12 module org.eclipse.jface.internal.databinding.viewers.CheckboxViewerCheckedElementsObservableSet;
|
|
13
|
|
14 import java.lang.all;
|
|
15
|
|
16 import java.util.Arrays;
|
|
17 import java.util.Set;
|
|
18
|
|
19 import org.eclipse.core.databinding.observable.Realm;
|
|
20 import org.eclipse.jface.databinding.viewers.IViewerObservableSet;
|
|
21 import org.eclipse.jface.viewers.CheckboxTableViewer;
|
|
22 import org.eclipse.jface.viewers.CheckboxTreeViewer;
|
|
23 import org.eclipse.jface.viewers.StructuredViewer;
|
|
24 import org.eclipse.jface.viewers.Viewer;
|
|
25
|
|
26 /**
|
|
27 * An observable set that tracks the checked elements in a CheckboxTableViewer
|
|
28 * or CheckboxTreeViewer
|
|
29 *
|
|
30 * @since 1.2
|
|
31 */
|
|
32 public class CheckboxViewerCheckedElementsObservableSet :
|
|
33 CheckableCheckedElementsObservableSet , IViewerObservableSet {
|
|
34 private StructuredViewer viewer;
|
|
35
|
|
36 /**
|
|
37 * Constructs a new instance on the given realm and checkable.
|
|
38 *
|
|
39 * @param realm
|
|
40 * the observable's realm
|
|
41 * @param viewer
|
|
42 * the CheckboxTableViewer viewer to track.
|
|
43 * @param elementType
|
|
44 * type of elements in the set
|
|
45 */
|
|
46 public this(Realm realm,
|
|
47 CheckboxTableViewer viewer, Object elementType) {
|
|
48 super(realm, viewer, elementType, createElementSet(viewer));
|
|
49 this.viewer = viewer;
|
|
50 }
|
|
51
|
|
52 /**
|
|
53 * Constructs a new instance on the given realm and checkable.
|
|
54 *
|
|
55 * @param realm
|
|
56 * the observable's realm
|
|
57 * @param viewer
|
|
58 * the CheckboxTreeViewer viewer to track.
|
|
59 * @param elementType
|
|
60 * type of elements in the set
|
|
61 */
|
|
62 public this(Realm realm,
|
|
63 CheckboxTreeViewer viewer, Object elementType) {
|
|
64 super(realm, viewer, elementType, createElementSet(viewer));
|
|
65 this.viewer = viewer;
|
|
66 }
|
|
67
|
|
68 Set createDiffSet() {
|
|
69 return ViewerElementSet.withComparer(viewer.getComparer());
|
|
70 }
|
|
71
|
|
72 private static Set createElementSet(CheckboxTableViewer viewer) {
|
|
73 Set set = ViewerElementSet.withComparer(viewer.getComparer());
|
|
74 set.addAll(Arrays.asList(viewer.getCheckedElements()));
|
|
75 return set;
|
|
76 }
|
|
77
|
|
78 private static Set createElementSet(CheckboxTreeViewer viewer) {
|
|
79 Set set = ViewerElementSet.withComparer(viewer.getComparer());
|
|
80 set.addAll(Arrays.asList(viewer.getCheckedElements()));
|
|
81 return set;
|
|
82 }
|
|
83
|
|
84 public Viewer getViewer() {
|
|
85 return viewer;
|
|
86 }
|
|
87
|
|
88 public synchronized void dispose() {
|
|
89 viewer = null;
|
|
90 super.dispose();
|
|
91 }
|
|
92 }
|