1 19 20 package org.netbeans.modules.subversion.ui.commit; 21 22 import java.io.*; 23 import java.util.List ; 24 import java.util.ArrayList ; 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 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 getBaseName(Node [] activatedNodes) { 54 int actionStatus = getActionStatus(activatedNodes); 55 switch (actionStatus) { 56 case UNDEFINED: 57 case EXCLUDING: 58 return "popup_commit_exclude"; case INCLUDING: 60 return "popup_commit_include"; default: 62 throw new RuntimeException ("Invalid action status: " + actionStatus); } 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 <String > paths = new ArrayList <String >(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 |