1 | package de.ugoe.cs.eventbench.swt;
|
---|
2 |
|
---|
3 | import java.util.SortedSet;
|
---|
4 |
|
---|
5 | import org.eclipse.swt.widgets.Composite;
|
---|
6 | import org.eclipse.swt.widgets.FileDialog;
|
---|
7 | import org.eclipse.swt.layout.GridLayout;
|
---|
8 | import org.eclipse.swt.widgets.Label;
|
---|
9 | import org.eclipse.swt.SWT;
|
---|
10 | import org.eclipse.swt.widgets.Text;
|
---|
11 | import org.eclipse.swt.layout.GridData;
|
---|
12 | import org.eclipse.swt.widgets.Button;
|
---|
13 |
|
---|
14 | import de.ugoe.cs.eventbench.assertions.AssertEvent;
|
---|
15 | import de.ugoe.cs.eventbench.assertions.FileEqualsReplay;
|
---|
16 | import de.ugoe.cs.eventbench.data.Event;
|
---|
17 |
|
---|
18 | import org.eclipse.swt.events.SelectionAdapter;
|
---|
19 | import org.eclipse.swt.events.SelectionEvent;
|
---|
20 |
|
---|
21 | public class InsertFileEquals extends AbstractInsertEventComposite {
|
---|
22 | private Text actualText;
|
---|
23 | private Text expectedText;
|
---|
24 |
|
---|
25 | public InsertFileEquals(Composite parent, int style) {
|
---|
26 | this(parent, style, null);
|
---|
27 | }
|
---|
28 |
|
---|
29 | /**
|
---|
30 | * Create the composite.
|
---|
31 | * @param parent
|
---|
32 | * @param style
|
---|
33 | */
|
---|
34 | public InsertFileEquals(Composite parent, int style, SortedSet<String> targets) {
|
---|
35 | super(parent, style, targets);
|
---|
36 | setLayout(new GridLayout(3, false));
|
---|
37 |
|
---|
38 |
|
---|
39 | Label lblExpectedFile = new Label(this, SWT.NONE);
|
---|
40 | lblExpectedFile.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
|
---|
41 | lblExpectedFile.setText("Expected file:");
|
---|
42 |
|
---|
43 | expectedText = new Text(this, SWT.BORDER);
|
---|
44 | expectedText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
|
---|
45 |
|
---|
46 | Button btnSearch = new Button(this, SWT.NONE);
|
---|
47 | btnSearch.addSelectionListener(new SelectionAdapter() {
|
---|
48 | @Override
|
---|
49 | public void widgetSelected(SelectionEvent e) {
|
---|
50 | FileDialog fileDialog = new FileDialog(getShell(), SWT.OPEN);
|
---|
51 | String filename = fileDialog.open();
|
---|
52 | if( filename!= null ) {
|
---|
53 | expectedText.setText(filename);
|
---|
54 | }
|
---|
55 | }
|
---|
56 | });
|
---|
57 | btnSearch.setText("Search...");
|
---|
58 |
|
---|
59 | Label lblActualFile = new Label(this, SWT.NONE);
|
---|
60 |
|
---|
61 | lblActualFile.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
|
---|
62 | lblActualFile.setText("Actual file:");
|
---|
63 |
|
---|
64 | actualText = new Text(this, SWT.BORDER);
|
---|
65 | actualText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
|
---|
66 | new Label(this, SWT.NONE);
|
---|
67 |
|
---|
68 | }
|
---|
69 |
|
---|
70 | @Override
|
---|
71 | protected void checkSubclass() {
|
---|
72 | // Disable the check that prevents subclassing of SWT components
|
---|
73 | }
|
---|
74 |
|
---|
75 | @Override
|
---|
76 | public Event<?> getEvent() {
|
---|
77 | FileEqualsReplay replay = new FileEqualsReplay(expectedText.getText(), actualText.getText());
|
---|
78 | AssertEvent<FileEqualsReplay> event = new AssertEvent<FileEqualsReplay>("FileEqualsAssertion");
|
---|
79 | event.addReplayEvent(replay);
|
---|
80 | return event;
|
---|
81 | }
|
---|
82 |
|
---|
83 | }
|
---|