1 | package de.ugoe.cs.eventbench.swt;
|
---|
2 |
|
---|
3 | import org.eclipse.swt.SWT;
|
---|
4 | import org.eclipse.swt.widgets.Text;
|
---|
5 | import org.eclipse.swt.widgets.Label;
|
---|
6 | import org.eclipse.swt.widgets.Composite;
|
---|
7 | import org.eclipse.swt.widgets.Button;
|
---|
8 | import org.eclipse.swt.layout.GridLayout;
|
---|
9 | import org.eclipse.swt.layout.GridData;
|
---|
10 | import org.eclipse.swt.events.SelectionAdapter;
|
---|
11 | import org.eclipse.swt.events.SelectionEvent;
|
---|
12 |
|
---|
13 | import org.eclipse.swt.events.KeyAdapter;
|
---|
14 | import org.eclipse.swt.events.KeyEvent;
|
---|
15 |
|
---|
16 |
|
---|
17 | import de.ugoe.cs.util.console.CommandExecuter;
|
---|
18 |
|
---|
19 | /**
|
---|
20 | * <p>
|
---|
21 | * Implements the composite for the console tab in the applications main window.
|
---|
22 | * </p>
|
---|
23 | *
|
---|
24 | * @author Steffen Herbold
|
---|
25 | * @version 1.0
|
---|
26 | */
|
---|
27 | public class ConsoleTabComposite extends Composite {
|
---|
28 |
|
---|
29 | protected Text textCommand;
|
---|
30 |
|
---|
31 | protected Text textConsoleOutput;
|
---|
32 |
|
---|
33 | /**
|
---|
34 | * Create the composite.
|
---|
35 | * @param parent
|
---|
36 | * @param style
|
---|
37 | */
|
---|
38 | public ConsoleTabComposite(Composite parent, int style) {
|
---|
39 | super(parent, style);
|
---|
40 | createContents();
|
---|
41 | }
|
---|
42 |
|
---|
43 | private void createContents() {
|
---|
44 | setLayout(new GridLayout(3, false));
|
---|
45 |
|
---|
46 | Label lblCommand = new Label(this, SWT.NONE);
|
---|
47 | lblCommand.setText("Command:");
|
---|
48 |
|
---|
49 | textCommand = new Text(this, SWT.BORDER);
|
---|
50 | textCommand.addKeyListener(new KeyAdapter() {
|
---|
51 | @Override
|
---|
52 | public void keyReleased(KeyEvent e) {
|
---|
53 | if( e.keyCode==SWT.CR ) {
|
---|
54 | executeCommand();
|
---|
55 | }
|
---|
56 | }
|
---|
57 | });
|
---|
58 | GridData gd_textCommand = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
|
---|
59 | gd_textCommand.widthHint = 304;
|
---|
60 | textCommand.setLayoutData(gd_textCommand);
|
---|
61 |
|
---|
62 | Button btnEnter = new Button(this, SWT.NONE);
|
---|
63 | btnEnter.addSelectionListener(new SelectionAdapter() {
|
---|
64 | @Override
|
---|
65 | public void widgetSelected(SelectionEvent e) {
|
---|
66 | executeCommand();
|
---|
67 | }
|
---|
68 | });
|
---|
69 | btnEnter.setText("Enter");
|
---|
70 |
|
---|
71 | textConsoleOutput = new Text(this, SWT.BORDER | SWT.READ_ONLY | SWT.H_SCROLL | SWT.V_SCROLL | SWT.CANCEL);
|
---|
72 | GridData gd_textConsoleOutput = new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1);
|
---|
73 | gd_textConsoleOutput.heightHint = 102;
|
---|
74 | gd_textConsoleOutput.widthHint = 456;
|
---|
75 | textConsoleOutput.setLayoutData(gd_textConsoleOutput);
|
---|
76 | }
|
---|
77 |
|
---|
78 | private void executeCommand() {
|
---|
79 | String command = textCommand.getText().trim();
|
---|
80 | CommandExecuter.getInstance().exec(command);
|
---|
81 | textCommand.setText("");
|
---|
82 | }
|
---|
83 |
|
---|
84 | @Override
|
---|
85 | protected void checkSubclass() {
|
---|
86 | // Disable the check that prevents subclassing of SWT components
|
---|
87 | }
|
---|
88 |
|
---|
89 | }
|
---|