KickJava   Java API By Example, From Geeks To Geeks.

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


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

43 public class TagAction extends AbstractSystemAction {
44     
45     private static TagCommand commandTemplate = new TagCommand();
46     private static final int enabledForStatus = FileInformation.STATUS_VERSIONED_MERGE
47                     | FileInformation.STATUS_VERSIONED_MODIFIEDINREPOSITORY
48                     | FileInformation.STATUS_VERSIONED_MODIFIEDLOCALLY
49                     | FileInformation.STATUS_VERSIONED_REMOVEDINREPOSITORY
50                     | FileInformation.STATUS_VERSIONED_UPTODATE;
51
52
53     protected String JavaDoc getBaseName(Node [] activatedNodes) {
54         return "CTL_MenuItem_Tag"; // NOI18N
55
}
56
57     protected int getFileEnabledStatus() {
58         return enabledForStatus;
59     }
60
61     protected int getDirectoryEnabledStatus() {
62         return FileInformation.STATUS_MANAGED & ~FileInformation.STATUS_NOTVERSIONED_EXCLUDED & ~FileInformation.STATUS_NOTVERSIONED_NEWLOCALLY;
63     }
64     
65     public void performCvsAction(Node[] nodes) {
66         File JavaDoc [] roots = getContext(nodes).getFiles();
67                 
68         TagCommand cmd = new TagCommand();
69         copy (cmd, commandTemplate);
70         
71         String JavaDoc title = MessageFormat.format(NbBundle.getBundle(TagAction.class).getString("CTL_TagDialog_Title"), getContextDisplayName(nodes));
72         
73         TagSettings settings = new TagSettings(roots);
74         settings.setCommand(cmd);
75         
76         JButton tag = new JButton(NbBundle.getMessage(TagAction.class, "CTL_TagDialog_Action_Tag"));
77         settings.putClientProperty("OKButton", tag);
78         settings.refreshComponents();
79         tag.setToolTipText(NbBundle.getMessage(TagAction.class, "TT_TagDialog_Action_Tag"));
80         DialogDescriptor descriptor = new DialogDescriptor(
81                 settings,
82                 title,
83                 true,
84                 new Object JavaDoc [] { tag, DialogDescriptor.CANCEL_OPTION },
85                 tag,
86                 DialogDescriptor.DEFAULT_ALIGN,
87                 new HelpCtx(TagAction.class),
88                 null);
89         descriptor.setClosingOptions(null);
90         Dialog JavaDoc dialog = DialogDisplayer.getDefault().createDialog(descriptor);
91         dialog.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(TagAction.class, "ACSD_TagDialog"));
92         dialog.setVisible(true);
93         if (descriptor.getValue() != tag) return;
94
95         settings.updateCommand(cmd);
96         copy(commandTemplate, cmd);
97         cmd.setFiles(roots);
98
99         ExecutorGroup group = new ExecutorGroup(getRunningName(nodes));
100         group.addExecutors(TagExecutor.splitCommand(cmd, CvsVersioningSystem.getInstance(), null));
101         group.execute();
102     }
103
104     protected boolean asynchronous() {
105         return false;
106     }
107     
108     private void copy(TagCommand c1, TagCommand c2) {
109         c1.setTag(c2.getTag());
110         c1.setCheckThatUnmodified(c2.isCheckThatUnmodified());
111         c1.setDeleteTag(c2.isDeleteTag());
112         c1.setOverrideExistingTag(c2.isOverrideExistingTag());
113     }
114 }
115
Popular Tags