Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: f83b547db9eb82ae870811fb61c261ea249fa7e8 (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
/*******************************************************************************
 * Copyright (c) 2009 Conselleria de Infraestructuras y Transporte, Generalitat 
 * de la Comunitat Valenciana . 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: Francisco Javier Cano Muñoz (Prodevelop) – Initial API 
 * implementation.
 *
 ******************************************************************************/
package org.eclipse.papyrus.navigator.actions;

import org.eclipse.jface.action.Action;
import org.eclipse.papyrus.navigator.ModelNavigator;
import org.eclipse.ui.IPropertyListener;

/**
 * Action that removes the prefix that shows the type of the element.
 * 
 * @author <a href="mailto:fjcano@prodevelop.es">Francisco Javier Cano Muñoz</a>
 * 
 */
// fjcano #291192
public class RemoveTypePrefixAction extends Action implements IPropertyListener {

	/**
	 * The {@link MOSKittModelNavigator} this action is attached to.
	 */
	private final ModelNavigator navigator;

	/**
	 * Constructor with {@link MOSKittModelNavigator} parameter.
	 * 
	 * @param commonNavigator
	 */
	public RemoveTypePrefixAction(ModelNavigator commonNavigator) {
		super("Remove type prefix");
		this.navigator = commonNavigator;
		this.setToolTipText("Remove type name prefix");
		init();
	}

	/**
	 * Initializing means setting the initial state of the {@link Action} and adding the action as
	 * an {@link IPropertyListener} to the {@link MOSKittModelNavigator}.
	 */
	private void init() {
		updateRemovePrefixTypesProperty(navigator.isRemovePrefixTypeEnabled());
		navigator.addPropertyListener(this);
	}

	/**
	 * Sets the navigator property to remove the prefix of the types.
	 */
	@Override
	public void run() {
		navigator.setRemovePrefixTypeEnabled(!navigator.isRemovePrefixTypeEnabled());
	}

	/**
	 * Upon a MOSKittModelNavigator.IS_REMOVEPREFIXTYPE_ENABLED_PROPERTY property change, update the
	 * model explorer.
	 */
	public void propertyChanged(Object source, int propId) {
		switch(propId) {
		case ModelNavigator.IS_REMOVEPREFIXTYPE_ENABLED_PROPERTY:
			updateRemovePrefixTypesProperty(((ModelNavigator)source).isRemovePrefixTypeEnabled());
		}
	}

	/**
	 * Update this model explorer.
	 * 
	 * @param removePrefixTypesEnabled
	 */
	private void updateRemovePrefixTypesProperty(boolean removePrefixTypesEnabled) {
		setChecked(removePrefixTypesEnabled);
	}
}

Back to the top