source: trunk/quest-ui-core/src/de/ugoe/cs/quest/ui/swt/SequencesTabComposite.java @ 434

Last change on this file since 434 was 434, checked in by sherbold, 12 years ago
  • renamed packages to fit QUEST project structure
  • Property svn:mime-type set to text/plain
File size: 4.4 KB
Line 
1package de.ugoe.cs.quest.ui.swt;
2
3import org.eclipse.swt.widgets.Composite;
4
5
6import org.eclipse.swt.SWT;
7import org.eclipse.swt.widgets.Button;
8import org.eclipse.swt.widgets.FileDialog;
9import org.eclipse.swt.widgets.List;
10import org.eclipse.swt.widgets.MessageBox;
11import org.eclipse.swt.layout.GridLayout;
12import org.eclipse.swt.layout.GridData;
13import org.eclipse.swt.events.SelectionAdapter;
14import org.eclipse.swt.events.SelectionEvent;
15
16import de.ugoe.cs.quest.ui.GlobalDataContainer;
17import de.ugoe.cs.util.console.CommandExecuter;
18
19public class SequencesTabComposite extends Composite {
20       
21        protected List sequenceList;
22       
23        /**
24         * Create the composite.
25         * @param parent
26         * @param style
27         */
28        public SequencesTabComposite(Composite parent, int style) {
29                super(parent, style);
30                createContents();
31        }
32
33        private void createContents() {
34                setLayout(new GridLayout(5, false));
35               
36                sequenceList = new List(this, SWT.BORDER | SWT.V_SCROLL | SWT.MULTI);
37                sequenceList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 5, 1));
38                sequenceList.setItems(new String[] {});
39               
40                Button btnEdit = new Button(this, SWT.NONE);
41                btnEdit.addSelectionListener(new SelectionAdapter() {
42                        @Override
43                        public void widgetSelected(SelectionEvent e) {
44                                String[] selectedSequences = sequenceList.getSelection();
45                                if( selectedSequences.length==0 ) {
46                                        SWTHelpers.noSelectionError(getShell());
47                                }
48                                else if(selectedSequences.length>1) {
49                                        MessageBox messageBox = new MessageBox(getShell(), SWT.ERROR);
50                                        messageBox.setMessage("Only one sequence can be edited at a time!");
51                                        messageBox.setText("Error");
52                                        messageBox.open();
53                                } else {
54                                        SequencesDialog sequencesDialog = new SequencesDialog(getShell(), SWT.NONE);
55                                        sequencesDialog.open(selectedSequences[0]);
56                                }
57                        }
58                });
59                btnEdit.setText("Edit");
60               
61                Button btnDelete = new Button(this, SWT.NONE);
62                btnDelete.addSelectionListener(new SelectionAdapter() {
63                        @Override
64                        public void widgetSelected(SelectionEvent e) {
65                                if( SWTHelpers.deleteSelectedFromStorage(sequenceList)) {
66                                        updateSequenceList();
67                                } else {
68                                        SWTHelpers.noSelectionError(getShell());
69                                }
70                        }
71                });
72                btnDelete.setText("Delete");
73               
74                Button btnReplay = new Button(this, SWT.NONE);
75                btnReplay.addSelectionListener(new SelectionAdapter() {
76                        @Override
77                        public void widgetSelected(SelectionEvent e) {
78                                String[] selectedSequences = sequenceList.getSelection();
79                                if( selectedSequences.length==0 ) {
80                                        SWTHelpers.noSelectionError(getShell());
81                                } else {
82                                        StringBuilder commandString = new StringBuilder("generateReplayfile ");
83                                        FileDialog fileDialog = new FileDialog(getShell());
84                                        String filename = fileDialog.open();
85                                        commandString.append(filename + " ");
86                                        for( String selected : selectedSequences ) {
87                                                commandString.append(selected + " ");
88                                        }
89                                        CommandExecuter.getInstance().exec(commandString.toString().trim());
90                                }
91                        }
92                });
93                btnReplay.setText("Replay");
94               
95                Button btnTrainModel = new Button(this, SWT.NONE);
96                btnTrainModel.addSelectionListener(new SelectionAdapter() {
97                        @Override
98                        public void widgetSelected(SelectionEvent e) {
99                                String[] selectedSequences = sequenceList.getSelection();
100                                if( selectedSequences.length==0 ) {
101                                        SWTHelpers.noSelectionError(getShell());
102                                } else {
103                                        TrainModelDialog trainDialog = new TrainModelDialog(getShell(), SWT.NONE);
104                                        trainDialog.setSequenceNames(selectedSequences);
105                                        trainDialog.open();
106                                }
107                        }
108                });
109                btnTrainModel.setText("Train Model");
110               
111                Button btnParse = new Button(this, SWT.NONE);
112                btnParse.addSelectionListener(new SelectionAdapter() {
113                        @Override
114                        public void widgetSelected(SelectionEvent e) {
115                                // TODO implement parsing of sequences
116                                MessageBox messageBox = new MessageBox(getShell(), SWT.ICON_INFORMATION);
117                                messageBox.setText("Not implemented!");
118                                messageBox.setMessage("Sorry! This functionality has not been implemented yet!");
119                                messageBox.open();
120                        }
121                });
122                btnParse.setText("Parse");
123        }
124       
125        public void updateSequenceList() {
126                sequenceList.removeAll();
127                for( String sequencesName : GlobalDataContainer.getInstance().getAllSequencesNames() ) {
128                        sequenceList.add(sequencesName);
129                }
130        }
131       
132        @Override
133        protected void checkSubclass() {
134                // Disable the check that prevents subclassing of SWT components
135        }
136
137}
Note: See TracBrowser for help on using the repository browser.