KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > versioning > system > cvss > ui > actions > tag > BranchAction


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.versioning.system.cvss.ui.actions.tag;
21
22 import org.netbeans.modules.versioning.system.cvss.ui.actions.AbstractSystemAction;
23 import org.netbeans.modules.versioning.system.cvss.ui.actions.update.UpdateExecutor;
24 import org.netbeans.modules.versioning.system.cvss.FileInformation;
25 import org.netbeans.modules.versioning.system.cvss.CvsVersioningSystem;
26 import org.netbeans.modules.versioning.system.cvss.ExecutorSupport;
27 import org.netbeans.modules.versioning.system.cvss.ExecutorGroup;
28 import org.netbeans.modules.versioning.system.cvss.util.Context;
29 import org.netbeans.lib.cvsclient.command.tag.TagCommand;
30 import org.netbeans.lib.cvsclient.command.update.UpdateCommand;
31 import org.netbeans.lib.cvsclient.command.GlobalOptions;
32 import org.openide.util.NbBundle;
33 import org.openide.util.RequestProcessor;
34 import org.openide.util.HelpCtx;
35 import org.openide.DialogDescriptor;
36 import org.openide.DialogDisplayer;
37 import org.openide.NotifyDescriptor;
38 import org.openide.nodes.Node;
39
40 import javax.swing.*;
41 import java.awt.Dialog JavaDoc;
42 import java.io.File JavaDoc;
43 import java.text.MessageFormat JavaDoc;
44
45 /**
46  * Performs the CVS 'tag -b' command on selected nodes.
47  *
48  * @author Maros Sandor
49  */

50 public class BranchAction extends AbstractSystemAction {
51
52     private static final int enabledForStatus = FileInformation.STATUS_VERSIONED_MERGE
53                     | FileInformation.STATUS_VERSIONED_MODIFIEDINREPOSITORY
54                     | FileInformation.STATUS_VERSIONED_MODIFIEDLOCALLY
55                     | FileInformation.STATUS_VERSIONED_REMOVEDINREPOSITORY
56                     | FileInformation.STATUS_VERSIONED_UPTODATE;
57     
58     protected String JavaDoc getBaseName(Node [] activatedNodes) {
59         return "CTL_MenuItem_Branch"; // NOI18N
60
}
61
62     protected int getFileEnabledStatus() {
63         return enabledForStatus;
64     }
65
66     protected boolean asynchronous() {
67         return false;
68     }
69     
70     public void performCvsAction(Node[] nodes) {
71         Context context = getContext(nodes);
72         if (context.getFiles().length == 0) {
73             DialogDisplayer.getDefault().notify(new NotifyDescriptor(
74                     NbBundle.getBundle(BranchAction.class).getString("CTL_BranchDialogNone_Prompt"),
75                     NbBundle.getBundle(BranchAction.class).getString("CTL_BranchDialogNone_Title"),
76                     NotifyDescriptor.DEFAULT_OPTION, NotifyDescriptor.ERROR_MESSAGE, null, null));
77             return;
78         }
79
80         String JavaDoc title = MessageFormat.format(NbBundle.getBundle(BranchAction.class).getString("CTL_BranchDialog_Title"), getContextDisplayName(nodes));
81
82         JButton branch = new JButton(NbBundle.getMessage(BranchAction.class, "CTL_BranchDialog_Action_Branch"));
83         branch.setToolTipText(NbBundle.getMessage(BranchAction.class, "TT_BranchDialog_Action_Branch"));
84         BranchSettings settings = new BranchSettings(context.getFiles());
85         settings.putClientProperty("OKButton", branch);
86         settings.onBranchNameChange();
87         DialogDescriptor descriptor = new DialogDescriptor(
88                 settings,
89                 title,
90                 true,
91                 new Object JavaDoc [] { branch, DialogDescriptor.CANCEL_OPTION },
92                 branch,
93                 DialogDescriptor.DEFAULT_ALIGN,
94                 new HelpCtx(BranchAction.class),
95                 null);
96         descriptor.setClosingOptions(null);
97
98         settings.putClientProperty("org.openide.DialogDescriptor", descriptor); // NOI18N
99
Dialog JavaDoc dialog = DialogDisplayer.getDefault().createDialog(descriptor);
100         dialog.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(BranchAction.class, "ACSD_BranchDialog"));
101         dialog.setVisible(true);
102         if (descriptor.getValue() != branch) return;
103
104         settings.saveSettings();
105
106         RequestProcessor.getDefault().post(new BranchExecutor(context, settings, getRunningName(nodes)));
107     }
108     
109     private static class BranchExecutor implements Runnable JavaDoc {
110
111         private final Context context;
112         private final BranchSettings settings;
113         private final String JavaDoc name;
114
115         public BranchExecutor(Context context, BranchSettings settings, String JavaDoc name) {
116             this.context = context;
117             this.settings = settings;
118             this.name = name;
119         }
120
121         public void run() {
122             ExecutorGroup group = new ExecutorGroup(name);
123             if (settings.isTaggingBase()) {
124                 group.addExecutors(tag(context.getFiles(), settings.getBaseTagName()));
125                 group.addBarrier(null);
126             }
127             group.addExecutors(branch(context.getFiles(), settings.getBranchName()));
128             group.addBarrier(null);
129             if (settings.isCheckingOutBranch()) {
130                 group.addExecutors(update(context, settings.getBranchName()));
131             }
132             group.execute();
133         }
134
135         private UpdateExecutor[] update(Context context, String JavaDoc revision) {
136             UpdateCommand cmd = new UpdateCommand();
137
138             GlobalOptions options = CvsVersioningSystem.createGlobalOptions();
139             if (context.getExclusions().size() > 0) {
140                 options.setExclusions((File JavaDoc[]) context.getExclusions().toArray(new File JavaDoc[context.getExclusions().size()]));
141             }
142             cmd.setUpdateByRevision(revision);
143             cmd.setFiles(context.getRootFiles());
144         
145             return UpdateExecutor.splitCommand(cmd, CvsVersioningSystem.getInstance(), options, null);
146         }
147
148         private ExecutorSupport[] branch(File JavaDoc[] roots, String JavaDoc branchName) {
149             TagCommand cmd = new TagCommand();
150
151             cmd.setMakeBranchTag(true);
152             cmd.setFiles(roots);
153             cmd.setTag(branchName);
154         
155             return TagExecutor.splitCommand(cmd, CvsVersioningSystem.getInstance(), null);
156         }
157
158         private ExecutorSupport[] tag(File JavaDoc[] roots, String JavaDoc tagName) {
159             TagCommand cmd = new TagCommand();
160         
161             cmd.setFiles(roots);
162             cmd.setTag(tagName);
163         
164             return TagExecutor.splitCommand(cmd, CvsVersioningSystem.getInstance(), null);
165         }
166     }
167 }
168
Popular Tags