001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008:
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019:
020: package org.netbeans.test.xslt.lib;
021:
022: import java.awt.Point;
023: import javax.swing.JList;
024: import org.netbeans.jellytools.TopComponentOperator;
025: import org.netbeans.jemmy.operators.JComponentOperator;
026: import org.netbeans.jemmy.operators.JListOperator;
027: import org.netbeans.jemmy.operators.JToggleButtonOperator;
028:
029: /**
030: *
031: * @author ca@netbeans.org
032: */
033:
034: public class PaletteOperator extends TopComponentOperator {
035: public static final String PALETTE_NAME = "Palette";
036:
037: public enum Groups {
038: OPERATOR("Operator"), STRING("String"), NUMBER("Number"), BOOLEAN(
039: "Boolean"), NODES("Nodes");
040:
041: private String val;
042:
043: Groups(String val) {
044: this .val = val;
045: }
046:
047: public String getValue() {
048: return val;
049: }
050: }
051:
052: /** Creates a new instance of PaletteOperator */
053: public PaletteOperator() {
054: super (PALETTE_NAME);
055: }
056:
057: public void expandGroup(Groups group) {
058: JToggleButtonOperator groupBtn = new JToggleButtonOperator(
059: this , group.getValue());
060: if (!groupBtn.isSelected()) {
061: groupBtn.pushNoBlock();
062: groupBtn.waitSelected(true);
063: }
064: }
065:
066: public void collapseGroup(Groups group) {
067: JToggleButtonOperator groupBtn = new JToggleButtonOperator(
068: this , group.getValue());
069: if (groupBtn.isSelected()) {
070: groupBtn.pushNoBlock();
071: groupBtn.waitSelected(false);
072: }
073: }
074:
075: public JListOperator getGroupListOperator(Groups group) {
076: Groups[] groups = Groups.values();
077: JListOperator opList = null;
078:
079: for (int i = 0; i < groups.length; i++) {
080: if (groups[i] == group) {
081: JComponentOperator opComponent = Helpers
082: .getComponentOperator(
083: this ,
084: "org.netbeans.modules.palette.ui.CategoryList",
085: null, i, 200);
086: opList = new JListOperator((JList) opComponent
087: .getSource());
088: break;
089: }
090: }
091:
092: return opList;
093: }
094:
095: public Point prepareNodeForClick(Groups group, String strItem) {
096: expandGroup(group);
097:
098: JListOperator opList = getGroupListOperator(group);
099:
100: int itemIndex = opList
101: .findItemIndex(new PaletteListItemChooser(strItem));
102:
103: opList.ensureIndexIsVisible(itemIndex);
104: Helpers.waitNoEvent();
105:
106: Point p = opList.getClickPoint(itemIndex);
107: return Helpers.getContainerPoint(opList, p, this );
108: }
109:
110: private class PaletteListItemChooser implements
111: JListOperator.ListItemChooser {
112: String itemLabel;
113:
114: public PaletteListItemChooser(String itemLabel) {
115: this .itemLabel = itemLabel;
116: }
117:
118: public boolean checkItem(JListOperator oper, int index) {
119: Object obj = oper.getModel().getElementAt(index);
120: return itemLabel.equals(obj.toString());
121: }
122:
123: public String getDescription() {
124: return ("Item equals to \"" + itemLabel + "\" string");
125: }
126: }
127:
128: }
|