KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > localhistory > ui > view > ShowLocalHistoryAction


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.view;
20
21 import java.beans.PropertyChangeEvent JavaDoc;
22 import java.beans.PropertyChangeListener JavaDoc;
23 import org.netbeans.modules.localhistory.ui.view.LocalHistoryDiffView;
24 import java.io.File JavaDoc;
25 import java.util.Set JavaDoc;
26 import javax.swing.SwingUtilities JavaDoc;
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 /**
36  *
37  * @author Tomas Stupka
38  * // XXX context
39  */

40 public class ShowLocalHistoryAction extends NodeAction {
41     
42     /** Creates a new instance of ShowLocalHistoryAction */
43     public ShowLocalHistoryAction() {
44         setIcon(null);
45         putValue("noIconInMenu", Boolean.TRUE); // NOI18N
46
}
47     
48     protected void performAction(final Node[] activatedNodes) {
49         VCSContext ctx = VCSContext.forNodes(activatedNodes);
50         final Set JavaDoc<File JavaDoc> rootSet = ctx.getRootFiles();
51
52         SwingUtilities.invokeLater(new Runnable JavaDoc() {
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 JavaDoc[] files = rootSet.toArray(new File JavaDoc[rootSet.size()]);
60                 if(files[0].isFile()) {
61                     // XXX hm
62
LocalHistoryFileView fileView = new LocalHistoryFileView(files);
63                     LocalHistoryDiffView diffView = new LocalHistoryDiffView();
64                     fileView.getExplorerManager().addPropertyChangeListener(diffView);
65                     fileView.getExplorerManager().addPropertyChangeListener(new PropertyChangeListener JavaDoc() {
66                         public void propertyChange(PropertyChangeEvent JavaDoc 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 JavaDoc<File JavaDoc> rootSet = ctx.getRootFiles();
85         if(rootSet == null) {
86             return false;
87         }
88         for (File JavaDoc file : rootSet) {
89             if(file != null && !file.isFile()) {
90
91                 return false;
92             }
93
94         }
95         return true;
96         
97 // boolean files = false;
98
// boolean folders = false;
99
// for (File file : rootSet) {
100
// if(file.isFile()) {
101
// if(folders) {
102
// return false;
103
// }
104
// files = true;
105
// }
106
// if(!file.isFile()) {
107
// if(files) {
108
// return false;
109
// }
110
// folders = true;
111
// }
112
// }
113
// return files && !folders || !files && folders;
114
}
115     
116     public String JavaDoc 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