source: trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/temporalrelation/DefaultGUIElementSequenceDetectionRule.java @ 439

Last change on this file since 439 was 439, checked in by pharms, 12 years ago

initial import after refactoring of module structure with Steffen

File size: 4.6 KB
Line 
1//-------------------------------------------------------------------------------------------------
2// Module    : $RCSfile: DefaultSequenceDetectionRule.java,v $
3// Version   : $Revision: 0.0 $  $Author: patrick $  $Date: 18.03.2012 $
4// Project   : TaskTreeCreator
5// Creation  : 2012 by patrick
6// Copyright : Patrick Harms, 2012
7//-------------------------------------------------------------------------------------------------
8package de.ugoe.cs.quest.tasktrees.temporalrelation;
9
10import de.ugoe.cs.quest.tasktrees.treeifc.InteractionTask;
11import de.ugoe.cs.quest.tasktrees.treeifc.Sequence;
12import de.ugoe.cs.quest.tasktrees.treeifc.TaskTreeBuilder;
13import de.ugoe.cs.quest.tasktrees.treeifc.TaskTreeNode;
14import de.ugoe.cs.quest.tasktrees.treeifc.TaskTreeNodeFactory;
15import de.ugoe.cs.tasktree.guimodel.GUIElement;
16
17//-------------------------------------------------------------------------------------------------
18/**
19 * TODO comment
20 *
21 * @version $Revision: $ $Date: 18.03.2012$
22 * @author 2012, last modified by $Author: patrick$
23 */
24//-------------------------------------------------------------------------------------------------
25public class DefaultGUIElementSequenceDetectionRule implements TemporalRelationshipRule
26{
27
28  //-----------------------------------------------------------------------------------------------
29  /* (non-Javadoc)
30   * @see de.ugoe.cs.tasktree.temporalrelation.TemporalRelationshipRule#apply(TaskTreeNode, TaskTreeBuilder, TaskTreeNodeFactory)
31   */
32  //-----------------------------------------------------------------------------------------------
33  @Override
34  public RuleApplicationResult apply(TaskTreeNode        parent,
35                                     TaskTreeBuilder     builder,
36                                     TaskTreeNodeFactory nodeFactory,
37                                     boolean             finalize)
38  {
39    if (!(parent instanceof Sequence))
40    {
41      return null;
42    }
43   
44    RuleApplicationResult result = new RuleApplicationResult();
45   
46    GUIElement currentGUIElement = null;
47    int startingIndex = -1;
48   
49    int index = 0;
50    while (index < parent.getChildren().size())
51    {
52      TaskTreeNode child = parent.getChildren().get(index);
53     
54      GUIElement guiElement = determineGUIElement(child);
55     
56      if ((guiElement != null) && (!guiElement.equals(currentGUIElement)))
57      {
58        if (startingIndex < 0)
59        {
60          startingIndex = index;
61          currentGUIElement = guiElement;
62        }
63        else
64        {
65          handleGuiElementSequence(parent, startingIndex, index - 1, builder, nodeFactory, result);
66
67          return result;
68        }
69      }
70     
71      index++;
72    }
73   
74    if (startingIndex > -1)
75    {
76      if (finalize && (startingIndex > 0))
77      {
78        handleGuiElementSequence
79          (parent, startingIndex, parent.getChildren().size() - 1, builder, nodeFactory, result);
80      }
81      else
82      {
83        result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FEASIBLE);
84      }
85    }
86   
87    return result;
88  }
89
90  //-----------------------------------------------------------------------------------------------
91  /**
92   * TODO: comment
93   *
94   * @param child
95   * @return
96   */
97  //-----------------------------------------------------------------------------------------------
98  private GUIElement determineGUIElement(TaskTreeNode node)
99  {
100    if (node instanceof InteractionTask)
101    {
102      return ((InteractionTask) node).getGUIElement();
103    }
104    else
105    {
106      return null;
107    }
108  }
109
110  //-----------------------------------------------------------------------------------------------
111  /**
112   * TODO: comment
113   *
114   */
115  //-----------------------------------------------------------------------------------------------
116  private void handleGuiElementSequence(TaskTreeNode          parent,
117                                        int                   startIndex,
118                                        int                   endIndex,
119                                        TaskTreeBuilder       builder,
120                                        TaskTreeNodeFactory   nodeFactory,
121                                        RuleApplicationResult result)
122  {
123    Sequence sequence = nodeFactory.createNewSequence();
124   
125    for (int i = startIndex; i <= endIndex; i++)
126    {
127      builder.addChild(sequence, parent.getChildren().get(startIndex));
128      builder.removeChild((Sequence) parent, startIndex);
129    }
130   
131    builder.addChild((Sequence) parent, startIndex, sequence);
132   
133    result.addNewlyCreatedParentNode(sequence);
134    result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FINISHED);
135  }
136
137}
Note: See TracBrowser for help on using the repository browser.