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

Last change on this file since 927 was 927, checked in by sherbold, 12 years ago
  • added copyright under the Apache License, Version 2.0
  • Property svn:mime-type set to text/plain
File size: 3.5 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.guimodel.GUIModel;
28import de.ugoe.cs.util.console.GlobalDataContainer;
29
30/**
31 * <p>
32 * TODO comment
33 * </p>
34 *
35 * @version $Revision: $ $Date: Aug 28, 2012$
36 * @author 2012, last modified by $Author: sherbold$
37 */
38public class GuiModelTabComposite extends Composite {
39
40    List guiModelList;
41
42    /**
43     * Create the composite.
44     *
45     * @param parent
46     * @param style
47     */
48    public GuiModelTabComposite(Composite parent, int style) {
49        super(parent, style);
50        createContents();
51    }
52
53    private void createContents() {
54        setLayout(new GridLayout(5, false));
55
56        guiModelList = new List(this, SWT.BORDER | SWT.V_SCROLL);
57        guiModelList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 5, 1));
58
59        Button btnShow = new Button(this, SWT.NONE);
60        btnShow.addSelectionListener(new SelectionAdapter() {
61            @Override
62            public void widgetSelected(SelectionEvent e) {
63                // TODO
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
94    @Override
95    protected void checkSubclass() {
96        // Disable the check that prevents subclassing of SWT components
97    }
98
99    public void updateModelList() {
100        guiModelList.removeAll();
101        for(String key : GlobalDataContainer.getInstance().getAllKeys()) {
102            if( GlobalDataContainer.getInstance().getData(key) instanceof GUIModel ) {
103                guiModelList.add(key);
104            }
105        }
106    }
107
108}
Note: See TracBrowser for help on using the repository browser.