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.properties;
018:
019: import java.io.IOException;
020: import java.util.ArrayList;
021: import java.util.List;
022:
023: import net.refractions.udig.catalog.IGeoResource;
024: import net.refractions.udig.project.ui.internal.Messages;
025:
026: import org.eclipse.ui.views.properties.IPropertyDescriptor;
027: import org.eclipse.ui.views.properties.IPropertySource2;
028: import org.eclipse.ui.views.properties.PropertyDescriptor;
029: import org.geotools.data.FeatureSource;
030:
031: /**
032: * A Property source for services.
033: *
034: * @author jeichar
035: * @since 0.3
036: */
037: public class IGeoResourcePropertySource implements IPropertySource2 {
038: private IGeoResource geoResource;
039: private IPropertyDescriptor[] descriptors;
040: private static final String RESOURCE = Messages.IGeoResourcePropertySource_0;
041: IPropertyDescriptor resourceDescriptor;
042: private static final String FEATURE_SOURCE = Messages.IGeoResourcePropertySource_1;
043:
044: /**
045: * Creates a new instance of DataPropertySource
046: *
047: * @param entry
048: */
049: public IGeoResourcePropertySource(IGeoResource entry) {
050: this .geoResource = entry;
051: }
052:
053: /**
054: * @see org.eclipse.ui.views.properties.IPropertySource#getEditableValue()
055: */
056: public Object getEditableValue() {
057: // TODO Auto-generated method stub
058: return null;
059: }
060:
061: /**
062: * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyDescriptors()
063: */
064: public IPropertyDescriptor[] getPropertyDescriptors() {
065: if (descriptors == null) {
066: List<IPropertyDescriptor> desc = new ArrayList<IPropertyDescriptor>();
067: try {
068: if (geoResource.canResolve(FeatureSource.class)) {
069: resourceDescriptor = new SchemaDescriptor(
070: FEATURE_SOURCE,
071: Messages.IGeoResourcePropertySource_schema,
072: (FeatureSource) geoResource.resolve(
073: FeatureSource.class, null));
074: } else {
075: resourceDescriptor = new PropertyDescriptor(
076: RESOURCE,
077: Messages.IGeoResourcePropertySource_data);
078: }
079: } catch (IOException e) {
080: // TODO Catch e
081: e.printStackTrace();
082: }
083: desc.add(resourceDescriptor);
084: descriptors = new IPropertyDescriptor[desc.size()];
085: desc.toArray(descriptors);
086: }
087: IPropertyDescriptor[] c = new IPropertyDescriptor[descriptors.length];
088: System.arraycopy(descriptors, 0, c, 0, c.length);
089: return c;
090: }
091:
092: /**
093: * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyValue(java.lang.Object)
094: */
095: public Object getPropertyValue(Object id) {
096: if (id.equals(FEATURE_SOURCE)) {
097: return resourceDescriptor;
098: }
099: if (id.equals(RESOURCE))
100: try {
101: return geoResource.resolve(FeatureSource.class, null);
102: } catch (IOException e) {
103: // TODO Catch e
104: e.printStackTrace();
105: }
106: return null;
107: }
108:
109: /**
110: * @see org.eclipse.ui.views.properties.IPropertySource#isPropertySet(java.lang.Object)
111: */
112: public boolean isPropertySet(Object id) {
113: // TODO Auto-generated method stub
114: return false;
115: }
116:
117: /**
118: * @see org.eclipse.ui.views.properties.IPropertySource#resetPropertyValue(java.lang.Object)
119: */
120: public void resetPropertyValue(Object id) {
121: // TODO Auto-generated method stub
122: }
123:
124: /**
125: * @see org.eclipse.ui.views.properties.IPropertySource#setPropertyValue(java.lang.Object,
126: * java.lang.Object)
127: */
128: public void setPropertyValue(Object id, Object value) {
129: // TODO Auto-generated method stub
130: }
131:
132: /**
133: * @see org.eclipse.ui.views.properties.IPropertySource2#isPropertyResettable(java.lang.Object)
134: */
135: public boolean isPropertyResettable(Object id) {
136: // TODO implement method body
137: return true;
138: }
139: }
|