01: /* uDig - User Friendly Desktop Internet GIS client
02: * http://udig.refractions.net
03: * (C) 2004, Refractions Research Inc.
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation;
08: * version 2.1 of the License.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: */
15: package net.refractions.udig.project.internal.impl;
16:
17: import org.eclipse.core.runtime.IConfigurationElement;
18: import org.eclipse.core.runtime.IExtension;
19:
20: import net.refractions.udig.catalog.IGeoResource;
21: import net.refractions.udig.core.internal.ExtensionPointProcessor;
22: import net.refractions.udig.core.internal.ExtensionPointUtil;
23: import net.refractions.udig.project.StyleContent;
24: import net.refractions.udig.project.interceptor.LayerInterceptor;
25: import net.refractions.udig.project.internal.Layer;
26: import net.refractions.udig.project.internal.ProjectPlugin;
27:
28: /**
29: * Sets the default style of the
30: * @author Jesse
31: * @since 1.1.0
32: */
33: public class SetStyleInterceptor implements LayerInterceptor {
34:
35: public void run(Layer layer) {
36: if (layer.getStyleBlackboard().getContent().isEmpty()) {
37: ExtensionPointProcessor scp = createDefaultStyles(layer
38: .getGeoResource(), layer);
39: ExtensionPointUtil.process(ProjectPlugin.getPlugin(),
40: StyleContent.XPID, scp);
41: }
42: }
43:
44: /**
45: * Creates a default style from each styleContent extension and puts them on the style blackboard of the layer.
46: * @param theResource
47: * @param theLayer
48: * @return
49: */
50: private ExtensionPointProcessor createDefaultStyles(
51: final IGeoResource theResource, final Layer theLayer) {
52: ExtensionPointProcessor scp = new ExtensionPointProcessor() {
53: public void process(IExtension extension,
54: IConfigurationElement element) throws Exception {
55: StyleContent styleContent = (StyleContent) element
56: .createExecutableExtension("class"); //$NON-NLS-1$
57: Object style = styleContent.createDefaultStyle(
58: theResource, theLayer.getDefaultColor(), null);
59:
60: if (style != null) {
61: theLayer.getStyleBlackboard().put(
62: styleContent.getId(), style);
63: }
64: }
65: };
66: return scp;
67: }
68:
69: }
|