KickJava   Java API By Example, From Geeks To Geeks.

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


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.BorderLayout JavaDoc;
23 import java.awt.Component JavaDoc;
24 import java.awt.Dimension JavaDoc;
25 import java.beans.BeanInfo JavaDoc;
26 import java.text.MessageFormat JavaDoc;
27 import java.util.ArrayList JavaDoc;
28 import java.util.Collection JavaDoc;
29 import java.util.HashMap JavaDoc;
30 import java.util.Map JavaDoc;
31 import javax.swing.Icon JavaDoc;
32 import javax.swing.ImageIcon JavaDoc;
33 import javax.swing.JButton JavaDoc;
34 import javax.swing.JDialog JavaDoc;
35 import javax.swing.JFrame JavaDoc;
36 import javax.swing.JPanel JavaDoc;
37 import javax.swing.event.ChangeListener JavaDoc;
38 import org.netbeans.modules.refactoring.api.RefactoringElement;
39 import org.netbeans.modules.refactoring.spi.ui.RefactoringCustomUI;
40 import org.netbeans.modules.refactoring.spi.ui.TreeElement;
41 import org.netbeans.modules.refactoring.spi.ui.TreeElementFactory;
42 import org.netbeans.modules.refactoring.spi.ui.UI;
43 import org.netbeans.modules.xml.nbprefuse.AnalysisViewer;
44 import org.netbeans.modules.xml.nbprefuse.View;
45 import org.netbeans.modules.xml.nbprefuse.util.GraphUtilities;
46 import org.netbeans.modules.xml.refactoring.FindUsageResult;
47 import org.netbeans.modules.xml.refactoring.RefactorRequest;
48 import org.netbeans.modules.refactoring.api.AbstractRefactoring;
49 import org.netbeans.modules.refactoring.spi.ui.CustomRefactoringPanel;
50 import org.netbeans.modules.refactoring.api.Problem;
51 import org.netbeans.modules.refactoring.api.WhereUsedQuery;
52 import org.netbeans.modules.xml.refactoring.RefactoringManager;
53 import org.netbeans.modules.xml.refactoring.ui.j.ui.RefactoringPanel;
54 import org.netbeans.modules.xml.refactoring.ui.tree.GraphHelper;
55 import org.netbeans.modules.xml.refactoring.ui.util.AnalysisUtilities;
56 import org.netbeans.modules.xml.refactoring.ui.views.WhereUsedView;
57 import org.netbeans.modules.xml.xam.Named;
58 import org.netbeans.modules.xml.xam.Referenceable;
59 import org.openide.nodes.Node;
60 import org.openide.util.HelpCtx;
61 import org.openide.util.NbBundle;
62 import org.openide.util.Utilities;
63 import org.openide.util.lookup.Lookups;
64 import prefuse.data.Graph;
65
66 /**
67  *
68  * @author Jeri Lockhart
69  */

70 public class WhereUsedQueryUI implements org.netbeans.modules.refactoring.spi.ui.RefactoringUI, RefactoringCustomUI {
71     
72     private String JavaDoc name = ""; //NOI18N
73
private WhereUsedQuery query;
74     private Referenceable ref;
75     private WhereUsedView view;
76     
77     /** Creates a new instance of WhereUsedQueryUI */
78     public WhereUsedQueryUI(WhereUsedView view,
79             Referenceable ref) {
80         this.view = view;
81         this.ref = ref;
82         name = AnalysisUtilities.getName(ref);
83         query = new WhereUsedQuery(Lookups.singleton(ref));
84     }
85
86     ////////////////////////////////////////////////////////////////////////////
87
/** Start Implementation of RefactoringUI
88      */

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

102     public CustomRefactoringPanel getPanel(ChangeListener JavaDoc parent) {
103        // return new WhereUsedPanel(ref, (ParametersPanel)parent);
104
//System.out.println("WhereUsedQueryUI: getPanel called");
105
return new WhereUsedPanel(ref, parent);
106     }
107
108     /**
109      * Implementation of this method should set the refactoring parameters entered
110      * by user into the refactoring-specific parameters panel (returned from getPanel
111      * method) into the underlying refactoring object.
112      *
113      * @return Chain of problems returned from the underlying refactoring object
114      * when trying to set its parameters.
115      */

116     public Problem setParameters() {
117         return null;
118     }
119
120     /**
121      * Indicates whether this class represents a real refactoring that changes
122      * code or whether it is just a query (e.g. all usages for a class).
123      *
124      * @return <code>true</code> if the class represents only a query,
125      * <code>false</code> if the class represents a real refactoring.
126      */

127     public boolean isQuery() {
128         return true;
129     }
130
131     public boolean hasParameters() {
132         return false;
133     }
134
135     /**
136      * Returns underlying refactoring object.
137      *
138      * @return Underlying refactoring object.
139      */

140     public AbstractRefactoring getRefactoring() {
141         return query;
142     }
143
144     /**
145      * Returns name of the refactoring.
146      *
147      * @return Refactoring name.
148      */

149    
150     public String JavaDoc getName() {
151         return new MessageFormat JavaDoc(NbBundle.getMessage(RefactoringPanel.class, "LBL_WhereUsed")).format (
152                     new Object JavaDoc[] {name}
153                 );
154     }
155
156     public HelpCtx getHelpCtx() {
157         return new HelpCtx(WhereUsedQueryUI.class);
158     }
159
160     /**
161      * Returns description of the refactoring.
162      *
163      * @return Refactoring description.
164      */

165     public String JavaDoc getDescription() {
166         return new MessageFormat JavaDoc(NbBundle.getMessage(RefactoringPanel.class, "DSC_WhereUsed")).format (
167                     new Object JavaDoc[] {name}
168                 );
169         
170     }
171
172     public Problem checkParameters() {
173         return null;
174     }
175     
176     public View getView() {
177        return view;
178     }
179
180     public Referenceable getTarget() {
181         return ref;
182     }
183     
184     public RefactorRequest getRefactorRequest() {
185         return null;
186     }
187
188     /**
189      * View graph View of Usages
190      */

191     public void setView(View view) {
192         this.view = WhereUsedView.class.cast(view);
193     }
194     
195     ////////////////////////////////////////////////////////////////////////////
196
/** End Implementation of RefactoringUI
197      */

198     ////////////////////////////////////////////////////////////////////////////
199

200     public Component JavaDoc getCustomComponent(Collection JavaDoc<RefactoringElement> elements) {
201         System.out.println("getCustomComponent called");
202         Referenceable ref = view.getQueryComponent();
203         GraphHelper gh = new GraphHelper(ref);
204         
205        // Map<RefactoringElement, TreeElement> nodes = new HashMap<RefactoringElement,TreeElement>();
206
ArrayList JavaDoc<TreeElement> nodes = new ArrayList JavaDoc<TreeElement>();
207         //ArrayList nodes = new ArrayList();
208
for (RefactoringElement element: elements) {
209                 TreeElement previewNode = TreeElementFactory.getTreeElement(element);
210             if(previewNode != null)
211                 nodes.add(previewNode);
212         }
213         
214         Graph graph = gh.loadGraph(nodes);
215         view.setGraph(graph);
216         AnalysisViewer analysisViewer = new AnalysisViewer();
217         analysisViewer.getPanel().setMinimumSize(new Dimension JavaDoc(10,10));
218         analysisViewer.getPanel().setPreferredSize(new Dimension JavaDoc(10,10));
219         view.showView(analysisViewer);
220        
221        return analysisViewer.getPanel();
222         
223         
224        /*JFrame.setDefaultLookAndFeelDecorated(true);
225         JFrame frame = new JFrame("FrameDemo");
226         frame.getContentPane().add(analysisViewer.getPanel());
227         frame.pack();
228         frame.setVisible(true);
229         
230         JPanel panel = new JPanel(new BorderLayout());
231         JButton button = new JButton("Press me");
232         panel.add(button);
233         JButton b = new JButton("SDAAAAA");
234         panel.add(b);
235         panel.setVisible(true);
236         return panel;*/

237     }
238
239     public Icon JavaDoc getCustomIcon() {
240        return new ImageIcon JavaDoc(
241             Utilities.loadImage(
242             "org/netbeans/modules/refactoring/api/resources/"+
243             "findusages.png"));
244     }
245
246     public String JavaDoc getCustomToolTip() {
247          return NbBundle.getMessage(WhereUsedQueryUI.class, "LBL_ShowGraph");
248     }
249     
250 }
251
Popular Tags