diff options
5 files changed, 79 insertions, 2 deletions
diff --git a/org.eclipse.debug.core/buildnotes_platform-debug.html b/org.eclipse.debug.core/buildnotes_platform-debug.html index 7f459229a..879c0945e 100644 --- a/org.eclipse.debug.core/buildnotes_platform-debug.html +++ b/org.eclipse.debug.core/buildnotes_platform-debug.html @@ -14,6 +14,9 @@ <li>added <code>DebugPlugin.ATTR_CONSOLE_ENCODING</code> - this launch attribute specifies the encoding used by the console. When unspecified the default system encoding is used. This constant replaces the now deprecated <code>IDebugUIConstants.ATTR_CONSOLE_ENCODING</code>.</li> + <li>added <code>org.eclipse.debug.ui.actions.IWatchExpressionFactoryAdapterExtension</code> - this is an + interface that can be optionally implemented by <code>IWatchExpressionFactoryAdapter</code>'s. Allows + the <b>Create Watch Expression</b> action to be dynamically enabled based on the selected variables.</li> <li>deprecated <code>IDebugUIConstants.ATTR_CONSOLE_ENCODING</code>.</li> </ul> diff --git a/org.eclipse.debug.ui/component.xml b/org.eclipse.debug.ui/component.xml index 126a6f8a9..e84d1def6 100644 --- a/org.eclipse.debug.ui/component.xml +++ b/org.eclipse.debug.ui/component.xml @@ -51,6 +51,7 @@ <type name="IToggleBreakpointsTargetExtension" /> <type name="IVariableValueEditor" /> <type name="IWatchExpressionFactoryAdapter" /> + <type name="IWatchExpressionFactoryAdapterExtension" /> <type name="LaunchAction" subclass="false" /> <type name="LaunchAsAction" subclass="false" /> <type name="LaunchShortcutsAction" /> diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/expressions/WatchAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/expressions/WatchAction.java index 351e906ca..ec3c15cd5 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/expressions/WatchAction.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/expressions/WatchAction.java @@ -25,6 +25,7 @@ import org.eclipse.debug.internal.ui.actions.ActionMessages; import org.eclipse.debug.ui.DebugUITools; import org.eclipse.debug.ui.IDebugUIConstants; import org.eclipse.debug.ui.actions.IWatchExpressionFactoryAdapter; +import org.eclipse.debug.ui.actions.IWatchExpressionFactoryAdapterExtension; import org.eclipse.jface.action.IAction; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; @@ -77,7 +78,7 @@ public class WatchAction implements IObjectActionDelegate { private void createExpression(IVariable variable) { IWatchExpression expression; - IWatchExpressionFactoryAdapter factory = (IWatchExpressionFactoryAdapter) variable.getAdapter(IWatchExpressionFactoryAdapter.class); + IWatchExpressionFactoryAdapter factory = getFactory(variable); try { String exp = variable.getName(); if (factory != null) { @@ -114,7 +115,8 @@ public class WatchAction implements IObjectActionDelegate { Iterator iterator = fSelection.iterator(); while (iterator.hasNext()) { IVariable variable = (IVariable) iterator.next(); - if (manager.hasWatchExpressionDelegate(variable.getModelIdentifier())) { + if (manager.hasWatchExpressionDelegate(variable.getModelIdentifier()) && + isFactoryEnabled(variable)) { enabled++; } else { break; @@ -124,4 +126,28 @@ public class WatchAction implements IObjectActionDelegate { action.setEnabled(enabled == size); } + /** + * Returns whether the factory adapter for the given variable is currently enabled. + * + * @param variable + * @return whether the factory is enabled + */ + private boolean isFactoryEnabled(IVariable variable) { + IWatchExpressionFactoryAdapter factory = getFactory(variable); + if (factory instanceof IWatchExpressionFactoryAdapterExtension) { + IWatchExpressionFactoryAdapterExtension ext = (IWatchExpressionFactoryAdapterExtension) factory; + return ext.canCreateWatchExpression(variable); + } + return true; + } + + /** + * Returns the factory adapter for the given variable or <code>null</code> if none. + * + * @param variable + * @return factory or <code>null</code> + */ + private IWatchExpressionFactoryAdapter getFactory(IVariable variable) { + return (IWatchExpressionFactoryAdapter) variable.getAdapter(IWatchExpressionFactoryAdapter.class); + } } diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/IWatchExpressionFactoryAdapter.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/IWatchExpressionFactoryAdapter.java index 8baa2e841..d6199cdfb 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/IWatchExpressionFactoryAdapter.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/IWatchExpressionFactoryAdapter.java @@ -25,6 +25,9 @@ import org.eclipse.debug.core.model.IVariable; * the watch expression is generated based on the variable's name. * </p> * <p> + * Also see the optional interface {@link IWatchExpressionFactoryAdapterExtension}. + * </p> + * <p> * Clients may implement this interface. * </p> * @since 3.2 diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/IWatchExpressionFactoryAdapterExtension.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/IWatchExpressionFactoryAdapterExtension.java new file mode 100644 index 000000000..fd277f1aa --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/IWatchExpressionFactoryAdapterExtension.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * 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.debug.ui.actions; + +import org.eclipse.debug.core.model.IVariable; + +/** + * Optional extension to the watch expression factory adapter to dynamically enable the + * 'Create Watch Expression' action, based on the selected variable. + * <p> + * By default, the 'Create Watch Expression' action is enabled for instances of + * {@link org.eclipse.debug.core.model.IVariable} that have an associated + * {@link org.eclipse.debug.core.model.IWatchExpressionDelegate} registered + * for that debug model. + * When a watch expression factory adapter is available for a variable that implements + * this interface, the factory is consulted to enable the action. + * </p> + * <p> + * Clients may implementing {@link IWatchExpressionFactoryAdapter} may also implement + * this interface. + * </p> + * @since 3.3 + */ +public interface IWatchExpressionFactoryAdapterExtension extends IWatchExpressionFactoryAdapter { + + /** + * Returns whether a watch expression can be created for the specified variable. + * + * @param variable variable a watch expression is required for + * @return whether an expression can be created + * @exception org.eclipse.core.runtime.CoreException if unable to create a watch + * expression + */ + public boolean canCreateWatchExpression(IVariable variable); + +} |