001: package com.calipso.reportgenerator.userinterface;
002:
003: import com.calipso.reportgenerator.reportdefinitions.types.FilterDefinitionFilterTypeType;
004: import com.calipso.reportgenerator.common.LanguageTraslator;
005: import com.calipso.reportgenerator.common.ReportSpec;
006: import com.calipso.reportgenerator.common.ReportFilterSpec;
007:
008: import java.util.*;
009:
010: /**
011: * Representa la coleccion de elementos editables
012: */
013:
014: public class UserParametersCollection {
015:
016: private static final int FROM_TO = 0;
017: private static final int FROM_QUANTITY = 1;
018: private static final int VALUE = 2;
019:
020: private ReportSpec reportSpec;
021: private Vector userParametersCollection;
022:
023: /**
024: * Inicializa una instancia de UserParametersCollection
025: * @param reportSpec Es necesario para la creacion de la coleccion
026: */
027: public UserParametersCollection(ReportSpec reportSpec) {
028: this .reportSpec = reportSpec;
029: }
030:
031: /**
032: * Llena un vector segun los parametros editables, que contiene objetos de tipo
033: * UserPameterElement
034: */
035: private void fillVisibleFilterDefinitionsVector() {
036: Collection filterCol = reportSpec.getEditFilterSpecs();
037: for (Iterator filterColIterator = filterCol.iterator(); filterColIterator
038: .hasNext();) {
039: ReportFilterSpec filterDefinition = (ReportFilterSpec) filterColIterator
040: .next();
041: if (filterDefinition.getVisual()) {
042: switch (filterDefinition.getFilterType().getType()) {
043: case FilterDefinitionFilterTypeType.RANGE_TYPE:
044: userParametersCollection.add(initializeElement(
045: FROM_TO, filterDefinition));
046: break;
047: case FilterDefinitionFilterTypeType.EQUALTO_TYPE:
048: userParametersCollection.add(initializeElement(
049: VALUE, filterDefinition));
050: break;
051: case FilterDefinitionFilterTypeType.GREATERTHAN_TYPE:
052: userParametersCollection.add(initializeElement(
053: VALUE, filterDefinition));
054: break;
055: case FilterDefinitionFilterTypeType.LESSTHAN_TYPE:
056: userParametersCollection.add(initializeElement(
057: VALUE, filterDefinition));
058: break;
059: case FilterDefinitionFilterTypeType.BEGINWITH_TYPE:
060: userParametersCollection.add(initializeElement(
061: VALUE, filterDefinition));
062: break;
063: case FilterDefinitionFilterTypeType.ENDWITH_TYPE:
064: userParametersCollection.add(initializeElement(
065: VALUE, filterDefinition));
066: break;
067: case FilterDefinitionFilterTypeType.RANKING_TYPE:
068: userParametersCollection.add(initializeElement(
069: VALUE, filterDefinition));
070: break; //TODO este sector nunca es utilizado
071: }
072: }
073: }
074: }
075:
076: /**
077: * Genera y devuelve un UserParameterElement dependiendo del tipo
078: * @param type indica si es Range, Top, o value
079: * @param filterDefinition FilterDefinition necesario para generar el UserParameterElement
080: * @return UserParameterElement recientemente creado
081: */
082: private UserParameterElement initializeElement(int type,
083: ReportFilterSpec filterDefinition) {
084: Hashtable values = new Hashtable();
085: Vector keysOrder = new Vector();
086: UserParameterElement userParameterElement = null;
087: String description = reportSpec.getDimensionFromName(
088: filterDefinition.getDimensionName()).getCaption();
089: String filterDefinitionName = filterDefinition.getName();
090: switch (type) {
091: case FROM_TO:
092: keysOrder.add(LanguageTraslator.traslate("146"));
093: keysOrder.add(LanguageTraslator.traslate("147"));
094: values.put(LanguageTraslator.traslate("146"), reportSpec
095: .getParamValues(false).get(
096: filterDefinition.getName() + "FROM")
097: .toString());
098: values.put(LanguageTraslator.traslate("147"), reportSpec
099: .getParamValues(false).get(
100: filterDefinition.getName() + "TO")
101: .toString());
102: userParameterElement = new UserParameterElement(
103: description, values, keysOrder,
104: filterDefinitionName, filterDefinition
105: .getDimensionName(), reportSpec);
106: break;
107: case FROM_QUANTITY:
108: keysOrder.add(LanguageTraslator.traslate("146"));
109: keysOrder.add(LanguageTraslator.traslate("149"));
110: values.put(LanguageTraslator.traslate("146"), reportSpec
111: .getParamValues(false).get(
112: filterDefinition.getName() + "FROM")
113: .toString());
114: values.put(LanguageTraslator.traslate("149"), reportSpec
115: .getParamValues(false).get(
116: filterDefinition.getName() + "QUANTITY")
117: .toString());
118: userParameterElement = new UserParameterElement(
119: description, values, keysOrder,
120: filterDefinitionName, filterDefinition
121: .getDimensionName(), reportSpec);
122: break;
123: case VALUE:
124: keysOrder.add(LanguageTraslator.traslate("150"));
125: values.put(LanguageTraslator.traslate("150"), reportSpec
126: .getParamValues(false).get(
127: filterDefinition.getName() + "VALUE")
128: .toString());
129: userParameterElement = new UserParameterElement(
130: description, values, keysOrder,
131: filterDefinitionName, filterDefinition
132: .getDimensionName(), reportSpec);
133: break;
134: }
135: return userParameterElement;
136: }
137:
138: /**
139: * Crea un Vector y lo inicializa con los UserParameterElement determinados
140: * @return
141: */
142: public Vector getUserParametersCollection() {
143: if (userParametersCollection == null) {
144: userParametersCollection = new Vector();
145: fillVisibleFilterDefinitionsVector();
146: }
147: return userParametersCollection;
148: }
149: }
|