Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 6350a4e5b44247801469f12690f5770d87e46421 (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
96
97
98
/*****************************************************************************
 * Copyright (c) 2011 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:
 *  Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
 *****************************************************************************/
package org.eclipse.papyrus.views.properties.widgets;

import org.eclipse.papyrus.views.properties.Activator;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;


/**
 * A Widget for editing Booleans. The widget is a button with two states.
 * The button can have either an image or a text
 *
 * @author Camille Letavernier
 */
public class BooleanToggle extends AbstractPropertyEditor {

	private org.eclipse.papyrus.infra.widgets.editors.BooleanToggle toggle;

	private String imagePath;

	private String text;

	/**
	 *
	 * Constructor.
	 *
	 * @param parent
	 *            The parent in which the widget will be created
	 * @param style
	 */
	public BooleanToggle(Composite parent, int style) {
		toggle = createBooleanToggle(parent, style);
		setEditor(toggle);
	}

	/**
	 * Creates the boolean toggle.
	 *
	 * @param parent
	 *            The composite in which the widget will be displayed
	 * @param style
	 *            The style for the widget
	 * @return the boolean toggle.
	 */
	protected org.eclipse.papyrus.infra.widgets.editors.BooleanToggle createBooleanToggle(Composite parent, int style) {
		return new org.eclipse.papyrus.infra.widgets.editors.BooleanToggle(parent, style);
	}

	/**
	 * Sets this button's text
	 *
	 * @param text
	 */
	public void setText(String text) {
		toggle.setText(this.text = text);
	}

	/**
	 * Return this button's text
	 *
	 * @return this button's text
	 */
	public String getText() {
		return text;
	}

	/**
	 * Sets this button's image
	 *
	 * @param imagePath
	 *            The path to the image, in the form /<plug-in>/<path>
	 */
	public void setImage(String imagePath) {
		this.imagePath = imagePath;
		Image image = Activator.getDefault().getImageFromPlugin(imagePath);
		toggle.setImage(image);
	}

	/**
	 * Returns the path to this editor's image
	 *
	 * @return
	 *         The path to this editor's image
	 */
	public String getImage() {
		return imagePath;
	}
}

Back to the top