Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/ChangeSetModelSorter.java4
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/SynchronizeModelElementSorter.java13
-rw-r--r--tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/ui/AllUITests.java1
-rw-r--r--tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/ui/PatchTreeTest.java182
4 files changed, 190 insertions, 10 deletions
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/ChangeSetModelSorter.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/ChangeSetModelSorter.java
index 9cd6963f7..f44fa5108 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/ChangeSetModelSorter.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/ChangeSetModelSorter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
+ * Copyright (c) 2000, 2011 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
@@ -106,7 +106,7 @@ public class ChangeSetModelSorter extends ViewerSorter {
if (embeddedSorter != null) {
return embeddedSorter.compare(viewer, o1, o2);
} else {
- compareNames(((ISynchronizeModelElement)o1).getName(), ((ISynchronizeModelElement)o2).getName());
+ return compareNames(((ISynchronizeModelElement)o1).getName(), ((ISynchronizeModelElement)o2).getName());
}
} else if (o1 instanceof ISynchronizeModelElement)
return 1;
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/SynchronizeModelElementSorter.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/SynchronizeModelElementSorter.java
index 8b9cac74d..af94ed8cc 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/SynchronizeModelElementSorter.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/SynchronizeModelElementSorter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * Copyright (c) 2000, 2011 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
@@ -31,13 +31,10 @@ public class SynchronizeModelElementSorter extends ResourceSorter {
public int compare(Viewer viewer, Object o1, Object o2) {
IResource resource1 = getResource(o1);
IResource resource2 = getResource(o2);
- int result;
- if (resource1 != null && resource2 != null) {
- result = super.compare(viewer, resource1, resource2);
- } else {
- result = super.compare(viewer, o1, o2);
- }
- return result;
+ Object objectToCompare1 = resource1==null ? o1 : resource1;
+ Object objectToCompare2 = resource2==null ? o2 : resource2;
+
+ return super.compare(viewer, objectToCompare1, objectToCompare2);
}
protected IResource getResource(Object obj) {
diff --git a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/ui/AllUITests.java b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/ui/AllUITests.java
index 93d31a5d1..c595f253a 100644
--- a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/ui/AllUITests.java
+++ b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/ui/AllUITests.java
@@ -36,6 +36,7 @@ public class AllUITests extends EclipseTest {
suite.addTest(CVSProjectSetImportTest.suite());
suite.addTest(CreatePatchTest.suite());
suite.addTest(CVSHisoryTableProviderTest.suite());
+ suite.addTest(PatchTreeTest.suite());
return suite;
}
diff --git a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/ui/PatchTreeTest.java b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/ui/PatchTreeTest.java
new file mode 100644
index 000000000..8ffe7820f
--- /dev/null
+++ b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/ui/PatchTreeTest.java
@@ -0,0 +1,182 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.team.tests.ccvs.ui;
+
+import junit.framework.Test;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerSorter;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Item;
+import org.eclipse.swt.widgets.Widget;
+import org.eclipse.team.core.TeamException;
+import org.eclipse.team.core.synchronize.SyncInfoSet;
+import org.eclipse.team.internal.ccvs.core.mapping.CVSActiveChangeSet;
+import org.eclipse.team.internal.ui.synchronize.ChangeSetCapability;
+import org.eclipse.team.internal.ui.synchronize.ChangeSetDiffNode;
+import org.eclipse.team.internal.ui.synchronize.ChangeSetModelProvider;
+import org.eclipse.team.internal.ui.synchronize.ChangeSetModelSorter;
+import org.eclipse.team.internal.ui.synchronize.SynchronizeModelElementSorter;
+import org.eclipse.team.internal.ui.synchronize.SynchronizePageConfiguration;
+import org.eclipse.team.internal.ui.synchronize.TreeViewerAdvisor;
+import org.eclipse.team.internal.ui.synchronize.UnchangedResourceModelElement;
+import org.eclipse.team.tests.ccvs.core.EclipseTest;
+import org.eclipse.team.ui.synchronize.ISynchronizePage;
+import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration;
+import org.eclipse.team.ui.synchronize.ISynchronizePageSite;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+
+public class PatchTreeTest extends EclipseTest {
+
+ public void testChangeSetModelSorter() throws CoreException {
+ MyTreeViewer tree = new MyTreeViewer();
+ tree.init();
+ ViewerSorter sorter = tree.getSorter();
+
+ UnchangedResourceModelElement elementZ = new UnchangedResourceModelElement(
+ null, getUniqueTestProject("z"));
+ ChangeSetDiffNode nodeA = new ChangeSetDiffNode(null,
+ new CVSActiveChangeSet(null, "a"));
+ ChangeSetDiffNode nodeB = new ChangeSetDiffNode(null,
+ new CVSActiveChangeSet(null, "b"));
+ ChangeSetDiffNode nodeC = new ChangeSetDiffNode(null,
+ new CVSActiveChangeSet(null, "c"));
+ Object[] elements = { nodeB, nodeC, elementZ, nodeA };
+
+ sorter.sort(tree, elements);
+
+ assertEquals(nodeA, elements[0]);
+ assertEquals(nodeB, elements[1]);
+ assertEquals(nodeC, elements[2]);
+ assertEquals(elementZ, elements[3]);
+ }
+
+ public void testDuplicatedElementsInPatchTree() throws TeamException,
+ CoreException {
+ MyTreeViewer tree = new MyTreeViewer();
+ tree.init();
+
+ UnchangedResourceModelElement element = new UnchangedResourceModelElement(
+ null, getUniqueTestProject("z"));
+ ChangeSetDiffNode nodeA = new ChangeSetDiffNode(null,
+ new CVSActiveChangeSet(null, "a"));
+ ChangeSetDiffNode nodeB = new ChangeSetDiffNode(null,
+ new CVSActiveChangeSet(null, "b"));
+ ChangeSetDiffNode nodeC = new ChangeSetDiffNode(null,
+ new CVSActiveChangeSet(null, "c"));
+ ChangeSetDiffNode nodeD = new ChangeSetDiffNode(null,
+ new CVSActiveChangeSet(null, "d"));
+
+ Item[] treeChildren = tree.testGetChildren(tree.getTree());
+ assertEquals(0, treeChildren.length);
+
+ Object children[] = { nodeC, nodeB, element, nodeA };
+ tree.testInternalAdd(children);
+ treeChildren = tree.testGetChildren(tree.getTree());
+ assertEquals(children.length, treeChildren.length);
+
+ Object childrenToAdd[] = { nodeD, element, nodeA, nodeB };
+ tree.testInternalAdd(childrenToAdd);
+ treeChildren = tree.testGetChildren(tree.getTree());
+
+ Object[] expected = { nodeC, nodeB, element, nodeA, nodeD };
+ assertEquals(expected.length, treeChildren.length);
+
+ for (int i = 0; i < treeChildren.length; i++) {
+ assertEquals(1, countByData(treeChildren, treeChildren[i]));
+ }
+ }
+
+ private int countByData(final Item[] a, Item o) {
+ int c = 0;
+ for (int i = 0; i < a.length; i++) {
+ if (a[i].getData() == o.getData())
+ c++;
+ }
+ return c;
+ }
+
+ private SynchronizePageConfiguration getMyConfiguration(final Viewer viewer) {
+ SynchronizePageConfiguration conf = new SynchronizePageConfiguration(
+ null);
+ conf.setPage(new ISynchronizePage() {
+
+ public void init(ISynchronizePageSite site)
+ throws PartInitException {
+ }
+
+ public Viewer getViewer() {
+ return viewer;
+ }
+
+ public boolean aboutToChangeProperty(
+ ISynchronizePageConfiguration configuration, String key,
+ Object newValue) {
+ return false;
+ }
+ });
+ return conf;
+ }
+
+ private class MyModelProvider extends ChangeSetModelProvider implements
+ IPropertyChangeListener {
+
+ public ChangeSetCapability getChangeSetCapability() {
+ return new ChangeSetCapability() {
+ };
+ }
+
+ public MyModelProvider(final Viewer viewer) {
+ super(getMyConfiguration(viewer), new SyncInfoSet(),
+ "sampleProviderId");
+ addPropertyChangeListener(this);
+ }
+
+ public void propertyChange(PropertyChangeEvent event) {
+ // nothing to do
+ }
+ }
+
+ private class MyTreeViewer extends
+ TreeViewerAdvisor.NavigableCheckboxTreeViewer {
+
+ public MyTreeViewer() {
+ super(new Composite(PlatformUI.getWorkbench()
+ .getActiveWorkbenchWindow().getShell(), SWT.NONE),
+ SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
+ }
+
+ public void testInternalAdd(Object[] childElements) {
+ internalAdd(this.getTree(), null, childElements);
+ }
+
+ public Item[] testGetChildren(Widget widget) {
+ return this.getChildren(widget);
+ }
+
+ public void init() {
+ ChangeSetModelProvider provider = new MyModelProvider(this);
+ provider.setViewerSorter(new SynchronizeModelElementSorter());
+ ChangeSetModelSorter sorter = new ChangeSetModelSorter(provider, 0);
+ setSorter(sorter);
+ }
+ }
+
+ public static Test suite() {
+ return suite(PatchTreeTest.class);
+ }
+
+}

Back to the top