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: package org.netbeans.modules.visualweb.gravy.properties;
043:
044: import java.awt.Component;
045: import java.awt.Container;
046: import javax.swing.JComponent;
047: import javax.swing.JTabbedPane;
048: import org.netbeans.jellytools.Bundle;
049: import org.netbeans.jemmy.ComponentChooser;
050: import org.netbeans.jemmy.ComponentSearcher;
051: import org.netbeans.jemmy.JemmyException;
052: import org.netbeans.jemmy.JemmyProperties;
053: import org.netbeans.jemmy.TestOut;
054: import org.netbeans.jemmy.Waitable;
055: import org.netbeans.jemmy.Waiter;
056: import org.netbeans.jemmy.operators.ContainerOperator;
057: import org.netbeans.jemmy.operators.JComponentOperator;
058: import org.netbeans.jemmy.operators.JTabbedPaneOperator;
059:
060: /**
061: * Handles org.openide.explorer.propertysheet.PropertySheetTab which
062: * represents a single tab of properties in a IDE property sheet.
063: * PropertySheetTab extends JPanel in IDE.
064: * <p>
065: * Usage:<br>
066: * <pre>
067: * PropertySheetOperator pso = new PropertySheetOperator("Properties of MyClass");
068: * PropertySheetTabOperator psto = new PropertySheetTabOperator(pso);
069: * Property pr = new Property(psto, "Template");
070: * System.out.println("\nProperty name="+pr.getName());
071: * System.out.println("\nProperty value="+pr.getValue());
072: * PropertySheetTabOperator psto = new PropertySheetTabOperator(pso, "Other Properties");
073: * </pre>
074: *
075: * @deprecated Use {@link PropertySheetOperator} instead
076: */
077: public class PropertySheetTabOperator extends ContainerOperator {//JComponentOperator {
078:
079: /** Waits for PropertySheetTab with given name in specified container. If tab
080: * exist and it is not active, it selects it.
081: * @param contOper where to find
082: * @param tabName name of tab
083: * @deprecated Use {@link PropertySheetOperator} instead
084: */
085: public PropertySheetTabOperator(ContainerOperator contOper,
086: String tabName) {
087: super (resolveParent(contOper));
088: //super(contOper.getParent());
089: //super((Container)contOper.getSource());
090: /*super(waitPropertySheetTab(contOper, tabName));
091: copyEnvironment(contOper);*/
092: }
093:
094: /** Waits for PropertySheetTab with name "Properties" in specified container.
095: * If tab exist and it is not active, it selects it.
096: * @param contOper where to find
097: * @deprecated Use {@link PropertySheetOperator} instead
098: */
099: public PropertySheetTabOperator(ContainerOperator contOper) {
100: super (resolveParent(contOper));
101: //super(contOper.getParent());
102: //super((Container)contOper.getSource());
103: /*super(waitPropertySheetTab(contOper,
104: Bundle.getString("org.openide.nodes.Bundle", "Properties")));
105: copyEnvironment(contOper);*/
106: }
107:
108: /** In case contOper is operator of PropertySheet instance we need to
109: * return parent because in Property we search for PropertySheet in that
110: * parent.
111: */
112: private static Container resolveParent(ContainerOperator contOper) {
113: if (contOper.getParent() == null) {
114: return (Container) contOper.getSource();
115: } else {
116: return contOper.getParent();
117: }
118: }
119:
120: /** Finds org.openide.explorer.propertysheet.PropertySheetTab in given
121: * container. On its parent (JTabbedPane) find a pane with given tabName
122: * and select that tab.
123: * @return JComponent representing PropertySheetTab, null if not found.
124: */
125: private static JComponent findPropertySheetTab(
126: ContainerOperator contOper, String tabName) {
127: ComponentChooser chooser = new PropertySheetTabChooser();
128: ComponentSearcher searcher = new ComponentSearcher(
129: (Container) contOper.getSource());
130: searcher.setOutput(TestOut.getNullOutput());
131: Component comp = searcher.findComponent(chooser);
132: if (comp == null) {
133: return null;
134: }
135: JTabbedPaneOperator tabbed = new JTabbedPaneOperator(
136: (JTabbedPane) comp.getParent());
137: int count = tabbed.getTabCount();
138: for (int i = 0; i < count; i++) {
139: if (contOper.getComparator().equals(tabbed.getTitleAt(i),
140: tabName)) {
141: tabbed.selectPage(i);
142: return (JComponent) tabbed.getSelectedComponent();
143: }
144: }
145: return null;
146: }
147:
148: /** Waits for PropertySheetTab.
149: * @see #findPropertySheetTab()
150: */
151: private static JComponent waitPropertySheetTab(
152: final ContainerOperator contOper, final String tabName) {
153: try {
154: Waiter waiter = new Waiter(new Waitable() {
155: public Object actionProduced(Object obj) {
156: return findPropertySheetTab(contOper, tabName);
157: }
158:
159: public String getDescription() {
160: return ("Wait PropertySheetTab \"" + tabName + "\".");
161: }
162: });
163: waiter.setOutput(JemmyProperties.getCurrentOutput());
164: return ((JComponent) waiter.waitAction(null));
165: } catch (InterruptedException e) {
166: throw new JemmyException(
167: "Interrupted waiting for PropertySheetTab");
168: }
169: }
170:
171: /** Chooser to find any instance of
172: * org.openide.explorer.propertysheet.PropertySheetTab.
173: */
174: private static class PropertySheetTabChooser implements
175: ComponentChooser {
176: public PropertySheetTabChooser() {
177: }
178:
179: public boolean checkComponent(Component comp) {
180: return comp.getClass().getName().equals(
181: "org.openide.explorer.propertysheet.SheetTable");
182: }
183:
184: public String getDescription() {
185: return "SheetTable";
186: }
187: }
188:
189: /** Count number of properties on the tab.
190: * @return number or properties
191: * @deprecated Use {@link PropertySheetOperator} instead
192: */
193: public int getCount() {
194: throw new JemmyException(
195: "Don't use this! No JTabbedPane is used in property sheet.");
196: /*// Trying to find non sense name it goes through all properties and
197: // returned index represents the count.
198: SheetButtonOperator.SheetButtonChooser chooser =
199: new SheetButtonOperator.SheetButtonChooser("Nonsense name @#$%^&", getComparator());
200: findComponent((Container)getSource(), chooser);
201: return chooser.getIndex()+1;*/
202: }
203: }
|