Source Code Cross Referenced for ClassOperator.java in  » IDE-Netbeans » uml » org » netbeans » test » umllib » customelements » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » uml » org.netbeans.test.umllib.customelements 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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:         * ClassOperator.java
0044:         *
0045:         * Created on May 6, 2005, 3:47 PM
0046:         *
0047:         * To change this template, choose Tools | Options and locate the template under
0048:         * the Source Creation and Management node. Right-click the template and choose
0049:         * Open. You can then make changes to the template in the Source Editor.
0050:         */
0051:
0052:        package org.netbeans.test.umllib.customelements;
0053:
0054:        import java.awt.Rectangle;
0055:        import java.awt.event.KeyEvent;
0056:        import java.util.ArrayList;
0057:        import java.util.StringTokenizer;
0058:        import org.netbeans.jemmy.EventTool;
0059:        import org.netbeans.jemmy.Timeout;
0060:        import org.netbeans.jemmy.drivers.DriverManager;
0061:        import org.netbeans.jemmy.drivers.input.KeyRobotDriver;
0062:        import org.netbeans.jemmy.drivers.input.MouseRobotDriver;
0063:        import org.netbeans.jemmy.operators.JTextFieldOperator;
0064:        import org.netbeans.test.umllib.CompartmentOperator;
0065:        import org.netbeans.test.umllib.CompartmentTypes;
0066:        import org.netbeans.test.umllib.DiagramElementChooser;
0067:        import org.netbeans.test.umllib.DiagramElementOperator;
0068:        import org.netbeans.test.umllib.DiagramElementOperator.ElementByVNChooser;
0069:        import org.netbeans.test.umllib.DiagramOperator;
0070:        import org.netbeans.test.umllib.EditControlOperator;
0071:        import org.netbeans.test.umllib.ElementTypes;
0072:        import org.netbeans.test.umllib.actions.InsertAttributeAction;
0073:        import org.netbeans.test.umllib.actions.InsertOperationAction;
0074:        import org.netbeans.test.umllib.exceptions.NotFoundException;
0075:
0076:        /**
0077:         *
0078:         * @author VijayaBabu Mummaneni
0079:         */
0080:        public class ClassOperator extends DiagramElementOperator {
0081:
0082:            public ClassOperator(DiagramOperator diagramOperator,
0083:                    String elementVN) throws NotFoundException {
0084:                super (diagramOperator, new ElementByVNChooser(elementVN,
0085:                        ElementTypes.CLASS), 0);
0086:            }
0087:
0088:            public ClassOperator(DiagramOperator diagramOperator,
0089:                    String elementVN, int index) throws NotFoundException {
0090:                super (diagramOperator, new ElementByVNChooser(elementVN,
0091:                        ElementTypes.CLASS), index);
0092:            }
0093:
0094:            public ClassOperator(DiagramOperator diagramOperator,
0095:                    DiagramElementChooser elementFinder, int index)
0096:                    throws NotFoundException {
0097:                super (diagramOperator, elementFinder, index);
0098:            }
0099:
0100:            public CompartmentOperator getExtensionPointsCompartment()
0101:                    throws NotFoundException {
0102:                CompartmentOperator extComp = new CompartmentOperator(this ,
0103:                        CompartmentTypes.EXTENSION_POINTS_LIST_COMPARTMENT);
0104:                return extComp;
0105:            }
0106:
0107:            public CompartmentOperator getMainAreaCompartment()
0108:                    throws NotFoundException {
0109:                CompartmentOperator mainComp = new CompartmentOperator(this ,
0110:                        CompartmentTypes.NAME_LIST_COMPARTMENT);
0111:                return mainComp;
0112:            }
0113:
0114:            public CompartmentOperator getNameCompartment()
0115:                    throws NotFoundException {
0116:                CompartmentOperator extComp = new CompartmentOperator(this ,
0117:                        CompartmentTypes.NAME_COMPARTMENT);
0118:                return extComp;
0119:            }
0120:
0121:            public CompartmentOperator getAttributesCompartment()
0122:                    throws NotFoundException {
0123:                CompartmentOperator extComp = new CompartmentOperator(this ,
0124:                        CompartmentTypes.ATTRIBUTE_LIST_COMPARTMENT);
0125:                return extComp;
0126:            }
0127:
0128:            public CompartmentOperator getOperationsCompartment()
0129:                    throws NotFoundException {
0130:                CompartmentOperator extComp = new CompartmentOperator(this ,
0131:                        CompartmentTypes.OPERATION_LIST_COMPARTMENT);
0132:                return extComp;
0133:            }
0134:
0135:            public CompartmentOperator getExtensionPointCompartment(int index)
0136:                    throws NotFoundException {
0137:                CompartmentOperator mainComp = new CompartmentOperator(this ,
0138:                        CompartmentTypes.EXTENSION_POINTS_LIST_COMPARTMENT);
0139:                ArrayList<CompartmentOperator> extPoints = mainComp
0140:                        .getCompartments();
0141:                if (extPoints != null && extPoints.size() > index) {
0142:                    return extPoints.get(index);
0143:                } else {
0144:                    throw new NotFoundException("Compartment with index "
0145:                            + index + " not found.");
0146:                }
0147:            }
0148:
0149:            public Rectangle getExtensionPointRectangle(String name)
0150:                    throws NotFoundException {
0151:                CompartmentOperator mainComp = new CompartmentOperator(this ,
0152:                        CompartmentTypes.EXTENSION_POINTS_LIST_COMPARTMENT);
0153:                ArrayList<CompartmentOperator> extPoints = mainComp
0154:                        .getCompartments();
0155:                return null;
0156:                /*if (extPoints!=null && extPoints.size()>index){
0157:                    return extPoints.get(index);
0158:                }else{
0159:                    throw new NotFoundException("Compartment with index "+index+" not found.");
0160:                } */
0161:            }
0162:
0163:            /**
0164:             * inserts new attribute. Actually invokes insertAttributeByPopup method.
0165:             * classOperatorUtil().attributeNaturalWayNaming is used to name added attribute.
0166:             * Default values can be passed as null.
0167:             * @param visibility String visibility value
0168:             * @param type String type value
0169:             * @param name String name value
0170:             * @param defValue String default value
0171:             * @param pressEnter to press enter after creation is finished or not
0172:             * @throws qa.uml.exceptions.NotFoundException
0173:             */
0174:            public void insertAttribute(String visibility, String type,
0175:                    String name, String defValue, boolean pressEnter)
0176:                    throws NotFoundException {
0177:                insertAttributeByPopup(visibility, type, name, defValue,
0178:                        pressEnter);
0179:            }
0180:
0181:            /**
0182:             * inserts attribute by popup menu.
0183:             * classOperatorUtil().attributeNaturalWayNaming is used to name added attribute.
0184:             * Default values can be passed as null.
0185:             * @param visibility String visibility value
0186:             * @param type String type value
0187:             * @param name String name value
0188:             * @param defValue String default value
0189:             * @param pressEnter to press enter after creation is finished or not
0190:             * @throws qa.uml.exceptions.NotFoundException
0191:             */
0192:            public void insertAttributeByPopup(String visibility, String type,
0193:                    String name, String defValue, boolean pressEnter)
0194:                    throws NotFoundException {
0195:                CompartmentOperator attribCompartment = getAttributesCompartment();
0196:                new InsertAttributeAction().performPopup(attribCompartment);
0197:                new classOperatorUtil().attributeNaturalWayNaming(visibility,
0198:                        type, name, defValue, pressEnter);
0199:            }
0200:
0201:            /**
0202:             * inserts attribute by shortcut
0203:             * classOperatorUtil().attributeNaturalWayNaming is used to name added attribute.
0204:             * Default values can be passed as null.
0205:             * @param visibility String visibility value
0206:             * @param type String type value
0207:             * @param name String name value
0208:             * @param defValue String default value
0209:             * @param pressEnter to press enter after creation is finished or not
0210:             * @throws qa.uml.exceptions.NotFoundException
0211:             */
0212:            public void insertAttributeByShortcut(String visibility,
0213:                    String type, String name, String defValue,
0214:                    boolean pressEnter) throws NotFoundException {
0215:                CompartmentOperator attribCompartment = getAttributesCompartment();
0216:                new InsertAttributeAction().performShortcut(attribCompartment);
0217:                new classOperatorUtil().attributeNaturalWayNaming(visibility,
0218:                        type, name, defValue, pressEnter);
0219:            }
0220:
0221:            /**
0222:             * inserts new operation. Actually invokes insertOperationByPopup method.
0223:             * classOperatorUtil().operationNaturalWayNaming is used to name added operation.
0224:             * Default values can be passed as null.
0225:             * @param visibility String visibility value
0226:             * @param retType String return Type value
0227:             * @param name String name value
0228:             * @param parameters String with operation parameters. Format is (parType parName, parType parName, ...);
0229:             * @param pressEnter to press enter after creation is finished or not
0230:             * @throws qa.uml.exceptions.NotFoundException
0231:             */
0232:            public void insertOperation(String visibility, String retType,
0233:                    String name, String parameters, boolean pressEnter)
0234:                    throws NotFoundException {
0235:                insertOperationByPopup(visibility, retType, name, parameters,
0236:                        pressEnter);
0237:            }
0238:
0239:            /**
0240:             * inserts attribute by popup menu
0241:             * classOperatorUtil().operationNaturalWayNaming is used to name added operation.
0242:             * Default values can be passed as null.
0243:             * @param visibility String visibility value
0244:             * @param retType String return Type value
0245:             * @param name String name value
0246:             * @param parameters String with operation parameters. Format is (parType parName, parType parName, ...);
0247:             * @param pressEnter to press enter after creation is finished or not
0248:             * @throws qa.uml.exceptions.NotFoundException
0249:             */
0250:            public void insertOperationByPopup(String visibility,
0251:                    String retType, String name, String parameters,
0252:                    boolean pressEnter) throws NotFoundException {
0253:                CompartmentOperator operationsCompartment = getOperationsCompartment();
0254:                new InsertOperationAction().performPopup(operationsCompartment);
0255:                new classOperatorUtil().operationNaturalWayNaming(visibility,
0256:                        retType, name, parameters, pressEnter);
0257:            }
0258:
0259:            /**
0260:             * inserts attribute by shortcut
0261:             * classOperatorUtil().operationNaturalWayNaming is used to name added operation.
0262:             * Default values can be passed as null.
0263:             * @param visibility String visibility value
0264:             * @param retType String return Type value
0265:             * @param name String name value
0266:             * @param parameters String with operation parameters. Format is (parType parName, parType parName, ...);
0267:             * @param pressEnter to press enter after creation is finished or not
0268:             * @throws qa.uml.exceptions.NotFoundException
0269:             */
0270:            public void insertOperationByShortcut(String visibility,
0271:                    String retType, String name, String parameters,
0272:                    boolean pressEnter) throws NotFoundException {
0273:                CompartmentOperator operationsCompartment = getOperationsCompartment();
0274:                new InsertOperationAction()
0275:                        .performShortcut(operationsCompartment);
0276:                new classOperatorUtil().operationNaturalWayNaming(visibility,
0277:                        retType, name, parameters, pressEnter);
0278:            }
0279:
0280:            public void getAllAttributes(String attributeName)
0281:                    throws NotFoundException {
0282:                CompartmentOperator attribCompartment = getAttributesCompartment();
0283:                new InsertAttributeAction().performPopup(attribCompartment);
0284:                // TBD
0285:            }
0286:
0287:            public void getAllOperations(String attributeName)
0288:                    throws NotFoundException {
0289:                CompartmentOperator attribCompartment = getAttributesCompartment();
0290:                new InsertAttributeAction().performPopup(attribCompartment);
0291:                //TBD
0292:            }
0293:
0294:            public boolean hasAttribute(String attributeName) {
0295:                //TBD
0296:                return false;
0297:            }
0298:
0299:            public boolean hasOperation(String operationName) {
0300:                //TBD
0301:                return false;
0302:            }
0303:
0304:            public void deleteAttribute(String attributeName)
0305:                    throws NotFoundException {
0306:                CompartmentOperator attribCompartment = getAttributesCompartment();
0307:                new InsertAttributeAction().performPopup(attribCompartment);
0308:                //TBD
0309:            }
0310:
0311:            public void deleteOperation(String operationName)
0312:                    throws NotFoundException {
0313:                CompartmentOperator attribCompartment = getAttributesCompartment();
0314:                new InsertAttributeAction().performPopup(attribCompartment);
0315:                //TBD
0316:            }
0317:
0318:            public static class classOperatorUtil {
0319:                //
0320:                private boolean innerCall = false;
0321:                //
0322:                public String defaultNewElementName = "Unnamed";
0323:                public String defaultReturnType = "void";
0324:                public String defaultAttributeType = "int";
0325:                public String defaultAttributeVisibility = "private";
0326:                public String defaultAttributeValue = "";
0327:                public String defaultOperationVisibility = "public";
0328:                //
0329:                private int minWait = 50;
0330:                private int longWait = 500;
0331:
0332:                {
0333:                    DriverManager.setMouseDriver(new MouseRobotDriver(
0334:                            new Timeout("", 10)));
0335:                    DriverManager.setKeyDriver(new KeyRobotDriver(new Timeout(
0336:                            "autoDelay", 50)));
0337:                }
0338:
0339:                /**
0340:                 * It works with existing edit control with
0341:                 * "anyVisibility anyType anyName = anyValue"  and "anyVisibility anyType anyName"
0342:                 * initial attribute with selected name (after Insert or double click).
0343:                 * Default values can be passed as null.
0344:                 * @param visibility
0345:                 * @param type
0346:                 * @param name
0347:                 * @param defValue
0348:                 * @param pressEnter
0349:                 * @return resulting string in edit control
0350:                 */
0351:                public String attributeNaturalWayNaming(String visibility,
0352:                        String type, String name, String defValue,
0353:                        boolean pressEnter) {
0354:                    new EventTool().waitNoEvent(minWait);
0355:                    //support null as default value
0356:                    if (defValue == null)
0357:                        defValue = defaultAttributeValue;
0358:                    //
0359:                    if (visibility == null)
0360:                        visibility = defaultAttributeVisibility;
0361:                    //
0362:                    if (type == null)
0363:                        type = defaultAttributeType;
0364:                    //
0365:                    if (name == null)
0366:                        name = defaultNewElementName;
0367:                    EditControlOperator ec = new EditControlOperator();
0368:                    JTextFieldOperator tf = ec.getTextFieldOperator();
0369:                    //
0370:                    String initialTxt = tf.getText();
0371:                    StringTokenizer prState = new StringTokenizer(initialTxt,
0372:                            " \t\n\r\f=");
0373:                    if (prState.countTokens() < 3) {
0374:                        innerCall = false;
0375:                        throw new UnsupportedOperationException(
0376:                                "Utility can't handle your case (Possible absence of visibility or/and type or/and name).");
0377:                    }
0378:                    String oldVis = prState.nextToken();
0379:                    String oldType = prState.nextToken();
0380:                    String oldName = prState.nextToken();
0381:                    String oldDefVal = "";
0382:                    if (prState.hasMoreTokens()) {
0383:                        oldDefVal = prState.nextToken();
0384:                    }
0385:
0386:                    tf.setCaretPosition(0);
0387:
0388:                    changeText(visibility, oldVis, tf);
0389:                    changeText(type, oldType, tf);
0390:                    changeText(name, oldName, tf);
0391:
0392:                    /*
0393:                     
0394:                    boolean isName=!oldName.equals(name);
0395:                    boolean isType=!oldType.equals(type);
0396:                    boolean isVis=!oldVis.equals(visibility);
0397:                    boolean isDefVal=!oldDefVal.equals(defValue);
0398:                    //different way:
0399:                    if(!isVis && !isType) {
0400:                        //only name and if needed defValue
0401:                        //check selection
0402:                        int nameFrom=initialTxt.indexOf(oldName,oldVis.length()+oldType.length());
0403:                        int nameTo=nameFrom+oldName.length();
0404:                        //check if name the same
0405:                        if(isName) {
0406:                            //select name
0407:                            if(tf.getSelectionStart()!=nameFrom && tf.getSelectionEnd()!=nameTo) {
0408:                                tf.selectText(nameFrom,nameTo);
0409:                            }
0410:                            if(name.length()>0) {
0411:                                //type name
0412:                                for(int i=0;i<name.length();i++) {
0413:                                    tf.typeKey(name.charAt(i));
0414:                                }
0415:                            } else {
0416:                                tf.pushKey(KeyEvent.VK_BACK_SPACE);
0417:                            }
0418:                            new EventTool().waitNoEvent(minWait);
0419:                        } else {
0420:                            //name the same as exists, do nothing
0421:                        }
0422:                        //
0423:                        if(isDefVal) {
0424:                            //go to def value
0425:                            if(oldDefVal.length()>0 || defValue.length()>0)tf.typeKey('=');
0426:                            //delete old def value
0427:                            for(int i=0;i<oldDefVal.length();i++) {
0428:                                tf.pushKey(KeyEvent.VK_DELETE);
0429:                            }
0430:                            if(defValue.length()>0) {
0431:                                //type new
0432:                                for(int i=0;i<defValue.length();i++) {
0433:                                    tf.typeKey(defValue.charAt(i));
0434:                                }
0435:                            } else if (oldDefVal.length()>0){
0436:                                tf.pushKey(KeyEvent.VK_RIGHT);
0437:                                tf.pushKey(KeyEvent.VK_BACK_SPACE);
0438:                            }
0439:                            new EventTool().waitNoEvent(minWait);
0440:                        }
0441:                    } else if(isType && !isVis) {
0442:                        if(isName || isDefVal) {
0443:                            //if there is need to change name and/or def value
0444:                            if(!innerCall){innerCall=true;attributeNaturalWayNaming(oldVis,oldType, name, oldDefVal, false);}
0445:                            if(!innerCall){innerCall=true;attributeNaturalWayNaming(visibility,type, name, oldDefVal, false);}
0446:                            if(!innerCall){innerCall=true;attributeNaturalWayNaming(visibility,type, name, defValue, false);}
0447:                        } else {
0448:                            int typeFrom=initialTxt.indexOf(oldType,oldVis.length());
0449:                            int typeTo=typeFrom+oldType.length();
0450:                            //
0451:                            if(tf.getSelectionStart()!=typeFrom && tf.getSelectionEnd()!=typeTo) {
0452:                                tf.selectText(typeFrom,typeTo);
0453:                            }
0454:                            if(type.length()>0) {
0455:                                for(int i=0;i<type.length();i++) {
0456:                                    tf.typeKey(type.charAt(i));
0457:                                }
0458:                            } else {
0459:                                tf.pushKey(KeyEvent.VK_BACK_SPACE);
0460:                            }
0461:                            new EventTool().waitNoEvent(minWait);
0462:                        }
0463:                    } else if(!isType && isVis) {
0464:                        if(isName || isDefVal) {
0465:                            //if there is need to change name and/or def value
0466:                            if(!innerCall){innerCall=true;attributeNaturalWayNaming(oldVis,oldType, name, oldDefVal, false);}
0467:                            if(!innerCall){innerCall=true;attributeNaturalWayNaming(visibility,type, name, oldDefVal, false);}
0468:                            if(!innerCall){innerCall=true;attributeNaturalWayNaming(visibility,type, name, defValue, false);}
0469:                        } else {
0470:                            int visFrom=0;
0471:                            int visTo=oldVis.length();
0472:                            //
0473:                            if(tf.getSelectionStart()!=visFrom && tf.getSelectionEnd()!=visTo) {
0474:                                tf.selectText(visFrom,visTo);
0475:                            }
0476:                            if(visibility.length()>0) {
0477:                                for(int i=0;i<visibility.length();i++) {
0478:                                    tf.typeKey(visibility.charAt(i));
0479:                                }
0480:                            } else {
0481:                                tf.pushKey(KeyEvent.VK_BACK_SPACE);
0482:                            }
0483:                            new EventTool().waitNoEvent(minWait);
0484:                        }
0485:                    } else if(isType && isVis) {
0486:                        if(!innerCall){innerCall=true;attributeNaturalWayNaming(visibility,oldType, oldName, oldDefVal, false);}
0487:                        if(!innerCall){innerCall=true;attributeNaturalWayNaming(visibility,type, oldName, oldDefVal, false);}
0488:                        if(!innerCall){innerCall=true;attributeNaturalWayNaming(visibility,type, name, defValue, false);}
0489:                    } else {
0490:                        innerCall=false;
0491:                        throw new UnsupportedOperationException("Utility can't handle your case (Combination of parameters).");
0492:                    }
0493:                     */
0494:                    //
0495:                    String ret = tf.getText();
0496:                    if (pressEnter) {
0497:                        tf.pushKey(KeyEvent.VK_ENTER);
0498:                        new EventTool().waitNoEvent(minWait);
0499:                    }
0500:                    innerCall = false;
0501:                    return ret;
0502:                }
0503:
0504:                private void changeText(String newString, String oldString,
0505:                        JTextFieldOperator textFieldOperator) {
0506:
0507:                    String blank = textFieldOperator.getText(textFieldOperator
0508:                            .getCaretPosition(), 1);
0509:                    while (" ".equals(blank)) {
0510:                        textFieldOperator.pushKey(KeyEvent.VK_RIGHT);
0511:                        blank = textFieldOperator.getText(textFieldOperator
0512:                                .getCaretPosition(), 1);
0513:                    }
0514:
0515:                    for (int i = 0; i < oldString.length(); i++) {
0516:                        textFieldOperator.pushKey(KeyEvent.VK_DELETE);
0517:                        new Timeout("", 1000);
0518:                    }
0519:
0520:                    for (int i = 0; i < newString.length(); i++) {
0521:                        textFieldOperator.typeKey(newString.charAt(i));
0522:                    }
0523:                }
0524:
0525:                /**
0526:                 * It works with existing edit control with
0527:                 * "anyVisibility anyType anyName = anyValue"  and "anyVisibility anyType anyName"
0528:                 * initial attribute with selected name (after Insert or double click).
0529:                 * Default values can be passed as null.
0530:                 * do not press enter at the end
0531:                 * @param visibility
0532:                 * @param type
0533:                 * @param name
0534:                 * @param defValue
0535:                 * @return resulting string in edit control
0536:                 */
0537:                public String attributeNaturalWayNaming(String visibility,
0538:                        String type, String name, String defValue) {
0539:                    return attributeNaturalWayNaming(visibility, type, name,
0540:                            defValue, false);
0541:                }
0542:
0543:                /**
0544:                 * It works with existing edit control with
0545:                 * "anyVisibility anyType anyName = anyValue"  and "anyVisibility anyType anyName"
0546:                 * initial attribute with selected name (after Insert or double click).
0547:                 * Default values can be passed as null.
0548:                 * do not press enter at the end
0549:                 * @param visibility
0550:                 * @param type
0551:                 * @param name
0552:                 * @return resulting string in edit control
0553:                 */
0554:                public String attributeNaturalWayNaming(String visibility,
0555:                        String type, String name) {
0556:                    return attributeNaturalWayNaming(visibility, type, name,
0557:                            null);
0558:                }
0559:
0560:                //==============================================================================================
0561:                /**
0562:                 * It works with existing edit control with
0563:                 * "anyVisibility anyRetType anyName( parType parName, ... )"  and "anyVisibility anyRetType anyName(  )"
0564:                 * initial attribute with selected name (after Insert or double click).
0565:                 * Default values can be passed as null.
0566:                 * @param visibility
0567:                 * @param retType
0568:                 * @param name
0569:                 * @param parTypes
0570:                 * @param parNames
0571:                 * @param pressEnter
0572:                 * @return resulting string in edit control
0573:                 */
0574:                public String operationNaturalWayNaming(String visibility,
0575:                        String retType, String name, String[] parTypes,
0576:                        String[] parNames, boolean pressEnter) {
0577:                    new EventTool().waitNoEvent(minWait);
0578:                    //support null as default value
0579:                    if (retType == null)
0580:                        retType = defaultReturnType;
0581:                    //
0582:                    if (visibility == null)
0583:                        visibility = defaultOperationVisibility;
0584:                    //
0585:                    if (name == null)
0586:                        name = defaultNewElementName;
0587:                    //
0588:                    if ((parTypes == null && parNames != null)
0589:                            || (parTypes != null && parNames == null)) {
0590:                        innerCall = false;
0591:                        throw new UnsupportedOperationException(
0592:                                "Utility can't handle your case(both parameters names and types should be null or both not null).");
0593:                    }
0594:                    //
0595:                    EditControlOperator ec = new EditControlOperator();
0596:                    JTextFieldOperator tf = ec.getTextFieldOperator();
0597:                    //
0598:                    String initialTxt = tf.getText();
0599:                    StringTokenizer prState = new StringTokenizer(initialTxt,
0600:                            " \t\n\r\f,()");
0601:                    String oldVis = prState.nextToken();
0602:                    String oldRetType = prState.nextToken();
0603:                    String oldName = prState.nextToken();
0604:                    //
0605:                    int numParam = prState.countTokens() / 2;
0606:                    //
0607:                    String[] oldParTypes = null;
0608:                    String[] oldParNames = null;
0609:                    if (numParam > 0) {
0610:                        oldParTypes = new String[numParam];
0611:                        oldParNames = new String[numParam];
0612:                        for (int i = 0; i < numParam; i++) {
0613:                            oldParTypes[i] = prState.nextToken();
0614:                            oldParNames[i] = prState.nextToken();
0615:
0616:                        }
0617:                    }
0618:                    boolean isName = !oldName.equals(name);
0619:                    boolean isRetType = !oldRetType.equals(retType);
0620:                    boolean isVis = !oldVis.equals(visibility);
0621:                    boolean isParam = (oldParTypes == null && parTypes != null)
0622:                            || (oldParTypes != null && parTypes == null)
0623:                            || (oldParTypes != null && parTypes != null && oldParTypes.length != parTypes.length);
0624:                    if (!isParam && oldParTypes != null) {
0625:                        //check parameters
0626:                        for (int i = 0; i < oldParTypes.length; i++) {
0627:                            isParam = !oldParTypes[i].equals(parTypes[i])
0628:                                    || !oldParNames[i].equals(parNames[i]);
0629:                            if (isParam)
0630:                                break;
0631:                        }
0632:                    }
0633:
0634:                    //different way:
0635:                    if (!isVis && !isRetType) {
0636:                        //only name and if needed defValue
0637:                        //check selection
0638:                        int nameFrom = initialTxt.indexOf(oldName, oldVis
0639:                                .length()
0640:                                + oldRetType.length());
0641:                        int nameTo = nameFrom + oldName.length();
0642:                        //check if name the same
0643:                        if (isName) {
0644:                            //select name
0645:                            if (tf.getSelectionStart() != nameFrom
0646:                                    && tf.getSelectionEnd() != nameTo) {
0647:                                tf.selectText(nameFrom, nameTo);
0648:                            }
0649:                            if (name.length() > 0) {
0650:                                //type name
0651:                                for (int i = 0; i < name.length(); i++) {
0652:                                    tf.typeKey(name.charAt(i));
0653:                                }
0654:                            } else {
0655:                                tf.pushKey(KeyEvent.VK_BACK_SPACE);
0656:                            }
0657:                            new EventTool().waitNoEvent(minWait);
0658:                        } else {
0659:                            //name the same as exists, do nothing
0660:                        }
0661:                        //
0662:                        if (isParam) {
0663:                            //go to parameters
0664:                            tf.typeKey('(');
0665:                            //
0666:                            if (oldParNames == null) {
0667:                                //type in new parameters
0668:                                for (int i = 0; i < parTypes.length; i++) {
0669:                                    for (int j = 0; j < parTypes[i].length(); j++)
0670:                                        tf.typeKey(parTypes[i].charAt(j));
0671:                                    tf.typeKey(' ');
0672:                                    for (int j = 0; j < parNames[i].length(); j++)
0673:                                        tf.typeKey(parNames[i].charAt(j));
0674:                                    if (i < (parTypes.length - 1))
0675:                                        tf.typeKey(',');
0676:                                }
0677:                            } else if (parNames == null) {
0678:                                //remove all
0679:                                int last = tf.getText().lastIndexOf(')');
0680:                                int first = tf.getText().indexOf('(');
0681:                                tf.setCaretPosition(last);
0682:                                for (int i = 0; i < (last - first - 1); i++)
0683:                                    tf.pushKey(KeyEvent.VK_BACK_SPACE);
0684:                            } else if (parNames.length == oldParNames.length) {
0685:                                int lastStart = tf.getText().indexOf('(');
0686:                                for (int i = 0; i < parNames.length; i++) {
0687:                                    //type
0688:                                    lastStart = tf.getText().indexOf(
0689:                                            oldParTypes[i], lastStart);
0690:                                    if (!parTypes[i].equals(oldParTypes[i])) {
0691:                                        tf.setCaretPosition(lastStart
0692:                                                + parTypes[i].length());
0693:                                        for (int j = 0; j < oldParTypes[i]
0694:                                                .length(); j++) {
0695:                                            tf.pushKey(KeyEvent.VK_BACK_SPACE);
0696:                                        }
0697:                                        for (int j = 0; j < parTypes[i]
0698:                                                .length(); j++) {
0699:                                            tf.typeKey(parTypes[i].charAt(j));
0700:                                        }
0701:                                    }
0702:                                    lastStart = tf.getText().indexOf(
0703:                                            oldParNames[i],
0704:                                            lastStart + parTypes[i].length());
0705:                                    if (!parNames[i].equals(oldParNames[i])) {
0706:                                        tf.setCaretPosition(lastStart
0707:                                                + parNames[i].length());
0708:                                        for (int j = 0; j < oldParNames[i]
0709:                                                .length(); j++) {
0710:                                            tf.pushKey(KeyEvent.VK_BACK_SPACE);
0711:                                        }
0712:                                        for (int j = 0; j < parNames[i]
0713:                                                .length(); j++) {
0714:                                            tf.typeKey(parNames[i].charAt(j));
0715:                                        }
0716:                                    }
0717:                                    lastStart = lastStart
0718:                                            + parNames[i].length();
0719:                                }
0720:                            } else if (parNames.length > oldParNames.length) {
0721:                                int lastStart = tf.getText().indexOf('(');
0722:                                for (int i = 0; i < oldParNames.length; i++) {
0723:                                    //type
0724:                                    lastStart = tf.getText().indexOf(
0725:                                            oldParTypes[i], lastStart);
0726:                                    if (!parTypes[i].equals(oldParTypes[i])) {
0727:                                        tf.setCaretPosition(lastStart
0728:                                                + parTypes[i].length());
0729:                                        for (int j = 0; j < oldParTypes[i]
0730:                                                .length(); j++) {
0731:                                            tf.pushKey(KeyEvent.VK_BACK_SPACE);
0732:                                        }
0733:                                        for (int j = 0; j < parTypes[i]
0734:                                                .length(); j++) {
0735:                                            tf.typeKey(parTypes[i].charAt(j));
0736:                                        }
0737:                                    }
0738:                                    lastStart = tf.getText().indexOf(
0739:                                            oldParNames[i],
0740:                                            lastStart + parTypes[i].length());
0741:                                    if (!parNames[i].equals(oldParNames[i])) {
0742:                                        tf.setCaretPosition(lastStart
0743:                                                + parNames[i].length());
0744:                                        for (int j = 0; j < oldParNames[i]
0745:                                                .length(); j++) {
0746:                                            tf.pushKey(KeyEvent.VK_BACK_SPACE);
0747:                                        }
0748:                                        for (int j = 0; j < parNames[i]
0749:                                                .length(); j++) {
0750:                                            tf.typeKey(parNames[i].charAt(j));
0751:                                        }
0752:                                    }
0753:                                    lastStart = lastStart
0754:                                            + parNames[i].length();
0755:                                }
0756:                                tf.typeKey(',');
0757:                                for (int i = oldParNames.length; i < parNames.length; i++) {
0758:                                    for (int j = 0; j < parTypes[i].length(); j++)
0759:                                        tf.typeKey(parTypes[i].charAt(j));
0760:                                    tf.typeKey(' ');
0761:                                    for (int j = 0; j < parNames[i].length(); j++)
0762:                                        tf.typeKey(parNames[i].charAt(j));
0763:                                    if (i < (parTypes.length - 1))
0764:                                        tf.typeKey(',');
0765:                                }
0766:                            } else {
0767:                                innerCall = false;
0768:                                throw new UnsupportedOperationException(
0769:                                        "Utility can't handle your case(decrease of number parameters will be implemented later).");
0770:                            }
0771:                            new EventTool().waitNoEvent(minWait);
0772:                        }
0773:                    } else if (isRetType && !isVis) {
0774:                        if (isName || isParam) {
0775:                            //if there is need to change name and/or def value
0776:                            if (!innerCall) {
0777:                                innerCall = true;
0778:                                operationNaturalWayNaming(oldVis, oldRetType,
0779:                                        name, oldParTypes, oldParNames, false);
0780:                            }
0781:                            if (!innerCall) {
0782:                                innerCall = true;
0783:                                operationNaturalWayNaming(visibility, retType,
0784:                                        name, oldParTypes, oldParNames, false);
0785:                            }
0786:                            if (!innerCall) {
0787:                                innerCall = true;
0788:                                operationNaturalWayNaming(visibility, retType,
0789:                                        name, parTypes, parNames, false);
0790:                            }
0791:                        } else {
0792:                            int typeFrom = initialTxt.indexOf(oldRetType,
0793:                                    oldVis.length());
0794:                            int typeTo = typeFrom + oldRetType.length();
0795:                            //
0796:                            if (tf.getSelectionStart() != typeFrom
0797:                                    && tf.getSelectionEnd() != typeTo) {
0798:                                tf.selectText(typeFrom, typeTo);
0799:                            }
0800:                            if (retType.length() > 0) {
0801:                                for (int i = 0; i < retType.length(); i++) {
0802:                                    tf.typeKey(retType.charAt(i));
0803:                                }
0804:                            } else {
0805:                                tf.pushKey(KeyEvent.VK_BACK_SPACE);
0806:                            }
0807:                            new EventTool().waitNoEvent(minWait);
0808:                        }
0809:                    } else if (!isRetType && isVis) {
0810:                        if (isName || isParam) {
0811:                            //if there is need to change name and/or def value
0812:                            if (!innerCall) {
0813:                                innerCall = true;
0814:                                operationNaturalWayNaming(oldVis, oldRetType,
0815:                                        name, oldParTypes, oldParNames, false);
0816:                            }
0817:                            if (!innerCall) {
0818:                                innerCall = true;
0819:                                operationNaturalWayNaming(visibility, retType,
0820:                                        name, oldParTypes, oldParNames, false);
0821:                            }
0822:                            if (!innerCall) {
0823:                                innerCall = true;
0824:                                operationNaturalWayNaming(visibility, retType,
0825:                                        name, parTypes, parNames, false);
0826:                            }
0827:                        } else {
0828:
0829:                            int visFrom = 0;
0830:                            int visTo = oldVis.length();
0831:                            //
0832:                            if (tf.getSelectionStart() != visFrom
0833:                                    && tf.getSelectionEnd() != visTo) {
0834:                                tf.selectText(visFrom, visTo);
0835:                            }
0836:                            if (visibility.length() > 0) {
0837:                                for (int i = 0; i < visibility.length(); i++) {
0838:                                    tf.typeKey(visibility.charAt(i));
0839:                                }
0840:                            } else {
0841:                                tf.pushKey(KeyEvent.VK_BACK_SPACE);
0842:                            }
0843:                            new EventTool().waitNoEvent(minWait);
0844:                        }
0845:                    } else if (isRetType && isVis) {
0846:                        if (!innerCall) {
0847:                            innerCall = true;
0848:                            operationNaturalWayNaming(visibility, oldRetType,
0849:                                    oldName, oldParTypes, oldParNames, false);
0850:                        }
0851:                        if (!innerCall) {
0852:                            innerCall = true;
0853:                            operationNaturalWayNaming(visibility, retType,
0854:                                    oldName, oldParTypes, oldParNames, false);
0855:                        }
0856:                        if (!innerCall) {
0857:                            innerCall = true;
0858:                            operationNaturalWayNaming(visibility, retType,
0859:                                    name, parTypes, parNames, false);
0860:                        }
0861:                    } else {
0862:                        innerCall = false;
0863:                        throw new UnsupportedOperationException(
0864:                                "Utility can't handle your case./changes:"
0865:                                        + isVis + ":" + isRetType + ":"
0866:                                        + isName + ":" + isParam);
0867:                    }
0868:                    //
0869:                    String ret = tf.getText();
0870:                    if (pressEnter) {
0871:                        tf.pushKey(KeyEvent.VK_ENTER);
0872:                        new EventTool().waitNoEvent(minWait);
0873:                    }
0874:                    innerCall = false;
0875:                    return ret;
0876:                }
0877:
0878:                /**
0879:                 * It works with existing edit control with
0880:                 * "anyVisibility anyRetType anyName( parType parName)"  and "anyVisibility anyRetType anyName(  )"
0881:                 * initial attribute with selected name (after Insert or double click).
0882:                 * Default values can be passed as null.
0883:                 * @param visibility
0884:                 * @param retType
0885:                 * @param name
0886:                 * @param parTypes
0887:                 * @param parNames
0888:                 * @param pressEnter
0889:                 * @return resulting string in edit control
0890:                 */
0891:                public String operationNaturalWayNaming(String visibility,
0892:                        String retType, String name, String parTypes,
0893:                        String parNames, boolean pressEnter) {
0894:                    String[] aparTypes = { parTypes };
0895:                    String[] aparNames = { parNames };
0896:                    return operationNaturalWayNaming(visibility, retType, name,
0897:                            aparTypes, aparNames, pressEnter);
0898:                }
0899:
0900:                /**
0901:                 * It works with existing edit control with
0902:                 * "anyVisibility anyRetType anyName( parType parName, ... )"  and "anyVisibility anyRetType anyName(  )"
0903:                 * initial attribute with selected name (after Insert or double click).
0904:                 * Default values can be passed as null.
0905:                 * @param visibility
0906:                 * @param retType
0907:                 * @param name
0908:                 * @param parTypes
0909:                 * @param parNames
0910:                 * @return resulting string in edit control
0911:                 */
0912:                public String operationNaturalWayNaming(String visibility,
0913:                        String retType, String name, String[] parTypes,
0914:                        String[] parNames) {
0915:                    return operationNaturalWayNaming(visibility, retType, name,
0916:                            parTypes, parNames, false);
0917:                }
0918:
0919:                /**
0920:                 * It works with existing edit control with
0921:                 * "anyVisibility anyRetType anyName( parType parName)"  and "anyVisibility anyRetType anyName(  )"
0922:                 * initial attribute with selected name (after Insert or double click).
0923:                 * Default values can be passed as null.
0924:                 * @param visibility
0925:                 * @param retType
0926:                 * @param name
0927:                 * @param parTypes
0928:                 * @param parNames
0929:                 * @return resulting string in edit control
0930:                 */
0931:                public String operationNaturalWayNaming(String visibility,
0932:                        String retType, String name, String parTypes,
0933:                        String parNames) {
0934:                    return operationNaturalWayNaming(visibility, retType, name,
0935:                            parTypes, parNames, false);
0936:                }
0937:
0938:                /**
0939:                 * It works with existing edit control with
0940:                 * "anyVisibility anyRetType anyName( parType parName, ... )"  and "anyVisibility anyRetType anyName(  )"
0941:                 * initial attribute with selected name (after Insert or double click).
0942:                 * Default values can be passed as null.
0943:                 * @param visibility
0944:                 * @param retType
0945:                 * @param name
0946:                 * @param parameters
0947:                 * @param pressEnter
0948:                 * @return resulting string in edit control
0949:                 */
0950:                public String operationNaturalWayNaming(String visibility,
0951:                        String retType, String name, String parameters,
0952:                        boolean pressEnter) {
0953:                    //
0954:                    String[] parTypes = null;
0955:                    String[] parNames = null;
0956:                    //
0957:                    if (parameters != null) {
0958:                        StringTokenizer prState = new StringTokenizer(
0959:                                parameters, " \t\n\r\f,()");
0960:                        int numParam = prState.countTokens() / 2;
0961:                        if (numParam > 0) {
0962:                            parTypes = new String[numParam];
0963:                            parNames = new String[numParam];
0964:                            for (int i = 0; i < numParam; i++) {
0965:                                parTypes[i] = prState.nextToken();
0966:                                parNames[i] = prState.nextToken();
0967:
0968:                            }
0969:                        }
0970:                    }
0971:                    //
0972:                    return operationNaturalWayNaming(visibility, retType, name,
0973:                            parTypes, parNames, pressEnter);
0974:                }
0975:
0976:                /**
0977:                 * It works with existing edit control with
0978:                 * "anyVisibility anyRetType anyName( parType parName, ... )"  and "anyVisibility anyRetType anyName(  )"
0979:                 * initial attribute with selected name (after Insert or double click).
0980:                 * Default values can be passed as null.
0981:                 * @param visibility
0982:                 * @param retType
0983:                 * @param name
0984:                 * @param parameters
0985:                 * @return resulting string in edit control
0986:                 */
0987:                public String operationNaturalWayNaming(String visibility,
0988:                        String retType, String name, String parameters) {
0989:                    return operationNaturalWayNaming(visibility, retType, name,
0990:                            parameters, false);
0991:                }
0992:
0993:                /**
0994:                 * It works with existing edit control with
0995:                 * "anyVisibility anyRetType anyName( parType parName, ... )"  and "anyVisibility anyRetType anyName(  )"
0996:                 * initial attribute with selected name (after Insert or double click).
0997:                 * Default values can be passed as null.
0998:                 * @param visibility
0999:                 * @param retType
1000:                 * @param name
1001:                 * @return resulting string in edit control
1002:                 */
1003:                public String operationNaturalWayNaming(String visibility,
1004:                        String retType, String name) {
1005:                    return operationNaturalWayNaming(visibility, retType, name,
1006:                            (String[]) null, (String[]) null, false);
1007:                }
1008:
1009:                //=========================================================================================================
1010:                public CompartmentOperator getNotConstructorFinalizerOperationCmp(
1011:                        CompartmentOperator opComp, String className, int index) {
1012:                    CompartmentOperator oprCmp = null;
1013:                    for (int i = 0; i < opComp.getCompartments().size(); i++) {
1014:                        String tmp = opComp.getCompartments().get(i).getName();
1015:                        //
1016:                        if (tmp.indexOf("public " + className + "(") == -1
1017:                                && tmp.indexOf("void finalize(") == -1) {
1018:                            oprCmp = opComp.getCompartments().get(i);
1019:                            break;
1020:                        }
1021:                    }
1022:                    return oprCmp;
1023:                }
1024:
1025:                public CompartmentOperator getNotConstructorFinalizerOperationCmp(
1026:                        CompartmentOperator opComp, String className) {
1027:                    return getNotConstructorFinalizerOperationCmp(opComp,
1028:                            className, 0);
1029:                }
1030:
1031:                //
1032:                public String getNotConstructorFinalizerOperationStr(
1033:                        CompartmentOperator opComp, String className, int index) {
1034:                    return getNotConstructorFinalizerOperationCmp(opComp,
1035:                            className, index).getName();
1036:                }
1037:
1038:                public String getNotConstructorFinalizerOperationStr(
1039:                        CompartmentOperator opComp, String className) {
1040:                    return getNotConstructorFinalizerOperationStr(opComp,
1041:                            className, 0);
1042:                }
1043:
1044:            }
1045:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.