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.sql.framework.ui.editor.property.impl;
042:
043: import java.beans.PropertyEditorManager;
044: import java.io.IOException;
045: import java.io.InputStream;
046: import java.util.Map;
047: import org.netbeans.modules.etl.ui.view.property.ETLResourceManager;
048:
049: import org.netbeans.modules.sql.framework.ui.editor.property.IPropertySheet;
050: import org.netbeans.modules.sql.framework.ui.editor.property.IResource;
051:
052: /**
053: * @author Ritesh Adval
054: * @version $Revision$
055: */
056: public class PropertyViewManager {
057:
058: static {
059: // Ensure string properties are edited without
060: // the default multiline custom editor.
061: PropertyEditorManager.registerEditor(String.class,
062: DefaultPropertyEditor.SingleLineTextEditor.class);
063: }
064:
065: private TemplateManager tMgr;
066:
067: /** Creates a new instance of PropertyViewManager */
068: public PropertyViewManager(InputStream in, IResource resource) {
069: tMgr = new TemplateManager(in, resource);
070: }
071:
072: public PropertyNode getPropertyNodeForTemplateName(
073: String templateName, Map customizerMap, Object bean)
074: throws IllegalArgumentException {
075: PropertyNode pNode = tMgr.getNodeForTemplateName(templateName);
076: if (pNode == null) {
077: throw new IllegalArgumentException(
078: "Can not load template for template "
079: + templateName);
080: }
081:
082: if (bean instanceof Map) {
083: PropUtil.setInitialPropertyValues((Map) bean,
084: customizerMap, pNode);
085: } else {
086: PropUtil.setInitialPropertyValues(bean, customizerMap,
087: pNode);
088: }
089: return pNode;
090: }
091:
092: /**
093: * get IPropertySheet which has gui property panels
094: *
095: * @param map map of property name as key and property value as value for which a
096: * property sheet needs to be created
097: * @param customizerMap map of property name as key and IPropertyCustomizer as value
098: * @param templateName name of the template in xml descriptor
099: */
100: public IPropertySheet getPropertySheet(Map map, Map customizerMap,
101: String templateName) {
102: PropertyNode pNode = getPropertyNodeForTemplateName(
103: templateName, customizerMap, map);
104: return new BasicPropertySheet(pNode);
105: }
106:
107: /**
108: * get IPropertySheet which has gui property panels
109: *
110: * @param map map of property name as key and property value as value for which a
111: * property sheet needs to be created
112: * @param templateName name of the template in xml descriptor
113: */
114: public IPropertySheet getPropertySheet(Map map, String templateName) {
115: return getPropertySheet(map, null, templateName);
116: }
117:
118: /**
119: * get IPropertySheet which has gui property panels
120: *
121: * @param bean bean to whose properties are reflected and a property sheet is created
122: * @param customizerMap map of property name as key and IPropertyCustomizer as value
123: * @param templateName name of the template in xml descriptor
124: */
125: public IPropertySheet getPropertySheet(Object bean,
126: Map customizerMap, String templateName) {
127: return getPropertySheet(bean, templateName);
128: }
129:
130: /**
131: * get IPropertySheet which has gui property panels
132: *
133: * @param bean bean to whose properties are reflected and a property sheet is created
134: * @param templateName name of the template in xml descriptor
135: */
136: public IPropertySheet getPropertySheet(Object bean,
137: String templateName) {
138: PropertyNode pNode = getPropertyNodeForTemplateName(
139: templateName, null, bean);
140: return new BasicPropertySheet(bean, pNode);
141: }
142:
143: public static PropertyViewManager getPropertyViewManager() {
144: InputStream stream = null;
145: PropertyViewManager pvMgr = null;
146: try {
147: stream = PropertyViewManager.class
148: .getClassLoader()
149: .getResourceAsStream(
150: "org/netbeans/modules/etl/ui/resources/etl_properties.xml");
151: pvMgr = new PropertyViewManager(stream,
152: new ETLResourceManager());
153: } finally {
154: if (stream != null) {
155: try {
156: stream.close();
157: } catch (IOException ignore) {
158: // ignore
159: }
160: }
161: }
162: return pvMgr;
163: }
164: }
|