comparison org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/ObservableMapLabelProvider.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 * 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
38 private IMapChangeListener mapChangeListener = new class() IMapChangeListener {
39 public void handleMapChange(MapChangeEvent event) {
40 Set affectedElements = event.diff.getChangedKeys();
41 LabelProviderChangedEvent newEvent = new LabelProviderChangedEvent(
42 this.outer, affectedElements
43 .toArray());
44 fireLabelProviderChanged(newEvent);
45 }
46 };
47
48 /**
49 * @param attributeMap
50 */
51 public this(IObservableMap attributeMap) {
52 this([ cast(IObservableMap)attributeMap ]);
53 }
54
55 /**
56 * @param attributeMaps
57 */
58 public this(IObservableMap[] attributeMaps) {
59 System.arraycopy(attributeMaps, 0, this.attributeMaps = attributeMaps, 0, attributeMaps.length);
60 for (int i = 0; i < attributeMaps.length; i++) {
61 attributeMaps[i].addMapChangeListener(mapChangeListener);
62 }
63 }
64
65 public void dispose() {
66 for (int i = 0; i < attributeMaps.length; i++) {
67 attributeMaps[i].removeMapChangeListener(mapChangeListener);
68 }
69 super.dispose();
70 }
71
72 public Image getImage(Object element) {
73 return null;
74 }
75
76 public String getText(Object element) {
77 return getColumnText(element, 0);
78 }
79
80 public Image getColumnImage(Object element, int columnIndex) {
81 return null;
82 }
83
84 public String getColumnText(Object element, int columnIndex) {
85 if (columnIndex < attributeMaps.length) {
86 Object result = attributeMaps[columnIndex].get(element);
87 return result is null ? "" : result.toString(); //$NON-NLS-1$
88 }
89 return null;
90 }
91
92 }