|
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-2000 Sun * Microsystems, Inc. All Rights Reserved. */ package org.openide.actions; import java.io.IOException; import java.util.Locale; import javax.swing.*; import org.openide.TopManager; import org.openide.ErrorManager; import org.openide.cookies.ProjectCookie; import org.openide.loaders.*; import org.openide.nodes.*; import org.openide.util.HelpCtx; import org.openide.util.NbBundle; import org.openide.util.UserCancelException; import org.openide.util.actions.CallableSystemAction; /** The OpenProject Action. * * @author Jaroslav Tulach */ public class OpenProjectAction extends CallableSystemAction implements Runnable { /** generated Serialized Version UID */ private static final long serialVersionUID = -1785983127137412341L; /* @return the action's icon */ public String getName() { return NbBundle.getBundle("org.openide.deprecated.Bundle", Locale.getDefault(), StepOutAction.class.getClassLoader()).getString("OpenProject"); } /* @return the action's help context */ public HelpCtx getHelpCtx() { return new HelpCtx (OpenProjectAction.class); } /* @return the action's icon */ public String iconResource() { return "org/openide/deprecated/openProject.gif"; // NOI18N } /* Action performed, opens dialog that allows user to choose a project. * It is then opened. */ public void performAction () { try { Panel panel = new Panel (); Node n = TopManager.getDefault ().getNodeOperation ().select ( NbBundle.getBundle("org.openide.deprecated.Bundle", Locale.getDefault(), StepOutAction.class.getClassLoader()).getString("CTL_OpenTitle"), NbBundle.getBundle("org.openide.deprecated.Bundle", Locale.getDefault(), StepOutAction.class.getClassLoader()).getString("CTL_OpenDescr"), getProjectRoot (panel), /* filter */panel )[0]; final ProjectCookie c = (ProjectCookie)n.getCookie (ProjectCookie.class); TopManager.getDefault ().openProject (c); } catch (UserCancelException e) { } catch (IOException e) { ErrorManager.getDefault ().notify (e); } } /** Create a hierarchy of templates. * @return a node representing all possible templates */ private static Node getProjectRoot (DataFilter ff) { DataFolder f = TopManager.getDefault ().getPlaces ().folders ().projects (); // listener used as filter (has method acceptDataObject) Children ch = f.createNodeChildren (ff); // filter the children ch = new ProjectChildren (new AbstractNode (ch)); // create the root return new PresentationFilterNode (f.getNodeDelegate (), ch); } /** @deprecated does nothing */ public void run() { } /** Actions listener which instantiates the template */ private static class Panel extends Object implements NodeAcceptor, DataFilter { static final long serialVersionUID =-3217011757079457914L; Panel() {} /** Data filter impl. */ public boolean acceptDataObject (DataObject obj) { return obj.getCookie (ProjectCookie.class) != null; } public boolean acceptNodes (Node[] n) { if (n.length != 1) { return false; } return n[0].getCookie (ProjectCookie.class) != null; } } /** Filter node children, that stops on data objects (does not go futher) */ private static class ProjectChildren extends FilterNode.Children { public ProjectChildren (Node or) { super (or); } protected Node copyNode (Node n) { DataFolder df = (DataFolder)n.getCookie (DataFolder.class); if (df == null) { // on normal nodes stop recursion return new PresentationFilterNode (n, LEAF); } else { // on folders use normal filtering return new PresentationFilterNode (n, new ProjectChildren (n)); } } } /* public static void main (String[] args) { new OpenProjectAction ().performAction (); } */ private static class PresentationFilterNode extends FilterNode { public PresentationFilterNode(org.openide.nodes.Node node, org.openide.nodes.Children children) { super(node, children); } public PresentationFilterNode(org.openide.nodes.Node node) { super(node); } public boolean canCopy() { return false; } public boolean canCut() { return false; } public boolean canDestroy() { return false; } public boolean canRename() { return false; } } } |
... 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.