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.HashMap;
011: import java.util.Iterator;
012:
013: /**
014: * Representa un componente grafico, mas bien un subPanel de la instancia
015: * de <code>UPsPanel</code>. Este panel se construye a partir de una instancia
016: * <code>UPValueElement</code> por lo que representa un panel de tipo value.
017: */
018:
019: public class UPValuePanel extends UPPanel implements
020: ParameterPanelConstructor {
021:
022: public UPValuePanel(UPValueElement owner) {
023: this .owner = owner;
024: initialize();
025: }
026:
027: private void initialize() {
028: setLayout(new GridLayout(1, 1));
029: add(getWestPanel());
030: add(getCenterPanel());
031: }
032:
033: private JPanel getCenterPanel() {
034: JPanel pnlCenter = new JPanel(new GridLayout(1, 1));
035: String dimensioName = owner.getFilterDefinition()
036: .getDimensionName();
037: int type;
038: if (dimensioName != null && !dimensioName.equalsIgnoreCase("")) {
039: type = owner.getReportSpec().getDimensionFromName(
040: dimensioName).getDataType().getType();
041: } else {
042: type = owner.getFilterDefinition().getDataType().getType();
043: }
044: fillCenterPanel(pnlCenter, type);
045: return pnlCenter;
046: }
047:
048: private void fillCenterPanel(JPanel pnlCenter, int type) {
049: switch (type) {
050: case ReportDataType.DATETIME_TYPE:
051: case ReportDataType.DATE_TYPE:
052: addWithDateTextField(pnlCenter);
053: break;
054: case ReportDataType.STRING_TYPE:
055: addWithStringTextField(pnlCenter);
056: break;
057: case ReportDataType.INTEGER_TYPE:
058: addWithIntegerTextField(pnlCenter);
059: break;
060: case ReportDataType.FLOAT_TYPE:
061: addWithFloatTextField(pnlCenter);
062: break;
063: case ReportDataType.BOOLEAN_TYPE:
064: addWithBooleanCheckBox(pnlCenter);
065: break;
066: }
067: }
068:
069: public void addWithBooleanCheckBox(JPanel pnlCenter) {
070: String key = owner.getFilterDefinition().getName()
071: + ((UPValueElement) owner).getUniqueArgument();
072: UPBooleanCheckBox booleanCheckBox = new UPBooleanCheckBox();
073: pnlCenter.add(booleanCheckBox);
074: super .addUPTextField(key, booleanCheckBox);
075: }
076:
077: public void addWithFloatTextField(JPanel pnlCenter) {
078: pnlCenter.add(new Label(((UPValueElement) owner)
079: .getUniqueTfCaption()));
080: String key = owner.getFilterDefinition().getName()
081: + ((UPValueElement) owner).getUniqueArgument();
082: Object object = owner.getReportSpec().getParamValues(false)
083: .get(key);
084: UPTextField textField = new UPFloatTextField(object.toString());
085: pnlCenter.add(textField);
086: super .addUPTextField(key, textField);
087: }
088:
089: public void addWithIntegerTextField(JPanel pnlCenter) {
090: pnlCenter.add(new Label(((UPValueElement) owner)
091: .getUniqueTfCaption()));
092: String key = owner.getFilterDefinition().getName()
093: + ((UPValueElement) owner).getUniqueArgument();
094: Object object = owner.getReportSpec().getParamValues(false)
095: .get(key);
096: UPTextField textField = new UPIntegerTextField(object
097: .toString());
098: pnlCenter.add(textField);
099: super .addUPTextField(key, textField);
100: }
101:
102: public void addWithStringTextField(JPanel pnlCenter) {
103: pnlCenter.add(new Label(((UPValueElement) owner)
104: .getUniqueTfCaption()));
105: String key = owner.getFilterDefinition().getName()
106: + ((UPValueElement) owner).getUniqueArgument();
107: Object object = owner.getReportSpec().getParamValues(false)
108: .get(key);
109: if (object == null) {
110: object = "";
111: }
112: UPTextField textField = new UPStringTextField(object.toString());
113: pnlCenter.add(textField);
114: super .addUPTextField(key, textField);
115: }
116:
117: public void addWithDateTextField(JPanel pnlCenter) {
118: pnlCenter.add(new Label(((UPValueElement) owner)
119: .getUniqueTfCaption()));
120: String key = owner.getFilterDefinition().getName()
121: + ((UPValueElement) owner).getUniqueArgument();
122: Object object = owner.getReportSpec().getParamValues(false)
123: .get(key);
124: UPTextField textField;
125: if (object instanceof SharedDate || object instanceof DateEx) {
126: textField = new UPDateTextField(object.toString());
127: } else {
128: textField = new UPDateTextField(super
129: .getDateFormatFrom(object.toString()));
130: }
131: pnlCenter.add(textField);
132: super .addUPTextField(key, textField);
133: }
134:
135: /*private JPanel getWestPanel() {
136: JPanel pnlWest = new JPanel(new BorderLayout());
137: String dimensioName = owner.getFilterDefinition().getDimensionName();
138: JLabel label;
139: if(dimensioName!=null && !dimensioName.equalsIgnoreCase("")){
140: String dimensionCaption = owner.getReportSpec().getDimensionFromName(dimensioName).getCaption();
141: label = new JLabel(dimensionCaption);
142: }else{
143: label = new JLabel(owner.getFilterDefinition().getName());
144: }
145: pnlWest.add(label, BorderLayout.CENTER);
146: return pnlWest;
147: }*/
148:
149: public boolean fillParamsMap(Map params) {
150: Map elements = super .getUpTextFieldCollection();
151: Iterator keysIterator = elements.keySet().iterator();
152: String key = (String) keysIterator.next();
153: UPComponent upComponent = (UPTextField) elements.get(key);
154: params.put(key, upComponent.getComponentValue());
155: return true;
156: }
157:
158: }
|