[526] | 1 | package de.ugoe.cs.quest.ui.swt;
|
---|
| 2 |
|
---|
| 3 | import java.util.Collection;
|
---|
| 4 |
|
---|
| 5 | import org.eclipse.swt.widgets.Dialog;
|
---|
| 6 | import org.eclipse.swt.widgets.Display;
|
---|
| 7 | import org.eclipse.swt.widgets.MessageBox;
|
---|
| 8 | import org.eclipse.swt.widgets.Shell;
|
---|
| 9 | import org.eclipse.swt.layout.GridLayout;
|
---|
| 10 | import org.eclipse.swt.widgets.List;
|
---|
| 11 | import org.eclipse.swt.SWT;
|
---|
| 12 | import org.eclipse.swt.widgets.Button;
|
---|
| 13 | import org.eclipse.swt.layout.GridData;
|
---|
| 14 |
|
---|
| 15 | import de.ugoe.cs.quest.SequenceInstanceOf;
|
---|
| 16 | import de.ugoe.cs.quest.eventcore.Event;
|
---|
[659] | 17 | import de.ugoe.cs.quest.eventcore.guimodel.GUIModel;
|
---|
[667] | 18 | import de.ugoe.cs.util.console.GlobalDataContainer;
|
---|
[526] | 19 |
|
---|
| 20 | import org.eclipse.swt.events.SelectionAdapter;
|
---|
| 21 | import org.eclipse.swt.events.SelectionEvent;
|
---|
| 22 |
|
---|
| 23 | public class SequencesDialog extends Dialog {
|
---|
| 24 |
|
---|
[570] | 25 | private String sequencesName;
|
---|
[526] | 26 |
|
---|
[570] | 27 | private List sequenceList;
|
---|
| 28 | private Collection<java.util.List<Event>> sequences;
|
---|
[659] | 29 | private GUIModel guiModel;
|
---|
[526] | 30 |
|
---|
[570] | 31 | protected Shell shell;
|
---|
[526] | 32 |
|
---|
[570] | 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 | }
|
---|
[526] | 43 |
|
---|
[570] | 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 | }
|
---|
[526] | 60 |
|
---|
[570] | 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 =
|
---|
[659] | 87 | new EditSequenceDialog(shell, SWT.NONE, guiModel);
|
---|
[570] | 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");
|
---|
[659] | 131 | guiModel = null;
|
---|
| 132 | if (targetObject instanceof GUIModel) {
|
---|
| 133 | guiModel = (GUIModel) targetObject;
|
---|
[570] | 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 |
|
---|
[526] | 144 | }
|
---|