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: * UMLDiagramOperator.java
044: *
045: * Created on 4 Feb 2005, 17:18
046: */
047:
048: package org.netbeans.test.umllib;
049:
050: import java.awt.Component;
051: import java.awt.Point;
052: import java.awt.Rectangle;
053: import java.awt.event.InputEvent;
054: import java.util.ArrayList;
055: import java.util.Iterator;
056: import javax.swing.JComponent;
057: import org.netbeans.core.windows.view.ui.tabcontrol.TabbedAdapter;
058: import org.netbeans.jellytools.MainWindowOperator;
059: import org.netbeans.jellytools.ProjectsTabOperator;
060: import org.netbeans.jellytools.TopComponentOperator;
061: import org.netbeans.jellytools.nodes.Node;
062: import org.netbeans.jemmy.ComponentChooser;
063: import org.netbeans.jemmy.EventTool;
064: import org.netbeans.jemmy.JemmyProperties;
065: import org.netbeans.jemmy.Timeout;
066: import org.netbeans.jemmy.Timeouts;
067: import org.netbeans.jemmy.Waitable;
068: import org.netbeans.jemmy.Waiter;
069: import org.netbeans.jemmy.drivers.MouseDriver;
070: import org.netbeans.jemmy.drivers.input.MouseRobotDriver;
071: import org.netbeans.jemmy.operators.JPopupMenuOperator;
072: import org.netbeans.jemmy.operators.Operator;
073: import org.netbeans.modules.uml.drawingarea.DiagramTopComponent;
074: import org.netbeans.modules.uml.ui.swing.drawingarea.ADDrawingAreaControl;
075: import org.netbeans.test.umllib.customelements.LifelineOperator;
076: import org.netbeans.test.umllib.exceptions.NotFoundException;
077: import org.netbeans.test.umllib.exceptions.NotFoundOnDiagramException;
078: import org.netbeans.test.umllib.exceptions.UMLCommonException;
079: import org.netbeans.test.umllib.util.LibProperties;
080:
081: import org.netbeans.jemmy.operators.JDialogOperator;
082: import org.netbeans.jemmy.operators.JButtonOperator;
083: import org.netbeans.jemmy.operators.JComboBoxOperator;
084: import org.netbeans.modules.uml.core.metamodel.core.foundation.IPresentationElement;
085: import org.netbeans.modules.uml.core.support.umlutils.ETList;
086: import org.netbeans.modules.uml.ui.support.applicationmanager.NodePresentation;
087: import org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject;
088: import org.netbeans.modules.uml.ui.swing.drawingarea.ADGraphWindow;
089: import org.netbeans.modules.uml.ui.swing.drawingarea.IDrawingAreaControl;
090: import org.openide.windows.TopComponent;
091:
092: /**
093: * This common diagram operator
094: * @author Alexei Mokeev
095: */
096: public class DiagramOperator extends TopComponentOperator {
097: private Component tcoSource = null;
098: private IDrawingAreaControl drawingAreaControl = null;
099: private DrawingAreaOperator drawingArea = null;
100: private String diagramName = null;
101: private DiagramToolbarOperator mToolbar = null;
102: private UMLPaletteOperator mPaletter = null;
103:
104: public static final long WAIT_DIAGRAM_TIMEOUT = 60000;
105:
106: static {
107: Timeouts.initDefault("DiagramOperator.WaitDiagramOperator",
108: WAIT_DIAGRAM_TIMEOUT);
109: }
110:
111: /**
112: * Creates a new instance of DiagramOperator
113: * @param diagramName Diagram name
114: */
115: public DiagramOperator(String diagramName) {
116: super ((JComponent) waitForDiagram(diagramName,
117: getDefaultStringComparator()));
118: this .diagramName = diagramName;
119: tcoSource = getSource();
120: drawingAreaControl = (IDrawingAreaControl) findSubComponent((ComponentChooser) new DrawingAreaControlChooser());
121: Component areaComp = findSubComponent((ComponentChooser) new DrawingAreaChooser());
122: drawingArea = new DrawingAreaOperator((ADGraphWindow) areaComp);
123: }
124:
125: /**
126: * Returns instance of IDrawingAreaControl for this diagram
127: * @return instance of IDrawingAreaControl for this diagram
128: */
129: public IDrawingAreaControl getDrawingAreaControl() {
130: return drawingAreaControl;
131: }
132:
133: /**
134: * Returns DrawingAreaOperator for this diagram
135: * @return DrawingAreaOperator for this diagram
136: */
137: public DrawingAreaOperator getDrawingArea() {
138: return drawingArea;
139: }
140:
141: /**
142: * Returns diagram name
143: * @return diagram name
144: */
145: public String getDiagramName() {
146: return diagramName;
147: }
148:
149: /**
150: * Return toolbar for this diagram
151: * @return Toolbar operator for this diagram
152: */
153: public DiagramToolbarOperator toolbar() {
154: if (mToolbar == null) {
155: mToolbar = new DiagramToolbarOperator(this );
156: }
157: return mToolbar;
158: }
159:
160: /**
161: * Return paletter for this diagram, activate palette
162: * @return Paletter operator for this diagram
163: */
164: public UMLPaletteOperator paletter() {
165: if (mPaletter == null || !mPaletter.isShowing()) {
166: mPaletter = new UMLPaletteOperator();
167: }
168: mPaletter.makeComponentVisible();
169: mPaletter.waitComponentVisible(true);
170: return mPaletter;
171: }
172:
173: /**
174: * Put element on diagram by pressing paletter butoon and clicking on
175: * the diagram
176: * @param name Name for new element
177: * @param elementType Type of new element
178: * @throws qa.uml.exceptions.NotFoundException when Button for the element is not found on paletter
179: * @return Operator for created element
180: */
181: public DiagramElementOperator putElementOnDiagram(String name,
182: ElementTypes elementType) throws NotFoundException {
183: Point p = getDrawingArea().getFreePoint();
184: return putElementOnDiagram(name, elementType, p.x, p.y);
185: }
186:
187: /**
188: * Put element on diagram by pressing paletter butoon and clicking on
189: * the diagram
190: * @param name Name for new element
191: * @param elementType Expanded Type of new element
192: * @throws qa.uml.exceptions.NotFoundException when Button for the element is not found on paletter
193: * @return Operator for created element
194: */
195: public DiagramElementOperator putElementOnDiagram(String name,
196: ExpandedElementTypes elementType) throws NotFoundException {
197: Point p = getDrawingArea().getFreePoint();
198: return putElementOnDiagram(name, elementType, p.x, p.y);
199: }
200:
201: /**
202: * create an element on diagram by pressing paletter butoon and clicking on
203: * the diagram
204: * @param name Name for new element
205: * @param elementType Type of new element
206: * @throws qa.uml.exceptions.NotFoundException
207: */
208: public void createGenericElementOnDiagram(String name,
209: ElementTypes elementType) throws NotFoundException {
210: Point p = getDrawingArea().getFreePoint();
211: createGenericElementOnDiagram(name, elementType, p.x, p.y,
212: LibProperties.getCurrentNamer(elementType));
213: }
214:
215: /**
216: * Put element on diagram by pressing paletter butoon and clicking on
217: * the diagram
218: * @param name Name for new element
219: * @param elementType Type of new element
220: * @param x X coordinate
221: * @param y Y coordinate
222: * @throws qa.uml.exceptions.NotFoundException when Button for the element is not found on paletter
223: * @return Operator for created element
224: */
225: public DiagramElementOperator putElementOnDiagram(String name,
226: ElementTypes elementType, int x, int y)
227: throws NotFoundException {
228: return putElementOnDiagram(name, elementType, x, y,
229: LibProperties.getCurrentNamer(elementType));
230: }
231:
232: /**
233: * Put element on diagram by pressing paletter butoon and clicking on
234: * the diagram
235: * @param name Name for new element
236: * @param elementType Expanded Type of new element
237: * @param x X coordinate
238: * @param y Y coordinate
239: * @throws qa.uml.exceptions.NotFoundException when Button for the element is not found on paletter
240: * @return Operator for created element
241: */
242: public DiagramElementOperator putElementOnDiagram(String name,
243: ExpandedElementTypes elementType, int x, int y)
244: throws NotFoundException {
245: return putElementOnDiagram(name, elementType, x, y,
246: LibProperties.getCurrentNamer(elementType));
247: }
248:
249: /**
250: * Put element on diagram by pressing paletter butoon and clicking on
251: * the diagram
252: * @param name Name for new element
253: * @param elementType Type of new element
254: * @param x X coordinate
255: * @param y Y coordinate
256: * @throws qa.uml.exceptions.NotFoundException when Button for the element is not found on paletter
257: */
258: public void createGenericElementOnDiagram(String name,
259: ElementTypes elementType, int x, int y)
260: throws NotFoundException {
261: createGenericElementOnDiagram(name, elementType, x, y,
262: LibProperties.getCurrentNamer(elementType));
263: }
264:
265: /**
266: * Put element on diagram by pressing paletter butoon and clicking on
267: * the diagram
268: * @param name Name for new element
269: * @param elementType Expanded Type of new element
270: * @param x X coordinate
271: * @param y Y coordinate
272: * @throws qa.uml.exceptions.NotFoundException when Button for the element is not found on paletter
273: */
274: public void createGenericElementOnDiagram(String name,
275: ExpandedElementTypes elementType, int x, int y)
276: throws NotFoundException {
277: createGenericElementOnDiagram(name, elementType, x, y,
278: LibProperties.getCurrentNamer(elementType));
279: }
280:
281: /**
282: * Put element on diagram by pressing paletter butoon and clicking on
283: * the diagram
284: * @param name Name for new element
285: * @param elementType Type of new element
286: * @param x X cooordinate of point where element will be created
287: * @param y Y cooordinate of point where element will be created
288: * @param namer Namer for this element. Certain elements
289: * should be named in very special way
290: * @throws qa.uml.exceptions.NotFoundException when Button for the element is not found on paletter
291: * @return Operator for created element
292: */
293: public DiagramElementOperator putElementOnDiagram(String name,
294: ElementTypes elementType, int x, int y, SetName namer)
295: throws NotFoundException {
296: createGenericElementOnDiagram(name, elementType, x, y, namer);
297: new EventTool().waitNoEvent(500);
298: try {
299: Thread.sleep(100);
300: } catch (Exception ex) {
301: }
302: if (elementType.equals(ElementTypes.LIFELINE)
303: || elementType.equals(ElementTypes.ACTOR_LIFELINE)) {
304: int semicolonPos = name.indexOf(':');
305: String lineName = name.substring(0, semicolonPos);
306: String classifierName = name.substring(semicolonPos + 1);
307: return new LifelineOperator(this , lineName, classifierName);
308: } else
309: return new DiagramElementOperator(this , name, elementType,
310: 0);
311: }
312:
313: /**
314: * Put element on diagram by pressing paletter butoon and clicking on
315: * the diagram
316: * @param name Name for new element
317: * @param elementType Expanded Type of new element
318: * @param x X cooordinate of point where element will be created
319: * @param y Y cooordinate of point where element will be created
320: * @param namer Namer for this element. Certain elements
321: * should be named in very special way
322: * @throws qa.uml.exceptions.NotFoundException when Button for the element is not found on paletter
323: * @return Operator for created element
324: */
325: public DiagramElementOperator putElementOnDiagram(String name,
326: ExpandedElementTypes elementType, int x, int y,
327: SetName namer) throws NotFoundException {
328: createGenericElementOnDiagram(name, elementType, x, y, namer);
329: new EventTool().waitNoEvent(500);
330: if (elementType.equals(ExpandedElementTypes.LIFELINE)
331: || elementType
332: .equals(ExpandedElementTypes.ACTOR_LIFELINE)) {
333: int semicolonPos = name.indexOf(':');
334: String lineName = name.substring(0, semicolonPos);
335: String classifierName = name.substring(semicolonPos + 1);
336: return new LifelineOperator(this , lineName, classifierName);
337: } else
338: return new DiagramElementOperator(this , name, elementType,
339: 0);
340: }
341:
342: /**
343: * Put element on diagram by pressing paletter butoon and clicking on
344: * the diagram
345: * @param name Name for new element
346: * @param elementType Type of new element
347: * @param x X cooordinate of point where element will be created
348: * @param y Y cooordinate of point where element will be created
349: * @param namer Namer for this element. Certain elements
350: * should be named in very special way
351: * @throws qa.uml.exceptions.NotFoundException
352: */
353: public void createGenericElementOnDiagram(String name,
354: ElementTypes elementType, int x, int y, SetName namer)
355: throws NotFoundException {
356: int old = getAllDiagramElements().size();
357: paletter().selectToolByType(elementType);
358: getDrawingArea().clickMouse(x, y, 1);
359: //check if any element was added
360: try {
361: Thread.sleep(100);
362: } catch (Exception ex) {
363: }
364: for (int i = 0; i < 50 && getAllDiagramElements().size() == old; i++) {
365: try {
366: Thread.sleep(100);
367: } catch (Exception ex) {
368: }
369: }
370: if (old == getAllDiagramElements().size())
371: throw new UMLCommonException(
372: "No new elements appear on diagram in 5 seconds (new "
373: + elementType + " was expected)");
374: //
375: toolbar().selectDefault();
376: try {
377: Thread.sleep(100);
378: } catch (Exception ex) {
379: }
380: if (name != null) {
381: namer.setName(getDrawingArea(), x, y, name);
382: }
383: try {
384: Thread.sleep(100);
385: } catch (Exception ex) {
386: }
387: }
388:
389: /**
390: * Put element on diagram by pressing paletter butoon and clicking on
391: * the diagram
392: * @param name Name for new element
393: * @param elementType Expanded Type of new element
394: * @param x X cooordinate of point where element will be created
395: * @param y Y cooordinate of point where element will be created
396: * @param namer Namer for this element. Certain elements
397: * should be named in very special way
398: * @throws qa.uml.exceptions.NotFoundException
399: */
400: public void createGenericElementOnDiagram(String name,
401: ExpandedElementTypes elementType, int x, int y,
402: SetName namer) throws NotFoundException {
403: int old = getAllDiagramElements().size();
404: paletter().selectToolByType(elementType);
405: getDrawingArea().clickMouse(x, y, 1);
406: //check if any element was added
407: try {
408: Thread.sleep(100);
409: } catch (Exception ex) {
410: }
411: for (int i = 0; i < 50 && getAllDiagramElements().size() == old; i++) {
412: try {
413: Thread.sleep(100);
414: } catch (Exception ex) {
415: }
416: }
417: if (old == getAllDiagramElements().size())
418: throw new UMLCommonException(
419: "No new elements appear on diagram in 5 seconds(new "
420: + elementType + " was expected)");
421: //
422: toolbar().selectDefault();
423: if (name != null) {
424: namer.setName(getDrawingArea(), x, y, name);
425: }
426: }
427:
428: /**
429: *
430: * @param node
431: */
432: public void createGenericElementOnDiagram(Node node) {
433: ProjectsTabOperator pto = ProjectsTabOperator.invoke();
434: Point startPoint = pto.tree().getPointToClick(
435: node.getTreePath());
436: Point endPoint = this .getDrawingArea().getFreePoint(200);
437: //MouseEventDriver evDriver = new MouseEventDriver();
438: MouseDriver driver = new MouseRobotDriver(new Timeout(
439: "autoDelay", 250));
440: //
441: driver.moveMouse(pto.tree(), startPoint.x, startPoint.y);
442: new Timeout("", 500).sleep();
443: driver.pressMouse(pto.tree(), startPoint.x, startPoint.y,
444: InputEvent.BUTTON1_MASK, 0);
445: new Timeout("", 500).sleep();
446: driver.moveMouse(this .getDrawingArea(), endPoint.x, endPoint.y);
447: for (int x = startPoint.x; x < endPoint.x; x += 10)
448: driver.moveMouse(this .getDrawingArea(), x, startPoint.y
449: + (endPoint.y - startPoint.y) * (x - startPoint.x)
450: / (endPoint.x - startPoint.x));
451: driver.moveMouse(this .getDrawingArea(), endPoint.x, endPoint.y);
452: new Timeout("", 500).sleep();
453: driver.releaseMouse(this .getDrawingArea(), endPoint.x,
454: endPoint.y, InputEvent.BUTTON1_MASK, 0);
455: new Timeout("", 500).sleep();
456: }
457:
458: /**
459: * Draw link on diagram
460: * @param linkElementType Link type
461: * @param fromElement Source element
462: * @param toElement target element
463: * @throws qa.uml.exceptions.NotFoundException when source or target is not found
464: * @return Operator for created link
465: */
466: public LinkOperator createLinkOnDiagram(LinkTypes linkElementType,
467: DiagramElementOperator fromElement,
468: DiagramElementOperator toElement) throws NotFoundException {
469: createGenericRelationshipOnDiagram(linkElementType,
470: fromElement, toElement);
471: if (linkElementType.equals(LinkTypes.COMPOSITION)
472: || linkElementType
473: .equals(LinkTypes.NAVIGABLE_COMPOSITION)
474: || linkElementType
475: .equals(LinkTypes.NAVIGABLE_AGGREGATION))
476: linkElementType = LinkTypes.AGGREGATION;
477: else if (linkElementType
478: .equals(LinkTypes.NAVIGABLE_ASSOCIATION))
479: linkElementType = LinkTypes.ASSOCIATION;
480: return new LinkOperator(fromElement, toElement, linkElementType);
481: }
482:
483: /**
484: * Create generic relationship on diagram
485: * @param linkElementType Link type
486: * @param fromElement Source element
487: * @param toElement target element
488: * @throws qa.uml.exceptions.NotFoundException when source or target is not found
489: */
490: public void createGenericRelationshipOnDiagram(
491: LinkTypes linkElementType,
492: DiagramElementOperator fromElement,
493: DiagramElementOperator toElement) throws NotFoundException {
494: paletter().selectToolByType(linkElementType);
495: paletter().waitSelection(linkElementType, true);
496: try {
497: Thread.sleep(100);
498: } catch (Exception ex) {
499: }
500: fromElement.clickOnCenter();
501: new Timeout("", 500).sleep();
502: try {
503: Thread.sleep(100);
504: } catch (Exception ex) {
505: }
506: toElement.clickOnCenter();
507: new Timeout("", 500).sleep();
508: try {
509: Thread.sleep(100);
510: } catch (Exception ex) {
511: }
512: toolbar().selectDefault();
513: //toElement.clickOnCenter(1,InputEvent.BUTTON3_MASK);
514: //paletter().selectToolByType(linkElementType);
515: }
516:
517: /**
518: * Returns all element from this diagram exclude NodePresentation elements
519: * @return all elements from this diagram exclude NodePresentation elements
520: */
521: public ArrayList<DiagramElementOperator> getDiagramElements() {
522: ArrayList<DiagramElementOperator> elements = new ArrayList<DiagramElementOperator>();
523:
524: //searching for elements matching elemenFinder criteria
525: ETList<IETGraphObject> allGraphs = getDrawingAreaControl()
526: .getAllItems6();
527: Iterator<IETGraphObject> tsIt = allGraphs.iterator();
528: while (tsIt.hasNext()) {
529: IETGraphObject graphObject = tsIt.next();
530: IPresentationElement presElement = graphObject
531: .getPresentationElement();
532: if (presElement == null) {
533: continue;
534: }
535: if (!(presElement instanceof NodePresentation)) { //We are looking only for nodes here
536: continue;
537: }
538:
539: elements.add(new DiagramElementOperator(this , graphObject));
540:
541: }
542: return elements;
543:
544: }
545:
546: /**
547: * Returns all element from this diagram
548: * @return all elements from this diagram
549: */
550: public ArrayList<DiagramElementOperator> getAllDiagramElements() {
551: ArrayList<DiagramElementOperator> elements = new ArrayList<DiagramElementOperator>();
552:
553: //searching for elements matching elemenFinder criteria
554: ETList<IETGraphObject> allGraphs = getDrawingAreaControl()
555: .getAllItems6();
556: Iterator<IETGraphObject> tsIt = allGraphs.iterator();
557: while (tsIt.hasNext()) {
558: IETGraphObject graphObject = tsIt.next();
559: IPresentationElement presElement = graphObject
560: .getPresentationElement();
561: if (presElement == null) {
562: continue;
563: }
564:
565: elements.add(new DiagramElementOperator(this , graphObject));
566:
567: }
568: return elements;
569:
570: }
571:
572: /**
573: * Returns if there any selected objects on diagram
574: * @return if there any selected objects on diagram
575: */
576: public boolean getHasSelectedElements() {
577:
578: return getDrawingAreaControl().getHasSelected(true);
579: }
580:
581: /**
582: * Returns if there any selected links on diagram
583: * @return if there any selected links on diagram
584: */
585: public boolean getHasSelectedLinks() {
586:
587: return getDrawingAreaControl().getHasSelectedEdges(true);
588: }
589:
590: /**
591: *
592: * @param name
593: * @return
594: */
595: public DiagramElementOperator getDiagramElement(String name) {
596:
597: for (DiagramElementOperator elem : getDiagramElements()) {
598: if (name.equals(elem.getSubjectVNs().get(0))) {
599: return elem;
600: }
601: }
602:
603: return null;
604: }
605:
606: /**
607: *
608: * @param diagramName
609: * @param diagramType
610: * @param projectNode
611: * @return
612: */
613: public static DiagramOperator createDiagram(String diagramName,
614: DiagramTypes diagramType, Node projectNode) {
615:
616: projectNode.callPopup().pushMenuNoBlock("New|Diagram");
617:
618: NewDiagramWizardOperator wiz = new NewDiagramWizardOperator();
619: wiz.setDiagramType(diagramType.toString());
620: wiz.setDiagramName(diagramName);
621: wiz.clickFinish();
622:
623: return new DiagramOperator(diagramName);
624:
625: }
626:
627: /**
628: * zooms diagram in using 'Zoom In' context menu
629: */
630: public void zoomIn() {
631: this .getDrawingArea().getPopup().pushMenu("Zoom In");
632: }
633:
634: /**
635: * zooms diagram in using 'Zoom Out' context menu
636: */
637: public void zoomOut() {
638: this .getDrawingArea().getPopup().pushMenu("Zoom Out");
639: }
640:
641: /**
642: * Selects diagram zoom percentage using UI.
643: * Invokes 'zoom...' diagram context menu and types specified percent text into opened 'zoom' dialog.
644: * @param ZoomCustomLevel string value to select in Percent ComboBox
645: */
646: public void selectZoomCustom(ZoomCustomLevel percent) {
647: this .getDrawingArea().getPopup().pushMenuNoBlock("Zoom...");
648: JDialogOperator zmdlg = new JDialogOperator("Zoom");
649: JComboBoxOperator percentDlg = new JComboBoxOperator(zmdlg);
650: percentDlg.selectItem(percent.getValue());
651: percentDlg.waitItemSelected(percent.getValue());
652: new JButtonOperator(zmdlg, "OK").push();
653: zmdlg.waitClosed();
654: }
655:
656: public enum ZoomCustomLevel {
657: PERCENT_25("25"), PERCENT_50("50"), PERCENT_100("100"), PERCENT_200(
658: "200"), PERCENT_400("400");
659:
660: private String value = "";
661:
662: private ZoomCustomLevel(String value) {
663: this .value = value;
664: }
665:
666: public String getValue() {
667: return this .value;
668: }
669: }
670:
671: public void waitClosed() {
672: long timeout = 5000;
673: if (getTimeouts().contains("DiagramOperator.WaitClosed"))
674: timeout = getTimeouts().getTimeout(
675: "DiagramOperator.WaitClosed");
676: for (long i = 0; i < timeout; i += 100) {
677: if (drawingArea.getSource().isVisible()) {
678: try {
679: Thread.sleep(100);
680: } catch (InterruptedException ex) {
681: ex.printStackTrace();
682: }
683: } else
684: return;
685: }
686: throw new UMLCommonException(
687: "Diagram/area is still visible after " + timeout
688: + " ms.");
689: }
690:
691: /** Returns TabbedAdapter component from parents hierarchy.
692: */
693: TabbedAdapter findTabbedAdapter() {
694: Component parent = getSource().getParent();
695: while (parent != null) {
696: if (parent instanceof TabbedAdapter) {
697: return (TabbedAdapter) parent;
698: } else {
699: parent = parent.getParent();
700: }
701: }
702: return null;
703: }
704:
705: /** call menu on its tab.
706: */
707: public JPopupMenuOperator callMenuOnTab() {
708: if (isOpened()) {
709: this .makeComponentVisible();
710: TabbedAdapter ta = findTabbedAdapter();
711: int index = ta.indexOf((TopComponent) getSource());
712:
713: Rectangle r = new Rectangle();
714: ta.getTabRect(index, r);
715: Point p = new Point(r.x + (r.width / 2), r.y
716: + (r.height / 2));
717: Component tabsComp = ta.getComponentAt(p);
718: return new JPopupMenuOperator(JPopupMenuOperator.callPopup(
719: tabsComp, p.x, p.y));
720: } else {
721: throw new UMLCommonException(
722: "Attempt to call tab menu on closed diagram.");
723: }
724: }
725:
726: /**
727: * Wait for diagram
728: * @return CompartmentOperator if found
729: * @param comp
730: * @param name diagramName
731: */
732: public static Component waitForDiagram(final String name,
733: final Operator.StringComparator comp) {
734: try {
735: Waiter w = new Waiter(new Waitable() {
736: public Object actionProduced(Object obj) {
737: return findDiagram(name, comp);
738: }
739:
740: public String getDescription() {
741: return ("Wait for a diagram");
742: }
743: });
744:
745: Timeouts t = JemmyProperties.getCurrentTimeouts();
746: t.setTimeout("Waiter.WaitingTime", t
747: .getTimeout("DiagramOperator.WaitDiagramOperator"));
748:
749: return (Component) w.waitAction(null);
750: } catch (InterruptedException ie) {
751: return null;
752: }
753: }
754:
755: /**
756: *
757: * @param name
758: * @param comp
759: * @return
760: */
761: public static Component findDiagram(String name,
762: Operator.StringComparator comp) {
763: //EditorWindowOperator mw = EditorWindowOperator.getEditor();
764: return MainWindowOperator.getDefault().findSubComponent(
765: new DiagramComponentChooser(name, comp));
766: }
767:
768: static class DiagramComponentChooser implements ComponentChooser {
769: String nm = null;
770: Operator.StringComparator cmp = null;
771:
772: /**
773: *
774: * @param name
775: * @param comp
776: */
777: DiagramComponentChooser(String name,
778: Operator.StringComparator comp) {
779: nm = name;
780: cmp = comp;
781: }
782:
783: /**
784: *
785: * @param arg0
786: * @return
787: */
788: public boolean checkComponent(java.awt.Component arg0) {
789: if (arg0 instanceof DiagramTopComponent) {
790: return cmp.equals(arg0.getName(), nm);
791: }
792: return false;
793: }
794:
795: /**
796: *
797: * @return
798: */
799: public String getDescription() {
800: return "Chooser for UML Diagram";
801: }
802: }
803:
804: static class DrawingAreaControlChooser implements ComponentChooser {
805:
806: DrawingAreaControlChooser() {
807:
808: }
809:
810: /*
811: * (non-Javadoc)
812: *
813: * @see org.netbeans.jemmy.ComponentChooser#checkComponent(java.awt.Component)
814: */
815: /**
816: *
817: * @param arg0
818: * @return
819: */
820: public boolean checkComponent(java.awt.Component arg0) {
821: if (arg0 instanceof ADDrawingAreaControl) {
822: return true;
823: }
824: return false;
825: }
826:
827: /*
828: * (non-Javadoc)
829: *
830: * @see org.netbeans.jemmy.ComponentChooser#getDescription()
831: */
832: /**
833: *
834: * @return
835: */
836: public String getDescription() {
837: return "Chooser for UML DrawingArea control";
838: }
839:
840: }
841:
842: class DrawingAreaChooser implements ComponentChooser {
843:
844: DrawingAreaChooser() {
845:
846: }
847:
848: /*
849: * (non-Javadoc)
850: *
851: * @see org.netbeans.jemmy.ComponentChooser#checkComponent(java.awt.Component)
852: */
853: /**
854: *
855: * @param arg0
856: * @return
857: */
858: public boolean checkComponent(java.awt.Component arg0) {
859: if (arg0 instanceof ADGraphWindow) {
860: return true;
861: }
862: return false;
863: }
864:
865: /*
866: * (non-Javadoc)
867: *
868: * @see org.netbeans.jemmy.ComponentChooser#getDescription()
869: */
870: /**
871: *
872: * @return
873: */
874: public String getDescription() {
875: return "Chooser for UML diagram pane";
876: }
877:
878: }
879: }
|