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 |
|
---|
15 | package de.ugoe.cs.autoquest.ui.swt;
|
---|
16 |
|
---|
17 | import org.eclipse.swt.widgets.Composite;
|
---|
18 | import org.eclipse.swt.widgets.FileDialog;
|
---|
19 | import org.eclipse.swt.layout.GridLayout;
|
---|
20 | import org.eclipse.swt.widgets.Label;
|
---|
21 | import org.eclipse.swt.SWT;
|
---|
22 | import org.eclipse.swt.widgets.Text;
|
---|
23 | import org.eclipse.swt.layout.GridData;
|
---|
24 | import org.eclipse.swt.widgets.Button;
|
---|
25 |
|
---|
26 | import de.ugoe.cs.autoquest.assertions.FileEqualsAssertEventType;
|
---|
27 | import de.ugoe.cs.autoquest.assertions.FileEqualsReplay;
|
---|
28 | import de.ugoe.cs.autoquest.eventcore.Event;
|
---|
29 | import de.ugoe.cs.autoquest.eventcore.guimodel.GUIModel;
|
---|
30 |
|
---|
31 | import org.eclipse.swt.events.SelectionAdapter;
|
---|
32 | import org.eclipse.swt.events.SelectionEvent;
|
---|
33 |
|
---|
34 | public class InsertFileEquals extends AbstractInsertEventComposite {
|
---|
35 | private Text actualText;
|
---|
36 | private Text expectedText;
|
---|
37 |
|
---|
38 | public InsertFileEquals(Composite parent, int style) {
|
---|
39 | this(parent, style, null);
|
---|
40 | }
|
---|
41 |
|
---|
42 | /**
|
---|
43 | * Create the composite.
|
---|
44 | *
|
---|
45 | * @param parent
|
---|
46 | * @param style
|
---|
47 | */
|
---|
48 | public InsertFileEquals(Composite parent, int style, GUIModel guiModel) {
|
---|
49 | super(parent, style, guiModel);
|
---|
50 | setLayout(new GridLayout(3, false));
|
---|
51 |
|
---|
52 | Label lblExpectedFile = new Label(this, SWT.NONE);
|
---|
53 | lblExpectedFile.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
|
---|
54 | lblExpectedFile.setText("Expected file:");
|
---|
55 |
|
---|
56 | expectedText = new Text(this, SWT.BORDER);
|
---|
57 | expectedText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
|
---|
58 |
|
---|
59 | Button btnSearch = new Button(this, SWT.NONE);
|
---|
60 | btnSearch.addSelectionListener(new SelectionAdapter() {
|
---|
61 | @Override
|
---|
62 | public void widgetSelected(SelectionEvent e) {
|
---|
63 | FileDialog fileDialog = new FileDialog(getShell(), SWT.OPEN);
|
---|
64 | String filename = fileDialog.open();
|
---|
65 | if (filename != null) {
|
---|
66 | expectedText.setText(filename);
|
---|
67 | }
|
---|
68 | }
|
---|
69 | });
|
---|
70 | btnSearch.setText("Search...");
|
---|
71 |
|
---|
72 | Label lblActualFile = new Label(this, SWT.NONE);
|
---|
73 |
|
---|
74 | lblActualFile.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
|
---|
75 | lblActualFile.setText("Actual file:");
|
---|
76 |
|
---|
77 | actualText = new Text(this, SWT.BORDER);
|
---|
78 | actualText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
|
---|
79 | new Label(this, SWT.NONE);
|
---|
80 |
|
---|
81 | }
|
---|
82 |
|
---|
83 | @Override
|
---|
84 | protected void checkSubclass() {
|
---|
85 | // Disable the check that prevents subclassing of SWT components
|
---|
86 | }
|
---|
87 |
|
---|
88 | @Override
|
---|
89 | public Event getEvent() {
|
---|
90 | FileEqualsReplay replay =
|
---|
91 | new FileEqualsReplay(expectedText.getText(), actualText.getText());
|
---|
92 | Event event = new Event(new FileEqualsAssertEventType());
|
---|
93 | event.addReplayable(replay);
|
---|
94 | return event;
|
---|
95 | }
|
---|
96 |
|
---|
97 | }
|
---|