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.usability.UsabilityEvaluationResult;
|
---|
26 | import de.ugoe.cs.util.console.GlobalDataContainer;
|
---|
27 |
|
---|
28 | import org.eclipse.swt.events.SelectionAdapter;
|
---|
29 | import org.eclipse.swt.events.SelectionEvent;
|
---|
30 |
|
---|
31 | public 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 | }
|
---|