1 19 20 package org.netbeans.modules.versioning.system.cvss.ui.actions.commit; 21 22 import org.openide.util.NbBundle; 23 import org.openide.util.HelpCtx; 24 import org.openide.DialogDescriptor; 25 import org.openide.DialogDisplayer; 26 import org.openide.nodes.Node; 27 import org.netbeans.lib.cvsclient.command.commit.CommitCommand; 28 import org.netbeans.lib.cvsclient.command.add.AddCommand; 29 import org.netbeans.lib.cvsclient.command.KeywordSubstitutionOptions; 30 import org.netbeans.lib.cvsclient.command.remove.RemoveCommand; 31 import org.netbeans.modules.versioning.system.cvss.*; 32 import org.netbeans.modules.versioning.system.cvss.CvsModuleConfig; 33 import org.netbeans.modules.versioning.system.cvss.executor.RemoveExecutor; 34 import org.netbeans.modules.versioning.system.cvss.util.Utils; 35 import org.netbeans.modules.versioning.system.cvss.util.Context; 36 import org.netbeans.modules.versioning.system.cvss.ui.actions.AbstractSystemAction; 37 import org.netbeans.modules.versioning.system.cvss.ui.actions.add.AddExecutor; 38 import org.netbeans.modules.versioning.util.VersioningListener; 39 import org.netbeans.modules.versioning.util.VersioningEvent; 40 import javax.swing.*; 41 import java.awt.Dialog ; 42 import java.io.File ; 43 import java.text.MessageFormat ; 44 import java.util.*; 45 import org.netbeans.modules.versioning.util.DialogBoundsPreserver; 46 47 52 public class CommitAction extends AbstractSystemAction { 53 54 static final String RECENT_COMMIT_MESSAGES = "commitAction.commitMessage"; 56 public CommitAction() { 57 setIcon(null); 58 putValue("noIconInMenu", Boolean.TRUE); } 60 61 protected String getBaseName(Node [] activatedNodes) { 62 return "CTL_MenuItem_Commit"; } 64 65 protected boolean enable(Node[] nodes) { 66 return CvsVersioningSystem.getInstance().getFileTableModel(Utils.getCurrentContext(nodes), FileInformation.STATUS_LOCAL_CHANGE).getNodes().length > 0; 67 } 68 69 72 public static void invokeCommit(String contentTitle, Context context, String runningName) { 73 ResourceBundle loc = NbBundle.getBundle(CommitAction.class); 74 if (CvsVersioningSystem.getInstance().getFileTableModel(context, FileInformation.STATUS_LOCAL_CHANGE).getNodes().length == 0) { 75 JOptionPane.showMessageDialog(null, loc.getString("MSG_NoFilesToCommit_Prompt"), 76 loc.getString("MSG_NoFilesToCommit_Title"), JOptionPane.INFORMATION_MESSAGE); 77 return; 78 } 79 80 CommitCommand cmd = new CommitCommand(); 81 cmd.setDisplayName(NbBundle.getMessage(CommitAction.class, "BK0001")); 83 final CommitSettings settings = new CommitSettings(); 84 final JButton commit = new JButton(loc.getString("CTL_CommitForm_Action_Commit")); 85 commit.setToolTipText(NbBundle.getMessage(CommitAction.class, "TT_CommitDialog_Action_Commit")); commit.setEnabled(false); 87 JButton cancel = new JButton(loc.getString("CTL_CommitForm_Action_Cancel")); 88 cancel.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(CommitAction.class, "ACSD_CommitDialog_Action_Cancel")); DialogDescriptor descriptor = new DialogDescriptor( 90 settings, 91 MessageFormat.format(loc.getString("CTL_CommitDialog_Title"), contentTitle), 92 true, 93 new Object [] { commit, cancel }, 94 commit, 95 DialogDescriptor.BOTTOM_ALIGN, 96 null, 97 null); 98 descriptor.setClosingOptions(null); 99 descriptor.setHelpCtx(new HelpCtx(CommitSettings.class)); 100 settings.addVersioningListener(new VersioningListener() { 101 public void versioningEvent(VersioningEvent event) { 102 refreshCommitDialog(settings, commit); 103 } 104 }); 105 setupNodes(settings, context); 106 settings.putClientProperty("contentTitle", contentTitle); settings.putClientProperty("DialogDescriptor", descriptor); Dialog dialog = DialogDisplayer.getDefault().createDialog(descriptor); 109 dialog.addWindowListener(new DialogBoundsPreserver(CvsModuleConfig.getDefault().getPreferences(), "svn.commit.dialog")); dialog.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(CommitAction.class, "ACSD_CommitDialog")); dialog.setVisible(true); 112 if (descriptor.getValue() != commit) return; 113 114 saveExclusions(settings); 115 116 cmd.setMessage(settings.getCommitMessage()); 117 org.netbeans.modules.versioning.util.Utils.insert(CvsModuleConfig.getDefault().getPreferences(), RECENT_COMMIT_MESSAGES, cmd.getMessage(), 20); 118 if (runningName == null) { 119 runningName = NbBundle.getMessage(CommitAction.class, "BK0002"); } 121 ExecutorGroup group = new ExecutorGroup(runningName); 122 addCommit(group, settings); 123 group.execute(); 124 } 125 126 private static void saveExclusions(CommitSettings settings) { 127 CommitSettings.CommitFile [] files = settings.getCommitFiles(); 128 for (int i = 0; i < files.length; i++) { 129 CommitSettings.CommitFile file = files[i]; 130 if (file.getOptions() == CommitOptions.EXCLUDE) { 131 CvsModuleConfig.getDefault().addExclusion(file.getNode().getFile()); 132 } else { 133 CvsModuleConfig.getDefault().removeExclusion(file.getNode().getFile()); 134 } 135 } 136 } 137 138 private static void setupNodes(CommitSettings settings, Context context) { 139 CvsFileNode [] filesToCommit = CvsVersioningSystem.getInstance().getFileTableModel(context, FileInformation.STATUS_LOCAL_CHANGE).getNodes(); 140 settings.setNodes(filesToCommit); 141 } 142 143 149 private static void refreshCommitDialog(CommitSettings settings, JButton commit) { 150 ResourceBundle loc = NbBundle.getBundle(CommitAction.class); 151 CommitSettings.CommitFile [] files = settings.getCommitFiles(); 152 Set<String > stickyTags = new HashSet<String >(); 153 boolean conflicts = false; 154 for (int i = 0; i < files.length; i++) { 155 CommitSettings.CommitFile file = files[i]; 156 if (file.getOptions() == CommitOptions.EXCLUDE) continue; 157 stickyTags.add(Utils.getSticky(file.getNode().getFile())); 158 int status = file.getNode().getInformation().getStatus(); 159 if ((status & FileInformation.STATUS_REMOTE_CHANGE) != 0 || status == FileInformation.STATUS_VERSIONED_CONFLICT) { 160 commit.setEnabled(false); 161 String msg = (status == FileInformation.STATUS_VERSIONED_CONFLICT) ? 162 loc.getString("MSG_CommitForm_ErrorConflicts") : 163 loc.getString("MSG_CommitForm_ErrorRemoteChanges"); 164 settings.setErrorLabel("<html><font color=\"#002080\">" + msg + "</font></html>"); conflicts = true; 166 } 167 stickyTags.add(Utils.getSticky(file.getNode().getFile())); 168 } 169 170 if (stickyTags.size() > 1) { 171 settings.setColumns(new String [] { CommitSettings.COLUMN_NAME_NAME, CommitSettings.COLUMN_NAME_STICKY, CommitSettings.COLUMN_NAME_STATUS, 172 CommitSettings.COLUMN_NAME_ACTION, CommitSettings.COLUMN_NAME_PATH }); 173 } else { 174 settings.setColumns(new String [] { CommitSettings.COLUMN_NAME_NAME, CommitSettings.COLUMN_NAME_STATUS, 175 CommitSettings.COLUMN_NAME_ACTION, CommitSettings.COLUMN_NAME_PATH }); 176 } 177 178 String contentTitle = (String ) settings.getClientProperty("contentTitle"); DialogDescriptor dd = (DialogDescriptor) settings.getClientProperty("DialogDescriptor"); String errorLabel; 181 if (stickyTags.size() <= 1) { 182 String stickyTag = stickyTags.size() == 0 ? null : (String ) stickyTags.iterator().next(); 183 if (stickyTag == null) { 184 dd.setTitle(MessageFormat.format(loc.getString("CTL_CommitDialog_Title"), contentTitle)); 185 errorLabel = ""; } else { 187 stickyTag = stickyTag.substring(1); 188 dd.setTitle(MessageFormat.format(loc.getString("CTL_CommitDialog_Title_Branch"), contentTitle, stickyTag)); 189 String msg = MessageFormat.format(loc.getString("MSG_CommitForm_InfoBranch"), stickyTag); 190 errorLabel = "<html><font color=\"#002080\">" + msg + "</font></html>"; } 192 } else { 193 dd.setTitle(MessageFormat.format(loc.getString("CTL_CommitDialog_Title_Branches"), contentTitle)); 194 String msg = loc.getString("MSG_CommitForm_ErrorMultipleBranches"); 195 errorLabel = "<html><font color=\"#CC0000\">" + msg + "</font></html>"; } 197 if (!conflicts) { 198 settings.setErrorLabel(errorLabel); 199 commit.setEnabled(true); 200 } 201 } 202 203 public void performCvsAction(Node[] nodes) { 204 invokeCommit(getContextDisplayName(nodes), getContext(nodes), getRunningName(nodes)); 205 } 206 207 protected boolean asynchronous() { 208 return false; 209 } 210 211 217 public static void addCommit(ExecutorGroup group, CommitSettings settings) { 218 FileStatusCache cache = CvsVersioningSystem.getInstance().getStatusCache(); 219 CommitSettings.CommitFile [] files = settings.getCommitFiles(); 220 List<File > commitBucket = new ArrayList<File >(); 221 List<File > addDefaultBucket = new ArrayList<File >(); 222 List<File > addKkvBucket = new ArrayList<File >(); 223 List<File > addKkvlBucket = new ArrayList<File >(); 224 List<File > addKkBucket = new ArrayList<File >(); 225 List<File > addKoBucket = new ArrayList<File >(); 226 List<File > addKbBucket = new ArrayList<File >(); 227 List<File > addKvBucket = new ArrayList<File >(); 228 List<File > removeBucket = new ArrayList<File >(); 229 for (int i = 0; i < files.length; i++) { 230 CommitSettings.CommitFile file = files[i]; 231 if (file.getOptions() == CommitOptions.EXCLUDE) continue; 232 if (file.getOptions() == CommitOptions.ADD_TEXT) { 233 addDefaultBucket.add(file.getNode().getFile()); 234 } else if (file.getOptions() == CommitOptions.ADD_BINARY) { 235 addKbBucket.add(file.getNode().getFile()); 236 } else if (file.getOptions() == CommitOptions.COMMIT_REMOVE) { 237 int status = cache.getStatus(file.getNode().getFile()).getStatus(); 238 if (status == FileInformation.STATUS_VERSIONED_DELETEDLOCALLY) { 239 removeBucket.add(file.getNode().getFile()); 240 } 241 } 242 commitBucket.add(file.getNode().getFile()); 243 } 244 245 group.addExecutors(createAdd(addDefaultBucket, null)); 247 group.addExecutors(createAdd(addKkvBucket, KeywordSubstitutionOptions.DEFAULT)); 248 group.addExecutors(createAdd(addKkvlBucket, KeywordSubstitutionOptions.DEFAULT_LOCKER)); 249 group.addExecutors(createAdd(addKkBucket, KeywordSubstitutionOptions.ONLY_KEYWORDS)); 250 group.addExecutors(createAdd(addKoBucket, KeywordSubstitutionOptions.OLD_VALUES)); 251 group.addExecutors(createAdd(addKbBucket, KeywordSubstitutionOptions.BINARY)); 252 group.addExecutors(createAdd(addKvBucket, KeywordSubstitutionOptions.ONLY_VALUES)); 253 group.addExecutors(createRemove(removeBucket)); 254 group.addExecutors(createCommit(commitBucket, settings.getCommitMessage())); 255 } 256 257 private static ExecutorSupport[] createCommit(List<File > bucket, String message) { 258 if (bucket.size() == 0) return null; 259 CommitCommand cmd = new CommitCommand(); 260 cmd.setFiles((File []) bucket.toArray(new File [bucket.size()])); 261 cmd.setMessage(org.netbeans.modules.versioning.util.Utils.wordWrap(message, CvsModuleConfig.getDefault().getWrapCommitMessagelength())); 262 return CommitExecutor.splitCommand(cmd, CvsVersioningSystem.getInstance(), null); 263 } 264 265 private static ExecutorSupport[] createRemove(List<File > bucket) { 266 if (bucket.size() == 0) return null; 267 RemoveCommand cmd = new RemoveCommand(); 268 cmd.setFiles((File []) bucket.toArray(new File [bucket.size()])); 269 return RemoveExecutor.splitCommand(cmd, CvsVersioningSystem.getInstance(), null); 270 } 271 272 private static ExecutorSupport[] createAdd(List<File > bucket, KeywordSubstitutionOptions option) { 273 if (bucket.size() == 0) return null; 274 AddCommand cmd = new AddCommand(); 275 cmd.setFiles((File []) bucket.toArray(new File [bucket.size()])); 276 cmd.setKeywordSubst(option); 277 return AddExecutor.splitCommand(cmd, CvsVersioningSystem.getInstance(), null); 278 279 } 280 } 281 | Popular Tags |