KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > ruby > railsprojects > ui > RemoveClassPathRootAction


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.ruby.railsprojects.ui;
21
22
23 import org.openide.nodes.Node;
24 import org.openide.util.NbBundle;
25 import org.openide.util.HelpCtx;
26 import org.openide.util.actions.NodeAction;
27 import org.netbeans.modules.ruby.spi.project.support.rake.EditableProperties;
28
29 import java.util.Iterator JavaDoc;
30
31 /**
32  * Action for removing an ClassPathRoot. The action looks up
33  * the {@link RemoveClassPathRootAction.Removable} in the
34  * activated node's Lookups and delegates to it.
35  * @author Tomas Zezula
36  */

37 final class RemoveClassPathRootAction extends NodeAction {
38
39     /**
40      * Implementation of this interfaces has to be placed
41      * into the node's Lookup to allow {@link RemoveClassPathRootAction}
42      * on the node.
43      */

44     static interface Removable {
45         /**
46          * Checks if the classpath root can be removed
47          * @return returns true if the action should be enabled
48          */

49         public boolean canRemove ();
50
51         /**
52          * Removes the classpath root
53          */

54         public abstract void remove ();
55     }
56
57     protected void performAction(Node[] activatedNodes) {
58         for (int i=0; i<activatedNodes.length; i++) {
59             Removable removable = (Removable) activatedNodes[i].getLookup().lookup(Removable.class);
60             if (removable!=null) {
61                 removable.remove();
62             }
63         }
64     }
65
66     protected boolean enable(Node[] activatedNodes) {
67         for (int i=0; i<activatedNodes.length; i++) {
68             Removable removable = (Removable) activatedNodes[i].getLookup().lookup(Removable.class);
69             if (removable==null) {
70                 return false;
71             }
72             if (!removable.canRemove()) {
73                 return false;
74             }
75         }
76         return true;
77     }
78
79     public String JavaDoc getName() {
80         return NbBundle.getMessage (RemoveClassPathRootAction.class,"CTL_RemoveProject");
81     }
82
83     public HelpCtx getHelpCtx() {
84         return new HelpCtx (RemoveClassPathRootAction.class);
85     }
86
87     protected boolean asynchronous() {
88         return false;
89     }
90
91     /**
92      * Checks if the reference is still used in the project.
93      * @param props the array of {@link EditableProperties} which
94      * should be checked.
95      * @param reference
96      * @return true if the reference is used
97      */

98     public static boolean isReferenced (EditableProperties[] props, String JavaDoc reference) {
99         for (int i=0; i< props.length; i++) {
100             for (Iterator JavaDoc it = props[i].values().iterator(); it.hasNext();) {
101                 String JavaDoc value = (String JavaDoc) it.next ();
102                 if (value != null && value.indexOf(reference)>=0) {
103                     return true;
104                 }
105             }
106         }
107         return false;
108     }
109 }
110
Popular Tags