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