001: package net.refractions.udig.style.sld;
002:
003: import net.refractions.udig.project.internal.Layer;
004:
005: import org.eclipse.jface.resource.ImageDescriptor;
006: import org.eclipse.swt.SWT;
007: import org.eclipse.swt.layout.FillLayout;
008: import org.eclipse.swt.widgets.Composite;
009: import org.eclipse.swt.widgets.Control;
010: import org.eclipse.ui.part.PageBook;
011: import org.geotools.styling.StyleBuilder;
012:
013: /**
014: * Provides a user interface to edit a component of an Style Layer Descriptor (SLD) style object.
015: * <p>
016: * An SLD style component can be one of the following classes of object:
017: * <ul>
018: * <li>
019: *
020: * @see org.geotools.renderer.style.Style
021: * <li>
022: * @see org.geotools.styling.FeatureTypeStyle
023: * <li>
024: * @see org.geotools.styling.Rule
025: * <li>
026: * @see org.geotools.styling.Symbolizer
027: * </ul>
028: * </p>
029: * <p>
030: * This object does not store state. Any state information of ui widgets must be immediatley
031: * reflected in the style component.
032: * </p>
033: * @author Justin Deoliveira, Refractions Research Inc.
034: */
035: public abstract class SLDEditorPart {
036:
037: public static final String XPID = "net.refractions.udig.style.sld.sldEditorPart"; //$NON-NLS-1$
038:
039: /** the ui control for the SLDEditor part * */
040: private Composite page;
041:
042: /** the style component * */
043: private Object content;
044:
045: /** the label for the SLDEditor part * */
046: private String label;
047:
048: /** the path to the icon for the extension * */
049: private ImageDescriptor image;
050:
051: /** the layer being styled * */
052: private Layer layer;
053:
054: /** the id of the plugin providing the extension * */
055: private String pluginId;
056:
057: /** style builder used to create styling * */
058: private StyleBuilder styleBuilder;
059:
060: public SLDEditorPart() {
061:
062: }
063:
064: /**
065: * Returns the ui control. This method should not be overridden.
066: *
067: * @return The ui control.
068: */
069: public Composite getPage() {
070: return page;
071: }
072:
073: /**
074: * Signals the ui control to be created. This method should not be overidden.
075: *
076: * @param parent The parent control.
077: */
078: public void createControl(PageBook book) {
079: page = new Composite(book, SWT.NONE);
080: page.setLayout(new FillLayout());
081: page.setData(getLabel());
082: createPartControl(page);
083: }
084:
085: /**
086: * @return Returns the content.
087: */
088: public Object getContent() {
089: return content;
090: }
091:
092: /**
093: * @param content The content to set.
094: */
095: public void setContent(Object content) {
096: this .content = content;
097: }
098:
099: /**
100: * @return Returns the label.
101: */
102: public String getLabel() {
103: return label;
104: }
105:
106: /**
107: * @param label The label to set.
108: */
109: public void setLabel(String label) {
110: this .label = label;
111: }
112:
113: /**
114: * @return Returns the layer.
115: */
116: public Layer getLayer() {
117: return layer;
118: }
119:
120: /**
121: * @param layer The layer to set.
122: */
123: public void setLayer(Layer layer) {
124: this .layer = layer;
125: }
126:
127: /**
128: * @param styleBuilder The styleBuilder to set.
129: */
130: public void setStyleBuilder(StyleBuilder styleBuilder) {
131: this .styleBuilder = styleBuilder;
132: }
133:
134: /**
135: * @return Returns the styleBuilder.
136: */
137: public StyleBuilder getStyleBuilder() {
138: return styleBuilder;
139: }
140:
141: /**
142: * @param image The image descriptor.
143: */
144: public void setImageDescriptor(ImageDescriptor image) {
145: this .image = image;
146: }
147:
148: /**
149: * @return The image descriptor.
150: */
151: public ImageDescriptor getImageDescriptor() {
152: return image;
153: }
154:
155: /**
156: * @param pluginId The pluginId to set.
157: */
158: public void setPluginId(String pluginId) {
159: this .pluginId = pluginId;
160: }
161:
162: /**
163: * @return Returns the pluginId.
164: */
165: public String getPluginId() {
166: return pluginId;
167: }
168:
169: /**
170: * Returns an image descriptor for the editor part. Sublcasses have the option of overiding to
171: * provide a custom image.
172: */
173: public ImageDescriptor createImageDescriptor() {
174: return SLD.createImageDescriptor(getContentType());
175: }
176:
177: /**
178: * Initializes the editor. This method is called before the ui is created so this method should
179: * not attempt to access any of its (yet to be created) widgets.
180: */
181: public abstract void init();
182:
183: /**
184: * Style class, like TextSymbolizer, used for editing.
185: *
186: * @return the class of style component the ui is used for editing.
187: */
188: public abstract Class getContentType();
189:
190: /**
191: * The internal method for creating the ui component. The parent control passed to the method
192: * must not be modified in any way.
193: *
194: * @param parent The parent control.
195: * @return The newly created control.
196: */
197: protected abstract Control createPartControl(Composite parent);
198:
199: /**
200: * Resets the editor. This method resets the ui to reflect the new state of the content being
201: * edited, and the layer being styled.. This method is not called unless content, and a layer
202: * are available.
203: */
204: public abstract void reset();
205: }
|