KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > subversion > ui > update > UpdateWithDependenciesAction


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.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 /**
34  * Updates selected projects and all projects they depend on.
35  *
36  * @author Maros Sandor
37  */

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 JavaDoc getBaseName(Node[] nodes) {
53         return "CTL_MenuItem_UpdateWithDependencies"; // NOI18N
54
}
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 JavaDoc() {
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