KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > calipso > reportgenerator > userinterface > UserParametersCollection


1 package com.calipso.reportgenerator.userinterface;
2
3 import com.calipso.reportgenerator.reportdefinitions.types.FilterDefinitionFilterTypeType;
4 import com.calipso.reportgenerator.common.LanguageTraslator;
5 import com.calipso.reportgenerator.common.ReportSpec;
6 import com.calipso.reportgenerator.common.ReportFilterSpec;
7
8 import java.util.*;
9
10 /**
11  * Representa la coleccion de elementos editables
12  */

13
14 public class UserParametersCollection {
15
16   private static final int FROM_TO = 0;
17   private static final int FROM_QUANTITY = 1;
18   private static final int VALUE = 2;
19
20   private ReportSpec reportSpec;
21   private Vector userParametersCollection;
22
23   /**
24    * Inicializa una instancia de UserParametersCollection
25    * @param reportSpec Es necesario para la creacion de la coleccion
26    */

27   public UserParametersCollection(ReportSpec reportSpec){
28     this.reportSpec = reportSpec;
29   }
30
31   /**
32    * Llena un vector segun los parametros editables, que contiene objetos de tipo
33    * UserPameterElement
34    */

35   private void fillVisibleFilterDefinitionsVector(){
36     Collection filterCol = reportSpec.getEditFilterSpecs();
37     for(Iterator filterColIterator = filterCol.iterator() ; filterColIterator.hasNext() ; ){
38       ReportFilterSpec filterDefinition = (ReportFilterSpec) filterColIterator.next();
39       if(filterDefinition.getVisual()){
40         switch(filterDefinition.getFilterType().getType()){
41           case FilterDefinitionFilterTypeType.RANGE_TYPE:
42             userParametersCollection.add(initializeElement(FROM_TO, filterDefinition));
43             break;
44           case FilterDefinitionFilterTypeType.EQUALTO_TYPE:
45             userParametersCollection.add(initializeElement(VALUE, filterDefinition));
46             break;
47           case FilterDefinitionFilterTypeType.GREATERTHAN_TYPE:
48             userParametersCollection.add(initializeElement(VALUE, filterDefinition));
49             break;
50           case FilterDefinitionFilterTypeType.LESSTHAN_TYPE:
51             userParametersCollection.add(initializeElement(VALUE, filterDefinition));
52             break;
53           case FilterDefinitionFilterTypeType.BEGINWITH_TYPE:
54             userParametersCollection.add(initializeElement(VALUE, filterDefinition));
55             break;
56           case FilterDefinitionFilterTypeType.ENDWITH_TYPE:
57             userParametersCollection.add(initializeElement(VALUE, filterDefinition));
58             break;
59           case FilterDefinitionFilterTypeType.RANKING_TYPE:
60             userParametersCollection.add(initializeElement(VALUE, filterDefinition));
61             break; //TODO este sector nunca es utilizado
62
}
63       }
64     }
65   }
66
67   /**
68    * Genera y devuelve un UserParameterElement dependiendo del tipo
69    * @param type indica si es Range, Top, o value
70    * @param filterDefinition FilterDefinition necesario para generar el UserParameterElement
71    * @return UserParameterElement recientemente creado
72    */

73   private UserParameterElement initializeElement(int type, ReportFilterSpec filterDefinition){
74     Hashtable values = new Hashtable();
75     Vector keysOrder = new Vector();
76     UserParameterElement userParameterElement = null;
77     String JavaDoc description = reportSpec.getDimensionFromName(filterDefinition.getDimensionName()).getCaption();
78     String JavaDoc filterDefinitionName = filterDefinition.getName();
79     switch(type){
80       case FROM_TO:
81         keysOrder.add(LanguageTraslator.traslate("146"));
82         keysOrder.add(LanguageTraslator.traslate("147"));
83         values.put(LanguageTraslator.traslate("146"), reportSpec.getParamValues(false).get(filterDefinition.getName()+"FROM").toString());
84         values.put(LanguageTraslator.traslate("147"), reportSpec.getParamValues(false).get(filterDefinition.getName()+"TO").toString());
85         userParameterElement = new UserParameterElement(description, values, keysOrder, filterDefinitionName, filterDefinition.getDimensionName(), reportSpec);
86         break;
87       case FROM_QUANTITY:
88         keysOrder.add(LanguageTraslator.traslate("146"));
89         keysOrder.add(LanguageTraslator.traslate("149"));
90         values.put(LanguageTraslator.traslate("146"), reportSpec.getParamValues(false).get(filterDefinition.getName()+"FROM").toString());
91         values.put(LanguageTraslator.traslate("149"), reportSpec.getParamValues(false).get(filterDefinition.getName()+"QUANTITY").toString());
92         userParameterElement = new UserParameterElement(description, values, keysOrder, filterDefinitionName, filterDefinition.getDimensionName(), reportSpec);
93         break;
94       case VALUE:
95         keysOrder.add(LanguageTraslator.traslate("150"));
96         values.put(LanguageTraslator.traslate("150"), reportSpec.getParamValues(false).get(filterDefinition.getName()+"VALUE").toString());
97         userParameterElement = new UserParameterElement(description, values, keysOrder, filterDefinitionName, filterDefinition.getDimensionName(), reportSpec);
98         break;
99     }
100     return userParameterElement;
101   }
102
103   /**
104    * Crea un Vector y lo inicializa con los UserParameterElement determinados
105    * @return
106    */

107   public Vector getUserParametersCollection(){
108     if(userParametersCollection == null){
109       userParametersCollection = new Vector();
110       fillVisibleFilterDefinitionsVector();
111     }
112     return userParametersCollection;
113   }
114 }
115
Popular Tags