Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: f4299461b8486765b17ffdf52636d85bf8041fed (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
/*****************************************************************************
 * Copyright (c) 2014 CEA LIST.
 *
 * 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:
 *  CEA LIST - Initial API and implementation
 *****************************************************************************/
package org.eclipse.papyrusrt.umlrt.tooling.ui.widgets;

import org.eclipse.emf.common.command.Command;
import org.eclipse.papyrus.infra.properties.ui.modelelement.ModelElement;
import org.eclipse.papyrus.infra.properties.ui.widgets.AbstractPropertyEditor;
import org.eclipse.papyrusrt.umlrt.core.utils.RTPortKindEnum;
import org.eclipse.papyrusrt.umlrt.core.utils.RTPortUtils;
import org.eclipse.papyrusrt.umlrt.profile.UMLRealTime.RTPort;
import org.eclipse.papyrusrt.umlrt.tooling.ui.modelelement.RTStereotypeModelElement;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.uml2.uml.Port;

/**
 * Specific EnumRadio that can have read only status only on some of the radio buttons
 */
public class PortRTKindPropertyEditor extends AbstractPropertyEditor {

	protected PortRTKindValueEditor kindValueEditor;

	protected int numColumns = -1;

	/**
	 * Constructor.
	 *
	 * @param parent
	 *            The composite in which the widget will be displayed
	 * @param style
	 *            The style for the widget
	 */
	public PortRTKindPropertyEditor(Composite parent, int style) {
		super(new PortRTKindValueEditor(parent, style));
		kindValueEditor = (PortRTKindValueEditor) valueEditor;
	}

	/**
	 * Applies the readOnly state to the editor
	 *
	 * @param readOnly
	 *            Indicates if this widget should be read-only
	 */
	protected void applyReadOnly(boolean readOnly) {
		super.applyReadOnly(readOnly);
		if (!readOnly) {
			// should be writable, but check for specific non executable commands
			ModelElement element = input.getModelElement(propertyPath);
			if (element instanceof RTStereotypeModelElement && ((RTStereotypeModelElement) element).getSource() instanceof RTPort) {
				for( RTPortKindEnum enumValue : RTPortKindEnum.values()) {
					Port port = ((RTPort) ((RTStereotypeModelElement) element).getSource()).getBase_Port();
					Command command = RTPortUtils.getChangeKindCommand(port, enumValue, true);
					boolean isEditable = command.canExecute();
					kindValueEditor.setReadOnly(enumValue, isEditable);
				}
			}
		}
	}

	/**
	 * Sets the maximum number of columns for this editor. The radio values
	 * will be distributed according to this number
	 *
	 * @param numColumns
	 */
	public void setNumColumns(int numColumns) {
		this.numColumns = numColumns;
		kindValueEditor.setNumColumns(numColumns);
	}

	/**
	 * Return the maximum number of columns for this editor
	 *
	 * @return
	 * 		The number of columns for this editor
	 */
	public int getNumColumns() {
		return numColumns;
	}

	@Override
	protected void doBinding() {
		kindValueEditor.setProviders(input.getContentProvider(propertyPath), input.getLabelProvider(propertyPath));
		super.doBinding();
	}

}

Back to the top