KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > schema > refactoring > ui > QueryPanel


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 package org.netbeans.modules.xml.schema.refactoring.ui;
20
21 import java.awt.*;
22 import java.beans.PropertyChangeEvent JavaDoc;
23 import java.lang.ref.WeakReference JavaDoc;
24 //import javax.jmi.reflect.RefObject;
25
import javax.swing.*;
26 import org.netbeans.modules.xml.schema.refactoring.query.CustomizerResults;
27 import org.netbeans.modules.xml.schema.refactoring.query.Query;
28 import org.openide.ErrorManager;
29 import org.openide.nodes.NodeEvent;
30 import org.openide.nodes.NodeMemberEvent;
31 import org.openide.nodes.NodeReorderEvent;
32 import org.openide.windows.TopComponent;
33 import org.netbeans.modules.xml.nbprefuse.AnalysisViewer;
34 import org.netbeans.modules.xml.refactoring.ui.j.spi.ui.ParametersPanel;
35 import org.netbeans.modules.xml.schema.model.SchemaModel;
36 import org.openide.loaders.DataObject;
37 import org.openide.nodes.Node;
38 import org.openide.nodes.NodeListener;
39 import org.openide.util.WeakListeners;
40
41 /**
42  * Panel for showing proposed changes (refactoring elements) of any refactoring.
43  *
44  * @author Pavel Flaska, Martin Matula
45  * @author Jeri Lockhart
46  */

47 //public class QueryPanel extends JPanel implements InvalidationListener {
48
public class QueryPanel extends JPanel implements NodeListener {
49     public static final long serialVersionUID = 1L;
50     
51     // PRIVATE FIELDS
52

53     private final Query query;
54     
55     private transient boolean isVisible = false;
56     private transient ParametersPanel parametersPanel = null;
57       
58     private WeakReference JavaDoc refCallerTC;
59     
60     private AnalysisViewer analysisViewer;
61         
62     private CustomizerResults results;
63     
64     
65     
66     
67     public QueryPanel(Query query) {
68         this(query,null);
69     }
70     
71     
72     @SuppressWarnings JavaDoc("unchecked")
73     public QueryPanel(Query query, TopComponent caller) {
74         if (caller!=null)
75             refCallerTC = new WeakReference JavaDoc(caller);
76         this.query = query;
77         initialize();
78         refresh(false);
79     }
80     
81     
82     public static void checkEventThread() {
83         if (!SwingUtilities.isEventDispatchThread()) {
84             ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL,
85                     new IllegalStateException JavaDoc(
86                     "This must happen in event thread!")); //NOI18N
87
}
88     }
89     
90     /* initializes all the query */
91     private void initialize() {
92         checkEventThread();
93         setFocusCycleRoot(true);
94         setLayout(new BorderLayout());
95         setName(query.getShortName());
96         
97         analysisViewer = new AnalysisViewer();
98 // analysisViewer.addPropertyChangeListener(
99
// AnalysisViewer.PROP_GRAPH_NODE_SELECTION_CHANGED_RELAY,this);
100
analysisViewer.getPanel().setMinimumSize(new Dimension(10,10));
101         analysisViewer.getPanel().setPreferredSize(new Dimension(10,10));
102         add(analysisViewer, BorderLayout.CENTER);
103         validate();
104         addDataOjectNodeListener();
105     }
106     
107     private void addDataOjectNodeListener() {
108         SchemaModel queryModel = query.getModel();
109         assert queryModel != null : "null query model";
110         DataObject dobj = (DataObject) queryModel.getModelSource().getLookup().lookup(DataObject.class);
111         assert dobj != null : "model source lookup has no data object";
112         Node node = dobj.getNodeDelegate();
113         node.addNodeListener((NodeListener)WeakListeners.create(NodeListener.class, this, node));
114     }
115     
116     void close() {
117         
118         QueryPanelContainer.getUsagesComponent().removePanel(this);
119         closeNotify();
120     }
121     
122     public boolean getIsVisible() {
123         return this.isVisible;
124     }
125     
126     public void setIsVisible(boolean isVisible){
127         this.isVisible = isVisible;
128     }
129     
130     private void refresh(final boolean showParametersPanel) {
131         checkEventThread();
132         query.runQuery(this, analysisViewer);
133
134     }
135     
136     // disables all components in a given container
137
private static void disableComponents(Container c) {
138         checkEventThread();
139         Component children[] = c.getComponents();
140         for (int i = 0; i < children.length; i++) {
141             if (children[i].isEnabled()) {
142                 children[i].setEnabled(false);
143             }
144             if (children[i] instanceof Container) {
145                 disableComponents((Container) children[i]);
146             }
147         }
148     }
149     
150     protected void closeNotify() {
151 // UndoWatcher.stopWatching(this);
152
if (refCallerTC != null) {
153             TopComponent tc = (TopComponent) refCallerTC.get();
154             if (tc != null && tc.isShowing()) {
155                 tc.requestActive();
156             }
157         }
158         //super.closeNotify();
159
}
160     
161     ////////////////////////////////////////////////////////////////////////////
162
// INNER CLASSES
163
////////////////////////////////////////////////////////////////////////////
164

165   
166     ////////////////////////////////////////////////////////////////////////////
167

168     /**
169      * Notifies this component that it now has a parent component.
170      * When this method is invoked, the chain of parent components is
171      * set up with <code>KeyboardAction</code> event listeners.
172      *
173      *
174      * @see #registerKeyboardAction
175      */

176 // public void addNotify() {
177
// super.addNotify();
178
// // When the NavigatorPanel's NavNode HighlightInSchemaViewAction
179
// // is performed on a NavNode, the NavigatorPanel fires an event
180
// // to the QueryPanelContainer. The RPC then fires
181
// // the PROP_HIGHLIGHT_IN_SCHEMA_VIEW to the AnalysisView
182
// // The AnalysisView then calls SchemaRepresentation.show()
183
// QueryPanelContainer rpc = QueryPanelContainer.getUsagesComponent();
184
// if (rpc != null){
185
// rpc.addPropertyChangeListener(AnalysisViewer.PROP_HIGHLIGHT_IN_SCHEMA_VIEW,
186
// analysisViewer);
187
// }
188
// }
189

190     public void childrenRemoved(NodeMemberEvent ev) {
191     }
192
193     public void childrenAdded(NodeMemberEvent ev) {
194     }
195
196     public void nodeDestroyed(NodeEvent ev) {
197         SwingUtilities.invokeLater(new Runnable JavaDoc() {
198             public void run() {
199                 close();
200             }
201         });
202     }
203
204     public void childrenReordered(NodeReorderEvent ev) {
205     }
206
207     public void propertyChange(PropertyChangeEvent JavaDoc evt) {
208     }
209     
210     
211   
212 } // end Refactor Panel
213
Popular Tags