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: * AttributeContainerOperator.java
044: *
045: * Created on January 27, 2006, 1:31 PM
046: *
047: */
048:
049: package org.netbeans.test.umllib.values.attributes;
050:
051: import java.awt.event.KeyEvent;
052: import java.util.ArrayList;
053: import org.netbeans.jemmy.operators.JTextFieldOperator;
054: import org.netbeans.test.umllib.CompartmentOperator;
055: import org.netbeans.test.umllib.CompartmentTypes;
056: import org.netbeans.test.umllib.DiagramElementOperator;
057: import org.netbeans.test.umllib.EditControlOperator;
058: import org.netbeans.test.umllib.util.LabelsAndTitles;
059: import org.netbeans.test.umllib.values.ValueOperator;
060: import org.netbeans.test.umllib.values.operatons.OperationElement;
061:
062: /**
063: *
064: * @author Alexandr Scherbatiy
065: */
066:
067: public class AttributeContainerOperator extends ValueOperator {
068:
069: private DiagramElementOperator elementOperator;
070: private CompartmentOperator attributeCompartment;
071:
072: /** Creates a new instance of AttributeContainerOperator */
073: public AttributeContainerOperator(
074: DiagramElementOperator elementOperator) {
075: this .elementOperator = elementOperator;
076: this .attributeCompartment = new CompartmentOperator(
077: elementOperator,
078: CompartmentTypes.ATTRIBUTE_LIST_COMPARTMENT);
079: }
080:
081: // ====================== Getting Action ================================
082:
083: public AttributeElement getAttribute(String name) {
084:
085: if (name == null) {
086: return null;
087: }
088:
089: AttributeElement[] elems = getAttributes();
090:
091: for (AttributeElement elem : elems) {
092: if (name.equals(elem.getName())) {
093: return elem;
094: }
095: }
096:
097: return null;
098: }
099:
100: public AttributeElement getAttribute(int index) {
101: AttributeElement[] elems = getAttributes();
102: return elems[index];
103: }
104:
105: public AttributeElement[] getAttributes() {
106:
107: ArrayList<CompartmentOperator> list = attributeCompartment
108: .getCompartments();
109: ArrayList<AttributeElement> attributeList = new ArrayList<AttributeElement>();
110:
111: for (CompartmentOperator compar : list) {
112: String parse = compar.getName();
113: //System.out.println("--- get operation: \"" + parse+ "\"");
114: AttributeElement elem = AttributeElement
115: .parseOperationElement(parse);
116: attributeList.add(elem);
117:
118: }
119:
120: return attributeList.toArray(new AttributeElement[] {});
121: }
122:
123: // ======================= Add / Rename / Remove Actions ===================
124:
125: public void addAttribute(AttributeElement attributeElement) {
126: addOperationByContextMenu(attributeElement);
127: }
128:
129: private void addOperationByContextMenu(
130: AttributeElement attributeElement) {
131:
132: System.out
133: .println("***************************************************");
134: AttributeElement old = new AttributeElement();
135: System.out.println("*** element = " + attributeElement);
136: System.out.println("*** old = " + old);
137: System.out.println("*** text = \""
138: + attributeElement.getText() + "\"");
139: System.out.println("*** old text = \"" + old.getText() + "\"");
140: attributeCompartment.getPopup().pushMenu(
141: LabelsAndTitles.POPUP_ADD_ATTRIBUTE);
142:
143: EditControlOperator ec = new EditControlOperator();
144: JTextFieldOperator textFieldOperator = ec
145: .getTextFieldOperator();
146:
147: //tf.setText(operationElement.getText());
148: textFieldOperator.setCaretPosition(0);
149:
150: changeText(attributeElement.getVisibility().getValue(), old
151: .getVisibility().getValue(), textFieldOperator);
152: changeText(attributeElement.getType().getValue(), old.getType()
153: .getValue(), textFieldOperator);
154: changeText(attributeElement.getName(), old.getName(),
155: textFieldOperator);
156:
157: textFieldOperator.pushKey(KeyEvent.VK_ENTER);
158:
159: }
160:
161: }
|