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-2006 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 gui.window;
043:
044: import java.awt.event.KeyEvent;
045: import java.lang.reflect.InvocationTargetException;
046:
047: import javax.swing.SwingUtilities;
048:
049: import org.netbeans.jellytools.Bundle;
050: import org.netbeans.jellytools.NbDialogOperator;
051: import org.netbeans.jellytools.actions.ActionNoBlock;
052: import org.netbeans.jellytools.actions.Action.Shortcut;
053: import org.netbeans.jellytools.properties.Property;
054: import org.netbeans.jellytools.properties.PropertySheetOperator;
055:
056: import org.netbeans.jemmy.JemmyProperties;
057: import org.netbeans.jemmy.operators.JTableOperator;
058:
059: /**
060: * Abstract class for Test of Property Editors.
061: *
062: * @author mmirilovic@netbeans.org
063: */
064: public abstract class PropertyEditors extends
065: org.netbeans.performance.test.utilities.PerformanceTestCase {
066:
067: protected static NbDialogOperator propertiesWindow = null;
068:
069: protected static JTableOperator tableOperator;
070:
071: /** Creates a new instance of ValidatePropertyEditors */
072: public PropertyEditors(String testName) {
073: super (testName);
074: expectedTime = WINDOW_OPEN;
075: }
076:
077: /** Creates a new instance of ValidatePropertyEditors */
078: public PropertyEditors(String testName, String performanceDataName) {
079: super (testName, performanceDataName);
080: expectedTime = WINDOW_OPEN;
081: }
082:
083: public void shutdown() {
084: if (propertiesWindow != null && propertiesWindow.isShowing())
085: propertiesWindow.close();
086: }
087:
088: public void initialize() {
089: propertiesWindow = openPropertySheet();
090: }
091:
092: /** Open property sheet (bean customizer). */
093: protected static NbDialogOperator openPropertySheet() {
094: String waitDialogTimeout = "DialogWaiter.WaitDialogTimeout";
095: long findTimeout = JemmyProperties
096: .getCurrentTimeout(waitDialogTimeout);
097: JemmyProperties.setCurrentTimeout(waitDialogTimeout, 3000);
098:
099: try {
100: propertiesWindow = new NbDialogOperator(Bundle.getString(
101: "org.netbeans.core.Bundle",
102: "CTL_FMT_LocalProperties", new Object[] {
103: new Integer(1), "TestNode" }));
104: } catch (org.netbeans.jemmy.TimeoutExpiredException exception) {
105: try {
106: SwingUtilities.invokeAndWait(new Runnable() {
107: public void run() {
108: new PropertyEditorsTestSheet();
109: }
110: });
111: } catch (InterruptedException ex) {
112: ex.printStackTrace();
113: } catch (InvocationTargetException ex) {
114: ex.printStackTrace();
115: }
116:
117: propertiesWindow = new NbDialogOperator(Bundle.getString(
118: "org.netbeans.core.Bundle",
119: "CTL_FMT_LocalProperties", new Object[] {
120: new Integer(1), "TestNode" }));
121: }
122:
123: JemmyProperties.setCurrentTimeout(waitDialogTimeout,
124: findTimeout);
125:
126: return propertiesWindow;
127: }
128:
129: protected static Property findProperty(String propertyName,
130: NbDialogOperator propertiesWindow) {
131: PropertySheetOperator propertySheet = new PropertySheetOperator(
132: propertiesWindow);
133: Property property = new Property(propertySheet, propertyName);
134:
135: // property.openEditor(); - doesn't work - custom editor is opened without Users Event
136: // hack for invoking Custom Editor by pushing shortcut CTRL+SPACE
137: tableOperator = propertySheet.tblSheet();
138: // Need to request focus before selection because invokeCustomEditor action works
139: // only when table is focused
140: tableOperator.makeComponentVisible();
141: tableOperator.requestFocus();
142: tableOperator.waitHasFocus();
143: // need to select property first
144: ((javax.swing.JTable) tableOperator.getSource())
145: .changeSelection(property.getRow(), 0, false, false);
146: // return new Property(new PropertySheetOperator(propertiesWindow), propertyName);
147: return property;
148: }
149:
150: protected static void openPropertyEditor() {
151: new ActionNoBlock(null, null, new Shortcut(KeyEvent.VK_SPACE,
152: KeyEvent.CTRL_MASK)).perform(tableOperator);
153: }
154:
155: }
|