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:
042: package org.netbeans.modules.visualweb.gravy.model.project.components;
043:
044: import org.netbeans.modules.visualweb.gravy.model.project.WebPage;
045: import org.netbeans.modules.visualweb.gravy.model.components.*;
046: import org.netbeans.modules.visualweb.gravy.properties.SheetTableOperator;
047: import org.netbeans.modules.visualweb.gravy.DocumentOutlineOperator;
048: import org.netbeans.modules.visualweb.gravy.RaveWindowOperator;
049: import org.netbeans.modules.visualweb.gravy.TestUtils;
050:
051: import org.netbeans.jemmy.operators.JTreeOperator;
052: import org.netbeans.jemmy.JemmyException;
053:
054: import java.awt.Container;
055: import javax.swing.JLabel;
056: import java.util.Hashtable;
057:
058: /**
059: * Common class for all components on web page.
060: */
061:
062: public class Component {
063:
064: final static String OS_MAC = "Mac OS X";
065: final static String OS_SOL = "SunOS";
066: final static String OS_WIN = "Windows";
067: final static String OS_LIN = "Linux";
068: final String propName = "id";
069: public WebPage Page;
070: protected String Type = "";
071:
072: /**
073: * Component's properties.
074: */
075: private Hashtable properties = new Hashtable();
076:
077: /**
078: * Create component on web page using web component from palette.
079: * @param webcomponent Web component from palette.
080: * @param name Name of component.
081: */
082: public Component(WebComponent webcomponent, String name) {
083: Type = webcomponent.getID();
084: properties.put(propName, name);
085: }
086:
087: /**
088: * Get name of component.
089: * @return Name of component.
090: */
091: public String getName() {
092: return ((String) getProperty(propName));
093: }
094:
095: /**
096: * Get type of component.
097: * @return Type of component.
098: */
099: public String getType() {
100: return Type;
101: }
102:
103: /**
104: * Return property value.
105: * @param name Name of property.
106: * @return Property value.
107: */
108: public String getProperty(String name) {
109: return properties.get(name).toString();
110: }
111:
112: /**
113: * Set property value.
114: * @param name Name of property.
115: * @param value Value of property.
116: */
117: public void setProperty(String name, String value) {
118: Page.open();
119: DocumentOutlineOperator outline = new DocumentOutlineOperator(
120: RaveWindowOperator.getDefaultRave());
121: TestUtils.wait(1000);
122: JTreeOperator aotree = outline.getStructTreeOperator();
123: try {
124: aotree.selectPath(aotree.findPath(Page.getName()
125: + "|page1|html1|body1|form1|" + getName()));
126: } catch (Exception e) {
127: throw new JemmyException("Path " + Page.getName()
128: + "|page1|html1|body1|form1|" + getName()
129: + " can't be selected!", e);
130: }
131: TestUtils.wait(1000);
132: try {
133: SheetTableOperator sheet = new SheetTableOperator();
134: String class_0 = ((Container) sheet.getRenderedComponent(
135: sheet.findCell("name:" + name, 0).y, 1))
136: .getComponent(0).getClass().getName();
137: String class_1 = ((Container) sheet.getRenderedComponent(
138: sheet.findCell("name:" + name, 0).y, 1))
139: .getComponent(1).getClass().getName();
140: String propName = ((JLabel) sheet.getRenderedComponent(
141: sheet.findCell("name:" + name, 0).y, 0)).getText();
142: if (class_1
143: .equals("org.openide.explorer.propertysheet.RendererFactory$StringRenderer"))
144: sheet.setTextValue(propName, value);
145: if (class_1
146: .equals("org.openide.explorer.propertysheet.RendererFactory$CheckboxRenderer"))
147: sheet.setCheckBoxValue(propName, value);
148: if (class_1
149: .equals("org.openide.explorer.propertysheet.RendererFactory$ComboboxRenderer")
150: || (class_0.indexOf("AquaComboBoxButton") != -1 && System
151: .getProperty("os.name").equals(OS_MAC))
152: || (class_0.indexOf("javax.swing.JButton") != -1 && System
153: .getProperty("os.name").equals(OS_SOL))
154: || (class_0.indexOf("WindowsComboBoxUI") != -1
155: && class_0.indexOf("ComboBoxButton") != -1 && System
156: .getProperty("os.name").indexOf(OS_WIN) != -1)
157: || (class_0.indexOf("javax.swing.JButton") != -1 && System
158: .getProperty("os.name").equals(OS_LIN)))
159: sheet.setComboBoxValue(propName, value);
160: } catch (Exception e) {
161: throw new JemmyException("Property can't be set!", e);
162: }
163: properties.put(name, value);
164: }
165: }
|