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

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