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