From 048ebbf014ee6cc0dcac043c9a5de5c506cf5dec Mon Sep 17 00:00:00 2001 From: Anton Leherbauer Date: Tue, 27 Apr 2010 13:59:29 +0000 Subject: [PATCH] Bug 310425 - [hover][api] Add support for optional details pane and default expansion level to advanced hover --- .../ExpressionInformationControlCreator.java | 112 +++++++++++++----- .../debug/ui/AbstractDsfDebugTextHover.java | 26 +++- 2 files changed, 104 insertions(+), 34 deletions(-) diff --git a/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/internal/ui/ExpressionInformationControlCreator.java b/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/internal/ui/ExpressionInformationControlCreator.java index d105a7f9886..2f0e2cee589 100644 --- a/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/internal/ui/ExpressionInformationControlCreator.java +++ b/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/internal/ui/ExpressionInformationControlCreator.java @@ -226,6 +226,15 @@ public class ExpressionInformationControlCreator implements IInformationControlC return super.computeSizeHint(); } + @Override + public void setSize(int width, int height) { + if (!isResizable() && fDetailPaneComposite != null) { + // add height of details pane + height += fDetailPaneComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT).y; + } + super.setSize(width, height); + } + /** * Returns the dialog settings for this hover or null if none * @@ -273,9 +282,14 @@ public class ExpressionInformationControlCreator implements IInformationControlC Point size = shell.getSize(); settings.put(WIDTH, size.x); settings.put(HEIGHT, size.y); - int[] weights = fSashForm.getWeights(); - settings.put(SASH_WEIGHT_TREE, weights[0]); - settings.put(SASH_WEIGHT_DETAILS, weights[1]); + int[] weights = fSashForm.getWeights(); + if (weights.length == 1) { + settings.put(SASH_WEIGHT_TREE, weights[0]); + } + else if (weights.length == 2) { + settings.put(SASH_WEIGHT_TREE, weights[0]); + settings.put(SASH_WEIGHT_DETAILS, weights[1]); + } } } } @@ -312,7 +326,7 @@ public class ExpressionInformationControlCreator implements IInformationControlC } fViewer = new TreeModelViewer(fSashForm, SWT.MULTI | SWT.VIRTUAL | SWT.FULL_SELECTION, context); - fViewer.setAutoExpandLevel(1); + fViewer.setAutoExpandLevel(fExpansionLevel); if (view != null) { // copy over filters @@ -325,26 +339,28 @@ public class ExpressionInformationControlCreator implements IInformationControlC } } fInputService = new ViewerInputService(fViewer, this); + fTree = fViewer.getTree(); - fDetailPaneComposite = SWTFactory.createComposite(fSashForm, 1, 1, GridData.FILL_BOTH); - Layout layout = fDetailPaneComposite.getLayout(); - if (layout instanceof GridLayout) { - GridLayout gl = (GridLayout) layout; - gl.marginHeight = 0; - gl.marginWidth = 0; - } - - fDetailPane = new DetailPaneProxy(new DetailPaneContainer()); - fDetailPane.display(null); // Bring up the default pane so the user doesn't see an empty composite - - fTree = fViewer.getTree(); - fTree.addSelectionListener(new SelectionListener() { - public void widgetSelected(SelectionEvent e) { - fDetailPane.display((IStructuredSelection)fViewer.getSelection()); - } - public void widgetDefaultSelected(SelectionEvent e) {} - }); - + if (fShowDetailPane) { + fDetailPaneComposite = SWTFactory.createComposite(fSashForm, 1, 1, GridData.FILL_BOTH); + Layout layout = fDetailPaneComposite.getLayout(); + if (layout instanceof GridLayout) { + GridLayout gl = (GridLayout) layout; + gl.marginHeight = 0; + gl.marginWidth = 0; + } + + fDetailPane = new DetailPaneProxy(new DetailPaneContainer()); + fDetailPane.display(null); // Bring up the default pane so the user doesn't see an empty composite + + fTree.addSelectionListener(new SelectionListener() { + public void widgetSelected(SelectionEvent e) { + fDetailPane.display((IStructuredSelection)fViewer.getSelection()); + } + public void widgetDefaultSelected(SelectionEvent e) {} + }); + } + initSashWeights(); // add update listener to auto-select and display details of root expression @@ -357,7 +373,9 @@ public class ExpressionInformationControlCreator implements IInformationControlC selection = new TreeSelection(fViewer.getTopElementPath()); } fViewer.setSelection(selection); - fDetailPane.display(selection); + if (fDetailPane != null) { + fDetailPane.display(selection); + } }}); } public void viewerUpdatesBegin() { @@ -402,10 +420,16 @@ public class ExpressionInformationControlCreator implements IInformationControlC if (settings != null) { int tree = getIntSetting(settings, SASH_WEIGHT_TREE); if (tree > 0) { - int details = getIntSetting(settings, SASH_WEIGHT_DETAILS); - if (details > 0) { - fSashForm.setWeights(new int[]{tree, details}); - } + if (fDetailPane != null) { + int details = getIntSetting(settings, SASH_WEIGHT_DETAILS); + if (details <= 0) { + details = tree / 2; + } + fSashForm.setWeights(new int[]{tree, details}); + } + else { + fSashForm.setWeights(new int[]{tree}); + } } } } @@ -413,7 +437,9 @@ public class ExpressionInformationControlCreator implements IInformationControlC @Override public void setBackgroundColor(Color background) { super.setBackgroundColor(background); - fDetailPaneComposite.setBackground(background); + if (fDetailPaneComposite != null) { + fDetailPaneComposite.setBackground(background); + } fTree.setBackground(background); } @@ -445,7 +471,7 @@ public class ExpressionInformationControlCreator implements IInformationControlC @Override public IInformationControlCreator getInformationPresenterControlCreator() { - return new ExpressionInformationControlCreator() { + return new ExpressionInformationControlCreator(fShowDetailPane, fExpansionLevel) { @Override public IInformationControl createInformationControl(Shell shell) { return new ExpressionInformationControl(shell, true); @@ -459,7 +485,31 @@ public class ExpressionInformationControlCreator implements IInformationControlC } - /* + protected final boolean fShowDetailPane; + protected final int fExpansionLevel; + + /** + * Create default expression information control creator. + *

+ * Same as {@link ExpressionInformationControlCreator(true, 1)}. + *

+ */ + public ExpressionInformationControlCreator() { + this(true, 1); + } + + /** + * Create expression information control creator with customization options. + * + * @param showDetailPane if true the detail pane will be shown + * @param expansionLevel tree level to which the expression should be expanded by default + */ + public ExpressionInformationControlCreator(boolean showDetailPane, int expansionLevel) { + fShowDetailPane = showDetailPane; + fExpansionLevel = expansionLevel; + } + + /* * @see org.eclipse.jface.text.IInformationControlCreator#createInformationControl(org.eclipse.swt.widgets.Shell) */ public IInformationControl createInformationControl(Shell parent) { diff --git a/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/AbstractDsfDebugTextHover.java b/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/AbstractDsfDebugTextHover.java index 81a0aec31c7..d3115574dd4 100644 --- a/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/AbstractDsfDebugTextHover.java +++ b/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/AbstractDsfDebugTextHover.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009 Nokia Corporation and others. + * Copyright (c) 2009, 2010 Nokia 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 @@ -7,6 +7,7 @@ * * Contributors: * Nokia Corporation - initial API and implementation + * Wind River Systems - Added support for advanced expression hover *******************************************************************************/ package org.eclipse.cdt.dsf.debug.ui; @@ -15,6 +16,7 @@ import java.util.concurrent.ExecutionException; import org.eclipse.cdt.debug.ui.editors.AbstractDebugTextHover; import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor; +import org.eclipse.cdt.dsf.concurrent.IDsfStatusConstants; import org.eclipse.cdt.dsf.concurrent.Query; import org.eclipse.cdt.dsf.debug.internal.ui.ExpressionInformationControlCreator; import org.eclipse.cdt.dsf.debug.service.IExpressions; @@ -71,6 +73,11 @@ abstract public class AbstractDsfDebugTextHover extends AbstractDebugTextHover i protected void execute(final DataRequestMonitor rm) { DsfSession session = DsfSession.getSession(frame.getSessionId()); IExpressions expressions = dsfServicesTracker.getService(IExpressions.class); + if (expressions == null) { + rm.setStatus(DsfUIPlugin.newErrorStatus(IDsfStatusConstants.REQUEST_FAILED, "No expression service", null)); //$NON-NLS-1$ + rm.done(); + return; + } IExpressionDMContext expressionDMC = expressions.createExpression(frame, expression); FormattedValueDMContext formattedValueContext = expressions.getFormattedValueContext(expressionDMC, getHoverFormat()); expressions.getFormattedExpressionValue(formattedValueContext, @@ -141,17 +148,30 @@ abstract public class AbstractDsfDebugTextHover extends AbstractDebugTextHover i } /** - * Returns whether the expression explorer information control should be used. + * Returns whether the "advanced" expression information control should be used. * The default implementation returns false. */ protected boolean useExpressionExplorer() { return false; } + /** + * Create an information control creator for the "advanced" hover. + * Called by {@link #getHoverControlCreator()} when {@link #useExpressionExplorer()} + * returns true. + * + * @param showDetailPane whether the detail pane should be visible + * @param defaultExpansionLevel automatically expand the expression to this level + * @return the information control creator + */ + protected final IInformationControlCreator createExpressionInformationControlCreator(boolean showDetailPane, int defaultExpansionLevel) { + return new ExpressionInformationControlCreator(showDetailPane, defaultExpansionLevel); + } + @Override public IInformationControlCreator getHoverControlCreator() { if (useExpressionExplorer()) { - return new ExpressionInformationControlCreator(); + return createExpressionInformationControlCreator(true, 1); } else { return new IInformationControlCreator() { public IInformationControl createInformationControl(Shell parent) {