001: package com.calipso.reportgenerator.userinterface;
002:
003: import com.calipso.reportgenerator.reportcalculator.SharedDate;
004: import com.calipso.reportgenerator.reportdefinitions.types.ReportDataType;
005: import com.calipso.common.DateEx;
006:
007: import javax.swing.*;
008: import java.awt.*;
009: import java.util.Map;
010: import java.util.Iterator;
011:
012: /**
013: * Representa un componente grafico, mas bien un subPanel de la instancia
014: * de <code>UPsPanel</code>. Este panel se construye a partir de una instancia
015: * <code>UPRangeElement</code> por lo que representa un panel de tipo range.
016: */
017:
018: public class UPRangePanel extends UPPanel implements
019: ParameterPanelConstructor {
020:
021: public UPRangePanel(UPRangeElement owner) {
022: this .owner = owner;
023: initialize();
024: }
025:
026: private void initialize() {
027: setLayout(new GridLayout(1, 1));
028: add(getWestPanel());
029: add(getCenterPanel());
030: }
031:
032: private JPanel getCenterPanel() {
033: JPanel pnlCenter = new JPanel(new GridLayout(2, 2));
034: String dimensioName = owner.getFilterDefinition()
035: .getDimensionName();
036: int type;
037: if (dimensioName != null && !dimensioName.equalsIgnoreCase("")) {
038: type = owner.getReportSpec().getDimensionFromName(
039: dimensioName).getDataType().getType();
040: } else {
041: type = owner.getFilterDefinition().getDataType().getType();
042: }
043: fillCenterPanel(pnlCenter, type);
044: return pnlCenter;
045: }
046:
047: private void fillCenterPanel(JPanel pnlCenter, int type) {
048: switch (type) {
049: case ReportDataType.DATETIME_TYPE:
050: case ReportDataType.DATE_TYPE:
051: addWithDateTextField(pnlCenter);
052: break;
053: case ReportDataType.STRING_TYPE:
054: addWithStringTextField(pnlCenter);
055: break;
056: case ReportDataType.INTEGER_TYPE:
057: addWithIntegerTextField(pnlCenter);
058: break;
059: case ReportDataType.FLOAT_TYPE:
060: addWithFloatTextField(pnlCenter);
061: break;
062: }
063: }
064:
065: public void addWithFloatTextField(JPanel pnlCenter) {
066: pnlCenter.add(new Label(((UPRangeElement) owner)
067: .getStartingTfCaption()));
068: String key = owner.getFilterDefinition().getName()
069: + ((UPRangeElement) owner).getStartingArgument();
070: Object object = owner.getReportSpec().getParamValues(false)
071: .get(key);
072: UPTextField textField = new UPFloatTextField(object.toString());
073: pnlCenter.add(textField);
074: super .addUPTextField(key, textField);
075: pnlCenter.add(new Label(((UPRangeElement) owner)
076: .getEndingTfCaption()));
077: key = owner.getFilterDefinition().getName()
078: + ((UPRangeElement) owner).getEndingArgument();
079: object = owner.getReportSpec().getParamValues(false).get(key);
080: textField = new UPFloatTextField(object.toString());
081: pnlCenter.add(textField);
082: super .addUPTextField(key, textField);
083: }
084:
085: public void addWithIntegerTextField(JPanel pnlCenter) {
086: pnlCenter.add(new Label(((UPRangeElement) owner)
087: .getStartingTfCaption()));
088: String key = owner.getFilterDefinition().getName()
089: + ((UPRangeElement) owner).getStartingArgument();
090: Object object = owner.getReportSpec().getParamValues(false)
091: .get(key);
092: UPTextField textField = new UPIntegerTextField(object
093: .toString());
094: pnlCenter.add(textField);
095: super .addUPTextField(key, textField);
096: pnlCenter.add(new Label(((UPRangeElement) owner)
097: .getEndingTfCaption()));
098: key = owner.getFilterDefinition().getName()
099: + ((UPRangeElement) owner).getEndingArgument();
100: object = owner.getReportSpec().getParamValues(false).get(key);
101: textField = new UPIntegerTextField(object.toString());
102: pnlCenter.add(textField);
103: super .addUPTextField(key, textField);
104: }
105:
106: public void addWithStringTextField(JPanel pnlCenter) {
107: pnlCenter.add(new Label(((UPRangeElement) owner)
108: .getStartingTfCaption()));
109: String key = owner.getFilterDefinition().getName()
110: + ((UPRangeElement) owner).getStartingArgument();
111: Object object = owner.getReportSpec().getParamValues(false)
112: .get(key);
113: UPTextField textField = new UPStringTextField(object.toString());
114: pnlCenter.add(textField);
115: super .addUPTextField(key, textField);
116: pnlCenter.add(new Label(((UPRangeElement) owner)
117: .getEndingTfCaption()));
118: key = owner.getFilterDefinition().getName()
119: + ((UPRangeElement) owner).getEndingArgument();
120: object = owner.getReportSpec().getParamValues(false).get(key);
121: textField = new UPStringTextField(object.toString());
122: pnlCenter.add(textField);
123: super .addUPTextField(key, textField);
124: }
125:
126: public void addWithDateTextField(JPanel pnlCenter) {
127: pnlCenter.add(new Label(((UPRangeElement) owner)
128: .getStartingTfCaption()));
129: String key = owner.getFilterDefinition().getName()
130: + ((UPRangeElement) owner).getStartingArgument();
131: Object object = owner.getReportSpec().getParamValues(false)
132: .get(key);
133: UPTextField textField;
134: if (object instanceof SharedDate || object instanceof DateEx) {
135: textField = new UPDateTextField(object.toString());
136: } else {
137: textField = new UPDateTextField(super
138: .getDateFormatFrom(object.toString()));
139: }
140: pnlCenter.add(textField);
141: super .addUPTextField(key, textField);
142: pnlCenter.add(new Label(((UPRangeElement) owner)
143: .getEndingTfCaption()));
144: key = owner.getFilterDefinition().getName()
145: + ((UPRangeElement) owner).getEndingArgument();
146: object = owner.getReportSpec().getParamValues(false).get(key);
147: if (object instanceof SharedDate || object instanceof DateEx) {
148: textField = new UPDateTextField(object.toString());
149: } else {
150: textField = new UPDateTextField(super
151: .getDateFormatFrom(object.toString()));
152: }
153: pnlCenter.add(textField);
154: super .addUPTextField(key, textField);
155: }
156:
157: public boolean fillParamsMap(Map params) {
158: Map elements = super .getUpTextFieldCollection();
159: Iterator keysIterator = elements.keySet().iterator();
160: String firstKey = (String) keysIterator.next();
161: String secondKey = (String) keysIterator.next();
162: UPTextField firstUPTextField = (UPTextField) elements
163: .get(firstKey);
164: UPTextField secondUPTextField = (UPTextField) elements
165: .get(secondKey);
166: if (firstUPTextField.isLessThan(secondUPTextField)) {
167: params.put(firstKey, firstUPTextField.getComponentValue());
168: params
169: .put(secondKey, secondUPTextField
170: .getComponentValue());
171: return true;
172: } else {
173: return false;
174: }
175: }
176:
177: }
|