Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 2d56288e4b05aefa9770a21a2d764f9c812a3d9b (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
99
100
101
/*******************************************************************************
 * Copyright (c) 2007, 2010 BMW Car IT, Technische Universitaet Muenchen, and others.
 * 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:
 * BMW Car IT - Initial API and implementation
 * Technische Universitaet Muenchen - Major refactoring and extension
 *******************************************************************************/
package org.eclipse.emf.edapt.history.instantiation.ui;

import org.eclipse.emf.edapt.common.ui.ResizeableDialogBase;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Text;

/**
 * Dialog to enter a Groovy script
 *
 * @author herrmama
 * @author $Author$
 * @version $Rev$
 * @levd.rating RED Rev:
 */
public class ScriptDialog extends ResizeableDialogBase {

	/**
	 * Last script
	 */
	private static String lastScript = ""; //$NON-NLS-1$

	/**
	 * Text widget
	 */
	private Text scriptText;

	/**
	 * Script
	 */
	private String script;

	/**
	 * Constructor
	 */
	public ScriptDialog() {
		super(new Point(640, 480), "Run script", //$NON-NLS-1$
			"This dialog allows to enter a script to be executed."); //$NON-NLS-1$
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	protected Control createDialogArea(Composite parent) {
		parent = (Composite) super.createDialogArea(parent);

		final Composite composite = new Composite(parent, SWT.None);
		composite.setLayoutData(new GridData(GridData.FILL_BOTH));
		final GridLayout layout = new GridLayout(1, false);
		composite.setLayout(layout);

		scriptText = new Text(composite, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL);
		scriptText.setLayoutData(new GridData(GridData.FILL_BOTH));
		scriptText.setText(lastScript);

		return parent;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	protected void okPressed() {
		script = scriptText.getText();
		lastScript = script;
		super.okPressed();
	}

	/**
	 * Get the script
	 *
	 * @return Groovy script
	 */
	public String getScript() {
		return script;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	protected void setShellStyle(int newShellStyle) {
		super.setShellStyle(newShellStyle | SWT.RESIZE);
	}
}

Back to the top