View Javadoc

1   /*
2       Jameleon - An automation testing tool..
3       Copyright (C) 2005 Christian W. Hargraves (engrean@hotmail.com)
4   
5       This library is free software; you can redistribute it and/or
6       modify it under the terms of the GNU Lesser General Public
7       License as published by the Free Software Foundation; either
8       version 2.1 of the License, or (at your option) any later version.
9   
10      This library is distributed in the hope that it will be useful,
11      but WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13      Lesser General Public License for more details.
14  
15      You should have received a copy of the GNU Lesser General Public
16      License along with this library; if not, write to the Free Software
17      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */
19  package net.sf.jameleon.ui;
20  
21  import java.util.LinkedHashMap;
22  import java.util.Iterator;
23  import java.util.List;
24  import java.util.Map;
25  
26  import javax.swing.JFrame;
27  
28  import net.sf.jameleon.bean.Attribute;
29  import net.sf.jameleon.function.FunctionTag;
30  
31  public class FunctionDebugDialog extends DebugDialog{
32  
33      private FunctionTag functionTag;
34  
35      public FunctionDebugDialog(Object source, JFrame rootFrame, TestCaseResultsPane tcrf, String title){
36          super(source, rootFrame, tcrf, title);
37      }
38  
39      /***
40       * Sets the source where the data is pulled and where the data
41       * needs to be changed if any values are changed in the table.
42       * @param source - The tag that represents this debug dialog
43       */
44      protected void setBreakPointSource(Object source){
45          functionTag = (FunctionTag)source;
46      }
47  
48      /***
49       * Gets the key-value pairs that are set via this tag
50       * @return the key-value pairs that are set via this tag
51       */
52      protected Map getAttributes(){
53          Map vars = new LinkedHashMap();
54          Map attrs = functionTag.getFunctionalPoint().getAttributes();
55          Iterator it = attrs.keySet().iterator();
56          String key;
57          while (it.hasNext()) {
58              key = (String)it.next();
59              vars.put(key, ((Attribute)attrs.get(key)).getValue());
60          }
61          return vars;
62      }
63  
64      /***
65       * Gets the description that shows up in the dialog box
66       * @return the description that shows up in the dialog box
67       */
68      protected String getTagDescription(){
69          return getTagsAsString(functionTag.getFunctionalPoint().getTagNames());
70      }
71  
72      /***
73       * Changes the value of the given attribute's name real-time
74       * @param attributeName - The name of the attribute to change
75       * @param newValue - The new value to set the attribute to
76       */
77      protected void setNewAttributeValue(String attributeName, String newValue){
78          Attribute attr = functionTag.getFunctionalPoint().getAttribute(attributeName);
79          if (isSupported(attr.getType())) {
80              functionTag.setAttribute(attributeName, newValue);
81          }
82      }
83  
84      private String getTagsAsString(List tagNames){
85          StringBuffer tags = new StringBuffer();
86          Iterator it = tagNames.iterator();
87          String tag;
88          while (it.hasNext()) {
89              tag = (String)it.next();
90              tags.append("<").append(tag).append("/> "); 
91          }
92          return tags.toString();
93      }
94  
95      private boolean isSupported(String type){
96          boolean supported = true;
97          if (type.startsWith("java.util")){
98              if (!type.equals("java.util.Date") && 
99                  !type.equals("java.util.Calendar") &&
100                 !type.equals("java.util.Currency")) {
101                 supported = false;
102             }
103         }
104         return supported;
105     }
106 
107 }