KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > jellytools > modules > java > FixImportsOperator


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.jellytools.modules.java;
21
22 import java.awt.Container JavaDoc;
23 import javax.swing.JDialog JavaDoc;
24 import javax.swing.JLabel JavaDoc;
25 import org.netbeans.jellytools.Bundle;
26 import org.netbeans.jellytools.NbDialogOperator;
27 import org.netbeans.jemmy.operators.JDialogOperator;
28 import org.netbeans.jemmy.operators.JLabelOperator;
29 import org.netbeans.jemmy.operators.JTableOperator;
30
31 /** Class implementing all necessary methods for handling "Fix Imports" NbDialog.
32  *
33  * @author Roman Strobl
34  * @author Jiri Prox
35  * @version 1.0
36  */

37 public class FixImportsOperator extends NbDialogOperator {
38     
39     /** Creates new FixImports that can handle it. */
40     public FixImportsOperator() {
41         super(waitFixImportDialog());
42     }
43
44     private JLabelOperator _lblHtmlTheFollowingClassNamesWereFoundInMoreThanOnePackageSelectTheFullyQualifiedNameToUseInTheImportStatementHtml;
45     private JTableOperator _tabHtmlTheFollowingClassNamesWereFoundInMoreThanOnePackageSelectTheFullyQualifiedNameToUseInTheImportStatementHtml;
46     // "<html>The following class names were found in more than one package. Select the fully qualified name to use in the import statement:</html>"
47
private static final String JavaDoc INTRO_LABEL = Bundle.getString("org.netbeans.modules.editor.java.Bundle", "FixDupImportStmts_IntroLbl");
48     // "Fix Imports"
49
//private static final String TITLE = Bundle.getString("org.netbeans.modules.editor.java.Bundle", "FixDuplicateImports_dlgTitle");
50
private static final String JavaDoc TITLE = "Fix All Imports";
51     /** Progress dialog with the same title can be found first. Then we have to check whether
52      * it contains correct label and if not wait for next dialog.
53      */

54     private static JDialog JavaDoc waitFixImportDialog() {
55         JDialogOperator candidate = new JDialogOperator(TITLE);
56         JLabel JavaDoc introLabel = JLabelOperator.findJLabel((Container JavaDoc)candidate.getSource(), INTRO_LABEL, true, true);
57         if(introLabel == null) {
58             candidate.waitClosed();
59             candidate = new JDialogOperator(TITLE);
60         }
61         return (JDialog JavaDoc)candidate.getSource();
62     }
63     
64     //******************************
65
// Subcomponents definition part
66
//******************************
67

68     /** Tries to find "<html>The following class names were found in more than one package. Select the fully qualified name to use in the import statement:</html>" JLabel in this dialog.
69      * @return JLabelOperator
70      */

71     public JLabelOperator lblHtmlTheFollowingClassNamesWereFoundInMoreThanOnePackageSelectTheFullyQualifiedNameToUseInTheImportStatementHtml() {
72         if (_lblHtmlTheFollowingClassNamesWereFoundInMoreThanOnePackageSelectTheFullyQualifiedNameToUseInTheImportStatementHtml==null) {
73             _lblHtmlTheFollowingClassNamesWereFoundInMoreThanOnePackageSelectTheFullyQualifiedNameToUseInTheImportStatementHtml = new JLabelOperator(this, INTRO_LABEL);
74         }
75         return _lblHtmlTheFollowingClassNamesWereFoundInMoreThanOnePackageSelectTheFullyQualifiedNameToUseInTheImportStatementHtml;
76     }
77
78     /** Tries to find null FixDuplicateImportStmts$JTableX in this dialog.
79      * @return JTableOperator
80      */

81     public JTableOperator tabHtmlTheFollowingClassNamesWereFoundInMoreThanOnePackageSelectTheFullyQualifiedNameToUseInTheImportStatementHtml() {
82         if (_tabHtmlTheFollowingClassNamesWereFoundInMoreThanOnePackageSelectTheFullyQualifiedNameToUseInTheImportStatementHtml==null) {
83             _tabHtmlTheFollowingClassNamesWereFoundInMoreThanOnePackageSelectTheFullyQualifiedNameToUseInTheImportStatementHtml = new JTableOperator(this);
84         }
85         return _tabHtmlTheFollowingClassNamesWereFoundInMoreThanOnePackageSelectTheFullyQualifiedNameToUseInTheImportStatementHtml;
86     }
87
88
89     //*****************************************
90
// High-level functionality definition part
91
//*****************************************
92

93     /** Performs verification of FixImports by accessing all its components.
94      */

95     public void verify() {
96         lblHtmlTheFollowingClassNamesWereFoundInMoreThanOnePackageSelectTheFullyQualifiedNameToUseInTheImportStatementHtml();
97         tabHtmlTheFollowingClassNamesWereFoundInMoreThanOnePackageSelectTheFullyQualifiedNameToUseInTheImportStatementHtml();
98         btOK();
99         btCancel();
100     }
101
102     /** Performs simple test of FixImports
103     * @param args the command line arguments
104     */

105     public static void main(String JavaDoc args[]) {
106         new FixImportsOperator().verify();
107         System.out.println("FixImports verification finished.");
108     }
109 }
110
111
Popular Tags