Skip to main content
summaryrefslogtreecommitdiffstats
blob: 1ed415f6f1a2be49b23c77585ec9484b35a92701 (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
/*
 *(c) Copyright QNX Software Systems Ltd. 2002.
 * All Rights Reserved.
 * 
 */

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

import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.text.ITextOperationTarget;
import org.eclipse.ui.texteditor.IUpdate;

/**
 * Enter type comment.
 * 
 * @since Jun 12, 2003
 */
public class MemoryViewAction extends Action implements IUpdate
{
	/** The text operation code */
	private int fOperationCode = -1;
	/** The text operation target */
	private ITextOperationTarget fOperationTarget;
	/** The text operation target provider */
	private IAdaptable fTargetProvider;

	public MemoryViewAction( ITextOperationTarget target, int operationCode )
	{
		super();
		fOperationCode = operationCode;
		fOperationTarget = target;
		update();
	}

	public MemoryViewAction( IAdaptable targetProvider, int operationCode )
	{
		super();
		fTargetProvider = targetProvider;
		fOperationCode = operationCode;
		update();
	}

	/**
	 * The <code>TextOperationAction</code> implementation of this 
	 * <code>IUpdate</code> method discovers the operation through the current
	 * editor's <code>ITextOperationTarget</code> adapter, and sets the
	 * enabled state accordingly.
	 */
	public void update()
	{
		if ( fTargetProvider != null && fOperationCode != -1 )
		{
			ITextOperationTarget target = getTextOperationTarget();
			boolean isEnabled = ( target != null && target.canDoOperation( fOperationCode ) );
			setEnabled( isEnabled );
		}
	}

	/**
	 * The <code>TextOperationAction</code> implementation of this 
	 * <code>IAction</code> method runs the operation with the current
	 * operation code.
	 */
	public void run()
	{
		ITextOperationTarget target = getTextOperationTarget();
		if ( fOperationCode != -1 && target != null )
			target.doOperation( fOperationCode );
	}

	private ITextOperationTarget getTextOperationTarget()
	{
		if ( fOperationTarget == null )
		{
			if ( fTargetProvider != null )
				return (ITextOperationTarget)fTargetProvider.getAdapter( ITextOperationTarget.class ); 
		}
		return fOperationTarget;
	}
}

Back to the top