KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > localhistory > ui > revert > RevertFileChanges


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.localhistory.ui.revert;
20
21 import java.awt.Dimension JavaDoc;
22 import java.beans.PropertyChangeEvent JavaDoc;
23 import java.beans.PropertyChangeListener JavaDoc;
24 import java.io.File JavaDoc;
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 /**
33  *
34  * @author Tomas Stupka
35  */

36 public class RevertFileChanges extends RevertChanges implements PropertyChangeListener JavaDoc {
37            
38     void show(File JavaDoc root) {
39                                 
40         long ts = LocalHistorySettings.getInstance().getLastSelectedEntry(root);
41         LocalHistoryFileView view = new LocalHistoryFileView (new File JavaDoc[] {root}, ts);
42         view.getPanel().setPreferredSize(new Dimension JavaDoc(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 JavaDoc() {
54             public void run() {
55                 Utils.revert(entry);
56             }
57         });
58     }
59
60     public void propertyChange(PropertyChangeEvent JavaDoc 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