KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > versioning > system > cvss > ui > history > SearchHistoryPanel


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.versioning.system.cvss.ui.history;
21
22 import org.openide.util.RequestProcessor;
23 import org.openide.util.NbBundle;
24 import org.openide.util.Lookup;
25 import org.openide.explorer.ExplorerManager;
26 import org.openide.nodes.Node;
27 import org.openide.windows.TopComponent;
28 import org.openide.awt.Mnemonics;
29 import org.openide.filesystems.FileObject;
30 import org.netbeans.modules.versioning.system.cvss.util.Utils;
31 import org.netbeans.modules.versioning.system.cvss.CvsVersioningSystem;
32 import org.netbeans.modules.versioning.system.cvss.VersionsCache;
33 import org.netbeans.modules.versioning.system.cvss.ui.actions.diff.DiffSetupSource;
34 import org.netbeans.modules.versioning.system.cvss.ui.actions.diff.Setup;
35 import org.netbeans.modules.versioning.util.NoContentPanel;
36 import org.netbeans.lib.cvsclient.command.log.LogInformation;
37 import org.netbeans.api.project.Project;
38
39 import javax.swing.*;
40 import java.io.File JavaDoc;
41 import java.util.*;
42 import java.beans.PropertyChangeEvent JavaDoc;
43 import java.beans.PropertyChangeListener JavaDoc;
44 import java.awt.event.KeyEvent JavaDoc;
45 import java.awt.event.ActionEvent JavaDoc;
46 import java.awt.event.ActionListener JavaDoc;
47 import java.awt.Dimension JavaDoc;
48
49 /**
50  * Contains all components of the Search History panel.
51  *
52  * @author Maros Sandor
53  */

54 class SearchHistoryPanel extends javax.swing.JPanel JavaDoc implements ExplorerManager.Provider, PropertyChangeListener JavaDoc, ActionListener JavaDoc, DiffSetupSource {
55
56     private final File JavaDoc[] roots;
57     private final SearchCriteriaPanel criteria;
58     
59     private Divider divider;
60     private RequestProcessor.Task currentSearchTask;
61
62     private boolean criteriaVisible;
63     private boolean searchInProgress;
64     private List results;
65     private List<Object JavaDoc> dispResults;
66     private SummaryView summaryView;
67     private DiffResultsView diffView;
68     
69     private AbstractAction nextAction;
70     private AbstractAction prevAction;
71
72     private Map<File JavaDoc, Project> fileProjects = new HashMap<File JavaDoc, Project>(100);
73     
74     /** Creates new form SearchHistoryPanel */
75     public SearchHistoryPanel(File JavaDoc [] roots, SearchCriteriaPanel criteria) {
76         this.roots = roots;
77         this.criteria = criteria;
78         criteriaVisible = true;
79         explorerManager = new ExplorerManager ();
80         initComponents();
81         setupComponents();
82         refreshComponents(true);
83     }
84
85     private void setupComponents() {
86         remove(jPanel1);
87
88         divider = new Divider(this);
89         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
90         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
91         gridBagConstraints.gridy = 2;
92         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
93         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
94         gridBagConstraints.weightx = 1.0;
95         gridBagConstraints.insets = new java.awt.Insets JavaDoc(2, 0, 2, 0);
96         add(divider, gridBagConstraints);
97
98         searchCriteriaPanel.add(criteria);
99         Action searchAction = new AbstractAction(NbBundle.getMessage(SearchHistoryPanel.class, "CTL_Search")) { // NOI18N
100
{
101                 putValue(Action.SHORT_DESCRIPTION, NbBundle.getMessage(SearchHistoryPanel.class, "TT_Search")); // NOI18N
102
}
103             public void actionPerformed(ActionEvent JavaDoc e) {
104                 search();
105             }
106         };
107         getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "search"); // NOI18N
108
getActionMap().put("search", searchAction); // NOI18N
109
bSearch.setAction(searchAction);
110         Mnemonics.setLocalizedText(bSearch, NbBundle.getMessage(SearchHistoryPanel.class, "CTL_Search")); // NOI18N
111

112         Dimension JavaDoc d1 = tbSummary.getPreferredSize();
113         Dimension JavaDoc d2 = tbDiff.getPreferredSize();
114         if (d1.width > d2.width) {
115             tbDiff.setPreferredSize(d1);
116         }
117         
118         nextAction = new AbstractAction(null, new javax.swing.ImageIcon JavaDoc(getClass().getResource("/org/netbeans/modules/versioning/system/cvss/resources/icons/diff-next.png"))) { // NOI18N
119
{
120                 putValue(Action.SHORT_DESCRIPTION, java.util.ResourceBundle.getBundle("org/netbeans/modules/versioning/system/cvss/ui/actions/diff/Bundle").
121                                                    getString("CTL_DiffPanel_Next_Tooltip"));
122             }
123             public void actionPerformed(ActionEvent JavaDoc e) {
124                 diffView.onNextButton();
125             }
126         };
127         prevAction = new AbstractAction(null, new javax.swing.ImageIcon JavaDoc(getClass().getResource("/org/netbeans/modules/versioning/system/cvss/resources/icons/diff-prev.png"))) { // NOI18N
128
{
129                 putValue(Action.SHORT_DESCRIPTION, java.util.ResourceBundle.getBundle("org/netbeans/modules/versioning/system/cvss/ui/actions/diff/Bundle").
130                                                    getString("CTL_DiffPanel_Prev_Tooltip"));
131             }
132             public void actionPerformed(ActionEvent JavaDoc e) {
133                 diffView.onPrevButton();
134             }
135         };
136         bNext.setAction(nextAction);
137         bPrev.setAction(prevAction);
138
139         getActionMap().put("jumpNext", nextAction); // NOI18N
140
getActionMap().put("jumpPrev", prevAction); // NOI18N
141
}
142
143     public void actionPerformed(ActionEvent JavaDoc e) {
144         if (e.getID() == Divider.DIVIDER_CLICKED) {
145             criteriaVisible = !criteriaVisible;
146             refreshComponents(false);
147         }
148     }
149     
150     void setSearchCriteriaVisible(boolean visible) {
151         criteriaVisible = visible;
152         refreshComponents(false);
153     }
154
155     private ExplorerManager explorerManager;
156
157     public void propertyChange(PropertyChangeEvent JavaDoc evt) {
158         if (ExplorerManager.PROP_SELECTED_NODES.equals(evt.getPropertyName())) {
159             TopComponent tc = (TopComponent) SwingUtilities.getAncestorOfClass(TopComponent.class, this);
160             if (tc == null) return;
161             tc.setActivatedNodes((Node[]) evt.getNewValue());
162         }
163     }
164
165     public void addNotify() {
166         super.addNotify();
167         explorerManager.addPropertyChangeListener(this);
168     }
169
170     public void removeNotify() {
171         explorerManager.removePropertyChangeListener(this);
172         super.removeNotify();
173     }
174     
175     public ExplorerManager getExplorerManager () {
176         return explorerManager;
177     }
178     
179     final void refreshComponents(boolean refreshResults) {
180         if (refreshResults) {
181             resultsPanel.removeAll();
182             if (results == null) {
183                 if (searchInProgress) {
184                     resultsPanel.add(new NoContentPanel(NbBundle.getMessage(SearchHistoryPanel.class, "LBL_SearchHistory_Searching"))); // NOI18N
185
} else {
186                     resultsPanel.add(new NoContentPanel(NbBundle.getMessage(SearchHistoryPanel.class, "LBL_SearchHistory_NoResults"))); // NOI18N
187
}
188             } else {
189                 if (tbSummary.isSelected()) {
190                     if (summaryView == null) {
191                         summaryView = new SummaryView(this, dispResults);
192                     }
193                     resultsPanel.add(summaryView.getComponent());
194                 } else {
195                     if (diffView == null) {
196                         diffView = new DiffResultsView(this, dispResults);
197                     }
198                     resultsPanel.add(diffView.getComponent());
199                 }
200             }
201             resultsPanel.revalidate();
202             resultsPanel.repaint();
203         }
204         nextAction.setEnabled(!tbSummary.isSelected() && diffView != null && diffView.isNextEnabled());
205         prevAction.setEnabled(!tbSummary.isSelected() && diffView != null && diffView.isPrevEnabled());
206
207         divider.setArrowDirection(criteriaVisible ? Divider.UP : Divider.DOWN);
208         searchCriteriaPanel.setVisible(criteriaVisible);
209         bSearch.setVisible(criteriaVisible);
210         revalidate();
211         repaint();
212     }
213     
214     /**
215      * It is called outside AWT.
216      *
217      * @param newResults
218      */

219     public void setResults(List newResults) {
220         setResults(newResults, false);
221     }
222
223     private void setResults(List newResults, boolean searching) {
224         if (newResults != null) this.dispResults = createDisplayList(newResults);
225         this.results = newResults;
226         this.searchInProgress = searching;
227         summaryView = null;
228         diffView = null;
229         SwingUtilities.invokeLater(new Runnable JavaDoc() {
230             public void run() {
231                 refreshComponents(true);
232             }
233         });
234     }
235     
236     List getDispResults() {
237         return dispResults;
238     }
239
240     private final Project NULL_PROJECT = new Project() {
241             
242         public FileObject getProjectDirectory() {
243             return null;
244         }
245
246         public Lookup getLookup() {
247             return null;
248         }
249     };
250
251     Project getProject(File JavaDoc file) {
252         Project p = fileProjects.get(file);
253         if (p == null) {
254             p = Utils.getProject(file);
255             if (p == null) p = NULL_PROJECT;
256             fileProjects.put(file, p);
257         }
258         if (p == NULL_PROJECT) p = null;
259         return p;
260     }
261     
262     public File JavaDoc[] getRoots() {
263         return roots;
264     }
265
266     public SearchCriteriaPanel getCriteria() {
267         return criteria;
268     }
269
270     private synchronized void search() {
271         if (currentSearchTask != null) {
272             currentSearchTask.cancel();
273         }
274         setResults(null, true);
275         SearchExecutor currentSearch = new SearchExecutor(this);
276         currentSearchTask = RequestProcessor.getDefault().create(currentSearch);
277         currentSearchTask.schedule(0);
278     }
279     
280     private List<Object JavaDoc> createDisplayList(List<LogInformation.Revision> inputList) {
281         List dispResults = new ArrayList();
282         if (inputList.isEmpty()) return dispResults;
283         
284         List<LogInformation.Revision> list = new ArrayList<LogInformation.Revision>(inputList);
285         Collections.sort(list, new ByRemotePathRevisionNumberComparator());
286
287         List<DispRevision> rs = new ArrayList<DispRevision>(list.size());
288         Set<String JavaDoc> addedBranchNumbers = new HashSet<String JavaDoc>(10);
289         for (LogInformation.Revision revision : list) {
290             String JavaDoc branchNumber = getBranchName(revision);
291             if (branchNumber != null && addedBranchNumbers.add(branchNumber)) {
292                 List<LogInformation.SymName> symNames = revision.getLogInfoHeader().getSymNamesForRevision(Utils.createBranchRevisionNumber(branchNumber));
293                 String JavaDoc branchName = null;
294                 if (symNames.size() > 0) {
295                     branchName = symNames.get(0).getName();
296                 }
297                 LogInformation.Revision aRev = revision.getLogInfoHeader().new Revision();
298                 aRev.setNumber(branchNumber);
299                 rs.add(new DispRevision(branchNumber, branchName, aRev));
300             }
301             List<LogInformation.SymName> allTtags = revision.getLogInfoHeader().getAllSymbolicNames();
302             List<String JavaDoc> revisionTags = new ArrayList<String JavaDoc>(2);
303             List<String JavaDoc> revisionBranches = new ArrayList<String JavaDoc>(2);
304             String JavaDoc aBranch = revision.getNumber() + ".0."; // NOI18N
305
for (LogInformation.SymName name : allTtags) {
306                 String JavaDoc nameRevision = name.getRevision();
307                 if (revision.getNumber().equals(nameRevision)) {
308                     revisionTags.add(name.getName());
309                 }
310                 if (nameRevision.startsWith(aBranch)) {
311                     int idx = nameRevision.lastIndexOf('.'); // NOI18N
312
revisionBranches.add(name.getName() + " (" + nameRevision.substring(0, idx - 1) + nameRevision.substring(idx + 1) + ")"); // NOI18N
313
}
314             }
315             rs.add(new DispRevision(revision, revisionTags, revisionBranches));
316         }
317         
318         ResultsContainer currentContainer = null;
319         
320         currentContainer = new ResultsContainer((rs.get(0)).getRevision().getLogInfoHeader());
321         currentContainer.add(createLocalRevision((rs.get(0)).getRevision().getLogInfoHeader()));
322         dispResults.add(currentContainer);
323         
324         for (DispRevision revision : rs) {
325             if (currentContainer.getHeader() != revision.getRevision().getLogInfoHeader()) {
326                 getProject(currentContainer.getHeader().getFile()); // precache outside AWT
327
if (currentContainer.getRevisions().size() < 1) {
328                     dispResults.remove(currentContainer);
329                     if (currentContainer.getRevisions().size() == 1) {
330                         dispResults.add(currentContainer.getRevisions().get(0));
331                     }
332                 }
333                 currentContainer = new ResultsContainer(revision.getRevision().getLogInfoHeader());
334                 currentContainer.add(createLocalRevision(revision.getRevision().getLogInfoHeader()));
335                 dispResults.add(currentContainer);
336             }
337             DispRevision parent = getParentRevision(rs, revision);
338             if (parent != null) {
339                 parent.addRevision(revision);
340             } else {
341                 currentContainer.add(revision);
342             }
343         }
344         if (currentContainer.getRevisions().size() < 1) {
345             dispResults.remove(currentContainer);
346             if (currentContainer.getRevisions().size() == 1) {
347                 dispResults.add(currentContainer.getRevisions().get(0));
348             }
349         }
350         return dispResults;
351     }
352
353     private DispRevision createLocalRevision(LogInformation logInfo) {
354         LogInformation.Revision currentRevision = logInfo.new Revision();
355         currentRevision.setNumber(VersionsCache.REVISION_CURRENT);
356         return new DispRevision(currentRevision, null, null);
357     }
358     
359     private String JavaDoc getBranchName(LogInformation.Revision rev) {
360         String JavaDoc number = rev.getNumber();
361         int idx = number.lastIndexOf('.', number.lastIndexOf('.') - 1); // NOI18N
362
return (idx == -1) ? null : number.substring(0, number.lastIndexOf('.')); // NOI18N
363
}
364
365     private static DispRevision getParentRevision(List results, DispRevision revision) {
366         String JavaDoc number = revision.getRevision().getNumber();
367         for (;;) {
368             int idx = number.lastIndexOf('.');
369             if (idx == -1) return null;
370             number = number.substring(0, idx);
371             LogInformation.Revision parentRev = revision.getRevision().getLogInfoHeader().new Revision();
372             parentRev.setNumber(number);
373             int index = Collections.binarySearch(results, new DispRevision(parentRev, null, null), revisionsComparator);
374             if (index >= 0) return (DispRevision) results.get(index);
375         }
376     }
377     
378     private static final Comparator revisionsComparator = new ByRemotePathRevisionNumberComparator() {
379         public int compare(Object JavaDoc o1, Object JavaDoc o2) {
380             return super.compare(((DispRevision) o1).getRevision(), ((DispRevision) o2).getRevision());
381         }
382     };
383
384     void executeSearch() {
385         search();
386     }
387
388     void showDiff(DispRevision revision) {
389         tbDiff.setSelected(true);
390         refreshComponents(true);
391         diffView.select(revision);
392     }
393
394     public void showDiff(ResultsContainer container) {
395         tbDiff.setSelected(true);
396         refreshComponents(true);
397         diffView.select(container);
398     }
399
400     /**
401      * Return diff setup describing shown history.
402      * It return empty collection on non-atomic
403      * revision ranges. XXX move this logic to clients?
404      */

405     public Collection<Setup> getSetups() {
406         if (dispResults == null) {
407             return Collections.emptySet();
408         }
409
410         List<Object JavaDoc> selectedItems = dispResults;
411         if (tbSummary.isSelected()) {
412             selectedItems = summaryView.getSelection();
413         } else {
414             selectedItems = diffView.getSelection();
415         }
416         
417         // treat empty selection as all-containers selection
418
if (selectedItems.size() == 0) {
419             for (Object JavaDoc o : dispResults) {
420                 if (o instanceof ResultsContainer) {
421                     selectedItems.add(o);
422                 }
423             }
424         }
425
426         // group selected revisions by its container, taking the oldest and newest revisions, producing a patch
427
// for container-only selections produce eldest-newest patches in them
428
List<Setup> setups = new ArrayList<Setup>(selectedItems.size());
429         Set<LogInformation> includedFiles = new HashSet<LogInformation>();
430         
431         for (Object JavaDoc item : selectedItems) {
432             if (!(item instanceof ResultsContainer)) continue;
433             ResultsContainer entry = (ResultsContainer) item;
434             File JavaDoc file = entry.getHeader().getFile();
435             
436             boolean atomicRange = true;
437             String JavaDoc prev = null;
438             List revisions = entry.getRevisions();
439             Iterator revs = revisions.iterator();
440             while (revs.hasNext()) {
441                 DispRevision revision = (DispRevision) revs.next();
442                 String JavaDoc rev = revision.getRevision().getNumber();
443                 if (VersionsCache.REVISION_CURRENT.equals(rev)) {
444                     // skip Local Copy revisions
445
continue;
446                 }
447                 if (prev != null) {
448                     if (!rev.equals(Utils.previousRevision(prev))) {
449                         atomicRange = false;
450                         break;
451                     }
452                 }
453                 prev = rev;
454             }
455
456             // skip containers with non-atomic range of revisions, the patch would make no sense
457
if (!atomicRange) {
458                 continue;
459             }
460
461             String JavaDoc eldest = entry.getEldestRevision();
462             String JavaDoc newest = entry.getNewestRevision();
463             Setup setup = new Setup(file, eldest, newest);
464             includedFiles.add(entry.getHeader());
465             setups.add(setup);
466         }
467         
468         for (int i = 0; i < selectedItems.size(); i++) {
469             Object JavaDoc item = selectedItems.get(i);
470             if (!(item instanceof DispRevision)) continue;
471             DispRevision rev1 = (DispRevision) item;
472             LogInformation header = rev1.getRevision().getLogInfoHeader();
473             if (includedFiles.contains(header)) continue;
474             String JavaDoc r1 = rev1.getRevision().getNumber();
475             String JavaDoc r2 = r1;
476             for (int j = i + 1; j < selectedItems.size(); j++) {
477                 Object JavaDoc item2 = selectedItems.get(j);
478                 if (!(item2 instanceof DispRevision)) continue;
479                 DispRevision rev2 = (DispRevision) item2;
480                 if (header.equals(rev2.getRevision().getLogInfoHeader())) {
481                     r2 = rev2.getRevision().getNumber();
482                 }
483             }
484             if (r2 == null) continue;
485             if (compareRevisions(r1, r2) > 0) {
486                 String JavaDoc tmp = r2;
487                 r2 = r1;
488                 r1 = tmp;
489             }
490             if (Utils.previousRevision(r1) != null) {
491                 r1 = Utils.previousRevision(r1);
492             }
493             Setup setup = new Setup(header.getFile(), r1, r2);
494             includedFiles.add(header);
495             setups.add(setup);
496         }
497         
498         return setups;
499     }
500
501     public String JavaDoc getSetupDisplayName() {
502         return null;
503     }
504
505     static class ResultsContainer {
506         
507         private List<DispRevision> revisions = new ArrayList<DispRevision>(2);
508         private String JavaDoc name;
509         private String JavaDoc path;
510         private final LogInformation header;
511
512         public ResultsContainer(LogInformation header) {
513             this.header = header;
514             File JavaDoc file = header.getFile();
515             try {
516                 name = CvsVersioningSystem.getInstance().getAdminHandler().getRepositoryForDirectory(file.getParentFile().getAbsolutePath(), "") + "/" + file.getName(); // NOI18N
517
} catch (Exception JavaDoc e) {
518                 name = header.getRepositoryFilename();
519                 if (name.endsWith(",v")) name = name.substring(0, name.lastIndexOf(",v")); // NOI18N
520
}
521             path = name.substring(0, name.lastIndexOf('/'));
522             name = name.substring(path.length() + 1);
523         }
524
525         public LogInformation getHeader() {
526             return header;
527         }
528
529         public void add(DispRevision revision) {
530             revisions.add(revisions.size(), revision);
531         }
532         
533         public String JavaDoc getName() {
534             return name;
535         }
536
537         public List<DispRevision> getRevisions() {
538             return revisions;
539         }
540
541         /**
542          * @return String previous revision before the eldest revision in the container (if the eldest is 1.6 then 1.5 is returned).
543          * If the container contains revision 1.1 then 1.1 is returned.
544          */

545         public String JavaDoc getEldestRevision() {
546             DispRevision rev = revisions.get(revisions.size() - 1);
547             String JavaDoc revNumber = Utils.previousRevision(rev.getRevision().getNumber());
548             return revNumber != null ? revNumber : rev.getRevision().getNumber();
549         }
550
551         public String JavaDoc getNewestRevision() {
552             String JavaDoc newest = revisions.get(0).getRevision().getNumber();
553             if (VersionsCache.REVISION_CURRENT.equals(newest)) newest = revisions.get(1).getRevision().getNumber();
554             return newest;
555         }
556         
557         public String JavaDoc getPath() {
558             return path;
559         }
560
561         public File JavaDoc getFile() {
562             return header.getFile();
563         }
564
565         /** Goes into clipboard */
566         public String JavaDoc toString() {
567             return getName() + " " + getPath(); // NOI18N
568
}
569     }
570
571     static class DispRevision {
572         
573         private final LogInformation.Revision revision;
574         private String JavaDoc name;
575         private List children;
576         private String JavaDoc path;
577         private int indentation;
578         
579         private final String JavaDoc branchNumber;
580         private final String JavaDoc branchName;
581         private final int hashCode;
582         private final List<String JavaDoc> tags;
583         private final List<String JavaDoc> branches;
584
585         public DispRevision(String JavaDoc branchNumber, String JavaDoc branchName, LogInformation.Revision revision) {
586             this.branchNumber = branchNumber;
587             this.branchName = branchName;
588             this.revision = revision;
589             this.hashCode = branchNumber.hashCode();
590             tags = null;
591             branches = null;
592         }
593         
594         public DispRevision(LogInformation.Revision revision, List<String JavaDoc> tags, List<String JavaDoc> branches) {
595             this.revision = revision;
596             this.tags = tags == null ? null : Collections.unmodifiableList(tags);
597             this.branches = branches == null ? null : Collections.unmodifiableList(branches);
598             this.hashCode = revision.hashCode();
599             this.branchNumber = null;
600             this.branchName = null;
601             File JavaDoc file = revision.getLogInfoHeader().getFile();
602             try {
603                 name = CvsVersioningSystem.getInstance().getAdminHandler().getRepositoryForDirectory(file.getParentFile().getAbsolutePath(), "") + "/" + file.getName(); // NOI18N
604
} catch (Exception JavaDoc e) {
605                 name = revision.getLogInfoHeader().getRepositoryFilename();
606                 if (name.endsWith(",v")) name = name.substring(0, name.lastIndexOf(",v")); // NOI18N
607
}
608             path = name.substring(0, name.lastIndexOf('/'));
609         }
610
611         public List<String JavaDoc> getTags() {
612             return tags;
613         }
614
615         public List<String JavaDoc> getBranches() {
616             return branches;
617         }
618
619         public String JavaDoc getBranchName() {
620             return branchName;
621         }
622
623         public String JavaDoc getName() {
624             return name;
625         }
626
627         public String JavaDoc getPath() {
628             return path;
629         }
630
631         public LogInformation.Revision getRevision() {
632             return revision;
633         }
634
635         public void addRevision(DispRevision revision) {
636             if (children == null) {
637                 children = new ArrayList();
638             }
639             children.add(revision);
640         }
641
642         public List getChildren() {
643             return children;
644         }
645
646         public boolean equals(Object JavaDoc o) {
647             if (this == o) return true;
648             if (!(o instanceof DispRevision)) return false;
649             if (branchNumber != null) {
650                 return branchNumber.equals(((DispRevision) o).branchNumber);
651             }
652             return revision.equals(((DispRevision) o).revision);
653         }
654
655         public int hashCode() {
656             return hashCode;
657         }
658
659         public int getIndentation() {
660             return indentation;
661         }
662         
663         public void setIndentation(int indentation) {
664             this.indentation = indentation;
665         }
666
667         /** Goes into clipboard */
668         public String JavaDoc toString() {
669             StringBuffer JavaDoc indent = new StringBuffer JavaDoc(" "); // NOI18N
670
for (int i = 0; i<getIndentation(); i++) {
671                 indent.append(" "); // NOI18N
672
}
673             StringBuffer JavaDoc text = new StringBuffer JavaDoc();
674             text.append(indent).append(getRevision().getNumber()).append("\t").append(getRevision().getDateString()).append(" ").append(getRevision().getAuthor()); // NOI18N
675
text.append("\n"); // NOI18N
676
text.append(getRevision().getMessage());
677
678             return text.toString();
679         }
680
681         public boolean isBranchRoot() {
682             return branchNumber != null;
683         }
684     }
685
686     /**
687      * Sorts found commits by 1. Filename 2. revision number
688      */

689     private static class ByRemotePathRevisionNumberComparator implements Comparator {
690
691         public int compare(Object JavaDoc o1, Object JavaDoc o2) {
692             LogInformation.Revision r1 = (LogInformation.Revision) o1;
693             LogInformation.Revision r2 = (LogInformation.Revision) o2;
694             int namec = r1.getLogInfoHeader().getFile().getName().compareToIgnoreCase(r2.getLogInfoHeader().getFile().getName());
695             if (namec != 0) return namec;
696             namec = r1.getLogInfoHeader().getRepositoryFilename().compareToIgnoreCase(r2.getLogInfoHeader().getRepositoryFilename());
697             if (namec != 0) return namec;
698             return compareRevisionsTrunkFirst(r1.getNumber(), r2.getNumber());
699         }
700     }
701     
702     public static int compareRevisionsTrunkFirst(String JavaDoc r1, String JavaDoc r2) {
703         StringTokenizer st1 = new StringTokenizer(r1, "."); // NOI18N
704
StringTokenizer st2 = new StringTokenizer(r2, "."); // NOI18N
705
for (;;) {
706             if (!st1.hasMoreTokens()) {
707                 return st2.hasMoreTokens() ? -1 : 0;
708             }
709             if (!st2.hasMoreTokens()) {
710                 return st1.hasMoreTokens() ? 1 : 0;
711             }
712             int n1 = Integer.parseInt(st1.nextToken());
713             int n2 = Integer.parseInt(st2.nextToken());
714             if (n1 != n2) return n2 - n1;
715         }
716     }
717     
718     /**
719      *
720      * @param r1
721      * @param r2
722      * @return negative integer if r1 is older than r2, positive integer if r1 is newer than r2, 0 if both revisions are equal
723      */

724     public static int compareRevisions(String JavaDoc r1, String JavaDoc r2) {
725         if (r1.equals(r2)) return 0;
726         StringTokenizer st1 = new StringTokenizer(r1, "."); // NOI18N
727
StringTokenizer st2 = new StringTokenizer(r2, "."); // NOI18N
728
for (;;) {
729             if (!st1.hasMoreTokens()) {
730                 return -1;
731             }
732             if (!st2.hasMoreTokens()) {
733                 return 1;
734             }
735             int n1 = Integer.parseInt(st1.nextToken());
736             int n2 = Integer.parseInt(st2.nextToken());
737             if (n1 != n2) return n1 - n2;
738         }
739     }
740         
741     /** This method is called from within the constructor to
742      * initialize the form.
743      * WARNING: Do NOT modify this code. The content of this method is
744      * always regenerated by the Form Editor.
745      */

746     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
747
private void initComponents() {
748         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
749
750         buttonGroup1 = new javax.swing.ButtonGroup JavaDoc();
751         searchCriteriaPanel = new javax.swing.JPanel JavaDoc();
752         bSearch = new javax.swing.JButton JavaDoc();
753         jPanel1 = new javax.swing.JPanel JavaDoc();
754         jToolBar1 = new javax.swing.JToolBar JavaDoc();
755         tbSummary = new javax.swing.JToggleButton JavaDoc();
756         tbDiff = new javax.swing.JToggleButton JavaDoc();
757         jSeparator2 = new javax.swing.JSeparator JavaDoc();
758         bNext = new javax.swing.JButton JavaDoc();
759         bPrev = new javax.swing.JButton JavaDoc();
760         resultsPanel = new javax.swing.JPanel JavaDoc();
761
762         setLayout(new java.awt.GridBagLayout JavaDoc());
763
764         setBorder(javax.swing.BorderFactory.createEmptyBorder(8, 8, 0, 8));
765         searchCriteriaPanel.setLayout(new java.awt.BorderLayout JavaDoc());
766
767         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
768         gridBagConstraints.gridx = 0;
769         gridBagConstraints.gridy = 0;
770         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
771         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
772         gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
773         gridBagConstraints.weightx = 1.0;
774         add(searchCriteriaPanel, gridBagConstraints);
775
776         bSearch.setToolTipText(java.util.ResourceBundle.getBundle("org/netbeans/modules/versioning/system/cvss/ui/history/Bundle").getString("TT_Search"));
777         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
778         gridBagConstraints.gridx = 0;
779         gridBagConstraints.gridy = 1;
780         gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
781         add(bSearch, gridBagConstraints);
782
783         jPanel1.setPreferredSize(new java.awt.Dimension JavaDoc(10, 6));
784         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
785         gridBagConstraints.gridy = 2;
786         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
787         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
788         gridBagConstraints.weightx = 1.0;
789         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 2, 0);
790         add(jPanel1, gridBagConstraints);
791
792         jToolBar1.setFloatable(false);
793         jToolBar1.setRollover(true);
794         buttonGroup1.add(tbSummary);
795         tbSummary.setSelected(true);
796         org.openide.awt.Mnemonics.setLocalizedText(tbSummary, java.util.ResourceBundle.getBundle("org/netbeans/modules/versioning/system/cvss/ui/history/Bundle").getString("CTL_ShowSummary"));
797         tbSummary.setToolTipText(java.util.ResourceBundle.getBundle("org/netbeans/modules/versioning/system/cvss/ui/history/Bundle").getString("TT_Summary"));
798         tbSummary.addActionListener(new java.awt.event.ActionListener JavaDoc() {
799             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
800                 onViewToggle(evt);
801             }
802         });
803
804         jToolBar1.add(tbSummary);
805
806         buttonGroup1.add(tbDiff);
807         org.openide.awt.Mnemonics.setLocalizedText(tbDiff, java.util.ResourceBundle.getBundle("org/netbeans/modules/versioning/system/cvss/ui/history/Bundle").getString("CTL_ShowDiff"));
808         tbDiff.setToolTipText(java.util.ResourceBundle.getBundle("org/netbeans/modules/versioning/system/cvss/ui/history/Bundle").getString("TT_ShowDiff"));
809         tbDiff.addActionListener(new java.awt.event.ActionListener JavaDoc() {
810             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
811                 onViewToggle(evt);
812             }
813         });
814
815         jToolBar1.add(tbDiff);
816
817         jSeparator2.setOrientation(javax.swing.SwingConstants.VERTICAL);
818         jSeparator2.setMaximumSize(new java.awt.Dimension JavaDoc(2, 32767));
819         jToolBar1.add(jSeparator2);
820
821         bNext.setIcon(new javax.swing.ImageIcon JavaDoc(getClass().getResource("/org/netbeans/modules/versioning/system/cvss/resources/icons/diff-next.png")));
822         jToolBar1.add(bNext);
823         bNext.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/versioning/system/cvss/ui/history/Bundle").getString("ACSN_NextDifference"));
824
825         bPrev.setIcon(new javax.swing.ImageIcon JavaDoc(getClass().getResource("/org/netbeans/modules/versioning/system/cvss/resources/icons/diff-prev.png")));
826         jToolBar1.add(bPrev);
827         bPrev.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/versioning/system/cvss/ui/history/Bundle").getString("ACSN_PrevDifference"));
828
829         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
830         gridBagConstraints.gridy = 3;
831         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
832         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
833         add(jToolBar1, gridBagConstraints);
834
835         resultsPanel.setLayout(new java.awt.BorderLayout JavaDoc());
836
837         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
838         gridBagConstraints.gridx = 0;
839         gridBagConstraints.gridy = 4;
840         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
841         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
842         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
843         gridBagConstraints.weightx = 1.0;
844         gridBagConstraints.weighty = 1.0;
845         gridBagConstraints.insets = new java.awt.Insets JavaDoc(8, 0, 8, 0);
846         add(resultsPanel, gridBagConstraints);
847
848     }
849     // </editor-fold>//GEN-END:initComponents
850

851     private void onViewToggle(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_onViewToggle
852
refreshComponents(true);
853     }//GEN-LAST:event_onViewToggle
854

855     
856     // Variables declaration - do not modify//GEN-BEGIN:variables
857
private javax.swing.JButton JavaDoc bNext;
858     private javax.swing.JButton JavaDoc bPrev;
859     private javax.swing.JButton JavaDoc bSearch;
860     private javax.swing.ButtonGroup JavaDoc buttonGroup1;
861     private javax.swing.JPanel JavaDoc jPanel1;
862     private javax.swing.JSeparator JavaDoc jSeparator2;
863     private javax.swing.JToolBar JavaDoc jToolBar1;
864     private javax.swing.JPanel JavaDoc resultsPanel;
865     private javax.swing.JPanel JavaDoc searchCriteriaPanel;
866     private javax.swing.JToggleButton JavaDoc tbDiff;
867     private javax.swing.JToggleButton JavaDoc tbSummary;
868     // End of variables declaration//GEN-END:variables
869

870 }
871
Popular Tags