KickJava   Java API By Example, From Geeks To Geeks.

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


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.JavaClass;
21 import org.netbeans.jmi.javamodel.Resource;
22 import org.netbeans.modules.javacore.api.JavaModel;
23 import org.netbeans.modules.refactoring.api.AbstractRefactoring;
24 import org.netbeans.modules.refactoring.api.Problem;
25 import org.netbeans.modules.refactoring.experimental.CopyClassRefactoring;
26 import org.netbeans.modules.refactoring.spi.ui.CustomRefactoringPanel;
27 import org.netbeans.modules.refactoring.spi.ui.ParametersPanel;
28 import org.netbeans.modules.refactoring.spi.ui.RefactoringUI;
29 import org.netbeans.modules.refactoring.ui.PullUpRefactoringUI;
30 import org.openide.util.HelpCtx;
31 import org.openide.util.NbBundle;
32
33 /** Refactoring UI object for Copy Class refactoring.
34  *
35  * @author Jan Becicka
36  */

37 public class CopyClassRefactoringUI implements RefactoringUI {
38     // reference to pull up refactoring this UI object corresponds to
39
private final CopyClassRefactoring refactoring;
40     // UI panel for collecting parameters
41
private CopyClassPanel panel;
42     
43     public CopyClassRefactoringUI(Resource resource) {
44         refactoring = new CopyClassRefactoring(resource);
45     }
46     
47     // --- IMPLEMENTATION OF RefactoringUI INTERFACE ---------------------------
48

49     public boolean isQuery() {
50         return false;
51     }
52
53     public CustomRefactoringPanel getPanel(ParametersPanel parent) {
54         if (panel == null) {
55             panel = new CopyClassPanel(parent, getName() + " - " + ((JavaClass) refactoring.getResource().getClassifiers().get(0)).getName(), refactoring.getResource().getPackageName(), JavaModel.getFileObject(refactoring.getResource()));
56         }
57         return panel;
58     }
59
60     public Problem setParameters() {
61         setupRefactoring();
62         return refactoring.checkParameters();
63     }
64     
65     public Problem checkParameters() {
66         if (panel==null)
67             return null;
68         setupRefactoring();
69         return refactoring.fastCheckParameters();
70     }
71     
72     private void setupRefactoring() {
73         refactoring.setTargetClassPathRoot(panel.getRootFolder());
74         refactoring.setTargetPackageName(panel.getPackageName().replace('/', '.'));
75         refactoring.setNewName(panel.getNewName());
76     }
77
78     public AbstractRefactoring getRefactoring() {
79         return refactoring;
80     }
81
82     public String JavaDoc getDescription() {
83         return NbBundle.getMessage(CopyClassAction.class, "DSC_CopyClass", refactoring.getNewName()); // NOI18N
84
}
85
86     public String JavaDoc getName() {
87         return NbBundle.getMessage(CopyClassAction.class, "LBL_CopyClass"); // NOI18N
88
}
89
90     public boolean hasParameters() {
91         return true;
92     }
93
94     public HelpCtx getHelpCtx() {
95         return new HelpCtx(PullUpRefactoringUI.class.getName());
96     }
97 }
Popular Tags