source: trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/swt/ModelsTabComposite.java @ 194

Last change on this file since 194 was 194, checked in by sherbold, 13 years ago

Work on the SWT GUI prototype. The prototype is still incomplete and should not be used.

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