Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 300347 | Differences between
and this patch

Collapse All | Expand All

(-)compare/org/eclipse/compare/internal/patch/DiffViewerComparator.java (+56 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.compare.internal.patch;
12
13
import java.util.Comparator;
14
import java.util.regex.Pattern;
15
16
import org.eclipse.compare.structuremergeviewer.DiffNode;
17
import org.eclipse.compare.structuremergeviewer.DocumentRangeNode;
18
import org.eclipse.jface.util.Policy;
19
import org.eclipse.jface.viewers.ViewerSorter;
20
21
public class DiffViewerComparator extends ViewerSorter {
22
23
	public boolean isSorterProperty(Object element, Object property) {
24
		return false;
25
	}
26
27
	public int category(Object node) {
28
		if (node instanceof DiffNode) {
29
			Object o= ((DiffNode) node).getId();
30
			if (o instanceof DocumentRangeNode)
31
				return ((DocumentRangeNode) o).getTypeCode();
32
		}
33
		return 0;
34
	}
35
36
	protected Comparator getComparator() {
37
		return new Comparator() {
38
			public int compare(Object arg0, Object arg1) {
39
				String label0 = arg0 == null ? "" : arg0.toString(); //$NON-NLS-1$
40
				String label1 = arg1 == null ? "" : arg1.toString(); //$NON-NLS-1$
41
42
				// see org.eclipse.compare.internal.patch.Hunk.getDescription()
43
				String pattern = "\\d+,\\d+ -> \\d+,\\d+.*"; //$NON-NLS-1$
44
45
				if (Pattern.matches(pattern, label0)
46
						&& Pattern.matches(pattern, label1)) {
47
					int oldStart0 = Integer.parseInt(label0.split(",")[0]); //$NON-NLS-1$
48
					int oldStart1 = Integer.parseInt(label1.split(",")[0]); //$NON-NLS-1$
49
50
					return oldStart0 - oldStart1;
51
				}
52
				return Policy.getComparator().compare(arg0, arg1);
53
			}
54
		};
55
	}
56
}
(-)compare/org/eclipse/compare/structuremergeviewer/DiffTreeViewer.java (-40 / +1 lines)
Lines 10-25 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.compare.structuremergeviewer;
11
package org.eclipse.compare.structuremergeviewer;
12
12
13
import java.util.Comparator;
14
import java.util.Iterator;
13
import java.util.Iterator;
15
import java.util.ResourceBundle;
14
import java.util.ResourceBundle;
16
import java.util.regex.Pattern;
17
15
18
import org.eclipse.compare.*;
16
import org.eclipse.compare.*;
19
import org.eclipse.compare.internal.Utilities;
17
import org.eclipse.compare.internal.Utilities;
18
import org.eclipse.compare.internal.patch.DiffViewerComparator;
20
import org.eclipse.jface.action.*;
19
import org.eclipse.jface.action.*;
21
import org.eclipse.jface.util.IPropertyChangeListener;
20
import org.eclipse.jface.util.IPropertyChangeListener;
22
import org.eclipse.jface.util.Policy;
23
import org.eclipse.jface.util.PropertyChangeEvent;
21
import org.eclipse.jface.util.PropertyChangeEvent;
24
import org.eclipse.jface.viewers.*;
22
import org.eclipse.jface.viewers.*;
25
import org.eclipse.swt.SWT;
23
import org.eclipse.swt.SWT;
Lines 41-83 Link Here
41
 */
39
 */
42
public class DiffTreeViewer extends TreeViewer {
40
public class DiffTreeViewer extends TreeViewer {
43
	
41
	
44
	static class DiffViewerComparator extends ViewerComparator {
45
	
46
		public boolean isSorterProperty(Object element, Object property) {
47
			return false;
48
		}
49
	
50
		public int category(Object node) {
51
			if (node instanceof DiffNode) {
52
				Object o= ((DiffNode) node).getId();
53
				if (o instanceof DocumentRangeNode)
54
					return ((DocumentRangeNode) o).getTypeCode();
55
			}
56
			return 0;
57
		}
58
59
		protected Comparator getComparator() {
60
			return new Comparator() {
61
				public int compare(Object arg0, Object arg1) {
62
					String label0 = arg0 == null ? "" : arg0.toString(); //$NON-NLS-1$
63
					String label1 = arg1 == null ? "" : arg1.toString(); //$NON-NLS-1$
64
65
					// see org.eclipse.compare.internal.patch.Hunk.getDescription()
66
					String pattern = "\\d+,\\d+ -> \\d+,\\d+.*"; //$NON-NLS-1$
67
68
					if (Pattern.matches(pattern, label0)
69
							&& Pattern.matches(pattern, label1)) {
70
						int oldStart0 = Integer.parseInt(label0.split(",")[0]); //$NON-NLS-1$
71
						int oldStart1 = Integer.parseInt(label1.split(",")[0]); //$NON-NLS-1$
72
73
						return oldStart0 - oldStart1;
74
					}
75
					return Policy.getComparator().compare(arg0, arg1);
76
				}
77
			};
78
		}
79
	}	
80
81
	class DiffViewerContentProvider implements ITreeContentProvider {
42
	class DiffViewerContentProvider implements ITreeContentProvider {
82
			
43
			
83
		public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
44
		public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
(-)plugin.xml (+8 lines)
Lines 632-637 Link Here
632
            <actionProvider
632
            <actionProvider
633
                  class="org.eclipse.team.internal.ui.synchronize.patch.ApplyPatchSynchronizationActionProvider">
633
                  class="org.eclipse.team.internal.ui.synchronize.patch.ApplyPatchSynchronizationActionProvider">
634
            </actionProvider>
634
            </actionProvider>
635
            <commonSorter
636
                  class="org.eclipse.compare.internal.patch.DiffViewerComparator">
637
               <parentExpression>
638
                  <instanceof
639
                        value="org.eclipse.compare.internal.patch.PatchFileDiffNode">
640
                  </instanceof>
641
               </parentExpression>
642
            </commonSorter>
635
         </navigatorContent>
643
         </navigatorContent>
636
      </extension>
644
      </extension>
637
      <extension
645
      <extension

Return to bug 300347