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:
007: The contents of this file are subject to the terms of either the GNU
008: General Public License Version 2 only ("GPL") or the Common
009: Development and Distribution License("CDDL") (collectively, the
010: "License"). You may not use this file except in compliance with the
011: License. You can obtain a copy of the License at
012: http://www.netbeans.org/cddl-gplv2.html
013: or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
014: specific language governing permissions and limitations under the
015: License. When distributing the software, include this License Header
016: Notice in each file and include the License file at
017: nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
018: particular file as subject to the "Classpath" exception as provided
019: by Sun in the GPL Version 2 section of the License file that
020: accompanied this code. If applicable, add the following below the
021: License Header, with the fields enclosed by brackets [] replaced by
022: your own identifying information:
023: "Portions Copyrighted [year] [name of copyright owner]"
024:
025: Contributor(s):
026:
027: The Original Software is NetBeans. The Initial Developer of the Original
028: Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
029: Microsystems, Inc. All Rights Reserved.
030:
031: If you wish your version of this file to be governed by only the CDDL
032: or only the GPL Version 2, indicate your decision by adding
033: "[Contributor] elects to include this software in this distribution
034: under the [CDDL or GPL Version 2] license." If you do not indicate a
035: single choice of license, a recipient has the option to distribute
036: your version of this file under either the CDDL, the GPL Version 2 or
037: to extend the choice of license to its licensees as provided above.
038: However, if you add GPL Version 2 code and therefore, elected the GPL
039: Version 2 license, then the option applies only if the new code is
040: made subject to such option by the copyright holder.
041: */
042: package org.netbeans.test.dataprovider.common;
043:
044: import java.awt.*;
045: import javax.swing.tree.*;
046: import org.netbeans.jemmy.*;
047: import org.netbeans.jemmy.operators.*;
048: import org.netbeans.modules.visualweb.gravy.*;
049: import org.netbeans.modules.visualweb.gravy.designer.*;
050: import org.netbeans.modules.visualweb.gravy.toolbox.*;
051:
052: public abstract class JSFComponent implements Constants {
053: protected String componentName, componentID, dbTableName;
054: protected Point componentPoint;
055:
056: protected void putVisualComponentOnDesigner(int x, int y) {
057: Utils.putComponentOnDesigner(PALETTE_NAME_BASIC,
058: this .componentName, this .componentID, x, y,
059: NAVIGATOR_TREE_NODE_FORM_PREFIX);
060: }
061:
062: protected void changeComponentID(String newComponentID) { // component should be selected
063: Utils.setTextPropertyValue(PROPERTY_NAME_ID, newComponentID);
064: Utils.logMsg("+++ Component [" + componentName + "("
065: + componentID + ")] has got new value of property ["
066: + PROPERTY_NAME_ID + "] = [" + newComponentID + "]");
067: componentID = newComponentID;
068: }
069:
070: protected Point getComponentPoint() { // component should be selected
071: Point componentPoint = Utils
072: .getSelectedComponentLeftUpperPoint();
073: if (componentPoint == null) {
074: throw new RuntimeException(
075: "Problem with getting of coordinates of ["
076: + componentName + "(" + componentID + ")]");
077: }
078: Utils.logMsg("+++ Component [" + componentID
079: + "] coordinates: [" + componentPoint.x + ", "
080: + componentPoint.y + "]");
081: return componentPoint;
082: }
083:
084: protected void putDBTableOnComponent() {
085: String dbURL = TestPropertiesHandler
086: .getDatabaseProperty("DB_URL");
087: Utils.putDBTableOnComponent(dbURL, dbTableName, componentPoint);
088: String rowSetName = NAVIGATOR_TREE_NODE_SESSION_PREFIX
089: + Utils.getBaseRowSetName(dbTableName), dataProviderName = NAVIGATOR_TREE_NODE_PAGE_PREFIX
090: + Utils.getBaseDataProviderName(dbTableName);
091: checkRowSetAppearance(rowSetName);
092: checkDataProviderAppearance(dataProviderName);
093: }
094:
095: protected void checkRowSetAppearance(String rowSetNodeName) {
096: StringBuffer errMsg = new StringBuffer();
097: if (Utils.findNavigatorTreeNode(rowSetNodeName, 3500, false) == null) {
098: errMsg.append("The tree node [" + rowSetNodeName
099: + "] isn't found in the window [Navigator]");
100: } else {
101: Utils.logMsg("+++ CachedRowSet [" + rowSetNodeName
102: + "] is found in the window [Navigator]");
103: }
104: if (errMsg.length() > 0) {
105: throw new RuntimeException(errMsg.toString());
106: }
107: }
108:
109: protected void checkDataProviderAppearance(
110: String dataProviderNodeName) {
111: StringBuffer errMsg = new StringBuffer();
112: if (Utils.findNavigatorTreeNode(dataProviderNodeName, 3500,
113: false) == null) {
114: errMsg.append((errMsg.length() > 0 ? " " : "")
115: + "The tree node [" + dataProviderNodeName
116: + "] isn't found in the window [Navigator]");
117: } else {
118: Utils.logMsg("+++ DataProvider [" + dataProviderNodeName
119: + "] is found in the window [Navigator]");
120: }
121: if (errMsg.length() > 0) {
122: throw new RuntimeException(errMsg.toString());
123: }
124: }
125:
126: protected void bindComponentDataProvider(String dataProviderName) {
127: callPopupMenuItem(POPUP_MENU_ITEM_BIND_DATA);
128: try {
129: JDialogOperator dialogOp = null;
130: try {
131: dialogOp = new JDialogOperator(DIALOG_TITLE_BIND_DATA);
132: } catch (TimeoutExpiredException tee) {
133: Util.wait(500);
134: new QueueTool().waitEmpty();
135: throw new RuntimeException("Dialog ["
136: + DIALOG_TITLE_BIND_DATA + "] didn't appear");
137: }
138: if (dialogOp != null) {
139: Utils.logMsg("+++ Dialog [" + DIALOG_TITLE_BIND_DATA
140: + "] is found");
141:
142: JComboBoxOperator comboboxOp = new JComboBoxOperator(
143: dialogOp, 0);
144: comboboxOp.selectItem(dataProviderName);
145: Util.wait(1500);
146: new QueueTool().waitEmpty();
147: Utils.logMsg("+++ Combobox item [" + dataProviderName
148: + "] is selected for component [" + componentID
149: + "]");
150:
151: JListOperator listOp = new JListOperator(dialogOp, 0);
152: listOp.selectItem(1);
153: String listSelectedValue = listOp.getSelectedValue()
154: .toString();
155: Util.wait(1500);
156: new QueueTool().waitEmpty();
157: Utils.logMsg("+++ List item [" + listSelectedValue
158: + "] is selected for component [" + componentID
159: + "]");
160:
161: new JButtonOperator(dialogOp, BUTTON_LABEL_OK)
162: .pushNoBlock();
163: Util.wait(1000);
164: new QueueTool().waitEmpty();
165: }
166: } catch (Exception e) {
167: e.printStackTrace(System.out);
168: throw new RuntimeException(e);
169: }
170: Util.wait(1000);
171: new QueueTool().waitEmpty();
172: Utils.doSaveAll();
173: }
174:
175: protected void callPopupMenuItem(String menuItemLabel) {
176: Utils.callPopupMenuOnNavigatorTreeNode(
177: NAVIGATOR_TREE_NODE_FORM_PREFIX + componentID,
178: menuItemLabel);
179: }
180: }
|