001: /**
002: *
003: */package net.refractions.udig.feature.editor;
004:
005: import net.refractions.udig.feature.editor.internal.Messages;
006: import net.refractions.udig.internal.ui.UiPlugin;
007: import net.refractions.udig.project.IMap;
008: import net.refractions.udig.project.ui.ApplicationGIS;
009: import net.refractions.udig.project.ui.IUDIGView;
010: import net.refractions.udig.project.ui.tool.IToolContext;
011:
012: import org.eclipse.core.runtime.IAdaptable;
013: import org.eclipse.jface.viewers.StructuredSelection;
014: import org.eclipse.swt.widgets.Composite;
015: import org.eclipse.ui.part.ViewPart;
016: import org.eclipse.ui.views.properties.IPropertyDescriptor;
017: import org.eclipse.ui.views.properties.IPropertySource;
018: import org.eclipse.ui.views.properties.PropertyDescriptor;
019: import org.eclipse.ui.views.properties.PropertySheetPage;
020: import org.geotools.feature.Feature;
021:
022: /**
023: * @author Jesse
024: *
025: */
026: public class DefaultEditor extends ViewPart implements IUDIGView {
027:
028: /**
029: *
030: */
031: public DefaultEditor() {
032: super ();
033: }
034:
035: private IToolContext context;
036: private PropertySheetPage featureDisplay;
037: private Feature current;
038:
039: /**
040: * @see net.refractions.udig.project.ui.IUDIGView#setContext()
041: */
042: public void setContext(IToolContext context) {
043: this .context = context;
044: }
045:
046: /**
047: * @see net.refractions.udig.project.ui.IUDIGView#getContext()
048: */
049: public IToolContext getContext() {
050: return context;
051: }
052:
053: public void editFeatureChanged(Feature feature) {
054: current = feature;
055: StructuredSelection selection;
056: Object value = defaultSource;
057: if (current != null)
058: value = current;
059: else
060: value = defaultSource;
061: selection = new StructuredSelection(value);
062: featureDisplay.selectionChanged(null, selection);
063: }
064:
065: /* (non-Javadoc)
066: * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
067: */
068: public void createPartControl(Composite parent) {
069: featureDisplay = new PropertySheetPage();
070: featureDisplay.createControl(parent);
071: final IMap map = ApplicationGIS.getActiveMap();
072: if (map != null) {
073: try {
074: editFeatureChanged(map.getEditManager()
075: .getEditFeature());
076: } catch (Throwable e) {
077: UiPlugin.log(
078: "Default Feature Editor threw an exception", e); //$NON-NLS-1$
079: }
080:
081: }
082: }
083:
084: /* (non-Javadoc)
085: * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
086: */
087: public void setFocus() {
088: featureDisplay.setFocus();
089: if (current == null)
090: featureDisplay.selectionChanged(null,
091: new StructuredSelection(defaultSource));
092: }
093:
094: IAdaptable defaultSource = new IAdaptable() {
095:
096: public Object getAdapter(Class adapter) {
097: if (IPropertySource.class.isAssignableFrom(adapter))
098: return new IPropertySource() {
099:
100: public void setPropertyValue(Object id, Object value) {
101: // TODO Auto-generated method stub
102:
103: }
104:
105: public void resetPropertyValue(Object id) {
106: // TODO Auto-generated method stub
107:
108: }
109:
110: public boolean isPropertySet(Object id) {
111: // TODO Auto-generated method stub
112: return false;
113: }
114:
115: public Object getPropertyValue(Object id) {
116: return ""; //$NON-NLS-1$
117: }
118:
119: public IPropertyDescriptor[] getPropertyDescriptors() {
120: return new PropertyDescriptor[] { new PropertyDescriptor(
121: "ID", Messages.DefaultEditor_1) }; //$NON-NLS-1$
122: }
123:
124: public Object getEditableValue() {
125: return null;
126: }
127:
128: };
129: return null;
130: }
131:
132: };
133: }
|