1 19 package org.netbeans.modules.subversion.ui.copy; 20 21 import java.awt.BorderLayout ; 22 import java.awt.Component ; 23 import java.awt.event.ItemEvent ; 24 import java.awt.event.ItemListener ; 25 import java.beans.PropertyChangeEvent ; 26 import java.beans.PropertyChangeListener ; 27 import java.io.File ; 28 import java.net.MalformedURLException ; 29 import javax.swing.DefaultComboBoxModel ; 30 import javax.swing.DefaultListCellRenderer ; 31 import javax.swing.JComboBox ; 32 import javax.swing.JLabel ; 33 import javax.swing.JList ; 34 import javax.swing.JPanel ; 35 import javax.swing.ListCellRenderer ; 36 import javax.swing.event.DocumentEvent ; 37 import javax.swing.event.DocumentListener ; 38 import javax.swing.text.JTextComponent ; 39 import org.netbeans.modules.subversion.RepositoryFile; 40 import org.netbeans.modules.subversion.ui.browser.Browser; 41 import org.netbeans.modules.subversion.ui.browser.RepositoryPaths; 42 import org.openide.ErrorManager; 43 import org.openide.util.NbBundle; 44 import org.tigris.subversion.svnclientadapter.SVNRevision; 45 import org.tigris.subversion.svnclientadapter.SVNUrl; 46 47 51 public class Merge extends CopyDialog implements ItemListener { 52 53 private String MERGE_START_URL_HISTORY_KEY = Merge.class.getName() + "_merge_from"; private String MERGE_END_URL_HISTORY_KEY = Merge.class.getName() + "_merge_after"; 56 public Merge(RepositoryFile repositoryRoot, File root) { 57 super(new MergePanel(), NbBundle.getMessage(Merge.class, "CTL_Merge_Prompt", root.getName()), NbBundle.getMessage(Merge.class, "CTL_Merge_Title")); 59 MergePanel panel = getMergePanel(); 60 61 panel.typeComboBox.setModel(new DefaultComboBoxModel ( 62 new MergeType[] { 63 new MergeOneFolderType(repositoryRoot, root), 64 new MergeTwoFoldersType(repositoryRoot, root), 65 new MergeSinceOriginType(repositoryRoot, root) 66 } 67 )); 68 panel.typeComboBox.setRenderer(createTypeRenderer()); 69 panel.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(Merge.class, "CTL_Merge_Title")); 70 panel.typeComboBox.addItemListener(this); 71 mergeTypeSelected(((MergeType) panel.typeComboBox.getSelectedItem())); 72 } 73 74 SVNUrl getMergeStartUrl() { 75 return getSelectedType().getMergeStartUrl(); 76 } 77 78 SVNUrl getMergeEndUrl() { 79 return getSelectedType().getMergeEndUrl(); 80 } 81 82 SVNRevision getMergeStartRevision() { 83 return getSelectedType().getMergeStartRevision(); 84 } 85 86 SVNRevision getMergeEndRevision() { 87 return getSelectedType().getMergeEndRevision(); 88 } 89 90 private MergeType getSelectedType() { 91 return (MergeType) getMergePanel().typeComboBox.getSelectedItem(); 92 } 93 94 private MergePanel getMergePanel() { 95 return (MergePanel) getPanel(); 96 } 97 98 private ListCellRenderer createTypeRenderer() { 99 return new DefaultListCellRenderer () { 100 public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { 101 super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); 102 if(value instanceof MergeType) { 103 setText(((MergeType)value).getDisplayName()); 104 } 105 return this; 106 } 107 }; 108 } 109 110 public void itemStateChanged(ItemEvent e) { 111 final MergeType type = (MergeType) e.getItem(); 112 mergeTypeSelected(type); 113 } 114 115 private void mergeTypeSelected(MergeType type) { 116 MergePanel panel = getMergePanel(); 117 panel.typeDescriptionLabel.setText(type.getDescription()); 118 119 panel.previewPanel.removeAll(); 120 panel.previewPanel.setLayout(new BorderLayout ()); 121 panel.previewPanel.add(type.getPreviewPanel(), BorderLayout.CENTER); 122 123 panel.mergeFieldsPanel.removeAll(); 124 panel.mergeFieldsPanel.setLayout(new BorderLayout ()); 125 panel.mergeFieldsPanel.add(type.getFieldsPanel(), BorderLayout.CENTER); 126 127 type.setPreviewLabels(); 128 panel.repaint(); 129 130 resetUrlComboBoxes(); 131 setupUrlComboBox(type.getStartUrlComboBox(), MERGE_START_URL_HISTORY_KEY); 132 setupUrlComboBox(type.getEndUrlComboBox(), MERGE_END_URL_HISTORY_KEY); 133 134 } 135 136 private abstract class MergeType implements DocumentListener , PropertyChangeListener { 137 138 private RepositoryPaths mergeStartRepositoryPaths; 139 private RepositoryPaths mergeEndRepositoryPaths; 140 private RepositoryFile repositoryFile; 141 142 private boolean startPathValid = false; 143 private boolean endPathValid = false; 144 145 MergeType (RepositoryFile repositoryFile) { 146 this.repositoryFile = repositoryFile; 147 } 148 149 protected void init(RepositoryPaths mergeStartRepositoryPaths, JLabel mergeStartRepositoryFolderLabel, RepositoryPaths mergeEndRepositoryPaths, JLabel mergeEndRepositoryFolderLabel, File root) { 150 if(mergeStartRepositoryPaths != null) { 151 this.mergeStartRepositoryPaths = mergeStartRepositoryPaths; 152 init(mergeStartRepositoryPaths, mergeStartRepositoryFolderLabel, root); 153 } else { 154 startPathValid = true; 156 } 157 if(mergeEndRepositoryPaths != null) { 158 this.mergeEndRepositoryPaths = mergeEndRepositoryPaths; 159 init(mergeEndRepositoryPaths, mergeEndRepositoryFolderLabel, root); 160 } else { 161 endPathValid = true; 163 } 164 } 165 166 private void init(RepositoryPaths paths, JLabel label, File root) { 167 String browserPurposeMessage; 168 int browserMode; 169 if(root.isFile()) { 170 if(label!=null) { 171 label.setText(org.openide.util.NbBundle.getMessage(Merge.class, "CTL_Merge_RepositoryFile")); } 173 browserPurposeMessage = org.openide.util.NbBundle.getMessage(CreateCopy.class, "LBL_BrowserMessageMergeFile"); 174 browserMode = Browser.BROWSER_SINGLE_SELECTION_ONLY | Browser.BROWSER_SHOW_FILES | Browser.BROWSER_FILES_SELECTION_ONLY; 175 } else { 176 browserPurposeMessage = org.openide.util.NbBundle.getMessage(CreateCopy.class, "LBL_BrowserMessageMergeFolder"); 177 browserMode = Browser.BROWSER_SINGLE_SELECTION_ONLY; 178 } 179 paths.setupBrowserBehavior(browserPurposeMessage, browserMode); 180 paths.addPropertyChangeListener(this); 181 } 182 183 protected abstract JPanel getFieldsPanel(); 184 protected abstract JPanel getPreviewPanel(); 185 protected abstract String getDisplayName(); 186 protected abstract String getDescription(); 187 protected abstract JComboBox getStartUrlComboBox(); 188 protected abstract JComboBox getEndUrlComboBox(); 189 protected abstract void setPreviewLabels(); 190 191 public SVNUrl getMergeStartUrl() { 192 try { 193 return mergeStartRepositoryPaths.getRepositoryFiles()[0].getFileUrl(); 194 } catch (MalformedURLException ex) { 195 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 198 } 199 return null; 200 } 201 202 public SVNUrl getMergeEndUrl() { 203 try { 204 return mergeEndRepositoryPaths.getRepositoryFiles()[0].getFileUrl(); 205 } catch (MalformedURLException ex) { 206 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 209 } 210 return null; 211 } 212 213 public SVNRevision getMergeStartRevision() { 214 try { 215 return mergeStartRepositoryPaths.getRepositoryFiles()[0].getRevision(); 216 } catch (MalformedURLException ex) { 217 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 220 } 221 return null; 222 } 223 224 public SVNRevision getMergeEndRevision() { 225 try { 226 return mergeEndRepositoryPaths.getRepositoryFiles()[0].getRevision(); 227 } catch (MalformedURLException ex) { 228 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 231 } 232 return null; 233 } 234 235 RepositoryPaths getMergeStartRepositoryPath() { 236 return mergeStartRepositoryPaths; 237 } 238 239 RepositoryPaths getMergeEndRepositoryPath() { 240 return mergeEndRepositoryPaths; 241 } 242 243 public void insertUpdate(DocumentEvent e) { 244 setPreviewLabels(); 245 } 246 247 public void removeUpdate(DocumentEvent e) { 248 setPreviewLabels(); 249 } 250 251 public void changedUpdate(DocumentEvent e) { 252 setPreviewLabels(); 253 } 254 255 protected RepositoryFile getRepositoryFile() { 256 return repositoryFile; 257 } 258 259 public void propertyChange(PropertyChangeEvent evt) { 260 if( evt.getPropertyName().equals(RepositoryPaths.PROP_VALID) ) { 261 boolean valid = ((Boolean ) evt.getNewValue()).booleanValue(); 262 if(evt.getSource() == getMergeStartRepositoryPath()) { 263 startPathValid = valid; 264 } else if(evt.getSource() == getMergeEndRepositoryPath()) { 265 endPathValid = valid; 266 } 267 getOKButton().setEnabled(startPathValid && endPathValid); 268 } 269 } 270 } 271 272 private class MergeTwoFoldersType extends MergeType { 273 274 private MergeTwoFoldersPanel panel; 275 private TwoFoldersPreviewPanel previewPanel; 276 277 public MergeTwoFoldersType(RepositoryFile repositoryRoot, File root) { 278 super(repositoryRoot); 279 280 panel = new MergeTwoFoldersPanel(); 281 previewPanel = new TwoFoldersPreviewPanel(); 282 283 RepositoryPaths mergeStartRepositoryPaths = 284 new RepositoryPaths( 285 repositoryRoot, 286 (JTextComponent ) panel.mergeStartUrlComboBox.getEditor().getEditorComponent(), 287 panel.mergeStartBrowseButton, 288 panel.mergeStartRevisionTextField, 289 panel.mergeStartSearchButton 290 ); 291 292 RepositoryPaths mergeEndRepositoryPaths = 293 new RepositoryPaths( 294 repositoryRoot, 295 (JTextComponent ) panel.mergeEndUrlComboBox.getEditor().getEditorComponent(), 296 panel.mergeEndBrowseButton, 297 panel.mergeEndRevisionTextField, 298 panel.mergeEndSearchButton 299 ); 300 301 init(mergeStartRepositoryPaths, 302 panel.mergeStartRepositoryFolderLabel, 303 mergeEndRepositoryPaths, 304 panel.mergeEndRepositoryFolderLabel, 305 root); 306 307 previewPanel.localFolderTextField.setText(root.getAbsolutePath()); 308 ((JTextComponent ) panel.mergeStartUrlComboBox.getEditor().getEditorComponent()).getDocument().addDocumentListener(this); 309 ((JTextComponent ) panel.mergeEndUrlComboBox.getEditor().getEditorComponent()).getDocument().addDocumentListener(this); 310 } 311 312 public String getDisplayName() { 313 return org.openide.util.NbBundle.getMessage(Merge.class, "CTL_Merge_TwoRepositoryFolders"); } 315 316 public String getDescription() { 317 return org.openide.util.NbBundle.getMessage(Merge.class, "CTL_Merge_TwoFoldersDesc"); } 319 320 public JPanel getFieldsPanel() { 321 return panel; 322 } 323 324 public JPanel getPreviewPanel() { 325 return previewPanel; 326 } 327 328 public JComboBox getStartUrlComboBox() { 329 return panel.mergeStartUrlComboBox; 330 } 331 332 public JComboBox getEndUrlComboBox() { 333 return panel.mergeEndUrlComboBox; 334 } 335 336 protected void setPreviewLabels() { 337 previewPanel.repositoryFolderTextField1.setText(getRepositoryFile().getRepositoryUrl() + "/" + panel.mergeStartUrlComboBox.getEditor().getItem().toString()); previewPanel.repositoryFolderTextField2.setText(getRepositoryFile().getRepositoryUrl() + "/" + panel.mergeEndUrlComboBox.getEditor().getItem().toString()); } 340 341 } 342 343 private class MergeOneFolderType extends MergeType { 344 345 private RepositoryPaths mergeEndRepositoryPaths; 346 private MergeOneFolderPanel panel; 347 private OneFolderPreviewPanel previewPanel; 348 349 350 public MergeOneFolderType(RepositoryFile repositoryRoot, File root) { 351 super(repositoryRoot); 352 353 panel = new MergeOneFolderPanel(); 354 previewPanel = new OneFolderPreviewPanel(); 355 356 RepositoryPaths mergeStartRepositoryPaths = 357 new RepositoryPaths( 358 repositoryRoot, 359 null, 360 null, 361 panel.mergeStartRevisionTextField, 362 panel.mergeStartSearchButton 363 ); 364 365 mergeEndRepositoryPaths = 366 new RepositoryPaths( 367 repositoryRoot, 368 (JTextComponent ) panel.mergeStartUrlComboBox.getEditor().getEditorComponent(), 369 panel.mergeStartBrowseButton, 370 panel.mergeEndRevisionTextField, 371 panel.mergeEndSearchButton 372 ); 373 374 init(mergeStartRepositoryPaths, 375 panel.mergeStartRepositoryFolderLabel, 376 mergeEndRepositoryPaths, 377 null, 378 root); 379 380 previewPanel.localFolderTextField.setText(root.getAbsolutePath()); 381 ((JTextComponent ) panel.mergeStartUrlComboBox.getEditor().getEditorComponent()).getDocument().addDocumentListener(this); 382 } 383 384 385 public SVNUrl getMergeStartUrl() { 386 return getMergeEndUrl(); 388 } 389 390 public String getDisplayName() { 391 return org.openide.util.NbBundle.getMessage(Merge.class, "CTL_Merge_OneRepositoryFolder"); } 393 394 public String getDescription() { 395 return org.openide.util.NbBundle.getMessage(Merge.class, "CTL_Merge_OneRepositoryFolderDesc"); } 397 398 public JPanel getFieldsPanel() { 399 return panel; 400 } 401 402 public JPanel getPreviewPanel() { 403 return previewPanel; 404 } 405 406 public JComboBox getStartUrlComboBox() { 407 return panel.mergeStartUrlComboBox; 408 } 409 410 public JComboBox getEndUrlComboBox() { 411 return null; 412 } 413 414 protected void setPreviewLabels() { 415 previewPanel.repositoryFolderTextField.setText(getRepositoryFile().getRepositoryUrl() + org.openide.util.NbBundle.getMessage(Merge.class, "/") + panel.mergeStartUrlComboBox.getEditor().getItem().toString()); } 417 418 } 419 420 private class MergeSinceOriginType extends MergeType { 421 422 private MergeSinceOriginPanel panel; 423 private RepositoryPaths mergeEndRepositoryPaths; 424 private SinceOriginPreviewPanel previewPanel; 425 426 public MergeSinceOriginType(RepositoryFile repositoryRoot, File root) { 427 super(repositoryRoot); 428 429 panel = new MergeSinceOriginPanel(); 430 previewPanel = new SinceOriginPreviewPanel(); 431 432 mergeEndRepositoryPaths = 433 new RepositoryPaths( 434 repositoryRoot, 435 (JTextComponent ) panel.mergeEndUrlComboBox.getEditor().getEditorComponent(), 436 panel.mergeEndBrowseButton, 437 panel.mergeEndRevisionTextField, 438 panel.mergeEndSearchButton 439 ); 440 441 init(null, null, mergeEndRepositoryPaths, panel.mergeEndRepositoryFolderLabel, root); 442 previewPanel.localFolderTextField.setText(root.getAbsolutePath()); 443 ((JTextComponent ) panel.mergeEndUrlComboBox.getEditor().getEditorComponent()).getDocument().addDocumentListener(this); 444 } 445 446 public String getDisplayName() { 447 return org.openide.util.NbBundle.getMessage(Merge.class, "CTL_Merge_OneRepositoryFolderSinceOrigin"); } 449 450 public String getDescription() { 451 return org.openide.util.NbBundle.getMessage(Merge.class, "CTL_Merge_OneRepositoryFolderSinceOriginDesc"); } 453 454 public JPanel getFieldsPanel() { 455 return panel; 456 } 457 458 public JPanel getPreviewPanel() { 459 return previewPanel; 460 } 461 462 public SVNUrl getMergeStartUrl() { 463 return null; 464 } 465 466 public SVNRevision getMergeStartRevision() { 467 return null; 468 } 469 470 public SVNUrl getMergeEndUrl() { 471 try { 472 return mergeEndRepositoryPaths.getRepositoryFiles()[0].getFileUrl(); 473 } catch (MalformedURLException ex) { 474 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 477 } 478 return null; 479 } 480 481 public SVNRevision getMergeEndRevision() { 482 try { 483 return mergeEndRepositoryPaths.getRepositoryFiles()[0].getRevision(); 484 } catch (MalformedURLException ex) { 485 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 488 } 489 return null; 490 } 491 492 RepositoryPaths getMergeStartRepositoryPath() { 493 return null; 494 } 495 496 RepositoryPaths getMergeEndRepositoryPath() { 497 return mergeEndRepositoryPaths; 498 } 499 500 public JComboBox getStartUrlComboBox() { 501 return null; 502 } 503 504 public JComboBox getEndUrlComboBox() { 505 return panel.mergeEndUrlComboBox; 506 } 507 508 protected void setPreviewLabels() { 509 previewPanel.repositoryFolderTextField.setText(getRepositoryFile().getRepositoryUrl() + "/" + panel.mergeEndUrlComboBox.getEditor().getItem().toString()); } 511 512 } 513 } | Popular Tags |