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.cachedrowsetdataprovider;
043:
044: import java.awt.*;
045: import java.util.*;
046: import java.util.regex.*;
047: import javax.swing.*;
048: import javax.swing.text.*;
049: import javax.swing.tree.*;
050: import org.netbeans.jemmy.*;
051: import org.netbeans.jemmy.operators.*;
052: import org.netbeans.modules.visualweb.gravy.*;
053: import org.netbeans.modules.visualweb.gravy.dataconnectivity.*;
054: import org.netbeans.modules.visualweb.gravy.designer.*;
055: import org.netbeans.modules.visualweb.gravy.toolbox.*;
056: import org.netbeans.test.dataprovider.common.*;
057:
058: public class TripTable extends JSFComponent {
059: public TripTable() {
060: componentName = COMPONENT_TABLE_NAME;
061: componentID = "table1"; // default Table id
062: dbTableName = DB_TABLE_TRIP;
063: }
064:
065: public String makeTripTable() {
066: String errMsg = null;
067: try {
068: putVisualComponentOnDesigner(25, 220);
069: // now Table component is selected in Navigator
070:
071: componentPoint = getComponentPoint(); // component should be selected
072: Utils.doSaveAll();
073:
074: putDBTableOnComponent();
075: Utils.doSaveAll();
076: modifyTableLayout();
077: modifyTripRowSet();
078: checkTableLayout();
079: setSQLTimestampConverter();
080: } catch (Exception e) {
081: e.printStackTrace(Utils.logStream);
082: errMsg = (e.getMessage() == null ? e.toString() : e
083: .getMessage());
084: }
085: return errMsg;
086: }
087:
088: private void modifyTripRowSet() { // modify SQL statement for tripRowSet
089: String tripRowSetNode = NAVIGATOR_TREE_NODE_SESSION_PREFIX
090: + Utils.getBaseRowSetName(dbTableName);
091: Utils.callPopupMenuOnNavigatorTreeNode(tripRowSetNode,
092: POPUP_MENU_ITEM_EDIT_SQL_STATEMENT);
093: QueryBuilderOperator queryBuilderOperator = new QueryBuilderOperator();
094: queryBuilderOperator.addParamCriteria(DB_TABLE_TRIP_PERSONID);
095:
096: Utils.doSaveAll();
097:
098: //queryBuilderOperator.close();
099: //Util.wait(500);
100: //new QueueTool().waitEmpty();
101: Utils.doCloseWindow();
102:
103: selectModifiedTripRowSet(tripRowSetNode);
104: String valuePropertyCommand = Utils
105: .getSelectedComponentProperty(PROPERTY_NAME_COMMAND);
106: Utils.logMsg("+++ [" + Utils.getBaseRowSetName(dbTableName)
107: + "]: value of property [" + PROPERTY_NAME_COMMAND
108: + "] = [" + valuePropertyCommand + "]");
109:
110: String pattern = PATTERN_ANY_CHARS + "WHERE"
111: + PATTERN_ANY_CHARS + DB_TABLE_TRIP_PERSONID
112: + PATTERN_ANY_CHARS + "=" + PATTERN_ANY_CHARS + "\\?";
113: String sqlWhereClause = "WHERE " + DB_TABLE_TRIP_PERSONID
114: + " = ?";
115: boolean result = Pattern.matches(pattern, sqlWhereClause);
116: if (!result) {
117: throw new RuntimeException("SQL statement for ["
118: + Utils.getBaseRowSetName(dbTableName)
119: + "] should end with [" + sqlWhereClause + "]");
120: }
121: Utils.logMsg("+++ Clause [" + sqlWhereClause
122: + "] was appended correctly to SQL statement of ["
123: + tripRowSetNode + "]");
124: }
125:
126: private void selectModifiedTripRowSet(String tripRowSetNode) {
127: /** a tree subnode tripRowSet won't be selected properly in the window Navigator by
128: * using JTreeOperator due to having very long node label "tripRowSet:SELECT ALL ..."
129: //Utils.use_JTreeOperator_Verification = false;
130: TreePath tripRowSetTreePath = Utils.findNavigatorTreeNode(tripRowSetNode, true);
131: //Utils.use_JTreeOperator_Verification = true;
132: **/
133: JTree jTree = ((JTree) Utils.getNavigatorTreeOperator()
134: .getSource());
135: TreePath treePath = Utils.selectChildOfTreeNode(jTree,
136: NAVIGATOR_TREE_NODE_SESSION_PREFIX.replace("|", ""),
137: Utils.getBaseRowSetName(dbTableName));
138: if (treePath == null) {
139: throw new RuntimeException(
140: "Tree node ["
141: + tripRowSetNode
142: + "] wasn't selected correctly in the window Navigator");
143: }
144: Utils.logMsg("+++ Selected treePath = ["
145: + jTree.getSelectionPath().toString() + "] ("
146: + treePath.getClass().getName() + ")");
147: }
148:
149: private void modifyTableLayout() {
150: callPopupMenuItem(POPUP_MENU_ITEM_TABLE_LAYOUT);
151: JDialogOperator jDialogOp = new JDialogOperator(
152: DIALOG_TITLE_TABLE_LAYOUT);
153: hideDBColumns(jDialogOp);
154:
155: new JButtonOperator(jDialogOp, BUTTON_LABEL_OK).pushNoBlock();
156: Util.wait(500);
157: new QueueTool().waitEmpty();
158: Utils.doSaveAll();
159: }
160:
161: private void hideDBColumns(JDialogOperator jDialogOp) {
162: JListOperator jListOp = new JListOperator(jDialogOp, 1);
163: String[] hiddenColumns = getHiddenDBColumnNames();
164: for (String hiddenColumnName : hiddenColumns) {
165: selectVisibleDBColumn(jListOp, hiddenColumnName);
166: Util.wait(500);
167: new QueueTool().waitEmpty();
168:
169: new JButtonOperator(jDialogOp, BUTTON_LABEL_TO_LEFT)
170: .pushNoBlock();
171: Util.wait(500);
172: new QueueTool().waitEmpty();
173: }
174: }
175:
176: private void selectVisibleDBColumn(JListOperator jListOp,
177: String columnName) {
178: int listSize = jListOp.getModel().getSize();
179: for (int i = 0; i < listSize; ++i) {
180: String listItem = jListOp.getModel().getElementAt(i)
181: .toString();
182: if (listItem.toUpperCase().endsWith(
183: columnName.toUpperCase())) {
184: jListOp.setSelectedIndex(i);
185: Utils
186: .logMsg("+++ DB column ["
187: + listItem
188: + "] was removed from list of Selected Table Columns");
189: break;
190: }
191: }
192: }
193:
194: private String[] getHiddenDBColumnNames() {
195: return (new String[] { DB_TABLE_TRIP_TRIPID,
196: DB_TABLE_TRIP_PERSONID, DB_TABLE_TRIP_LASTUPDATED });
197: }
198:
199: private void checkTableLayout() {
200: callPopupMenuItem(POPUP_MENU_ITEM_TABLE_LAYOUT);
201: JDialogOperator jDialogOp = new JDialogOperator(
202: DIALOG_TITLE_TABLE_LAYOUT);
203: java.util.List<String> tableColumnList = makeVisibleColumnList(jDialogOp), controlColumnList = Arrays
204: .asList(getVisibleDBColumnNames());
205:
206: new JButtonOperator(jDialogOp, BUTTON_LABEL_CANCEL)
207: .pushNoBlock();
208: Util.wait(500);
209: new QueueTool().waitEmpty();
210:
211: for (int i = 0; i < tableColumnList.size(); ++i) {
212: String columnName = tableColumnList.get(i), controlName = controlColumnList
213: .get(i);
214: if (!columnName.toUpperCase().endsWith(
215: controlName.toUpperCase())) {
216: throw new RuntimeException("List of table columns "
217: + tableColumnList
218: + " doesn't correspond to control list: "
219: + controlColumnList);
220: }
221: }
222: Utils.logMsg("+++ List of table columns is correct: "
223: + tableColumnList);
224: }
225:
226: private java.util.List<String> makeVisibleColumnList(
227: JDialogOperator jDialogOp) {
228: JListOperator jListOp = new JListOperator(jDialogOp, 1);
229: int listSize = jListOp.getModel().getSize();
230: java.util.List<String> visibleColumnList = new ArrayList<String>();
231: for (int i = 0; i < listSize; ++i) {
232: String listItem = jListOp.getModel().getElementAt(i)
233: .toString();
234: visibleColumnList.add(listItem);
235: }
236: return visibleColumnList;
237: }
238:
239: private String[] getVisibleDBColumnNames() {
240: return (new String[] { DB_TABLE_TRIP_DEPDATE,
241: DB_TABLE_TRIP_DEPCITY, DB_TABLE_TRIP_DESTCITY,
242: DB_TABLE_TRIP_TRIPTYPEID });
243: }
244:
245: private void setSQLTimestampConverter() {
246: Utils.putComponentOnDesigner(PALETTE_NAME_CONVERTERS,
247: COMPONENT_SQL_TIMESTAMP_CONVERTER_NAME,
248: SQL_TIMESTAMP_CONVERTER_ID, 5, 5,
249: NAVIGATOR_TREE_NODE_PAGE_PREFIX);
250: Utils.findNavigatorTreeNode(NAVIGATOR_TREE_NODE_PAGE_PREFIX
251: + SQL_TIMESTAMP_CONVERTER_ID, true);
252: Utils.setTextPropertyValue(PROPERTY_NAME_PATTERN,
253: SQL_TIMESTAMP_CONVERTER_PATTERN);
254: Utils.doSaveAll();
255:
256: JTree jTree = ((JTree) Utils.getNavigatorTreeOperator()
257: .getSource());
258: TreePath parentTreePath = Utils.findNavigatorTreeNode(
259: NAVIGATOR_TREE_NODE_TABLE1_ROWGROUP_PREFIX, true);
260: TreePath treePath = Utils.selectChildOfTreeNode(jTree,
261: parentTreePath, 0);
262: treePath = Utils.selectChildOfTreeNode(jTree, treePath, 0);
263: if (treePath == null) {
264: throw new RuntimeException(
265: "1st child of tree node ["
266: + parentTreePath.toString()
267: + "] wasn't selected correctly in the window Navigator");
268: }
269: Utils.logMsg("+++ Selected treePath = ["
270: + jTree.getSelectionPath().toString() + "] ("
271: + treePath.getClass().getName() + ")");
272:
273: Utils.setComboboxPropertyValue(PROPERTY_NAME_CONVERTER,
274: SQL_TIMESTAMP_CONVERTER_ID);
275: Utils.doSaveAll();
276: Utils.logMsg("+++ SQL Timestamp converter was added.");
277: }
278: }
|