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.util.ArrayList;
020: import java.util.List;
021:
022: import net.refractions.udig.project.ui.internal.Messages;
023:
024: import org.eclipse.jface.viewers.CellEditor;
025: import org.eclipse.swt.widgets.Composite;
026: import org.eclipse.ui.views.properties.IPropertyDescriptor;
027: import org.eclipse.ui.views.properties.IPropertySource;
028: import org.eclipse.ui.views.properties.PropertyDescriptor;
029: import org.geotools.data.FeatureSource;
030: import org.geotools.feature.AttributeType;
031: import org.geotools.feature.FeatureType;
032: import org.geotools.feature.GeometryAttributeType;
033:
034: /**
035: * A Descriptor for a FeatureType aka Schema for the properties view.
036: *
037: * @author jeichar
038: * @since 1.0.0
039: */
040: public class SchemaDescriptor extends PropertyDescriptor implements
041: IPropertySource {
042:
043: private IPropertyDescriptor[] descriptors;
044: private FeatureType type;
045:
046: /**
047: * Creates a new instance of FeatureSourceDescriptor
048: *
049: * @param id
050: * @param name
051: * @param source
052: */
053: public SchemaDescriptor(Object id, String name, FeatureSource source) {
054: super (id, name);
055: type = source.getSchema();
056: }
057:
058: /**
059: * @see org.eclipse.ui.views.properties.PropertyDescriptor#createPropertyEditor(org.eclipse.swt.widgets.Composite)
060: */
061: public CellEditor createPropertyEditor(Composite parent) {
062: return new SchemaEditor(parent, type);
063: }
064:
065: /**
066: * @see org.eclipse.ui.views.properties.IPropertySource#getEditableValue()
067: */
068: public Object getEditableValue() {
069: // TODO Auto-generated method stub
070: return null;
071: }
072:
073: /**
074: * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyDescriptors()
075: */
076: public IPropertyDescriptor[] getPropertyDescriptors() {
077: if (descriptors == null) {
078: List<IPropertyDescriptor> desc = new ArrayList<IPropertyDescriptor>();
079: AttributeType[] attrs = type.getAttributeTypes();
080: PropertyDescriptor d;
081: for (int i = 0; i < attrs.length; i++) {
082: String name = attrs[i].getName().toLowerCase();
083: name = name.substring(0, 1).toUpperCase()
084: + name.substring(1);
085: d = new PropertyDescriptor(Integer.valueOf(i), name);
086: if (attrs[i] instanceof GeometryAttributeType)
087: d.setCategory(Messages.ScemaDescriptor_geometry);
088: else
089: d
090: .setCategory(Messages.ScemaDescriptor_attributeTypes);
091: desc.add(d);
092: }
093: descriptors = new IPropertyDescriptor[desc.size()];
094: desc.toArray(descriptors);
095: }
096: IPropertyDescriptor[] c = new IPropertyDescriptor[descriptors.length];
097: System.arraycopy(descriptors, 0, c, 0, c.length);
098: return c;
099: }
100:
101: /**
102: * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyValue(java.lang.Object)
103: */
104: public Object getPropertyValue(Object id) {
105: int i = ((Integer) id).intValue();
106: String name = type.getAttributeType(i).getType().getName();
107: return name.substring(name.lastIndexOf('.') + 1);
108: }
109:
110: /**
111: * @see org.eclipse.ui.views.properties.IPropertySource#isPropertySet(java.lang.Object)
112: */
113: public boolean isPropertySet(Object id) {
114: // TODO Auto-generated method stub
115: return false;
116: }
117:
118: /**
119: * @see org.eclipse.ui.views.properties.IPropertySource#resetPropertyValue(java.lang.Object)
120: */
121: public void resetPropertyValue(Object id) {
122: // TODO Auto-generated method stub
123:
124: }
125:
126: /**
127: * @see org.eclipse.ui.views.properties.IPropertySource#setPropertyValue(java.lang.Object,
128: * java.lang.Object)
129: */
130: public void setPropertyValue(Object id, Object value) {
131: // TODO Auto-generated method stub
132:
133: }
134: }
|