source: trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/swt/SequencesDialog.java @ 230

Last change on this file since 230 was 230, checked in by sherbold, 13 years ago
  • extended SWT-GUI with dialogs for editing sequences and adding of assertions

Comment for Revision 229 (comment missing due to Subversive bug):

  • changed de.ugoe.cs.eventbench.assertions.FileEqualsReplay? and de.ugoe.cs.eventbench.assertions.TextEqualsReplay? such that the actual and expected values are now defined via the constructor
  • changed storage method for targets that are found during the parsing of MFC usage log files. If the sequences are stored in the variable "seqsName" the targets are stored in the variable "seqsName_targets"
  • adapted classes in de.ugoe.cs.eventbench.swing to the changes above
  • marked the classes in de.ugoe.cs.eventbench.swing as deprecated as the Swing GUI will not be part of further maintenance. Use the SWT GUI instead.
  • Property svn:mime-type set to text/plain
File size: 4.4 KB
Line 
1package de.ugoe.cs.eventbench.swt;
2
3import java.util.Collection;
4import java.util.SortedSet;
5import java.util.TreeSet;
6
7import org.eclipse.swt.widgets.Dialog;
8import org.eclipse.swt.widgets.Display;
9import org.eclipse.swt.widgets.MessageBox;
10import org.eclipse.swt.widgets.Shell;
11import org.eclipse.swt.layout.GridLayout;
12import org.eclipse.swt.widgets.List;
13import org.eclipse.swt.SWT;
14import org.eclipse.swt.widgets.Button;
15import org.eclipse.swt.layout.GridData;
16
17import de.ugoe.cs.eventbench.SequenceInstanceOf;
18import de.ugoe.cs.eventbench.data.Event;
19import de.ugoe.cs.eventbench.data.GlobalDataContainer;
20import org.eclipse.swt.events.SelectionAdapter;
21import org.eclipse.swt.events.SelectionEvent;
22
23public class SequencesDialog extends Dialog {
24
25        private String sequencesName;
26       
27        private List sequenceList;
28        private Collection<java.util.List<Event<?>>> sequences;
29        private SortedSet<String> targets;
30       
31        protected Object result;
32        protected Shell shell;
33
34        /**
35         * Create the dialog.
36         * @param parent
37         * @param style
38         */
39        public SequencesDialog(Shell parent, int style) {
40                super(parent, style);
41                setText("SWT Dialog");
42        }
43
44        /**
45         * Open the dialog.
46         * @return the result
47         */
48        public Object open(String sequencesName) {
49                this.sequencesName = sequencesName;
50                sequences = null;
51                createContents();
52                shell.open();
53                shell.layout();
54                Display display = getParent().getDisplay();
55                while (!shell.isDisposed()) {
56                        if (!display.readAndDispatch()) {
57                                display.sleep();
58                        }
59                }
60                return result;
61        }
62
63        /**
64         * Create contents of the dialog.
65         */
66        private void createContents() {
67                shell = new Shell(getParent(), SWT.SHELL_TRIM | SWT.BORDER | SWT.APPLICATION_MODAL);
68                shell.setSize(248, 299);
69                shell.setText(getText());
70                shell.setLayout(new GridLayout(2, false));
71               
72                sequenceList = new List(shell, SWT.BORDER | SWT.V_SCROLL);
73                sequenceList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
74                updateSequenceList();
75               
76                Button btnShow = new Button(shell, SWT.NONE);
77                btnShow.addSelectionListener(new SelectionAdapter() {
78                        @Override
79                        public void widgetSelected(SelectionEvent e) {
80                                int index = sequenceList.getSelectionIndex();
81                                if( index==-1 ) {
82                                        MessageBox messageBox = new MessageBox(shell, SWT.ERROR);
83                                        messageBox.setMessage("No sequence selected!");
84                                        messageBox.setText("Error");
85                                        messageBox.open();
86                                } else {
87                                        EditSequenceDialog editSequenceDialog = new EditSequenceDialog(shell, SWT.NONE, targets);
88                                        int counter = 0;
89                                        java.util.List<Event<?>> selectedSequence = null;
90                                        for( java.util.List<Event<?>> sequence : sequences ) {
91                                                if( counter==index ) {
92                                                        selectedSequence = sequence;
93                                                        break;
94                                                }
95                                                counter++;
96                                        }
97                                        editSequenceDialog.open(selectedSequence);
98                                        updateSequenceList();
99                                }
100                        }
101                });
102                btnShow.setText("Show");
103               
104                Button btnClose = new Button(shell, SWT.NONE);
105                btnClose.addSelectionListener(new SelectionAdapter() {
106                        @Override
107                        public void widgetSelected(SelectionEvent e) {
108                                shell.dispose();
109                        }
110                });
111                btnClose.setText("Close");
112
113        }
114       
115        @SuppressWarnings("unchecked")
116        private void updateSequenceList() {
117                sequenceList.removeAll();
118                Object dataObject = GlobalDataContainer.getInstance().getData(sequencesName);
119                if( SequenceInstanceOf.isCollectionOfSequences(dataObject)) {
120                        sequences = (Collection<java.util.List<Event<?>>>) dataObject;
121                        int seqDigits = 4; // TODO calculate seqDigits dynamically
122                        int counter = 1;
123                        for( java.util.List<Event<?>> sequence : sequences ) {
124                                String seqName = "#"+Integer.toString(counter, seqDigits)+": "+sequence.size();
125                                sequenceList.add(seqName);
126                                counter++;
127                        }
128                        Object targetObject = GlobalDataContainer.getInstance().getData(sequencesName+"_targets");
129                        targets = null;
130                        if( targetObject instanceof SortedSet ) {
131                                if( !((SortedSet<?>) targetObject).isEmpty() ) {
132                                        if( ((SortedSet<?>) targetObject).first() instanceof String ) {
133                                                targets = (SortedSet<String>) targetObject;
134                                        }
135                                }
136                        }
137                        if( targets==null ) {
138                                targets = new TreeSet<String>();
139                                for( java.util.List<Event<?>> sequence : sequences ) {
140                                        for( Event<?> event : sequence ) {
141                                                String target = event.getTarget();
142                                                if( target!=null ) {
143                                                        targets.add(target);
144                                                }
145                                        }
146                                }
147                        }
148                } else {
149                        // TODO this should not happen - needs to be handled anyways
150                }
151        }
152
153}
Note: See TracBrowser for help on using the repository browser.