Bug 75852
[variables] Support for custom details view widgets. test suite updates
diff --git a/org.eclipse.jdt.debug.tests/plugin.xml b/org.eclipse.jdt.debug.tests/plugin.xml
index 366cd1b..9e8a028 100644
--- a/org.eclipse.jdt.debug.tests/plugin.xml
+++ b/org.eclipse.jdt.debug.tests/plugin.xml
@@ -422,5 +422,20 @@
</configurationType>
</shortcut>
</extension>
+ <extension
+ point="org.eclipse.debug.ui.detailPaneFactories">
+ <detailFactories
+ class="org.eclipse.jdt.debug.testplugin.TestDetailPaneFactory"
+ id="testDetailPaneFactory">
+ <enablement>
+ <with
+ variable="selection">
+ <count
+ value="2">
+ </count>
+ </with>
+ </enablement>
+ </detailFactories>
+ </extension>
</plugin>
diff --git a/org.eclipse.jdt.debug.tests/test plugin/org/eclipse/jdt/debug/testplugin/TestDetailPane.java b/org.eclipse.jdt.debug.tests/test plugin/org/eclipse/jdt/debug/testplugin/TestDetailPane.java
new file mode 100644
index 0000000..4ef5753
--- /dev/null
+++ b/org.eclipse.jdt.debug.tests/test plugin/org/eclipse/jdt/debug/testplugin/TestDetailPane.java
@@ -0,0 +1,234 @@
+/*******************************************************************************
+ * Copyright (c) 2006 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.jdt.debug.testplugin;
+
+import java.util.Iterator;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.debug.core.DebugException;
+import org.eclipse.debug.core.model.IValue;
+import org.eclipse.debug.core.model.IVariable;
+import org.eclipse.debug.internal.ui.VariablesViewModelPresentation;
+import org.eclipse.debug.ui.IDebugModelPresentation;
+import org.eclipse.debug.ui.IDetailPane;
+import org.eclipse.debug.ui.IValueDetailListener;
+import org.eclipse.jface.text.Document;
+import org.eclipse.jface.text.TextViewer;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.ui.IWorkbenchPartSite;
+import org.eclipse.ui.progress.WorkbenchJob;
+
+/**
+ * Creates a test detail pane that is instantiated by TestDetailPaneFactory
+ * Contains multiple controls in a composite, making it useful for manually
+ * testing the detail pane API. This detail pane is also used by the test
+ * suite.
+ *
+ * @see org.eclipse.jdt.debug.tests.ui.DetailPaneManagerTests.java
+ */
+public class TestDetailPane implements IDetailPane, IValueDetailListener {
+
+ public static final String ID = "TestDetailPane";
+ IWorkbenchPartSite fWorkbenchPartSite;
+ private Table fTable;
+ private TextViewer fText;
+ private Composite fComposite;
+ private Button fWordWrapButton;
+ private IDebugModelPresentation fModelPresentation;
+
+ /**
+ * Runs a seperate job to calculate the detailed information for a selected variable
+ */
+ class DetailJob implements Runnable{
+
+ private IValue fValue;
+ private IValueDetailListener fListener;
+
+ public DetailJob(IValue value, IValueDetailListener listener){
+ fValue = value;
+ fListener = listener;
+ }
+
+ public void run() {
+ fModelPresentation.computeDetail(fValue, fListener);
+ }
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.ui.IDetailPane#init(org.eclipse.ui.IWorkbenchPartSite)
+ */
+ public void init(IWorkbenchPartSite workbenchPartSite) {
+ fWorkbenchPartSite = workbenchPartSite;
+
+ fModelPresentation = new VariablesViewModelPresentation();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.ui.IDetailPane#createControl(org.eclipse.swt.widgets.Composite)
+ */
+ public Control createControl(Composite parent) {
+ fComposite = new Composite(parent, SWT.NONE);
+ fComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
+ fComposite.setLayout(new FillLayout(SWT.HORIZONTAL));
+ fTable = new Table(fComposite,SWT.FULL_SELECTION);
+ fTable.addSelectionListener(new SelectionListener(){
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+ widgetSelected(e);
+ }
+
+ public void widgetSelected(SelectionEvent e) {
+ int index = fTable.getSelectionIndex();
+ if (index >= 0){
+ TableItem item = fTable.getItem(index);
+ if (item != null){
+ Thread detailJob = new Thread(new DetailJob((IValue)item.getData(),getValueDetailListener()));
+ detailJob.start();
+ }
+ else{
+ fText.setDocument(null);
+ }
+ }
+ }
+
+
+ });
+
+ Composite composite = new Composite(fComposite,SWT.NONE);
+ composite.setLayout(new FillLayout(SWT.VERTICAL));
+ fText = new TextViewer(composite,SWT.READ_ONLY);
+
+ fWordWrapButton = new Button(composite,SWT.CHECK);
+ fWordWrapButton.setText("Word Wrap");
+ fWordWrapButton.setSelection(false);
+ fWordWrapButton.addSelectionListener(new SelectionListener(){
+ public void widgetDefaultSelected(SelectionEvent e) {
+ widgetSelected(e);
+ }
+ public void widgetSelected(SelectionEvent e) {
+ fText.getTextWidget().setWordWrap(fWordWrapButton.getSelection());
+ }
+ });
+
+
+
+ return fComposite;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.ui.IDetailPane#display(org.eclipse.jface.viewers.IStructuredSelection)
+ */
+ public void display(IStructuredSelection element) {
+
+ if (element != null){
+
+ fTable.removeAll();
+ fText.setDocument(null);
+
+ Iterator iterator = element.iterator();
+ while (iterator.hasNext()){
+
+ Object selection = iterator.next();
+ if (selection != null && selection instanceof IVariable){
+
+ IValue val = null;
+ try {
+
+ val = ((IVariable)selection).getValue();
+ TableItem newItem = new TableItem(fTable,SWT.NONE);
+ newItem.setText(val.getValueString());
+ newItem.setData(val);
+
+ } catch (DebugException e) {
+
+ }
+ }
+ }
+ }
+ else{
+ fTable.removeAll();
+ }
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.ui.IDetailPane#setFocus()
+ */
+ public boolean setFocus(){
+ if (fText != null){
+ fText.getTextWidget().setFocus();
+ return true;
+ }
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.ui.IDetailPane#dispose()
+ */
+ public void dispose() {
+ if (fComposite != null) fComposite.dispose();
+ if (fModelPresentation != null) fModelPresentation.dispose();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.ui.IDetailPane#getID()
+ */
+ public String getID() {
+ return ID;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.ui.IDetailPane#getName()
+ */
+ public String getName() {
+ return "Test Pane";
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.ui.IDetailPane#getDescription()
+ */
+ public String getDescription() {
+ return "Test Pane Description";
+ }
+
+ protected IValueDetailListener getValueDetailListener(){
+ return this;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.ui.IValueDetailListener#detailComputed(org.eclipse.debug.core.model.IValue, java.lang.String)
+ */
+ public void detailComputed(IValue value, final String result){
+ WorkbenchJob append = new WorkbenchJob("append details") { //$NON-NLS-1$
+ public IStatus runInUIThread(IProgressMonitor monitor) {
+ fText.setDocument(new Document(result));
+ return Status.OK_STATUS;
+
+ }
+ };
+ append.setSystem(true);
+ append.schedule();
+ }
+
+}
diff --git a/org.eclipse.jdt.debug.tests/test plugin/org/eclipse/jdt/debug/testplugin/TestDetailPaneFactory.java b/org.eclipse.jdt.debug.tests/test plugin/org/eclipse/jdt/debug/testplugin/TestDetailPaneFactory.java
new file mode 100644
index 0000000..51b0e33
--- /dev/null
+++ b/org.eclipse.jdt.debug.tests/test plugin/org/eclipse/jdt/debug/testplugin/TestDetailPaneFactory.java
@@ -0,0 +1,88 @@
+/*******************************************************************************
+ * Copyright (c) 2006 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.jdt.debug.testplugin;
+
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.debug.ui.IDetailPane;
+import org.eclipse.debug.ui.IDetailPaneFactory;
+import org.eclipse.jface.viewers.IStructuredSelection;
+
+/**
+ * This is a detail pane factory that produces <code>TestDetailPane</code>'s.
+ * Included in the test plugin by being contributed to the
+ * org.eclipse.debug.ui.detailPaneFactories extension point.
+ *
+ * @see org.eclipse.jdt.debug.tests.ui.DetailPaneManagerTests.java
+ */
+public class TestDetailPaneFactory implements IDetailPaneFactory {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.internal.ui.views.variables.IDetailsFactory#createDetailsArea(java.lang.String)
+ */
+ public IDetailPane createDetailPane(String id) {
+ return new TestDetailPane();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.internal.ui.views.variables.IDetailsFactory#getDetailsTypes(org.eclipse.jface.viewers.IStructuredSelection)
+ */
+ public Set getDetailPaneTypes(IStructuredSelection selection) {
+ Set possibleIDs = new HashSet(1);
+ if (selection != null){
+ possibleIDs.add(TestDetailPane.ID);
+ }
+ return possibleIDs;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.ui.IDetailPaneFactory#getDefaultDetailPane(org.eclipse.jface.viewers.IStructuredSelection)
+ */
+ public String getDefaultDetailPane(IStructuredSelection selection) {
+ if (selection.getFirstElement() instanceof String){
+ if (((String)selection.getFirstElement()).equals("test pane is default")){
+ return TestDetailPane.ID;
+ }
+ }
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.internal.ui.views.variables.IDetailsFactory#getName(java.lang.String)
+ */
+ public String getDetailPaneName(String id) {
+ if (id.equals(TestDetailPane.ID)){
+ return "Test Pane";
+ }
+ else{
+ return null;
+ }
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.internal.ui.views.variables.IDetailsFactory#getDescription(java.lang.String)
+ */
+ public String getDetailPaneDescription(String id) {
+ if (id.equals(TestDetailPane.ID)){
+ return "Test Pane Description";
+ }
+ else{
+ return null;
+ }
+
+ }
+
+
+
+}
diff --git a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/AutomatedSuite.java b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/AutomatedSuite.java
index 27e028c..084e39a 100644
--- a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/AutomatedSuite.java
+++ b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/AutomatedSuite.java
@@ -91,6 +91,7 @@
import org.eclipse.jdt.debug.tests.sourcelookup.ProjectSourceContainerTests;
import org.eclipse.jdt.debug.tests.sourcelookup.SourceLocationTests;
import org.eclipse.jdt.debug.tests.sourcelookup.SourceLookupTests;
+import org.eclipse.jdt.debug.tests.ui.DetailPaneManagerTests;
import org.eclipse.jdt.debug.tests.ui.ViewMangementTests;
/**
@@ -240,6 +241,9 @@
// Leak tests
addTest(new TestSuite(InstructionPointerTests.class));
+
+ // Variables View Detail Pane tests
+ addTest(new TestSuite(DetailPaneManagerTests.class));
}
}
diff --git a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/ui/DetailPaneManagerTests.java b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/ui/DetailPaneManagerTests.java
new file mode 100644
index 0000000..7b03756
--- /dev/null
+++ b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/ui/DetailPaneManagerTests.java
@@ -0,0 +1,225 @@
+/*******************************************************************************
+ * Copyright (c) 2006 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.jdt.debug.tests.ui;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.debug.internal.ui.views.variables.details.DefaultDetailPane;
+import org.eclipse.debug.internal.ui.views.variables.details.DetailPaneManager;
+import org.eclipse.debug.ui.IDetailPane;
+import org.eclipse.jdt.debug.testplugin.TestDetailPane;
+import org.eclipse.jdt.debug.tests.AbstractDebugTest;
+import org.eclipse.jdt.internal.debug.core.model.JDIDebugElement;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+
+/**
+ * Tests the detail pane functionality by testing <code>DetailPaneManager</code>.
+ * The manager is responsible for the default detail pane contributed by the
+ * platform and detail panes contributed at the org.eclipse.debug.ui.detailPaneFactories.
+ * The manager must keep track of which is the preferred detail pane to display and
+ * know what detail panes can be displayed for certain types of selections.
+ */
+public class DetailPaneManagerTests extends AbstractDebugTest {
+
+ DetailPaneManager fManager;
+
+ /**
+ * Initializes the test class and gets the singleton detail pane manager.
+ * @param name
+ */
+ public DetailPaneManagerTests(String name) {
+ super(name);
+ fManager = DetailPaneManager.getDefault();
+ // Make sure that the default pane has been loaded.
+ fManager.getPreferredPaneFromSelection(null);
+ }
+
+ /**
+ * Tests that the manager makes correct default selection when
+ * one or more detail panes are available.
+ */
+ public void testGetUserPreferredDetailPane() {
+ String id = fManager.getUserPreferredDetailPane(new HashSet());
+ assertEquals("Incorrect pane ID", null, id);
+
+ Set detailPanes = new HashSet();
+ detailPanes.add("NewPane1");
+ id = fManager.getUserPreferredDetailPane(detailPanes);
+ assertEquals("Incorrect pane ID", null, id);
+
+ detailPanes.add("NewPane2");
+ id = fManager.getUserPreferredDetailPane(detailPanes);
+ assertEquals("Incorrect pane ID", null, id);
+
+ detailPanes.add(DefaultDetailPane.ID);
+ id = fManager.getUserPreferredDetailPane(detailPanes);
+ assertEquals("Incorrect pane ID", null, id);
+
+ detailPanes.clear();
+ detailPanes.add(DefaultDetailPane.ID);
+ id = fManager.getUserPreferredDetailPane(detailPanes);
+ assertEquals("Incorrect pane ID", DefaultDetailPane.ID, id);
+ }
+
+ /**
+ * Tests that the manager can remember which detail pane is
+ * currently the preferred pane.
+ */
+ public void testSetPreferredDetailPane() {
+ fManager.setPreferredDetailPane(null, null);
+ String id = fManager.getUserPreferredDetailPane(null);
+ assertEquals("Incorrect pane ID", null, id);
+
+ fManager.setPreferredDetailPane(null, "Example");
+ id = fManager.getUserPreferredDetailPane(null);
+ assertEquals("Incorrect pane ID", null, id);
+
+ Set detailPanes = new HashSet();
+ detailPanes.add("Example1");
+ fManager.setPreferredDetailPane(detailPanes, "Example1");
+ id = fManager.getUserPreferredDetailPane(detailPanes);
+ assertEquals("Incorrect pane ID", "Example1", id);
+
+ detailPanes.add("Example2");
+ fManager.setPreferredDetailPane(detailPanes, "Example2");
+ id = fManager.getUserPreferredDetailPane(detailPanes);
+ assertEquals("Incorrect pane ID", "Example2", id);
+
+ detailPanes.add(DefaultDetailPane.ID);
+ id = fManager.getUserPreferredDetailPane(detailPanes);
+ assertEquals("Incorrect pane ID", null, id);
+ fManager.setPreferredDetailPane(detailPanes, "Example2");
+ id = fManager.getUserPreferredDetailPane(detailPanes);
+ assertEquals("Incorrect pane ID", "Example2", id);
+ }
+
+ /**
+ * Tests that the manager can determine the preferred pane
+ * given a selection.
+ */
+ public void testGetPreferredPaneFromSelection() {
+ IStructuredSelection selection = null;
+ String id = fManager.getPreferredPaneFromSelection(selection);
+ assertEquals("Incorrect pane ID", DefaultDetailPane.ID, id);
+
+ selection = new StructuredSelection();
+ id = fManager.getPreferredPaneFromSelection(selection);
+ assertEquals("Incorrect pane ID", DefaultDetailPane.ID, id);
+
+ selection = new StructuredSelection(new String[]{"example selection"});
+ id = fManager.getPreferredPaneFromSelection(selection);
+ assertEquals("Incorrect pane ID", DefaultDetailPane.ID, id);
+
+ selection = new StructuredSelection(new String[]{"test pane is default","example selection"});
+ id = fManager.getPreferredPaneFromSelection(selection);
+ assertEquals("Incorrect pane ID", TestDetailPane.ID, id);
+
+ selection = new StructuredSelection(new String[]{"String1","String2"});
+ id = fManager.getPreferredPaneFromSelection(selection);
+ assertEquals("Incorrect pane ID", TestDetailPane.ID, id);
+
+ selection = new StructuredSelection(new String[]{"String1","String2"});
+ fManager.setPreferredDetailPane(fManager.getAvailablePaneIDs(selection), DefaultDetailPane.ID);
+ id = fManager.getPreferredPaneFromSelection(selection);
+ assertEquals("Incorrect pane ID", DefaultDetailPane.ID, id);
+
+ selection = new StructuredSelection(new String[]{"String1","String2","String3"});
+ id = fManager.getPreferredPaneFromSelection(selection);
+ assertEquals("Incorrect pane ID", DefaultDetailPane.ID, id);
+
+ selection = new StructuredSelection(new JDIDebugElement[]{});
+ id = fManager.getPreferredPaneFromSelection(selection);
+ assertEquals("Incorrect pane ID", DefaultDetailPane.ID, id);
+ }
+
+ /**
+ * Tests that the manager returns all possible panes that can be used
+ * for a given selection.
+ */
+ public void testGetAvailablePaneIDs() {
+ IStructuredSelection selection = null;
+ Set result = fManager.getAvailablePaneIDs(selection);
+ assertTrue("Set was incorrect",result.size()==1 && result.contains(DefaultDetailPane.ID));
+
+ selection = new StructuredSelection(new String[]{"example selection"});
+ result = fManager.getAvailablePaneIDs(selection);
+ assertTrue("Set was incorrect",result.size()==1 && result.contains(DefaultDetailPane.ID));
+
+ selection = new StructuredSelection(new String[]{"test pane is default","example selection"});
+ result = fManager.getAvailablePaneIDs(selection);
+ assertTrue("Set was incorrect",result.size()==2 && result.contains(DefaultDetailPane.ID) && result.contains(TestDetailPane.ID));
+
+ selection = new StructuredSelection(new String[]{"String1","String2"});
+ result = fManager.getAvailablePaneIDs(selection);
+ assertTrue("Set was incorrect",result.size()==2 && result.contains(DefaultDetailPane.ID) && result.contains(TestDetailPane.ID));
+
+ selection = new StructuredSelection(new String[]{"String1","String2","String3"});
+ result = fManager.getAvailablePaneIDs(selection);
+ assertTrue("Set was incorrect",result.size()==1 && result.contains(DefaultDetailPane.ID));
+ }
+
+ /**
+ * Checks that the manager can query the correct factory to produce
+ * a detail pane with the given ID.
+ */
+ public void testGetDetailPaneFromID() {
+ IDetailPane pane = fManager.getDetailPaneFromID(null);
+ assertNull("Incorrect pane returned",pane);
+
+ pane = fManager.getDetailPaneFromID("ThisPaneDoesNotExist");
+ assertNull("Incorrect pane returned",pane);
+
+ pane = fManager.getDetailPaneFromID(DefaultDetailPane.ID);
+ assertNotNull("Incorrect pane returned",pane);
+
+ pane = fManager.getDetailPaneFromID(TestDetailPane.ID);
+ assertNotNull("Incorrect pane returned",pane);
+ }
+
+ /**
+ * Checks that the manager can query the correct factory to produce
+ * the name of the detail pane with the given ID.
+ */
+ public void testGetNameFromID() {
+ String name = fManager.getNameFromID(null);
+ assertEquals("Incorrect name returned",null,name);
+
+ name = fManager.getNameFromID("ThisPaneDoesNotExist");
+ assertEquals("Incorrect name returned",null,name);
+
+ name = fManager.getNameFromID(DefaultDetailPane.ID);
+ assertEquals("Incorrect name returned",DefaultDetailPane.NAME,name);
+
+ name = fManager.getNameFromID(TestDetailPane.ID);
+ assertEquals("Incorrect name returned","Test Pane",name);
+ }
+
+ /**
+ * Checks that the manager can query the correct factory to produce
+ * the description of the detail pane with the given ID.
+ */
+ public void testGetDescriptionFromID() {
+ String description = fManager.getDescriptionFromID(null);
+ assertEquals("Incorrect name returned",null,description);
+
+ description = fManager.getDescriptionFromID("ThisPaneDoesNotExist");
+ assertEquals("Incorrect name returned",null,description);
+
+ description = fManager.getDescriptionFromID(DefaultDetailPane.ID);
+ assertEquals("Incorrect name returned",DefaultDetailPane.DESCRIPTION,description);
+
+ description = fManager.getDescriptionFromID(TestDetailPane.ID);
+ assertEquals("Incorrect name returned","Test Pane Description",description);
+ }
+
+}