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