KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > project > ui > actions > OpenSubprojects


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.project.ui.actions;
21
22 import org.netbeans.api.project.Project;
23 import org.netbeans.modules.project.ui.OpenProjectList;
24 import org.netbeans.spi.project.SubprojectProvider;
25 import org.openide.util.HelpCtx;
26 import org.openide.util.NbBundle;
27 import org.openide.util.actions.NodeAction;
28
29 /** Action opening all "subprojects" of given project
30  */

31 public class OpenSubprojects extends NodeAction {
32
33     private static final String JavaDoc ICON = "org/netbeans/modules/project/ui/resources/openProject.gif"; //NOI18N
34

35     /** Creates a new instance of BrowserAction */
36     public OpenSubprojects() {
37     }
38         
39     public String JavaDoc getName() {
40         return NbBundle.getMessage( OpenSubprojects.class, "LBL_OpenSubprojectsAction_Name" ); // NOI18N
41
}
42     
43     public String JavaDoc iconResource() {
44         return ICON;
45     }
46     
47     public HelpCtx getHelpCtx() {
48         return HelpCtx.DEFAULT_HELP;
49     }
50     
51     protected boolean asynchronous() {
52         return false;
53     }
54     
55     protected boolean enable(org.openide.nodes.Node[] activatedNodes) {
56         
57         if ( activatedNodes == null || activatedNodes.length == 0 ) {
58             return false; // No nodes no closing
59
}
60         
61         // Find out whether all nodes have project in lookup
62
boolean someSubprojects = false; // And have some subprojects;
63
for( int i = 0; i < activatedNodes.length; i++ ) {
64             Project p = (Project)activatedNodes[i].getLookup().lookup( Project.class );
65             if ( p == null ) {
66                 return false;
67             }
68             else {
69                 
70                 SubprojectProvider spp = (SubprojectProvider)p.getLookup().lookup( SubprojectProvider.class );
71                 
72                 if ( spp != null && !spp.getSubprojects().isEmpty() ) {
73                     someSubprojects = true;
74                 }
75             }
76         }
77         
78         return someSubprojects;
79     }
80     
81     protected void performAction(org.openide.nodes.Node[] activatedNodes) {
82     
83         for( int i = 0; i < activatedNodes.length; i++ ) {
84             Project p = (Project)activatedNodes[i].getLookup().lookup( Project.class );
85             if ( p != null ) {
86                 OpenProjectList.getDefault().open(new Project[] {p}, true, true);
87             }
88         }
89         
90     }
91     
92 }
93
Popular Tags