KickJava   Java API By Example, From Geeks To Geeks.

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

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

53     public SafeDeleteUI(T[] selectedElements) {
54         this.elementsToDelete = selectedElements;
55         refactoring = new SafeDeleteRefactoring(Lookups.fixed(elementsToDelete));
56     }
57     
58     /**
59      * Delegates to the fastCheckParameters of the underlying
60      * refactoring
61      * @return Returns the result of fastCheckParameters of the
62      * underlying refactoring
63      */

64     public org.netbeans.modules.refactoring.api.Problem checkParameters() {
65         //refactoring.setCheckInComments(panel.isSearchInComments());
66
return refactoring.fastCheckParameters();
67     }
68     
69     public String JavaDoc getDescription() {
70         //TODO: Check bounds here. Might throw an OutofBoundsException otherwise.
71
// if (elementsToDelete[0] instanceof JavaClass) {
72
// return getString("DSC_SafeDelClasses", elementsToDelete);// NOI18N
73
// } else {
74
// if (elementsToDelete[0] instanceof Method) {
75
// if (elementsToDelete.length > 1)
76
// return getString("DSC_SafeDelMethods");// NOI18N
77
// else
78
// return getString("DSC_SafeDelMethod", elementsToDelete[0]);// NOI18N
79
// }
80
//
81
// }
82
// if(elementsToDelete[0] instanceof Resource){
83
// return NbBundle.getMessage(SafeDeleteUI.class, "DSC_SafeDel",
84
// ((Resource)elementsToDelete[0]).getName()); // NOI18N
85
// }
86
// return NbBundle.getMessage(SafeDeleteUI.class, "DSC_SafeDel", elementsToDelete); // NOI18N
87
return "Safe Delete";
88     }
89     
90     public org.openide.util.HelpCtx getHelpCtx() {
91         
92         return new HelpCtx(SafeDeleteUI.class.getName());
93     }
94     
95     public String JavaDoc getName() {
96         
97         return NbBundle.getMessage(SafeDeleteUI.class, "LBL_SafeDel"); // NOI18N
98
}
99     
100     public CustomRefactoringPanel getPanel(ChangeListener JavaDoc parent) {
101         //TODO:Do you want to just use Arrays.asList?
102
if(panel == null)
103             panel = new SafeDeletePanel();
104         return panel;
105     }
106     
107     public AbstractRefactoring getRefactoring() {
108         
109         return refactoring;
110     }
111     
112     public boolean hasParameters() {
113         
114         return false;
115     }
116     /**
117      * Returns false, since this refactoring is not a query.
118      * @return false
119      */

120     public boolean isQuery() {
121         return false;
122     }
123     
124     public Problem setParameters() {
125         //refactoring.setCheckInComments(panel.isSearchInComments());
126
return refactoring.checkParameters();
127     }
128     
129     //Helper methods------------------
130

131     private String JavaDoc getString(String JavaDoc key) {
132         if (bundle == null) {
133             bundle = NbBundle.getBundle(SafeDeleteUI.class);
134         }
135         return bundle.getString(key);
136     }
137     
138     private String JavaDoc getString(String JavaDoc key, Object JavaDoc value) {
139         return new MessageFormat JavaDoc(getString(key)).format(new Object JavaDoc[] {value});
140     }
141     
142     
143 }
144
Popular Tags