[927] | 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. |
---|
[658] | 14 | |
---|
[927] | 15 | |
---|
[922] | 16 | package de.ugoe.cs.autoquest.ui.swt; |
---|
[658] | 17 | |
---|
[2168] | 18 | import java.util.Collections; |
---|
| 19 | import java.util.LinkedList; |
---|
| 20 | |
---|
[658] | 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 | |
---|
[2146] | 30 | import de.ugoe.cs.autoquest.eventcore.IHierarchicalEventTarget; |
---|
| 31 | import de.ugoe.cs.autoquest.eventcore.IHierarchicalEventTargetModel; |
---|
[667] | 32 | import de.ugoe.cs.util.console.GlobalDataContainer; |
---|
[658] | 33 | |
---|
| 34 | /** |
---|
| 35 | * <p> |
---|
[1275] | 36 | * listing GUI models contained in the data store |
---|
[658] | 37 | * </p> |
---|
| 38 | * |
---|
[1275] | 39 | * @author 2012, Steffen Herbold, Patrick Harms |
---|
[658] | 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 | |
---|
[1275] | 53 | /** |
---|
| 54 | * <p> |
---|
| 55 | * fills the list of available GUI models and provides buttons for their detailed visualization |
---|
| 56 | * </p> |
---|
| 57 | */ |
---|
[2146] | 58 | private <T extends IHierarchicalEventTarget> void createContents() { |
---|
[658] | 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]; |
---|
[2146] | 74 | |
---|
| 75 | @SuppressWarnings("unchecked") |
---|
| 76 | IHierarchicalEventTargetModel<T> model = |
---|
| 77 | (IHierarchicalEventTargetModel<T>) GlobalDataContainer.getInstance().getData(modelName); |
---|
[658] | 78 | |
---|
[2146] | 79 | ShowGuiModelDialog<T> showGuiModelDialog = |
---|
| 80 | new ShowGuiModelDialog<T>(getShell(), SWT.NONE, model, modelName); |
---|
| 81 | |
---|
[658] | 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 | |
---|
[1275] | 102 | /** |
---|
| 103 | * Disable the check that prevents subclassing of SWT components |
---|
| 104 | */ |
---|
[658] | 105 | @Override |
---|
| 106 | protected void checkSubclass() { |
---|
| 107 | // Disable the check that prevents subclassing of SWT components |
---|
| 108 | } |
---|
| 109 | |
---|
[1275] | 110 | /** |
---|
| 111 | * <p> |
---|
| 112 | * convenience method for updating the list of available GUI models |
---|
| 113 | * </p> |
---|
| 114 | */ |
---|
[658] | 115 | public void updateModelList() { |
---|
| 116 | guiModelList.removeAll(); |
---|
[2168] | 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); |
---|
[666] | 123 | } |
---|
[658] | 124 | } |
---|
[2168] | 125 | |
---|
| 126 | Collections.sort(guiModels); |
---|
| 127 | |
---|
| 128 | for (String entry : guiModels) { |
---|
| 129 | guiModelList.add(entry); |
---|
| 130 | } |
---|
[658] | 131 | } |
---|
| 132 | |
---|
| 133 | } |
---|