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

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