1 19 package org.netbeans.modules.localhistory.ui.revert; 20 21 import java.io.File ; 22 import java.io.FileFilter ; 23 import java.text.DateFormat ; 24 import java.text.ParseException ; 25 import java.text.SimpleDateFormat ; 26 import java.util.Date ; 27 import javax.swing.event.DocumentEvent ; 28 import javax.swing.event.DocumentListener ; 29 import org.netbeans.modules.localhistory.LocalHistory; 30 import org.netbeans.modules.localhistory.store.StoreEntry; 31 import org.netbeans.modules.localhistory.utils.Utils; 32 import org.netbeans.modules.versioning.util.FlatFolder; 33 34 38 public class RevertFolderChanges extends RevertChanges implements DocumentListener { 39 40 public final static DateFormat TS_FORMAT = new SimpleDateFormat ("yyyy-MM-dd HH:mm"); 41 private RevertFolderPanel panel; 42 43 void show(File root) { 44 panel = new RevertFolderPanel(); 45 panel.dateTextField.setText(TS_FORMAT.format(new Date (System.currentTimeMillis()))); 46 panel.dateTextField.getDocument().addDocumentListener(this); 47 if(show(panel)) { 48 revertFolder(root, getTimeStamp()); 50 } 51 } 52 53 private void revertFolder(File root, long ts) { 54 File [] files = root.listFiles(); 56 StoreEntry[] entries = LocalHistory.getInstance().getLocalHistoryStore().getFolderState(root, files, ts); 57 for(StoreEntry entry : entries) { 58 Utils.revert(entry); 59 } 60 61 if(root instanceof FlatFolder) { 62 return; } 64 65 File [] revertedFolders = root.listFiles(new FileFilter () { 68 public boolean accept(File file) { 69 return file.isDirectory(); 70 } 71 }); 72 for(File revertedFolder : revertedFolders) { 73 revertFolder(revertedFolder, ts); 74 } 75 } 76 77 private long getTimeStamp() { 78 Date date; 79 try { 80 date = TS_FORMAT.parse(panel.dateTextField.getText()); 81 } catch(ParseException e) { 82 return -1; 84 } 85 return date.getTime(); 86 } 87 88 public void insertUpdate(DocumentEvent arg0) { 89 validateUserInput(); 90 } 91 92 public void removeUpdate(DocumentEvent arg0) { 93 validateUserInput(); 94 } 95 96 public void changedUpdate(DocumentEvent arg0) { 97 validateUserInput(); 98 } 99 100 private void validateUserInput() { 101 setValid(panel.dateTextField.isEditValid()); 102 } 103 } 104 | Popular Tags |