1 19 package org.netbeans.modules.versioning.system.cvss.ui.actions.commit; 20 21 import org.openide.util.NbBundle; 22 import org.openide.util.actions.Presenter; 23 import org.openide.awt.Mnemonics; 24 import org.netbeans.modules.versioning.system.cvss.CvsModuleConfig; 25 import org.netbeans.modules.versioning.spi.VCSContext; 26 27 import javax.swing.*; 28 import java.io.File ; 29 import java.awt.event.ActionEvent ; 30 import java.util.*; 31 32 37 public class ExcludeFromCommitAction extends AbstractAction implements Presenter.Menu { 38 39 private final VCSContext ctx; 40 private final int status; 41 42 public ExcludeFromCommitAction(VCSContext ctx) { 43 this.ctx = ctx; 44 putValue(Action.NAME, NbBundle.getBundle(ExcludeFromCommitAction.class).getString("CTL_MenuItem_ExcludeFromCommit")); 45 status = getActionStatus(); 46 if (status == 1) { 47 putValue("BooleanState.Selected", Boolean.FALSE); } else if (status == 2) { 49 putValue("BooleanState.Selected", Boolean.TRUE); } 51 setEnabled(status != -1); 52 } 53 54 public JMenuItem getMenuPresenter() { 55 JCheckBoxMenuItem item = new JCheckBoxMenuItem(this); 56 if (status != -1) item.setSelected(status == 2); 57 Mnemonics.setLocalizedText(item, item.getText()); 58 return item; 59 } 60 61 private int getActionStatus() { 62 CvsModuleConfig config = CvsModuleConfig.getDefault(); 63 Set<File > files = ctx.getRootFiles(); 64 int status = -1; 65 for (File file : files) { 66 if (config.isExcludedFromCommit(file)) { 67 if (status == 1) return -1; 68 status = 2; 69 } 70 else { 71 if (status == 2) return -1; 72 status = 1; 73 } 74 } 75 return status; 76 } 77 78 public void actionPerformed(ActionEvent e) { 79 CvsModuleConfig config = CvsModuleConfig.getDefault(); 80 Set<File > files = ctx.getRootFiles(); 81 for (File file : files) { 82 if (status == 1) { 83 config.addExclusion(file); 84 } else if (status == 2) { 85 config.removeExclusion(file); 86 } 87 } 88 } 89 } 90 | Popular Tags |