001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.xml.schema.refactoring.ui;
042:
043: import java.awt.*;
044: import java.beans.PropertyChangeEvent;
045: import java.lang.ref.WeakReference; //import javax.jmi.reflect.RefObject;
046: import javax.swing.*;
047: import org.netbeans.modules.xml.schema.refactoring.query.CustomizerResults;
048: import org.netbeans.modules.xml.schema.refactoring.query.Query;
049: import org.openide.ErrorManager;
050: import org.openide.nodes.NodeEvent;
051: import org.openide.nodes.NodeMemberEvent;
052: import org.openide.nodes.NodeReorderEvent;
053: import org.openide.windows.TopComponent;
054: import org.netbeans.modules.xml.nbprefuse.AnalysisViewer;
055: import org.netbeans.modules.xml.schema.model.SchemaModel;
056: import org.openide.loaders.DataObject;
057: import org.openide.nodes.Node;
058: import org.openide.nodes.NodeListener;
059: import org.openide.util.WeakListeners;
060:
061: /**
062: * Panel for showing proposed changes (refactoring elements) of any refactoring.
063: *
064: * @author Pavel Flaska, Martin Matula
065: * @author Jeri Lockhart
066: */
067: //public class QueryPanel extends JPanel implements InvalidationListener {
068: public class QueryPanel extends JPanel implements NodeListener {
069: public static final long serialVersionUID = 1L;
070:
071: // PRIVATE FIELDS
072:
073: private final Query query;
074:
075: private transient boolean isVisible = false;
076: // private transient ParametersPanel parametersPanel = null;
077:
078: private WeakReference refCallerTC;
079:
080: private AnalysisViewer analysisViewer;
081:
082: private CustomizerResults results;
083:
084: public QueryPanel(Query query) {
085: this (query, null);
086: }
087:
088: @SuppressWarnings("unchecked")
089: public QueryPanel(Query query, TopComponent caller) {
090: if (caller != null)
091: refCallerTC = new WeakReference(caller);
092: this .query = query;
093: initialize();
094: refresh(false);
095: }
096:
097: public static void checkEventThread() {
098: if (!SwingUtilities.isEventDispatchThread()) {
099: ErrorManager.getDefault().notify(
100: ErrorManager.INFORMATIONAL,
101: new IllegalStateException(
102: "This must happen in event thread!")); //NOI18N
103: }
104: }
105:
106: /* initializes all the query */
107: private void initialize() {
108: checkEventThread();
109: setFocusCycleRoot(true);
110: setLayout(new BorderLayout());
111: setName(query.getShortName());
112:
113: analysisViewer = new AnalysisViewer();
114: // analysisViewer.addPropertyChangeListener(
115: // AnalysisViewer.PROP_GRAPH_NODE_SELECTION_CHANGED_RELAY,this);
116: analysisViewer.getPanel().setMinimumSize(new Dimension(10, 10));
117: analysisViewer.getPanel().setPreferredSize(
118: new Dimension(10, 10));
119: add(analysisViewer, BorderLayout.CENTER);
120: validate();
121: addDataOjectNodeListener();
122: }
123:
124: private void addDataOjectNodeListener() {
125: SchemaModel queryModel = query.getModel();
126: assert queryModel != null : "null query model";
127: DataObject dobj = (DataObject) queryModel.getModelSource()
128: .getLookup().lookup(DataObject.class);
129: assert dobj != null : "model source lookup has no data object";
130: Node node = dobj.getNodeDelegate();
131: node.addNodeListener((NodeListener) WeakListeners.create(
132: NodeListener.class, this , node));
133: }
134:
135: void close() {
136:
137: QueryPanelContainer.getUsagesComponent().removePanel(this );
138: closeNotify();
139: }
140:
141: public boolean getIsVisible() {
142: return this .isVisible;
143: }
144:
145: public void setIsVisible(boolean isVisible) {
146: this .isVisible = isVisible;
147: }
148:
149: private void refresh(final boolean showParametersPanel) {
150: checkEventThread();
151: query.runQuery(this , analysisViewer);
152:
153: }
154:
155: // disables all components in a given container
156: private static void disableComponents(Container c) {
157: checkEventThread();
158: Component children[] = c.getComponents();
159: for (int i = 0; i < children.length; i++) {
160: if (children[i].isEnabled()) {
161: children[i].setEnabled(false);
162: }
163: if (children[i] instanceof Container) {
164: disableComponents((Container) children[i]);
165: }
166: }
167: }
168:
169: protected void closeNotify() {
170: // UndoWatcher.stopWatching(this);
171: if (refCallerTC != null) {
172: TopComponent tc = (TopComponent) refCallerTC.get();
173: if (tc != null && tc.isShowing()) {
174: tc.requestActive();
175: }
176: }
177: //super.closeNotify();
178: }
179:
180: ////////////////////////////////////////////////////////////////////////////
181: // INNER CLASSES
182: ////////////////////////////////////////////////////////////////////////////
183:
184: ////////////////////////////////////////////////////////////////////////////
185:
186: /**
187: * Notifies this component that it now has a parent component.
188: * When this method is invoked, the chain of parent components is
189: * set up with <code>KeyboardAction</code> event listeners.
190: *
191: *
192: * @see #registerKeyboardAction
193: */
194: // public void addNotify() {
195: // super.addNotify();
196: // // When the NavigatorPanel's NavNode HighlightInSchemaViewAction
197: // // is performed on a NavNode, the NavigatorPanel fires an event
198: // // to the QueryPanelContainer. The RPC then fires
199: // // the PROP_HIGHLIGHT_IN_SCHEMA_VIEW to the AnalysisView
200: // // The AnalysisView then calls SchemaRepresentation.show()
201: // QueryPanelContainer rpc = QueryPanelContainer.getUsagesComponent();
202: // if (rpc != null){
203: // rpc.addPropertyChangeListener(AnalysisViewer.PROP_HIGHLIGHT_IN_SCHEMA_VIEW,
204: // analysisViewer);
205: // }
206: // }
207: public void childrenRemoved(NodeMemberEvent ev) {
208: }
209:
210: public void childrenAdded(NodeMemberEvent ev) {
211: }
212:
213: public void nodeDestroyed(NodeEvent ev) {
214: SwingUtilities.invokeLater(new Runnable() {
215: public void run() {
216: close();
217: }
218: });
219: }
220:
221: public void childrenReordered(NodeReorderEvent ev) {
222: }
223:
224: public void propertyChange(PropertyChangeEvent evt) {
225: }
226:
227: } // end Refactor Panel
|