KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > versioning > system > cvss > ui > actions > ignore > IgnoreAction


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.versioning.system.cvss.ui.actions.ignore;
21
22 import org.netbeans.modules.versioning.system.cvss.FileInformation;
23 import org.netbeans.modules.versioning.system.cvss.CvsVersioningSystem;
24 import org.netbeans.modules.versioning.system.cvss.FileStatusCache;
25 import org.netbeans.modules.versioning.system.cvss.util.Utils;
26 import org.netbeans.modules.versioning.system.cvss.ui.actions.AbstractSystemAction;
27 import org.openide.nodes.Node;
28
29 import java.io.File JavaDoc;
30
31 /**
32  * Adds files to .cvsignore file.
33  *
34  * @author Maros Sandor
35  */

36 public class IgnoreAction extends AbstractSystemAction {
37     
38     public static final int UNDEFINED = 0;
39     public static final int IGNORING = 1;
40     public static final int UNIGNORING = 2;
41     
42     protected String JavaDoc getBaseName(Node [] activatedNodes) {
43         int actionStatus = getActionStatus(activatedNodes);
44         switch (actionStatus) {
45         case UNDEFINED:
46         case IGNORING:
47             return "CTL_MenuItem_Ignore"; // NOI18N
48
case UNIGNORING:
49             return "CTL_MenuItem_Unignore"; // NOI18N
50
default:
51             throw new RuntimeException JavaDoc("Invalid action status: " + actionStatus); // NOI18N
52
}
53     }
54
55     public int getActionStatus(Node [] nodes) {
56         return getActionStatus(Utils.getCurrentContext(nodes).getFiles());
57     }
58
59     public int getActionStatus(File JavaDoc [] files) {
60         int actionStatus = -1;
61         FileStatusCache cache = CvsVersioningSystem.getInstance().getStatusCache();
62         for (int i = 0; i < files.length; i++) {
63             if (files[i].getName().equals(".cvsignore")) { // NOI18N
64
actionStatus = UNDEFINED;
65                 break;
66             }
67             FileInformation info = cache.getStatus(files[i]);
68             if (info.getStatus() == FileInformation.STATUS_NOTVERSIONED_NEWLOCALLY) {
69                 actionStatus = (actionStatus == -1 || actionStatus == IGNORING) ? IGNORING : UNDEFINED;
70             } else if (info.getStatus() == FileInformation.STATUS_NOTVERSIONED_EXCLUDED) {
71                 actionStatus = ((actionStatus == -1 || actionStatus == UNIGNORING) && canBeUnignored(files[i])) ? UNIGNORING : UNDEFINED;
72             } else {
73                 actionStatus = UNDEFINED;
74                 break;
75             }
76         }
77         return actionStatus == -1 ? UNDEFINED : actionStatus;
78     }
79     
80     private boolean canBeUnignored(File JavaDoc file) {
81         return CvsVersioningSystem.getInstance().isInCvsIgnore(file);
82     }
83
84     protected boolean enable(Node[] nodes) {
85         return getActionStatus(nodes) != UNDEFINED;
86     }
87
88     public void performCvsAction(Node[] nodes) {
89         int actionStatus = getActionStatus(nodes);
90         if (actionStatus == IGNORING) {
91             CvsVersioningSystem.getInstance().setIgnored(Utils.getCurrentContext(nodes).getFiles());
92         } else if (actionStatus == UNIGNORING) {
93             CvsVersioningSystem.getInstance().setNotignored(Utils.getCurrentContext(nodes).getFiles());
94         } else {
95             throw new RuntimeException JavaDoc("Invalid action status: " + actionStatus); // NOI18N
96
}
97     }
98
99     protected boolean asynchronous() {
100         return false;
101     }
102
103 }
104
Popular Tags