78
|
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 164247
|
|
11 * Brad Reynolds - bug 164134
|
|
12 *******************************************************************************/
|
|
13
|
|
14 module org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider;
|
|
15
|
|
16 import java.lang.all;
|
|
17
|
|
18 import java.util.Set;
|
|
19
|
|
20 import org.eclipse.core.databinding.observable.map.IMapChangeListener;
|
|
21 import org.eclipse.core.databinding.observable.map.IObservableMap;
|
|
22 import org.eclipse.core.databinding.observable.map.MapChangeEvent;
|
|
23 import org.eclipse.jface.viewers.ILabelProvider;
|
|
24 import org.eclipse.jface.viewers.ITableLabelProvider;
|
|
25 import org.eclipse.jface.viewers.LabelProvider;
|
|
26 import org.eclipse.jface.viewers.LabelProviderChangedEvent;
|
|
27 import org.eclipse.swt.graphics.Image;
|
|
28
|
|
29 /**
|
|
30 * @since 1.1
|
|
31 *
|
|
32 */
|
|
33 public class ObservableMapLabelProvider : LabelProvider
|
|
34 , ILabelProvider, ITableLabelProvider {
|
|
35
|
|
36 private final IObservableMap[] attributeMaps;
|
|
37
|
85
|
38 private IMapChangeListener mapChangeListener;
|
|
39 class MapChangeListener : IMapChangeListener {
|
78
|
40 public void handleMapChange(MapChangeEvent event) {
|
|
41 Set affectedElements = event.diff.getChangedKeys();
|
|
42 LabelProviderChangedEvent newEvent = new LabelProviderChangedEvent(
|
|
43 this.outer, affectedElements
|
|
44 .toArray());
|
|
45 fireLabelProviderChanged(newEvent);
|
|
46 }
|
|
47 };
|
|
48
|
|
49 /**
|
|
50 * @param attributeMap
|
|
51 */
|
|
52 public this(IObservableMap attributeMap) {
|
|
53 this([ cast(IObservableMap)attributeMap ]);
|
|
54 }
|
|
55
|
|
56 /**
|
|
57 * @param attributeMaps
|
|
58 */
|
|
59 public this(IObservableMap[] attributeMaps) {
|
85
|
60 mapChangeListener = new MapChangeListener();
|
|
61 System.arraycopyT(attributeMaps, 0, this.attributeMaps = attributeMaps, 0, attributeMaps.length);
|
78
|
62 for (int i = 0; i < attributeMaps.length; i++) {
|
|
63 attributeMaps[i].addMapChangeListener(mapChangeListener);
|
|
64 }
|
|
65 }
|
|
66
|
|
67 public void dispose() {
|
|
68 for (int i = 0; i < attributeMaps.length; i++) {
|
|
69 attributeMaps[i].removeMapChangeListener(mapChangeListener);
|
|
70 }
|
|
71 super.dispose();
|
|
72 }
|
|
73
|
|
74 public Image getImage(Object element) {
|
|
75 return null;
|
|
76 }
|
|
77
|
|
78 public String getText(Object element) {
|
|
79 return getColumnText(element, 0);
|
|
80 }
|
|
81
|
|
82 public Image getColumnImage(Object element, int columnIndex) {
|
|
83 return null;
|
|
84 }
|
|
85
|
|
86 public String getColumnText(Object element, int columnIndex) {
|
|
87 if (columnIndex < attributeMaps.length) {
|
|
88 Object result = attributeMaps[columnIndex].get(element);
|
|
89 return result is null ? "" : result.toString(); //$NON-NLS-1$
|
|
90 }
|
|
91 return null;
|
|
92 }
|
|
93
|
|
94 }
|