|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.modules.favorites; import java.awt.BorderLayout; import java.beans.BeanInfo; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.beans.PropertyVetoException; import java.io.File; import java.io.IOException; import java.util.Stack; import javax.swing.ActionMap; import javax.swing.SwingUtilities; import javax.swing.text.DefaultEditorKit; import org.openide.ErrorManager; import org.openide.explorer.ExplorerManager; import org.openide.explorer.ExplorerUtils; import org.openide.explorer.view.BeanTreeView; import org.openide.explorer.view.TreeView; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; import org.openide.loaders.DataFolder; import org.openide.loaders.DataObject; import org.openide.loaders.DataObjectNotFoundException; import org.openide.loaders.DataShadow; import org.openide.nodes.*; import org.openide.util.NbBundle; import org.openide.windows.TopComponent; import org.openide.windows.WindowManager; /** Special class for projects tab in main explorer */ public class Tab extends TopComponent implements Runnable, ExplorerManager.Provider { static final long serialVersionUID =-8178367548546385799L; /** data object which should be selected in EQ; synch array when accessing */ private static final DataObject[] needToSelect = new DataObject[1]; private static transient Tab DEFAULT; /** composited view */ transient protected TreeView view; /** listeners to the root context and IDE settings */ transient private PropertyChangeListener weakRcL; transient private NodeListener weakNRcL; transient private NodeListener rcListener; /** validity flag */ transient private boolean valid = true; private ExplorerManager manager; /** Creates */ private Tab() { this.manager = new ExplorerManager(); ActionMap map = this.getActionMap (); map.put(DefaultEditorKit.copyAction, ExplorerUtils.actionCopy(manager)); map.put(DefaultEditorKit.cutAction, ExplorerUtils.actionCut(manager)); map.put(DefaultEditorKit.pasteAction, ExplorerUtils.actionPaste(manager)); map.put("delete", ExplorerUtils.actionDelete (manager, true)); // or false // following line tells the top component which lookup should be associated with it associateLookup (ExplorerUtils.createLookup (manager, map)); } public ExplorerManager getExplorerManager() { return manager; } /** Return preferred ID */ protected String preferredID () { return "favorites"; //NOI18N } /** Initialize visual content of component */ protected void componentShowing () { super.componentShowing (); if (view == null) { view = initGui (); view.getAccessibleContext().setAccessibleName( NbBundle.getMessage( Tab.class, "ACSN_ExplorerBeanTree")); view.getAccessibleContext().setAccessibleDescription( NbBundle.getMessage( Tab.class, "ACSD_ExplorerBeanTree")); } run(); } /** Initializes gui of this component. Subclasses can override * this method to install their own gui. * @return Tree view that will serve as main view for this explorer. */ protected TreeView initGui () { TreeView view = new BeanTreeView(); view.setRootVisible (true); view.setDragSource (true); setLayout(new BorderLayout()); add (view); return view; } protected void componentActivated() { ExplorerUtils.activateActions(manager, true); } protected void componentDeactivated() { ExplorerUtils.activateActions(manager, false); } /** Transfer focus to view. */ public void requestFocus () { super.requestFocus(); if (view != null) { view.requestFocus(); } } /** Transfer focus to view. */ public boolean requestFocusInWindow () { super.requestFocusInWindow(); if (view != null) { return view.requestFocusInWindow(); } else { return false; } } /** Sets new root context to view. Name, icon, tooltip * of this top component will be updated properly */ public void setRootContext (Node rc) { Node oldRC = getExplorerManager().getRootContext(); // remove old listener, if possible if (weakRcL != null) { oldRC.removePropertyChangeListener(weakRcL); } if (weakNRcL != null) { oldRC.removeNodeListener(weakNRcL); } getExplorerManager().setRootContext(rc); initializeWithRootContext(rc); } public Node getRootContext () { return getExplorerManager().getRootContext(); } /** Implementation of DeferredPerformer.DeferredCommand * Performs initialization of component's attributes * after deserialization (component's name, icon etc, * according to the root context) */ public void run() { if (!valid) { valid = true; validateRootContext(); } } // Bugfix #5891 04 Sep 2001 by Jiri Rechtacek // the title is derived from the root context // it isn't changed by a selected node in the tree /** Called when the explored context changes. * Overriden - we don't want title to change in this style. */ protected void updateTitle () { // set name by the root context setName(getExplorerManager ().getRootContext().getDisplayName()); } private NodeListener rcListener () { if (rcListener == null) { rcListener = new RootContextListener(); } return rcListener; } /** Initialize this top component properly with information * obtained from specified root context node */ private void initializeWithRootContext (Node rc) { // update TC's attributes setIcon(rc.getIcon(BeanInfo.ICON_COLOR_16x16)); setToolTipText(rc.getDisplayName()); setName(rc.getDisplayName()); updateTitle(); // attach listener if (weakRcL == null) { weakRcL = org.openide.util.WeakListeners.propertyChange( rcListener(), rc ); } rc.addPropertyChangeListener(weakRcL); if (weakNRcL == null) { weakNRcL = org.openide.nodes.NodeOp.weakNodeListener ( rcListener(), rc ); } rc.addNodeListener(weakNRcL); } // put a request for later validation // we must do this here, because of ExplorerManager's deserialization. // Root context of ExplorerManager is validated AFTER all other // deserialization, so we must wait for it protected final void scheduleValidation() { valid = false; // WindowManagerImpl.deferredPerformer().putRequest(this, null); SwingUtilities.invokeLater(this); // TEMP } /* Updated accessible name of the tree view */ public void setName(String name) { super.setName(name); if (view != null) { view.getAccessibleContext().setAccessibleName(name); } } /* Updated accessible description of the tree view */ public void setToolTipText(String text) { super.setToolTipText(text); if (view != null) { view.getAccessibleContext().setAccessibleDescription(text); } } /** Multi - purpose listener, listens to: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.