KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > refactoring > experimental > ui > IntroduceVariableRefactoringUI


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.experimental.ui;
20 import org.netbeans.jmi.javamodel.ArrayAccess;
21 import org.netbeans.jmi.javamodel.Element;
22 import org.netbeans.jmi.javamodel.Expression;
23 import org.netbeans.jmi.javamodel.JavaModelPackage;
24 import org.netbeans.jmi.javamodel.Type;
25 import org.netbeans.modules.refactoring.spi.ui.CustomRefactoringPanel;
26 import org.netbeans.modules.refactoring.spi.ui.RefactoringUI;
27 import org.netbeans.modules.refactoring.experimental.IntroduceVariableRefactoring;
28 import org.openide.util.HelpCtx;
29 import org.openide.util.NbBundle;
30
31 /**
32  *
33  * @author Daniel Prusa
34  */

35 public class IntroduceVariableRefactoringUI implements RefactoringUI {
36     private final IntroduceVariableRefactoring refactoring;
37     private Expression expression;
38     private IntroduceVariablePanel panel;
39
40     public IntroduceVariableRefactoringUI(Element element, int startOffset, int endOffset) {
41         refactoring = new IntroduceVariableRefactoring(element, startOffset, endOffset);
42         this.expression = refactoring.getExpression();
43     }
44
45     public boolean isQuery() {
46         return false;
47     }
48
49     public CustomRefactoringPanel getPanel(org.netbeans.modules.refactoring.spi.ui.ParametersPanel parent) {
50         if (panel == null) {
51             Type[] types;
52             if (expression != null) {
53                 Type type = null;
54                 if (expression instanceof ArrayAccess) { // [TODO] this is workaroung, getType() should work
55
type = ((org.netbeans.jmi.javamodel.Array)((ArrayAccess) expression).getArray().getType()).getType();
56                 } else {
57                     type = expression.getType();
58                 }
59                 if (type == null) {
60                     JavaModelPackage pkg = (JavaModelPackage) expression.refOutermostPackage();
61                     type = pkg.getType().resolve("java.lang.Object"); // NOI18N
62
}
63                 types = new Type[] {type};
64             } else {
65                 types = new Type[0];
66             }
67             panel = new IntroduceVariablePanel(parent, "lokalek", types); // [TODO] // NOI18N
68
}
69         return panel;
70     }
71
72     public org.netbeans.modules.refactoring.api.Problem setParameters() {
73         refactoring.setVariableName(panel.getVariableName());
74         refactoring.setFinal(panel.declareFinal());
75         refactoring.setReplaceAll(panel.replaceAllOccurrences());
76         refactoring.setVariableType(panel.getVariableType());
77         return refactoring.checkParameters();
78     }
79     
80     public org.netbeans.modules.refactoring.api.Problem checkParameters() {
81         /*
82         newName = panel.getNameValue();
83         if (refactoring instanceof RenameRefactoring) {
84             ((RenameRefactoring) refactoring).setNewName(newName);
85         } else {
86             ((MoveClassRefactoring) refactoring).setNewPackageName(newName);
87         }
88          */

89         refactoring.setVariableName(panel.getVariableName());
90         refactoring.setFinal(panel.declareFinal());
91         refactoring.setReplaceAll(panel.replaceAllOccurrences());
92         refactoring.setVariableType(panel.getVariableType());
93         return refactoring.fastCheckParameters();
94     }
95
96     public org.netbeans.modules.refactoring.api.AbstractRefactoring getRefactoring() {
97         return refactoring;
98     }
99
100     public String JavaDoc getDescription() {
101         return ""; // NOI18N [TODO]
102
/*
103         return new MessageFormat(NbBundle.getMessage(IntroduceVariableAction.class, "DSC_IntroduceVariable")).format (
104                     new Object[] {dispOldName, newName}
105                 );
106          */

107     }
108
109     public String JavaDoc getName() {
110         return NbBundle.getMessage(IntroduceVariableAction.class, "LBL_IntroduceVariable");
111     }
112
113     public boolean hasParameters() {
114         return true;
115     }
116
117     public HelpCtx getHelpCtx() {
118         return new HelpCtx(IntroduceVariableRefactoringUI.class.getName());
119     }
120 }
121
Popular Tags