KickJava   Java API By Example, From Geeks To Geeks.

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


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.modules.refactoring.java.ui;
21
22 import java.text.MessageFormat JavaDoc;
23 import java.util.Arrays JavaDoc;
24 import java.util.ResourceBundle JavaDoc;
25 import javax.swing.event.ChangeListener JavaDoc;
26 import org.netbeans.api.java.source.CompilationInfo;
27 import org.netbeans.api.java.source.TreePathHandle;
28 import org.netbeans.modules.refactoring.api.AbstractRefactoring;
29 import org.netbeans.modules.refactoring.api.Problem;
30 import org.netbeans.modules.refactoring.api.SafeDeleteRefactoring;
31 import org.netbeans.modules.refactoring.spi.ui.CustomRefactoringPanel;
32 import org.netbeans.modules.refactoring.spi.ui.RefactoringUI;
33 import org.openide.filesystems.FileObject;
34 import org.openide.util.HelpCtx;
35 import org.openide.util.NbBundle;
36 import org.openide.util.lookup.Lookups;
37
38 /**
39  * A CustomRefactoringUI subclass that represents Safe Delete
40  * @author Bharath Ravikumar
41  */

42 public class SafeDeleteUI implements RefactoringUI{
43     
44     private final Object JavaDoc[] elementsToDelete;
45     
46     private final SafeDeleteRefactoring refactoring;
47     
48     private SafeDeletePanel panel;
49     
50     private ResourceBundle JavaDoc bundle;
51     
52     /**
53      * Creates a new instance of SafeDeleteUI
54      * @param selectedElements An array of selected Elements that need to be
55      * safely deleted
56      */

57     public SafeDeleteUI(FileObject[] selectedElements) {
58         this.elementsToDelete = selectedElements;
59         refactoring = new SafeDeleteRefactoring(Lookups.fixed(elementsToDelete));
60     }
61
62     /**
63      * Creates a new instance of SafeDeleteUI
64      * @param selectedElements An array of selected Elements that need to be
65      * safely deleted
66      */

67     public SafeDeleteUI(TreePathHandle[] selectedElements, CompilationInfo info) {
68         this.elementsToDelete = selectedElements;
69         refactoring = new SafeDeleteRefactoring(Lookups.fixed(elementsToDelete));
70         refactoring.getContext().add(info.getClasspathInfo());
71     }
72     
73     /**
74      * Delegates to the fastCheckParameters of the underlying
75      * refactoring
76      * @return Returns the result of fastCheckParameters of the
77      * underlying refactoring
78      */

79     public org.netbeans.modules.refactoring.api.Problem checkParameters() {
80         refactoring.setCheckInComments(panel.isSearchInComments());
81         return refactoring.fastCheckParameters();
82     }
83     
84     public String JavaDoc getDescription() {
85         //TODO: Check bounds here. Might throw an OutofBoundsException otherwise.
86
// if (elementsToDelete[0] instanceof JavaClass) {
87
// return getString("DSC_SafeDelClasses", elementsToDelete);// NOI18N
88
// } else {
89
// if (elementsToDelete[0] instanceof ExecutableElement) {
90
// if (elementsToDelete.length > 1)
91
// return getString("DSC_SafeDelMethods");// NOI18N
92
// else
93
// return getString("DSC_SafeDelMethod", elementsToDelete[0]);// NOI18N
94
// }
95
//
96
// }
97
// if(elementsToDelete[0] instanceof Resource){
98
// return NbBundle.getMessage(SafeDeleteUI.class, "DSC_SafeDel",
99
// ((Resource)elementsToDelete[0]).getName()); // NOI18N
100
// }
101
return NbBundle.getMessage(SafeDeleteUI.class, "DSC_SafeDel", elementsToDelete); // NOI18N
102
}
103     
104     public org.openide.util.HelpCtx getHelpCtx() {
105         
106         return new HelpCtx(SafeDeleteUI.class.getName());
107     }
108     
109     public String JavaDoc getName() {
110         
111         return NbBundle.getMessage(SafeDeleteUI.class, "LBL_SafeDel"); // NOI18N
112
}
113     
114     public CustomRefactoringPanel getPanel(ChangeListener JavaDoc parent) {
115         //TODO:Do you want to just use Arrays.asList?
116
if(panel == null)
117             panel = new SafeDeletePanel(refactoring, Arrays.asList(elementsToDelete));
118         return panel;
119     }
120     
121     public AbstractRefactoring getRefactoring() {
122         
123         return refactoring;
124     }
125     
126     public boolean hasParameters() {
127         
128         return true;
129     }
130     /**
131      * Returns false, since this refactoring is not a query.
132      * @return false
133      */

134     public boolean isQuery() {
135         return false;
136     }
137     
138     public Problem setParameters() {
139         refactoring.setCheckInComments(panel.isSearchInComments());
140         return refactoring.checkParameters();
141     }
142     
143     //Helper methods------------------
144

145     private String JavaDoc getString(String JavaDoc key) {
146         if (bundle == null) {
147             bundle = NbBundle.getBundle(SafeDeleteUI.class);
148         }
149         return bundle.getString(key);
150     }
151     
152     private String JavaDoc getString(String JavaDoc key, Object JavaDoc value) {
153         return new MessageFormat JavaDoc(getString(key)).format(new Object JavaDoc[] {value});
154     }
155     
156     
157 }
158
Popular Tags