KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > versioning > system > cvss > ui > actions > status > StatusProjectsAction


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
20 package org.netbeans.modules.versioning.system.cvss.ui.actions.status;
21
22 import org.netbeans.modules.versioning.system.cvss.ui.syncview.CvsSynchronizeTopComponent;
23 import org.netbeans.modules.versioning.system.cvss.util.Utils;
24 import org.netbeans.modules.versioning.system.cvss.util.Context;
25 import org.netbeans.api.project.ui.OpenProjects;
26 import org.netbeans.api.project.*;
27 import org.openide.util.NbBundle;
28 import org.openide.util.HelpCtx;
29 import org.openide.util.RequestProcessor;
30 import org.openide.util.actions.SystemAction;
31
32 import javax.swing.*;
33 import java.awt.event.ActionEvent JavaDoc;
34 import java.awt.*;
35
36 /**
37  * Open the Versioning status view for all projects.
38  *
39  * @author Maros Sandor
40  */

41 public class StatusProjectsAction extends SystemAction {
42
43     public StatusProjectsAction() {
44         setIcon(null);
45         putValue("noIconInMenu", Boolean.TRUE); // NOI18N
46
}
47
48     public String JavaDoc getName() {
49         return NbBundle.getMessage(StatusProjectsAction.class, "CTL_MenuItem_StatusProjects_Label");
50     }
51
52     public HelpCtx getHelpCtx() {
53         return new HelpCtx(StatusProjectsAction.class);
54     }
55
56     /**
57      * Enabled for opened project and if no Versining view refresh in progress.
58      */

59     public boolean isEnabled() {
60         if (super.isEnabled()) {
61             Project projects[] = OpenProjects.getDefault().getOpenProjects();
62             for (int i = 0; i < projects.length; i++) {
63                 Project project = projects[i];
64                 if (Utils.isVersionedProject(project)) {
65                     return true;
66                 }
67             }
68         }
69         return false;
70     }
71
72     public void actionPerformed(ActionEvent JavaDoc e) {
73         RequestProcessor.getDefault().post(new Runnable JavaDoc() {
74             public void run() {
75                 async();
76             }
77         });
78     }
79
80     private void async() {
81         try {
82             setEnabled(false);
83             SwingUtilities.invokeLater(new Runnable JavaDoc() {
84                 public void run() {
85                     CvsSynchronizeTopComponent stc = CvsSynchronizeTopComponent.getInstance();
86                     stc.setContext(null);
87                     stc.open();
88                 }
89             });
90
91             Project [] projects = OpenProjects.getDefault().getOpenProjects();
92
93             final Context ctx = Utils.getProjectsContext(projects);
94             final String JavaDoc title;
95             if (projects.length == 1) {
96                 Project project = projects[0];
97                 ProjectInformation pinfo = ProjectUtils.getInformation(project);
98                 title = pinfo.getDisplayName();
99             } else {
100                 title = NbBundle.getMessage(StatusProjectsAction.class, "CTL_StatusProjects_WindowTitle", Integer.toString(projects.length));
101             }
102             SwingUtilities.invokeLater(new Runnable JavaDoc() {
103                 public void run() {
104                     CvsSynchronizeTopComponent stc = CvsSynchronizeTopComponent.getInstance();
105                     stc.setContentTitle(title);
106                     stc.setContext(ctx);
107                     stc.open();
108                     stc.requestActive();
109                     if (shouldPostRefresh()) {
110                         stc.performRefreshAction();
111                     }
112                 }
113             });
114
115         } finally {
116             setEnabled(true);
117         }
118
119     }
120
121     protected boolean shouldPostRefresh() {
122         return true;
123     }
124 }
125
126
Popular Tags