KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > subversion > ui > copy > MergeAction


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.copy;
21
22 import java.io.File JavaDoc;
23 import org.netbeans.modules.subversion.FileInformation;
24 import org.netbeans.modules.subversion.RepositoryFile;
25 import org.netbeans.modules.subversion.Subversion;
26 import org.netbeans.modules.subversion.client.SvnClient;
27 import org.netbeans.modules.subversion.client.SvnProgressSupport;
28 import org.netbeans.modules.subversion.ui.actions.ContextAction;
29 import org.netbeans.modules.subversion.util.Context;
30 import org.netbeans.modules.subversion.util.SvnUtils;
31 import org.netbeans.modules.versioning.util.Utils;
32 import org.openide.ErrorManager;
33 import org.openide.nodes.Node;
34 import org.tigris.subversion.svnclientadapter.ISVNLogMessage;
35 import org.tigris.subversion.svnclientadapter.SVNClientException;
36 import org.tigris.subversion.svnclientadapter.SVNRevision;
37 import org.tigris.subversion.svnclientadapter.SVNUrl;
38
39 /**
40  *
41  * @author Tomas Stupka
42  */

43 public class MergeAction extends ContextAction {
44
45     public MergeAction() {
46     }
47
48     protected String JavaDoc getBaseName(Node[] activatedNodes) {
49         return "CTL_MenuItem_Merge"; // NOI18N
50
}
51
52     protected int getFileEnabledStatus() {
53         return FileInformation.STATUS_MANAGED
54              & ~FileInformation.STATUS_NOTVERSIONED_EXCLUDED
55              & ~FileInformation.STATUS_NOTVERSIONED_NEWLOCALLY;
56     }
57
58     protected int getDirectoryEnabledStatus() {
59         return FileInformation.STATUS_MANAGED
60              & ~FileInformation.STATUS_NOTVERSIONED_EXCLUDED
61              & ~FileInformation.STATUS_NOTVERSIONED_NEWLOCALLY;
62     }
63     
64     protected void performContextAction(final Node[] nodes) {
65         Context ctx = getContext(nodes);
66         final File JavaDoc root = ctx.getRootFiles()[0];
67         SVNUrl url = SvnUtils.getRepositoryRootUrl(root);
68         final RepositoryFile repositoryRoot = new RepositoryFile(url, url, SVNRevision.HEAD);
69      
70         final Merge merge = new Merge(repositoryRoot, root);
71         if(merge.showDialog()) {
72             ContextAction.ProgressSupport support = new ContextAction.ProgressSupport(this, nodes) {
73                 public void perform() {
74                     performMerge(merge, repositoryRoot, root, this);
75                 }
76             };
77             support.start(createRequestProcessor(nodes));
78         }
79     }
80
81     private void performMerge(Merge merge, RepositoryFile repositoryRoot, File JavaDoc root, SvnProgressSupport support) {
82         File JavaDoc[][] split = Utils.splitFlatOthers(new File JavaDoc[] {root} );
83         boolean recursive;
84         // there can be only 1 root file
85
if(split[0].length > 0) {
86             recursive = false;
87         } else {
88             recursive = true;
89         }
90
91         try {
92             SvnClient client;
93             try {
94                 client = Subversion.getInstance().getClient(repositoryRoot.getRepositoryUrl());
95             } catch (SVNClientException ex) {
96                 ErrorManager.getDefault().notify(ex);
97                 return;
98             }
99
100             if(support.isCanceled()) {
101                 return;
102             }
103             
104             SVNUrl endUrl = merge.getMergeEndUrl();
105             SVNRevision endRevision = merge.getMergeEndRevision();
106                         
107             SVNUrl startUrl = merge.getMergeStartUrl();
108             SVNRevision startRevision;
109             if(startUrl != null) {
110                 startRevision = merge.getMergeStartRevision();
111             } else {
112                 // XXX is this the only way we can do it?
113
startUrl = endUrl;
114                 ISVNLogMessage[] log = client.getLogMessages(startUrl, new SVNRevision.Number(0), new SVNRevision.Number(0), SVNRevision.HEAD, true, false, 0L);
115                 startRevision = log[0].getRevision();
116             }
117             if(support.isCanceled()) {
118                 return;
119             }
120             
121             client.merge(startUrl,
122                          startRevision,
123                          endUrl,
124                          endRevision,
125                          root,
126                          false,
127                          recursive);
128
129         } catch (SVNClientException ex) {
130             support.annotate(ex);
131         }
132     }
133 }
134
Popular Tags