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

Last change on this file since 750 was 750, checked in by sherbold, 12 years ago
  • added command cleanupKeyInteractions to handle invalid KeyPressed/KeyReleased? pairs
  • fixed minor bug in command condenseMouseClicks
  • fixed minor bug in command correctKeyInteractionTargets
  • fixed minor bug in command detectTextInputEvents
  • fixed minor bug in command sortKeyInteractions
  • beautified showing of sequences in SWT GUI
  • updated ArgoUML GUI Mappings
  • Property svn:mime-type set to text/plain
File size: 4.9 KB
Line 
1package de.ugoe.cs.quest.ui.swt;
2
3import java.util.Collection;
4
5import org.eclipse.swt.widgets.Dialog;
6import org.eclipse.swt.widgets.Display;
7import org.eclipse.swt.widgets.MessageBox;
8import org.eclipse.swt.widgets.Shell;
9import org.eclipse.swt.layout.GridLayout;
10import org.eclipse.swt.widgets.List;
11import org.eclipse.swt.SWT;
12import org.eclipse.swt.widgets.Button;
13import org.eclipse.swt.layout.GridData;
14
15import de.ugoe.cs.quest.SequenceInstanceOf;
16import de.ugoe.cs.quest.eventcore.Event;
17import de.ugoe.cs.quest.eventcore.guimodel.GUIModel;
18import de.ugoe.cs.util.console.GlobalDataContainer;
19
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 GUIModel guiModel;
30
31    protected Shell shell;
32
33    /**
34     * Create the dialog.
35     *
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     */
47    public void open(String sequencesName) {
48        this.sequencesName = sequencesName;
49        sequences = null;
50        createContents();
51        shell.open();
52        shell.layout();
53        Display display = getParent().getDisplay();
54        while (!shell.isDisposed()) {
55            if (!display.readAndDispatch()) {
56                display.sleep();
57            }
58        }
59    }
60
61    /**
62     * Create contents of the dialog.
63     */
64    private void createContents() {
65        shell = new Shell(getParent(), SWT.SHELL_TRIM | SWT.BORDER | SWT.APPLICATION_MODAL);
66        shell.setSize(248, 299);
67        shell.setText(getText());
68        shell.setLayout(new GridLayout(2, false));
69
70        sequenceList = new List(shell, SWT.BORDER | SWT.V_SCROLL);
71        sequenceList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
72        updateSequenceList();
73
74        Button btnShow = new Button(shell, SWT.NONE);
75        btnShow.addSelectionListener(new SelectionAdapter() {
76            @Override
77            public void widgetSelected(SelectionEvent e) {
78                int index = sequenceList.getSelectionIndex();
79                if (index == -1) {
80                    MessageBox messageBox = new MessageBox(shell, SWT.ERROR);
81                    messageBox.setMessage("No sequence selected!");
82                    messageBox.setText("Error");
83                    messageBox.open();
84                }
85                else {
86                    EditSequenceDialog editSequenceDialog =
87                        new EditSequenceDialog(shell, SWT.NONE, guiModel);
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 = Integer.toString(sequences.size()).length();
122            int counter = 1;
123            for (java.util.List<Event> sequence : sequences) {
124                String seqName =
125                    "#" + String.format("%0" + seqDigits + "d", counter) + ": " + sequence.size();
126                sequenceList.add(seqName);
127                counter++;
128            }
129            Object targetObject =
130                GlobalDataContainer.getInstance().getData(sequencesName + "_targets");
131            guiModel = null;
132            if (targetObject instanceof GUIModel) {
133                guiModel = (GUIModel) targetObject;
134            }
135        }
136        else {
137            MessageBox messageBox = new MessageBox(shell, SWT.ERROR);
138            messageBox.setMessage("Internal error. Sequences object not of expected type!");
139            messageBox.setText("Error");
140            messageBox.open();
141        }
142    }
143
144}
Note: See TracBrowser for help on using the repository browser.