Changeset 1026 for trunk


Ignore:
Timestamp:
01/02/13 10:07:51 (12 years ago)
Author:
fglaser
Message:
  • GUIElementTree is now generic to allow different id types in the internal handling of GUI elements. This became necessary during the development of HTMLLogParser.
File:
1 edited

Legend:

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

    r1025 r1026  
    3131 * <p> 
    3232 * The GUIElementTree represents the hierarchical structure of the GUI elements "as it is" currently during 
    33  * a session. It may change during the session due to creation and destruction of GUI elements. 
     33 * a session. It may change during the session due to creation and destruction of GUI elements. The parameter 
     34 * T represents the id type of the GUI elements that are handled internally. 
    3435 * </p> 
    3536 *  
     
    3839 * @version 1.0 
    3940 */ 
    40 public class GUIElementTree { 
    41         /* Note that in the current version the id of a GUI element is assumed to be a long. For future 
    42         versions it might be more suitable to change to some generic id type. */ 
    43          
    44          /** 
     41public class GUIElementTree<T> { 
     42    /** 
    4543     * <p> 
    4644     * Map of all GUI elements that are part of the tree for efficient searching. The keys of the 
     
    4846     * </p> 
    4947     */ 
    50     private Map<Long, IGUIElement> guiElements; 
     48    private Map<T, IGUIElement> guiElements; 
    5149 
    5250    /** 
     
    5654     * </p> 
    5755     */ 
    58     private Map<Long, IGUIElementSpec> guiElementSpecs; 
     56    private Map<T, IGUIElementSpec> guiElementSpecs; 
    5957 
    6058    /** 
     
    6462     * </p> 
    6563     */ 
    66     private Map<Long, List<Long>> childRelations; 
     64    private Map<T, List<T>> childRelations; 
    6765 
    6866    /** 
     
    7270     * </p> 
    7371     */ 
    74     private Map<Long, Long> parentRelations; 
     72    private Map<T, T> parentRelations; 
    7573 
    7674    /** 
     
    9694     */ 
    9795    public GUIElementTree() { 
    98         guiElementSpecs = new HashMap<Long, IGUIElementSpec>(); 
    99         childRelations = new HashMap<Long, List<Long>>(); 
    100         parentRelations = new HashMap<Long, Long>(); 
    101         guiElements = new HashMap<Long, IGUIElement>(); 
     96        guiElementSpecs = new HashMap<T, IGUIElementSpec>(); 
     97        childRelations = new HashMap<T, List<T>>(); 
     98        parentRelations = new HashMap<T, T>(); 
     99        guiElements = new HashMap<T, IGUIElement>(); 
    102100        guiModel = new GUIModel(); 
    103101    } 
     
    110108     */ 
    111109    public GUIElementTree(GUIModel guiModel){ 
    112         guiElementSpecs = new HashMap<Long, IGUIElementSpec>(); 
    113         childRelations = new HashMap<Long, List<Long>>(); 
    114         parentRelations = new HashMap<Long, Long>(); 
    115         guiElements = new HashMap<Long, IGUIElement>(); 
     110        guiElementSpecs = new HashMap<T, IGUIElementSpec>(); 
     111        childRelations = new HashMap<T, List<T>>(); 
     112        parentRelations = new HashMap<T, T>(); 
     113        guiElements = new HashMap<T, IGUIElement>(); 
    116114        this.guiModel = guiModel; 
    117115    } 
     
    129127     *                    the GUI element specification 
    130128     */ 
    131     public void add(Long guiElementID, 
    132                                 Long parentID, 
     129    public void add(T guiElementID, 
     130                                T parentID, 
    133131                    IGUIElementSpec guiElementSpec) 
    134132    { 
     
    138136                IGUIElementSpec parent = guiElementSpecs.get(parentID); 
    139137            if (parent != null) { 
    140                 List<Long> otherChildren = childRelations.get(parentID); 
     138                List<T> otherChildren = childRelations.get(parentID); 
    141139 
    142140                if (otherChildren == null) { 
    143                     otherChildren = new ArrayList<Long>(); 
     141                    otherChildren = new ArrayList<T>(); 
    144142                    childRelations.put(parentID, otherChildren); 
    145143                } 
     
    153151            List<IGUIElementSpec> guiElementPath = new ArrayList<IGUIElementSpec>(); 
    154152 
    155             Long currentElementID = guiElementID; 
     153            T currentElementID = guiElementID; 
    156154            while (guiElementSpec != null) { 
    157155                guiElementPath.add(0, guiElementSpec); 
     
    180178     * @return {@link IGUIElementSpec} of the GUI element with the given id if found, null otherwise 
    181179     */ 
    182     public IGUIElement find(long id) { 
     180    public IGUIElement find(T id) { 
    183181        return guiElements.get(id); 
    184182    } 
     
    194192     * @return number of GUI elements that were removed 
    195193     */ 
    196     public int remove(long id) { 
     194    public int remove(T id) { 
    197195        int removedCounter = 0; 
    198196        IGUIElementSpec node = guiElementSpecs.remove(id); 
     
    200198        if (node != null) { 
    201199                removedCounter++; 
    202             List<Long> nodesToBeRemoved = childRelations.remove(id); 
     200            List<T> nodesToBeRemoved = childRelations.remove(id); 
    203201 
    204202            // remove all children and sub-children, if any 
    205203            if (nodesToBeRemoved != null) { 
    206204                for (int i = 0; i < nodesToBeRemoved.size(); i++) { 
    207                     Long nodeToBeRemoved = nodesToBeRemoved.get(i); 
    208                     List<Long> children = 
     205                    T nodeToBeRemoved = nodesToBeRemoved.get(i); 
     206                    List<T> children = 
    209207                        childRelations.remove(nodeToBeRemoved); 
    210208 
     
    221219            /* the node may be a child node of a parent. So search for it in the child relations 
    222220            of the parent and remove it */ 
    223             Long parent = parentRelations.remove(id); 
     221            T parent = parentRelations.remove(id); 
    224222            if (parent != null) { 
    225                 List<Long> children = childRelations.get(parent); 
     223                List<T> children = childRelations.get(parent); 
    226224 
    227225                if (children != null) { 
Note: See TracChangeset for help on using the changeset viewer.