Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Zarna2011-10-13 11:36:27 +0000
committerTomasz Zarna2011-10-13 11:36:27 +0000
commitf0e53ee2640b02d1f95f87dfcfa88331c3336845 (patch)
tree666e298f81221c128f3c0249c32154b1aef93861 /bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/DiffViewerComparator.java
parente4281ecfd04ac79545ba778419a1cfa257818d4c (diff)
downloadeclipse.platform.team-f0e53ee2640b02d1f95f87dfcfa88331c3336845.tar.gz
eclipse.platform.team-f0e53ee2640b02d1f95f87dfcfa88331c3336845.tar.xz
eclipse.platform.team-f0e53ee2640b02d1f95f87dfcfa88331c3336845.zip
bug 359032: Move plugins under bundles/org.eclipse.compare/plugins/ to
bundles/
Diffstat (limited to 'bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/DiffViewerComparator.java')
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/DiffViewerComparator.java56
1 files changed, 56 insertions, 0 deletions
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/DiffViewerComparator.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/DiffViewerComparator.java
new file mode 100644
index 000000000..5a0134edd
--- /dev/null
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/DiffViewerComparator.java
@@ -0,0 +1,56 @@
+/*******************************************************************************
+ * Copyright (c) 2010 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.compare.internal.patch;
+
+import java.util.Comparator;
+import java.util.regex.Pattern;
+
+import org.eclipse.compare.structuremergeviewer.DiffNode;
+import org.eclipse.compare.structuremergeviewer.DocumentRangeNode;
+import org.eclipse.jface.util.Policy;
+import org.eclipse.jface.viewers.ViewerSorter;
+
+public class DiffViewerComparator extends ViewerSorter {
+
+ public boolean isSorterProperty(Object element, Object property) {
+ return false;
+ }
+
+ public int category(Object node) {
+ if (node instanceof DiffNode) {
+ Object o= ((DiffNode) node).getId();
+ if (o instanceof DocumentRangeNode)
+ return ((DocumentRangeNode) o).getTypeCode();
+ }
+ return 0;
+ }
+
+ protected Comparator getComparator() {
+ return new Comparator() {
+ public int compare(Object arg0, Object arg1) {
+ String label0 = arg0 == null ? "" : arg0.toString(); //$NON-NLS-1$
+ String label1 = arg1 == null ? "" : arg1.toString(); //$NON-NLS-1$
+
+ // see org.eclipse.compare.internal.patch.Hunk.getDescription()
+ String pattern = "\\d+,\\d+ -> \\d+,\\d+.*"; //$NON-NLS-1$
+
+ if (Pattern.matches(pattern, label0)
+ && Pattern.matches(pattern, label1)) {
+ int oldStart0 = Integer.parseInt(label0.split(",")[0]); //$NON-NLS-1$
+ int oldStart1 = Integer.parseInt(label1.split(",")[0]); //$NON-NLS-1$
+
+ return oldStart0 - oldStart1;
+ }
+ return Policy.getComparator().compare(arg0, arg1);
+ }
+ };
+ }
+} \ No newline at end of file

Back to the top