KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > refactoring > java > ui > ExtractInterfaceRefactoringUI


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 package org.netbeans.modules.refactoring.java.ui;
20
21 import java.util.Iterator JavaDoc;
22 import javax.swing.event.ChangeListener JavaDoc;
23 import org.netbeans.api.java.source.CompilationInfo;
24 import org.netbeans.api.java.source.TreePathHandle;
25 import org.netbeans.modules.refactoring.api.AbstractRefactoring;
26 import org.netbeans.modules.refactoring.api.Problem;
27 import org.netbeans.modules.refactoring.java.api.ExtractInterfaceRefactoring;
28 import org.netbeans.modules.refactoring.java.ui.ExtractInterfaceAction;
29 import org.netbeans.modules.refactoring.java.ui.ExtractInterfacePanel;
30 import org.netbeans.modules.refactoring.spi.ui.CustomRefactoringPanel;
31 import org.netbeans.modules.refactoring.spi.ui.RefactoringUI;
32 import org.openide.util.HelpCtx;
33 import org.openide.util.NbBundle;
34
35 /** Refactoring UI object for Extract Interface refactoring.
36  *
37  * @author Martin Matula, Jan Becicka
38  */

39 public class ExtractInterfaceRefactoringUI implements RefactoringUI {
40     // reference to extract interface refactoring this UI object corresponds to
41
private final ExtractInterfaceRefactoring refactoring;
42     // source type
43
private final TreePathHandle sourceType;
44     // UI panel for collecting parameters
45
private ExtractInterfacePanel panel;
46     
47     /** Creates a new instance of ExtractInterfaceRefactoringUI
48      * @param selectedElements Elements the refactoring action was invoked on.
49      */

50     public ExtractInterfaceRefactoringUI(TreePathHandle selectedElement, CompilationInfo info) {
51         // compute source type
52
//sourceType = getSourceType(selectedElement);
53
sourceType = selectedElement;
54         // create an instance of pull up refactoring object
55
refactoring = new ExtractInterfaceRefactoring(sourceType);
56     }
57     
58     // --- IMPLEMENTATION OF RefactoringUI INTERFACE ---------------------------
59

60     public boolean isQuery() {
61         return false;
62     }
63
64     public CustomRefactoringPanel getPanel(ChangeListener JavaDoc parent) {
65         if (panel == null) {
66             panel = new ExtractInterfacePanel(refactoring, parent);
67         }
68         return panel;
69     }
70
71     public Problem setParameters() {
72         //TODO:
73
//captureParameters();
74
return refactoring.checkParameters();
75     }
76     
77     public Problem checkParameters() {
78         //TODO:
79
//captureParameters();
80
return refactoring.fastCheckParameters();
81     }
82
83     public AbstractRefactoring getRefactoring() {
84         return refactoring;
85     }
86
87     public String JavaDoc getDescription() {
88         return NbBundle.getMessage(ExtractInterfaceAction.class, "DSC_ExtractInterface", "TODO: getName()"/* sourceType.getName()*/); // NOI18N
89
}
90
91     public String JavaDoc getName() {
92         return NbBundle.getMessage(ExtractInterfaceAction.class, "LBL_ExtractInterface"); // NOI18N
93
}
94
95     public boolean hasParameters() {
96         return true;
97     }
98
99     public HelpCtx getHelpCtx() {
100         return new HelpCtx(ExtractInterfaceRefactoringUI.class.getName());
101     }
102     
103     // --- PRIVATE HELPER METHODS ----------------------------------------------
104

105 // /** Gets parameters from the refactoring panel and sets them
106
// * to the refactoring object.
107
// */
108
// private void captureParameters() {
109
// refactoring.setIfcName(panel.getIfcName());
110
// refactoring.setMembers(panel.getMembers());
111
// }
112
//
113
// static TreePathHandle getSourceType(TreePathHandle element) {
114
// JavaClass result = null;
115
// // iterate through the containers of the element (until we get to null
116
// // or a resource)
117
// while (element != null && !(element instanceof Resource)) {
118
// if (element instanceof JavaClass) {
119
// result = (JavaClass) element;
120
// break;
121
// }
122
// element = (Element) element.refImmediateComposite();
123
// }
124
// if (result == null && element instanceof Resource) {
125
// String name = ((Resource) element).getName();
126
// int start = name.lastIndexOf('/') + 1;
127
// int end = name.indexOf('.', start);
128
// if (end < 0) end = name.length();
129
// name = name.substring(start, end);
130
// for (Iterator it = ((Resource) element).getClassifiers().iterator(); it.hasNext();) {
131
// JavaClass cls = (JavaClass) it.next();
132
// result = cls;
133
// // if the class of a same name is found, exit the loop
134
// if (name.equals(cls.getSimpleName())) break;
135
// }
136
// // if no class of the same name is found, then the last class in
137
// // the resource is taken as the selected one
138
// }
139
// return result;
140
// }
141
}
Popular Tags