KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.netbeans.modules.subversion.ui.copy;
20
21 import java.awt.BorderLayout JavaDoc;
22 import java.awt.Component JavaDoc;
23 import java.awt.event.ItemEvent JavaDoc;
24 import java.awt.event.ItemListener JavaDoc;
25 import java.beans.PropertyChangeEvent JavaDoc;
26 import java.beans.PropertyChangeListener JavaDoc;
27 import java.io.File JavaDoc;
28 import java.net.MalformedURLException JavaDoc;
29 import javax.swing.DefaultComboBoxModel JavaDoc;
30 import javax.swing.DefaultListCellRenderer JavaDoc;
31 import javax.swing.JComboBox JavaDoc;
32 import javax.swing.JLabel JavaDoc;
33 import javax.swing.JList JavaDoc;
34 import javax.swing.JPanel JavaDoc;
35 import javax.swing.ListCellRenderer JavaDoc;
36 import javax.swing.event.DocumentEvent JavaDoc;
37 import javax.swing.event.DocumentListener JavaDoc;
38 import javax.swing.text.JTextComponent JavaDoc;
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 /**
48  *
49  * @author Tomas Stupka
50  */

51 public class Merge extends CopyDialog implements ItemListener JavaDoc {
52         
53     private String JavaDoc MERGE_START_URL_HISTORY_KEY = Merge.class.getName() + "_merge_from"; // NOI18N
54
private String JavaDoc MERGE_END_URL_HISTORY_KEY = Merge.class.getName() + "_merge_after"; // NOI18N
55

56     public Merge(RepositoryFile repositoryRoot, File JavaDoc root) {
57         super(new MergePanel(), NbBundle.getMessage(Merge.class, "CTL_Merge_Prompt", root.getName()), NbBundle.getMessage(Merge.class, "CTL_Merge_Title")); // NOI18N
58

59         MergePanel panel = getMergePanel();
60
61         panel.typeComboBox.setModel(new DefaultComboBoxModel JavaDoc(
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 JavaDoc createTypeRenderer() {
99         return new DefaultListCellRenderer JavaDoc() {
100             public Component JavaDoc getListCellRendererComponent(JList JavaDoc list, Object JavaDoc 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 JavaDoc 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 JavaDoc());
121         panel.previewPanel.add(type.getPreviewPanel(), BorderLayout.CENTER);
122         
123         panel.mergeFieldsPanel.removeAll();
124         panel.mergeFieldsPanel.setLayout(new BorderLayout JavaDoc());
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 JavaDoc, PropertyChangeListener JavaDoc {
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 JavaDoc mergeStartRepositoryFolderLabel, RepositoryPaths mergeEndRepositoryPaths, JLabel JavaDoc mergeEndRepositoryFolderLabel, File JavaDoc root) {
150             if(mergeStartRepositoryPaths != null) {
151                 this.mergeStartRepositoryPaths = mergeStartRepositoryPaths;
152                 init(mergeStartRepositoryPaths, mergeStartRepositoryFolderLabel, root);
153             } else {
154                 // won't ever chage -> will always be valid
155
startPathValid = true;
156             }
157             if(mergeEndRepositoryPaths != null) {
158                 this.mergeEndRepositoryPaths = mergeEndRepositoryPaths;
159                 init(mergeEndRepositoryPaths, mergeEndRepositoryFolderLabel, root);
160             } else {
161                 // won't ever chage -> will always be valid
162
endPathValid = true;
163             }
164         }
165
166         private void init(RepositoryPaths paths, JLabel JavaDoc label, File JavaDoc root) {
167             String JavaDoc 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")); // NOI18N
172
}
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 JavaDoc getFieldsPanel();
184         protected abstract JPanel JavaDoc getPreviewPanel();
185         protected abstract String JavaDoc getDisplayName();
186         protected abstract String JavaDoc getDescription();
187         protected abstract JComboBox JavaDoc getStartUrlComboBox();
188         protected abstract JComboBox JavaDoc getEndUrlComboBox();
189         protected abstract void setPreviewLabels();
190
191         public SVNUrl getMergeStartUrl() {
192             try {
193                 return mergeStartRepositoryPaths.getRepositoryFiles()[0].getFileUrl();
194             } catch (MalformedURLException JavaDoc ex) {
195                 // should be already checked and
196
// not happen at this place anymore
197
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 JavaDoc ex) {
206                 // should be already checked and
207
// not happen at this place anymore
208
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 JavaDoc ex) {
217                 // should be already checked and
218
// not happen at this place anymore
219
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 JavaDoc ex) {
228                 // should be already checked and
229
// not happen at this place anymore
230
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 JavaDoc e) {
244             setPreviewLabels();
245         }
246
247         public void removeUpdate(DocumentEvent JavaDoc e) {
248             setPreviewLabels();
249         }
250
251         public void changedUpdate(DocumentEvent JavaDoc e) {
252             setPreviewLabels();
253         }
254
255         protected RepositoryFile getRepositoryFile() {
256             return repositoryFile;
257         }
258         
259         public void propertyChange(PropertyChangeEvent JavaDoc evt) {
260             if( evt.getPropertyName().equals(RepositoryPaths.PROP_VALID) ) {
261                 boolean valid = ((Boolean JavaDoc) 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 JavaDoc root) {
278             super(repositoryRoot);
279
280             panel = new MergeTwoFoldersPanel();
281             previewPanel = new TwoFoldersPreviewPanel();
282
283             RepositoryPaths mergeStartRepositoryPaths =
284                 new RepositoryPaths(
285                     repositoryRoot,
286                     (JTextComponent JavaDoc) 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 JavaDoc) 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 JavaDoc) panel.mergeStartUrlComboBox.getEditor().getEditorComponent()).getDocument().addDocumentListener(this);
309             ((JTextComponent JavaDoc) panel.mergeEndUrlComboBox.getEditor().getEditorComponent()).getDocument().addDocumentListener(this);
310         }
311
312         public String JavaDoc getDisplayName() {
313             return org.openide.util.NbBundle.getMessage(Merge.class, "CTL_Merge_TwoRepositoryFolders"); // NOI18N
314
}
315
316         public String JavaDoc getDescription() {
317             return org.openide.util.NbBundle.getMessage(Merge.class, "CTL_Merge_TwoFoldersDesc"); // NOI18N
318
}
319
320         public JPanel JavaDoc getFieldsPanel() {
321             return panel;
322         }
323
324         public JPanel JavaDoc getPreviewPanel() {
325             return previewPanel;
326         }
327
328         public JComboBox JavaDoc getStartUrlComboBox() {
329             return panel.mergeStartUrlComboBox;
330         }
331
332         public JComboBox JavaDoc getEndUrlComboBox() {
333             return panel.mergeEndUrlComboBox;
334         }
335
336         protected void setPreviewLabels() {
337             previewPanel.repositoryFolderTextField1.setText(getRepositoryFile().getRepositoryUrl() + "/" + panel.mergeStartUrlComboBox.getEditor().getItem().toString()); // NOI18N
338
previewPanel.repositoryFolderTextField2.setText(getRepositoryFile().getRepositoryUrl() + "/" + panel.mergeEndUrlComboBox.getEditor().getItem().toString()); // NOI18N
339
}
340         
341     }
342
343     private class MergeOneFolderType extends MergeType {
344
345         private RepositoryPaths mergeEndRepositoryPaths;
346         private MergeOneFolderPanel panel;
347         private OneFolderPreviewPanel previewPanel;
348
349         /** Creates a new instance of MergeOneFolderType */
350         public MergeOneFolderType(RepositoryFile repositoryRoot, File JavaDoc 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 JavaDoc) 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 JavaDoc) panel.mergeStartUrlComboBox.getEditor().getEditorComponent()).getDocument().addDocumentListener(this);
382         }
383
384         
385         public SVNUrl getMergeStartUrl() {
386             // in this case iths the same folder url
387
return getMergeEndUrl();
388         }
389
390         public String JavaDoc getDisplayName() {
391             return org.openide.util.NbBundle.getMessage(Merge.class, "CTL_Merge_OneRepositoryFolder"); // NOI18N
392
}
393
394         public String JavaDoc getDescription() {
395             return org.openide.util.NbBundle.getMessage(Merge.class, "CTL_Merge_OneRepositoryFolderDesc"); // NOI18N
396
}
397
398         public JPanel JavaDoc getFieldsPanel() {
399             return panel;
400         }
401
402         public JPanel JavaDoc getPreviewPanel() {
403             return previewPanel;
404         }
405         
406         public JComboBox JavaDoc getStartUrlComboBox() {
407             return panel.mergeStartUrlComboBox;
408         }
409
410         public JComboBox JavaDoc 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()); // NOI18N
416
}
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 JavaDoc root) {
427             super(repositoryRoot);
428             
429             panel = new MergeSinceOriginPanel();
430             previewPanel = new SinceOriginPreviewPanel();
431
432             mergeEndRepositoryPaths =
433                 new RepositoryPaths(
434                     repositoryRoot,
435                     (JTextComponent JavaDoc) 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 JavaDoc) panel.mergeEndUrlComboBox.getEditor().getEditorComponent()).getDocument().addDocumentListener(this);
444         }
445
446         public String JavaDoc getDisplayName() {
447             return org.openide.util.NbBundle.getMessage(Merge.class, "CTL_Merge_OneRepositoryFolderSinceOrigin"); // NOI18N
448
}
449
450         public String JavaDoc getDescription() {
451             return org.openide.util.NbBundle.getMessage(Merge.class, "CTL_Merge_OneRepositoryFolderSinceOriginDesc"); // NOI18N
452
}
453
454         public JPanel JavaDoc getFieldsPanel() {
455             return panel;
456         }
457
458         public JPanel JavaDoc 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 JavaDoc ex) {
474                 // should be already checked and
475
// not happen at this place anymore
476
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 JavaDoc ex) {
485                 // should be already checked and
486
// not happen at this place anymore
487
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 JavaDoc getStartUrlComboBox() {
501             return null;
502         }
503
504         public JComboBox JavaDoc getEndUrlComboBox() {
505             return panel.mergeEndUrlComboBox;
506         }
507
508         protected void setPreviewLabels() {
509             previewPanel.repositoryFolderTextField.setText(getRepositoryFile().getRepositoryUrl() + "/" + panel.mergeEndUrlComboBox.getEditor().getItem().toString()); // NOI18N
510
}
511
512     }
513 }
Popular Tags