Changeset 659 for trunk/quest-ui-swt


Ignore:
Timestamp:
08/28/12 10:42:56 (12 years ago)
Author:
sherbold
Message:
  • modified adding of assertions to work with GUI models. As a side effect, it is currently impossible to add assertions to sequences whose event targets are not based on a GUI model
Location:
trunk/quest-ui-swt/src/main/java/de/ugoe/cs/quest/ui/swt
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/quest-ui-swt/src/main/java/de/ugoe/cs/quest/ui/swt/AbstractInsertEventComposite.java

    r655 r659  
    11package de.ugoe.cs.quest.ui.swt; 
    2  
    3 import java.util.SortedSet; 
    42 
    53import org.eclipse.swt.widgets.Composite; 
    64 
    75import de.ugoe.cs.quest.eventcore.Event; 
     6import de.ugoe.cs.quest.eventcore.guimodel.GUIModel; 
    87 
    98abstract public class AbstractInsertEventComposite extends Composite { 
    109 
    11     protected SortedSet<String> targets; 
     10    protected GUIModel guiModel; 
    1211 
    13     public AbstractInsertEventComposite(Composite parent, int style, SortedSet<String> targets) { 
     12    public AbstractInsertEventComposite(Composite parent, int style, GUIModel guiModel) { 
    1413        super(parent, style); 
    15         this.targets = targets; 
     14        this.guiModel = guiModel; 
    1615    } 
    1716 
  • trunk/quest-ui-swt/src/main/java/de/ugoe/cs/quest/ui/swt/EditSequenceDialog.java

    r655 r659  
    11package de.ugoe.cs.quest.ui.swt; 
    2  
    3 import java.util.SortedSet; 
    42 
    53import org.eclipse.swt.widgets.Dialog; 
     
    2018 
    2119import de.ugoe.cs.quest.eventcore.Event; 
     20import de.ugoe.cs.quest.eventcore.guimodel.GUIModel; 
    2221 
    2322public class EditSequenceDialog extends Dialog { 
     
    2928 
    3029    private java.util.List<Event> sequence; 
    31     private SortedSet<String> targets; 
     30    private GUIModel guiModel; 
    3231 
    3332    /** 
     
    3736     * @param style 
    3837     */ 
    39     public EditSequenceDialog(Shell parent, int style, SortedSet<String> targets) { 
     38    public EditSequenceDialog(Shell parent, int style, GUIModel guiModel) { 
    4039        super(parent, style); 
    4140        setText("SWT Dialog"); 
    42         this.targets = targets; 
     41        this.guiModel = guiModel; 
    4342    } 
    4443 
     
    169168        for (Event event : sequence) { 
    170169            TableItem tableItem = new TableItem(table, SWT.NONE); 
    171             // TODO check if toString is sufficient 
    172             String target = event.getTarget().toString(); 
     170            String target = null; 
     171            if( event.getTarget()!=null ) { 
     172                target = event.getTarget().toString(); 
     173            } 
    173174            if (target != null) { 
    174175                // the target is split into multiple lines, as one line may 
     
    185186 
    186187    private void openInsertDialog(int position) { 
    187         InsertAssertionDialog insertDialog = new InsertAssertionDialog(shell, SWT.NONE, targets); 
     188        InsertAssertionDialog insertDialog = new InsertAssertionDialog(shell, SWT.NONE, guiModel); 
    188189        Event event = insertDialog.open(); 
    189190        if (event != null) { 
  • trunk/quest-ui-swt/src/main/java/de/ugoe/cs/quest/ui/swt/InsertAssertionDialog.java

    r655 r659  
    33import java.util.ArrayList; 
    44import java.util.List; 
    5 import java.util.SortedSet; 
    65 
    76import org.eclipse.swt.widgets.Dialog; 
     
    1817 
    1918import de.ugoe.cs.quest.eventcore.Event; 
     19import de.ugoe.cs.quest.eventcore.guimodel.GUIModel; 
    2020 
    2121public class InsertAssertionDialog extends Dialog { 
     
    2727 
    2828    List<AbstractInsertEventComposite> insertEventComposites; 
    29     SortedSet<String> targets; 
     29    GUIModel guiModel; 
    3030 
    3131    /** 
     
    3535     * @param style 
    3636     */ 
    37     public InsertAssertionDialog(Shell parent, int style, SortedSet<String> targets) { 
     37    public InsertAssertionDialog(Shell parent, int style, GUIModel guiModel) { 
    3838        super(parent, style); 
    3939        setText("SWT Dialog"); 
    40         this.targets = targets; 
     40        this.guiModel = guiModel; 
    4141    } 
    4242 
     
    7676        tbtmTextEquals.setText("TextEquals"); 
    7777        AbstractInsertEventComposite compTextEquals = 
    78             new InsertTextEquals(tabFolder, SWT.NO_BACKGROUND, targets); 
     78            new InsertTextEquals(tabFolder, SWT.NO_BACKGROUND, guiModel); 
    7979        tbtmTextEquals.setControl(compTextEquals); 
    8080        insertEventComposites.add(compTextEquals); 
     
    8383        tbtmFileEquals.setText("FileEquals"); 
    8484        AbstractInsertEventComposite compFileEquals = 
    85             new InsertFileEquals(tabFolder, SWT.NO_BACKGROUND, targets); 
     85            new InsertFileEquals(tabFolder, SWT.NO_BACKGROUND, guiModel); 
    8686        tbtmFileEquals.setControl(compFileEquals); 
    8787        insertEventComposites.add(compFileEquals); 
  • trunk/quest-ui-swt/src/main/java/de/ugoe/cs/quest/ui/swt/InsertFileEquals.java

    r657 r659  
    11package de.ugoe.cs.quest.ui.swt; 
    2  
    3 import java.util.SortedSet; 
    42 
    53import org.eclipse.swt.widgets.Composite; 
     
    1513import de.ugoe.cs.quest.assertions.FileEqualsReplay; 
    1614import de.ugoe.cs.quest.eventcore.Event; 
     15import de.ugoe.cs.quest.eventcore.guimodel.GUIModel; 
    1716 
    1817import org.eclipse.swt.events.SelectionAdapter; 
     
    3332     * @param style 
    3433     */ 
    35     public InsertFileEquals(Composite parent, int style, SortedSet<String> targets) { 
    36         super(parent, style, targets); 
     34    public InsertFileEquals(Composite parent, int style, GUIModel guiModel) { 
     35        super(parent, style, guiModel); 
    3736        setLayout(new GridLayout(3, false)); 
    3837 
  • trunk/quest-ui-swt/src/main/java/de/ugoe/cs/quest/ui/swt/InsertTextEquals.java

    r655 r659  
     1 
    12package de.ugoe.cs.quest.ui.swt; 
    23 
    3 import java.util.SortedSet; 
     4import java.util.List; 
    45 
    56import org.eclipse.swt.widgets.Composite; 
     
    1415 
    1516import de.ugoe.cs.quest.assertions.TextEqualsAssertEventType; 
     17import de.ugoe.cs.quest.assertions.TextEqualsReplay; 
    1618import de.ugoe.cs.quest.eventcore.Event; 
    17 import de.ugoe.cs.util.ArrayTools; 
     19import de.ugoe.cs.quest.eventcore.IEventTarget; 
     20import de.ugoe.cs.quest.eventcore.guimodel.GUIModel; 
     21import de.ugoe.cs.quest.eventcore.guimodel.IGUIElement; 
    1822 
    1923import org.eclipse.swt.events.SelectionAdapter; 
     
    2226public class InsertTextEquals extends AbstractInsertEventComposite { 
    2327    private Text expectedText; 
    24     private Tree targetTree; 
    25     private Text targetText; 
     28    private Tree guiTree; 
    2629 
    2730    /** 
     
    3134     * @param style 
    3235     */ 
    33     public InsertTextEquals(Composite parent, int style, SortedSet<String> targets) { 
    34         super(parent, style, targets); 
     36    public InsertTextEquals(Composite parent, int style, GUIModel guiModel) { 
     37        super(parent, style, guiModel); 
    3538        setLayout(new GridLayout(3, false)); 
    3639 
     
    4245        expectedText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1)); 
    4346 
    44         Label lblTargetWidget = new Label(this, SWT.NONE); 
    45         lblTargetWidget.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); 
    46         lblTargetWidget.setText("Target Widget:"); 
    47  
    48         targetText = new Text(this, SWT.BORDER); 
    49         targetText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1)); 
    50         new Label(this, SWT.NONE); 
    51  
    52         targetTree = new Tree(this, SWT.BORDER); 
    53         targetTree.addSelectionListener(new SelectionAdapter() { 
    54             @Override 
    55             public void widgetSelected(SelectionEvent e) { 
    56                 TreeItem[] selection = targetTree.getSelection(); 
    57                 if (selection.length == 1) { 
    58                     TreeItem item = selection[0]; 
    59                     String targetString = item.getText(); 
    60                     item = item.getParentItem(); 
    61                     while (item != null) { 
    62                         // TODO the "." is hard coded for the JFCMonitor. should be flexible 
    63                         targetString = item.getText() + "." + targetString; 
    64                         item = item.getParentItem(); 
    65                     } 
    66                     targetText.setText(targetString); 
    67                 } 
    68             } 
    69         }); 
    70         targetTree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); 
    71         buildTargetTree(); 
     47        guiTree = new Tree(this, SWT.BORDER); 
     48        guiTree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); 
     49        buildGuiTree(); 
    7250        new Label(this, SWT.NONE); 
    7351 
     
    7654            @Override 
    7755            public void widgetSelected(SelectionEvent e) { 
    78                 expandAll(targetTree, true); 
     56                expandAll(guiTree, true); 
    7957            } 
    8058        }); 
     
    8563            @Override 
    8664            public void widgetSelected(SelectionEvent e) { 
    87                 expandAll(targetTree, false); 
     65                expandAll(guiTree, false); 
    8866            } 
    8967        }); 
     
    9977    @Override 
    10078    public Event getEvent() { 
    101         // TODO make compatible to new event core 
    102         /* 
    103          * IEventTarget target = targetText.getText(); TextEqualsReplay replay = new 
    104          * TextEqualsReplay(expectedText.getText(), target); 
    105          */ 
    106         Event event = new Event(new TextEqualsAssertEventType()); 
    107         /* 
    108          * event.setTarget(target); event.addReplayable(replay); 
    109          */ 
     79        // TODO possibly display error if no target is selected 
     80        TreeItem[] selection = guiTree.getSelection(); 
     81        IEventTarget target = null; 
     82        TextEqualsReplay replay = null; 
     83        if (selection.length == 1) { 
     84            target = (IEventTarget) selection[0].getData(); 
     85            replay = new TextEqualsReplay(expectedText.getText(), target.toString()); 
     86        } 
     87 
     88        Event event = new Event(new TextEqualsAssertEventType(), target); 
     89 
     90        event.setTarget(target); 
     91        if (replay != null) { 
     92            event.addReplayable(replay); 
     93        } 
     94 
    11095        return event; 
    11196    } 
    11297 
    113     private void buildTargetTree() { 
    114         for (String target : targets) { 
    115             TreeItem currentParent = null; 
    116             TreeItem[] currentItems = targetTree.getItems(); 
     98    private void buildGuiTree() { 
     99        for (IGUIElement element : guiModel.getRootElements()) { 
     100            TreeItem child = new TreeItem(guiTree, SWT.NULL); 
     101            child.setText(element.toString()); 
     102            child.setData(element); 
     103            buildGuiTree(child, guiModel.getChildren(element)); 
     104        } 
     105    } 
    117106 
    118             // TODO needs rule for target splitting. currently its hard coded for JFCEvent targets. 
    119             String[] targetParts = target.split("\\.\\["); 
    120             for (String targetPart : targetParts) { 
    121                 String[] currentTexts = new String[currentItems.length]; 
    122                 for (int i = 0; i < currentItems.length; i++) { 
    123                     currentTexts[i] = currentItems[i].getText(); 
    124                 } 
    125                 if (currentParent != null) { 
    126                     targetPart = "[" + targetPart; 
    127                 } 
    128                 int index = ArrayTools.findIndex(currentTexts, targetPart); 
    129                 if (index >= 0) { 
    130                     currentParent = currentItems[index]; 
    131                 } 
    132                 else { 
    133                     if (currentParent == null) { 
    134                         currentParent = new TreeItem(targetTree, SWT.NULL); 
    135                         currentParent.setText(targetPart); 
    136                     } 
    137                     else { 
    138                         currentParent = new TreeItem(currentParent, SWT.NULL); 
    139                         currentParent.setText(targetPart); 
    140                     } 
    141                 } 
    142                 currentItems = currentParent.getItems(); 
    143             } 
     107    private void buildGuiTree(TreeItem currentParent, List<IGUIElement> elements) { 
     108        for (IGUIElement element : elements) { 
     109            TreeItem child = new TreeItem(currentParent, SWT.NULL); 
     110            child.setText(element.toString()); 
     111            child.setData(element); 
     112            buildGuiTree(child, guiModel.getChildren(element)); 
    144113        } 
    145  
    146114    } 
    147115 
  • trunk/quest-ui-swt/src/main/java/de/ugoe/cs/quest/ui/swt/SequencesDialog.java

    r655 r659  
    22 
    33import java.util.Collection; 
    4 import java.util.SortedSet; 
    5 import java.util.TreeSet; 
    64 
    75import org.eclipse.swt.widgets.Dialog; 
     
    1715import de.ugoe.cs.quest.SequenceInstanceOf; 
    1816import de.ugoe.cs.quest.eventcore.Event; 
     17import de.ugoe.cs.quest.eventcore.guimodel.GUIModel; 
    1918import de.ugoe.cs.quest.ui.GlobalDataContainer; 
    2019 
     
    2827    private List sequenceList; 
    2928    private Collection<java.util.List<Event>> sequences; 
    30     private SortedSet<String> targets; 
     29    private GUIModel guiModel; 
    3130 
    3231    protected Shell shell; 
     
    8685                else { 
    8786                    EditSequenceDialog editSequenceDialog = 
    88                         new EditSequenceDialog(shell, SWT.NONE, targets); 
     87                        new EditSequenceDialog(shell, SWT.NONE, guiModel); 
    8988                    int counter = 0; 
    9089                    java.util.List<Event> selectedSequence = null; 
     
    130129            Object targetObject = 
    131130                GlobalDataContainer.getInstance().getData(sequencesName + "_targets"); 
    132             targets = null; 
    133             if (targetObject instanceof SortedSet) { 
    134                 if (!((SortedSet<?>) targetObject).isEmpty()) { 
    135                     if (((SortedSet<?>) targetObject).first() instanceof String) { 
    136                         targets = (SortedSet<String>) targetObject; 
    137                     } 
    138                 } 
     131            guiModel = null; 
     132            if (targetObject instanceof GUIModel) { 
     133                guiModel = (GUIModel) targetObject; 
    139134            } 
    140             if (targets == null) { 
    141                 targets = new TreeSet<String>(); 
    142                 for (java.util.List<Event> sequence : sequences) { 
    143                     for (Event event : sequence) { 
    144                         // TODO check if toString() is sufficient 
    145                         String target = event.getTarget().toString(); 
    146                         if (target != null) { 
    147                             targets.add(target); 
    148                         } 
    149                     } 
    150                 } 
     135            if (guiModel == null) { 
     136                MessageBox messageBox = new MessageBox(shell, SWT.ERROR); 
     137                messageBox.setMessage("Operation not supported!\nOnly works for GUI sequences."); 
     138                messageBox.setText("Error"); 
     139                messageBox.open(); 
    151140            } 
    152141        } 
Note: See TracChangeset for help on using the changeset viewer.