Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEd Swartz2010-03-24 20:32:55 +0000
committerEd Swartz2010-03-24 20:32:55 +0000
commit2cfb9a353a74ebc9e83512416b8f5f0cd264998a (patch)
tree3d53ba0635cbf4e314377232bdb6775c5d42b135 /debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt
parent1ba8d3916d0eb69237907c90db11b341b635f04b (diff)
downloadorg.eclipse.cdt-2cfb9a353a74ebc9e83512416b8f5f0cd264998a.tar.gz
org.eclipse.cdt-2cfb9a353a74ebc9e83512416b8f5f0cd264998a.tar.xz
org.eclipse.cdt-2cfb9a353a74ebc9e83512416b8f5f0cd264998a.zip
Fix bug 306553 by generalizing Cast To Type / Display As Array UI so it can be implemented by adapters. In DSF, add IExpressions2 service to implement this support.
Diffstat (limited to 'debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt')
-rw-r--r--debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/CastToArrayActionHandler.java (renamed from debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/CastToArrayActionDelegate.java)77
-rw-r--r--debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/CastToTypeActionHandler.java (renamed from debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/CastToTypeActionDelegate.java)82
-rw-r--r--debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RestoreDefaultTypeActionHandler.java (renamed from debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RestoreDefaultTypeActionDelegate.java)75
3 files changed, 106 insertions, 128 deletions
diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/CastToArrayActionDelegate.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/CastToArrayActionHandler.java
index 1c84bcba07d..3e37a31b1f3 100644
--- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/CastToArrayActionDelegate.java
+++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/CastToArrayActionHandler.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2006 QNX Software Systems and others.
+ * Copyright (c) 2004, 2010 QNX Software 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
@@ -7,6 +7,7 @@
*
* Contributors:
* QNX Software Systems - Initial API and implementation
+ * Nokia - adapt to new command framework
*******************************************************************************/
package org.eclipse.cdt.debug.internal.ui.actions;
@@ -16,11 +17,10 @@ import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
import org.eclipse.cdt.utils.ui.controls.ControlFactory;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.debug.core.DebugException;
+import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.ui.IDebugView;
-import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
-import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
@@ -38,15 +38,19 @@ import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.IObjectActionDelegate;
+import org.eclipse.ui.ISources;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.actions.ActionDelegate;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.expressions.IEvaluationContext;
/**
* The delegate of the "Display As Array" action.
*/
-public class CastToArrayActionDelegate extends ActionDelegate implements IObjectActionDelegate {
+public class CastToArrayActionHandler extends AbstractHandler {
protected class CastToArrayDialog extends Dialog {
@@ -227,27 +231,15 @@ public class CastToArrayActionDelegate extends ActionDelegate implements IObject
private IWorkbenchPart fTargetPart = null;
- public CastToArrayActionDelegate() {
+ public CastToArrayActionHandler() {
super();
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, org.eclipse.ui.IWorkbenchPart)
- */
- public void setActivePart( IAction action, IWorkbenchPart targetPart ) {
- fTargetPart = targetPart;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
- */
- public void run( IAction action ) {
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ fTargetPart = HandlerUtil.getActivePartChecked(event);
if ( getCastToArray() == null )
- return;
+ return null;
+
BusyIndicator.showWhile( Display.getCurrent(), new Runnable() {
public void run() {
@@ -269,27 +261,28 @@ public class CastToArrayActionDelegate extends ActionDelegate implements IObject
CDebugUIPlugin.log( getStatus() );
}
}
+
+ return null;
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
- */
- public void selectionChanged( IAction action, ISelection selection ) {
- if ( selection instanceof IStructuredSelection ) {
- Object element = ((IStructuredSelection)selection).getFirstElement();
- if ( element instanceof ICastToArray ) {
- boolean enabled = ((ICastToArray)element).canCastToArray();
- action.setEnabled( enabled );
- if ( enabled ) {
- setCastToArray( (ICastToArray)element );
- return;
- }
- }
- }
- action.setEnabled( false );
- setCastToArray( null );
+ @Override
+ public void setEnabled(Object evaluationContext) {
+ ICastToArray castToArray = getCastToArray(evaluationContext);
+ setBaseEnabled( castToArray != null );
+ setCastToArray(castToArray);
+ }
+
+ private ICastToArray getCastToArray(Object evaluationContext) {
+ if (evaluationContext instanceof IEvaluationContext) {
+ Object s = ((IEvaluationContext) evaluationContext).getVariable(ISources.ACTIVE_MENU_SELECTION_NAME);
+ if (s instanceof IStructuredSelection) {
+ IStructuredSelection ss = (IStructuredSelection)s;
+ if (!ss.isEmpty()) {
+ return (ICastToArray)DebugPlugin.getAdapter(ss.getFirstElement(), ICastToArray.class);
+ }
+ }
+ }
+ return null;
}
protected ICastToArray getCastToArray() {
diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/CastToTypeActionDelegate.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/CastToTypeActionHandler.java
index 4dd86418456..1494871faef 100644
--- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/CastToTypeActionDelegate.java
+++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/CastToTypeActionHandler.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2006 QNX Software Systems and others.
+ * Copyright (c) 2004, 2010 QNX Software 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
@@ -7,19 +7,23 @@
*
* Contributors:
* QNX Software Systems - Initial API and implementation
+ * Nokia - adapt to new command framework
*******************************************************************************/
package org.eclipse.cdt.debug.internal.ui.actions;
import org.eclipse.cdt.debug.core.model.ICastToType;
import org.eclipse.cdt.debug.internal.ui.CDebugImages;
import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.expressions.IEvaluationContext;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.debug.core.DebugException;
+import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.ui.IDebugView;
-import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.IInputValidator;
import org.eclipse.jface.dialogs.InputDialog;
-import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
@@ -27,15 +31,15 @@ import org.eclipse.jface.window.Window;
import org.eclipse.swt.custom.BusyIndicator;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.IObjectActionDelegate;
+import org.eclipse.ui.ISources;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.actions.ActionDelegate;
+import org.eclipse.ui.handlers.HandlerUtil;
/**
* The delegate of the "Cast To Type" action.
*/
-public class CastToTypeActionDelegate extends ActionDelegate implements IObjectActionDelegate {
+public class CastToTypeActionHandler extends AbstractHandler {
static protected class CastToTypeInputValidator implements IInputValidator {
@@ -74,29 +78,18 @@ public class CastToTypeActionDelegate extends ActionDelegate implements IObjectA
private IStatus fStatus = null;
- private IWorkbenchPart fTargetPart = null;
+ private IWorkbenchPart fTargetPart;
- public CastToTypeActionDelegate() {
+ public CastToTypeActionHandler() {
super();
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, org.eclipse.ui.IWorkbenchPart)
- */
- public void setActivePart( IAction action, IWorkbenchPart targetPart ) {
- fTargetPart = targetPart;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
- */
- public void run( IAction action ) {
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ fTargetPart = HandlerUtil.getActivePartChecked(event);
+
if ( getCastToType() == null )
- return;
+ return null;
+
BusyIndicator.showWhile( Display.getCurrent(), new Runnable() {
public void run() {
@@ -118,27 +111,28 @@ public class CastToTypeActionDelegate extends ActionDelegate implements IObjectA
CDebugUIPlugin.log( getStatus() );
}
}
+
+ return null;
}
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
- */
- public void selectionChanged( IAction action, ISelection selection ) {
- if ( selection instanceof IStructuredSelection ) {
- Object element = ((IStructuredSelection)selection).getFirstElement();
- if ( element instanceof ICastToType ) {
- boolean enabled = ((ICastToType)element).canCast();
- action.setEnabled( enabled );
- if ( enabled ) {
- setCastToType( (ICastToType)element );
- return;
- }
- }
- }
- action.setEnabled( false );
- setCastToType( null );
+
+ @Override
+ public void setEnabled(Object evaluationContext) {
+ ICastToType castToType = getCastToType(evaluationContext);
+ setBaseEnabled( castToType != null );
+ setCastToType(castToType);
+ }
+
+ private ICastToType getCastToType(Object evaluationContext) {
+ if (evaluationContext instanceof IEvaluationContext) {
+ Object s = ((IEvaluationContext) evaluationContext).getVariable(ISources.ACTIVE_MENU_SELECTION_NAME);
+ if (s instanceof IStructuredSelection) {
+ IStructuredSelection ss = (IStructuredSelection)s;
+ if (!ss.isEmpty()) {
+ return (ICastToType)DebugPlugin.getAdapter(ss.getFirstElement(), ICastToType.class);
+ }
+ }
+ }
+ return null;
}
protected ICastToType getCastToType() {
diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RestoreDefaultTypeActionDelegate.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RestoreDefaultTypeActionHandler.java
index 71b4ed9dd3c..2bfb645f1f4 100644
--- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RestoreDefaultTypeActionDelegate.java
+++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RestoreDefaultTypeActionHandler.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2006 QNX Software Systems and others.
+ * Copyright (c) 2004, 2010 QNX Software 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
@@ -7,40 +7,34 @@
*
* Contributors:
* QNX Software Systems - Initial API and implementation
+ * Nokia - port to command framework
*******************************************************************************/
package org.eclipse.cdt.debug.internal.ui.actions;
import org.eclipse.cdt.debug.core.model.ICastToType;
import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.expressions.IEvaluationContext;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.debug.core.DebugException;
-import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.custom.BusyIndicator;
import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.IObjectActionDelegate;
-import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.ISources;
import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.actions.ActionDelegate;
/**
* The delegate of the "Restore Default Type" action.
*/
-public class RestoreDefaultTypeActionDelegate extends ActionDelegate implements IObjectActionDelegate {
+public class RestoreDefaultTypeActionHandler extends AbstractHandler {
private ICastToType fCastToType = null;
private IStatus fStatus = null;
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, org.eclipse.ui.IWorkbenchPart)
- */
- public void setActivePart( IAction action, IWorkbenchPart targetPart ) {
- }
-
protected ICastToType getCastToType() {
return fCastToType;
}
@@ -49,14 +43,10 @@ public class RestoreDefaultTypeActionDelegate extends ActionDelegate implements
fCastToType = castToType;
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
- */
- public void run( IAction action ) {
+ public Object execute(ExecutionEvent event) throws ExecutionException {
if ( getCastToType() == null )
- return;
+ return null;
+
BusyIndicator.showWhile( Display.getCurrent(), new Runnable() {
public void run() {
@@ -78,29 +68,30 @@ public class RestoreDefaultTypeActionDelegate extends ActionDelegate implements
CDebugUIPlugin.log( getStatus() );
}
}
+
+ return null;
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
- */
- public void selectionChanged( IAction action, ISelection selection ) {
- if ( selection instanceof IStructuredSelection ) {
- Object element = ((IStructuredSelection)selection).getFirstElement();
- if ( element instanceof ICastToType ) {
- boolean enabled = ((ICastToType)element).isCasted();
- action.setEnabled( enabled );
- if ( enabled ) {
- setCastToType( (ICastToType)element );
- return;
- }
- }
- }
- action.setEnabled( false );
- setCastToType( null );
+ @Override
+ public void setEnabled(Object evaluationContext) {
+ ICastToType castToType = getCastToType(evaluationContext);
+ setBaseEnabled( castToType != null && castToType.isCasted() );
+ setCastToType(castToType);
}
-
+
+ private ICastToType getCastToType(Object evaluationContext) {
+ if (evaluationContext instanceof IEvaluationContext) {
+ Object s = ((IEvaluationContext) evaluationContext).getVariable(ISources.ACTIVE_MENU_SELECTION_NAME);
+ if (s instanceof IStructuredSelection) {
+ IStructuredSelection ss = (IStructuredSelection)s;
+ if (!ss.isEmpty()) {
+ return (ICastToType)DebugPlugin.getAdapter(ss.getFirstElement(), ICastToType.class);
+ }
+ }
+ }
+ return null;
+ }
+
public IStatus getStatus() {
return fStatus;
}

Back to the top