Removed unused ServeAction.
[nbgit.git] / src / org / netbeans / modules / git / ui / commit / ExcludeFromCommitAction.java
blob4c7038a717bb3acbc91d05563d9d2ce7b9f7dc8e
1 /*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6 * The contents of this file are subject to the terms of either the GNU
7 * General Public License Version 2 only ("GPL") or the Common
8 * Development and Distribution License("CDDL") (collectively, the
9 * "License"). You may not use this file except in compliance with the
10 * License. You can obtain a copy of the License at
11 * http://www.netbeans.org/cddl-gplv2.html
12 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13 * specific language governing permissions and limitations under the
14 * License. When distributing the software, include this License Header
15 * Notice in each file and include the License file at
16 * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17 * particular file as subject to the "Classpath" exception as provided
18 * by Sun in the GPL Version 2 section of the License file that
19 * accompanied this code. If applicable, add the following below the
20 * License Header, with the fields enclosed by brackets [] replaced by
21 * your own identifying information:
22 * "Portions Copyrighted [year] [name of copyright owner]"
24 * Contributor(s):
26 * The Original Software is NetBeans. The Initial Developer of the Original
27 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28 * Microsystems, Inc. All Rights Reserved.
29 * Portions Copyright 2008 Alexander Coles (Ikonoklastik Productions).
31 * If you wish your version of this file to be governed by only the CDDL
32 * or only the GPL Version 2, indicate your decision by adding
33 * "[Contributor] elects to include this software in this distribution
34 * under the [CDDL or GPL Version 2] license." If you do not indicate a
35 * single choice of license, a recipient has the option to distribute
36 * your version of this file under either the CDDL, the GPL Version 2 or
37 * to extend the choice of license to its licensees as provided above.
38 * However, if you add GPL Version 2 code and therefore, elected the GPL
39 * Version 2 license, then the option applies only if the new code is
40 * made subject to such option by the copyright holder.
42 package org.netbeans.modules.git.ui.commit;
44 import java.awt.event.ActionEvent;
45 import java.io.File;
46 import java.util.ArrayList;
47 import java.util.List;
48 import java.util.Set;
49 import javax.swing.Action;
50 import org.netbeans.modules.git.FileInformation;
51 import org.netbeans.modules.git.Git;
52 import org.netbeans.modules.git.GitModuleConfig;
53 import org.netbeans.modules.git.GitProgressSupport;
54 import org.netbeans.modules.git.ui.actions.ContextAction;
55 import org.netbeans.modules.versioning.spi.VCSContext;
56 import org.openide.util.RequestProcessor;
59 /**
61 * @author Petr Kuzel
63 public final class ExcludeFromCommitAction extends ContextAction {
65 public static final int UNDEFINED = -1;
66 public static final int EXCLUDING = 1;
67 public static final int INCLUDING = 2;
69 private final VCSContext context;
71 public ExcludeFromCommitAction(String name, VCSContext context) {
72 this.context = context;
73 putValue(Action.NAME, name);
76 protected boolean enable(VCSContext ctx) {
77 return getActionStatus(ctx) != UNDEFINED;
80 protected int getFileEnabledStatus() {
81 return FileInformation.STATUS_LOCAL_CHANGE;
84 protected int getDirectoryEnabledStatus() {
85 return FileInformation.STATUS_LOCAL_CHANGE;
88 protected String getBaseName(VCSContext ctx) {
89 int actionStatus = getActionStatus(ctx);
90 switch (actionStatus) {
91 case UNDEFINED:
92 case EXCLUDING:
93 return "popup_commit_exclude"; // NOI18N
94 case INCLUDING:
95 return "popup_commit_include"; // NOI18N
96 default:
97 throw new RuntimeException("Invalid action status: " + actionStatus); // NOI18N
101 public int getActionStatus(VCSContext ctx) {
102 GitModuleConfig config = GitModuleConfig.getDefault();
103 int status = UNDEFINED;
104 if (ctx == null) ctx = context;
105 Set<File> files = ctx.getRootFiles();
106 for (File file : files) {
107 if (config.isExcludedFromCommit(file.getAbsolutePath())) {
108 if (status == EXCLUDING) {
109 return UNDEFINED;
111 status = INCLUDING;
112 } else {
113 if (status == INCLUDING) {
114 return UNDEFINED;
116 status = EXCLUDING;
119 return status;
122 public void performAction(ActionEvent e) {
123 final VCSContext ctx = context;
124 RequestProcessor rp = Git.getInstance().getRequestProcessor();
125 GitProgressSupport support = new GitProgressSupport() {
126 public void perform() {
127 GitModuleConfig config = GitModuleConfig.getDefault();
128 int status = getActionStatus(ctx);
129 Set<File> files = ctx.getRootFiles();
130 List<String> paths = new ArrayList<String>(files.size());
131 for (File file : files) {
132 paths.add(file.getAbsolutePath());
134 if (isCanceled()) return;
135 if (status == EXCLUDING) {
136 config.addExclusionPaths(paths);
137 } else if (status == INCLUDING) {
138 config.removeExclusionPaths(paths);
142 support.start(rp, "", ""); // NOI18N