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.SWT;
|
---|
18 | import org.eclipse.swt.widgets.Composite;
|
---|
19 | import org.eclipse.swt.widgets.Button;
|
---|
20 | import org.eclipse.swt.widgets.List;
|
---|
21 | import org.eclipse.swt.widgets.MessageBox;
|
---|
22 | import org.eclipse.swt.layout.GridLayout;
|
---|
23 | import org.eclipse.swt.layout.GridData;
|
---|
24 |
|
---|
25 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel;
|
---|
26 | import de.ugoe.cs.autoquest.usageprofiles.FirstOrderMarkovModel;
|
---|
27 | import de.ugoe.cs.autoquest.usageprofiles.IDotCompatible;
|
---|
28 | import de.ugoe.cs.autoquest.usageprofiles.IStochasticProcess;
|
---|
29 | import de.ugoe.cs.util.console.CommandExecuter;
|
---|
30 | import de.ugoe.cs.util.console.GlobalDataContainer;
|
---|
31 |
|
---|
32 | import org.eclipse.swt.events.SelectionAdapter;
|
---|
33 | import org.eclipse.swt.events.SelectionEvent;
|
---|
34 |
|
---|
35 | public class ModelsTabComposite extends Composite {
|
---|
36 |
|
---|
37 | /** */
|
---|
38 | List modelList;
|
---|
39 |
|
---|
40 | /** */
|
---|
41 | Button btnShow;
|
---|
42 |
|
---|
43 | /** */
|
---|
44 | Button btnDelete_1;
|
---|
45 |
|
---|
46 | /** */
|
---|
47 | Button btnGenSequences;
|
---|
48 |
|
---|
49 | /** */
|
---|
50 | Button btnProperties;
|
---|
51 |
|
---|
52 | /** */
|
---|
53 | Button btnCreateDot;
|
---|
54 |
|
---|
55 | /**
|
---|
56 | * Create the composite.
|
---|
57 | *
|
---|
58 | * @param parent
|
---|
59 | * @param style
|
---|
60 | */
|
---|
61 | public ModelsTabComposite(Composite parent, int style) {
|
---|
62 | super(parent, style);
|
---|
63 | createContents();
|
---|
64 | }
|
---|
65 |
|
---|
66 | /**
|
---|
67 | *
|
---|
68 | */
|
---|
69 | private void createContents() {
|
---|
70 | setLayout(new GridLayout(5, false));
|
---|
71 |
|
---|
72 | modelList = new List(this, SWT.BORDER | SWT.V_SCROLL);
|
---|
73 | modelList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 5, 1));
|
---|
74 | modelList.addSelectionListener(new SelectionAdapter() {
|
---|
75 | @Override
|
---|
76 | public void widgetSelected(SelectionEvent e) {
|
---|
77 | String[] selectedStrings = modelList.getSelection();
|
---|
78 | if (selectedStrings.length == 1) {
|
---|
79 | btnShow.setEnabled(true);
|
---|
80 | btnDelete_1.setEnabled(true);
|
---|
81 | Object obj = GlobalDataContainer.getInstance().getData(selectedStrings[0]);
|
---|
82 | if (obj instanceof IStochasticProcess) {
|
---|
83 | btnGenSequences.setEnabled(true);
|
---|
84 | btnProperties.setEnabled(true);
|
---|
85 | btnCreateDot.setEnabled(true);
|
---|
86 | }
|
---|
87 | else {
|
---|
88 | btnGenSequences.setEnabled(false);
|
---|
89 | btnProperties.setEnabled(false);
|
---|
90 | btnCreateDot.setEnabled(false);
|
---|
91 | }
|
---|
92 | }
|
---|
93 | else if (selectedStrings.length > 1) {
|
---|
94 | btnShow.setEnabled(false);
|
---|
95 | btnDelete_1.setEnabled(true);
|
---|
96 | btnProperties.setEnabled(false);
|
---|
97 | btnCreateDot.setEnabled(false);
|
---|
98 |
|
---|
99 | boolean enableSequenceGeneration = true;
|
---|
100 | for (String selectedString : selectedStrings) {
|
---|
101 | Object obj = GlobalDataContainer.getInstance().getData(selectedString);
|
---|
102 | if (!(obj instanceof IStochasticProcess)) {
|
---|
103 | enableSequenceGeneration = false;
|
---|
104 | break;
|
---|
105 | }
|
---|
106 | }
|
---|
107 | btnGenSequences.setEnabled(enableSequenceGeneration);
|
---|
108 | }
|
---|
109 | }
|
---|
110 | });
|
---|
111 |
|
---|
112 | btnShow = new Button(this, SWT.NONE);
|
---|
113 | btnShow.addSelectionListener(new SelectionAdapter() {
|
---|
114 | @Override
|
---|
115 | public void widgetSelected(SelectionEvent e) {
|
---|
116 | String[] selectedStrings = modelList.getSelection();
|
---|
117 | if (selectedStrings.length == 0) {
|
---|
118 | SWTHelpers.noSelectionError(getShell());
|
---|
119 | return;
|
---|
120 | }
|
---|
121 | else if (selectedStrings.length > 1) {
|
---|
122 | SWTHelpers.moreThanOneSelectedError(getShell());
|
---|
123 | return;
|
---|
124 | }
|
---|
125 |
|
---|
126 | Object obj = GlobalDataContainer.getInstance().getData(selectedStrings[0]);
|
---|
127 |
|
---|
128 | if (obj instanceof FirstOrderMarkovModel) {
|
---|
129 | String command = "showMarkovModel " + selectedStrings[0];
|
---|
130 | CommandExecuter.getInstance().exec(command);
|
---|
131 | }
|
---|
132 | else if (obj instanceof ITaskModel) {
|
---|
133 | ShowTaskTreeDialog showTaskTreeDialog = new ShowTaskTreeDialog
|
---|
134 | (getShell(), SWT.NONE, (ITaskModel) obj, selectedStrings[0]);
|
---|
135 | showTaskTreeDialog.open();
|
---|
136 | }
|
---|
137 | else {
|
---|
138 | MessageBox messageBox = new MessageBox(getShell(), SWT.NONE);
|
---|
139 | messageBox.setText("Feature Not Available");
|
---|
140 | messageBox.setMessage("This feature is currently only available for " +
|
---|
141 | "first-order Markov models and task trees.");
|
---|
142 | messageBox.open();
|
---|
143 | }
|
---|
144 | }
|
---|
145 | });
|
---|
146 | btnShow.setText("Visualize");
|
---|
147 | btnShow.setEnabled(false);
|
---|
148 |
|
---|
149 | btnDelete_1 = new Button(this, SWT.NONE);
|
---|
150 | btnDelete_1.addSelectionListener(new SelectionAdapter() {
|
---|
151 | @Override
|
---|
152 | public void widgetSelected(SelectionEvent e) {
|
---|
153 | if (SWTHelpers.deleteSelectedFromStorage(modelList)) {
|
---|
154 | updateModelList();
|
---|
155 | }
|
---|
156 | else {
|
---|
157 | SWTHelpers.noSelectionError(getShell());
|
---|
158 | }
|
---|
159 | }
|
---|
160 | });
|
---|
161 | btnDelete_1.setText("Delete");
|
---|
162 | btnDelete_1.setEnabled(false);
|
---|
163 |
|
---|
164 | btnGenSequences = new Button(this, SWT.NONE);
|
---|
165 | btnGenSequences.addSelectionListener(new SelectionAdapter() {
|
---|
166 | @Override
|
---|
167 | public void widgetSelected(SelectionEvent e) {
|
---|
168 | String[] selectedStrings = modelList.getSelection();
|
---|
169 | if (selectedStrings.length == 0) {
|
---|
170 | SWTHelpers.noSelectionError(getShell());
|
---|
171 | return;
|
---|
172 | }
|
---|
173 |
|
---|
174 | boolean enableSequenceGeneration = true;
|
---|
175 | for (String selectedString : selectedStrings) {
|
---|
176 | Object obj = GlobalDataContainer.getInstance().getData(selectedString);
|
---|
177 | if (!(obj instanceof IStochasticProcess)) {
|
---|
178 | enableSequenceGeneration = false;
|
---|
179 | break;
|
---|
180 | }
|
---|
181 | }
|
---|
182 |
|
---|
183 | if (enableSequenceGeneration) {
|
---|
184 | GenerateSequencesDialog generateSequencesDialog =
|
---|
185 | new GenerateSequencesDialog(getShell(), SWT.NONE);
|
---|
186 | generateSequencesDialog.setProcessName(selectedStrings[0]);
|
---|
187 | generateSequencesDialog.open();
|
---|
188 | }
|
---|
189 | else {
|
---|
190 | MessageBox messageBox = new MessageBox(getShell(), SWT.NONE);
|
---|
191 | messageBox.setText("Feature Not Available");
|
---|
192 | messageBox.setMessage("This feature is not available for task trees. Please " +
|
---|
193 | "deselect the selected task tree(s)!");
|
---|
194 | messageBox.open();
|
---|
195 | }
|
---|
196 | }
|
---|
197 | });
|
---|
198 | btnGenSequences.setText("Gen. Sequences");
|
---|
199 | btnGenSequences.setEnabled(false);
|
---|
200 |
|
---|
201 | btnProperties = new Button(this, SWT.NONE);
|
---|
202 | btnProperties.addSelectionListener(new SelectionAdapter() {
|
---|
203 | @Override
|
---|
204 | public void widgetSelected(SelectionEvent e) {
|
---|
205 | String[] selectedStrings = modelList.getSelection();
|
---|
206 | if (selectedStrings.length == 0) {
|
---|
207 | SWTHelpers.noSelectionError(getShell());
|
---|
208 | return;
|
---|
209 | }
|
---|
210 | else if (selectedStrings.length > 1) {
|
---|
211 | SWTHelpers.moreThanOneSelectedError(getShell());
|
---|
212 | return;
|
---|
213 | }
|
---|
214 |
|
---|
215 | Object obj = GlobalDataContainer.getInstance().getData(selectedStrings[0]);
|
---|
216 |
|
---|
217 | if (obj instanceof IStochasticProcess) {
|
---|
218 | IStochasticProcess process = (IStochasticProcess) obj;
|
---|
219 | ModelPropertiesDialog modelPropertiesDialog =
|
---|
220 | new ModelPropertiesDialog(getShell(), SWT.NONE);
|
---|
221 | modelPropertiesDialog.setStochasticProcess(process);
|
---|
222 | modelPropertiesDialog.open();
|
---|
223 | }
|
---|
224 | else {
|
---|
225 | MessageBox messageBox = new MessageBox(getShell(), SWT.NONE);
|
---|
226 | messageBox.setText("Feature Not Available");
|
---|
227 | messageBox.setMessage("The feature is currently only available for " +
|
---|
228 | "stochastic processes. Please select a model that " +
|
---|
229 | "is a stochastic process.");
|
---|
230 | messageBox.open();
|
---|
231 | }
|
---|
232 | }
|
---|
233 | });
|
---|
234 | btnProperties.setText("Properties");
|
---|
235 | btnProperties.setEnabled(false);
|
---|
236 |
|
---|
237 | btnCreateDot = new Button(this, SWT.NONE);
|
---|
238 | btnCreateDot.addSelectionListener(new SelectionAdapter() {
|
---|
239 | @Override
|
---|
240 | public void widgetSelected(SelectionEvent e) {
|
---|
241 | String[] selectedStrings = modelList.getSelection();
|
---|
242 | if (selectedStrings.length == 0) {
|
---|
243 | SWTHelpers.noSelectionError(getShell());
|
---|
244 | return;
|
---|
245 | }
|
---|
246 | else if (selectedStrings.length > 1) {
|
---|
247 | SWTHelpers.moreThanOneSelectedError(getShell());
|
---|
248 | return;
|
---|
249 | }
|
---|
250 |
|
---|
251 | Object obj = GlobalDataContainer.getInstance().getData(selectedStrings[0]);
|
---|
252 |
|
---|
253 | if (obj instanceof IStochasticProcess) {
|
---|
254 | String command;
|
---|
255 | if (obj instanceof IDotCompatible) {
|
---|
256 | command = "printDot ";
|
---|
257 | }
|
---|
258 | else {
|
---|
259 | command = "printTrieDot ";
|
---|
260 | }
|
---|
261 | command += selectedStrings[0];
|
---|
262 | CommandExecuter.getInstance().exec(command);
|
---|
263 | }
|
---|
264 | else {
|
---|
265 | MessageBox messageBox = new MessageBox(getShell(), SWT.NONE);
|
---|
266 | messageBox.setText("Feature Not Available");
|
---|
267 | messageBox.setMessage("The feature is currently only available for " +
|
---|
268 | "stochastic processes. Please select a model that " +
|
---|
269 | "is a stochastic process.");
|
---|
270 | messageBox.open();
|
---|
271 | }
|
---|
272 | }
|
---|
273 | });
|
---|
274 | btnCreateDot.setText("Create DOT");
|
---|
275 | btnCreateDot.setEnabled(false);
|
---|
276 | }
|
---|
277 |
|
---|
278 | /**
|
---|
279 | *
|
---|
280 | */
|
---|
281 | @Override
|
---|
282 | protected void checkSubclass() {
|
---|
283 | // Disable the check that prevents subclassing of SWT components
|
---|
284 | }
|
---|
285 |
|
---|
286 | /**
|
---|
287 | *
|
---|
288 | */
|
---|
289 | public void updateModelList() {
|
---|
290 | modelList.removeAll();
|
---|
291 | for (String key : GlobalDataContainer.getInstance().getAllKeys()) {
|
---|
292 | if ((GlobalDataContainer.getInstance().getData(key) instanceof IStochasticProcess) ||
|
---|
293 | (GlobalDataContainer.getInstance().getData(key) instanceof ITaskModel))
|
---|
294 | {
|
---|
295 | modelList.add(key);
|
---|
296 | }
|
---|
297 | }
|
---|
298 | }
|
---|
299 |
|
---|
300 | }
|
---|