1 19 package org.netbeans.modules.localhistory.ui.revert; 20 21 import java.awt.Dimension ; 22 import java.beans.PropertyChangeEvent ; 23 import java.beans.PropertyChangeListener ; 24 import java.io.File ; 25 import org.netbeans.modules.localhistory.LocalHistorySettings; 26 import org.netbeans.modules.localhistory.store.StoreEntry; 27 import org.netbeans.modules.localhistory.ui.view.LocalHistoryFileView; 28 import org.netbeans.modules.localhistory.utils.Utils; 29 import org.openide.nodes.Node; 30 import org.openide.util.RequestProcessor; 31 32 36 public class RevertFileChanges extends RevertChanges implements PropertyChangeListener { 37 38 void show(File root) { 39 40 long ts = LocalHistorySettings.getInstance().getLastSelectedEntry(root); 41 LocalHistoryFileView view = new LocalHistoryFileView (new File [] {root}, ts); 42 view.getPanel().setPreferredSize(new Dimension (550, 250)); 43 if(show(view.getPanel())) { 44 StoreEntry[] entries = view.getSelectedEntries(); 45 if(entries != null && entries.length > 0) { 46 revert(entries[0]); 47 LocalHistorySettings.getInstance().setLastSelectedEntry(root, entries[0].getTimestamp()); 48 } 49 } 50 } 51 52 private void revert(final StoreEntry entry) { 53 RequestProcessor.getDefault().post(new Runnable () { 54 public void run() { 55 Utils.revert(entry); 56 } 57 }); 58 } 59 60 public void propertyChange(PropertyChangeEvent evt) { 61 setValid(isEnabled((Node[])evt.getNewValue())); 62 } 63 64 private boolean isEnabled(Node[] nodes) { 65 if(nodes == null || nodes.length != 1) { 66 return false; 67 } 68 for(Node node : nodes) { 69 StoreEntry se = node.getLookup().lookup(StoreEntry.class); 70 if(se == null) { 71 return false; 72 } 73 } 74 return true; 75 } 76 } 77 | Popular Tags |