KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > refactoring > ui > j > spi > ui > DeleteRefactoringUI


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.refactoring.ui.j.spi.ui;
21
22 import java.awt.Component JavaDoc;
23 import java.awt.Dimension JavaDoc;
24 import java.text.MessageFormat JavaDoc;
25 import java.util.ArrayList JavaDoc;
26 import java.util.Collection JavaDoc;
27 import java.util.HashMap JavaDoc;
28 import java.util.Map JavaDoc;
29 import javax.swing.Icon JavaDoc;
30 import javax.swing.ImageIcon JavaDoc;
31 import javax.swing.event.ChangeListener JavaDoc;
32 import org.netbeans.modules.refactoring.api.RefactoringElement;
33 import org.netbeans.modules.refactoring.api.SafeDeleteRefactoring;
34 import org.netbeans.modules.refactoring.spi.RefactoringElementImplementation;
35 import org.netbeans.modules.refactoring.spi.ui.RefactoringCustomUI;
36 import org.netbeans.modules.refactoring.spi.ui.TreeElement;
37 import org.netbeans.modules.refactoring.spi.ui.TreeElementFactory;
38 import org.netbeans.modules.xml.nbprefuse.AnalysisViewer;
39 import org.netbeans.modules.xml.nbprefuse.View;
40 import org.netbeans.modules.xml.refactoring.DeleteRequest;
41 import org.netbeans.modules.xml.refactoring.RefactorRequest;
42 import org.netbeans.modules.refactoring.api.AbstractRefactoring;
43 import org.netbeans.modules.refactoring.api.Problem;
44 import org.netbeans.modules.refactoring.api.WhereUsedQuery;
45 import org.netbeans.modules.refactoring.spi.ui.CustomRefactoringPanel;
46 import org.netbeans.modules.xml.refactoring.ui.j.ui.RefactoringPanel;
47 import org.netbeans.modules.xml.refactoring.ui.j.ui.SafeDeletePanel;
48 import org.netbeans.modules.xml.refactoring.ui.tree.GraphHelper;
49 import org.netbeans.modules.xml.refactoring.ui.views.WhereUsedView;
50 import org.netbeans.modules.xml.xam.Nameable;
51 import org.netbeans.modules.xml.xam.NamedReferenceable;
52 import org.netbeans.modules.xml.xam.Referenceable;
53 import org.openide.util.HelpCtx;
54 import org.openide.util.NbBundle;
55 import org.openide.util.Utilities;
56 import org.openide.util.lookup.Lookups;
57 import prefuse.data.Graph;
58
59 /**
60  *
61  * @author Jeri Lockhart
62  */

63 public class DeleteRefactoringUI implements org.netbeans.modules.refactoring.spi.ui.RefactoringUI, RefactoringCustomUI{
64     
65     private WhereUsedQuery query;
66     private WhereUsedView view;
67     private DeleteRequest deleteRequest;
68     private CustomRefactoringPanel panel;
69     private AbstractRefactoring refactoring;
70     private NamedReferenceable target;
71     
72     /** Creates a new instance of WhereUsedQueryUI */
73     public DeleteRefactoringUI(WhereUsedView view, DeleteRequest request) {
74         this.view = view;
75         deleteRequest = request;
76         query = new WhereUsedQuery(Lookups.singleton(request.getTarget()));
77         target = request.getTarget();
78         refactoring = new SafeDeleteRefactoring(Lookups.singleton(target));
79     }
80     
81     public DeleteRefactoringUI(WhereUsedView view, NamedReferenceable target) {
82         this(view, new DeleteRequest(target));
83     }
84     
85     public DeleteRefactoringUI(NamedReferenceable target){
86         this.target= target;
87         refactoring = new SafeDeleteRefactoring(Lookups.singleton(target));
88     }
89
90     ////////////////////////////////////////////////////////////////////////////
91
/** Start Implementation of RefactoringUI
92      */

93     ////////////////////////////////////////////////////////////////////////////
94
/**
95      * Returns refactoring-specific panel containing input fields for
96      * refactoring parameters. This method is called by ParametersPanel
97      * which is responsible for displaying refactoring parameters dialog.
98      * Name of the panel returned from this method will be used as the dialog
99      * name. This panel can use setPreviewEnabled method of the passed
100      * ParametersPanel to enable/disable Preview button of the refactoring
101      * parameters dialog.
102      *
103      * @param parent ParametersPanel that the returned panel will be displayed in.
104      * @return Refactoring-specific parameters panel.
105      */

106     public CustomRefactoringPanel getPanel(ChangeListener JavaDoc parent) {
107          System.out.println("Is getPanel getting called???");
108         
109         if(panel == null)
110             panel = new SafeDeletePanel(target);
111         return panel;
112     }
113
114     /**
115      * Implementation of this method should set the refactoring parameters entered
116      * by user into the refactoring-specific parameters panel (returned from getPanel
117      * method) into the underlying refactoring object.
118      *
119      * @return Chain of problems returned from the underlying refactoring object
120      * when trying to set its parameters.
121      */

122     public Problem setParameters() {
123        // return null;
124
return refactoring.checkParameters();
125     }
126
127     /**
128      * Indicates whether this class represents a real refactoring that changes
129      * code or whether it is just a query (e.g. all usages for a class).
130      *
131      * @return <code>true</code> if the class represents only a query,
132      * <code>false</code> if the class represents a real refactoring.
133      */

134     public boolean isQuery() {
135         return false;
136     }
137
138     public boolean hasParameters() {
139         return true;
140     }
141
142     /**
143      * Returns underlying refactoring object.
144      *
145      * @return Underlying refactoring object.
146      */

147     public AbstractRefactoring getRefactoring() {
148         return refactoring;
149       // return query;
150
}
151
152
153     public HelpCtx getHelpCtx() {
154         return new HelpCtx(DeleteRefactoringUI.class);
155     }
156
157     /**
158      * Returns description of the refactoring.
159      *
160      * @return Refactoring description.
161      */

162     public String JavaDoc getDescription() {
163         return new MessageFormat JavaDoc(NbBundle.getMessage(RefactoringPanel.class, "LBL_Delete")).format (
164                     new Object JavaDoc[] {target.getName() }
165                 );
166         
167     }
168
169     public Problem checkParameters() {
170         //return null;
171
return refactoring.fastCheckParameters();
172     }
173     
174     
175     public View getView() {
176        return view;
177     }
178     
179     public void setView(View view){
180         
181         this.view = WhereUsedView.class.cast(view);
182     }
183     
184     
185     /**
186      *
187      *
188      * @returns RefactorRequest
189      */

190     public RefactorRequest getRefactorRequest() {
191         return deleteRequest;
192         
193     }
194     
195     
196     /**
197      * Returns name of the refactoring.
198      *
199      * @return Refactoring name.
200      */

201     public String JavaDoc getName() {
202         return new MessageFormat JavaDoc(NbBundle.getMessage(RefactoringPanel.class, "LBL_Delete")).format (
203                     new Object JavaDoc[] {target.getName()}
204                 );
205     }
206     
207     ////////////////////////////////////////////////////////////////////////////
208
/** End Implementation of RefactoringUI
209      */

210     ////////////////////////////////////////////////////////////////////////////
211

212    public NamedReferenceable getTarget() {
213         return deleteRequest.getTarget();
214     }
215    
216    
217      public Component JavaDoc getCustomComponent(Collection JavaDoc<RefactoringElement> elements) {
218         System.out.println("getCustomComponent called");
219         WhereUsedView view = new WhereUsedView(target);
220         GraphHelper gh = new GraphHelper((target));
221         
222         
223         ArrayList JavaDoc<TreeElement> nodes = new ArrayList JavaDoc<TreeElement>();
224         for (RefactoringElement element: elements) {
225                 TreeElement previewNode = TreeElementFactory.getTreeElement(element);
226             if(previewNode != null)
227                 nodes.add(previewNode);
228         }
229         
230         Graph graph = gh.loadGraph(nodes);
231         view.setGraph(graph);
232         AnalysisViewer analysisViewer = new AnalysisViewer();
233         analysisViewer.getPanel().setMinimumSize(new Dimension JavaDoc(10,10));
234         analysisViewer.getPanel().setPreferredSize(new Dimension JavaDoc(10,10));
235         view.showView(analysisViewer);
236        
237        return analysisViewer.getPanel();
238     }
239
240     public Icon JavaDoc getCustomIcon() {
241          return new ImageIcon JavaDoc(
242             Utilities.loadImage(
243             "org/netbeans/modules/refactoring/api/resources/"+
244             "findusages.png"));
245     }
246
247     public String JavaDoc getCustomToolTip() {
248          return NbBundle.getMessage(WhereUsedQueryUI.class, "LBL_ShowGraph");
249     }
250 }
251
Popular Tags