source: trunk/autoquest-ui-swt/src/main/java/de/ugoe/cs/autoquest/ui/swt/GuiModelTabComposite.java @ 2156

Last change on this file since 2156 was 2156, checked in by pharms, 7 years ago

added first version of generic event plugin and required adaptations

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