1 | // Copyright 2012 Georg-August-Universität Göttingen, Germany
|
---|
2 | //
|
---|
3 | // Licensed under the Apache License, Version 2.0 (the "License");
|
---|
4 | // you may not use this file except in compliance with the License.
|
---|
5 | // You may obtain a copy of the License at
|
---|
6 | //
|
---|
7 | // http://www.apache.org/licenses/LICENSE-2.0
|
---|
8 | //
|
---|
9 | // Unless required by applicable law or agreed to in writing, software
|
---|
10 | // distributed under the License is distributed on an "AS IS" BASIS,
|
---|
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
12 | // See the License for the specific language governing permissions and
|
---|
13 | // limitations under the License.
|
---|
14 |
|
---|
15 | package de.ugoe.cs.autoquest.ui.swt;
|
---|
16 |
|
---|
17 | import org.eclipse.swt.widgets.Composite;
|
---|
18 |
|
---|
19 | import java.util.Collections;
|
---|
20 | import java.util.LinkedList;
|
---|
21 |
|
---|
22 | import org.eclipse.swt.SWT;
|
---|
23 | import org.eclipse.swt.widgets.Button;
|
---|
24 | import org.eclipse.swt.widgets.FileDialog;
|
---|
25 | import org.eclipse.swt.widgets.List;
|
---|
26 | import org.eclipse.swt.widgets.MessageBox;
|
---|
27 | import org.eclipse.swt.layout.GridLayout;
|
---|
28 | import org.eclipse.swt.layout.GridData;
|
---|
29 | import org.eclipse.swt.events.SelectionAdapter;
|
---|
30 | import org.eclipse.swt.events.SelectionEvent;
|
---|
31 |
|
---|
32 | import de.ugoe.cs.autoquest.SequenceInstanceOf;
|
---|
33 | import de.ugoe.cs.util.console.CommandExecuter;
|
---|
34 | import de.ugoe.cs.util.console.GlobalDataContainer;
|
---|
35 |
|
---|
36 | public class SequencesTabComposite extends Composite {
|
---|
37 |
|
---|
38 | protected List sequenceList;
|
---|
39 |
|
---|
40 | /**
|
---|
41 | * Create the composite.
|
---|
42 | *
|
---|
43 | * @param parent
|
---|
44 | * @param style
|
---|
45 | */
|
---|
46 | public SequencesTabComposite(Composite parent, int style) {
|
---|
47 | super(parent, style);
|
---|
48 | createContents();
|
---|
49 | }
|
---|
50 |
|
---|
51 | private void createContents() {
|
---|
52 | setLayout(new GridLayout(5, false));
|
---|
53 |
|
---|
54 | sequenceList = new List(this, SWT.BORDER | SWT.V_SCROLL | SWT.MULTI);
|
---|
55 | sequenceList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 5, 1));
|
---|
56 | sequenceList.setItems(new String[] { });
|
---|
57 |
|
---|
58 | Button btnEdit = new Button(this, SWT.NONE);
|
---|
59 | btnEdit.addSelectionListener(new SelectionAdapter() {
|
---|
60 | @Override
|
---|
61 | public void widgetSelected(SelectionEvent e) {
|
---|
62 | String[] selectedSequences = sequenceList.getSelection();
|
---|
63 | if (selectedSequences.length == 0) {
|
---|
64 | SWTHelpers.noSelectionError(getShell());
|
---|
65 | }
|
---|
66 | else if (selectedSequences.length > 1) {
|
---|
67 | MessageBox messageBox = new MessageBox(getShell(), SWT.ERROR);
|
---|
68 | messageBox.setMessage("Only one sequence can be edited at a time!");
|
---|
69 | messageBox.setText("Error");
|
---|
70 | messageBox.open();
|
---|
71 | }
|
---|
72 | else {
|
---|
73 | SequencesDialog sequencesDialog = new SequencesDialog(getShell(), SWT.NONE);
|
---|
74 | sequencesDialog.open(selectedSequences[0]);
|
---|
75 | }
|
---|
76 | }
|
---|
77 | });
|
---|
78 | btnEdit.setText("Edit");
|
---|
79 |
|
---|
80 | Button btnDelete = new Button(this, SWT.NONE);
|
---|
81 | btnDelete.addSelectionListener(new SelectionAdapter() {
|
---|
82 | @Override
|
---|
83 | public void widgetSelected(SelectionEvent e) {
|
---|
84 | if (SWTHelpers.deleteSelectedFromStorage(sequenceList)) {
|
---|
85 | updateSequenceList();
|
---|
86 | }
|
---|
87 | else {
|
---|
88 | SWTHelpers.noSelectionError(getShell());
|
---|
89 | }
|
---|
90 | }
|
---|
91 | });
|
---|
92 | btnDelete.setText("Delete");
|
---|
93 |
|
---|
94 | Button btnReplay = new Button(this, SWT.NONE);
|
---|
95 | btnReplay.addSelectionListener(new SelectionAdapter() {
|
---|
96 | @Override
|
---|
97 | public void widgetSelected(SelectionEvent e) {
|
---|
98 | String[] selectedSequences = sequenceList.getSelection();
|
---|
99 | if (selectedSequences.length == 0) {
|
---|
100 | SWTHelpers.noSelectionError(getShell());
|
---|
101 | }
|
---|
102 | else {
|
---|
103 | StringBuilder commandString = new StringBuilder("generateReplayfile ");
|
---|
104 | FileDialog fileDialog = new FileDialog(getShell());
|
---|
105 | String filename = fileDialog.open();
|
---|
106 | commandString.append(filename + " ");
|
---|
107 | for (String selected : selectedSequences) {
|
---|
108 | commandString.append(selected + " ");
|
---|
109 | }
|
---|
110 | CommandExecuter.getInstance().exec(commandString.toString().trim());
|
---|
111 | }
|
---|
112 | }
|
---|
113 | });
|
---|
114 | btnReplay.setText("Replay");
|
---|
115 |
|
---|
116 | Button btnTrainModel = new Button(this, SWT.NONE);
|
---|
117 | btnTrainModel.addSelectionListener(new SelectionAdapter() {
|
---|
118 | @Override
|
---|
119 | public void widgetSelected(SelectionEvent e) {
|
---|
120 | String[] selectedSequences = sequenceList.getSelection();
|
---|
121 | if (selectedSequences.length == 0) {
|
---|
122 | SWTHelpers.noSelectionError(getShell());
|
---|
123 | }
|
---|
124 | else {
|
---|
125 | TrainModelDialog trainDialog = new TrainModelDialog(getShell(), SWT.NONE);
|
---|
126 | trainDialog.setSequenceNames(selectedSequences);
|
---|
127 | trainDialog.open();
|
---|
128 | }
|
---|
129 | }
|
---|
130 | });
|
---|
131 | btnTrainModel.setText("Train Model");
|
---|
132 |
|
---|
133 | Button btnParse = new Button(this, SWT.NONE);
|
---|
134 | btnParse.addSelectionListener(new SelectionAdapter() {
|
---|
135 | @Override
|
---|
136 | public void widgetSelected(SelectionEvent e) {
|
---|
137 | // TODO implement parsing of sequences
|
---|
138 | MessageBox messageBox = new MessageBox(getShell(), SWT.ICON_INFORMATION);
|
---|
139 | messageBox.setText("Not implemented!");
|
---|
140 | messageBox.setMessage("Sorry! This functionality has not been implemented yet!");
|
---|
141 | messageBox.open();
|
---|
142 | }
|
---|
143 | });
|
---|
144 | btnParse.setText("Parse");
|
---|
145 | }
|
---|
146 |
|
---|
147 | public void updateSequenceList() {
|
---|
148 | sequenceList.removeAll();
|
---|
149 |
|
---|
150 | java.util.List<String> sequences = new LinkedList<>();
|
---|
151 |
|
---|
152 | for (String key : GlobalDataContainer.getInstance().getAllKeys()) {
|
---|
153 | if (SequenceInstanceOf.isCollectionOfSequences(GlobalDataContainer.getInstance().getData(key))) {
|
---|
154 | sequences.add(key);
|
---|
155 | }
|
---|
156 | }
|
---|
157 |
|
---|
158 | Collections.sort(sequences);
|
---|
159 |
|
---|
160 | for (String entry : sequences) {
|
---|
161 | sequenceList.add(entry);
|
---|
162 | }
|
---|
163 | }
|
---|
164 |
|
---|
165 | @Override
|
---|
166 | protected void checkSubclass() {
|
---|
167 | // Disable the check that prevents subclassing of SWT components
|
---|
168 | }
|
---|
169 |
|
---|
170 | }
|
---|