1 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 ; 30 31 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 getBaseName(Node [] activatedNodes) { 43 int actionStatus = getActionStatus(activatedNodes); 44 switch (actionStatus) { 45 case UNDEFINED: 46 case IGNORING: 47 return "CTL_MenuItem_Ignore"; case UNIGNORING: 49 return "CTL_MenuItem_Unignore"; default: 51 throw new RuntimeException ("Invalid action status: " + actionStatus); } 53 } 54 55 public int getActionStatus(Node [] nodes) { 56 return getActionStatus(Utils.getCurrentContext(nodes).getFiles()); 57 } 58 59 public int getActionStatus(File [] 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")) { 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 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 ("Invalid action status: " + actionStatus); } 97 } 98 99 protected boolean asynchronous() { 100 return false; 101 } 102 103 } 104 | Popular Tags |