diff options
author | Pawel Piech | 2010-01-21 05:04:36 +0000 |
---|---|---|
committer | Pawel Piech | 2010-01-21 05:04:36 +0000 |
commit | fdfcf440a8a8efca8027f4d673a54826669c999f (patch) | |
tree | 9a036d1938b5e3f5b0dde6db9065c4cb5b6b6847 /org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui | |
parent | 9c982be7f7da595b67506ac9a7a81b9f6e9c36d8 (diff) | |
download | eclipse.platform.debug-fdfcf440a8a8efca8027f4d673a54826669c999f.tar.gz eclipse.platform.debug-fdfcf440a8a8efca8027f4d673a54826669c999f.tar.xz eclipse.platform.debug-fdfcf440a8a8efca8027f4d673a54826669c999f.zip |
Bug 235646 - [Expressions View] Add support for columns in the expressions view.
Diffstat (limited to 'org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui')
11 files changed, 490 insertions, 31 deletions
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugUIMessages.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugUIMessages.java index 72518dc52..4f2ad1628 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugUIMessages.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugUIMessages.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 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 @@ -252,6 +252,11 @@ public class DebugUIMessages extends NLS { public static String WorkingDirectoryBlock_1; public static String WorkingDirectoryBlock_Exception_occurred_reading_configuration___15; + // + // Elements + // + public static String ExpressionManagerContentProvider_1; + static { // load message values from bundle file NLS.initializeMessages(BUNDLE_NAME, DebugUIMessages.class); diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugUIMessages.properties b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugUIMessages.properties index f0e2cb06c..8068829d2 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugUIMessages.properties +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugUIMessages.properties @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2000, 2009 IBM Corporation and others. +# Copyright (c) 2000, 2010 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 @@ -236,3 +236,8 @@ WorkingDirectoryBlock_19=Ot&her: WorkingDirectoryBlock_20=Working directory not specified WorkingDirectoryBlock_1=&File System... WorkingDirectoryBlock_Exception_occurred_reading_configuration___15=Exception occurred reading configuration: + +############################################################## +# Elements +############################################################## +ExpressionManagerContentProvider_1=Add new expression diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/VariableColumnFactoryAdapter.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/VariableColumnFactoryAdapter.java index c756501a0..79d3e8f7c 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/VariableColumnFactoryAdapter.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/VariableColumnFactoryAdapter.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. + * Copyright (c) 2006, 2010 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 @@ -7,9 +7,11 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Wind Rvier Systems - added support for columns (bug 235646) *******************************************************************************/ package org.eclipse.debug.internal.ui.elements.adapters; +import org.eclipse.debug.core.IExpressionManager; import org.eclipse.debug.core.model.IStackFrame; import org.eclipse.debug.internal.ui.viewers.model.provisional.IColumnPresentation; import org.eclipse.debug.internal.ui.viewers.model.provisional.IColumnPresentationFactory; @@ -28,8 +30,11 @@ public class VariableColumnFactoryAdapter implements IColumnPresentationFactory */ public IColumnPresentation createColumnPresentation(IPresentationContext context, Object element) { String id = context.getId(); - if (IDebugUIConstants.ID_VARIABLE_VIEW.equals(id) || IDebugUIConstants.ID_REGISTER_VIEW.equals(id)) { - if (element instanceof IStackFrame) { + if (IDebugUIConstants.ID_VARIABLE_VIEW.equals(id) || + IDebugUIConstants.ID_REGISTER_VIEW.equals(id) || + IDebugUIConstants.ID_EXPRESSION_VIEW.equals(id)) + { + if (element instanceof IStackFrame || element instanceof IExpressionManager) { return new VariableColumnPresentation(); } } @@ -41,8 +46,11 @@ public class VariableColumnFactoryAdapter implements IColumnPresentationFactory */ public String getColumnPresentationId(IPresentationContext context, Object element) { String id = context.getId(); - if (IDebugUIConstants.ID_VARIABLE_VIEW.equals(id) || IDebugUIConstants.ID_REGISTER_VIEW.equals(id)) { - if (element instanceof IStackFrame) { + if (IDebugUIConstants.ID_VARIABLE_VIEW.equals(id) || + IDebugUIConstants.ID_REGISTER_VIEW.equals(id) || + IDebugUIConstants.ID_EXPRESSION_VIEW.equals(id)) + { + if (element instanceof IStackFrame || element instanceof IExpressionManager) { return VariableColumnPresentation.DEFAULT_VARIABLE_COLUMN_PRESENTATION; } } diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/WatchExpressionCellModifier.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/WatchExpressionCellModifier.java new file mode 100644 index 000000000..077d6ed76 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/elements/adapters/WatchExpressionCellModifier.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Wind River Systems - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.internal.ui.elements.adapters; + +import org.eclipse.debug.core.model.IWatchExpression; +import org.eclipse.debug.internal.ui.DefaultLabelProvider; +import org.eclipse.jface.viewers.ICellModifier; + +/** + * Watch expressions modifier can change the expression name but not its value. + * + * @since 3.6 + */ +public class WatchExpressionCellModifier implements ICellModifier { + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.ICellModifier#canModify(java.lang.Object, java.lang.String) + */ + public boolean canModify(Object element, String property) { + if (VariableColumnPresentation.COLUMN_VARIABLE_NAME.equals(property)) { + return element instanceof IWatchExpression; + } + return false; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.ICellModifier#getValue(java.lang.Object, java.lang.String) + */ + public Object getValue(Object element, String property) { + if (VariableColumnPresentation.COLUMN_VARIABLE_NAME.equals(property)) { + return DefaultLabelProvider.escapeSpecialChars( ((IWatchExpression)element).getExpressionText() ); + } + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.ICellModifier#modify(java.lang.Object, java.lang.String, java.lang.Object) + */ + public void modify(Object element, String property, Object value) { + Object oldValue = getValue(element, property); + if (!value.equals(oldValue)) { + if (VariableColumnPresentation.COLUMN_VARIABLE_NAME.equals(property)) { + if (element instanceof IWatchExpression) { + if (value instanceof String) { + // The value column displays special characters + // escaped, so encode the string with any special + // characters escaped properly + String expressionText = DefaultLabelProvider.encodeEsacpedChars((String)value); + IWatchExpression expression = (IWatchExpression) element; + expression.setExpressionText(expressionText); + } + } + } + } + } + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/model/elements/ExpressionContentProvider.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/model/elements/ExpressionContentProvider.java index 6a6c2d249..67628f2d9 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/model/elements/ExpressionContentProvider.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/model/elements/ExpressionContentProvider.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. + * Copyright (c) 2006, 2010 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 @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Wind Rvier Systems - added support for columns (bug 235646) *******************************************************************************/ package org.eclipse.debug.internal.ui.model.elements; @@ -21,20 +22,68 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.debug.core.model.IErrorReportingExpression; import org.eclipse.debug.core.model.IExpression; import org.eclipse.debug.core.model.IValue; +import org.eclipse.debug.internal.core.IInternalDebugCoreConstants; +import org.eclipse.debug.internal.ui.elements.adapters.VariableColumnPresentation; import org.eclipse.debug.internal.ui.viewers.model.ViewerAdapterService; import org.eclipse.debug.internal.ui.viewers.model.ViewerUpdateMonitor; import org.eclipse.debug.internal.ui.viewers.model.provisional.IChildrenCountUpdate; import org.eclipse.debug.internal.ui.viewers.model.provisional.IChildrenUpdate; import org.eclipse.debug.internal.ui.viewers.model.provisional.IElementContentProvider; +import org.eclipse.debug.internal.ui.viewers.model.provisional.IElementLabelProvider; import org.eclipse.debug.internal.ui.viewers.model.provisional.IHasChildrenUpdate; +import org.eclipse.debug.internal.ui.viewers.model.provisional.ILabelUpdate; import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext; import org.eclipse.debug.internal.ui.viewers.model.provisional.IViewerUpdate; +import org.eclipse.debug.ui.IDebugUIConstants; +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.FontData; /** * @since 3.3 */ public class ExpressionContentProvider extends VariableContentProvider { + /** + * @since 3.6 + * Element object used to wrap the expression error message. It displays + * the error message only in the first column if columns are visible. + */ + private static class ErrorMessageElement implements IElementLabelProvider { + + public ErrorMessageElement(String message) { + fMessage = message; + } + + private final String fMessage; + + public void update(ILabelUpdate[] updates) { + for (int i = 0; i < updates.length; i++) { + String[] columnIds = updates[i].getColumnIds(); + if (columnIds == null) { + updateLabel(updates[i], 0); + } else { + for (int j = 0; j < columnIds.length; j++) { + if (VariableColumnPresentation.COLUMN_VARIABLE_NAME.equals(columnIds[j])) { + updateLabel(updates[i], j); + } else { + updates[i].setLabel(IInternalDebugCoreConstants.EMPTY_STRING, j); + } + } + } + + updates[i].done(); + } + } + + private void updateLabel(ILabelUpdate update, int columnIndex) { + update.setLabel(fMessage, columnIndex); + FontData fontData = JFaceResources.getFontDescriptor(IDebugUIConstants.PREF_VARIABLE_TEXT_FONT).getFontData()[0]; + fontData.setStyle(SWT.ITALIC); + + } + } + /* (non-Javadoc) * @see org.eclipse.debug.internal.ui.model.elements.ElementContentProvider#update(org.eclipse.debug.internal.ui.viewers.model.provisional.IChildrenCountUpdate[]) */ @@ -132,7 +181,7 @@ public class ExpressionContentProvider extends VariableContentProvider { String[] messages = expression.getErrorMessages(); LinkedHashSet set = new LinkedHashSet(messages.length); for (int i = 0; i < messages.length; i++) { - set.add(messages[i]); + set.add(new ErrorMessageElement(messages[i])); } return set.toArray(); } diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/model/elements/ExpressionLabelProvider.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/model/elements/ExpressionLabelProvider.java index 8788f0cd6..66c83e013 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/model/elements/ExpressionLabelProvider.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/model/elements/ExpressionLabelProvider.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 IBM Corporation and others. + * Copyright (c) 2006, 2010 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 @@ -7,11 +7,17 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Wind Rvier Systems - added support for columns (bug 235646) *******************************************************************************/ package org.eclipse.debug.internal.ui.model.elements; import org.eclipse.core.runtime.CoreException; import org.eclipse.debug.core.model.IErrorReportingExpression; +import org.eclipse.debug.core.model.IExpression; +import org.eclipse.debug.core.model.IValue; +import org.eclipse.debug.core.model.IWatchExpression; +import org.eclipse.debug.internal.ui.DebugUIMessages; +import org.eclipse.debug.internal.ui.elements.adapters.VariableColumnPresentation; import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext; import org.eclipse.jface.viewers.TreePath; import org.eclipse.swt.graphics.RGB; @@ -29,10 +35,127 @@ public class ExpressionLabelProvider extends VariableLabelProvider { if (element instanceof IErrorReportingExpression) { IErrorReportingExpression expression = (IErrorReportingExpression) element; if (expression.hasErrors()) { - return new RGB(255, 0, 0); + if (columnId == null || columnId.equals(VariableColumnPresentation.COLUMN_VARIABLE_VALUE)) { + return new RGB(255, 0, 0); + } } } return super.getForeground(elementPath, presentationContext, columnId); } + protected String getLabel(TreePath elementPath, IPresentationContext context, String columnId) throws CoreException { + if (columnId == null) { + return super.getLabel(elementPath, context, columnId); + } else { + IExpression expression = (IExpression) elementPath.getLastSegment(); + IValue value = expression.getValue(); + return getColumnText(expression, value, context, columnId); + } + } + + /** + * Returns text for a specific columns for the expression/value. + * + * @param expression expression to retrieve text for + * @param value the value associated with the variable + * @param context presentation context specifying how to display the text + * @param columnId the column to get the text for + * @return the label text + * @throws CoreException + * + * @since 3.6 + */ + private String getColumnText(IExpression expression, IValue value, IPresentationContext context, String columnId) throws CoreException { + if (VariableColumnPresentation.COLUMN_VARIABLE_NAME.equals(columnId)) { + return getExpressionName(expression, context); + } else if (VariableColumnPresentation.COLUMN_VARIABLE_VALUE.equals(columnId)) { + return getExpressionValueText(expression, value, context); + } else if (VariableColumnPresentation.COLUMN_VALUE_TYPE.equals(columnId) || + VariableColumnPresentation.COLUMN_VARIABLE_TYPE.equals(columnId)) + { + if (value != null) { + return getValueTypeName(null, value, context); + } + } + return null; + } + + /** + * Returns the expression's text to show in the view's name column. + * + * @param expression expression to retrieve text for + * @param context presentation context specifying how to display the text + * + * @since 3.6 + */ + protected String getExpressionName(IExpression expression, IPresentationContext context) throws CoreException { + if (expression instanceof IWatchExpression) { + return getWatchExpressionName((IWatchExpression) expression, context); + } + return expression.getExpressionText(); + } + + /** + * Returns the watch expression's text to show in the view's name column. + * + * @since 3.6 + */ + private String getWatchExpressionName(IWatchExpression expression, IPresentationContext context) throws CoreException { + StringBuffer result= new StringBuffer(); + + String snippet = expression.getExpressionText().trim(); + StringBuffer snippetBuffer = new StringBuffer(); + if (snippet.length() > 30){ + snippetBuffer.append(snippet.substring(0, 15)); + snippetBuffer.append(DebugUIMessages.DefaultLabelProvider_0); + snippetBuffer.append(snippet.substring(snippet.length() - 15)); + } else { + snippetBuffer.append(snippet); + } + snippet = snippetBuffer.toString().replaceAll("[\n\r\t]+", " "); //$NON-NLS-1$//$NON-NLS-2$ + + result.append('"'); + result.append(snippet); + result.append('"'); + + return result.toString(); + } + + /** + * Returns the expression's value, or a message to show in the value column, + * if the value is not available. + * + * @param expression expression to retrieve text for + * @param value the value associated with the variable + * @param context presentation context specifying how to display the text + * @return string representing the expression's value + * @throws CoreException + * + * @since 3.6 + */ + protected String getExpressionValueText(IExpression expression, IValue value, IPresentationContext context) throws CoreException { + if (expression instanceof IWatchExpression) { + IWatchExpression watchExpression = (IWatchExpression)expression; + StringBuffer result = new StringBuffer(); + + if (watchExpression.isPending()) { + result.append(DebugUIMessages.DefaultLabelProvider_12); + } else if (watchExpression.hasErrors()) { + result.append(DebugUIMessages.DefaultLabelProvider_13); + } else if (value != null) { + result.append( getValueText(null, value, context) ); + } + if (!watchExpression.isEnabled()) { + result.append(DebugUIMessages.DefaultLabelProvider_15); + } + + return result.toString(); + } + + if (value != null) { + return getValueText(null, value, context); + } + return null; + } + } diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/model/elements/ExpressionManagerContentProvider.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/model/elements/ExpressionManagerContentProvider.java index 94503f48f..b275b2d43 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/model/elements/ExpressionManagerContentProvider.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/model/elements/ExpressionManagerContentProvider.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. + * Copyright (c) 2006, 2010 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 @@ -7,34 +7,168 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Wind Rvier Systems - added support for columns (bug 235646) *******************************************************************************/ package org.eclipse.debug.internal.ui.model.elements; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.IExpressionManager; +import org.eclipse.debug.core.ILaunch; +import org.eclipse.debug.core.model.IDebugElement; +import org.eclipse.debug.core.model.IWatchExpression; +import org.eclipse.debug.internal.core.IInternalDebugCoreConstants; +import org.eclipse.debug.internal.ui.DebugUIMessages; +import org.eclipse.debug.internal.ui.DefaultLabelProvider; +import org.eclipse.debug.internal.ui.elements.adapters.VariableColumnPresentation; +import org.eclipse.debug.internal.ui.viewers.model.provisional.IElementEditor; +import org.eclipse.debug.internal.ui.viewers.model.provisional.IElementLabelProvider; +import org.eclipse.debug.internal.ui.viewers.model.provisional.ILabelUpdate; import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext; import org.eclipse.debug.internal.ui.viewers.model.provisional.IViewerUpdate; +import org.eclipse.debug.ui.DebugUITools; import org.eclipse.debug.ui.IDebugUIConstants; +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.jface.viewers.CellEditor; +import org.eclipse.jface.viewers.ICellModifier; +import org.eclipse.jface.viewers.TextCellEditor; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.widgets.Composite; /** * Default content provider for the expression manager. */ public class ExpressionManagerContentProvider extends ElementContentProvider { + /** + * An element representing the "Add new expression" entry in the + * expressions view. + * + * @since 3.6 + */ + private static class AddNewExpressionElement implements IElementLabelProvider, IElementEditor, ICellModifier { + + public void update(ILabelUpdate[] updates) { + for (int i = 0; i < updates.length; i++) { + String[] columnIds = updates[i].getColumnIds(); + if (columnIds == null) { + updateLabel(updates[i], 0); + } else { + for (int j = 0; j < columnIds.length; j++) { + if (VariableColumnPresentation.COLUMN_VARIABLE_NAME.equals(columnIds[j])) { + updateLabel(updates[i], j); + } else { + updates[i].setLabel(IInternalDebugCoreConstants.EMPTY_STRING, j); + } + } + } + + updates[i].done(); + } + } + + private void updateLabel(ILabelUpdate update, int columnIndex) { + update.setLabel(DebugUIMessages.ExpressionManagerContentProvider_1, columnIndex); + + // Display the "Add new expression" element in italic to + // distinguish it from user elements in view. + FontData fontData = JFaceResources.getFontDescriptor(IDebugUIConstants.PREF_VARIABLE_TEXT_FONT).getFontData()[0]; + fontData.setStyle(SWT.ITALIC); + update.setFontData(fontData, columnIndex); + } + + public CellEditor getCellEditor(IPresentationContext context, String columnId, Object element, Composite parent) { + return new TextCellEditor(parent); + } + + public ICellModifier getCellModifier(IPresentationContext context, Object element) { + return this; + } + + public boolean canModify(Object element, String property) { + return (VariableColumnPresentation.COLUMN_VARIABLE_NAME.equals(property)); + } + + public Object getValue(Object element, String property) { + return IInternalDebugCoreConstants.EMPTY_STRING; + } + + public void modify(Object element, String property, Object value) { + // If an expression is entered, add a new watch expression to the + // manager. + if (value instanceof String && + !IInternalDebugCoreConstants.EMPTY_STRING.equals( ((String)value).trim()) ) + { + String expressionText = DefaultLabelProvider.encodeEsacpedChars((String)value); + IWatchExpression newExpression= + DebugPlugin.getDefault().getExpressionManager().newWatchExpression(expressionText); + DebugPlugin.getDefault().getExpressionManager().addExpression(newExpression); + newExpression.setExpressionContext(getContext()); + } + } + + private IDebugElement getContext() { + IAdaptable object = DebugUITools.getDebugContext(); + IDebugElement context = null; + if (object instanceof IDebugElement) { + context = (IDebugElement) object; + } else if (object instanceof ILaunch) { + context = ((ILaunch) object).getDebugTarget(); + } + return context; + } + + } + + private static final AddNewExpressionElement ADD_NEW_EXPRESSION_ELEMENT = new AddNewExpressionElement(); + /* (non-Javadoc) * @see org.eclipse.debug.internal.ui.viewers.model.provisional.elements.ElementContentProvider#getChildCount(java.lang.Object, org.eclipse.debug.internal.ui.viewers.provisional.IPresentationContext) */ protected int getChildCount(Object element, IPresentationContext context, IViewerUpdate monitor) throws CoreException { - return ((IExpressionManager) element).getExpressions().length; + // Add the "Add new expression" element only if columns are displayed. + return ((IExpressionManager) element).getExpressions().length + + (context.getColumns() != null ? 1 : 0); } /* (non-Javadoc) * @see org.eclipse.debug.internal.ui.viewers.model.provisional.elements.ElementContentProvider#getChildren(java.lang.Object, int, int, org.eclipse.debug.internal.ui.viewers.provisional.IPresentationContext) */ protected Object[] getChildren(Object parent, int index, int length, IPresentationContext context, IViewerUpdate monitor) throws CoreException { - return getElements(((IExpressionManager) parent).getExpressions(), index, length); + if (context.getColumns() != null) { + return getElements(((IExpressionManager) parent).getExpressions(), ADD_NEW_EXPRESSION_ELEMENT, index, length); + } else { + return getElements(((IExpressionManager) parent).getExpressions(), index, length); + } } + /** + * Returns a subrange of elements from the given elements array plus the last element. + * + * @see ElementContentProvider#getElements(Object[], int, int) + * + * @since 3.6 + */ + private Object[] getElements(Object[] elements, Object lastElement, int index, int length) { + + int max = elements.length + 1; + if (index < max && ((index + length) > max)) { + length = max - index; + } + if ((index + length) <= max) { + Object[] sub = new Object[length]; + System.arraycopy(elements, index, sub, 0, Math.min(elements.length - index, length)); + if (index + length > elements.length) { + sub[length - 1] = lastElement; + } + return sub; + } + return null; + } + + /* (non-Javadoc) * @see org.eclipse.debug.internal.ui.viewers.model.provisional.elements.ElementContentProvider#supportsContextId(java.lang.String) */ @@ -46,7 +180,7 @@ public class ExpressionManagerContentProvider extends ElementContentProvider { * @see org.eclipse.debug.internal.ui.model.elements.ElementContentProvider#hasChildren(java.lang.Object, org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext, org.eclipse.debug.internal.ui.viewers.model.provisional.IViewerUpdate) */ protected boolean hasChildren(Object element, IPresentationContext context, IViewerUpdate monitor) throws CoreException { - return ((IExpressionManager)element).hasExpressions(); + return true; } } diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/model/elements/WatchExpressionEditor.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/model/elements/WatchExpressionEditor.java new file mode 100644 index 000000000..88c329e71 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/model/elements/WatchExpressionEditor.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Wind River Systems - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.internal.ui.model.elements; + +import org.eclipse.debug.internal.ui.elements.adapters.WatchExpressionCellModifier; +import org.eclipse.debug.internal.ui.viewers.model.provisional.IElementEditor; +import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext; +import org.eclipse.jface.viewers.CellEditor; +import org.eclipse.jface.viewers.ICellModifier; +import org.eclipse.jface.viewers.TextCellEditor; +import org.eclipse.swt.widgets.Composite; + +/** + * @since 3.6 + */ +public class WatchExpressionEditor implements IElementEditor { + + /* (non-Javadoc) + * @see org.eclipse.debug.internal.ui.viewers.model.provisional.IElementEditor#getCellEditor(org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext, java.lang.String, java.lang.Object, org.eclipse.swt.widgets.Composite) + */ + public CellEditor getCellEditor(IPresentationContext context, String columnId, Object element, Composite parent) { + return new TextCellEditor(parent); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.internal.ui.viewers.model.provisional.IElementEditor#getCellModifier(org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext, java.lang.Object) + */ + public ICellModifier getCellModifier(IPresentationContext context, Object element) { + return new WatchExpressionCellModifier(); + } + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/ExpressionManagerModelProxy.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/ExpressionManagerModelProxy.java index 686cd0d2f..8e5d77991 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/ExpressionManagerModelProxy.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/update/ExpressionManagerModelProxy.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. + * Copyright (c) 2005, 2010 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 @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Wind Rvier Systems - added support for columns (bug 235646) *******************************************************************************/ package org.eclipse.debug.internal.ui.viewers.update; @@ -19,6 +20,8 @@ import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelDelta; 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; +import org.eclipse.jface.util.IPropertyChangeListener; +import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.jface.viewers.Viewer; @@ -27,7 +30,7 @@ import org.eclipse.jface.viewers.Viewer; * * @see org.eclipse.debug.internal.core.ExpressionManager */ -public class ExpressionManagerModelProxy extends AbstractModelProxy implements IExpressionsListener2 { +public class ExpressionManagerModelProxy extends AbstractModelProxy implements IExpressionsListener2, IPropertyChangeListener { /* (non-Javadoc) * @see org.eclipse.debug.internal.ui.viewers.update.EventHandlerModelProxy#init(org.eclipse.debug.internal.ui.viewers.IPresentationContext) @@ -35,6 +38,7 @@ public class ExpressionManagerModelProxy extends AbstractModelProxy implements I public void init(IPresentationContext context) { super.init(context); getExpressionManager().addExpressionListener(this); + context.addPropertyChangeListener(this); } /* (non-Javadoc) @@ -55,6 +59,7 @@ public class ExpressionManagerModelProxy extends AbstractModelProxy implements I * @see org.eclipse.debug.internal.ui.viewers.update.EventHandlerModelProxy#dispose() */ public synchronized void dispose() { + getPresentationContext().removePropertyChangeListener(this); super.dispose(); getExpressionManager().removeExpressionListener(this); } @@ -64,13 +69,14 @@ public class ExpressionManagerModelProxy extends AbstractModelProxy implements I */ public void expressionsMoved(IExpression[] expressions, int index){ ModelDelta delta = new ModelDelta(getExpressionManager(), IModelDelta.NO_CHANGE); + int count = getElementsCount(); for (int i = 0; i < expressions.length; i++) { IExpression expression = expressions[i]; delta.addNode(expression, IModelDelta.REMOVED); } for (int i = 0; i < expressions.length; i++) { IExpression expression = expressions[i]; - delta.addNode(expression, index+i, IModelDelta.INSERTED); + delta.addNode(expression, index+i, IModelDelta.ADDED, count); } fireModelChanged(delta); } @@ -79,10 +85,11 @@ public class ExpressionManagerModelProxy extends AbstractModelProxy implements I * @see org.eclipse.debug.internal.core.IExpressionsListener2#expressionsInserted(org.eclipse.debug.core.model.IExpression[], int) */ public void expressionsInserted(IExpression[] expressions, int index){ + int count = getElementsCount(); ModelDelta delta = new ModelDelta(getExpressionManager(), IModelDelta.NO_CHANGE); for (int i = 0; i < expressions.length; i++) { IExpression expression = expressions[i]; - delta.addNode(expression, index+i, IModelDelta.INSERTED | IModelDelta.INSTALL); + delta.addNode(expression, index+i, IModelDelta.ADDED | IModelDelta.INSTALL, count); } fireModelChanged(delta); } @@ -91,6 +98,14 @@ public class ExpressionManagerModelProxy extends AbstractModelProxy implements I * @see org.eclipse.debug.core.IExpressionsListener#expressionsAdded(org.eclipse.debug.core.model.IExpression[]) */ public void expressionsAdded(IExpression[] expressions) { + int index = getExpressionManager().getExpressions().length - expressions.length; + int count = getElementsCount(); + ModelDelta delta = new ModelDelta(getExpressionManager(), IModelDelta.NO_CHANGE); + for (int i = 0; i < expressions.length; i++) { + IExpression expression = expressions[i]; + delta.addNode(expression, index+i, IModelDelta.ADDED | IModelDelta.INSTALL, count); + } + fireModelChanged(delta); updateExpressions(expressions, IModelDelta.ADDED | IModelDelta.INSTALL); } @@ -117,4 +132,20 @@ public class ExpressionManagerModelProxy extends AbstractModelProxy implements I fireModelChanged(delta); } + private int getElementsCount() { + // Account for the "Add new expression" element only if columns are + // displayed. + return getExpressionManager().getExpressions().length + + (getPresentationContext().getColumns() != null ? 1 : 0); + } + + public void propertyChange(PropertyChangeEvent event) { + // If columns are turned on/off, refresh the view to account for the + // "Add new expression" element. + if (IPresentationContext.PROPERTY_COLUMNS.equals(event.getProperty())) { + fireModelChanged(new ModelDelta(getExpressionManager(), IModelDelta.CONTENT)); + } + } + + } diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/expression/ExpressionView.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/expression/ExpressionView.java index 61d200907..1b62dcf10 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/expression/ExpressionView.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/expression/ExpressionView.java @@ -39,7 +39,6 @@ import org.eclipse.jface.action.Separator; import org.eclipse.jface.util.LocalSelectionTransfer; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.swt.SWT; import org.eclipse.swt.dnd.Clipboard; import org.eclipse.swt.dnd.DND; import org.eclipse.swt.dnd.TextTransfer; @@ -141,13 +140,6 @@ public class ExpressionView extends VariablesView { protected String getToggleActionLabel() { return VariablesViewMessages.ExpressionView_4; } - - /* (non-Javadoc) - * @see org.eclipse.debug.internal.ui.views.variables.VariablesView#getViewerStyle() - */ - protected int getViewerStyle() { - return SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL | SWT.VIRTUAL; - } /* (non-Javadoc) * @see org.eclipse.debug.internal.ui.views.variables.VariablesView#getPresentationContextId() diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/DebugElementAdapterFactory.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/DebugElementAdapterFactory.java index d95b7e5fc..3d491d5e2 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/DebugElementAdapterFactory.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/DebugElementAdapterFactory.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 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 @@ -9,6 +9,7 @@ * IBM Corporation - initial API and implementation * Wind River Systems - support for alternative expression view content providers * Patrick Chuong (Texas Instruments) - Improve usability of the breakpoint view (Bug 238956) + * Wind Rvier Systems - added support for columns (bug 235646) *******************************************************************************/ package org.eclipse.debug.internal.ui.views.launch; @@ -27,6 +28,7 @@ import org.eclipse.debug.core.model.IRegisterGroup; import org.eclipse.debug.core.model.IStackFrame; import org.eclipse.debug.core.model.IThread; import org.eclipse.debug.core.model.IVariable; +import org.eclipse.debug.core.model.IWatchExpression; import org.eclipse.debug.internal.ui.breakpoints.provisional.IBreakpointContainer; import org.eclipse.debug.internal.ui.elements.adapters.AsynchronousDebugLabelAdapter; import org.eclipse.debug.internal.ui.elements.adapters.DefaultBreakpointManagerInput; @@ -68,6 +70,7 @@ import org.eclipse.debug.internal.ui.model.elements.VariableContentProvider; import org.eclipse.debug.internal.ui.model.elements.VariableEditor; import org.eclipse.debug.internal.ui.model.elements.VariableLabelProvider; import org.eclipse.debug.internal.ui.model.elements.VariableMementoProvider; +import org.eclipse.debug.internal.ui.model.elements.WatchExpressionEditor; import org.eclipse.debug.internal.ui.viewers.model.provisional.IColumnPresentationFactory; import org.eclipse.debug.internal.ui.viewers.model.provisional.IElementContentProvider; import org.eclipse.debug.internal.ui.viewers.model.provisional.IElementEditor; @@ -104,6 +107,7 @@ public class DebugElementAdapterFactory implements IAdapterFactory { private static IElementLabelProvider fgLPBreakpoint = new BreakpointLabelProvider(); private static IElementLabelProvider fgLPBreakpointContainer = new BreakpointContainerLabelProvider(); private static IElementEditor fgEEVariable = new VariableEditor(); + private static IElementEditor fgEEWatchExpression = new WatchExpressionEditor(); private static IAsynchronousContentAdapter fgAsyncMemoryRetrieval = new MemoryRetrievalContentAdapter(); private static IAsynchronousContentAdapter fgAsyncMemoryBlock = new MemoryBlockContentAdapter(); @@ -255,9 +259,9 @@ public class DebugElementAdapterFactory implements IAdapterFactory { } if (adapterType.equals(IColumnPresentationFactory.class)) { - if (adaptableObject instanceof IStackFrame) { - return fgVariableColumnFactory; - } + if (adaptableObject instanceof IStackFrame || adaptableObject instanceof IExpressionManager) { + return fgVariableColumnFactory; + } } if (adapterType.equals(IElementMementoProvider.class)) { @@ -294,6 +298,9 @@ public class DebugElementAdapterFactory implements IAdapterFactory { if (adaptableObject instanceof IVariable) { return fgEEVariable; } + if (adaptableObject instanceof IWatchExpression) { + return fgEEWatchExpression; + } } if (adapterType.equals(IViewerInputProvider.class)) { |