|
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-2004 Sun
* Microsystems, Inc. All Rights Reserved.
*/
package org.netbeans.modules.project.ui;
import java.awt.Image;
import java.lang.ref.WeakReference;
import java.util.Iterator;
import java.util.Map;
import java.util.WeakHashMap;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.netbeans.api.project.Sources;
import org.openide.nodes.FilterNode;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.CharConversionException;
import java.text.MessageFormat;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.ResourceBundle;
import javax.swing.Action;
import org.netbeans.api.project.Project;
import org.netbeans.api.project.ProjectUtils;
import org.netbeans.spi.project.ui.LogicalViewProvider;
import org.openide.ErrorManager;
import org.openide.nodes.AbstractNode;
import org.openide.nodes.Children;
import org.openide.nodes.Node;
import org.openide.util.Lookup;
import org.openide.util.NbBundle;
import org.openide.util.Utilities;
import org.openide.util.WeakListeners;
import org.openide.util.lookup.Lookups;
import org.openide.util.lookup.ProxyLookup;
import org.openide.xml.XMLUtil;
import org.openidex.search.SearchInfo;
import org.openidex.search.SearchInfoFactory;
/** Root node for list of open projects
* @author Petr Hrebejk
*/
public class ProjectsRootNode extends AbstractNode {
static final int PHYSICAL_VIEW = 0;
static final int LOGICAL_VIEW = 1;
private static final String ICON_BASE = "org/netbeans/modules/project/ui/resources/projectsRootNode"; //NOI18N
private static final Action[] NO_ACTIONS = new Action[0];
private static Action[] ACTIONS;
private ResourceBundle bundle;
private Node.Handle handle;
public ProjectsRootNode( int type ) {
super( new ProjectChildren( type ) );
setIconBase( ICON_BASE );
handle = new Handle( type );
}
public String getName() {
return ( "OpenProjects" ); // NOI18N
}
public String getDisplayName() {
if ( this.bundle == null ) {
this.bundle = NbBundle.getBundle( ProjectsRootNode.class );
}
return bundle.getString( "LBL_OpenProjectsNode_Name" ); // NOI18N
}
public boolean canRename() {
return false;
}
public Node.Handle getHandle() {
return handle;
}
public Action[] getActions( boolean context ) {
if ( context ) {
return NO_ACTIONS;
}
else {
if ( ACTIONS == null ) {
// Create the actions
ACTIONS = new Action[] {
// XXX
// SystemAction.get( NodeNewProjectAction.class ),
// SystemAction.get( NodeOpenProjectAction.class ),
};
}
return ACTIONS;
}
}
/** Finds node for given object in the view
* @return the node or null if the node was not found
*/
Node findNode( Object target ) {
ProjectChildren ch = (ProjectChildren)getChildren();
if ( ch.type == LOGICAL_VIEW ) {
Node[] nodes = ch.getNodes( true );
for( int i = 0; i < nodes.length; i++ ) {
Project p = (Project)nodes[i].getLookup().lookup( Project.class );
if ( p == null ) {
continue;
}
LogicalViewProvider lvp = (LogicalViewProvider)p.getLookup().lookup( LogicalViewProvider.class );
if ( lvp != null ) {
Node selectedNode = lvp.findPath( nodes[i], target );
if ( selectedNode != null ) {
return selectedNode;
}
}
}
return null;
}
else if ( ch.type == PHYSICAL_VIEW ) {
Node[] nodes = ch.getNodes( true );
for( int i = 0; i < nodes.length; i++ ) {
PhysicalView.PathFinder pf = (PhysicalView.PathFinder)nodes[i].getLookup().lookup( PhysicalView.PathFinder.class );
if ( pf != null ) {
Node n = pf.findPath( nodes[i], target );
if ( n != null ) {
return n;
}
}
}
return null;
}
else {
return null;
}
}
private static class Handle implements Node.Handle {
private static final long serialVersionUID = 78374332058L;
private int viewType;
public Handle( int viewType ) {
this.viewType = viewType;
}
public Node getNode() {
return new ProjectsRootNode( viewType );
}
}
// XXX Needs to listen to project rename
// However project rename is currently disabled so it is not a big deal
static class ProjectChildren extends Children.Keys implements ChangeListener, PropertyChangeListener {
private java.util.Map /*
|
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 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.