Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 420092cd0564ef8b14deaf72901e96b4241003c2 (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
89
90
91
92
93
94
95
96
97
98
99
100
/*******************************************************************************
 * 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
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

package org.eclipse.debug.internal.ui.views.memory;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.debug.core.model.IMemoryBlockRetrieval;
import org.eclipse.debug.internal.ui.DebugUIPlugin;
import org.eclipse.debug.internal.ui.actions.ActionMessages;
import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.debug.ui.actions.IAddMemoryBlocksTarget;
import org.eclipse.debug.ui.memory.IMemoryRenderingSite;

/**
 * This is the retargettable add memory block action in the Memory View. All
 * AddMemoryBlock actions in the view will use this action to make sure that
 * clients can override the "Add Memory Monitor" dialog.
 *
 */
public class RetargetAddMemoryBlockAction extends AddMemoryBlockAction {

	public RetargetAddMemoryBlockAction(IMemoryRenderingSite site) {
		super(site);
	}

	public RetargetAddMemoryBlockAction(IMemoryRenderingSite site, boolean addDefaultRenderings) {
		super(site, addDefaultRenderings);
	}

	public RetargetAddMemoryBlockAction(String text, int style, IMemoryRenderingSite site) {
		super(text, style, site);
	}

	@Override
	public void run() {
		// get current selection from Debug View
		Object debugContext = DebugUITools.getPartDebugContext(fSite.getSite());
		IAddMemoryBlocksTarget target = getAddMemoryBlocksTarget(debugContext);

		if (target != null) {
			try {
				if (target.supportsAddMemoryBlocks(getMemoryView())) {
					target.addMemoryBlocks(getMemoryView(), getMemoryView().getSite().getSelectionProvider().getSelection());
				} else
					super.run();
			} catch (CoreException e) {
				DebugUIPlugin.errorDialog(DebugUIPlugin.getShell(), ActionMessages.RetargetAddMemoryBlockAction_0, ActionMessages.RetargetAddMemoryBlockAction_1, e);
			}
		} else {
			super.run();
		}
	}

	@Override
	protected void updateAction(Object debugContext) {

		try {
			IAddMemoryBlocksTarget target = getAddMemoryBlocksTarget(debugContext);

			if (target != null) {
				if (target.supportsAddMemoryBlocks(getMemoryView())) {
					if (getMemoryView().getSite().getSelectionProvider() != null)
						setEnabled(target.canAddMemoryBlocks(getMemoryView(), getMemoryView().getSite().getSelectionProvider().getSelection()));
					else
						super.updateAction(debugContext);
				} else
					super.updateAction(debugContext);
			} else {
				super.updateAction(debugContext);
			}
		} catch (CoreException e) {
			DebugUIPlugin.log(e);
		}
	}

	private IAddMemoryBlocksTarget getAddMemoryBlocksTarget(Object debugContext) {
		IMemoryBlockRetrieval standardMemRetrieval = MemoryViewUtil.getMemoryBlockRetrieval(debugContext);

		if (standardMemRetrieval == null)
			return null;

		IAddMemoryBlocksTarget target = null;

		if (standardMemRetrieval instanceof IAddMemoryBlocksTarget) {
			target = (IAddMemoryBlocksTarget) standardMemRetrieval;
		} else if (standardMemRetrieval instanceof IAdaptable) {
			target = ((IAdaptable) standardMemRetrieval).getAdapter(IAddMemoryBlocksTarget.class);
		}
		return target;
	}
}

Back to the top