Mercurial > projects > dwt2
comparison org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/ObservableSetContentProvider.d @ 78:0a55d2d5a946
Added file for databinding
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Tue, 14 Apr 2009 11:35:29 +0200 |
parents | |
children |
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 * Brad Reynolds - bug 116920 | |
11 * Matthew Hall - bugs 215531, 226765 | |
12 *******************************************************************************/ | |
13 module org.eclipse.jface.databinding.viewers.ObservableSetContentProvider; | |
14 | |
15 import java.lang.all; | |
16 | |
17 import java.util.Set; | |
18 | |
19 import org.eclipse.core.databinding.observable.IObservableCollection; | |
20 import org.eclipse.core.databinding.observable.set.IObservableSet; | |
21 import org.eclipse.core.databinding.observable.set.ISetChangeListener; | |
22 import org.eclipse.core.databinding.observable.set.SetChangeEvent; | |
23 import org.eclipse.core.runtime.Assert; | |
24 import org.eclipse.jface.internal.databinding.viewers.ObservableCollectionContentProvider; | |
25 import org.eclipse.jface.viewers.AbstractListViewer; | |
26 import org.eclipse.jface.viewers.AbstractTableViewer; | |
27 import org.eclipse.jface.viewers.IStructuredContentProvider; | |
28 import org.eclipse.jface.viewers.Viewer; | |
29 | |
30 /** | |
31 * A {@link IStructuredContentProvider content provider} for | |
32 * {@link AbstractTableViewer} or {@link AbstractListViewer} that provides | |
33 * elements of an {@link IObservableSet} when set as the viewer's input. Objects | |
34 * of this class listen for changes to the observable set, and will insert and | |
35 * remove viewer elements to reflect observed changes. | |
36 * | |
37 * <p> | |
38 * This class is not intended to be subclassed by clients. | |
39 * | |
40 * @since 1.1 | |
41 */ | |
42 public class ObservableSetContentProvider : IStructuredContentProvider { | |
43 private ObservableCollectionContentProvider impl; | |
44 | |
45 private static class Impl : ObservableCollectionContentProvider | |
46 , ISetChangeListener { | |
47 protected void checkInput(Object input) { | |
48 Assert | |
49 .isTrue(null !is cast(IObservableSet)input, | |
50 "This content provider only works with input of type IObservableSet"); //$NON-NLS-1$ | |
51 } | |
52 | |
53 protected void addCollectionChangeListener( | |
54 IObservableCollection collection) { | |
55 (cast(IObservableSet) collection).addSetChangeListener(this); | |
56 } | |
57 | |
58 protected void removeCollectionChangeListener( | |
59 IObservableCollection collection) { | |
60 (cast(IObservableSet) collection).removeSetChangeListener(this); | |
61 } | |
62 | |
63 public void handleSetChange(SetChangeEvent event) { | |
64 if (isViewerDisposed()) | |
65 return; | |
66 | |
67 Set removals = event.diff.getRemovals(); | |
68 viewerUpdater.remove(removals.toArray()); | |
69 knownElements.removeAll(removals); | |
70 | |
71 Set additions = event.diff.getAdditions(); | |
72 knownElements.addAll(additions); | |
73 viewerUpdater.add(additions.toArray()); | |
74 } | |
75 } | |
76 | |
77 /** | |
78 * Constructs an ObservableSetContentProvider | |
79 */ | |
80 public this() { | |
81 impl = new Impl(); | |
82 } | |
83 | |
84 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { | |
85 impl.inputChanged(viewer, oldInput, newInput); | |
86 } | |
87 | |
88 public Object[] getElements(Object inputElement) { | |
89 return impl.getElements(inputElement); | |
90 } | |
91 | |
92 public void dispose() { | |
93 impl.dispose(); | |
94 } | |
95 | |
96 /** | |
97 * Returns the set of elements known to this content provider. Label | |
98 * providers may track this set if they need to be notified about additions | |
99 * before the viewer sees the added element, and notified about removals | |
100 * after the element was removed from the viewer. This is intended for use | |
101 * by label providers, as it will always return the items that need labels. | |
102 * | |
103 * @return unmodifiable set of items that will need labels | |
104 */ | |
105 public IObservableSet getKnownElements() { | |
106 return impl.getKnownElements(); | |
107 } | |
108 } |