1 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 ; 34 import java.awt.*; 35 36 41 public class StatusProjectsAction extends SystemAction { 42 43 public StatusProjectsAction() { 44 setIcon(null); 45 putValue("noIconInMenu", Boolean.TRUE); } 47 48 public String 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 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 e) { 73 RequestProcessor.getDefault().post(new Runnable () { 74 public void run() { 75 async(); 76 } 77 }); 78 } 79 80 private void async() { 81 try { 82 setEnabled(false); 83 SwingUtilities.invokeLater(new Runnable () { 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 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 () { 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 |