KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > refactoring > java > 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.java.ui;
20 import java.io.IOException JavaDoc;
21 import java.net.MalformedURLException JavaDoc;
22 import java.net.URL JavaDoc;
23 import javax.swing.event.ChangeListener JavaDoc;
24 import org.netbeans.modules.refactoring.api.AbstractRefactoring;
25 import org.netbeans.modules.refactoring.api.SingleCopyRefactoring;
26 import org.netbeans.modules.refactoring.api.Problem;
27 import org.netbeans.modules.refactoring.java.RetoucheUtils;
28 import org.netbeans.modules.refactoring.java.ui.CopyClassPanel;
29 import org.netbeans.modules.refactoring.spi.ui.CustomRefactoringPanel;
30 import org.netbeans.modules.refactoring.spi.ui.RefactoringUI;
31 import org.netbeans.modules.refactoring.spi.ui.RefactoringUI;
32 import org.netbeans.modules.refactoring.spi.ui.RefactoringUIBypass;
33 import org.openide.filesystems.FileObject;
34 import org.openide.filesystems.URLMapper;
35 import org.openide.util.HelpCtx;
36 import org.openide.util.NbBundle;
37 import org.openide.util.datatransfer.PasteType;
38 import org.openide.util.lookup.Lookups;
39
40 /** Refactoring UI object for Copy Class refactoring.
41  *
42  * @author Jan Becicka
43  */

44 public class CopyClassRefactoringUI implements RefactoringUI, RefactoringUIBypass {
45     // reference to pull up refactoring this UI object corresponds to
46
private final SingleCopyRefactoring refactoring;
47     // UI panel for collecting parameters
48
private CopyClassPanel panel;
49     private FileObject resource;
50     private FileObject targetFolder;
51     private PasteType paste;
52     
53     public CopyClassRefactoringUI(FileObject resource, FileObject target, PasteType paste) {
54         refactoring = new SingleCopyRefactoring(Lookups.singleton(resource));
55         this.resource = resource;
56         this.targetFolder = target;
57         this.paste=paste;
58     }
59     
60     // --- IMPLEMENTATION OF RefactoringUI INTERFACE ---------------------------
61

62     public boolean isQuery() {
63         return false;
64     }
65
66     public CustomRefactoringPanel getPanel(ChangeListener JavaDoc parent) {
67         if (panel == null) {
68             FileObject target = targetFolder!=null?targetFolder:resource.getParent();
69             panel = new CopyClassPanel(parent,
70                     getName() + " - " + resource.getName(),
71                     RetoucheUtils.getPackageName(target),
72                     target,
73                     resource.getName());
74             panel.setCombosEnabled(!(targetFolder!=null));
75         }
76         return panel;
77     }
78
79     public Problem setParameters() {
80         setupRefactoring();
81         return refactoring.checkParameters();
82     }
83     
84     public Problem checkParameters() {
85         if (panel==null)
86             return null;
87         setupRefactoring();
88         return refactoring.fastCheckParameters();
89     }
90     
91     private void setupRefactoring() {
92         refactoring.setNewName(panel.getNewName());
93         URL JavaDoc url = URLMapper.findURL(panel.getRootFolder(), URLMapper.EXTERNAL);
94         try {
95             refactoring.setTarget(Lookups.singleton(new URL JavaDoc(url.toExternalForm() + "/" + panel.getPackageName().replace('.','/'))));
96         } catch (MalformedURLException JavaDoc ex) {
97             ex.printStackTrace();
98         }
99     }
100
101     public AbstractRefactoring getRefactoring() {
102         return refactoring;
103     }
104
105     public String JavaDoc getDescription() {
106         return NbBundle.getMessage(CopyClassRefactoringUI.class, "DSC_CopyClass", refactoring.getNewName()); // NOI18N
107
}
108
109     public String JavaDoc getName() {
110         return NbBundle.getMessage(CopyClassRefactoringUI.class, "LBL_CopyClass"); // NOI18N
111
}
112
113     public boolean hasParameters() {
114         return true;
115     }
116
117     public HelpCtx getHelpCtx() {
118         return new HelpCtx(CopyClassRefactoringUI.class.getName());
119     }
120     public boolean isRefactoringBypassRequired() {
121         return !panel.isUpdateReferences();
122     }
123     public void doRefactoringBypass() throws IOException JavaDoc {
124         paste.paste();
125     }
126 }
Popular Tags