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

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