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-2008 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:
042: /*
043: * PaletteHelper.java
044: *
045: * Created on February 20, 2008, 9:00 AM
046: */
047: package org.netbeans.modules.visualweb.test.components.util;
048:
049: import java.awt.Point;
050: import java.util.Properties;
051: import org.netbeans.jellytools.Bundle;
052: import org.netbeans.jemmy.JemmyException;
053: import org.netbeans.modules.visualweb.gravy.RaveWindowOperator;
054: import org.netbeans.modules.visualweb.gravy.designer.DesignerPaneOperator;
055: import org.netbeans.modules.visualweb.gravy.properties.SheetTableOperator;
056: import org.netbeans.modules.visualweb.gravy.toolbox.PaletteContainerOperator;
057:
058: /**
059: *
060: * @author Martin.Schovanek@sun.com
061: */
062: public enum PaletteHelper {
063:
064: ADVANCED(Const.JSF_BUNDLE, Const.JSF_ADVACED_PREFIX,
065: Const.PALETTE_PREFIX + "Advanced"), ADVANCED_DATA_PROVIDERS(
066: Const.DATA_BUNDLE, Const.DATA_PREFIX, Const.PALETTE_PREFIX
067: + "AdvancedDataProviders"), BASIC(Const.WS_BUNDLE,
068: Const.WS_PREFIX, Const.PALETTE_PREFIX + "Basic"), COMPOSITE(
069: Const.WS_BUNDLE, Const.WS_PREFIX, Const.PALETTE_PREFIX
070: + "Composite"), CONVERTERS(Const.JSF_BUNDLE,
071: Const.JSF_CONVERTERS_PREFIX, Const.PALETTE_PREFIX
072: + "Converters"), DATA_PROVIDERS(Const.DATA_BUNDLE,
073: Const.DATA_PREFIX, Const.PALETTE_PREFIX + "DataProviders"), LAYOUT(
074: Const.WS_BUNDLE, Const.WS_PREFIX, Const.PALETTE_PREFIX
075: + "Layout"), STANDARD(Const.JSF_BUNDLE,
076: Const.JSF_STANDARD_PREFIX, Const.PALETTE_PREFIX
077: + "Standard"), VALIDATORS(Const.JSF_BUNDLE,
078: Const.JSF_VALIDATORS_PREFIX, Const.PALETTE_PREFIX
079: + "Validators");
080:
081: // Resouurce Bundle name
082: private final String bundle;
083: // components keys prefix
084: private final String compPrefix;
085: // palete display name
086: private final String palette;
087:
088: PaletteHelper(String bundle, String prefix, String paletteKey) {
089: this .bundle = bundle;
090: this .compPrefix = prefix;
091: this .palette = getString(bundle, paletteKey);
092: }
093:
094: /**
095: * Appends the specified component on [x,y] position and sets approriate text
096: * properties.
097: *
098: * @param componentId 'compPrefix' + this value should be a valid 'bundle' key.
099: * @param x x coordinate
100: * @param y y coordinate
101: * @param properties String[n][2] array, where n is nuber of properties,
102: * [n][0] - is property name and [n][1] - is it value.
103: */
104: public void addComponent(String componentId, int x, int y,
105: String properties) {
106: String component = getString(bundle, compPrefix + componentId);
107: log("** Adding component " + palette + " > " + component);
108: DesignerPaneOperator designerOp = new DesignerPaneOperator(
109: RaveWindowOperator.getDefaultRave());
110: PaletteContainerOperator paletteOp = new PaletteContainerOperator(
111: palette);
112: paletteOp.addComponent(component, designerOp, new Point(x, y));
113: if (properties != null) {
114: Properties prop = ComponentUtils
115: .parseProperties(properties);
116: SheetTableOperator sheet = new SheetTableOperator();
117: for (Object key : prop.keySet()) {
118: String val = prop.getProperty((String) key);
119: log("** Setting property: " + key + "=" + val);
120: sheet.setTextValue((String) key, val);
121: }
122: }
123: }
124:
125: private String getString(String bundle, String key) {
126: String str = null;
127: try {
128: str = Bundle.getStringTrimmed(bundle, key);
129: } catch (JemmyException je) {
130: throw new JemmyException("Key: " + key
131: + " was not found in: " + bundle, je);
132: }
133: return str;
134: }
135:
136: private void log(String msg) {
137: System.err.println(msg);
138: }
139:
140: private class Const {
141:
142: static final String DATA_BUNDLE = "org.netbeans.modules.visualweb.dataprovider.designtime.resources.Bundle";
143: static final String DATA_PREFIX = "NAME_com-sun-webui-jsf-component-";
144: static final String JSF_BUNDLE = "org.netbeans.modules.visualweb.jsfsupport.designtime.resources.Bundle";
145: static final String JSF_ADVACED_PREFIX = "NAME_org-netbeans-modules-visualweb-faces-dt-component-";
146: static final String JSF_CONVERTERS_PREFIX = "NAME_org-netbeans-modules-visualweb-faces-dt-converter-";
147: static final String JSF_STANDARD_PREFIX = "NAME_org-netbeans-modules-visualweb-faces-dt-component-html-";
148: static final String JSF_VALIDATORS_PREFIX = "NAME_org-netbeans-modules-visualweb-faces-dt-validator-";
149: static final String PALETTE_PREFIX = "CreatorDesignerPalette5/";
150: static final String WS_BUNDLE = "org.netbeans.modules.visualweb.woodstock.webui.jsf.designtime.resources.Bundle";
151: static final String WS_PREFIX = "NAME_com-sun-webui-jsf-component-";
152: };
153: }
|