001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: /*
043: * OperationOperator.java
044: *
045: * Created on December 6, 2005, 4:41 PM
046: *
047: */
048:
049: package org.netbeans.test.umllib.values.operatons;
050:
051: import java.awt.event.KeyEvent;
052: import java.util.ArrayList;
053: import java.util.List;
054: import org.netbeans.jellytools.ProjectsTabOperator;
055: import org.netbeans.jellytools.nodes.Node;
056: import org.netbeans.jemmy.operators.JTextFieldOperator;
057: import org.netbeans.test.umllib.CompartmentOperator;
058: import org.netbeans.test.umllib.CompartmentTypes;
059: import org.netbeans.test.umllib.DiagramElementOperator;
060: import org.netbeans.test.umllib.EditControlOperator;
061: import org.netbeans.test.umllib.util.LabelsAndTitles;
062: import org.netbeans.test.umllib.util.PopupConstants;
063: import org.netbeans.test.umllib.values.Argument;
064: import org.netbeans.test.umllib.values.ValueOperator;
065:
066: /**
067: *
068: * @author Alexandr Scherbatiy
069: */
070:
071: public class OperationContainerOperator extends ValueOperator {
072:
073: private DiagramElementOperator elementOperator;
074: private CompartmentOperator operationCompartment;
075:
076: /** Creates a new instance of OperationOperator */
077: public OperationContainerOperator(
078: DiagramElementOperator elementOperator) {
079: this .elementOperator = elementOperator;
080: this .operationCompartment = new CompartmentOperator(
081: elementOperator,
082: CompartmentTypes.OPERATION_LIST_COMPARTMENT);
083: }
084:
085: // ====================== Getting Action ================================
086:
087: public OperationElement getOperation(String name) {
088: return getOperation(name, 0);
089: }
090:
091: public OperationElement getOperation(String name, int index) {
092: OperationElement[] elems = getOperations(name);
093: return elems[index];
094: }
095:
096: public OperationElement getOperation(int index) {
097: OperationElement[] elems = getOperations();
098: return elems[index];
099: }
100:
101: public OperationElement[] getOperations() {
102: return getOperations(null);
103: }
104:
105: public OperationElement[] getOperations(String name) {
106:
107: ArrayList<CompartmentOperator> list = operationCompartment
108: .getCompartments();
109: ArrayList<OperationElement> operationList = new ArrayList<OperationElement>();
110:
111: for (CompartmentOperator compar : list) {
112: String parse = compar.getName();
113: //System.out.println("--- get operation: \"" + parse+ "\"");
114: OperationElement elem = OperationElement
115: .parseOperationElement(parse);
116: if (name == null || elem.getName().equals(name)) {
117: operationList.add(elem);
118: }
119:
120: }
121:
122: return operationList.toArray(new OperationElement[] {});
123: }
124:
125: // ======================= Add / Rename / Remove Actions ===================
126:
127: public void addOperation(OperationElement operationElement,
128: String projectTreePath) {
129:
130: System.out.println("*** add operation by tree Path: \""
131: + projectTreePath + "\"");
132: Node treeNode = new Node(new ProjectsTabOperator().tree(),
133: projectTreePath);
134: treeNode.performPopupAction(PopupConstants.ADD_OPERATION);
135:
136: addOperationByContextMenu(operationElement);
137: }
138:
139: public void addOperation(OperationElement operationElement) {
140: addOperationByContextMenu(operationElement);
141: }
142:
143: private void addOperationByContextMenu(
144: OperationElement operationElement) {
145:
146: System.out
147: .println("***************************************************");
148: OperationElement old = new OperationElement();
149: System.out.println("*** element = " + operationElement);
150: System.out.println("*** old = " + old);
151: System.out.println("*** text = \""
152: + operationElement.getText() + "\"");
153: System.out.println("*** old text = \"" + old.getText() + "\"");
154: operationCompartment.getPopup().pushMenu(
155: LabelsAndTitles.POPUP_ADD_OPERATION);
156:
157: EditControlOperator ec = new EditControlOperator();
158: JTextFieldOperator textFieldOperator = ec
159: .getTextFieldOperator();
160:
161: //tf.setText(operationElement.getText());
162: textFieldOperator.setCaretPosition(0);
163:
164: changeText(operationElement.getVisibility().getValue(), old
165: .getVisibility().getValue(), textFieldOperator);
166: changeText(operationElement.getType().getValue(), old.getType()
167: .getValue(), textFieldOperator);
168: changeText(operationElement.getName(), old.getName(),
169: textFieldOperator);
170:
171: List<Argument> argList = operationElement.getArguments();
172:
173: // TBD: should add multiple arguments!!!
174:
175: for (int i = 0; i < argList.size(); i++) {
176: moveRight(textFieldOperator);
177: printText(argList.get(i).getType().getValue(),
178: textFieldOperator);
179: printText(argList.get(i).getName(), textFieldOperator);
180: }
181:
182: pressEnter(textFieldOperator);
183: }
184:
185: }
|