0001: /*
0002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0003: *
0004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
0005: *
0006: * The contents of this file are subject to the terms of either the GNU
0007: * General Public License Version 2 only ("GPL") or the Common
0008: * Development and Distribution License("CDDL") (collectively, the
0009: * "License"). You may not use this file except in compliance with the
0010: * License. You can obtain a copy of the License at
0011: * http://www.netbeans.org/cddl-gplv2.html
0012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
0013: * specific language governing permissions and limitations under the
0014: * License. When distributing the software, include this License Header
0015: * Notice in each file and include the License file at
0016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
0017: * particular file as subject to the "Classpath" exception as provided
0018: * by Sun in the GPL Version 2 section of the License file that
0019: * accompanied this code. If applicable, add the following below the
0020: * License Header, with the fields enclosed by brackets [] replaced by
0021: * your own identifying information:
0022: * "Portions Copyrighted [year] [name of copyright owner]"
0023: *
0024: * Contributor(s):
0025: *
0026: * The Original Software is NetBeans. The Initial Developer of the Original
0027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
0028: * Microsystems, Inc. All Rights Reserved.
0029: *
0030: * If you wish your version of this file to be governed by only the CDDL
0031: * or only the GPL Version 2, indicate your decision by adding
0032: * "[Contributor] elects to include this software in this distribution
0033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
0034: * single choice of license, a recipient has the option to distribute
0035: * your version of this file under either the CDDL, the GPL Version 2 or
0036: * to extend the choice of license to its licensees as provided above.
0037: * However, if you add GPL Version 2 code and therefore, elected the GPL
0038: * Version 2 license, then the option applies only if the new code is
0039: * made subject to such option by the copyright holder.
0040: */
0041:
0042: /*
0043: * Utils.java
0044: *
0045: * Created on 31 ���� 2005 �., 19:11
0046: * @author psb
0047: */
0048:
0049: package org.netbeans.test.uml.designpatterns.utils;
0050:
0051: import java.awt.Point;
0052: import java.awt.event.InputEvent;
0053: import org.netbeans.jellytools.TopComponentOperator;
0054: import org.netbeans.jellytools.TreeTableOperator;
0055: import org.netbeans.jellytools.actions.Action;
0056: import org.netbeans.jemmy.JemmyProperties;
0057: import org.netbeans.jemmy.Timeouts;
0058: import org.netbeans.jemmy.drivers.input.MouseEventDriver;
0059: import org.netbeans.jemmy.operators.JComboBoxOperator;
0060: import org.netbeans.modules.uml.ui.swing.treetable.JTreeTable;
0061: import java.awt.event.KeyEvent;
0062: import java.util.StringTokenizer;
0063: import javax.swing.JTextField;
0064: import org.netbeans.jellytools.MainWindowOperator;
0065: import org.netbeans.jellytools.NewProjectWizardOperator;
0066: import org.netbeans.jellytools.actions.NewProjectAction;
0067: import org.netbeans.jellytools.nodes.Node;
0068: import org.netbeans.jellytools.nodes.ProjectRootNode;
0069: import org.netbeans.jellytools.properties.Property;
0070: import org.netbeans.jellytools.properties.PropertySheetOperator;
0071: import org.netbeans.jemmy.EventTool;
0072: import org.netbeans.jemmy.Timeout;
0073: import org.netbeans.jemmy.drivers.DriverManager;
0074: import org.netbeans.jemmy.drivers.input.KeyRobotDriver;
0075: import org.netbeans.jemmy.drivers.input.MouseRobotDriver;
0076: import org.netbeans.jemmy.operators.JButtonOperator;
0077: import org.netbeans.jemmy.operators.JCheckBoxOperator;
0078: import org.netbeans.jemmy.operators.JDialogOperator;
0079: import org.netbeans.jemmy.operators.JLabelOperator;
0080: import org.netbeans.jemmy.operators.JListOperator;
0081: import org.netbeans.jemmy.operators.JMenuBarOperator;
0082: import org.netbeans.jemmy.operators.JProgressBarOperator;
0083: import org.netbeans.jemmy.operators.JTableOperator;
0084: import org.netbeans.jemmy.operators.JTextFieldOperator;
0085: import org.netbeans.jemmy.operators.JTreeOperator;
0086: import org.netbeans.jemmy.util.Dumper;
0087: import org.netbeans.test.umllib.CompartmentOperator;
0088: import org.netbeans.test.umllib.DiagramOperator;
0089: import org.netbeans.test.umllib.EditControlOperator;
0090: import org.netbeans.test.umllib.exceptions.NotFoundException;
0091: import org.netbeans.test.umllib.testcases.UMLTestCase;
0092: import org.netbeans.test.umllib.util.LabelsAndTitles;
0093: import org.netbeans.test.umllib.util.OptionsOperator;
0094:
0095: /**
0096: *
0097: * @author psb
0098: */
0099: public class Utils {
0100:
0101: //
0102: private static boolean innerCall = false;
0103: //
0104: private static String umlSourcePackagesColumn = "int";
0105: private static String umlSourcePackagesLabel = "public";
0106: private static String umlSourceUsageColumn = "public";
0107: //
0108: public static String defaultNewElementName = "Unnamed";
0109: public static String defaultReturnType = "void";
0110: public static String defaultAttributeType = "int";
0111: public static String defaultAttributeVisibility = "private";
0112: public static String defaultAttributeValue = "";
0113: public static String defaultOperationVisibility = "public";
0114: public static String defaultClassVisibility = "Java Application";
0115: //
0116: public static String javaProjectsCategory = "Project Name:";
0117: public static String javaProjectApplication = "Project Location:";
0118: //
0119: public static final String createDesignCenterProjectTitle = "Create Design Center Project";
0120: public static final String createDesignCenterProjectNameLabel = "Project Name:";
0121: public static final String createDesignCenterProjectLocationLabel = "Project Location:";
0122: //
0123: private static int minWait = 500;
0124: private static int longWait = 1000;
0125: {
0126: DriverManager.setMouseDriver(new MouseRobotDriver(new Timeout(
0127: "", 10)));
0128: DriverManager.setKeyDriver(new KeyRobotDriver(new Timeout(
0129: "autoDelay", 50)));
0130: }
0131:
0132: /**
0133: * It works with existing edit control with
0134: * "anyVisibility anyType anyName = anyValue" and "anyVisibility anyType anyName"
0135: * initial attribute with selected name (after Insert or double click).
0136: * Default values can be passed as null.
0137: * @param visibility
0138: * @param type
0139: * @param name
0140: * @param defValue
0141: * @param pressEnter
0142: * @return resulting string in edit control
0143: */
0144: public static String attributeNaturalWayNaming(String visibility,
0145: String type, String name, String defValue,
0146: boolean pressEnter) {
0147: new EventTool().waitNoEvent(minWait);
0148: //support null as default value
0149: if (defValue == null) {
0150: defValue = defaultAttributeValue;
0151: }
0152: //
0153: if (visibility == null) {
0154: visibility = defaultAttributeVisibility;
0155: }
0156: //
0157: if (type == null) {
0158: type = defaultAttributeType;
0159: }
0160: //
0161: if (name == null) {
0162: name = defaultNewElementName;
0163: }
0164: EditControlOperator ec = new EditControlOperator();
0165: JTextFieldOperator tf = ec.getTextFieldOperator();
0166: //
0167: String initialTxt = tf.getText();
0168: StringTokenizer prState = new StringTokenizer(initialTxt,
0169: " \t\n\r\f=");
0170: if (prState.countTokens() < 3) {
0171: innerCall = false;
0172: throw new UnsupportedOperationException(
0173: "Utility can't handle your case (Possible absence of visibility or/and type or/and name).");
0174: }
0175: String oldVis = prState.nextToken();
0176: String oldType = prState.nextToken();
0177: String oldName = prState.nextToken();
0178: String oldDefVal = "";
0179: if (prState.hasMoreTokens()) {
0180: oldDefVal = prState.nextToken();
0181: }
0182: boolean isName = !oldName.equals(name);
0183: boolean isType = !oldType.equals(type);
0184: boolean isVis = !oldVis.equals(visibility);
0185: boolean isDefVal = !oldDefVal.equals(defValue);
0186: //different way:
0187: if (!isVis && !isType) {
0188: //only name and if needed defValue
0189: //check selection
0190: int nameFrom = initialTxt.indexOf(oldName, oldVis.length()
0191: + oldType.length());
0192: int nameTo = nameFrom + oldName.length();
0193: //check if name the same
0194: if (isName) {
0195: //select name
0196: if (tf.getSelectionStart() != nameFrom
0197: && tf.getSelectionEnd() != nameTo) {
0198: tf.selectText(nameFrom, nameTo);
0199: }
0200: if (name.length() > 0) {
0201: //type name
0202: for (int i = 0; i < name.length(); i++) {
0203: tf.typeKey(name.charAt(i));
0204: }
0205: } else {
0206: tf.pushKey(KeyEvent.VK_BACK_SPACE);
0207: }
0208: new EventTool().waitNoEvent(minWait);
0209: } else {
0210: //name the same as exists, do nothing
0211: }
0212: //
0213: if (isDefVal) {
0214: //go to def value
0215: if (oldDefVal.length() > 0 || defValue.length() > 0) {
0216: tf.typeKey('=');
0217: }
0218: //delete old def value
0219: for (int i = 0; i < oldDefVal.length(); i++) {
0220: tf.pushKey(KeyEvent.VK_DELETE);
0221: }
0222: if (defValue.length() > 0) {
0223: //type new
0224: for (int i = 0; i < defValue.length(); i++) {
0225: tf.typeKey(defValue.charAt(i));
0226: }
0227: } else if (oldDefVal.length() > 0) {
0228: tf.pushKey(KeyEvent.VK_RIGHT);
0229: tf.pushKey(KeyEvent.VK_BACK_SPACE);
0230: }
0231: new EventTool().waitNoEvent(minWait);
0232: }
0233: } else if (isType && !isVis) {
0234: if (isName || isDefVal) {
0235: //if there is need to change name and/or def value
0236: if (!innerCall) {
0237: innerCall = true;
0238: attributeNaturalWayNaming(oldVis, oldType, name,
0239: oldDefVal, false);
0240: }
0241: if (!innerCall) {
0242: innerCall = true;
0243: attributeNaturalWayNaming(visibility, type, name,
0244: oldDefVal, false);
0245: }
0246: if (!innerCall) {
0247: innerCall = true;
0248: attributeNaturalWayNaming(visibility, type, name,
0249: defValue, false);
0250: }
0251: } else {
0252: int typeFrom = initialTxt.indexOf(oldType, oldVis
0253: .length());
0254: int typeTo = typeFrom + oldType.length();
0255: //
0256: if (tf.getSelectionStart() != typeFrom
0257: && tf.getSelectionEnd() != typeTo) {
0258: tf.selectText(typeFrom, typeTo);
0259: }
0260: if (type.length() > 0) {
0261: for (int i = 0; i < type.length(); i++) {
0262: tf.typeKey(type.charAt(i));
0263: }
0264: } else {
0265: tf.pushKey(KeyEvent.VK_BACK_SPACE);
0266: }
0267: new EventTool().waitNoEvent(minWait);
0268: }
0269: } else if (!isType && isVis) {
0270: if (isName || isDefVal) {
0271: //if there is need to change name and/or def value
0272: if (!innerCall) {
0273: innerCall = true;
0274: attributeNaturalWayNaming(oldVis, oldType, name,
0275: oldDefVal, false);
0276: }
0277: if (!innerCall) {
0278: innerCall = true;
0279: attributeNaturalWayNaming(visibility, type, name,
0280: oldDefVal, false);
0281: }
0282: if (!innerCall) {
0283: innerCall = true;
0284: attributeNaturalWayNaming(visibility, type, name,
0285: defValue, false);
0286: }
0287: } else {
0288: int visFrom = 0;
0289: int visTo = oldVis.length();
0290: //
0291: if (tf.getSelectionStart() != visFrom
0292: && tf.getSelectionEnd() != visTo) {
0293: tf.selectText(visFrom, visTo);
0294: }
0295: if (visibility.length() > 0) {
0296: for (int i = 0; i < visibility.length(); i++) {
0297: tf.typeKey(visibility.charAt(i));
0298: }
0299: } else {
0300: tf.pushKey(KeyEvent.VK_BACK_SPACE);
0301: }
0302: new EventTool().waitNoEvent(minWait);
0303: }
0304: } else if (isType && isVis) {
0305: if (!innerCall) {
0306: innerCall = true;
0307: attributeNaturalWayNaming(visibility, oldType, oldName,
0308: oldDefVal, false);
0309: }
0310: if (!innerCall) {
0311: innerCall = true;
0312: attributeNaturalWayNaming(visibility, type, oldName,
0313: oldDefVal, false);
0314: }
0315: if (!innerCall) {
0316: innerCall = true;
0317: attributeNaturalWayNaming(visibility, type, name,
0318: defValue, false);
0319: }
0320: } else {
0321: innerCall = false;
0322: throw new UnsupportedOperationException(
0323: "Utility can\'t handle your case (Combination of parameters).");
0324: }
0325: //
0326: String ret = tf.getText();
0327: if (pressEnter) {
0328: tf.pushKey(KeyEvent.VK_ENTER);
0329: new EventTool().waitNoEvent(minWait);
0330: }
0331: innerCall = false;
0332: return ret;
0333: }
0334:
0335: /**
0336: * It works with existing edit control with
0337: * "anyVisibility anyType anyName = anyValue" and "anyVisibility anyType anyName"
0338: * initial attribute with selected name (after Insert or double click).
0339: * Default values can be passed as null.
0340: * do not press enter at the end
0341: * @param visibility
0342: * @param type
0343: * @param name
0344: * @param defValue
0345: * @return resulting string in edit control
0346: */
0347: public static String attributeNaturalWayNaming(String visibility,
0348: String type, String name, String defValue) {
0349: return attributeNaturalWayNaming(visibility, type, name,
0350: defValue, false);
0351: }
0352:
0353: /**
0354: * It works with existing edit control with
0355: * "anyVisibility anyType anyName = anyValue" and "anyVisibility anyType anyName"
0356: * initial attribute with selected name (after Insert or double click).
0357: * Default values can be passed as null.
0358: * do not press enter at the end
0359: * @param visibility
0360: * @param type
0361: * @param name
0362: * @return resulting string in edit control
0363: */
0364: public static String attributeNaturalWayNaming(String visibility,
0365: String type, String name) {
0366: return attributeNaturalWayNaming(visibility, type, name, null);
0367: }
0368:
0369: //==============================================================================================
0370: /**
0371: * It works with existing edit control with
0372: * "anyVisibility anyRetType anyName( parType parName, ... )" and "anyVisibility anyRetType anyName( )"
0373: * initial attribute with selected name (after Insert or double click).
0374: * Default values can be passed as null.
0375: * @param visibility
0376: * @param retType
0377: * @param name
0378: * @param parTypes
0379: * @param parNames
0380: * @param pressEnter
0381: * @return resulting string in edit control
0382: */
0383: public static String operationNaturalWayNaming(String visibility,
0384: String retType, String name, String[] parTypes,
0385: String[] parNames, boolean pressEnter) {
0386: new EventTool().waitNoEvent(minWait);
0387: //support null as default value
0388: if (retType == null) {
0389: retType = defaultReturnType;
0390: }
0391: //
0392: if (visibility == null) {
0393: visibility = defaultOperationVisibility;
0394: }
0395: //
0396: if (name == null) {
0397: name = defaultNewElementName;
0398: }
0399: //
0400: if ((parTypes == null && parNames != null)
0401: || (parTypes != null && parNames == null)) {
0402: innerCall = false;
0403: throw new UnsupportedOperationException(
0404: "Utility can't handle your case(both parameters names and types should be null or both not null).");
0405: }
0406: //
0407: EditControlOperator ec = new EditControlOperator();
0408: JTextFieldOperator tf = ec.getTextFieldOperator();
0409: //
0410: String initialTxt = tf.getText();
0411: StringTokenizer prState = new StringTokenizer(initialTxt,
0412: " \t\n\r\f,()");
0413: String oldVis = prState.nextToken();
0414: String oldRetType = prState.nextToken();
0415: String oldName = prState.nextToken();
0416: //
0417: int numParam = prState.countTokens() / 2;
0418: //
0419: String[] oldParTypes = null;
0420: String[] oldParNames = null;
0421: if (numParam > 0) {
0422: oldParTypes = new String[numParam];
0423: oldParNames = new String[numParam];
0424: for (int i = 0; i < numParam; i++) {
0425: oldParTypes[i] = prState.nextToken();
0426: oldParNames[i] = prState.nextToken();
0427: }
0428: }
0429: boolean isName = !oldName.equals(name);
0430: boolean isRetType = !oldRetType.equals(retType);
0431: boolean isVis = !oldVis.equals(visibility);
0432: boolean isParam = (oldParTypes == null && parTypes != null)
0433: || (oldParTypes != null && parTypes == null)
0434: || (oldParTypes != null && parTypes != null && oldParTypes.length != parTypes.length);
0435: if (!isParam && oldParTypes != null) {
0436: //check parameters
0437: for (int i = 0; i < oldParTypes.length; i++) {
0438: isParam = !oldParTypes[i].equals(parTypes[i])
0439: || !oldParNames[i].equals(parNames[i]);
0440: if (isParam) {
0441: break;
0442: }
0443: }
0444: }
0445:
0446: //different way:
0447: if (!isVis && !isRetType) {
0448: //only name and if needed defValue
0449: //check selection
0450: int nameFrom = initialTxt.indexOf(oldName, oldVis.length()
0451: + oldRetType.length());
0452: int nameTo = nameFrom + oldName.length();
0453: //check if name the same
0454: if (isName) {
0455: //select name
0456: if (tf.getSelectionStart() != nameFrom
0457: && tf.getSelectionEnd() != nameTo) {
0458: tf.selectText(nameFrom, nameTo);
0459: }
0460: if (name.length() > 0) {
0461: //type name
0462: for (int i = 0; i < name.length(); i++) {
0463: tf.typeKey(name.charAt(i));
0464: }
0465: } else {
0466: tf.pushKey(KeyEvent.VK_BACK_SPACE);
0467: }
0468: new EventTool().waitNoEvent(minWait);
0469: } else {
0470: //name the same as exists, do nothing
0471: }
0472: //
0473: if (isParam) {
0474: //go to parameters
0475: tf.typeKey('(');
0476: //
0477: if (oldParNames == null) {
0478: //type in new parameters
0479: for (int i = 0; i < parTypes.length; i++) {
0480: for (int j = 0; j < parTypes[i].length(); j++) {
0481: tf.typeKey(parTypes[i].charAt(j));
0482: }
0483: tf.typeKey(' ');
0484: for (int j = 0; j < parNames[i].length(); j++) {
0485: tf.typeKey(parNames[i].charAt(j));
0486: }
0487: if (i < (parTypes.length - 1)) {
0488: tf.typeKey(',');
0489: }
0490: }
0491: } else if (parNames == null) {
0492: //remove all
0493: int last = tf.getText().lastIndexOf(')');
0494: int first = tf.getText().indexOf('(');
0495: tf.setCaretPosition(last);
0496: for (int i = 0; i < (last - first - 1); i++) {
0497: tf.pushKey(KeyEvent.VK_BACK_SPACE);
0498: }
0499: } else if (parNames.length == oldParNames.length) {
0500: int lastStart = tf.getText().indexOf('(');
0501: for (int i = 0; i < parNames.length; i++) {
0502: //type
0503: lastStart = tf.getText().indexOf(
0504: oldParTypes[i], lastStart);
0505: if (!parTypes[i].equals(oldParTypes[i])) {
0506: tf.setCaretPosition(lastStart
0507: + parTypes[i].length());
0508: for (int j = 0; j < oldParTypes[i].length(); j++) {
0509: tf.pushKey(KeyEvent.VK_BACK_SPACE);
0510: }
0511: for (int j = 0; j < parTypes[i].length(); j++) {
0512: tf.typeKey(parTypes[i].charAt(j));
0513: }
0514: }
0515: lastStart = tf.getText().indexOf(
0516: oldParNames[i],
0517: lastStart + parTypes[i].length());
0518: if (!parNames[i].equals(oldParNames[i])) {
0519: tf.setCaretPosition(lastStart
0520: + parNames[i].length());
0521: for (int j = 0; j < oldParNames[i].length(); j++) {
0522: tf.pushKey(KeyEvent.VK_BACK_SPACE);
0523: }
0524: for (int j = 0; j < parNames[i].length(); j++) {
0525: tf.typeKey(parNames[i].charAt(j));
0526: }
0527: }
0528: lastStart = lastStart + parNames[i].length();
0529: }
0530: } else if (parNames.length > oldParNames.length) {
0531: int lastStart = tf.getText().indexOf('(');
0532: for (int i = 0; i < oldParNames.length; i++) {
0533: //type
0534: lastStart = tf.getText().indexOf(
0535: oldParTypes[i], lastStart);
0536: if (!parTypes[i].equals(oldParTypes[i])) {
0537: tf.setCaretPosition(lastStart
0538: + parTypes[i].length());
0539: for (int j = 0; j < oldParTypes[i].length(); j++) {
0540: tf.pushKey(KeyEvent.VK_BACK_SPACE);
0541: }
0542: for (int j = 0; j < parTypes[i].length(); j++) {
0543: tf.typeKey(parTypes[i].charAt(j));
0544: }
0545: }
0546: lastStart = tf.getText().indexOf(
0547: oldParNames[i],
0548: lastStart + parTypes[i].length());
0549: if (!parNames[i].equals(oldParNames[i])) {
0550: tf.setCaretPosition(lastStart
0551: + oldParNames[i].length());
0552: for (int j = 0; j < oldParNames[i].length(); j++) {
0553: tf.pushKey(KeyEvent.VK_BACK_SPACE);
0554: }
0555: for (int j = 0; j < parNames[i].length(); j++) {
0556: tf.typeKey(parNames[i].charAt(j));
0557: }
0558: }
0559: lastStart = lastStart + parNames[i].length();
0560: }
0561: tf.typeKey(',');
0562: for (int i = oldParNames.length; i < parNames.length; i++) {
0563: for (int j = 0; j < parTypes[i].length(); j++) {
0564: tf.typeKey(parTypes[i].charAt(j));
0565: }
0566: tf.typeKey(' ');
0567: for (int j = 0; j < parNames[i].length(); j++) {
0568: tf.typeKey(parNames[i].charAt(j));
0569: }
0570: if (i < (parTypes.length - 1)) {
0571: tf.typeKey(',');
0572: }
0573: }
0574: } else {
0575: innerCall = false;
0576: throw new UnsupportedOperationException(
0577: "Utility can\'t handle your case(decrease of number parameters will be implemented later).");
0578: }
0579: new EventTool().waitNoEvent(minWait);
0580: }
0581: } else if (isRetType && !isVis) {
0582: if (isName || isParam) {
0583: //if there is need to change name and/or def value
0584: if (!innerCall) {
0585: innerCall = true;
0586: operationNaturalWayNaming(oldVis, oldRetType, name,
0587: oldParTypes, oldParNames, false);
0588: }
0589: if (!innerCall) {
0590: innerCall = true;
0591: operationNaturalWayNaming(visibility, retType,
0592: name, oldParTypes, oldParNames, false);
0593: }
0594: if (!innerCall) {
0595: innerCall = true;
0596: operationNaturalWayNaming(visibility, retType,
0597: name, parTypes, parNames, false);
0598: }
0599: } else {
0600: int typeFrom = initialTxt.indexOf(oldRetType, oldVis
0601: .length());
0602: int typeTo = typeFrom + oldRetType.length();
0603: //
0604: if (tf.getSelectionStart() != typeFrom
0605: && tf.getSelectionEnd() != typeTo) {
0606: tf.selectText(typeFrom, typeTo);
0607: }
0608: if (retType.length() > 0) {
0609: for (int i = 0; i < retType.length(); i++) {
0610: tf.typeKey(retType.charAt(i));
0611: }
0612: } else {
0613: tf.pushKey(KeyEvent.VK_BACK_SPACE);
0614: }
0615: new EventTool().waitNoEvent(minWait);
0616: }
0617: } else if (!isRetType && isVis) {
0618: if (isName || isParam) {
0619: //if there is need to change name and/or def value
0620: if (!innerCall) {
0621: innerCall = true;
0622: operationNaturalWayNaming(oldVis, oldRetType, name,
0623: oldParTypes, oldParNames, false);
0624: }
0625: if (!innerCall) {
0626: innerCall = true;
0627: operationNaturalWayNaming(visibility, retType,
0628: name, oldParTypes, oldParNames, false);
0629: }
0630: if (!innerCall) {
0631: innerCall = true;
0632: operationNaturalWayNaming(visibility, retType,
0633: name, parTypes, parNames, false);
0634: }
0635: } else {
0636: int visFrom = 0;
0637: int visTo = oldVis.length();
0638: //
0639: if (tf.getSelectionStart() != visFrom
0640: && tf.getSelectionEnd() != visTo) {
0641: tf.selectText(visFrom, visTo);
0642: }
0643: if (visibility.length() > 0) {
0644: for (int i = 0; i < visibility.length(); i++) {
0645: tf.typeKey(visibility.charAt(i));
0646: }
0647: } else {
0648: tf.pushKey(KeyEvent.VK_BACK_SPACE);
0649: }
0650: new EventTool().waitNoEvent(minWait);
0651: }
0652: } else if (isRetType && isVis) {
0653: if (!innerCall) {
0654: innerCall = true;
0655: operationNaturalWayNaming(visibility, oldRetType,
0656: oldName, oldParTypes, oldParNames, false);
0657: }
0658: if (!innerCall) {
0659: innerCall = true;
0660: operationNaturalWayNaming(visibility, retType, oldName,
0661: oldParTypes, oldParNames, false);
0662: }
0663: if (!innerCall) {
0664: innerCall = true;
0665: operationNaturalWayNaming(visibility, retType, name,
0666: parTypes, parNames, false);
0667: }
0668: } else {
0669: innerCall = false;
0670: throw new UnsupportedOperationException(
0671: "Utility can\'t handle your case./changes:" + isVis
0672: + ":" + isRetType + ":" + isName + ":"
0673: + isParam);
0674: }
0675: //
0676: String ret = tf.getText();
0677: if (pressEnter) {
0678: tf.pushKey(KeyEvent.VK_ENTER);
0679: new EventTool().waitNoEvent(minWait);
0680: }
0681: innerCall = false;
0682: return ret;
0683: }
0684:
0685: /**
0686: * It works with existing edit control with
0687: * "anyVisibility anyRetType anyName( parType parName)" and "anyVisibility anyRetType anyName( )"
0688: * initial attribute with selected name (after Insert or double click).
0689: * Default values can be passed as null.
0690: * @param visibility
0691: * @param retType
0692: * @param name
0693: * @param parTypes
0694: * @param parNames
0695: * @param pressEnter
0696: * @return resulting string in edit control
0697: */
0698: public static String operationNaturalWayNaming(String visibility,
0699: String retType, String name, String parTypes,
0700: String parNames, boolean pressEnter) {
0701: String[] aparTypes = { parTypes };
0702: String[] aparNames = { parNames };
0703: return operationNaturalWayNaming(visibility, retType, name,
0704: aparTypes, aparNames, pressEnter);
0705: }
0706:
0707: /**
0708: * It works with existing edit control with
0709: * "anyVisibility anyRetType anyName( parType parName, ... )" and "anyVisibility anyRetType anyName( )"
0710: * initial attribute with selected name (after Insert or double click).
0711: * Default values can be passed as null.
0712: * @param visibility
0713: * @param retType
0714: * @param name
0715: * @param parTypes
0716: * @param parNames
0717: * @return resulting string in edit control
0718: */
0719: public static String operationNaturalWayNaming(String visibility,
0720: String retType, String name, String[] parTypes,
0721: String[] parNames) {
0722: return operationNaturalWayNaming(visibility, retType, name,
0723: parTypes, parNames, false);
0724: }
0725:
0726: /**
0727: * It works with existing edit control with
0728: * "anyVisibility anyRetType anyName( parType parName)" and "anyVisibility anyRetType anyName( )"
0729: * initial attribute with selected name (after Insert or double click).
0730: * Default values can be passed as null.
0731: * @param visibility
0732: * @param retType
0733: * @param name
0734: * @param parTypes
0735: * @param parNames
0736: * @return resulting string in edit control
0737: */
0738: public static String operationNaturalWayNaming(String visibility,
0739: String retType, String name, String parTypes,
0740: String parNames) {
0741: return operationNaturalWayNaming(visibility, retType, name,
0742: parTypes, parNames, false);
0743: }
0744:
0745: /**
0746: * It works with existing edit control with
0747: * "anyVisibility anyRetType anyName( parType parName, ... )" and "anyVisibility anyRetType anyName( )"
0748: * initial attribute with selected name (after Insert or double click).
0749: * Default values can be passed as null.
0750: * @param visibility
0751: * @param retType
0752: * @param name
0753: * @param parameters
0754: * @param pressEnter
0755: * @return resulting string in edit control
0756: */
0757: public static String operationNaturalWayNaming(String visibility,
0758: String retType, String name, String parameters,
0759: boolean pressEnter) {
0760: //
0761: StringTokenizer prState = new StringTokenizer(parameters,
0762: " \t\n\r\f,()");
0763: int numParam = prState.countTokens() / 2;
0764: //
0765: String[] parTypes = null;
0766: String[] parNames = null;
0767: if (numParam > 0) {
0768: parTypes = new String[numParam];
0769: parNames = new String[numParam];
0770: for (int i = 0; i < numParam; i++) {
0771: parTypes[i] = prState.nextToken();
0772: parNames[i] = prState.nextToken();
0773: }
0774: }
0775: //
0776: return operationNaturalWayNaming(visibility, retType, name,
0777: parTypes, parNames, pressEnter);
0778: }
0779:
0780: /**
0781: * It works with existing edit control with
0782: * "anyVisibility anyRetType anyName( parType parName, ... )" and "anyVisibility anyRetType anyName( )"
0783: * initial attribute with selected name (after Insert or double click).
0784: * Default values can be passed as null.
0785: * @param visibility
0786: * @param retType
0787: * @param name
0788: * @param parameters
0789: * @return resulting string in edit control
0790: */
0791: public static String operationNaturalWayNaming(String visibility,
0792: String retType, String name, String parameters) {
0793: return operationNaturalWayNaming(visibility, retType, name,
0794: parameters, false);
0795: }
0796:
0797: /**
0798: * It works with existing edit control with
0799: * "anyVisibility anyRetType anyName( parType parName, ... )" and "anyVisibility anyRetType anyName( )"
0800: * initial attribute with selected name (after Insert or double click).
0801: * Default values can be passed as null.
0802: * @param visibility
0803: * @param retType
0804: * @param name
0805: * @return resulting string in edit control
0806: */
0807: public static String operationNaturalWayNaming(String visibility,
0808: String retType, String name) {
0809: return operationNaturalWayNaming(visibility, retType, name,
0810: (String[]) null, (String[]) null, false);
0811: }
0812:
0813: //=========================================================================================================
0814: public static CompartmentOperator getNotConstructorFinalizerOperationCmp(
0815: CompartmentOperator opComp, String className, int index) {
0816: int count_index = 0;
0817: CompartmentOperator oprCmp = null;
0818: for (int i = 0; i < opComp.getCompartments().size(); i++) {
0819: String tmp = opComp.getCompartments().get(i).getName();
0820: //
0821: if (tmp.indexOf("public " + className + "(") == -1
0822: && tmp.indexOf("void finalize(") == -1) {
0823: if (count_index >= index) {
0824: oprCmp = opComp.getCompartments().get(i);
0825: break;
0826: } else {
0827: count_index++;
0828: }
0829: }
0830: }
0831: return oprCmp;
0832: }
0833:
0834: public static CompartmentOperator getNotConstructorFinalizerOperationCmp(
0835: CompartmentOperator opComp, String className) {
0836: return getNotConstructorFinalizerOperationCmp(opComp,
0837: className, 0);
0838: }
0839:
0840: //
0841: public static String getNotConstructorFinalizerOperationStr(
0842: CompartmentOperator opComp, String className, int index) {
0843: return getNotConstructorFinalizerOperationCmp(opComp,
0844: className, index).getName();
0845: }
0846:
0847: public static String getNotConstructorFinalizerOperationStr(
0848: CompartmentOperator opComp, String className) {
0849: return getNotConstructorFinalizerOperationStr(opComp,
0850: className, 0);
0851: }
0852:
0853: public static void setTextProperty(String pName, String pValue) {
0854: PropertySheetOperator ps = new PropertySheetOperator();
0855: Property nmProp = new Property(ps, pName);
0856: double nmPntX = ps.tblSheet().getCellRect(nmProp.getRow(), 1,
0857: false).getCenterX();
0858: double nmPntY = ps.tblSheet().getCellRect(nmProp.getRow(), 1,
0859: false).getCenterY();
0860: ps.clickMouse((int) nmPntX, (int) nmPntY, 1);
0861: new EventTool().waitNoEvent(minWait);
0862: new JTextFieldOperator(ps, nmProp.getValue());
0863: for (int i = 0; i < pValue.length(); i++) {
0864: ps.typeKey(pValue.charAt(i));
0865: }
0866: ps.pushKey(KeyEvent.VK_ENTER);
0867: }
0868:
0869: public static String getTextPropertyValue(PropertySheetOperator ps,
0870: String pName) {
0871: return new Property(ps, pName).getValue();
0872: }
0873:
0874: //remove double spaces,
0875: //remove spaces with delimiters
0876: public static boolean compareWithoutExtraSpaceChars(String s1,
0877: String s2) {
0878: s1 = s1.trim();
0879: s1 = s1.replace("\t", " ");
0880: s1 = s1.replace(" ", " ");
0881: s1 = s1.replace(" (", "(");
0882: s1 = s1.replace("( )", "()");
0883: s1 = s1.replace(" ,", ",");
0884: s1 = s1.replace(", ", ",");
0885: s2 = s2.trim();
0886: s2 = s2.replace("\t", " ");
0887: s2 = s2.replace(" ", " ");
0888: s2 = s2.replace(" (", "(");
0889: s2 = s2.replace("( )", "()");
0890: s2 = s2.replace(" ,", ",");
0891: s2 = s2.replace(", ", ",");
0892: return s1.equals(s2);
0893: }
0894:
0895: //
0896: public static void prepareProjects(String workdir, String prName) {
0897: ///UML
0898: new NewProjectAction().performMenu();
0899: NewProjectWizardOperator newWizardOper = new NewProjectWizardOperator();
0900: new EventTool().waitNoEvent(1500);
0901: try {
0902: Thread.sleep(1000);
0903: } catch (Exception ex) {
0904: }
0905: //newWizardOper.selectCategory(org.netbeans.test.umllib.util.LabelsAndTitles.UML_PROJECTS_CATEGORY);
0906: JTreeOperator catTree = new JTreeOperator(newWizardOper);
0907: catTree.moveMouse(0, 0);
0908: catTree
0909: .selectPath(catTree
0910: .findPath(org.netbeans.test.umllib.util.LabelsAndTitles.UML_PROJECTS_CATEGORY));
0911: catTree
0912: .waitSelected(catTree
0913: .findPath(org.netbeans.test.umllib.util.LabelsAndTitles.UML_PROJECTS_CATEGORY));
0914: new EventTool().waitNoEvent(500);
0915: newWizardOper
0916: .selectProject(org.netbeans.test.umllib.util.LabelsAndTitles.JAVA_UML_PROJECT_LABEL);
0917: newWizardOper.next();
0918: JLabelOperator ploL = new JLabelOperator(newWizardOper,
0919: "Project Location:");
0920: JTextFieldOperator ploT = new JTextFieldOperator(
0921: (JTextField) (ploL.getLabelFor()));
0922: ploT.clearText();
0923: ploT.typeText(workdir);
0924: JLabelOperator pnmL = new JLabelOperator(newWizardOper,
0925: "Project Name:");
0926: JTextFieldOperator pnmT = new JTextFieldOperator(
0927: (JTextField) (pnmL.getLabelFor()));
0928: pnmT.clearText();
0929: pnmT.typeText(prName);
0930: // newWizardOper.finish();
0931: new JButtonOperator(newWizardOper, "Finish").push();
0932: new JButtonOperator(new JDialogOperator("Create New Diagram"),
0933: "Cancel").push();
0934:
0935: //properties
0936: new JMenuBarOperator(MainWindowOperator.getDefault())
0937: .pushMenu("Window|Properties");
0938: new PropertySheetOperator();
0939: new EventTool().waitNoEvent(500);
0940: //
0941: }
0942:
0943: //=====================================================
0944: //check class declaration(with default constructor)
0945: public static boolean isClassSourceValid(String classTxt,
0946: String pkg, String classVis, String className) {
0947: return classTxt
0948: .matches("[ \n\r\t]*package[ \\t\\r\\n]+"
0949: + pkg
0950: + "[ \\t\\r\\n]*;[ \\t\\r\\n]*"
0951: + classVis
0952: + "[ \\t\\r\\n]+"
0953: + className
0954: + "[ \\t\\r\\n]*\\{[ \\t\\r\\n]*public[ \\t\\r\\n]+"
0955: + className
0956: + "[ \\t\\r\\n]*\\([ \\t\\r\\n]*\\)[ \\t\\r\\n]*\\{[ \\t\\r\\n]*\\}[ \\t\\r\\n]*\\}[ \\t\\r\\n]*");
0957: }
0958:
0959: //=====================================================
0960: //node to node drag
0961: public static void dragNDropNode(JTreeOperator tree, Node from,
0962: Node to, int mButton, int modif) {
0963: Point startPoint = tree.getPointToClick(from.getTreePath());
0964: Point endPoint = tree.getPointToClick(to.getTreePath());
0965: //tree.dragNDrop(startPoint.x,startPoint.y,endPoint.x,endPoint.y,mButton,modif);
0966: MouseRobotDriver driver = new MouseRobotDriver(new Timeout("",
0967: 250));
0968: driver.moveMouse(tree, startPoint.x, startPoint.y);
0969: driver.pressMouse(tree, startPoint.x, startPoint.y, mButton,
0970: modif);
0971: driver.moveMouse(tree, endPoint.x, endPoint.y);
0972: driver.releaseMouse(tree, endPoint.x, endPoint.y, mButton,
0973: modif);
0974: }
0975:
0976: public static void dragNDropNode(JTreeOperator tree, Node from,
0977: Node to, int mButton) {
0978: dragNDropNode(tree, from, to, mButton, 0);
0979: }
0980:
0981: public static void dragNDropNode(JTreeOperator tree, Node from,
0982: Node to) {
0983: dragNDropNode(tree, from, to, InputEvent.BUTTON1_MASK);
0984: }
0985:
0986: //
0987: public static void setDefaultPreferences() {
0988: OptionsOperator op = OptionsOperator.invoke();
0989: op = op.invokeAdvanced();
0990: TreeTableOperator tr = op.treeTable();
0991: //
0992: tr.tree().selectPath(tr.tree().findPath("UML"));
0993: tr.tree().waitSelected(tr.tree().findPath("UML"));
0994: new EventTool().waitNoEvent(1000);
0995: PropertySheetOperator ps = new PropertySheetOperator(op);
0996: Property pr = new Property(ps, "Prompt to Save Diagram");
0997: pr.setValue(1);
0998: if (!pr.getValue().equalsIgnoreCase("No")) {
0999: pr.setValue(0);
1000: }
1001: //
1002: tr.tree().selectPath(tr.tree().findPath("UML|New Project"));
1003: tr.tree().waitSelected(tr.tree().findPath("UML|New Project"));
1004: new EventTool().waitNoEvent(1000);
1005: ps = new PropertySheetOperator(op);
1006: pr = new Property(ps, "Create New Diagram");
1007: pr.setValue(1);
1008: if (pr.getValue().equalsIgnoreCase("yes")) {
1009: pr.setValue(0);
1010: }
1011: new JButtonOperator(op, "Close").push();
1012: }
1013: }
|