// The MIT License (MIT)
//
// Copyright (c) 2015, 2016 Arian Fornaris
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions: The above copyright notice and this permission
// notice shall be included in all copies or substantial portions of the
// Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
package phasereditor.canvas.ui.editors.grid.editors;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
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.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.wb.swt.SWTResourceManager;

/**
 * @author arian
 *
 */
public class TextDialog extends Dialog {
	private Text _text;
	private String _result;
	private String _initText;
	private String _title;
	private String _msg;
	private Label _msgLabel;

	/**
	 * Create the dialog.
	 * 
	 * @param parentShell
	 */
	public TextDialog(Shell parentShell) {
		super(parentShell);
	}

	/**
	 * Create contents of the dialog.
	 * 
	 * @param parent
	 */
	@Override
	protected Control createDialogArea(Composite parent) {
		Composite container = (Composite) super.createDialogArea(parent);
		GridLayout gridLayout = (GridLayout) container.getLayout();
		gridLayout.marginWidth = 5;
		gridLayout.marginHeight = 5;

		_msgLabel = new Label(container, SWT.NONE);

		_text = new Text(container, SWT.BORDER | SWT.MULTI);
		_text.setTabs(4);
		_text.setFont(SWTResourceManager.getFont("Courier New", _text.getFont().getFontData()[0].getHeight(), SWT.NORMAL));
		_text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

		_text.setText(_initText == null ? "{\n}" : _initText);
		_msgLabel.setText(_msg == null ? "Enter the text:" : _msg);
		return container;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.
	 * Shell)
	 */
	@Override
	protected void configureShell(Shell newShell) {
		super.configureShell(newShell);
		if (_title != null) {
			newShell.setText(_title);
		}
	}

	/**
	 * Create contents of the button bar.
	 * 
	 * @param parent
	 */
	@Override
	protected void createButtonsForButtonBar(Composite parent) {
		createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
		createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
	}

	@Override
	protected void okPressed() {
		_result = _text.getText();
		super.okPressed();
	}

	public String getResult() {
		return _result;
	}

	/**
	 * Return the initial size of the dialog.
	 */
	@Override
	protected Point getInitialSize() {
		return new Point(387, 300);
	}

	public void setInitialText(String initText) {
		_initText = initText;
	}

	/**
	 * @param title
	 *            the title to set
	 */
	public void setTitle(String title) {
		_title = title;
	}

	/**
	 * @param msg
	 */
	public void setMessage(String msg) {
		_msg = msg;
	}

}

@@ -2014,16 +2014,45 @@
 Shell);%0A
+%09%09setShellStyle(SWT.RESIZE);%0A
 %09%7D%0A%0A%09/**
@@ -2463,16 +2463,59 @@
 BORDER %7C
+ SWT.H_SCROLL %7C SWT.V_SCROLL %7C SWT.CANCEL %7C
  SWT.MUL
@@ -3748,16 +3748,16 @@
 int(
-387, 300
+571, 443
 );%0A%09

set text dialog scrollable and resizable.