01: /*
02: * uDig - User Friendly Desktop Internet GIS client
03: * http://udig.refractions.net
04: * (C) 2004, Refractions Research Inc.
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation;
09: * version 2.1 of the License.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: */
17: package net.refractions.udig.project.ui.internal.adapters;
18:
19: import org.eclipse.core.runtime.Platform;
20: import org.eclipse.jface.viewers.IContentProvider;
21: import org.eclipse.jface.viewers.ITableColorProvider;
22: import org.eclipse.jface.viewers.ITableLabelProvider;
23: import org.eclipse.jface.viewers.ITreeContentProvider;
24: import org.eclipse.jface.viewers.Viewer;
25: import org.eclipse.swt.graphics.Color;
26: import org.eclipse.swt.graphics.Image;
27:
28: /**
29: * Adapts UDIG objects to table content and label providers.
30: * <p>
31: * Used to display UDIG Objects in tables, such as propertie view?
32: * </p>
33: *
34: * @author jones
35: * @since 0.3
36: */
37: public class UDIGTableProviderAdapter extends
38: UDIGAdapterContentProvider implements IContentProvider,
39: ITableColorProvider, ITableLabelProvider {
40:
41: private ITableColorProvider colors;
42:
43: /**
44: * @see org.eclipse.jface.viewers.ITableColorProvider#getForeground(java.lang.Object, int)
45: */
46: public Color getForeground(Object element, int columnIndex) {
47: return colors.getForeground(element, columnIndex);
48: }
49:
50: /**
51: * @see org.eclipse.jface.viewers.ITableColorProvider#getBackground(java.lang.Object, int)
52: */
53: public Color getBackground(Object element, int columnIndex) {
54: return colors.getBackground(element, columnIndex);
55: }
56:
57: /**
58: * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object, int)
59: */
60: public Image getColumnImage(Object element, int columnIndex) {
61: return ((ITableLabelProvider) labels).getColumnImage(element,
62: columnIndex);
63: }
64:
65: /**
66: * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
67: */
68: public String getColumnText(Object element, int columnIndex) {
69: return ((ITableLabelProvider) labels).getColumnText(element,
70: columnIndex);
71: }
72:
73: /**
74: * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer,
75: * java.lang.Object, java.lang.Object)
76: */
77: public void inputChanged(Viewer viewer, Object oldInput,
78: Object newInput) {
79: if (newInput != null && newInput != oldInput) {
80: content = (ITreeContentProvider) Platform
81: .getAdapterManager().getAdapter(newInput,
82: ITreeContentProvider.class);
83: labels = (ITableLabelProvider) Platform.getAdapterManager()
84: .getAdapter(newInput, ITableLabelProvider.class);
85: colors = (ITableColorProvider) Platform.getAdapterManager()
86: .getAdapter(newInput, ITableColorProvider.class);
87: }
88: }
89:
90: }
|