[570] | 1 |
|
---|
[526] | 2 | package de.ugoe.cs.quest.ui.swt;
|
---|
| 3 |
|
---|
| 4 | import java.util.SortedSet;
|
---|
| 5 |
|
---|
| 6 | import org.eclipse.swt.widgets.Composite;
|
---|
| 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.Tree;
|
---|
| 13 | import org.eclipse.swt.widgets.Button;
|
---|
| 14 | import org.eclipse.swt.widgets.TreeItem;
|
---|
| 15 |
|
---|
[548] | 16 | import de.ugoe.cs.quest.assertions.TextEqualsAssertEventType;
|
---|
[526] | 17 | import de.ugoe.cs.quest.eventcore.Event;
|
---|
| 18 | import de.ugoe.cs.util.ArrayTools;
|
---|
| 19 |
|
---|
| 20 | import org.eclipse.swt.events.SelectionAdapter;
|
---|
| 21 | import org.eclipse.swt.events.SelectionEvent;
|
---|
| 22 |
|
---|
| 23 | public class InsertTextEquals extends AbstractInsertEventComposite {
|
---|
[570] | 24 | private Text expectedText;
|
---|
| 25 | private Tree targetTree;
|
---|
| 26 | private Text targetText;
|
---|
[526] | 27 |
|
---|
[570] | 28 | /**
|
---|
| 29 | * Create the composite.
|
---|
| 30 | *
|
---|
| 31 | * @param parent
|
---|
| 32 | * @param style
|
---|
| 33 | */
|
---|
| 34 | public InsertTextEquals(Composite parent, int style, SortedSet<String> targets) {
|
---|
| 35 | super(parent, style, targets);
|
---|
| 36 | setLayout(new GridLayout(3, false));
|
---|
[526] | 37 |
|
---|
[570] | 38 | Label lblExpectedValue = new Label(this, SWT.NONE);
|
---|
| 39 | lblExpectedValue.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
|
---|
| 40 | lblExpectedValue.setText("Expected Value:");
|
---|
[526] | 41 |
|
---|
[570] | 42 | expectedText = new Text(this, SWT.BORDER);
|
---|
| 43 | expectedText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
|
---|
[526] | 44 |
|
---|
[570] | 45 | Label lblTargetWidget = new Label(this, SWT.NONE);
|
---|
| 46 | lblTargetWidget.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
|
---|
| 47 | lblTargetWidget.setText("Target Widget:");
|
---|
| 48 |
|
---|
| 49 | targetText = new Text(this, SWT.BORDER);
|
---|
| 50 | targetText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
|
---|
| 51 | new Label(this, SWT.NONE);
|
---|
| 52 |
|
---|
| 53 | targetTree = new Tree(this, SWT.BORDER);
|
---|
| 54 | targetTree.addSelectionListener(new SelectionAdapter() {
|
---|
| 55 | @Override
|
---|
| 56 | public void widgetSelected(SelectionEvent e) {
|
---|
| 57 | TreeItem[] selection = targetTree.getSelection();
|
---|
| 58 | if (selection.length == 1) {
|
---|
| 59 | TreeItem item = selection[0];
|
---|
| 60 | String targetString = item.getText();
|
---|
| 61 | item = item.getParentItem();
|
---|
| 62 | while (item != null) {
|
---|
| 63 | // TODO the "." is hard coded for the JFCMonitor. should be flexible
|
---|
| 64 | targetString = item.getText() + "." + targetString;
|
---|
| 65 | item = item.getParentItem();
|
---|
| 66 | }
|
---|
| 67 | targetText.setText(targetString);
|
---|
| 68 | }
|
---|
| 69 | }
|
---|
| 70 | });
|
---|
| 71 | targetTree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
|
---|
| 72 | buildTargetTree();
|
---|
| 73 | new Label(this, SWT.NONE);
|
---|
| 74 |
|
---|
| 75 | Button btnExpandAll = new Button(this, SWT.NONE);
|
---|
| 76 | btnExpandAll.addSelectionListener(new SelectionAdapter() {
|
---|
| 77 | @Override
|
---|
| 78 | public void widgetSelected(SelectionEvent e) {
|
---|
| 79 | expandAll(targetTree, true);
|
---|
| 80 | }
|
---|
| 81 | });
|
---|
| 82 | btnExpandAll.setText("Expand all");
|
---|
| 83 |
|
---|
| 84 | Button btnCollapseAll = new Button(this, SWT.NONE);
|
---|
| 85 | btnCollapseAll.addSelectionListener(new SelectionAdapter() {
|
---|
| 86 | @Override
|
---|
| 87 | public void widgetSelected(SelectionEvent e) {
|
---|
| 88 | expandAll(targetTree, false);
|
---|
| 89 | }
|
---|
| 90 | });
|
---|
| 91 | btnCollapseAll.setText("Collapse all");
|
---|
| 92 |
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | @Override
|
---|
| 96 | protected void checkSubclass() {
|
---|
| 97 | // Disable the check that prevents subclassing of SWT components
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | @Override
|
---|
| 101 | public Event getEvent() {
|
---|
| 102 | // TODO make compatible to new event core
|
---|
| 103 | /*
|
---|
| 104 | * IEventTarget target = targetText.getText(); TextEqualsReplay replay = new
|
---|
| 105 | * TextEqualsReplay(expectedText.getText(), target);
|
---|
| 106 | */
|
---|
| 107 | Event event = new Event(new TextEqualsAssertEventType());
|
---|
| 108 | /*
|
---|
| 109 | * event.setTarget(target); event.addReplayable(replay);
|
---|
| 110 | */
|
---|
| 111 | return event;
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | private void buildTargetTree() {
|
---|
| 115 | for (String target : targets) {
|
---|
| 116 | TreeItem currentParent = null;
|
---|
| 117 | TreeItem[] currentItems = targetTree.getItems();
|
---|
| 118 |
|
---|
| 119 | // TODO needs rule for target splitting. currently its hard coded for JFCEvent targets.
|
---|
| 120 | String[] targetParts = target.split("\\.\\[");
|
---|
| 121 | for (String targetPart : targetParts) {
|
---|
| 122 | String[] currentTexts = new String[currentItems.length];
|
---|
| 123 | for (int i = 0; i < currentItems.length; i++) {
|
---|
| 124 | currentTexts[i] = currentItems[i].getText();
|
---|
| 125 | }
|
---|
| 126 | if (currentParent != null) {
|
---|
| 127 | targetPart = "[" + targetPart;
|
---|
| 128 | }
|
---|
| 129 | int index = ArrayTools.findIndex(currentTexts, targetPart);
|
---|
| 130 | if (index >= 0) {
|
---|
| 131 | currentParent = currentItems[index];
|
---|
| 132 | }
|
---|
| 133 | else {
|
---|
| 134 | if (currentParent == null) {
|
---|
| 135 | currentParent = new TreeItem(targetTree, SWT.NULL);
|
---|
| 136 | currentParent.setText(targetPart);
|
---|
| 137 | }
|
---|
| 138 | else {
|
---|
| 139 | currentParent = new TreeItem(currentParent, SWT.NULL);
|
---|
| 140 | currentParent.setText(targetPart);
|
---|
| 141 | }
|
---|
| 142 | }
|
---|
| 143 | currentItems = currentParent.getItems();
|
---|
| 144 | }
|
---|
| 145 | }
|
---|
| 146 |
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 | private void expandAll(Tree tree, boolean expanded) {
|
---|
| 150 | for (TreeItem item : tree.getItems()) {
|
---|
| 151 | expandAll(item, expanded);
|
---|
| 152 | }
|
---|
| 153 | }
|
---|
| 154 |
|
---|
| 155 | private void expandAll(TreeItem item, boolean expanded) {
|
---|
| 156 | item.setExpanded(expanded);
|
---|
| 157 | for (TreeItem childItem : item.getItems()) {
|
---|
| 158 | expandAll(childItem, expanded);
|
---|
| 159 | }
|
---|
| 160 | }
|
---|
| 161 |
|
---|
[526] | 162 | }
|
---|