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.layout.GridLayout;
|
---|
7 | import org.eclipse.swt.widgets.Label;
|
---|
8 | import org.eclipse.swt.SWT;
|
---|
9 | import org.eclipse.swt.widgets.Text;
|
---|
10 | import org.eclipse.swt.layout.GridData;
|
---|
11 | import org.eclipse.swt.widgets.Tree;
|
---|
12 | import org.eclipse.swt.widgets.Button;
|
---|
13 | import org.eclipse.swt.widgets.TreeItem;
|
---|
14 |
|
---|
15 | import de.ugoe.cs.eventbench.assertions.AssertEvent;
|
---|
16 | import de.ugoe.cs.eventbench.assertions.TextEqualsReplay;
|
---|
17 | import de.ugoe.cs.eventbench.data.Event;
|
---|
18 | import org.eclipse.swt.events.SelectionAdapter;
|
---|
19 | import org.eclipse.swt.events.SelectionEvent;
|
---|
20 |
|
---|
21 | public class InsertTextEquals extends AbstractInsertEventComposite {
|
---|
22 | private Text expectedText;
|
---|
23 | private Tree targetTree;
|
---|
24 | private Text targetText;
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * Create the composite.
|
---|
28 | * @param parent
|
---|
29 | * @param style
|
---|
30 | */
|
---|
31 | public InsertTextEquals(Composite parent, int style, SortedSet<String> targets) {
|
---|
32 | super(parent, style, targets);
|
---|
33 | setLayout(new GridLayout(3, false));
|
---|
34 |
|
---|
35 | Label lblExpectedValue = new Label(this, SWT.NONE);
|
---|
36 | lblExpectedValue.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
|
---|
37 | lblExpectedValue.setText("Expected Value:");
|
---|
38 |
|
---|
39 | expectedText = new Text(this, SWT.BORDER);
|
---|
40 | expectedText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
|
---|
41 |
|
---|
42 | Label lblTargetWidget = new Label(this, SWT.NONE);
|
---|
43 | lblTargetWidget.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
|
---|
44 | lblTargetWidget.setText("Target Widget:");
|
---|
45 |
|
---|
46 | targetText = new Text(this, SWT.BORDER);
|
---|
47 | targetText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
|
---|
48 | new Label(this, SWT.NONE);
|
---|
49 |
|
---|
50 | targetTree = new Tree(this, SWT.BORDER);
|
---|
51 | targetTree.addSelectionListener(new SelectionAdapter() {
|
---|
52 | @Override
|
---|
53 | public void widgetSelected(SelectionEvent e) {
|
---|
54 | TreeItem[] selection = targetTree.getSelection();
|
---|
55 | if( selection.length==1 ) {
|
---|
56 | TreeItem item = selection[0];
|
---|
57 | String targetString = item.getText();
|
---|
58 | item = item.getParentItem();
|
---|
59 | while( item!=null ) {
|
---|
60 | targetString = item.getText()+targetString;
|
---|
61 | item = item.getParentItem();
|
---|
62 | }
|
---|
63 | targetText.setText(targetString);
|
---|
64 | }
|
---|
65 | }
|
---|
66 | });
|
---|
67 | targetTree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
|
---|
68 | buildTargetTree();
|
---|
69 | new Label(this, SWT.NONE);
|
---|
70 |
|
---|
71 | Button btnExpandAll = new Button(this, SWT.NONE);
|
---|
72 | btnExpandAll.addSelectionListener(new SelectionAdapter() {
|
---|
73 | @Override
|
---|
74 | public void widgetSelected(SelectionEvent e) {
|
---|
75 | expandAll(targetTree, true);
|
---|
76 | }
|
---|
77 | });
|
---|
78 | btnExpandAll.setText("Expand all");
|
---|
79 |
|
---|
80 | Button btnCollapseAll = new Button(this, SWT.NONE);
|
---|
81 | btnCollapseAll.addSelectionListener(new SelectionAdapter() {
|
---|
82 | @Override
|
---|
83 | public void widgetSelected(SelectionEvent e) {
|
---|
84 | expandAll(targetTree, false);
|
---|
85 | }
|
---|
86 | });
|
---|
87 | btnCollapseAll.setText("Collapse all");
|
---|
88 |
|
---|
89 | }
|
---|
90 |
|
---|
91 | @Override
|
---|
92 | protected void checkSubclass() {
|
---|
93 | // Disable the check that prevents subclassing of SWT components
|
---|
94 | }
|
---|
95 |
|
---|
96 | @Override
|
---|
97 | public Event<?> getEvent() {
|
---|
98 | String target = targetText.getText();
|
---|
99 | TextEqualsReplay replay = new TextEqualsReplay(expectedText.getText(), target);
|
---|
100 | AssertEvent<TextEqualsReplay> event = new AssertEvent<TextEqualsReplay>("TextEqualsAssertion");
|
---|
101 | event.setTarget(target);
|
---|
102 | event.addReplayEvent(replay);
|
---|
103 | return event;
|
---|
104 | }
|
---|
105 |
|
---|
106 | private void buildTargetTree() {
|
---|
107 | for( String target : targets ) {
|
---|
108 | TreeItem item = new TreeItem(targetTree, SWT.NULL);
|
---|
109 | item.setText(target);
|
---|
110 | // TODO needs rule that "splits" targets if necessary
|
---|
111 | }
|
---|
112 |
|
---|
113 | }
|
---|
114 |
|
---|
115 | private void expandAll(Tree tree, boolean expanded) {
|
---|
116 | for( TreeItem item : tree.getItems() ) {
|
---|
117 | expandAll(item, expanded);
|
---|
118 | }
|
---|
119 | }
|
---|
120 |
|
---|
121 | private void expandAll(TreeItem item, boolean expanded) {
|
---|
122 | item.setExpanded(expanded);
|
---|
123 | for( TreeItem childItem : item.getItems() ) {
|
---|
124 | expandAll(childItem, expanded);
|
---|
125 | }
|
---|
126 | }
|
---|
127 |
|
---|
128 |
|
---|
129 | }
|
---|