From aba39fdfa424d2163b08cb228455e785efa0b92f Mon Sep 17 00:00:00 2001 From: Michael Rennie Date: Thu, 5 May 2011 16:13:14 +0000 Subject: Copyright updates --- .../debug/tests/viewer/model/CheckTests.java | 2 +- .../viewer/model/ColumnPresentationTests.java | 762 ++++++++++----------- .../debug/tests/viewer/model/ContentTests.java | 2 +- .../debug/tests/viewer/model/DeltaTests.java | 2 +- .../model/ITestModelUpdatesListenerConstants.java | 2 +- .../tests/viewer/model/JFaceViewerLazyTests.java | 2 +- .../tests/viewer/model/JFaceViewerPopupTests.java | 2 +- .../tests/viewer/model/JFaceViewerStateTests.java | 2 +- .../viewer/model/JFaceViewerTopIndexTests.java | 2 +- .../eclipe/debug/tests/viewer/model/LazyTests.java | 18 +- .../debug/tests/viewer/model/PerformanceTests.java | 2 +- .../debug/tests/viewer/model/PopupTests.java | 2 +- .../debug/tests/viewer/model/SelectionTests.java | 2 +- .../debug/tests/viewer/model/StateTests.java | 2 +- .../eclipe/debug/tests/viewer/model/TestModel.java | 2 +- .../viewer/model/TestModelUpdatesListener.java | 22 +- .../debug/tests/viewer/model/TreePathWrapper.java | 10 + .../debug/tests/viewer/model/UpdateTests.java | 2 +- .../viewer/model/VirtualViewerLazyModeTests.java | 2 +- .../viewer/model/VirtualViewerPopupTests.java | 2 +- .../org/eclipse/debug/tests/AutomatedSuite.java | 2 +- .../src/org/eclipse/debug/tests/LocalSuite.java | 2 +- 22 files changed, 429 insertions(+), 419 deletions(-) (limited to 'org.eclipse.debug.tests') diff --git a/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/CheckTests.java b/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/CheckTests.java index cf9af6ab8..51812ff00 100644 --- a/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/CheckTests.java +++ b/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/CheckTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009 Wind River Systems and others. + * Copyright (c) 2009, 2011 Wind River Systems 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 diff --git a/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/ColumnPresentationTests.java b/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/ColumnPresentationTests.java index ceaa82751..6f3b2e47e 100644 --- a/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/ColumnPresentationTests.java +++ b/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/ColumnPresentationTests.java @@ -1,381 +1,381 @@ -/******************************************************************************* - * Copyright (c) 2009 Wind River Systems 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: - * Wind River Systems - initial API and implementation - *******************************************************************************/ -package org.eclipe.debug.tests.viewer.model; - -import java.util.Arrays; - -import junit.framework.TestCase; - -import org.eclipe.debug.tests.viewer.model.TestModel.TestElement; -import org.eclipse.debug.internal.ui.viewers.model.provisional.IColumnPresentation; -import org.eclipse.debug.internal.ui.viewers.model.provisional.IColumnPresentation2; -import org.eclipse.debug.internal.ui.viewers.model.provisional.IColumnPresentationFactory; -import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext; -import org.eclipse.debug.internal.ui.viewers.model.provisional.PresentationContext; -import org.eclipse.debug.internal.ui.viewers.model.provisional.TreeModelViewer; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.viewers.TreePath; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ControlEvent; -import org.eclipse.swt.events.ControlListener; -import org.eclipse.swt.layout.FillLayout; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Tree; -import org.eclipse.swt.widgets.TreeColumn; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.XMLMemento; - -/** - * Tests to verify that the viewer properly handles initial columns width. - */ -public class ColumnPresentationTests extends TestCase implements ITestModelUpdatesListenerConstants { - private Display fDisplay; - private Shell fShell; - private TreeModelViewer fViewer; - private TestModelUpdatesListener fListener; - private boolean fResized = false; - - public ColumnPresentationTests(String name) { - super(name); - } - - /** - * @throws java.lang.Exception - */ - protected void setUp() throws Exception { - createViewer(); - } - - /** - * @throws java.lang.Exception - */ - protected void tearDown() throws Exception { - destroyViewer(); - } - - void createViewer() { - fDisplay = PlatformUI.getWorkbench().getDisplay(); - fShell = new Shell(fDisplay); - fShell.setSize(800, 600); - fShell.setLayout(new FillLayout()); - fViewer = new TreeModelViewer(fShell, SWT.VIRTUAL, new PresentationContext("TestViewer")); - fViewer.getTree().addControlListener(new ControlListener() { - public void controlResized(ControlEvent e) { - fResized = true; - } - - public void controlMoved(ControlEvent e) { - } - }); - fListener = new TestModelUpdatesListener(fViewer, false, false); - fShell.open(); - } - - void destroyViewer() throws InterruptedException { - fListener.dispose(); - fViewer.getPresentationContext().dispose(); - // Close the shell. - fShell.close(); - while (!fShell.isDisposed()) { - if (!fDisplay.readAndDispatch()) { - Thread.sleep(0); - } - } - } - - void recreateViewer() throws InterruptedException { - destroyViewer(); - createViewer(); - } - - static class MyColumnPresentation implements IColumnPresentation { - private IPresentationContext fContext; - protected String[] columnIds; - - MyColumnPresentation() { - columnIds = new String[5]; - for (int i = 0; i < columnIds.length; i++) { - columnIds[i] = "ColumnId_" + i; - } - } - - public void init(IPresentationContext context) { - fContext = context; - } - - public void dispose() { - fContext = null; - } - - public ImageDescriptor getImageDescriptor(String id) { - return null; - } - - protected IPresentationContext getPresentationContext() { - return fContext; - } - - public String[] getAvailableColumns() { - return columnIds; - } - - public String[] getInitialColumns() { - return columnIds; - } - - public String getHeader(String id) { - return id; - } - - public String getId() { - return "MyColumnPresentationID"; - } - - public boolean isOptional() { - return true; - } - - } - - static class MyColumnPresentation2 extends MyColumnPresentation implements IColumnPresentation2 { - int[] repliedWidths; - - MyColumnPresentation2() { - super(); - for (int i = 0; i < columnIds.length; i++) { - columnIds[i] += "_2"; - } - repliedWidths = new int[columnIds.length]; - Arrays.fill(repliedWidths, -2); - } - - public int getInitialColumnWidth(String id, int treeWidgetWidth, - String[] visibleColumnIds) { - for (int i = 0; i < columnIds.length; i++) { - if (id.equals(columnIds[i]) && i == 0) { - repliedWidths[i] = 2 * (treeWidgetWidth / visibleColumnIds.length); - return repliedWidths[i]; - } - if (id.equals(columnIds[i]) && (i == 1 || i == 2)) { - repliedWidths[i] = (treeWidgetWidth / visibleColumnIds.length) / 2; - return repliedWidths[i]; - } - if (id.equals(columnIds[i]) && i == 3) { - repliedWidths[i] = (treeWidgetWidth / visibleColumnIds.length); - return repliedWidths[i]; - } - if (id.equals(columnIds[i]) && i == 4) { - repliedWidths[i] = -1; - return repliedWidths[i]; - } - } - return -1; - } - - public String getId() { - return "MyColumnPresentation2ID"; - } - } - - class MyModel extends TestModel implements IColumnPresentationFactory { - MyColumnPresentation colPresenation; - - MyModel(MyColumnPresentation cp1) { - colPresenation = cp1; - } - - public IColumnPresentation createColumnPresentation( - IPresentationContext context, Object element) { - if (colPresenation != null) { - return colPresenation; - } - return null; - } - - public String getColumnPresentationId(IPresentationContext context, - Object element) { - if (colPresenation != null) { - return colPresenation.getId(); - } - return null; - } - - } - - private TestModel makeModel(MyColumnPresentation cp, String rootSufffix) throws InterruptedException { - MyModel model = new MyModel(cp); - model.setRoot(new TestElement(model, "root" + rootSufffix, new TestElement[] { - new TestElement(model, "1", true, true, new TestElement[0]), - new TestElement(model, "2", true, false, new TestElement[0]), - new TestElement(model, "3", false, true, new TestElement[0]), - new TestElement(model, "4", false, false, new TestElement[0]), - new TestElement(model, "5", new TestElement[0]), - new TestElement(model, "6", new TestElement[0]) })); - fListener.reset(TreePath.EMPTY, model.getRootElement(), -1, true, false); - fViewer.setInput(model.getRootElement()); - while (!fListener.isFinished()) { - if (!fDisplay.readAndDispatch()) { - Thread.sleep(0); - } - } - model.validateData(fViewer, TreePath.EMPTY); - return model; - } - - /** - * In this test: verify that tree viewer can handle IColumnPresentation - * implementation without requiring the presentation being - * IColumnPresentation2 (i.e. ensure we do not break backward compatibility - * of interface). Also, we verify that the initial columns width is the - * average of tree width / number of visible columns, which is the logic - * in InternalTreeModelViewer. - */ - public void testInitialColumnAverageWidth() throws InterruptedException { - // Try to wait for the shell painting to settle - if (!fDisplay.readAndDispatch ()) Thread.sleep(0); - fResized = false; - - MyColumnPresentation colPre = new MyColumnPresentation(); - makeModel(colPre, "m1"); - Tree tree = fViewer.getTree(); - TreeColumn[] columns = tree.getColumns(); - int treeWidth = tree.getSize().x; - int avgWidth = treeWidth / columns.length; - - // Resizing the tree invalidates the test. - if (fResized) { - return; - } - - for (int i = 0; i < columns.length - 1; i++) { - assertEquals(avgWidth, columns[i].getWidth()); - } - // Checking of the width of the last column is not reliable. - // I.e. it's handled differenty on different platforms. - //int remainder = treeWidth % columns.length; - //assertEquals(avgWidth + remainder, columns[columns.length - 1].getWidth()); - } - - /** - * In this test: verify that tree viewer can handle IColumnPresentation2. - * Also, we verify that the initial columns width is the width computed by - * the IColumnPresentation2 implementation. - */ - public void testInitialColumnWidth() throws InterruptedException { - // Try to wait for the shell painting to settle - if (!fDisplay.readAndDispatch ()) Thread.sleep(0); - fResized = false; - - MyColumnPresentation2 colPre = new MyColumnPresentation2(); - makeModel(colPre, "m2"); - Tree tree = fViewer.getTree(); - TreeColumn[] columns = tree.getColumns(); - - // Resizing the tree invalidates the test. - if (fResized) { - return; - } - - for (int i = 0; i < columns.length; i++) { - int width = colPre.repliedWidths[i]; - if (width != -1) { - assertEquals(width, columns[i].getWidth()); - } - } - } - - /** - * In this test: verify that tree viewer can handle IColumnPresentation2. - * Also, we verify that the initial columns width from IColumnPresentation2 - * is not used when there are user settings inside the viewer which are - * created from user resizing columns. - */ - public void testRespectUserSettings() throws InterruptedException { - MyColumnPresentation2 colPre = new MyColumnPresentation2(); - makeModel(colPre, "m2"); - TreeColumn[] columns = fViewer.getTree().getColumns(); - // simulate user resizing each column width - int[] newWidths = new int[columns.length]; - for (int i = 0; i < columns.length; i++) { - newWidths[i] = columns[i].getWidth() + 10; - columns[i].setWidth(newWidths[i]); - } - for (int i = 0; i < columns.length; i++) { - assertEquals(newWidths[i], columns[i].getWidth()); - } - // get InternalTreeModelViewer to rebuild columns due to change of - // model and presentation - first set to another model and column - // presentation, then switch to a model with original presentation. - makeModel(new MyColumnPresentation(), "m1"); - makeModel(colPre, "m3"); - // verify user resized widths are used instead of the initial widths from IColumnPresentation2 - columns = fViewer.getTree().getColumns(); - for (int i = 0; i < columns.length; i++) { - assertEquals(newWidths[i], columns[i].getWidth()); - } - - // get InternalTreeModelViewer to rebuild columns due to hide and show columns - fViewer.setShowColumns(false); - do { - if (!fDisplay.readAndDispatch()) { - Thread.sleep(0); - } - } while (fViewer.getTree().getColumns().length > 0); - fViewer.setShowColumns(true); - do { - if (!fDisplay.readAndDispatch()) { - Thread.sleep(0); - } - } while (fViewer.getTree().getColumns().length != newWidths.length); - // verify user resized widths are used instead of the initial widths from IColumnPresentation2 - columns = fViewer.getTree().getColumns(); - for (int i = 0; i < columns.length; i++) { - assertEquals(newWidths[i], columns[i].getWidth()); - } - } - - /** - * In this test: verify that tree viewer can handle IColumnPresentation2. - * Also, we verify that the initial columns width from IColumnPresentation2 - * is not used when there are user settings inside the viewer which are - * restored from memento, e.g., restoring workspace, etc. - */ - public void testRespectMemento() throws InterruptedException { - MyColumnPresentation2 colPre = new MyColumnPresentation2(); - makeModel(colPre, "m2"); - TreeColumn[] columns = fViewer.getTree().getColumns(); - // simulate user resizing each column width - int[] newWidths = new int[columns.length]; - for (int i = 0; i < columns.length; i++) { - newWidths[i] = columns[i].getWidth() + 10; - columns[i].setWidth(newWidths[i]); - } - for (int i = 0; i < columns.length; i++) { - assertEquals(newWidths[i], columns[i].getWidth()); - } - // save memento - final XMLMemento memento = XMLMemento.createWriteRoot("TEST"); - fViewer.saveState(memento); - // throw away any settings inside the viewer and create a new viewer - // with memento settings, this is the same effect resulted from closing - // and opening workspace again. - recreateViewer(); - fViewer.initState(memento); - // get InternalTreeModelViewer to rebuild columns - makeModel(colPre, "m2"); - // verify widths from memento are used instead of the initial widths from IColumnPresentation2 - columns = fViewer.getTree().getColumns(); - for (int i = 0; i < columns.length; i++) { - assertEquals(newWidths[i], columns[i].getWidth()); - } - } -} +/******************************************************************************* + * Copyright (c) 2009, 2011 Wind River Systems 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: + * Wind River Systems - initial API and implementation + *******************************************************************************/ +package org.eclipe.debug.tests.viewer.model; + +import java.util.Arrays; + +import junit.framework.TestCase; + +import org.eclipe.debug.tests.viewer.model.TestModel.TestElement; +import org.eclipse.debug.internal.ui.viewers.model.provisional.IColumnPresentation; +import org.eclipse.debug.internal.ui.viewers.model.provisional.IColumnPresentation2; +import org.eclipse.debug.internal.ui.viewers.model.provisional.IColumnPresentationFactory; +import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext; +import org.eclipse.debug.internal.ui.viewers.model.provisional.PresentationContext; +import org.eclipse.debug.internal.ui.viewers.model.provisional.TreeModelViewer; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.TreePath; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ControlEvent; +import org.eclipse.swt.events.ControlListener; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeColumn; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.XMLMemento; + +/** + * Tests to verify that the viewer properly handles initial columns width. + */ +public class ColumnPresentationTests extends TestCase implements ITestModelUpdatesListenerConstants { + private Display fDisplay; + private Shell fShell; + private TreeModelViewer fViewer; + private TestModelUpdatesListener fListener; + private boolean fResized = false; + + public ColumnPresentationTests(String name) { + super(name); + } + + /** + * @throws java.lang.Exception + */ + protected void setUp() throws Exception { + createViewer(); + } + + /** + * @throws java.lang.Exception + */ + protected void tearDown() throws Exception { + destroyViewer(); + } + + void createViewer() { + fDisplay = PlatformUI.getWorkbench().getDisplay(); + fShell = new Shell(fDisplay); + fShell.setSize(800, 600); + fShell.setLayout(new FillLayout()); + fViewer = new TreeModelViewer(fShell, SWT.VIRTUAL, new PresentationContext("TestViewer")); + fViewer.getTree().addControlListener(new ControlListener() { + public void controlResized(ControlEvent e) { + fResized = true; + } + + public void controlMoved(ControlEvent e) { + } + }); + fListener = new TestModelUpdatesListener(fViewer, false, false); + fShell.open(); + } + + void destroyViewer() throws InterruptedException { + fListener.dispose(); + fViewer.getPresentationContext().dispose(); + // Close the shell. + fShell.close(); + while (!fShell.isDisposed()) { + if (!fDisplay.readAndDispatch()) { + Thread.sleep(0); + } + } + } + + void recreateViewer() throws InterruptedException { + destroyViewer(); + createViewer(); + } + + static class MyColumnPresentation implements IColumnPresentation { + private IPresentationContext fContext; + protected String[] columnIds; + + MyColumnPresentation() { + columnIds = new String[5]; + for (int i = 0; i < columnIds.length; i++) { + columnIds[i] = "ColumnId_" + i; + } + } + + public void init(IPresentationContext context) { + fContext = context; + } + + public void dispose() { + fContext = null; + } + + public ImageDescriptor getImageDescriptor(String id) { + return null; + } + + protected IPresentationContext getPresentationContext() { + return fContext; + } + + public String[] getAvailableColumns() { + return columnIds; + } + + public String[] getInitialColumns() { + return columnIds; + } + + public String getHeader(String id) { + return id; + } + + public String getId() { + return "MyColumnPresentationID"; + } + + public boolean isOptional() { + return true; + } + + } + + static class MyColumnPresentation2 extends MyColumnPresentation implements IColumnPresentation2 { + int[] repliedWidths; + + MyColumnPresentation2() { + super(); + for (int i = 0; i < columnIds.length; i++) { + columnIds[i] += "_2"; + } + repliedWidths = new int[columnIds.length]; + Arrays.fill(repliedWidths, -2); + } + + public int getInitialColumnWidth(String id, int treeWidgetWidth, + String[] visibleColumnIds) { + for (int i = 0; i < columnIds.length; i++) { + if (id.equals(columnIds[i]) && i == 0) { + repliedWidths[i] = 2 * (treeWidgetWidth / visibleColumnIds.length); + return repliedWidths[i]; + } + if (id.equals(columnIds[i]) && (i == 1 || i == 2)) { + repliedWidths[i] = (treeWidgetWidth / visibleColumnIds.length) / 2; + return repliedWidths[i]; + } + if (id.equals(columnIds[i]) && i == 3) { + repliedWidths[i] = (treeWidgetWidth / visibleColumnIds.length); + return repliedWidths[i]; + } + if (id.equals(columnIds[i]) && i == 4) { + repliedWidths[i] = -1; + return repliedWidths[i]; + } + } + return -1; + } + + public String getId() { + return "MyColumnPresentation2ID"; + } + } + + class MyModel extends TestModel implements IColumnPresentationFactory { + MyColumnPresentation colPresenation; + + MyModel(MyColumnPresentation cp1) { + colPresenation = cp1; + } + + public IColumnPresentation createColumnPresentation( + IPresentationContext context, Object element) { + if (colPresenation != null) { + return colPresenation; + } + return null; + } + + public String getColumnPresentationId(IPresentationContext context, + Object element) { + if (colPresenation != null) { + return colPresenation.getId(); + } + return null; + } + + } + + private TestModel makeModel(MyColumnPresentation cp, String rootSufffix) throws InterruptedException { + MyModel model = new MyModel(cp); + model.setRoot(new TestElement(model, "root" + rootSufffix, new TestElement[] { + new TestElement(model, "1", true, true, new TestElement[0]), + new TestElement(model, "2", true, false, new TestElement[0]), + new TestElement(model, "3", false, true, new TestElement[0]), + new TestElement(model, "4", false, false, new TestElement[0]), + new TestElement(model, "5", new TestElement[0]), + new TestElement(model, "6", new TestElement[0]) })); + fListener.reset(TreePath.EMPTY, model.getRootElement(), -1, true, false); + fViewer.setInput(model.getRootElement()); + while (!fListener.isFinished()) { + if (!fDisplay.readAndDispatch()) { + Thread.sleep(0); + } + } + model.validateData(fViewer, TreePath.EMPTY); + return model; + } + + /** + * In this test: verify that tree viewer can handle IColumnPresentation + * implementation without requiring the presentation being + * IColumnPresentation2 (i.e. ensure we do not break backward compatibility + * of interface). Also, we verify that the initial columns width is the + * average of tree width / number of visible columns, which is the logic + * in InternalTreeModelViewer. + */ + public void testInitialColumnAverageWidth() throws InterruptedException { + // Try to wait for the shell painting to settle + if (!fDisplay.readAndDispatch ()) Thread.sleep(0); + fResized = false; + + MyColumnPresentation colPre = new MyColumnPresentation(); + makeModel(colPre, "m1"); + Tree tree = fViewer.getTree(); + TreeColumn[] columns = tree.getColumns(); + int treeWidth = tree.getSize().x; + int avgWidth = treeWidth / columns.length; + + // Resizing the tree invalidates the test. + if (fResized) { + return; + } + + for (int i = 0; i < columns.length - 1; i++) { + assertEquals(avgWidth, columns[i].getWidth()); + } + // Checking of the width of the last column is not reliable. + // I.e. it's handled differenty on different platforms. + //int remainder = treeWidth % columns.length; + //assertEquals(avgWidth + remainder, columns[columns.length - 1].getWidth()); + } + + /** + * In this test: verify that tree viewer can handle IColumnPresentation2. + * Also, we verify that the initial columns width is the width computed by + * the IColumnPresentation2 implementation. + */ + public void testInitialColumnWidth() throws InterruptedException { + // Try to wait for the shell painting to settle + if (!fDisplay.readAndDispatch ()) Thread.sleep(0); + fResized = false; + + MyColumnPresentation2 colPre = new MyColumnPresentation2(); + makeModel(colPre, "m2"); + Tree tree = fViewer.getTree(); + TreeColumn[] columns = tree.getColumns(); + + // Resizing the tree invalidates the test. + if (fResized) { + return; + } + + for (int i = 0; i < columns.length; i++) { + int width = colPre.repliedWidths[i]; + if (width != -1) { + assertEquals(width, columns[i].getWidth()); + } + } + } + + /** + * In this test: verify that tree viewer can handle IColumnPresentation2. + * Also, we verify that the initial columns width from IColumnPresentation2 + * is not used when there are user settings inside the viewer which are + * created from user resizing columns. + */ + public void testRespectUserSettings() throws InterruptedException { + MyColumnPresentation2 colPre = new MyColumnPresentation2(); + makeModel(colPre, "m2"); + TreeColumn[] columns = fViewer.getTree().getColumns(); + // simulate user resizing each column width + int[] newWidths = new int[columns.length]; + for (int i = 0; i < columns.length; i++) { + newWidths[i] = columns[i].getWidth() + 10; + columns[i].setWidth(newWidths[i]); + } + for (int i = 0; i < columns.length; i++) { + assertEquals(newWidths[i], columns[i].getWidth()); + } + // get InternalTreeModelViewer to rebuild columns due to change of + // model and presentation - first set to another model and column + // presentation, then switch to a model with original presentation. + makeModel(new MyColumnPresentation(), "m1"); + makeModel(colPre, "m3"); + // verify user resized widths are used instead of the initial widths from IColumnPresentation2 + columns = fViewer.getTree().getColumns(); + for (int i = 0; i < columns.length; i++) { + assertEquals(newWidths[i], columns[i].getWidth()); + } + + // get InternalTreeModelViewer to rebuild columns due to hide and show columns + fViewer.setShowColumns(false); + do { + if (!fDisplay.readAndDispatch()) { + Thread.sleep(0); + } + } while (fViewer.getTree().getColumns().length > 0); + fViewer.setShowColumns(true); + do { + if (!fDisplay.readAndDispatch()) { + Thread.sleep(0); + } + } while (fViewer.getTree().getColumns().length != newWidths.length); + // verify user resized widths are used instead of the initial widths from IColumnPresentation2 + columns = fViewer.getTree().getColumns(); + for (int i = 0; i < columns.length; i++) { + assertEquals(newWidths[i], columns[i].getWidth()); + } + } + + /** + * In this test: verify that tree viewer can handle IColumnPresentation2. + * Also, we verify that the initial columns width from IColumnPresentation2 + * is not used when there are user settings inside the viewer which are + * restored from memento, e.g., restoring workspace, etc. + */ + public void testRespectMemento() throws InterruptedException { + MyColumnPresentation2 colPre = new MyColumnPresentation2(); + makeModel(colPre, "m2"); + TreeColumn[] columns = fViewer.getTree().getColumns(); + // simulate user resizing each column width + int[] newWidths = new int[columns.length]; + for (int i = 0; i < columns.length; i++) { + newWidths[i] = columns[i].getWidth() + 10; + columns[i].setWidth(newWidths[i]); + } + for (int i = 0; i < columns.length; i++) { + assertEquals(newWidths[i], columns[i].getWidth()); + } + // save memento + final XMLMemento memento = XMLMemento.createWriteRoot("TEST"); + fViewer.saveState(memento); + // throw away any settings inside the viewer and create a new viewer + // with memento settings, this is the same effect resulted from closing + // and opening workspace again. + recreateViewer(); + fViewer.initState(memento); + // get InternalTreeModelViewer to rebuild columns + makeModel(colPre, "m2"); + // verify widths from memento are used instead of the initial widths from IColumnPresentation2 + columns = fViewer.getTree().getColumns(); + for (int i = 0; i < columns.length; i++) { + assertEquals(newWidths[i], columns[i].getWidth()); + } + } +} diff --git a/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/ContentTests.java b/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/ContentTests.java index ece0b3e0c..0725b1fd3 100644 --- a/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/ContentTests.java +++ b/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/ContentTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009 Wind River Systems and others. + * Copyright (c) 2009, 2011 Wind River Systems 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 diff --git a/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/DeltaTests.java b/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/DeltaTests.java index 16fd3485a..d78e9367d 100644 --- a/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/DeltaTests.java +++ b/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/DeltaTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009 Wind River Systems and others. + * Copyright (c) 2009, 2011 Wind River Systems 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 diff --git a/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/ITestModelUpdatesListenerConstants.java b/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/ITestModelUpdatesListenerConstants.java index 73b4cb027..0d47d6ed5 100644 --- a/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/ITestModelUpdatesListenerConstants.java +++ b/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/ITestModelUpdatesListenerConstants.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009 Wind River Systems and others. + * Copyright (c) 2009, 2010 Wind River Systems 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 diff --git a/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/JFaceViewerLazyTests.java b/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/JFaceViewerLazyTests.java index 42028b0b7..fa6183d61 100644 --- a/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/JFaceViewerLazyTests.java +++ b/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/JFaceViewerLazyTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009 Wind River Systems and others. + * Copyright (c) 2009, 2010 Wind River Systems 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 diff --git a/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/JFaceViewerPopupTests.java b/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/JFaceViewerPopupTests.java index f3dcce096..70f41bd3c 100644 --- a/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/JFaceViewerPopupTests.java +++ b/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/JFaceViewerPopupTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009 Wind River Systems and others. + * Copyright (c) 2009, 2010 Wind River Systems 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 diff --git a/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/JFaceViewerStateTests.java b/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/JFaceViewerStateTests.java index 2e4f23979..07104a79b 100644 --- a/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/JFaceViewerStateTests.java +++ b/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/JFaceViewerStateTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009 Wind River Systems and others. + * Copyright (c) 2009, 2010 Wind River Systems 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 diff --git a/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/JFaceViewerTopIndexTests.java b/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/JFaceViewerTopIndexTests.java index ffa53e9f9..7ca0eceb1 100644 --- a/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/JFaceViewerTopIndexTests.java +++ b/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/JFaceViewerTopIndexTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010 Wind River Systems and others. + * Copyright (c) 2010, 2011 Wind River Systems 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 diff --git a/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/LazyTests.java b/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/LazyTests.java index 373e67132..f6566d9bc 100644 --- a/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/LazyTests.java +++ b/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/LazyTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009 Wind River Systems and others. + * Copyright (c) 2009, 2011 Wind River Systems 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 @@ -160,12 +160,12 @@ abstract public class LazyTests extends TestCase implements ITestModelUpdatesLis // for the content update sequence to finish (elements off screen will // not be updated). // TODO: child count for element 1 is updated multiple times. - fListener.reset(); - fListener.setFailOnMultipleModelUpdateSequences(true); - fListener.setFailOnRedundantUpdates(false); + fListener.reset(); + fListener.setFailOnMultipleModelUpdateSequences(true); + fListener.setFailOnRedundantUpdates(false); fViewer.setInput(model.getRootElement()); - fListener.addLabelUpdate(model.findElement("1.0")); - while (!fListener.isFinished(CONTENT_UPDATES_COMPLETE | LABEL_COMPLETE)) if (!fDisplay.readAndDispatch ()) Thread.sleep(0); + fListener.addLabelUpdate(model.findElement("1.0")); + while (!fListener.isFinished(CONTENT_UPDATES_COMPLETE | LABEL_COMPLETE)) if (!fDisplay.readAndDispatch ()) Thread.sleep(0); // Set selection so that the initial selection is not empty fViewer.setSelection(new TreeSelection(new TreePath[] { model.findElement("1.0")} )); @@ -190,7 +190,7 @@ abstract public class LazyTests extends TestCase implements ITestModelUpdatesLis fListener.addLabelUpdate(_1_0_newElementPath); model.postDelta(rootDelta); - while (!fListener.isFinished(MODEL_CHANGED_COMPLETE | LABEL_COMPLETE)) + while (!fListener.isFinished(MODEL_CHANGED_COMPLETE | LABEL_COMPLETE)) if (!fDisplay.readAndDispatch ()) Thread.sleep(0); @@ -218,7 +218,7 @@ abstract public class LazyTests extends TestCase implements ITestModelUpdatesLis fListener.reset(); fListener.setFailOnRedundantUpdates(false); fViewer.reveal(model.findElement("1"), 500); - while (!fListener.isFinished(CONTENT_UPDATES_COMPLETE)) if (!fDisplay.readAndDispatch ()) Thread.sleep(0); + while (!fListener.isFinished(CONTENT_UPDATES_COMPLETE)) if (!fDisplay.readAndDispatch ()) Thread.sleep(0); // Create delta to refresh the "1" element. TestElement rootElement = model.getRootElement(); @@ -248,7 +248,7 @@ abstract public class LazyTests extends TestCase implements ITestModelUpdatesLis } model.postDelta(rootDelta); - while (!fListener.isFinished(CONTENT_UPDATES_COMPLETE | MODEL_CHANGED_COMPLETE)) + while (!fListener.isFinished(CONTENT_UPDATES_COMPLETE | MODEL_CHANGED_COMPLETE)) if (!fDisplay.readAndDispatch ()) Thread.sleep(0); } } diff --git a/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/PerformanceTests.java b/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/PerformanceTests.java index c184485e8..55a140e2c 100644 --- a/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/PerformanceTests.java +++ b/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/PerformanceTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009 Wind River Systems and others. + * Copyright (c) 2009, 2011 Wind River Systems 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 diff --git a/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/PopupTests.java b/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/PopupTests.java index 73c592a5a..19247755d 100644 --- a/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/PopupTests.java +++ b/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/PopupTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009 Wind River Systems and others. + * Copyright (c) 2009, 2011 Wind River Systems 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 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 3c70b8a45..e062ed719 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009 Wind River Systems and others. + * Copyright (c) 2009, 2011 Wind River Systems 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 diff --git a/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/StateTests.java b/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/StateTests.java index 3828e03c2..9f1b85aa4 100644 --- a/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/StateTests.java +++ b/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/StateTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 Wind River Systems and others. + * Copyright (c) 2009, 2011 Wind River Systems 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 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 609ce9838..d64f6bb0b 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009 Wind River Systems and others. + * Copyright (c) 2009, 2010 Wind River Systems 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 diff --git a/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/TestModelUpdatesListener.java b/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/TestModelUpdatesListener.java index ebe686801..31a3523f2 100644 --- a/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/TestModelUpdatesListener.java +++ b/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/TestModelUpdatesListener.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 Wind River Systems and others. + * Copyright (c) 2009, 2011 Wind River Systems 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 @@ -132,10 +132,10 @@ public class TestModelUpdatesListener fFailOnRedundantUpdates = failOnRedundantUpdates; } - public void setFailOnRedundantLabelUpdates(boolean failOnRedundantLabelUpdates) { - fFailOnRedundantLabelUpdates = failOnRedundantLabelUpdates; - } - + public void setFailOnRedundantLabelUpdates(boolean failOnRedundantLabelUpdates) { + fFailOnRedundantLabelUpdates = failOnRedundantLabelUpdates; + } + public void setFailOnMultipleModelUpdateSequences(boolean failOnMultipleLabelUpdateSequences) { fFailOnMultipleModelUpdateSequences = failOnMultipleLabelUpdateSequences; } @@ -171,7 +171,7 @@ public class TestModelUpdatesListener public void reset() { fJobError = null; fRedundantUpdates.clear(); - fRedundantLabelUpdates.clear(); + fRedundantLabelUpdates.clear(); fRedundantHasChildrenUpdateExceptions.clear(); fRedundantChildCountUpdateExceptions.clear(); fRedundantChildrenUpdateExceptions.clear(); @@ -375,9 +375,9 @@ public class TestModelUpdatesListener if (fFailOnRedundantUpdates && !fRedundantUpdates.isEmpty()) { Assert.fail("Redundant Updates: " + fRedundantUpdates.toString()); } - if (fFailOnRedundantLabelUpdates && !fRedundantLabelUpdates.isEmpty()) { - Assert.fail("Redundant Label Updates: " + fRedundantLabelUpdates.toString()); - } + if (fFailOnRedundantLabelUpdates && !fRedundantLabelUpdates.isEmpty()) { + Assert.fail("Redundant Label Updates: " + fRedundantLabelUpdates.toString()); + } if (fFailOnMultipleLabelUpdateSequences && !fMultipleLabelUpdateSequencesObserved) { Assert.fail("Multiple label update sequences detected"); } @@ -534,10 +534,10 @@ public class TestModelUpdatesListener fLabelUpdatesCounter--; } if (!fLabelUpdates.remove(update.getElementPath()) && - fFailOnRedundantLabelUpdates && + fFailOnRedundantLabelUpdates && !fRedundantLabelUpdateExceptions.contains(update.getElementPath())) { - fRedundantLabelUpdates.add(update); + fRedundantLabelUpdates.add(update); Assert.fail("Redundant update: " + update); } } diff --git a/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/TreePathWrapper.java b/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/TreePathWrapper.java index e45f72fd5..23484333f 100644 --- a/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/TreePathWrapper.java +++ b/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/TreePathWrapper.java @@ -1,3 +1,13 @@ +/******************************************************************************* + * 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.eclipe.debug.tests.viewer.model; import junit.framework.Assert; diff --git a/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/UpdateTests.java b/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/UpdateTests.java index 1044f62d1..2f6a0985a 100644 --- a/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/UpdateTests.java +++ b/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/UpdateTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009 Wind River Systems and others. + * Copyright (c) 2009, 2011 Wind River Systems 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 diff --git a/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/VirtualViewerLazyModeTests.java b/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/VirtualViewerLazyModeTests.java index e3b2ea827..300f76424 100644 --- a/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/VirtualViewerLazyModeTests.java +++ b/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/VirtualViewerLazyModeTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009 Wind River Systems and others. + * Copyright (c) 2009, 2011 Wind River Systems 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 diff --git a/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/VirtualViewerPopupTests.java b/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/VirtualViewerPopupTests.java index 71484d116..ee8e9c745 100644 --- a/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/VirtualViewerPopupTests.java +++ b/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/VirtualViewerPopupTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009 Wind River Systems and others. + * Copyright (c) 2009, 2010 Wind River Systems 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 diff --git a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/AutomatedSuite.java b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/AutomatedSuite.java index 745993e4f..82ba80b7a 100644 --- a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/AutomatedSuite.java +++ b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/AutomatedSuite.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 IBM Corporation and others. + * Copyright (c) 2009, 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 diff --git a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/LocalSuite.java b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/LocalSuite.java index bfe8ba5fa..55acd5731 100644 --- a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/LocalSuite.java +++ b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/LocalSuite.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 IBM Corporation and others. + * Copyright (c) 2009, 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 -- cgit v1.2.3