001: /*
002: * uDig - User Friendly Desktop Internet GIS client
003: * http://udig.refractions.net
004: * (C) 2004, Refractions Research Inc.
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: */
017: package net.refractions.udig.project.ui.internal.adapters;
018:
019: import org.eclipse.core.runtime.Platform;
020: import org.eclipse.jface.viewers.IBaseLabelProvider;
021: import org.eclipse.jface.viewers.IContentProvider;
022: import org.eclipse.jface.viewers.ILabelProvider;
023: import org.eclipse.jface.viewers.ILabelProviderListener;
024: import org.eclipse.jface.viewers.ITreeContentProvider;
025: import org.eclipse.jface.viewers.Viewer;
026: import org.eclipse.swt.graphics.Image;
027:
028: /**
029: * Adapts UDIG objects to tree content and label providers.
030: *
031: * @author jones
032: * @since 0.3
033: */
034: public class UDIGAdapterContentProvider implements
035: ITreeContentProvider, ILabelProvider {
036:
037: protected ITreeContentProvider content;
038: protected IBaseLabelProvider labels;
039:
040: /**
041: * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
042: */
043: public Object[] getChildren(Object parentElement) {
044: if (content == null)
045: return null;
046: return content.getChildren(parentElement);
047: }
048:
049: /**
050: * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
051: */
052: public Object getParent(Object element) {
053: if (content == null)
054: return null;
055: return content.getParent(element);
056: }
057:
058: /**
059: * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
060: */
061: public boolean hasChildren(Object element) {
062: if (content == null)
063: return false;
064: return content.hasChildren(element);
065: }
066:
067: /**
068: * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object)
069: */
070: public Image getImage(Object element) {
071: if (labels == null)
072: return null;
073: return ((ILabelProvider) labels).getImage(element);
074: }
075:
076: /**
077: * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
078: */
079: public String getText(Object element) {
080: if (labels == null)
081: return null;
082: return ((ILabelProvider) labels).getText(element);
083: }
084:
085: /**
086: * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
087: */
088: public Object[] getElements(Object inputElement) {
089: if (content == null)
090: return null;
091: return content.getElements(inputElement);
092: }
093:
094: /**
095: * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
096: */
097: public void dispose() {
098: if (content != null)
099: content.dispose();
100: if (labels != null)
101: labels.dispose();
102: }
103:
104: /**
105: * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer,
106: * java.lang.Object, java.lang.Object)
107: */
108: public void inputChanged(Viewer viewer, Object oldInput,
109: Object newInput) {
110: content = (ITreeContentProvider) Platform.getAdapterManager()
111: .getAdapter(newInput, IContentProvider.class);
112: labels = (ILabelProvider) Platform.getAdapterManager()
113: .getAdapter(newInput, ILabelProvider.class);
114: }
115:
116: /**
117: * @see org.eclipse.jface.viewers.IBaseLabelProvider#addListener(org.eclipse.jface.viewers.ILabelProviderListener)
118: */
119: public void addListener(ILabelProviderListener listener) {
120: if (labels == null)
121: return;
122: labels.addListener(listener);
123: }
124:
125: /**
126: * @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(java.lang.Object,
127: * java.lang.String)
128: */
129: public boolean isLabelProperty(Object element, String property) {
130: if (labels == null)
131: return false;
132: return labels.isLabelProperty(element, property);
133: }
134:
135: /**
136: * @see org.eclipse.jface.viewers.IBaseLabelProvider#removeListener(org.eclipse.jface.viewers.ILabelProviderListener)
137: */
138: public void removeListener(ILabelProviderListener listener) {
139: if (labels == null)
140: return;
141: labels.removeListener(listener);
142: }
143:
144: }
|