source: trunk/autoquest-ui-swt/src/main/java/de/ugoe/cs/autoquest/ui/swt/SequencesTabComposite.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.2 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.widgets.Composite;
18
19import org.eclipse.swt.SWT;
20import org.eclipse.swt.widgets.Button;
21import org.eclipse.swt.widgets.FileDialog;
22import org.eclipse.swt.widgets.List;
23import org.eclipse.swt.widgets.MessageBox;
24import org.eclipse.swt.layout.GridLayout;
25import org.eclipse.swt.layout.GridData;
26import org.eclipse.swt.events.SelectionAdapter;
27import org.eclipse.swt.events.SelectionEvent;
28
29import de.ugoe.cs.autoquest.SequenceInstanceOf;
30import de.ugoe.cs.util.console.CommandExecuter;
31import de.ugoe.cs.util.console.GlobalDataContainer;
32
33public class SequencesTabComposite extends Composite {
34
35    protected List sequenceList;
36
37    /**
38     * Create the composite.
39     *
40     * @param parent
41     * @param style
42     */
43    public SequencesTabComposite(Composite parent, int style) {
44        super(parent, style);
45        createContents();
46    }
47
48    private void createContents() {
49        setLayout(new GridLayout(5, false));
50
51        sequenceList = new List(this, SWT.BORDER | SWT.V_SCROLL | SWT.MULTI);
52        sequenceList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 5, 1));
53        sequenceList.setItems(new String[] { });
54
55        Button btnEdit = new Button(this, SWT.NONE);
56        btnEdit.addSelectionListener(new SelectionAdapter() {
57            @Override
58            public void widgetSelected(SelectionEvent e) {
59                String[] selectedSequences = sequenceList.getSelection();
60                if (selectedSequences.length == 0) {
61                    SWTHelpers.noSelectionError(getShell());
62                }
63                else if (selectedSequences.length > 1) {
64                    MessageBox messageBox = new MessageBox(getShell(), SWT.ERROR);
65                    messageBox.setMessage("Only one sequence can be edited at a time!");
66                    messageBox.setText("Error");
67                    messageBox.open();
68                }
69                else {
70                    SequencesDialog sequencesDialog = new SequencesDialog(getShell(), SWT.NONE);
71                    sequencesDialog.open(selectedSequences[0]);
72                }
73            }
74        });
75        btnEdit.setText("Edit");
76
77        Button btnDelete = new Button(this, SWT.NONE);
78        btnDelete.addSelectionListener(new SelectionAdapter() {
79            @Override
80            public void widgetSelected(SelectionEvent e) {
81                if (SWTHelpers.deleteSelectedFromStorage(sequenceList)) {
82                    updateSequenceList();
83                }
84                else {
85                    SWTHelpers.noSelectionError(getShell());
86                }
87            }
88        });
89        btnDelete.setText("Delete");
90
91        Button btnReplay = new Button(this, SWT.NONE);
92        btnReplay.addSelectionListener(new SelectionAdapter() {
93            @Override
94            public void widgetSelected(SelectionEvent e) {
95                String[] selectedSequences = sequenceList.getSelection();
96                if (selectedSequences.length == 0) {
97                    SWTHelpers.noSelectionError(getShell());
98                }
99                else {
100                    StringBuilder commandString = new StringBuilder("generateReplayfile ");
101                    FileDialog fileDialog = new FileDialog(getShell());
102                    String filename = fileDialog.open();
103                    commandString.append(filename + " ");
104                    for (String selected : selectedSequences) {
105                        commandString.append(selected + " ");
106                    }
107                    CommandExecuter.getInstance().exec(commandString.toString().trim());
108                }
109            }
110        });
111        btnReplay.setText("Replay");
112
113        Button btnTrainModel = new Button(this, SWT.NONE);
114        btnTrainModel.addSelectionListener(new SelectionAdapter() {
115            @Override
116            public void widgetSelected(SelectionEvent e) {
117                String[] selectedSequences = sequenceList.getSelection();
118                if (selectedSequences.length == 0) {
119                    SWTHelpers.noSelectionError(getShell());
120                }
121                else {
122                    TrainModelDialog trainDialog = new TrainModelDialog(getShell(), SWT.NONE);
123                    trainDialog.setSequenceNames(selectedSequences);
124                    trainDialog.open();
125                }
126            }
127        });
128        btnTrainModel.setText("Train Model");
129
130        Button btnParse = new Button(this, SWT.NONE);
131        btnParse.addSelectionListener(new SelectionAdapter() {
132            @Override
133            public void widgetSelected(SelectionEvent e) {
134                // TODO implement parsing of sequences
135                MessageBox messageBox = new MessageBox(getShell(), SWT.ICON_INFORMATION);
136                messageBox.setText("Not implemented!");
137                messageBox.setMessage("Sorry! This functionality has not been implemented yet!");
138                messageBox.open();
139            }
140        });
141        btnParse.setText("Parse");
142    }
143
144    public void updateSequenceList() {
145        sequenceList.removeAll();
146        for(String key : GlobalDataContainer.getInstance().getAllKeys()) {
147            if( SequenceInstanceOf.isCollectionOfSequences(GlobalDataContainer.getInstance().getData(key)) ) {
148                sequenceList.add(key);
149            }
150        }
151    }
152
153    @Override
154    protected void checkSubclass() {
155        // Disable the check that prevents subclassing of SWT components
156    }
157
158}
Note: See TracBrowser for help on using the repository browser.