1 | package de.ugoe.cs.quest.ui.swt;
|
---|
2 |
|
---|
3 | import org.eclipse.swt.widgets.Composite;
|
---|
4 |
|
---|
5 | import org.eclipse.swt.SWT;
|
---|
6 | import org.eclipse.swt.widgets.Button;
|
---|
7 | import org.eclipse.swt.widgets.FileDialog;
|
---|
8 | import org.eclipse.swt.widgets.List;
|
---|
9 | import org.eclipse.swt.widgets.MessageBox;
|
---|
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.quest.ui.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 | *
|
---|
25 | * @param parent
|
---|
26 | * @param style
|
---|
27 | */
|
---|
28 | public SequencesTabComposite(Composite parent, int style) {
|
---|
29 | super(parent, style);
|
---|
30 | createContents();
|
---|
31 | }
|
---|
32 |
|
---|
33 | private void createContents() {
|
---|
34 | setLayout(new GridLayout(5, false));
|
---|
35 |
|
---|
36 | sequenceList = new List(this, SWT.BORDER | SWT.V_SCROLL | SWT.MULTI);
|
---|
37 | sequenceList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 5, 1));
|
---|
38 | sequenceList.setItems(new String[] { });
|
---|
39 |
|
---|
40 | Button btnEdit = new Button(this, SWT.NONE);
|
---|
41 | btnEdit.addSelectionListener(new SelectionAdapter() {
|
---|
42 | @Override
|
---|
43 | public void widgetSelected(SelectionEvent e) {
|
---|
44 | String[] selectedSequences = sequenceList.getSelection();
|
---|
45 | if (selectedSequences.length == 0) {
|
---|
46 | SWTHelpers.noSelectionError(getShell());
|
---|
47 | }
|
---|
48 | else if (selectedSequences.length > 1) {
|
---|
49 | MessageBox messageBox = new MessageBox(getShell(), SWT.ERROR);
|
---|
50 | messageBox.setMessage("Only one sequence can be edited at a time!");
|
---|
51 | messageBox.setText("Error");
|
---|
52 | messageBox.open();
|
---|
53 | }
|
---|
54 | else {
|
---|
55 | SequencesDialog sequencesDialog = new SequencesDialog(getShell(), SWT.NONE);
|
---|
56 | sequencesDialog.open(selectedSequences[0]);
|
---|
57 | }
|
---|
58 | }
|
---|
59 | });
|
---|
60 | btnEdit.setText("Edit");
|
---|
61 |
|
---|
62 | Button btnDelete = new Button(this, SWT.NONE);
|
---|
63 | btnDelete.addSelectionListener(new SelectionAdapter() {
|
---|
64 | @Override
|
---|
65 | public void widgetSelected(SelectionEvent e) {
|
---|
66 | if (SWTHelpers.deleteSelectedFromStorage(sequenceList)) {
|
---|
67 | updateSequenceList();
|
---|
68 | }
|
---|
69 | else {
|
---|
70 | SWTHelpers.noSelectionError(getShell());
|
---|
71 | }
|
---|
72 | }
|
---|
73 | });
|
---|
74 | btnDelete.setText("Delete");
|
---|
75 |
|
---|
76 | Button btnReplay = new Button(this, SWT.NONE);
|
---|
77 | btnReplay.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 | }
|
---|
84 | else {
|
---|
85 | StringBuilder commandString = new StringBuilder("generateReplayfile ");
|
---|
86 | FileDialog fileDialog = new FileDialog(getShell());
|
---|
87 | String filename = fileDialog.open();
|
---|
88 | commandString.append(filename + " ");
|
---|
89 | for (String selected : selectedSequences) {
|
---|
90 | commandString.append(selected + " ");
|
---|
91 | }
|
---|
92 | CommandExecuter.getInstance().exec(commandString.toString().trim());
|
---|
93 | }
|
---|
94 | }
|
---|
95 | });
|
---|
96 | btnReplay.setText("Replay");
|
---|
97 |
|
---|
98 | Button btnTrainModel = new Button(this, SWT.NONE);
|
---|
99 | btnTrainModel.addSelectionListener(new SelectionAdapter() {
|
---|
100 | @Override
|
---|
101 | public void widgetSelected(SelectionEvent e) {
|
---|
102 | String[] selectedSequences = sequenceList.getSelection();
|
---|
103 | if (selectedSequences.length == 0) {
|
---|
104 | SWTHelpers.noSelectionError(getShell());
|
---|
105 | }
|
---|
106 | else {
|
---|
107 | TrainModelDialog trainDialog = new TrainModelDialog(getShell(), SWT.NONE);
|
---|
108 | trainDialog.setSequenceNames(selectedSequences);
|
---|
109 | trainDialog.open();
|
---|
110 | }
|
---|
111 | }
|
---|
112 | });
|
---|
113 | btnTrainModel.setText("Train Model");
|
---|
114 |
|
---|
115 | Button btnParse = new Button(this, SWT.NONE);
|
---|
116 | btnParse.addSelectionListener(new SelectionAdapter() {
|
---|
117 | @Override
|
---|
118 | public void widgetSelected(SelectionEvent e) {
|
---|
119 | // TODO implement parsing of sequences
|
---|
120 | MessageBox messageBox = new MessageBox(getShell(), SWT.ICON_INFORMATION);
|
---|
121 | messageBox.setText("Not implemented!");
|
---|
122 | messageBox.setMessage("Sorry! This functionality has not been implemented yet!");
|
---|
123 | messageBox.open();
|
---|
124 | }
|
---|
125 | });
|
---|
126 | btnParse.setText("Parse");
|
---|
127 | }
|
---|
128 |
|
---|
129 | public void updateSequenceList() {
|
---|
130 | sequenceList.removeAll();
|
---|
131 | for (String sequencesName : GlobalDataContainer.getInstance().getAllSequencesNames()) {
|
---|
132 | sequenceList.add(sequencesName);
|
---|
133 | }
|
---|
134 | }
|
---|
135 |
|
---|
136 | @Override
|
---|
137 | protected void checkSubclass() {
|
---|
138 | // Disable the check that prevents subclassing of SWT components
|
---|
139 | }
|
---|
140 |
|
---|
141 | }
|
---|