source: trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/swt/InsertTextEquals.java @ 293

Last change on this file since 293 was 230, checked in by sherbold, 13 years ago
  • extended SWT-GUI with dialogs for editing sequences and adding of assertions

Comment for Revision 229 (comment missing due to Subversive bug):

  • changed de.ugoe.cs.eventbench.assertions.FileEqualsReplay? and de.ugoe.cs.eventbench.assertions.TextEqualsReplay? such that the actual and expected values are now defined via the constructor
  • changed storage method for targets that are found during the parsing of MFC usage log files. If the sequences are stored in the variable "seqsName" the targets are stored in the variable "seqsName_targets"
  • adapted classes in de.ugoe.cs.eventbench.swing to the changes above
  • marked the classes in de.ugoe.cs.eventbench.swing as deprecated as the Swing GUI will not be part of further maintenance. Use the SWT GUI instead.
  • Property svn:mime-type set to text/plain
File size: 3.9 KB
Line 
1package de.ugoe.cs.eventbench.swt;
2
3import java.util.SortedSet;
4
5import org.eclipse.swt.widgets.Composite;
6import org.eclipse.swt.layout.GridLayout;
7import org.eclipse.swt.widgets.Label;
8import org.eclipse.swt.SWT;
9import org.eclipse.swt.widgets.Text;
10import org.eclipse.swt.layout.GridData;
11import org.eclipse.swt.widgets.Tree;
12import org.eclipse.swt.widgets.Button;
13import org.eclipse.swt.widgets.TreeItem;
14
15import de.ugoe.cs.eventbench.assertions.AssertEvent;
16import de.ugoe.cs.eventbench.assertions.TextEqualsReplay;
17import de.ugoe.cs.eventbench.data.Event;
18import org.eclipse.swt.events.SelectionAdapter;
19import org.eclipse.swt.events.SelectionEvent;
20
21public 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}
Note: See TracBrowser for help on using the repository browser.