source: trunk/autoquest-ui-swt/src/main/java/de/ugoe/cs/autoquest/ui/swt/UsabilityTabComposite.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
File size: 5.6 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.usability.UsabilityEvaluationResult;
29import de.ugoe.cs.util.console.GlobalDataContainer;
30
31import org.eclipse.swt.events.SelectionAdapter;
32import org.eclipse.swt.events.SelectionEvent;
33
34public class UsabilityTabComposite extends Composite {
35
36    /** */
37    private List evaluationResultsList;
38
39    /** */
40    private Button btnShow;
41
42    /** */
43    private Button btnDelete_1;
44
45    /**
46     * Create the composite.
47     *
48     * @param parent
49     * @param style
50     */
51    public UsabilityTabComposite(Composite parent, int style) {
52        super(parent, style);
53        createContents();
54    }
55
56    /**
57     *
58     */
59    private void createContents() {
60        setLayout(new GridLayout(5, false));
61
62        evaluationResultsList = new List(this, SWT.BORDER | SWT.V_SCROLL);
63        evaluationResultsList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 5, 1));
64        evaluationResultsList.addSelectionListener(new SelectionAdapter() {
65            @Override
66            public void widgetSelected(SelectionEvent e) {
67                String[] selectedStrings = evaluationResultsList.getSelection();
68                if (selectedStrings.length == 1) {
69                    btnShow.setEnabled(true);
70                    btnDelete_1.setEnabled(true);
71                }
72                else if (selectedStrings.length > 1) {
73                    btnShow.setEnabled(false);
74                    btnDelete_1.setEnabled(true);
75                }
76                else {
77                    btnShow.setEnabled(false);
78                    btnDelete_1.setEnabled(false);
79                }
80            }
81        });
82
83        btnShow = new Button(this, SWT.NONE);
84        btnShow.addSelectionListener(new SelectionAdapter() {
85            @Override
86            public void widgetSelected(SelectionEvent e) {
87                String[] selectedStrings = evaluationResultsList.getSelection();
88                if (selectedStrings.length == 0) {
89                    SWTHelpers.noSelectionError(getShell());
90                    return;
91                }
92                else if (selectedStrings.length > 1) {
93                    SWTHelpers.moreThanOneSelectedError(getShell());
94                    return;
95                }
96
97                Object obj = GlobalDataContainer.getInstance().getData(selectedStrings[0]);
98
99                if (obj instanceof UsabilityEvaluationResult) {
100                    ShowUsabilityEvaluationResultDialog showUsabilityEvaluationResultDialog =
101                        new ShowUsabilityEvaluationResultDialog
102                            (getShell(), SWT.NONE, (UsabilityEvaluationResult) obj,
103                             selectedStrings[0]);
104                    showUsabilityEvaluationResultDialog.open();
105                }
106                else {
107                    MessageBox messageBox = new MessageBox(getShell(), SWT.NONE);
108                    messageBox.setText("Feature Not Available");
109                    messageBox.setMessage("This feature is currently only available for " +
110                                          "usability evaluation results.");
111                    messageBox.open();
112                }
113            }
114        });
115        btnShow.setText("Show");
116        btnShow.setEnabled(false);
117
118        btnDelete_1 = new Button(this, SWT.NONE);
119        btnDelete_1.addSelectionListener(new SelectionAdapter() {
120            @Override
121            public void widgetSelected(SelectionEvent e) {
122                if (SWTHelpers.deleteSelectedFromStorage(evaluationResultsList)) {
123                    updateResultList();
124                }
125                else {
126                    SWTHelpers.noSelectionError(getShell());
127                }
128            }
129        });
130        btnDelete_1.setText("Delete");
131        btnDelete_1.setEnabled(false);
132    }
133
134    /**
135     *
136     */
137    @Override
138    protected void checkSubclass() {
139        // Disable the check that prevents subclassing of SWT components
140    }
141
142    /**
143     *
144     */
145    public void updateResultList() {
146        evaluationResultsList.removeAll();
147       
148        java.util.List<String> results = new LinkedList<>();
149       
150        for (String key : GlobalDataContainer.getInstance().getAllKeys()) {
151            Object data = GlobalDataContainer.getInstance().getData(key);
152            if (data instanceof UsabilityEvaluationResult) {
153                results.add(key);
154            }
155        }
156       
157        Collections.sort(results);
158       
159        for (String entry : results) {
160            evaluationResultsList.add(entry);
161        }
162    }
163
164}
Note: See TracBrowser for help on using the repository browser.