Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 1ff5a94c6de6c438524e248042f40beb647ffa0c (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
/*******************************************************************************
 * Copyright (c) 2008, 2010 Wind River Systems, Inc. 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:
 *     Wind River Systems - initial API and implementation
 *******************************************************************************/
package org.eclipse.cdt.dsf.debug.internal.ui.disassembly.actions;

import org.eclipse.cdt.dsf.debug.internal.ui.disassembly.provisional.IDisassemblyPart;
import org.eclipse.core.runtime.Assert;
import org.eclipse.jface.action.Action;
import org.eclipse.ui.IPropertyListener;
import org.eclipse.ui.texteditor.IUpdate;

public abstract class AbstractDisassemblyAction extends Action implements IUpdate, IPropertyListener {

	protected IDisassemblyPart fDisassemblyPart;

	AbstractDisassemblyAction() {
	}

	/**
	 * Create a disassembly action.
	 * 
	 * @param disassemblyPart
	 */
	public AbstractDisassemblyAction(IDisassemblyPart disassemblyPart) {
		Assert.isLegal(disassemblyPart != null);
		fDisassemblyPart= disassemblyPart;
		fDisassemblyPart.addPropertyListener(this);
	}

	/**
	 * Create a disassembly action.
	 * 
	 * @param disassemblyPart
	 * @param style
	 *            one of <code>AS_PUSH_BUTTON</code>,
	 *            <code>AS_CHECK_BOX</code>, <code>AS_DROP_DOWN_MENU</code>,
	 *            <code>AS_RADIO_BUTTON</code>, and
	 *            <code>AS_UNSPECIFIED</code>.
	 */
	public AbstractDisassemblyAction(IDisassemblyPart disassemblyPart, int style) {
		super(null, style);
		Assert.isLegal(disassemblyPart != null);
		fDisassemblyPart= disassemblyPart;
		fDisassemblyPart.addPropertyListener(this);
	}


	/**
	 * @return the disassembly part
	 */
	public final IDisassemblyPart getDisassemblyPart() {
		return fDisassemblyPart;
	}
	
	/*
	 * @see org.eclipse.jface.action.Action#run()
	 */
	@Override
	public abstract void run();

	@Override
	public void update() {
		boolean enabled= fDisassemblyPart == null || fDisassemblyPart.isConnected();
		setEnabled(enabled);
	}
	
	/*
	 * @see org.eclipse.ui.IPropertyListener#propertyChanged(java.lang.Object, int)
	 */
	@Override
	public void propertyChanged(Object source, int propId) {
		if (source == fDisassemblyPart && (propId & 0x500) != 0) {
			update();
		}
	}
}

Back to the top