1 19 package org.netbeans.modules.localhistory.ui.revert; 20 import java.io.File ; 21 import java.util.Set ; 22 import org.netbeans.modules.localhistory.ui.revert.RevertChanges; 23 import org.netbeans.modules.versioning.spi.VCSContext; 24 import org.openide.LifecycleManager; 25 import org.openide.nodes.Node; 26 import org.openide.util.HelpCtx; 27 import org.openide.util.NbBundle; 28 import org.openide.util.actions.NodeAction; 29 30 34 public class RevertToAction extends NodeAction { 35 36 public RevertToAction() { 37 setIcon(null); 38 putValue("noIconInMenu", Boolean.TRUE); } 40 41 public HelpCtx getHelpCtx() { 42 return new HelpCtx(getClass()); 43 } 44 45 protected boolean asynchronous() { 46 return false; 47 } 48 49 protected void performAction(final Node[] activatedNodes) { 50 LifecycleManager.getDefault().saveAll(); 55 56 VCSContext ctx = VCSContext.forNodes(activatedNodes); 57 final Set <File > rootSet = ctx.getRootFiles(); 58 File [] roots = rootSet.toArray(new File [rootSet.size()]); 59 60 RevertChanges revertChanges; 61 if(roots[0].isFile()) { 62 revertChanges = new RevertFileChanges(); 63 } else { 64 revertChanges = new RevertFolderChanges(); 65 } 66 revertChanges.show(roots[0]); 67 } 68 69 protected boolean enable(Node[] activatedNodes) { 70 if(activatedNodes == null || activatedNodes.length != 1) { 72 return false; 73 } 74 VCSContext ctx = VCSContext.forNodes(activatedNodes); 75 Set <File > rootSet = ctx.getRootFiles(); 76 return rootSet != null && rootSet.size() > 0; 77 } 78 79 public String getName() { 80 return getMenuName(); 81 } 82 83 public static String getMenuName() { 84 return NbBundle.getMessage(RevertToAction.class, "LBL_RevertToAction"); 85 } 86 } 87 | Popular Tags |