diff options
author | Pawel Piech | 2010-06-18 19:31:24 +0000 |
---|---|---|
committer | Pawel Piech | 2010-06-18 19:31:24 +0000 |
commit | 8690dc0100e0f54129dcb1a77ce1923e33de9f80 (patch) | |
tree | 0f26b9b7c0621c93a707f10a0d2be02129d28e17 /org.eclipse.debug.tests | |
parent | 14ccc0911993cd9267e522cee25c3fff897a5d8c (diff) | |
download | eclipse.platform.debug-8690dc0100e0f54129dcb1a77ce1923e33de9f80.tar.gz eclipse.platform.debug-8690dc0100e0f54129dcb1a77ce1923e33de9f80.tar.xz eclipse.platform.debug-8690dc0100e0f54129dcb1a77ce1923e33de9f80.zip |
Bug 317100 - Debug breadcrumb does not allow to switch threads
Diffstat (limited to 'org.eclipse.debug.tests')
-rw-r--r-- | org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/SelectionTests.java | 67 | ||||
-rw-r--r-- | org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/TestModel.java | 14 |
2 files changed, 79 insertions, 2 deletions
diff --git a/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/SelectionTests.java b/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/SelectionTests.java index 9b072f7db..7d2df922b 100644 --- a/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/SelectionTests.java +++ b/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/SelectionTests.java @@ -17,6 +17,8 @@ import junit.framework.TestCase; import org.eclipse.debug.internal.ui.viewers.model.ITreeModelViewer; import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelDelta; +import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelSelectionPolicy; +import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext; import org.eclipse.debug.internal.ui.viewers.model.provisional.ModelDelta; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelectionChangedListener; @@ -31,7 +33,7 @@ import org.eclipse.ui.PlatformUI; /** * Tests to verify that the viewer properly handles selection changes. */ -abstract public class SelectionTests extends TestCase { +abstract public class SelectionTests extends TestCase implements ITestModelUpdatesListenerConstants { Display fDisplay; Shell fShell; ITreeModelViewer fViewer; @@ -114,6 +116,69 @@ abstract public class SelectionTests extends TestCase { } /** + * In this test verify that selection policy can prevent selection + * from being set and verify that a FORCE flag can override the selection + * policy. + */ + public void testSelectionPolicy() { + // Create the model and populate the view. + final TestModel model = makeMultiLevelModel(); + + // Set the selection and verify it. + TreeSelection selection_3_3_3 = new TreeSelection(model.findElement("3.3.3")); + fViewer.setSelection(selection_3_3_3, true, false); + assertEquals(selection_3_3_3, fViewer.getSelection()); + + model.setSelectionPolicy(new IModelSelectionPolicy() { + + public ISelection replaceInvalidSelection(ISelection invalidSelection, ISelection newSelection) { + return null; + } + + public boolean overrides(ISelection existing, ISelection candidate, IPresentationContext context) { + return false; + } + + public boolean isSticky(ISelection selection, IPresentationContext context) { + return true; + } + + public boolean contains(ISelection selection, IPresentationContext context) { + return true; + } + }); + + // Attempt to change selection and verify that old selection is still valid. + TreeSelection selection_3_3_1 = new TreeSelection(model.findElement("3.3.1")); + fViewer.setSelection(selection_3_3_1, true, false); + assertEquals(selection_3_3_3, fViewer.getSelection()); + + // Now attempt to *force* selection and verify that new selection was set. + fViewer.setSelection(selection_3_3_1, true, true); + assertEquals(selection_3_3_1, fViewer.getSelection()); + + // Create the an update delta to attempt to change selection back to + // 3.3.3 and verify that selection did not get overriden. + TreePath path_3_3_3 = model.findElement("3.3.3"); + ModelDelta baseDelta = new ModelDelta(model.getRootElement(), IModelDelta.NO_CHANGE); + ModelDelta delta_3_3_3 = model.getElementDelta(baseDelta, path_3_3_3, false); + delta_3_3_3.setFlags(IModelDelta.SELECT); + fViewer.updateViewer(baseDelta); + while (!fListener.isFinished(MODEL_CHANGED_COMPLETE)) + if (!fDisplay.readAndDispatch ()) fDisplay.sleep (); + assertEquals(selection_3_3_1, fViewer.getSelection()); + + // Add the *force* flag to the selection delta and update viewer again. + // Verify that selection did change. + delta_3_3_3.setFlags(IModelDelta.SELECT | IModelDelta.FORCE); + fViewer.updateViewer(baseDelta); + while (!fListener.isFinished(MODEL_CHANGED_COMPLETE)) + if (!fDisplay.readAndDispatch ()) fDisplay.sleep (); + assertEquals(selection_3_3_3, fViewer.getSelection()); + } + + + /** * In this test: * - set a seleciton to an element * - then remove that element diff --git a/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/TestModel.java b/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/TestModel.java index e172326eb..042650a59 100644 --- a/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/TestModel.java +++ b/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/TestModel.java @@ -31,6 +31,8 @@ import org.eclipse.debug.internal.ui.viewers.model.provisional.ILabelUpdate; import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelDelta; import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelProxy; import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelProxyFactory2; +import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelSelectionPolicy; +import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelSelectionPolicyFactory; import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext; import org.eclipse.debug.internal.ui.viewers.model.provisional.ModelDelta; import org.eclipse.debug.internal.ui.viewers.provisional.AbstractModelProxy; @@ -44,7 +46,7 @@ import org.eclipse.jface.viewers.Viewer; * * @since 3.6 */ -public class TestModel implements IElementContentProvider, IElementLabelProvider, IModelProxyFactory2 , IElementMementoProvider { +public class TestModel implements IElementContentProvider, IElementLabelProvider, IModelProxyFactory2 , IElementMementoProvider, IModelSelectionPolicyFactory { public static class TestElement extends PlatformObject { private final TestModel fModel; @@ -155,6 +157,8 @@ public class TestModel implements IElementContentProvider, IElementLabelProvider private Object fInput = null; private TreePath fRootPath = TreePath.EMPTY; private ModelProxy fModelProxy; + private IModelSelectionPolicy fModelSelectionPolicy; + /** * Constructor private. Use static factory methods instead. @@ -165,6 +169,14 @@ public class TestModel implements IElementContentProvider, IElementLabelProvider return fRoot; } + public void setSelectionPolicy(IModelSelectionPolicy modelSelectionPolicy) { + fModelSelectionPolicy = modelSelectionPolicy; + } + + public IModelSelectionPolicy createModelSelectionPolicyAdapter(Object element, IPresentationContext context) { + return fModelSelectionPolicy; + } + public ModelDelta getBaseDelta(ModelDelta rootDelta) { ModelDelta delta = rootDelta; for (int i = 0; i < fRootPath.getSegmentCount(); i++) { |