KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > subversion > ui > commit > ExcludeFromCommitAction


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.subversion.ui.commit;
21
22 import java.io.*;
23 import java.util.List JavaDoc;
24 import java.util.ArrayList JavaDoc;
25
26 import org.netbeans.modules.subversion.ui.actions.*;
27 import org.netbeans.modules.subversion.FileInformation;
28 import org.netbeans.modules.subversion.SvnModuleConfig;
29 import org.openide.nodes.*;
30
31 /**
32  *
33  * @author Petr Kuzel
34  */

35 public final class ExcludeFromCommitAction extends ContextAction {
36
37     public static final int UNDEFINED = -1;
38     public static final int EXCLUDING = 1;
39     public static final int INCLUDING = 2;
40
41     protected boolean enable(Node[] nodes) {
42         return getActionStatus(nodes) != UNDEFINED;
43     }
44
45     protected int getFileEnabledStatus() {
46         return FileInformation.STATUS_LOCAL_CHANGE;
47     }
48
49     protected int getDirectoryEnabledStatus() {
50         return FileInformation.STATUS_LOCAL_CHANGE;
51     }
52
53     protected String JavaDoc getBaseName(Node [] activatedNodes) {
54         int actionStatus = getActionStatus(activatedNodes);
55         switch (actionStatus) {
56         case UNDEFINED:
57         case EXCLUDING:
58             return "popup_commit_exclude"; // NOI18N
59
case INCLUDING:
60             return "popup_commit_include"; // NOI18N
61
default:
62             throw new RuntimeException JavaDoc("Invalid action status: " + actionStatus); // NOI18N
63
}
64     }
65     
66     public int getActionStatus(Node[] nodes) {
67         SvnModuleConfig config = SvnModuleConfig.getDefault();
68         File [] files = getContext(nodes).getFiles();
69         int status = UNDEFINED;
70         for (int i = 0; i < files.length; i++) {
71             if (config.isExcludedFromCommit(files[i].getAbsolutePath())) {
72                 if (status == EXCLUDING) {
73                     return UNDEFINED;
74                 }
75                 status = INCLUDING;
76             } else {
77                 if (status == INCLUDING) {
78                     return UNDEFINED;
79                 }
80                 status = EXCLUDING;
81             }
82         }
83         return status;
84     }
85
86     public void performContextAction(final Node[] nodes) {
87         ProgressSupport support = new ContextAction.ProgressSupport(this, nodes) {
88             public void perform() {
89                 SvnModuleConfig config = SvnModuleConfig.getDefault();
90                 int status = getActionStatus(nodes);
91                 File [] files = getContext(nodes).getFiles();
92                 List JavaDoc<String JavaDoc> paths = new ArrayList JavaDoc<String JavaDoc>(files.length);
93                 for (File file : files) {
94                     paths.add(file.getAbsolutePath());
95                 }
96                 if (isCanceled()) return;
97                 if (status == EXCLUDING) {
98                     config.addExclusionPaths(paths);
99                 } else if (status == INCLUDING) {
100                     config.removeExclusionPaths(paths);
101                 }
102             }
103         };
104         support.start(createRequestProcessor(nodes));
105     }
106
107 }
108
Popular Tags