source: trunk/autoquest-ui-swt/src/main/java/de/ugoe/cs/autoquest/ui/swt/ModelsTabComposite.java @ 2168

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