1 19 20 package org.netbeans.modules.versioning.system.cvss.ui.actions.project; 21 22 import org.openide.util.actions.SystemAction; 23 import org.openide.util.HelpCtx; 24 import org.openide.util.NbBundle; 25 import org.openide.util.RequestProcessor; 26 import org.openide.nodes.Node; 27 import org.openide.windows.WindowManager; 28 import org.netbeans.modules.versioning.system.cvss.util.Utils; 29 import org.netbeans.modules.versioning.system.cvss.util.Context; 30 import org.netbeans.modules.versioning.system.cvss.ui.actions.update.UpdateExecutor; 31 import org.netbeans.modules.versioning.system.cvss.CvsVersioningSystem; 32 import org.netbeans.modules.versioning.system.cvss.ExecutorGroup; 33 import org.netbeans.modules.versioning.spi.VCSContext; 34 import org.netbeans.lib.cvsclient.command.update.UpdateCommand; 35 import org.netbeans.lib.cvsclient.command.GlobalOptions; 36 import org.netbeans.api.project.Project; 37 import org.netbeans.spi.project.SubprojectProvider; 38 39 import java.io.File ; 40 import java.util.*; 41 import java.awt.event.ActionEvent ; 42 43 50 public final class UpdateWithDependenciesAction extends SystemAction { 51 52 public UpdateWithDependenciesAction() { 53 setIcon(null); 54 putValue("noIconInMenu", Boolean.TRUE); } 56 57 public void actionPerformed(ActionEvent ev) { 58 setEnabled(false); 59 final Node nodes[] = WindowManager.getDefault().getRegistry().getActivatedNodes(); 60 RequestProcessor.getDefault().post(new Runnable () { 61 public void run() { 62 async(nodes); 63 } 64 }); 65 66 } 67 68 private void async(Node[] nodes) { 69 70 ExecutorGroup group = new ExecutorGroup(NbBundle.getMessage(UpdateWithDependenciesAction.class, "BK2001")); 71 try { 72 group.progress(NbBundle.getMessage(UpdateWithDependenciesAction.class, "BK2002")); 73 74 Set projects = new HashSet(); 75 Set<Context> contexts = new LinkedHashSet<Context>(); 76 77 for (int i = 0; i < nodes.length; i++) { 78 Node node = nodes[i]; 79 Project project = (Project) node.getLookup().lookup(Project.class); 80 addUpdateContexts(contexts, project, projects); 81 } 82 83 if (contexts.size() > 0) { 84 Context context = new Context(new HashSet(), new HashSet(), new HashSet()); 85 for (Context cx : contexts) { 86 context = context.union(cx); 87 } 88 UpdateCommand updateCommand = new UpdateCommand(); 89 updateCommand.setBuildDirectories(true); 90 updateCommand.setPruneDirectories(true); 91 updateCommand.setFiles(context.getFiles()); 92 93 GlobalOptions gtx = CvsVersioningSystem.createGlobalOptions(); 94 gtx.setExclusions((File []) context.getExclusions().toArray(new File [0])); 95 group.addExecutors(UpdateExecutor.splitCommand(updateCommand, CvsVersioningSystem.getInstance(), gtx, org.netbeans.modules.versioning.util.Utils.getContextDisplayName(VCSContext.forNodes(nodes)))); 96 97 group.execute(); 98 } 99 } finally { 100 setEnabled(true); 101 } 102 } 103 104 public boolean isEnabled() { 105 Node [] nodes = WindowManager.getDefault().getRegistry().getActivatedNodes(); 106 for (int i = 0; i < nodes.length; i++) { 107 Node node = nodes[i]; 108 if (Utils.isVersionedProject(node) == false) { 109 return false; 110 } 111 } 112 return nodes.length > 0; 113 } 114 115 protected boolean asynchronous() { 116 return false; 117 } 118 119 public String getName() { 120 return NbBundle.getMessage(UpdateWithDependenciesAction.class, "CTL_MenuItem_UpdateWithDependencies"); 121 } 122 123 public HelpCtx getHelpCtx() { 124 return null; 125 } 126 127 128 private static void addUpdateContexts(Collection contexts, Project project, Set updatedProjects) { 129 if (updatedProjects.contains(project)) { 130 return; 131 } 132 updatedProjects.add(project); 133 134 Context ctx = createProjectContext(project); 135 if (ctx.getFiles().length > 0) { 136 contexts.add(ctx); 137 } 138 139 SubprojectProvider deps = (SubprojectProvider) project.getLookup().lookup(SubprojectProvider.class); 140 Iterator it = deps.getSubprojects().iterator(); 141 while (it.hasNext()) { 142 Project subProject = (Project) it.next(); 143 addUpdateContexts(contexts, subProject, updatedProjects); } 145 } 146 147 private static Context createProjectContext(Project project) { 148 Set files = new HashSet(); 149 Set roots = new HashSet(); 150 Set excludes = new HashSet(); 151 152 Utils.addProjectFiles(files, roots, excludes, project); 154 Iterator it = files.iterator(); 155 while (it.hasNext()) { 156 File file = (File ) it.next(); 157 File probe = null; 158 if (file.isDirectory()) { 159 probe = new File (file, "CVS/Repository"); } 161 if (file.isFile()) { 162 probe = new File (file.getParentFile(), "CVS/Repository"); } 164 if (probe == null || probe.isFile() == false) { 165 it.remove(); 166 } 167 } 168 return new Context(files, roots, excludes); 169 } 170 171 } 172 | Popular Tags |