package org.isaacparker.commandrunner;

import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Label;
import org.eclipse.wb.swt.SWTResourceManager;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;

public class CommandExecuteWindow {

	protected Shell shell;
	private Text textCmd;

	/**
	 * Launch the application.
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			CommandExecuteWindow window = new CommandExecuteWindow();
			window.open();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Open the window.
	 */
	public void open() {
		Display display = Display.getDefault();
		createContents();
		shell.open();
		shell.layout();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
	}

	/**
	 * Create contents of the window.
	 */
	protected void createContents() {
		shell = new Shell();
		shell.setSize(450, 300);
		shell.setText("SWT Application");
		
		textCmd = new Text(shell, SWT.BORDER);
		textCmd.addKeyListener(new KeyAdapter() {
			@Override
			public void keyPressed(KeyEvent e) {
				 if(e.keyCode == SWT.CR || e.keyCode == SWT.LF) {
					 System.out.println("Enter pressed");
				 }
			}
		});
		textCmd.setToolTipText("Type your command here");
		textCmd.setBounds(0, 241, 353, 21);
		
		Button btnRun = new Button(shell, SWT.NONE);
		btnRun.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				System.out.println("Run button pressed");
			}
		});
		btnRun.setBounds(359, 237, 75, 25);
		btnRun.setText("Run");
		
		Label lblOutput = new Label(shell, SWT.NONE);
		lblOutput.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
		lblOutput.setBounds(0, 10, 434, 221);
		
		

	}
}
