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.List;
|
---|
19 | import org.eclipse.swt.widgets.MessageBox;
|
---|
20 | import org.eclipse.swt.widgets.Shell;
|
---|
21 |
|
---|
22 | import de.ugoe.cs.util.console.CommandExecuter;
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * <p>
|
---|
26 | * class containing convenience methods for the SWT UI
|
---|
27 | * </p>
|
---|
28 | *
|
---|
29 | * @author Steffen Herbold, Patrick Harms
|
---|
30 | */
|
---|
31 | public class SWTHelpers {
|
---|
32 |
|
---|
33 | /**
|
---|
34 | * deletes the objects selected in the provided list from the data store
|
---|
35 | */
|
---|
36 | public static boolean deleteSelectedFromStorage(final List list) {
|
---|
37 | String[] selectedStrings = list.getSelection();
|
---|
38 | if (selectedStrings.length == 0) {
|
---|
39 | return false;
|
---|
40 | }
|
---|
41 | else {
|
---|
42 | for (String selected : selectedStrings) {
|
---|
43 | String command = "deleteObject " + selected;
|
---|
44 | CommandExecuter.getInstance().exec(command);
|
---|
45 | }
|
---|
46 | return true;
|
---|
47 | }
|
---|
48 | }
|
---|
49 |
|
---|
50 | /**
|
---|
51 | * alerts, that no object is selected but a selection is required
|
---|
52 | */
|
---|
53 | public static void noSelectionError(final Shell shell) {
|
---|
54 | MessageBox messageBox = new MessageBox(shell, SWT.ERROR);
|
---|
55 | messageBox.setMessage
|
---|
56 | ("No objects selected! Please select at least one object to execute this function");
|
---|
57 | messageBox.setText("Error");
|
---|
58 | messageBox.open();
|
---|
59 | }
|
---|
60 |
|
---|
61 | /**
|
---|
62 | * alerts, that too many objects are selected but a selection of only one is required
|
---|
63 | */
|
---|
64 | public static void moreThanOneSelectedError(final Shell shell) {
|
---|
65 | MessageBox messageBox = new MessageBox(shell, SWT.ERROR);
|
---|
66 | messageBox.setMessage("Too many objects selected for this function! Select only one!");
|
---|
67 | messageBox.setText("Error");
|
---|
68 | messageBox.open();
|
---|
69 | }
|
---|
70 |
|
---|
71 | }
|
---|