Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: e17db6b6fee7197a253551fb274c62c713238188 (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
/*****************************************************************************
 * 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.papyrus.infra.widgets.editors.EnumRadio;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;

/**
 * Value Editor specific to the PortRTKind.
 */
public class PortRTKindValueEditor extends EnumRadio {

	public PortRTKindValueEditor(Composite parent, int style, String label) {
		super(parent, style, label);
	}

	public PortRTKindValueEditor(Composite parent, int style) {
		super(parent, style);
	}

	@Override
	public void setReadOnly(boolean readOnly) {
		for (Button button : values.keySet()) {
			if (readOnly) {
				if (!button.isDisposed()) {
					button.setEnabled(false);
				}
			}
		}
		if (!buttonsArea.isDisposed()) {
			buttonsArea.setEnabled(!readOnly);
		}
	}

	/**
	 * Sets the read only state for a particular value of the enum radio. if the button is the selected one, no change will be applied to it
	 * 
	 * @param value
	 *            the value for which read only status should be applied
	 * @param readOnly
	 *            <code>true</code> if the element should be set read only
	 */
	public void setReadOnly(Object value, boolean readOnly) {
		for (Button button : values.keySet()) {
			// even if not read only, we should check each value if it has some specifics that apply and make it not enable
			Object object = values.get(button);
			if (object == value) {
				if (!button.isDisposed()) {
					button.setEnabled(readOnly);
				}

			}
		}
	}

	@Override
	public boolean isReadOnly() {
		for (Button button : values.keySet()) {
			if (!button.isDisposed() && button.isEnabled()) {
				return false;
			}
		}
		return true;
	}
}

Back to the top