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: * Portions Copyrighted 2007 Sun Microsystems, Inc.
027: */
028:
029: package org.netbeans.modules.navigator;
030:
031: import java.beans.PropertyVetoException;
032: import javax.swing.Action;
033: import javax.swing.ActionMap;
034: import javax.swing.JComponent;
035: import javax.swing.JPanel;
036: import javax.swing.text.DefaultEditorKit;
037: import org.netbeans.spi.navigator.NavigatorPanel;
038: import org.openide.explorer.ExplorerManager;
039: import org.openide.explorer.ExplorerUtils;
040: import org.openide.explorer.view.ListView;
041: import org.openide.nodes.AbstractNode;
042: import org.openide.nodes.Children;
043: import org.openide.nodes.Node;
044: import org.openide.util.Exceptions;
045: import org.openide.util.Lookup;
046:
047: /** Example of Explorer View integration into NavigatorPanel, with working
048: * explorer actions. Nodes selected in explorer view, managed by explorer
049: * manager, are propagated to global activated nodes.
050: *
051: * Key points for integration are: <br></br>
052: * - return lookup created using ExplorerUtils.createLookup(...) from getLookup() method
053: * - use ExplorerUtils.activateActions(..) for actions activation in panelActivated
054: *
055: * @author Dafe Simonek
056: */
057: public class ListViewNavigatorPanel extends JPanel implements
058: NavigatorPanel, ExplorerManager.Provider {
059:
060: private ExplorerManager manager;
061: private ListView listView;
062: private Lookup lookup;
063: private Action copyAction;
064:
065: public ListViewNavigatorPanel() {
066: manager = new ExplorerManager();
067: ActionMap map = getActionMap();
068: copyAction = ExplorerUtils.actionCopy(manager);
069: map.put(DefaultEditorKit.copyAction, copyAction);
070: map.put(DefaultEditorKit.cutAction, ExplorerUtils
071: .actionCut(manager));
072: map.put(DefaultEditorKit.pasteAction, ExplorerUtils
073: .actionPaste(manager));
074: map.put("delete", ExplorerUtils.actionDelete(manager, true)); // or false
075:
076: lookup = ExplorerUtils.createLookup(manager, map);
077:
078: listView = new ListView();
079: fillListView(listView);
080:
081: add(listView);
082: }
083:
084: public String getDisplayName() {
085: return "List view panel";
086: }
087:
088: public String getDisplayHint() {
089: return "List view based navigator panel";
090: }
091:
092: public JComponent getComponent() {
093: return this ;
094: }
095:
096: public void panelActivated(Lookup context) {
097: ExplorerUtils.activateActions(manager, true);
098: }
099:
100: public void panelDeactivated() {
101: ExplorerUtils.activateActions(manager, false);
102: }
103:
104: public Lookup getLookup() {
105: return lookup;
106: }
107:
108: public ExplorerManager getExplorerManager() {
109: return manager;
110: }
111:
112: public Action getCopyAction() {
113: return copyAction;
114: }
115:
116: private void fillListView(ListView listView) {
117: try {
118: Node testNode = new AbstractNode(Children.LEAF);
119: manager.setRootContext(testNode);
120: manager.setSelectedNodes(new Node[] { testNode });
121: } catch (PropertyVetoException ex) {
122: Exceptions.printStackTrace(ex);
123: }
124: }
125:
126: }
|