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 | |
---|
16 | package de.ugoe.cs.autoquest.ui.swt; |
---|
17 | |
---|
18 | import java.util.Collections; |
---|
19 | import java.util.LinkedList; |
---|
20 | |
---|
21 | import org.eclipse.swt.SWT; |
---|
22 | import org.eclipse.swt.events.SelectionAdapter; |
---|
23 | import org.eclipse.swt.events.SelectionEvent; |
---|
24 | import org.eclipse.swt.layout.GridData; |
---|
25 | import org.eclipse.swt.layout.GridLayout; |
---|
26 | import org.eclipse.swt.widgets.Button; |
---|
27 | import org.eclipse.swt.widgets.Composite; |
---|
28 | import org.eclipse.swt.widgets.List; |
---|
29 | |
---|
30 | import de.ugoe.cs.autoquest.eventcore.IHierarchicalEventTarget; |
---|
31 | import de.ugoe.cs.autoquest.eventcore.IHierarchicalEventTargetModel; |
---|
32 | import de.ugoe.cs.util.console.GlobalDataContainer; |
---|
33 | |
---|
34 | /** |
---|
35 | * <p> |
---|
36 | * listing GUI models contained in the data store |
---|
37 | * </p> |
---|
38 | * |
---|
39 | * @author 2012, Steffen Herbold, Patrick Harms |
---|
40 | */ |
---|
41 | public class GuiModelTabComposite extends Composite { |
---|
42 | |
---|
43 | List guiModelList; |
---|
44 | |
---|
45 | /** |
---|
46 | * Create the composite. |
---|
47 | */ |
---|
48 | public GuiModelTabComposite(Composite parent, int style) { |
---|
49 | super(parent, style); |
---|
50 | createContents(); |
---|
51 | } |
---|
52 | |
---|
53 | /** |
---|
54 | * <p> |
---|
55 | * fills the list of available GUI models and provides buttons for their detailed visualization |
---|
56 | * </p> |
---|
57 | */ |
---|
58 | private <T extends IHierarchicalEventTarget> void createContents() { |
---|
59 | setLayout(new GridLayout(5, false)); |
---|
60 | |
---|
61 | guiModelList = new List(this, SWT.BORDER | SWT.V_SCROLL); |
---|
62 | guiModelList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 5, 1)); |
---|
63 | |
---|
64 | Button btnShow = new Button(this, SWT.NONE); |
---|
65 | btnShow.addSelectionListener(new SelectionAdapter() { |
---|
66 | @Override |
---|
67 | public void widgetSelected(SelectionEvent e) { |
---|
68 | String[] selectedStrings = guiModelList.getSelection(); |
---|
69 | if (selectedStrings.length == 0) { |
---|
70 | SWTHelpers.noSelectionError(getShell()); |
---|
71 | return; |
---|
72 | } |
---|
73 | String modelName = selectedStrings[0]; |
---|
74 | |
---|
75 | @SuppressWarnings("unchecked") |
---|
76 | IHierarchicalEventTargetModel<T> model = |
---|
77 | (IHierarchicalEventTargetModel<T>) GlobalDataContainer.getInstance().getData(modelName); |
---|
78 | |
---|
79 | ShowGuiModelDialog<T> showGuiModelDialog = |
---|
80 | new ShowGuiModelDialog<T>(getShell(), SWT.NONE, model, modelName); |
---|
81 | |
---|
82 | showGuiModelDialog.open(); |
---|
83 | } |
---|
84 | }); |
---|
85 | btnShow.setText("Show"); |
---|
86 | |
---|
87 | Button btnDelete_1 = new Button(this, SWT.NONE); |
---|
88 | btnDelete_1.addSelectionListener(new SelectionAdapter() { |
---|
89 | @Override |
---|
90 | public void widgetSelected(SelectionEvent e) { |
---|
91 | if (SWTHelpers.deleteSelectedFromStorage(guiModelList)) { |
---|
92 | updateModelList(); |
---|
93 | } |
---|
94 | else { |
---|
95 | SWTHelpers.noSelectionError(getShell()); |
---|
96 | } |
---|
97 | } |
---|
98 | }); |
---|
99 | btnDelete_1.setText("Delete"); |
---|
100 | } |
---|
101 | |
---|
102 | /** |
---|
103 | * Disable the check that prevents subclassing of SWT components |
---|
104 | */ |
---|
105 | @Override |
---|
106 | protected void checkSubclass() { |
---|
107 | // Disable the check that prevents subclassing of SWT components |
---|
108 | } |
---|
109 | |
---|
110 | /** |
---|
111 | * <p> |
---|
112 | * convenience method for updating the list of available GUI models |
---|
113 | * </p> |
---|
114 | */ |
---|
115 | public void updateModelList() { |
---|
116 | guiModelList.removeAll(); |
---|
117 | |
---|
118 | java.util.List<String> guiModels = new LinkedList<>(); |
---|
119 | |
---|
120 | for (String key : GlobalDataContainer.getInstance().getAllKeys()) { |
---|
121 | if (GlobalDataContainer.getInstance().getData(key) instanceof IHierarchicalEventTargetModel) { |
---|
122 | guiModels.add(key); |
---|
123 | } |
---|
124 | } |
---|
125 | |
---|
126 | Collections.sort(guiModels); |
---|
127 | |
---|
128 | for (String entry : guiModels) { |
---|
129 | guiModelList.add(entry); |
---|
130 | } |
---|
131 | } |
---|
132 | |
---|
133 | } |
---|