Skip to main content
summaryrefslogtreecommitdiffstats
blob: 5bb8e00a1f3c9a0134b50b8acbe86962071d70f9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*******************************************************************************
 * Copyright (c) 2008 Nokia 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:
 *     Ken Ryall (Nokia) - initial API and implementation (207231)
 *******************************************************************************/
package org.eclipse.cdt.debug.internal.ui.actions;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.eclipse.cdt.debug.core.model.ICVariable;
import org.eclipse.cdt.debug.internal.ui.CDebugUIUtils;
import org.eclipse.cdt.debug.internal.ui.views.memory.AddMemoryBlocks;
import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.ui.IDebugUIConstants;
import org.eclipse.debug.ui.memory.IMemoryRenderingSite;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PartInitException;

public class ViewMemoryActionDelegate implements IObjectActionDelegate {

	private ICVariable[] variables;

	public ViewMemoryActionDelegate() {}

	public void setActivePart(IAction action, IWorkbenchPart targetPart) {
	}
	
	public void run(IAction action) {
		
		IWorkbenchPage page = CDebugUIPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
		IViewPart newView;
		try {
			newView = page.showView(IDebugUIConstants.ID_MEMORY_VIEW, null, IWorkbenchPage.VIEW_ACTIVATE);			
			IMemoryRenderingSite memSite = (IMemoryRenderingSite) newView;
			new AddMemoryBlocks().addMemoryBlocksForVariables(variables, memSite);
		} catch (ClassCastException e) {
			CDebugUIUtils.openError(ActionMessages.getString("ViewMemoryActionDelegate.ErrorTitle"), ActionMessages.getString("ViewMemoryActionDelegate.CantOpenMemoryView"), e); //$NON-NLS-1$ //$NON-NLS-2$
		} catch (PartInitException e) {
			CDebugUIUtils.openError(ActionMessages.getString("ViewMemoryActionDelegate.ErrorTitle"), ActionMessages.getString("ViewMemoryActionDelegate.CantOpenMemoryView"), e); //$NON-NLS-1$ //$NON-NLS-2$
		} catch (DebugException e) {
			CDebugUIUtils.openError(ActionMessages.getString("ViewMemoryActionDelegate.ErrorTitle"), ActionMessages.getString("ViewMemoryActionDelegate.CantViewMemory"), e); //$NON-NLS-1$ //$NON-NLS-2$
		}
	}

	@SuppressWarnings("unchecked")
	public void selectionChanged(IAction action, ISelection selection) {
		if ( selection instanceof IStructuredSelection ) {
			List<Object> list = new ArrayList<Object>();
			IStructuredSelection ssel = (IStructuredSelection)selection;
			Iterator<Object> i = ssel.iterator();
			while( i.hasNext() ) {
				Object o = i.next();
				if ( o instanceof ICVariable ) {
					action.setEnabled( true );
					list.add( o );
				}
			}
			setVariables( list.toArray( new ICVariable[list.size()] ) );
		}
		else {
			action.setChecked( false );
			action.setEnabled( false );
		}
	}

	protected ICVariable[] getVariables() {
		return variables;
	}

	private void setVariables( ICVariable[] variables ) {
		this.variables = variables;
	}

}

Back to the top