Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: bfaaae2f4693a7f701e1a70374a629adf54fc757 (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
package org.eclipse.papyrus.dev.project.management.dialog;

import org.eclipse.jface.dialogs.IInputValidator;
import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;

/**
 * 
 * This input dialog provides a field to edit and a checkbox
 * 
 */
//TODO move this class in an upper project
public class InputDialogWithCheckBox extends InputDialog {

	/**
	 * the checkbox
	 */
	private Button checkbox;

	/**
	 * the message for the checkbox
	 */
	final private String checkboxMessage;

	/**
	 * the initial state of the checkbox
	 */
	final private boolean checkboxStatus;

	/**
	 * the state of the checkbox when the dialog is closed
	 */
	private boolean finalState;

	/**
	 * 
	 * Constructor.
	 * 
	 * @param parentShell
	 * @param dialogTitle
	 * @param dialogMessage
	 * @param initialValue
	 * @param checkboxMessage
	 * @param checkboxStatus
	 * @param validator
	 */
	public InputDialogWithCheckBox(Shell parentShell, String dialogTitle, String dialogMessage, String initialValue, final String checkboxMessage, final boolean checkboxStatus, final IInputValidator validator) {
		super(parentShell, dialogTitle, dialogMessage, initialValue, validator);
		this.checkboxMessage = checkboxMessage;
		this.checkboxStatus = checkboxStatus;
	}

	/**
	 * 
	 * @see org.eclipse.jface.dialogs.Dialog#createContents(org.eclipse.swt.widgets.Composite)
	 * 
	 * @param parent
	 * @return
	 */
	@Override
	protected Control createContents(Composite parent) {
		Control ctrl = super.createContents(parent);
		checkbox = new Button((Composite)((Composite)ctrl).getChildren()[0], SWT.CHECK);
		checkbox.setText(checkboxMessage);
		checkbox.setSelection(checkboxStatus);
		return ctrl;
	}


	/**
	 * 
	 * @return
	 *         <code>true</code> if the checkbox is checked
	 */
	public boolean isChecked() {
		return this.finalState;
	}

	/**
	 * save the state of the checkbox
	 * 
	 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
	 * 
	 */
	@Override
	protected void okPressed() {
		finalState = this.checkbox.getSelection();
		super.okPressed();
	}
}

Back to the top