1 | package de.ugoe.cs.eventbench.swt;
|
---|
2 |
|
---|
3 | import org.eclipse.swt.widgets.Composite;
|
---|
4 |
|
---|
5 |
|
---|
6 | import org.eclipse.swt.SWT;
|
---|
7 | import org.eclipse.swt.widgets.Button;
|
---|
8 | import org.eclipse.swt.widgets.FileDialog;
|
---|
9 | import org.eclipse.swt.widgets.List;
|
---|
10 | import org.eclipse.swt.layout.GridLayout;
|
---|
11 | import org.eclipse.swt.layout.GridData;
|
---|
12 | import org.eclipse.swt.events.SelectionAdapter;
|
---|
13 | import org.eclipse.swt.events.SelectionEvent;
|
---|
14 |
|
---|
15 | import de.ugoe.cs.eventbench.data.GlobalDataContainer;
|
---|
16 | import de.ugoe.cs.util.console.CommandExecuter;
|
---|
17 |
|
---|
18 | public class SequencesTabComposite extends Composite {
|
---|
19 |
|
---|
20 | protected List sequenceList;
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * Create the composite.
|
---|
24 | * @param parent
|
---|
25 | * @param style
|
---|
26 | */
|
---|
27 | public SequencesTabComposite(Composite parent, int style) {
|
---|
28 | super(parent, style);
|
---|
29 | createContents();
|
---|
30 | }
|
---|
31 |
|
---|
32 | private void createContents() {
|
---|
33 | setLayout(new GridLayout(5, false));
|
---|
34 |
|
---|
35 | sequenceList = new List(this, SWT.BORDER | SWT.V_SCROLL | SWT.MULTI);
|
---|
36 | sequenceList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 5, 1));
|
---|
37 | sequenceList.setItems(new String[] {});
|
---|
38 |
|
---|
39 | Button btnEdit = new Button(this, SWT.NONE);
|
---|
40 | btnEdit.setText("Edit");
|
---|
41 |
|
---|
42 | Button btnDelete = new Button(this, SWT.NONE);
|
---|
43 | btnDelete.addSelectionListener(new SelectionAdapter() {
|
---|
44 | @Override
|
---|
45 | public void widgetSelected(SelectionEvent e) {
|
---|
46 | if( SWTHelpers.deleteSelectedFromStorage(sequenceList)) {
|
---|
47 | updateSequenceList();
|
---|
48 | } else {
|
---|
49 | SWTHelpers.noSelectionError(getShell());
|
---|
50 | }
|
---|
51 | }
|
---|
52 | });
|
---|
53 | btnDelete.setText("Delete");
|
---|
54 |
|
---|
55 | Button btnReplay = new Button(this, SWT.NONE);
|
---|
56 | btnReplay.addSelectionListener(new SelectionAdapter() {
|
---|
57 | @Override
|
---|
58 | public void widgetSelected(SelectionEvent e) {
|
---|
59 | String[] selectedSequences = sequenceList.getSelection();
|
---|
60 | if( selectedSequences.length==0 ) {
|
---|
61 | SWTHelpers.noSelectionError(getShell());
|
---|
62 | } else {
|
---|
63 | StringBuilder commandString = new StringBuilder("generateReplayfile ");
|
---|
64 | FileDialog fileDialog = new FileDialog(getShell());
|
---|
65 | String filename = fileDialog.open();
|
---|
66 | commandString.append(filename + " ");
|
---|
67 | for( String selected : selectedSequences ) {
|
---|
68 | commandString.append(selected + " ");
|
---|
69 | }
|
---|
70 | CommandExecuter.getInstance().exec(commandString.toString().trim());
|
---|
71 | }
|
---|
72 | }
|
---|
73 | });
|
---|
74 | btnReplay.setText("Replay");
|
---|
75 |
|
---|
76 | Button btnTrainModel = new Button(this, SWT.NONE);
|
---|
77 | btnTrainModel.addSelectionListener(new SelectionAdapter() {
|
---|
78 | @Override
|
---|
79 | public void widgetSelected(SelectionEvent e) {
|
---|
80 | String[] selectedSequences = sequenceList.getSelection();
|
---|
81 | if( selectedSequences.length==0 ) {
|
---|
82 | SWTHelpers.noSelectionError(getShell());
|
---|
83 | } else {
|
---|
84 | TrainModelDialog trainDialog = new TrainModelDialog(getShell(), SWT.NONE);
|
---|
85 | trainDialog.setSequenceNames(selectedSequences);
|
---|
86 | trainDialog.open();
|
---|
87 | }
|
---|
88 | }
|
---|
89 | });
|
---|
90 | btnTrainModel.setText("Train Model");
|
---|
91 |
|
---|
92 | Button btnParse = new Button(this, SWT.NONE);
|
---|
93 | btnParse.setText("Parse");
|
---|
94 | }
|
---|
95 |
|
---|
96 | public void updateSequenceList() {
|
---|
97 | sequenceList.removeAll();
|
---|
98 | for( String sequencesName : GlobalDataContainer.getInstance().getAllSequencesNames() ) {
|
---|
99 | sequenceList.add(sequencesName);
|
---|
100 | }
|
---|
101 | }
|
---|
102 |
|
---|
103 | @Override
|
---|
104 | protected void checkSubclass() {
|
---|
105 | // Disable the check that prevents subclassing of SWT components
|
---|
106 | }
|
---|
107 |
|
---|
108 | }
|
---|