[658] | 1 | |
---|
| 2 | package de.ugoe.cs.quest.ui.swt; |
---|
| 3 | |
---|
| 4 | import org.eclipse.swt.SWT; |
---|
| 5 | import org.eclipse.swt.events.SelectionAdapter; |
---|
| 6 | import org.eclipse.swt.events.SelectionEvent; |
---|
| 7 | import org.eclipse.swt.layout.GridData; |
---|
| 8 | import org.eclipse.swt.layout.GridLayout; |
---|
| 9 | import org.eclipse.swt.widgets.Button; |
---|
| 10 | import org.eclipse.swt.widgets.Composite; |
---|
| 11 | import org.eclipse.swt.widgets.List; |
---|
| 12 | |
---|
| 13 | import de.ugoe.cs.quest.eventcore.guimodel.GUIModel; |
---|
[667] | 14 | import de.ugoe.cs.util.console.GlobalDataContainer; |
---|
[658] | 15 | |
---|
| 16 | /** |
---|
| 17 | * <p> |
---|
| 18 | * TODO comment |
---|
| 19 | * </p> |
---|
| 20 | * |
---|
| 21 | * @version $Revision: $ $Date: Aug 28, 2012$ |
---|
| 22 | * @author 2012, last modified by $Author: sherbold$ |
---|
| 23 | */ |
---|
| 24 | public class GuiModelTabComposite extends Composite { |
---|
| 25 | |
---|
| 26 | List guiModelList; |
---|
| 27 | |
---|
| 28 | /** |
---|
| 29 | * Create the composite. |
---|
| 30 | * |
---|
| 31 | * @param parent |
---|
| 32 | * @param style |
---|
| 33 | */ |
---|
| 34 | public GuiModelTabComposite(Composite parent, int style) { |
---|
| 35 | super(parent, style); |
---|
| 36 | createContents(); |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | private void createContents() { |
---|
| 40 | setLayout(new GridLayout(5, false)); |
---|
| 41 | |
---|
| 42 | guiModelList = new List(this, SWT.BORDER | SWT.V_SCROLL); |
---|
| 43 | guiModelList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 5, 1)); |
---|
| 44 | |
---|
| 45 | Button btnShow = new Button(this, SWT.NONE); |
---|
| 46 | btnShow.addSelectionListener(new SelectionAdapter() { |
---|
| 47 | @Override |
---|
| 48 | public void widgetSelected(SelectionEvent e) { |
---|
| 49 | // TODO |
---|
| 50 | String[] selectedStrings = guiModelList.getSelection(); |
---|
| 51 | if (selectedStrings.length == 0) { |
---|
| 52 | SWTHelpers.noSelectionError(getShell()); |
---|
| 53 | return; |
---|
| 54 | } |
---|
| 55 | String modelName = selectedStrings[0]; |
---|
| 56 | GUIModel model = (GUIModel) GlobalDataContainer.getInstance().getData(modelName); |
---|
| 57 | |
---|
| 58 | ShowGuiModelDialog showGuiModelDialog = |
---|
| 59 | new ShowGuiModelDialog(getShell(), SWT.NONE, model, modelName); |
---|
| 60 | showGuiModelDialog.open(); |
---|
| 61 | } |
---|
| 62 | }); |
---|
| 63 | btnShow.setText("Show"); |
---|
| 64 | |
---|
| 65 | Button btnDelete_1 = new Button(this, SWT.NONE); |
---|
| 66 | btnDelete_1.addSelectionListener(new SelectionAdapter() { |
---|
| 67 | @Override |
---|
| 68 | public void widgetSelected(SelectionEvent e) { |
---|
| 69 | if (SWTHelpers.deleteSelectedFromStorage(guiModelList)) { |
---|
| 70 | updateModelList(); |
---|
| 71 | } |
---|
| 72 | else { |
---|
| 73 | SWTHelpers.noSelectionError(getShell()); |
---|
| 74 | } |
---|
| 75 | } |
---|
| 76 | }); |
---|
| 77 | btnDelete_1.setText("Delete"); |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | @Override |
---|
| 81 | protected void checkSubclass() { |
---|
| 82 | // Disable the check that prevents subclassing of SWT components |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | public void updateModelList() { |
---|
| 86 | guiModelList.removeAll(); |
---|
[666] | 87 | for(String key : GlobalDataContainer.getInstance().getAllKeys()) { |
---|
| 88 | if( GlobalDataContainer.getInstance().getData(key) instanceof GUIModel ) { |
---|
| 89 | guiModelList.add(key); |
---|
| 90 | } |
---|
[658] | 91 | } |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | } |
---|