1 19 package org.netbeans.modules.localhistory.ui.view; 20 21 import java.beans.PropertyChangeEvent ; 22 import java.beans.PropertyChangeListener ; 23 import org.netbeans.modules.localhistory.ui.view.LocalHistoryDiffView; 24 import java.io.File ; 25 import java.util.Set ; 26 import javax.swing.SwingUtilities ; 27 import org.netbeans.modules.localhistory.ui.view.LocalHistoryTopComponent; 28 import org.netbeans.modules.versioning.spi.VCSContext; 29 import org.openide.explorer.ExplorerManager; 30 import org.openide.nodes.Node; 31 import org.openide.util.HelpCtx; 32 import org.openide.util.NbBundle; 33 import org.openide.util.actions.NodeAction; 34 35 40 public class ShowLocalHistoryAction extends NodeAction { 41 42 43 public ShowLocalHistoryAction() { 44 setIcon(null); 45 putValue("noIconInMenu", Boolean.TRUE); } 47 48 protected void performAction(final Node[] activatedNodes) { 49 VCSContext ctx = VCSContext.forNodes(activatedNodes); 50 final Set <File > rootSet = ctx.getRootFiles(); 51 52 SwingUtilities.invokeLater(new Runnable () { 53 public void run() { 54 final LocalHistoryTopComponent tc = new LocalHistoryTopComponent(); 55 tc.setName(NbBundle.getMessage(this.getClass(), "CTL_LocalHistoryTopComponent", activatedNodes[0].getDisplayName())); 56 tc.open(); 57 tc.requestActive(); 58 59 File [] files = rootSet.toArray(new File [rootSet.size()]); 60 if(files[0].isFile()) { 61 LocalHistoryFileView fileView = new LocalHistoryFileView(files); 63 LocalHistoryDiffView diffView = new LocalHistoryDiffView(); 64 fileView.getExplorerManager().addPropertyChangeListener(diffView); 65 fileView.getExplorerManager().addPropertyChangeListener(new PropertyChangeListener () { 66 public void propertyChange(PropertyChangeEvent evt) { 67 if(ExplorerManager.PROP_SELECTED_NODES.equals(evt.getPropertyName())) { 68 tc.setActivatedNodes((Node[]) evt.getNewValue()); 69 } 70 } 71 }); 72 tc.init(diffView.getPanel(), fileView); 73 } 74 } 75 }); 76 77 } 78 79 protected boolean enable(Node[] activatedNodes) { 80 if(activatedNodes == null || activatedNodes.length != 1) { 81 return false; 82 } 83 VCSContext ctx = VCSContext.forNodes(activatedNodes); 84 Set <File > rootSet = ctx.getRootFiles(); 85 if(rootSet == null) { 86 return false; 87 } 88 for (File file : rootSet) { 89 if(file != null && !file.isFile()) { 90 91 return false; 92 } 93 94 } 95 return true; 96 97 } 115 116 public String getName() { 117 return NbBundle.getMessage(this.getClass(), "CTL_ShowLocalHistory"); 118 } 119 120 public HelpCtx getHelpCtx() { 121 return new HelpCtx(ShowLocalHistoryAction.class); 122 } 123 124 } 125 | Popular Tags |