Changeset 2156


Ignore:
Timestamp:
05/22/17 15:15:35 (7 years ago)
Author:
pharms
Message:

added first version of generic event plugin and required adaptations

Location:
trunk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/autoquest-core-events/src/main/java/de/ugoe/cs/autoquest/eventcore/guimodel/GUIElementTree.java

    r2146 r2156  
    1515package de.ugoe.cs.autoquest.eventcore.guimodel; 
    1616 
    17 import java.util.ArrayList; 
    18 import java.util.HashMap; 
    19 import java.util.List; 
    20 import java.util.Map; 
    21  
    22 import de.ugoe.cs.autoquest.eventcore.EventTargetModelException; 
    23 import de.ugoe.cs.autoquest.eventcore.IEventTargetFactory; 
     17import de.ugoe.cs.autoquest.eventcore.HierarchicalEventTargetTree; 
    2418import de.ugoe.cs.autoquest.eventcore.guimodel.GUIElementFactory; 
    2519import de.ugoe.cs.autoquest.eventcore.guimodel.GUIModel; 
     
    4034 * @version 1.0 
    4135 */ 
    42 public class GUIElementTree<T> { 
    43     /** 
    44      * <p> 
    45      * Map of all GUI elements that are part of the tree for efficient searching. The keys of the 
    46      * map are the ids of the GUI elements. 
    47      * </p> 
    48      */ 
    49     private Map<T, IGUIElement> guiElements; 
    50  
    51     /** 
    52      * <p> 
    53      * Map of all GUI element specifications that are part of the tree for efficient searching. The 
    54      * keys of the map are the ids of the GUI elements. 
    55      * </p> 
    56      */ 
    57     private Map<T, IGUIElementSpec> guiElementSpecs; 
    58  
    59     /** 
    60      * <p> 
    61      * Map of all children of GUI elements that are part of the tree. The keys of the map are the 
    62      * ids of the parent GUI elements. 
    63      * </p> 
    64      */ 
    65     private Map<T, List<T>> childRelations; 
    66  
    67     /** 
    68      * <p> 
    69      * Map of all parents of GUI elements that are part of the tree. The keys of the map are the 
    70      * ids of the child GUI elements. 
    71      * </p> 
    72      */ 
    73     private Map<T, T> parentRelations; 
    74  
    75     /** 
    76      * <p> 
    77      * the internally created GUI model 
    78      * </p> 
    79      */ 
    80     private GUIModel guiModel; 
    81  
    82     /** 
    83      * <p> 
    84      * the GUI element factory used in the model 
    85      * </p> 
    86      */ 
    87     private IEventTargetFactory guiElementFactory = GUIElementFactory.getInstance(); 
     36public class GUIElementTree<T> extends HierarchicalEventTargetTree<T, IGUIElement, IGUIElementSpec> 
     37{ 
    8838 
    8939    /** 
     
    9343     */ 
    9444    public GUIElementTree() { 
    95         guiElementSpecs = new HashMap<T, IGUIElementSpec>(); 
    96         childRelations = new HashMap<T, List<T>>(); 
    97         parentRelations = new HashMap<T, T>(); 
    98         guiElements = new HashMap<T, IGUIElement>(); 
    99         guiModel = new GUIModel(); 
     45        this(new GUIModel()); 
    10046    } 
    10147     
     
    10753     */ 
    10854    public GUIElementTree(GUIModel guiModel){ 
    109         guiElementSpecs = new HashMap<T, IGUIElementSpec>(); 
    110         childRelations = new HashMap<T, List<T>>(); 
    111         parentRelations = new HashMap<T, T>(); 
    112         guiElements = new HashMap<T, IGUIElement>(); 
    113         this.guiModel = guiModel; 
    114     } 
    115  
    116     /** 
    117      * <p> 
    118      * Adds a new GUI element to the tree. 
    119      * </p> 
    120      *  
    121      * @param guiElementID 
    122      *            id of the GUI element to be created 
    123      * @param parentID 
    124      *            id of the parent GUI element  
    125      * @param guiElementSpec 
    126      *            the GUI element specification 
    127      *             
    128      * @throws EventTargetModelException if the GUI element can not be added to the underlying GUI model 
    129      */ 
    130     public void add(T guiElementID, 
    131                     T parentID, 
    132                     IGUIElementSpec guiElementSpec) 
    133         throws EventTargetModelException 
    134     { 
    135         IGUIElement guiElement = guiElements.get(guiElementID); 
    136          
    137         if (guiElement == null) { 
    138             IGUIElementSpec parent = guiElementSpecs.get(parentID); 
    139             if (parent != null) { 
    140                 List<T> otherChildren = childRelations.get(parentID); 
    141  
    142                 if (otherChildren == null) { 
    143                     otherChildren = new ArrayList<T>(); 
    144                     childRelations.put(parentID, otherChildren); 
    145                 } 
    146  
    147                 otherChildren.add(guiElementID); 
    148  
    149                 parentRelations.put(guiElementID, parentID); 
    150             } 
    151             guiElementSpecs.put(guiElementID, guiElementSpec); 
    152              
    153             List<IGUIElementSpec> guiElementPath = new ArrayList<IGUIElementSpec>(); 
    154  
    155             T currentElementID = guiElementID; 
    156             while (guiElementSpec != null) { 
    157                 guiElementPath.add(0, guiElementSpec); 
    158                 currentElementID = parentRelations.get(currentElementID); 
    159                 guiElementSpec = guiElementSpecs.get(currentElementID); 
    160             } 
    161  
    162             guiElement = (IGUIElement) guiModel.integratePath(guiElementPath, guiElementFactory); 
    163             guiElements.put(guiElementID, guiElement); 
    164         } 
    165     } 
    166  
    167     /** 
    168      * <p> 
    169      * Searches the tree for a GUI element with the specified id and returns its 
    170      * {@link IGUIElement} . 
    171      * </p> 
    172      *  
    173      * @param id 
    174      *            id that is looked for 
    175      * @return {@link IGUIElementSpec} of the GUI element with the given id if found, null otherwise 
    176      */ 
    177     public IGUIElement find(T id) { 
    178         return guiElements.get(id); 
    179     } 
    180  
    181     /** 
    182      * <p> 
    183      * Returns the id of the provided {@link IGUIElement}. The comparison is performed using the 
    184      * equals method of the GUI element. 
    185      * </p> 
    186      *  
    187      * @param guiElement 
    188      *            guiElement that is looked for 
    189      * @return the id of the GUI element, null if the GUI element can not be found 
    190      */ 
    191     public T find(IGUIElement guiElement) { 
    192         for (Map.Entry<T, IGUIElement> entry : guiElements.entrySet()) { 
    193             if (guiElement.equals(entry.getValue())) { 
    194                 return entry.getKey(); 
    195             } 
    196         } 
    197          
    198         return null; 
    199     } 
    200  
    201     /** 
    202      * <p> 
    203      * Removes a GUI element (defined by its id) from the tree. All children of the GUI element will be 
    204      * removed recursively. 
    205      * </p> 
    206      *  
    207      * @param id 
    208      *            id of the GUI element to be removed 
    209      * @return number of GUI elements that were removed 
    210      */ 
    211     public int remove(T id) { 
    212         int removedCounter = 0; 
    213         IGUIElementSpec node = guiElementSpecs.remove(id); 
    214  
    215         if (node != null) { 
    216             removedCounter++; 
    217             List<T> nodesToBeRemoved = childRelations.remove(id); 
    218  
    219             // remove all children and sub-children, if any 
    220             if (nodesToBeRemoved != null) { 
    221                 for (int i = 0; i < nodesToBeRemoved.size(); i++) { 
    222                     T nodeToBeRemoved = nodesToBeRemoved.get(i); 
    223                     List<T> children = 
    224                         childRelations.remove(nodeToBeRemoved); 
    225  
    226                     if (children != null) { 
    227                         nodesToBeRemoved.addAll(children); 
    228                     } 
    229  
    230                     guiElementSpecs.remove(nodeToBeRemoved); 
    231                     parentRelations.remove(nodeToBeRemoved); 
    232                     removedCounter++; 
    233                 } 
    234             } 
    235  
    236             /* the node may be a child node of a parent. So search for it in the child relations 
    237             of the parent and remove it */ 
    238             T parent = parentRelations.remove(id); 
    239             if (parent != null) { 
    240                 List<T> children = childRelations.get(parent); 
    241  
    242                 if (children != null) { 
    243                     for (int i = 0; i < children.size(); i++) { 
    244                         if (children.get(i) == id) { 
    245                             children.remove(i); 
    246                             break; 
    247                         } 
    248                     } 
    249  
    250                     if (children.size() <= 0) { 
    251                         childRelations.remove(parent); 
    252                     } 
    253                 } 
    254             } 
    255         } 
    256         return removedCounter; 
     55        super(guiModel, GUIElementFactory.getInstance()); 
    25756    } 
    25857 
     
    26160     */ 
    26261    public GUIModel getGUIModel() { 
    263         return guiModel; 
    264     } 
    265  
    266     /** 
    267      * <p> 
    268      * Returns the number of nodes contained in the JFCComponentTree. 
    269      * </p> 
    270      *  
    271      * @return number of nodes 
    272      */ 
    273     public int size() { 
    274         return guiElementSpecs.size(); 
     62        return (GUIModel) super.getHierarchicalEventTargetModel(); 
    27563    } 
    27664 
  • trunk/autoquest-distribution/pom.xml

    r2120 r2156  
    6767      <groupId>de.ugoe.cs.autoquest</groupId> 
    6868      <artifactId>autoquest-plugin-uml</artifactId> 
     69      <version>${project.parent.version}</version> 
     70    </dependency> 
     71    <dependency> 
     72      <groupId>de.ugoe.cs.autoquest</groupId> 
     73      <artifactId>autoquest-plugin-genericevents</artifactId> 
    6974      <version>${project.parent.version}</version> 
    7075    </dependency> 
  • trunk/autoquest-ui-swt/src/main/java/de/ugoe/cs/autoquest/ui/swt/GuiModelTabComposite.java

    r2146 r2156  
    2727import de.ugoe.cs.autoquest.eventcore.IHierarchicalEventTarget; 
    2828import de.ugoe.cs.autoquest.eventcore.IHierarchicalEventTargetModel; 
    29 import de.ugoe.cs.autoquest.eventcore.guimodel.GUIModel; 
    3029import de.ugoe.cs.util.console.GlobalDataContainer; 
    3130 
     
    114113        guiModelList.removeAll(); 
    115114        for(String key : GlobalDataContainer.getInstance().getAllKeys()) { 
    116             if( GlobalDataContainer.getInstance().getData(key) instanceof GUIModel ) { 
     115            if( GlobalDataContainer.getInstance().getData(key) instanceof IHierarchicalEventTargetModel ) { 
    117116                guiModelList.add(key); 
    118117            } 
Note: See TracChangeset for help on using the changeset viewer.