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.ui.operations;
16:
17: import net.refractions.udig.internal.ui.UiPlugin;
18:
19: import org.eclipse.core.runtime.IConfigurationElement;
20: import org.eclipse.core.runtime.Platform;
21:
22: public class PropertyParser implements FilterParser {
23:
24: public PropertyParser() {
25: super ();
26: }
27:
28: public OpFilter parse(IConfigurationElement element) {
29: String desiredPropertyId = element.getAttribute("propertyId"); //$NON-NLS-1$
30: // try the deprecated one if the required new one is not there
31: if (desiredPropertyId == null
32: || desiredPropertyId.trim().length() == 0)
33: desiredPropertyId = element.getAttribute("name"); //$NON-NLS-1$
34: String expectedValue = element.getAttribute("expectedValue"); //$NON-NLS-1$
35:
36: if (desiredPropertyId == null
37: || desiredPropertyId.length() == 0) {
38: UiPlugin
39: .log(
40: "EnablesFor element is not valid. PropertyId must be supplied.", null); //$NON-NLS-1$
41: return OpFilter.TRUE;
42: }
43:
44: IConfigurationElement[] configuration = Platform
45: .getExtensionRegistry().getConfigurationElementsFor(
46: "net.refractions.udig.ui.objectProperty"); //$NON-NLS-1$
47: IConfigurationElement propertyElement = null;
48: String targetClass = null;
49: for (IConfigurationElement configurationElement : configuration) {
50: if (propertyElement != null)
51: break;
52: IConfigurationElement[] children = configurationElement
53: .getChildren("property"); //$NON-NLS-1$
54: for (IConfigurationElement child : children) {
55: String currentPropertyID = child.getAttribute("id"); //$NON-NLS-1$
56: currentPropertyID = child.getNamespaceIdentifier()
57: + "." + currentPropertyID; //$NON-NLS-1$
58: if (currentPropertyID.equals(desiredPropertyId)) {
59: propertyElement = child;
60: targetClass = configurationElement
61: .getAttribute("targetClass"); //$NON-NLS-1$
62: // try the deprecated one if the required new one is not there
63: if (targetClass == null
64: || targetClass.trim().length() == 0)
65: targetClass = configurationElement
66: .getAttribute("class"); //$NON-NLS-1$
67: break;
68: }
69: }
70: }
71:
72: if (propertyElement == null) {
73: UiPlugin
74: .log(
75: "PropertyParser: Parsing PropertyValue, desired Propert: " + desiredPropertyId + " not found. Referenced in plugin: " + element.getNamespaceIdentifier(), null); //$NON-NLS-1$ //$NON-NLS-2$
76: return OpFilter.TRUE;
77: }
78:
79: if (targetClass == null) {
80: UiPlugin
81: .log(
82: "PropertyParser: Parsing PropertyValue, no target class defined in property" + desiredPropertyId, null); //$NON-NLS-1$
83:
84: return OpFilter.TRUE;
85: }
86:
87: OpFilterPropertyValueCondition enablesFor;
88: enablesFor = new OpFilterPropertyValueCondition(
89: propertyElement, targetClass, expectedValue);
90:
91: return enablesFor;
92: }
93:
94: public String getElementName() {
95: return "property"; //$NON-NLS-1$
96: }
97: }
|