1 19 20 package org.netbeans.modules.subversion.ui.update; 21 22 import org.netbeans.modules.subversion.ui.actions.ContextAction; 23 import org.netbeans.modules.subversion.util.Context; 24 import org.netbeans.modules.subversion.util.SvnUtils; 25 import org.netbeans.api.project.Project; 26 import org.netbeans.spi.project.SubprojectProvider; 27 import org.openide.nodes.Node; 28 import org.openide.util.RequestProcessor; 29 30 import java.util.*; 31 import org.netbeans.modules.subversion.FileInformation; 32 33 38 public class UpdateWithDependenciesAction extends ContextAction { 39 40 private boolean running; 41 42 protected int getFileEnabledStatus() { 43 return FileInformation.STATUS_IN_REPOSITORY; 44 } 45 46 protected int getDirectoryEnabledStatus() { 47 return FileInformation.STATUS_MANAGED 48 & ~FileInformation.STATUS_NOTVERSIONED_EXCLUDED 49 & ~FileInformation.STATUS_NOTVERSIONED_NEWLOCALLY; 50 } 51 52 protected String getBaseName(Node[] nodes) { 53 return "CTL_MenuItem_UpdateWithDependencies"; } 55 56 protected boolean enable(Node[] nodes) { 57 for (int i = 0; i < nodes.length; i++) { 58 Node node = nodes[i]; 59 if (SvnUtils.isVersionedProject(node) == false) { 60 return false; 61 } 62 } 63 return !running && super.enable(nodes); 64 } 65 66 protected void performContextAction(final Node[] nodes) { 67 running = true; 68 RequestProcessor.getDefault().post(new Runnable () { 69 public void run() { 70 try { 71 updateWithDependencies(nodes); 72 } finally { 73 running = false; 74 } 75 } 76 }); 77 } 78 79 private void updateWithDependencies(Node[] nodes) { 80 Set<Project> projectsToUpdate = new HashSet<Project>(nodes.length * 2); 81 for (Node node : nodes) { 82 Project project = (Project) node.getLookup().lookup(Project.class); 83 projectsToUpdate.add(project); 84 SubprojectProvider deps = (SubprojectProvider) project.getLookup().lookup(SubprojectProvider.class); 85 Set<? extends Project> children = deps.getSubprojects(); 86 for (Project child : children) { 87 if (SvnUtils.isVersionedProject(child)) { 88 projectsToUpdate.add(child); 89 } 90 } 91 } 92 Context context = SvnUtils.getProjectsContext(projectsToUpdate.toArray(new Project[projectsToUpdate.size()])); 93 UpdateAction.performUpdate(context); 94 } 95 } 96 | Popular Tags |