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.visualweb.propertyeditors.binding.data;
042:
043: import java.awt.BorderLayout;
044: import java.awt.Cursor;
045: import java.awt.Point;
046: import java.awt.event.ActionEvent;
047: import java.awt.event.ActionListener;
048: import java.beans.PropertyChangeEvent;
049: import java.beans.PropertyChangeListener;
050: import java.io.IOException;
051: import java.util.ArrayList;
052: import java.util.List;
053: import javax.swing.Action;
054: import javax.swing.JButton;
055: import javax.swing.JDialog;
056: import javax.swing.JPanel;
057: import org.openide.DialogDescriptor;
058: import org.openide.DialogDisplayer;
059: import org.openide.ErrorManager;
060: import org.openide.cookies.InstanceCookie;
061: import org.openide.explorer.ExplorerManager;
062: import org.openide.explorer.view.BeanTreeView;
063: import org.openide.explorer.view.TreeView;
064: import org.openide.filesystems.FileObject;
065: import org.openide.filesystems.Repository;
066: import org.openide.loaders.DataFolder;
067: import org.openide.loaders.FolderInstance;
068: import org.openide.nodes.AbstractNode;
069: import org.openide.nodes.FilterNode;
070: import org.openide.nodes.Node;
071: import org.openide.util.HelpCtx;
072: import org.openide.util.NbBundle;
073: import org.openide.util.actions.NodeAction;
074: import org.openide.windows.TopComponent;
075: import org.openide.windows.WindowManager;
076:
077: /**
078: * This panel provides a cloned view of DataSources, WebServices and EJB nodes
079: * in the Server Navigator.
080: *
081: * @author Winston Prakash
082: */
083: public class DataProviderExplorerPanel extends JPanel implements
084: ExplorerManager.Provider {
085:
086: private final TreeView view = new BeanTreeView();
087: private final ServernavChildren children = new ServernavChildren();
088:
089: TopComponent tc = WindowManager.getDefault().findTopComponent(
090: "serverNavigator");
091:
092: public DataProviderExplorerPanel() {
093: view.setDropTarget(false);
094: view.setDragSource(false);
095: view.setRootVisible(false);
096:
097: setLayout(new BorderLayout());
098: add(view, BorderLayout.CENTER);
099: getExplorerManager().setRootContext(new AbstractNode(children));
100: initialize();
101: }
102:
103: /**
104: * Initialization the explorer panel.
105: */
106: public void initialize() {
107: FileObject fo = Repository.getDefault().getDefaultFileSystem()
108: .findResource("ServerNavigator");
109: if (fo != null) {
110: DataFolder folder = DataFolder.findFolder(fo);
111: final ServerNavigatorFolder servNavFolder = new ServerNavigatorFolder(
112: folder);
113: servNavFolder.recreate();
114: servNavFolder.instanceFinished();
115: fo
116: .addFileChangeListener(new org.openide.filesystems.FileChangeAdapter() {
117: public void fileDeleted(
118: org.openide.filesystems.FileEvent evt) {
119: servNavFolder.recreate();
120: }
121:
122: public void fileDataCreated(
123: org.openide.filesystems.FileEvent evt) {
124: servNavFolder.recreate();
125: }
126: });
127: }
128: tc.requestActive();
129: }
130:
131: public HelpCtx getHelpCtx() {
132: Node[] selNodes = getExplorerManager().getSelectedNodes();
133: if (selNodes != null && selNodes.length == 1)
134: return selNodes[0].getHelpCtx();
135: else
136: return HelpCtx.DEFAULT_HELP;
137: }
138:
139: ExplorerManager explorerManager = new ExplorerManager();
140:
141: public ExplorerManager getExplorerManager() {
142: return explorerManager;
143: }
144:
145: /**
146: * This class is used to add the nodes specified in the layer file's
147: * <code>AddDataProviderDialog</code> folder.
148: */
149: private final class ServerNavigatorFolder extends FolderInstance {
150:
151: public ServerNavigatorFolder(final DataFolder folder) {
152: super (folder);
153: }
154:
155: /**
156: * Updates the <code>AddDataProviderDialog</code> with nodes specified in the children of
157: * AddDataProviderDialog folder in the layer file.
158: */
159: protected Object createInstance(InstanceCookie[] cookies)
160: throws IOException, ClassNotFoundException {
161: final List nodes = new ArrayList();
162: for (int i = 0; i < cookies.length; i++) {
163: try {
164: Object obj = cookies[i].instanceCreate();
165: if (obj instanceof Node) {
166: Node node = ((Node) obj).cloneNode();
167: if (node
168: .getName()
169: .equals(
170: NbBundle
171: .getMessage(
172: DataProviderExplorerPanel.class,
173: "DATA_SOURCES"))) { // NO_I18N
174: //|| node.getName().equals(NbBundle.getMessage(DataProviderExplorerPanel.class,"ENTERPRISE_JAVA_BEANS")) // NO_I18N
175: //|| node.getName().equals(NbBundle.getMessage(DataProviderExplorerPanel.class,"Web_Services"))){ // NO_I18N
176: nodes.add(node);
177: view.expandNode(node);
178: }
179: }
180: } catch (ClassNotFoundException ex) {
181: ErrorManager.getDefault().notify(ex);
182: } catch (IOException ex) {
183: ErrorManager.getDefault().notify(ex);
184: }
185: }
186:
187: javax.swing.SwingUtilities.invokeLater(new Runnable() {
188: public void run() {
189: DataProviderExplorerPanel.this .children
190: .updateKeys(nodes);
191: }
192: });
193: return nodes;
194: }
195: }
196:
197: private class ServernavChildren extends
198: org.openide.nodes.Children.Keys {
199: protected Node[] createNodes(Object key) {
200: if (key instanceof Node) {
201: final Node node = (Node) key;
202:
203: // XXX Trick to expand the node
204: javax.swing.SwingUtilities.invokeLater(new Runnable() {
205: public void run() {
206: if (view != null) {
207: view.expandNode(node);
208: }
209: }
210: });
211: return new Node[] { node };
212: }
213:
214: return new Node[0];
215: }
216:
217: protected void removeNotify() {
218: setKeys(java.util.Collections.EMPTY_SET);
219: }
220:
221: public void updateKeys(java.util.Collection keys) {
222: setKeys(keys);
223: }
224: }
225: }
|