source: trunk/autoquest-ui-swt/src/main/java/de/ugoe/cs/autoquest/ui/swt/ModelsTabComposite.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: 6.8 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
15package de.ugoe.cs.autoquest.ui.swt;
16
17import org.eclipse.swt.SWT;
18import org.eclipse.swt.widgets.Composite;
19import org.eclipse.swt.widgets.Button;
20import org.eclipse.swt.widgets.List;
21import org.eclipse.swt.widgets.MessageBox;
22import org.eclipse.swt.layout.GridLayout;
23import org.eclipse.swt.layout.GridData;
24
25import de.ugoe.cs.autoquest.usageprofiles.FirstOrderMarkovModel;
26import de.ugoe.cs.autoquest.usageprofiles.IDotCompatible;
27import de.ugoe.cs.autoquest.usageprofiles.IStochasticProcess;
28import de.ugoe.cs.util.console.CommandExecuter;
29import de.ugoe.cs.util.console.GlobalDataContainer;
30
31import org.eclipse.swt.events.SelectionAdapter;
32import org.eclipse.swt.events.SelectionEvent;
33
34public class ModelsTabComposite extends Composite {
35
36    List modelList;
37
38    /**
39     * Create the composite.
40     *
41     * @param parent
42     * @param style
43     */
44    public ModelsTabComposite(Composite parent, int style) {
45        super(parent, style);
46        createContents();
47    }
48
49    private void createContents() {
50        setLayout(new GridLayout(5, false));
51
52        modelList = new List(this, SWT.BORDER | SWT.V_SCROLL);
53        modelList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 5, 1));
54
55        Button btnShow = new Button(this, SWT.NONE);
56        btnShow.addSelectionListener(new SelectionAdapter() {
57            @Override
58            public void widgetSelected(SelectionEvent e) {
59                String[] selectedStrings = modelList.getSelection();
60                if (selectedStrings.length == 0) {
61                    SWTHelpers.noSelectionError(getShell());
62                    return;
63                }
64                IStochasticProcess process =
65                    (IStochasticProcess) GlobalDataContainer.getInstance()
66                        .getData(selectedStrings[0]);
67                if (process instanceof FirstOrderMarkovModel) {
68                    String command = "showMarkovModel " + selectedStrings[0];
69                    CommandExecuter.getInstance().exec(command);
70                }
71                else {
72                    MessageBox messageBox = new MessageBox(getShell(), SWT.NONE);
73                    messageBox.setText("Feature Not Available");
74                    messageBox
75                        .setMessage("The feature is currently only available for first-order Markov models.");
76                    messageBox.open();
77                }
78            }
79        });
80        btnShow.setText("Visualize");
81
82        Button btnDelete_1 = new Button(this, SWT.NONE);
83        btnDelete_1.addSelectionListener(new SelectionAdapter() {
84            @Override
85            public void widgetSelected(SelectionEvent e) {
86                if (SWTHelpers.deleteSelectedFromStorage(modelList)) {
87                    updateModelList();
88                }
89                else {
90                    SWTHelpers.noSelectionError(getShell());
91                }
92            }
93        });
94        btnDelete_1.setText("Delete");
95
96        Button btnGenSequences = new Button(this, SWT.NONE);
97        btnGenSequences.addSelectionListener(new SelectionAdapter() {
98            @Override
99            public void widgetSelected(SelectionEvent e) {
100                String[] selectedStrings = modelList.getSelection();
101                if (selectedStrings.length == 0) {
102                    SWTHelpers.noSelectionError(getShell());
103                    return;
104                }
105                GenerateSequencesDialog generateSequencesDialog =
106                    new GenerateSequencesDialog(getShell(), SWT.NONE);
107                generateSequencesDialog.setProcessName(selectedStrings[0]);
108                generateSequencesDialog.open();
109            }
110        });
111        btnGenSequences.setText("Gen. Sequences");
112
113        Button btnProperties = new Button(this, SWT.NONE);
114        btnProperties.addSelectionListener(new SelectionAdapter() {
115            @Override
116            public void widgetSelected(SelectionEvent e) {
117                String[] selectedStrings = modelList.getSelection();
118                if (selectedStrings.length == 0) {
119                    SWTHelpers.noSelectionError(getShell());
120                    return;
121                }
122                IStochasticProcess process =
123                    (IStochasticProcess) GlobalDataContainer.getInstance()
124                        .getData(selectedStrings[0]);
125                ModelPropertiesDialog modelPropertiesDialog =
126                    new ModelPropertiesDialog(getShell(), SWT.NONE);
127                modelPropertiesDialog.setStochasticProcess(process);
128                modelPropertiesDialog.open();
129            }
130        });
131        btnProperties.setText("Properties");
132
133        Button btnCreateDot = new Button(this, SWT.NONE);
134        btnCreateDot.addSelectionListener(new SelectionAdapter() {
135            @Override
136            public void widgetSelected(SelectionEvent e) {
137                String[] selectedStrings = modelList.getSelection();
138                if (selectedStrings.length == 0) {
139                    SWTHelpers.noSelectionError(getShell());
140                    return;
141                }
142                IStochasticProcess process =
143                    (IStochasticProcess) GlobalDataContainer.getInstance()
144                        .getData(selectedStrings[0]);
145                String command = "";
146                if (process instanceof IDotCompatible) {
147                    command = "printDot ";
148                }
149                else {
150                    command = "printTrieDot ";
151                }
152                command += selectedStrings[0];
153                CommandExecuter.getInstance().exec(command);
154            }
155        });
156        btnCreateDot.setText("Create DOT");
157    }
158
159    @Override
160    protected void checkSubclass() {
161        // Disable the check that prevents subclassing of SWT components
162    }
163
164    public void updateModelList() {
165        modelList.removeAll();
166        for(String key : GlobalDataContainer.getInstance().getAllKeys()) {
167            if( GlobalDataContainer.getInstance().getData(key) instanceof IStochasticProcess ) {
168                modelList.add(key);
169            }
170        }
171    }
172
173}
Note: See TracBrowser for help on using the repository browser.