001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.compapp.casaeditor.properties;
042:
043: import org.netbeans.modules.compapp.casaeditor.properties.extension.ExtensionPropertyFactory;
044: import java.util.Map;
045: import org.netbeans.modules.compapp.casaeditor.Constants;
046: import org.netbeans.modules.compapp.casaeditor.model.casa.CasaComponent;
047: import org.netbeans.modules.compapp.casaeditor.model.casa.CasaEndpointRef;
048: import org.netbeans.modules.compapp.casaeditor.model.casa.CasaExtensibilityElement;
049: import org.netbeans.modules.compapp.casaeditor.model.casa.CasaServiceUnit;
050: import org.netbeans.modules.compapp.casaeditor.nodes.CasaNode;
051: import org.netbeans.modules.compapp.projects.jbi.api.JbiExtensionAttribute;
052: import org.openide.ErrorManager;
053: import org.openide.nodes.Node;
054: import org.openide.nodes.PropertySupport;
055: import org.openide.nodes.Sheet;
056: import org.openide.util.NbBundle;
057:
058: /**
059: * @author nk160297
060: */
061: public abstract class PropertyUtils {
062:
063: public static enum PropertiesGroups {
064: MAIN_SET, IDENTIFICATION_SET, TARGET_SET, CONSUMER_SET, PROVIDER_SET, EXPERT_SET, COLOR_SET, FONT_SET, GENERIC_SET;
065:
066: private String myDisplayName;
067:
068: public String getDisplayName() {
069: if (myDisplayName == null) {
070: myDisplayName = NbBundle.getMessage(PropertyType.class,
071: this .toString());
072: }
073: return myDisplayName;
074: }
075: }
076:
077: public static Node.Property createErrorProperty(String displayName) {
078: return new PropertySupport.ReadOnly<String>("error", // NOI18N
079: String.class, displayName, Constants.EMPTY_STRING) {
080: public String getValue() {
081: return NbBundle.getMessage(PropertyUtils.class,
082: "PROP_ERROR_VALUE"); // NOI18N
083: }
084: };
085: }
086:
087: public static void installEndpointInterfaceQNameProperty(
088: Sheet.Set propertySet, CasaNode node,
089: CasaEndpointRef component, String propertyType,
090: String attributeName, String displayName,
091: String displayDescription) {
092: try {
093: Node.Property property = new PropertyEndpointInterfaceQName(
094: node, component, propertyType, attributeName,
095: displayName, displayDescription);
096: propertySet.put(property);
097: } catch (Exception e) {
098: propertySet.put(createErrorProperty(displayName));
099: ErrorManager.getDefault().notify(e);
100: }
101: }
102:
103: public static void installEndpointServiceQNameProperty(
104: Sheet.Set propertySet, CasaNode node,
105: CasaEndpointRef component, String propertyType,
106: String attributeName, String displayName,
107: String displayDescription) {
108: try {
109: Node.Property property = new PropertyEndpointServiceQName(
110: node, component, propertyType, attributeName,
111: displayName, displayDescription);
112: propertySet.put(property);
113: } catch (Exception e) {
114: propertySet.put(createErrorProperty(displayName));
115: ErrorManager.getDefault().notify(e);
116: }
117: }
118:
119: public static void installEndpointNameProperty(
120: Sheet.Set propertySet, CasaNode node,
121: CasaComponent component, String propertyType,
122: String attributeName, String displayName,
123: String displayDescription) {
124: try {
125: Node.Property property = new PropertyEndpointName(node,
126: component, propertyType, attributeName,
127: displayName, displayDescription);
128: propertySet.put(property);
129: } catch (Exception e) {
130: propertySet.put(createErrorProperty(displayName));
131: ErrorManager.getDefault().notify(e);
132: }
133: }
134:
135: public static void installServiceUnitNameProperty(
136: Sheet.Set propertySet, CasaNode node,
137: CasaServiceUnit component, String propertyType,
138: String attributeName, String displayName,
139: String displayDescription) {
140: try {
141: Node.Property property = new PropertyServiceUnitName(node,
142: component, propertyType, attributeName,
143: displayName, displayDescription);
144: propertySet.put(property);
145: } catch (Exception e) {
146: propertySet.put(createErrorProperty(displayName));
147: ErrorManager.getDefault().notify(e);
148: }
149: }
150:
151: /**
152: * Installs a CASA configuration extension property.
153: *
154: * @param propertySet target property sheet set
155: * @param node node corresponding to the extension point component
156: * @param extensionPointComponent a CASA extension point component
157: * @param firstEE the first (top-level) CASA extensibility element
158: * directly under the CASA extension point component
159: * @param lastEE the owner CASA extensibility element of the new
160: * attribute being installed
161: * @param propertyType
162: * @param type class type of the attribute
163: * @param attributeName name of the attribute
164: * @param displayname display name of the attribute
165: * @param description description of the attribute
166: */
167: public static void installExtensionProperty(Sheet.Set propertySet,
168: CasaNode node, CasaComponent extensionPointComponent,
169: CasaExtensibilityElement firstEE,
170: CasaExtensibilityElement lastEE, String propertyType,
171: String attrType, String attributeName, String displayName,
172: String description) {
173:
174: if (attrType == null) {
175: System.err.println("Unsupported property type for "
176: + attributeName);
177: attrType = "String"; //JbiExtensionAttribute.Type.STRING;
178: }
179:
180: try {
181: Node.Property property = ExtensionPropertyFactory
182: .getProperty(node, extensionPointComponent,
183: firstEE, lastEE, propertyType, attrType,
184: attributeName, displayName, description);
185:
186: propertySet.put(property);
187: } catch (Exception e) {
188: propertySet.put(createErrorProperty(displayName));
189: ErrorManager.getDefault().notify(e);
190: }
191: }
192:
193: /**
194: * Installs a CASA configuration extension property of enumerated strings.
195: *
196: * @param propertySet target property sheet set
197: * @param node node corresponding to the extension point component
198: * @param extensionPointComponent a CASA extension point component
199: * @param firstEE the first (top-level) CASA extensibility element
200: * directly under the CASA extension point component
201: * @param lastEE the owner CASA extensibility element of the new
202: * attribute being installed
203: * @param propertyType
204: * @param type class type of the attribute
205: * @param attributeName name of the attribute
206: * @param displayname display name of the attribute
207: * @param description description of the attribute
208: * @param choiceMap a map mapping choice element names to pre-built
209: * extensibility elements
210: * @param defaultChoice default choice
211: */
212: public static void installChoiceExtensionProperty(
213: Sheet.Set propertySet, CasaNode node,
214: CasaComponent extensionPointComponent,
215: CasaExtensibilityElement firstEE,
216: CasaExtensibilityElement lastEE, String propertyType,
217: Class valueType, String attributeName, String displayName,
218: String description,
219: Map<String, CasaExtensibilityElement> choiceMap,
220: String defaultChoice) {
221:
222: assert valueType == String.class;
223:
224: try {
225: Node.Property property = ExtensionPropertyFactory
226: .getProperty(node, extensionPointComponent,
227: firstEE, lastEE, propertyType,
228: attributeName, displayName, description,
229: choiceMap, defaultChoice);
230:
231: propertySet.put(property);
232: } catch (Exception e) {
233: propertySet.put(createErrorProperty(displayName));
234: ErrorManager.getDefault().notify(e);
235: }
236: }
237: }
|