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: * Portions Copyrighted 2007 Sun Microsystems, Inc.
027: */
028: package org.netbeans.jellytools.modules.java;
029:
030: import java.awt.Container;
031: import java.util.HashMap;
032: import java.util.Map;
033: import javax.swing.JDialog;
034: import javax.swing.JLabel;
035: import org.netbeans.jemmy.operators.*;
036: import org.netbeans.jemmy.util.NameComponentChooser;
037:
038: /** Class implementing all necessary methods for handling "Fix All Imports" NbDialog.
039: *
040: * @author Jiri Prox Jiri.Prox@Sun.COM
041: * @version 1.0
042: */
043: public class FixAllImports extends JDialogOperator {
044:
045: /** Creates new FixAllImports that can handle it.
046: */
047: public FixAllImports() {
048: super (waitFixImportDialog());
049: }
050:
051: private static JDialog waitFixImportDialog() {
052: JDialogOperator candidate = new JDialogOperator(TITLE);
053: return (JDialog) candidate.getSource();
054: }
055:
056: public static final String TITLE = "Fix All Imports";
057: private JLabelOperator _lblHtmlSelectTheFullyQualifiedNameToUseInTheImportStatementHtml;
058: private JComboBoxOperator _cbo;
059: public static final String ITEM_COMSUNXMLINTERNALBINDV2SCHEMAGENXMLSCHEMALIST = "com.sun.xml.internal.bind.v2.schemagen.xmlschema.List";
060: public static final String ITEM_JAVAAWTLIST = "java.awt.List";
061: public static final String ITEM_JAVAUTILLIST = "java.util.List";
062: private JLabelOperator _lblVector;
063: private JComboBoxOperator _cboVector;
064: public static final String ITEM_JAVAUTILVECTOR = "java.util.Vector";
065: private JButtonOperator _btMetalScrollButton;
066: private JButtonOperator _btMetalScrollButton2;
067: private JButtonOperator _btMetalScrollButton3;
068: private JButtonOperator _btMetalScrollButton4;
069: private JCheckBoxOperator _cbRemoveUnusedImports;
070: private JLabelOperator _lblImportStatements;
071: private JButtonOperator _btOK;
072: private JButtonOperator _btCancel;
073: private JLabelOperator _lblNothingToFix;
074:
075: //******************************
076: // Subcomponents definition part
077: //******************************
078:
079: /** Tries to find "<html>Select the fully qualified name to use in the import statement.</html>" JLabel in this dialog.
080: * @return JLabelOperator
081: */
082: public JLabelOperator lblHtmlSelectTheFullyQualifiedNameToUseInTheImportStatementHtml() {
083: if (_lblHtmlSelectTheFullyQualifiedNameToUseInTheImportStatementHtml == null) {
084: _lblHtmlSelectTheFullyQualifiedNameToUseInTheImportStatementHtml = new JLabelOperator(
085: this ,
086: "<html>Select the fully qualified name to use in the import statement.</html>");
087: }
088: return _lblHtmlSelectTheFullyQualifiedNameToUseInTheImportStatementHtml;
089: }
090:
091: /** Tries to find null JComboBox in this dialog.
092: * @return JComboBoxOperator
093: */
094:
095: private Map<Integer, JComboBoxOperator> operators = new HashMap<Integer, JComboBoxOperator>();
096:
097: public JComboBoxOperator cbo(int index) {
098: Integer i = new Integer(index);
099: JComboBoxOperator _cbo = operators.get(i);
100: if (_cbo == null) {
101: _cbo = new JComboBoxOperator(this , index);
102: operators.put(i, _cbo);
103: }
104: return _cbo;
105: }
106:
107: public JComboBoxOperator get(int key) {
108: return operators.get(key);
109: }
110:
111: private Map<Integer, JLabelOperator> labelOperators = new HashMap<Integer, JLabelOperator>();
112:
113: public JLabelOperator lo(int index) {
114: Integer i = new Integer(index);
115: JLabelOperator _lo = labelOperators.get(i);
116: if (_lo == null) {
117: _lo = new JLabelOperator(this , index + 2);
118: labelOperators.put(i, _lo);
119: }
120: return _lo;
121: }
122:
123: public JLabelOperator getLo(int key) {
124: return labelOperators.get(key);
125: }
126:
127: /** Tries to find "Remove unused imports" JCheckBox in this dialog.
128: * @return JCheckBoxOperator
129: */
130: public JCheckBoxOperator cbRemoveUnusedImports() {
131: if (_cbRemoveUnusedImports == null) {
132: _cbRemoveUnusedImports = new JCheckBoxOperator(this ,
133: "Remove unused imports");
134: }
135: return _cbRemoveUnusedImports;
136: }
137:
138: /** Tries to find "Import Statements:" JLabel in this dialog.
139: * @return JLabelOperator
140: */
141: public JLabelOperator lblImportStatements() {
142: if (_lblImportStatements == null) {
143: _lblImportStatements = new JLabelOperator(this ,
144: "Import Statements:");
145: }
146: return _lblImportStatements;
147: }
148:
149: public JLabelOperator lblNothingToFix() {
150: if (_lblNothingToFix == null) {
151: _lblNothingToFix = new JLabelOperator(this ,
152: "<nothing to fix>");
153: }
154: return _lblNothingToFix;
155: }
156:
157: /** Tries to find "OK" JButton in this dialog.
158: * @return JButtonOperator
159: */
160: public JButtonOperator btOK() {
161: if (_btOK == null) {
162: _btOK = new JButtonOperator(this , "OK");
163: }
164: return _btOK;
165: }
166:
167: /** Tries to find "Cancel" JButton in this dialog.
168: * @return JButtonOperator
169: */
170: public JButtonOperator btCancel() {
171: if (_btCancel == null) {
172: _btCancel = new JButtonOperator(this , "Cancel");
173: }
174: return _btCancel;
175: }
176:
177: //****************************************
178: // Low-level functionality definition part
179: //****************************************
180:
181: /** returns selected item for cboList
182: * @return String item
183: */
184: public String getSelectedList(int index) {
185: return cbo(index).getSelectedItem().toString();
186: }
187:
188: /** checks or unchecks given JCheckBox
189: * @param state boolean requested state
190: */
191: public void checkRemoveUnusedImports(boolean state) {
192: if (cbRemoveUnusedImports().isSelected() != state) {
193: cbRemoveUnusedImports().push();
194: }
195: }
196:
197: /** clicks on "OK" JButton
198: */
199: public void ok() {
200: btOK().push();
201: }
202:
203: /** clicks on "Cancel" JButton
204: */
205: public void cancel() {
206: btCancel().push();
207: }
208:
209: //*****************************************
210: // High-level functionality definition part
211: //*****************************************
212:
213: /** Performs verification of FixAllImports by accessing all its components.
214: */
215: public void verify() {
216: lblHtmlSelectTheFullyQualifiedNameToUseInTheImportStatementHtml();
217: cbRemoveUnusedImports();
218: lblImportStatements();
219: btOK();
220: btCancel();
221: }
222:
223: /** Performs simple test of FixAllImports
224: * @param args the command line arguments
225: */
226: public static void main(String args[]) {
227: new FixAllImports().verify();
228: System.out.println("FixAllImports verification finished.");
229: }
230: }
|