0001: /*
0002: Dejar un solo constructor de Column Properties , no esta actualizxada y por lo tanto falla los exclude value , aunque puede tener otras consecuencias
0003: */
0004:
0005: package com.calipso.reportgenerator.userinterface;
0006:
0007: import com.calipso.reportgenerator.reportdefinitions.types.DimensionDefinitionLocationType;
0008: import com.calipso.reportgenerator.reportdefinitions.types.DimensionDefinitionOrderType;
0009: import com.calipso.reportgenerator.reportdefinitions.ReportView;
0010: import com.calipso.reportgenerator.userinterface.DimensionValuesSearcherUI;
0011: import com.calipso.reportgenerator.common.*;
0012: import javax.swing.*;
0013: import javax.swing.table.DefaultTableModel;
0014: import java.awt.*;
0015: import java.awt.event.*;
0016: import java.util.*;
0017: import java.util.List;
0018: import java.io.IOException;
0019: import javax.swing.table.*;
0020: import com.calipso.reportgenerator.common.InfoException;
0021:
0022: /**
0023: * Esta clase define el componente a visualizar
0024: *
0025: */
0026: public class PivotTable extends JComponent implements
0027: FieldPositionListener {
0028:
0029: private Container contentPane;
0030: private JPanel pageFields;
0031: private JPanel pageFillerRigth;
0032: private JScrollPane pageFieldsScrollPane;
0033: private JScrollPane centerJScrollPane;
0034: private JScrollPane leftCenterScrollPane;
0035: private JScrollPane colTableJScroll;
0036: private JScrollBar pageFieldScrollBar;
0037: private JSplitPane mainSplit;
0038: private JPanel mainSplitPanel;
0039: private JPanel leftCenterPanel;
0040: private JPanel rigthCenterPanel;
0041: private JPanel leftSplitNorthPanel;
0042: private JPanel centerSplitNorthPanel;
0043: private JPanel southRowFieldDropTarget;
0044: private JPanel columnPanel;
0045: private JPanel southFiller;
0046: private JPanel eastFiller;
0047: private JPanel columnHeaderPanel;
0048: private JPanel northPanel;
0049: private JTable datajTable;
0050: private JTable rowHeaderjTable;
0051: private JTable columnHeaderjTable;
0052: private JPanel pageConteinerComponent;
0053: private JFrame frame;
0054: private JButton maximizar;
0055: private JScrollBar horizontal;
0056: private JScrollBar vertical;
0057: private ReportResult reportResult;
0058: private PivotTableFrame pivotTableFrame;
0059: private Map changeDimensionLocation;
0060: private boolean withTotals;
0061: private int page;
0062: private int row;
0063: private int col;
0064: private Map dragPanels;
0065: private Map targetPanels;
0066: private ColorConditionManager colorConditionManager;
0067: private int width;
0068: private Map metricStates;
0069: private Map rowHeaderDimension;
0070: private PivotTableProperties tableProperties;
0071: private AplicationView view;
0072: private JPanel metrics;
0073: private JPopupMenu popupMenu;
0074: private final int DEFAULT_COLUMN_WIDTH = 75;
0075: private ReportView reportView;
0076:
0077: /**
0078: * Inicializa un objeto PivoteTable
0079: * @param pivotTableFrame
0080: */
0081: public PivotTable(PivotTableFrame pivotTableFrame,
0082: ReportView reportView) throws InfoException {
0083: col = 0;
0084: row = 0;
0085: page = 0;
0086: width = 0;
0087: this .reportView = reportView;
0088: this .pivotTableFrame = pivotTableFrame;
0089: this .maximizar = pivotTableFrame.getMaximizar();
0090: this .colorConditionManager = new ColorConditionManager();
0091: if (this .reportView == null) {
0092: tableProperties = new PivotTableProperties();
0093: tableProperties
0094: .setConditionManager(this .colorConditionManager);
0095: tableProperties.setWithTotal(true);
0096: setReportResult(pivotTableFrame.getReportResult());
0097: initTableProperties();
0098: withTotals = true;
0099: } else {
0100: tableProperties = new PivotTableProperties();
0101: tableProperties
0102: .setConditionManager(this .colorConditionManager);
0103: tableProperties.setWithTotal(reportView.getVisibleTotals());
0104: withTotals = reportView.getVisibleTotals();
0105: setReportResult(pivotTableFrame.getReportResult());
0106: initTableProperties();
0107: tableProperties.assignFromView(reportView);
0108: }
0109: this .changeDimensionLocation = new Hashtable();
0110: setContentPane(pivotTableFrame.getPivotPanel());
0111: setFrame(pivotTableFrame.getFrame());
0112: initComponents();
0113: setColorConditionManager(this .colorConditionManager);
0114: setComponentSize();
0115: setRowSize();
0116: setDefaultSize();
0117: if (getRowHeaderDimension().isEmpty()) {
0118: mainSplit.setDividerLocation(100);
0119: } else {
0120: mainSplit.setDividerLocation(adjustmentSizeSplit());
0121: }
0122: }
0123:
0124: /**
0125: * Iniocializa el objeto PivotTablePropertie
0126: //* @throws InfoException
0127: */
0128:
0129: private void initTableProperties() throws InfoException {
0130: try {
0131: ArrayList rowList = (ArrayList) reportResult
0132: .getReportQuery().getDimensionsByLocation(
0133: DimensionDefinitionLocationType.ROW);
0134: fillColumnsProperties(rowList,
0135: DimensionDefinitionLocationType.ROW.toString());
0136:
0137: ArrayList pageList = (ArrayList) reportResult
0138: .getReportQuery().getDimensionsByLocation(
0139: DimensionDefinitionLocationType.PAGE);
0140: fillColumnsProperties(pageList,
0141: DimensionDefinitionLocationType.PAGE.toString());
0142:
0143: ArrayList columnList = (ArrayList) reportResult
0144: .getReportQuery().getDimensionsByLocation(
0145: DimensionDefinitionLocationType.COLUMN);
0146: fillColumnsProperties(columnList,
0147: DimensionDefinitionLocationType.COLUMN.toString());
0148: } catch (Exception e) {
0149: throw new InfoException(LanguageTraslator.traslate("227"));
0150:
0151: }
0152: getMetricStates();
0153:
0154: }
0155:
0156: /**
0157: * Sete el ancho por default de cada columnPrropertie
0158: */
0159: private void setDefaultSize() {
0160:
0161: for (int index = 0; index < tableProperties
0162: .getColumnProperties().size(); index++) {
0163: ColumnProperties properties = (ColumnProperties) tableProperties
0164: .getColumnProperties().get(index);
0165: if (properties.getLocation().compareToIgnoreCase("PAGE") == 0) {
0166: properties.setWidth(DEFAULT_COLUMN_WIDTH);
0167: } else {
0168: if (properties.getLocation().compareToIgnoreCase(
0169: "COLUMN") == 0) {
0170: properties.setWidth(DEFAULT_COLUMN_WIDTH);
0171: }
0172: }
0173: }
0174: }
0175:
0176: /**
0177: * Sete las propiedades por default de cada ColumnPropertie de la vista
0178: */
0179: private void setRowSize() {
0180: Map map = getRowHeaderDimension();
0181: Iterator iterator = map.values().iterator();
0182: int index = 0;
0183: while (iterator.hasNext()) {
0184: ColumnProperties properties = (ColumnProperties) iterator
0185: .next();
0186: JPanel panel = (JPanel) dragPanels.get(properties
0187: .getColumnName());
0188: panel.getPreferredSize().width = DEFAULT_COLUMN_WIDTH;
0189: panel.setMinimumSize(panel.getPreferredSize());
0190: panel.setMaximumSize(panel.getPreferredSize());
0191: tableProperties.getColumnProperties().remove(properties);
0192: properties.setWidth(DEFAULT_COLUMN_WIDTH);
0193: rowHeaderjTable.getColumnModel().getColumn(index)
0194: .setPreferredWidth(DEFAULT_COLUMN_WIDTH);
0195: tableProperties.getColumnProperties().add(properties);
0196: index++;
0197: }
0198: rowHeaderDimension = map;
0199: mainSplit.setDividerLocation(DEFAULT_COLUMN_WIDTH * index);
0200: mainSplit.setMinimumSize(new Dimension(100, 0));
0201: mainSplit.invalidate();
0202: invaildatePanels();
0203: }
0204:
0205: /**
0206: * Retona un map , con todas las columnProperties ubicadas en ROW
0207: * @return
0208: */
0209: private Map getAllRowColumnProperties() {
0210: Map map = new HashMap();
0211: for (int index = 0; index < tableProperties
0212: .getColumnProperties().size(); index++) {
0213: ColumnProperties properties = (ColumnProperties) tableProperties
0214: .getColumnProperties().get(index);
0215: if (properties.getLocation().compareToIgnoreCase("ROW") == 0) {
0216: Object[] objects = (Object[]) changeDimensionLocation
0217: .get(properties.getColumnName());
0218: if (objects != null) {
0219: properties.setUbication(((Integer) objects[1])
0220: .intValue());
0221: }
0222: map.put(properties.getColumnName(), properties);
0223: }
0224: }
0225: return map;
0226: }
0227:
0228: /**
0229: * Seta el objeto ColorConditionManager
0230: * @param colorConditionManager
0231: */
0232: private void setColorConditionManager(
0233: ColorConditionManager colorConditionManager) {
0234: this .colorConditionManager = colorConditionManager;
0235: tableProperties.setConditionManager(colorConditionManager);
0236: ((DataTableCellRenderer) getDatajTable().getDefaultRenderer(
0237: Object.class))
0238: .setColorConditionManager(colorConditionManager);
0239: }
0240:
0241: /**
0242: * Metodo de creacion de los componente de la PivoteTable
0243: */
0244: private void initComponents() throws InfoException {
0245: dragPanels = new Hashtable();
0246: targetPanels = new Hashtable();
0247: popupMenu = new JPopupMenu();
0248: fillParamValuePopupMenu();
0249: getContentPane().add(createPageFieldComponents(),
0250: BorderLayout.NORTH);
0251: getContentPane().add(createMainSplitPanel(),
0252: BorderLayout.CENTER);
0253: getContentPane().add(createMetricsPanel(), BorderLayout.SOUTH);
0254: fillContents(getReportResult());
0255: createEvent();
0256: }
0257:
0258: /**
0259: * Crea el panel donde se colocan los checkBox de metrica
0260: * @return
0261: */
0262: private Component createMetricsPanel() {
0263: metrics = new JPanel();
0264: metrics.setLayout(new javax.swing.BoxLayout(metrics,
0265: javax.swing.BoxLayout.X_AXIS));
0266: List list = getReportResult().getReportQuery().getMetrics();
0267: for (int index = 0; index < list.size(); index++) {
0268: QueryMetric metric = (QueryMetric) list.get(index);
0269: if (metric.getVisible()) {
0270: final JCheckBox checkBox = new JCheckBox(
0271: getReportResult().getMetricFromName(
0272: metric.getName()).getCaption(), true);
0273: checkBox.setName(metric.getName());
0274: metrics.add(checkBox);
0275: checkBox.addActionListener(new ActionListener() {
0276: public void actionPerformed(ActionEvent e) {
0277: try {
0278: setMetricsProperties(checkBox);
0279: } catch (InfoException e1) {
0280: ShowExceptionMessageDialog
0281: .initExceptionDialogMessage(
0282: LanguageTraslator
0283: .traslate("137"),
0284: e1);
0285: }
0286: }
0287: });
0288: } else {
0289: final JCheckBox checkBox = new JCheckBox(
0290: getReportResult().getMetricFromName(
0291: metric.getName()).getCaption(), false);
0292: checkBox.setName(metric.getName());
0293: metrics.add(checkBox);
0294: checkBox.addActionListener(new ActionListener() {
0295: public void actionPerformed(ActionEvent e) {
0296: try {
0297: setMetricsProperties(checkBox);
0298: } catch (InfoException e1) {
0299: ShowExceptionMessageDialog
0300: .initExceptionDialogMessage(
0301: LanguageTraslator
0302: .traslate("137"),
0303: e1);
0304: }
0305: }
0306: });
0307: }
0308: }
0309: JScrollPane pane = new JScrollPane(metrics);
0310: pane.setSize(new Dimension(getPreferredSize().width, 50));
0311: pane.setPreferredSize(new Dimension(getPreferredSize().width,
0312: 50));
0313: pane
0314: .setMaximumSize(new Dimension(getPreferredSize().width,
0315: 50));
0316: pane
0317: .setMinimumSize(new Dimension(getPreferredSize().width,
0318: 50));
0319: return pane;
0320: }
0321:
0322: /**
0323: * Setea las propiedades de las distintas metricas
0324: * @param checkBox
0325:
0326: */
0327: private void setMetricsProperties(JCheckBox checkBox)
0328: throws InfoException {
0329: String name = checkBox.getName();
0330: ((MetricState) getMetricStates().get(name)).setVisible(checkBox
0331: .isSelected());
0332: {
0333: pivotTableFrame
0334: .updateQuerry((MetricState) metricStates
0335: .get(checkBox.getName()), checkBox,
0336: tableProperties);
0337: if (!tableProperties.getMetricProperies().contains(
0338: getMetricStates().get(name))) {
0339: tableProperties.getMetricProperies().add(
0340: getMetricStates().get(name));
0341: } else {
0342: tableProperties.getMetricProperies().remove(
0343: getMetricStates().get(name));
0344: tableProperties.getMetricProperies().add(
0345: getMetricStates().get(name));
0346: }
0347: fillContents(reportResult);
0348: resizeComponent();
0349:
0350: }
0351: }
0352:
0353: /**
0354: * Actualiza el estado de los checkBox correspondiente a las metricas
0355: //* @throws InfoException
0356: */
0357: public void updateMetricCheckBoxes() throws InfoException {
0358: String name;
0359: for (int i = 0; i < metrics.getComponentCount(); i++) {
0360: JCheckBox jCheckBox = (JCheckBox) metrics.getComponents()[i];
0361: name = jCheckBox.getName();
0362: jCheckBox.setSelected(reportResult.getReportQuery()
0363: .getQueryMetricFromName(name).getVisible());
0364: }
0365: }
0366:
0367: /**
0368: * Retorna un map con los estados de las metricas
0369: * @return
0370: */
0371: public Map getMetricStates() throws InfoException {
0372: if (metricStates == null) {
0373: metricStates = new HashMap();
0374: loadAllMetrics(metricStates);
0375: }
0376: return metricStates;
0377: }
0378:
0379: /**
0380: * Metodo de publicacion de eventos de PivoteTable
0381: *
0382: */
0383: private void createEvent() {
0384:
0385: pageFieldScrollBar
0386: .addAdjustmentListener(new java.awt.event.AdjustmentListener() {
0387: public void adjustmentValueChanged(
0388: java.awt.event.AdjustmentEvent evt) {
0389: pageFieldScrollBarAdjustmentValueChanged(evt);
0390: }
0391: });
0392: rowHeaderjTable
0393: .addComponentListener(new java.awt.event.ComponentAdapter() {
0394: public void componentResized(
0395: java.awt.event.ComponentEvent evt) {
0396: try {
0397: rowHeaderjTableComponentResized();
0398: } catch (InfoException e) {
0399: ShowExceptionMessageDialog
0400: .initExceptionDialogMessage(
0401: LanguageTraslator
0402: .traslate("214"), e);
0403: }
0404: }
0405: });
0406: /*maximizar.addActionListener(new java.awt.event.ActionListener() {
0407: public void actionPerformed(java.awt.event.ActionEvent evt) {
0408: maximizarActionPerformed();
0409: }
0410: });*/
0411: horizontal
0412: .addAdjustmentListener(new java.awt.event.AdjustmentListener() {
0413: public void adjustmentValueChanged(
0414: java.awt.event.AdjustmentEvent evt) {
0415: horizontalScrollBarAdjustmentValue(evt);
0416: }
0417: });
0418: vertical
0419: .addAdjustmentListener(new java.awt.event.AdjustmentListener() {
0420: public void adjustmentValueChanged(
0421: java.awt.event.AdjustmentEvent evt) {
0422: verticalScrollBarAdjustmentValue(evt);
0423: }
0424: });
0425: rowHeaderjTable.getTableHeader().addMouseListener(
0426: new java.awt.event.MouseAdapter() {
0427: public void mouseReleased(
0428: java.awt.event.MouseEvent evt) {
0429: rowTableHeaderMouseReleased(evt);
0430: }
0431: });
0432: datajTable.getTableHeader().addMouseListener(
0433: new java.awt.event.MouseAdapter() {
0434: public void mouseReleased(
0435: java.awt.event.MouseEvent evt) {
0436: dataTableHeaderMouseReleased();
0437: }
0438: });
0439:
0440: /*pivotTableFrame.getColorIndicator().addActionListener(new java.awt.event.ActionListener() {
0441: public void actionPerformed(java.awt.event.ActionEvent evt) {
0442: executeSemafore();
0443: }
0444: });*/
0445:
0446: /*pivotTableFrame.getExcel().addActionListener(new java.awt.event.ActionListener() {
0447: public void actionPerformed(java.awt.event.ActionEvent evt) {
0448: executeExcelFormatSerializer();
0449: }
0450: });
0451:
0452: pivotTableFrame.getSearcher().addActionListener(new java.awt.event.ActionListener() {
0453: public void actionPerformed(java.awt.event.ActionEvent evt) {
0454: executeSearcher();
0455: }
0456: });
0457:
0458: pivotTableFrame.getViewBtn().addActionListener(new ActionListener() {
0459: public void actionPerformed(ActionEvent e) {
0460: executeViewBtn();
0461: }
0462: }); */
0463: datajTable.addMouseListener(new MouseAdapter() {
0464: public void mouseClicked(MouseEvent e) {
0465: fillParamValuePopupMenu(e);
0466: }
0467: });
0468: /*pivotTableFrame.getEditDimensionValueBtn().addActionListener(new ActionListener() {
0469: public void actionPerformed(ActionEvent e) {
0470: try {
0471: executeEditDimensionValues();
0472: }
0473: catch (InfoException e1) {
0474: ShowExceptionMessageDialog.initExceptionDialogMessage(LanguageTraslator.traslate("214"), e1);
0475: }
0476: }
0477: });*/
0478: /*pivotTableFrame.getOrdenBtn().addActionListener(new ActionListener() {
0479: public void actionPerformed(ActionEvent e) {
0480: try {
0481: executeEditOrdenValues();
0482: }
0483: catch (InfoException e1) {
0484: ShowExceptionMessageDialog.initExceptionDialogMessage(LanguageTraslator.traslate("214"), e1);
0485: }
0486: }
0487: });*/
0488: }
0489:
0490: public void executeViewBtn() {
0491: try {
0492: fillComponents();
0493: executeAplicationView();
0494: } catch (InfoException e1) {
0495: ShowExceptionMessageDialog.initExceptionDialogMessage(
0496: LanguageTraslator.traslate("214"), e1);
0497:
0498: }
0499: }
0500:
0501: /**
0502: * Ejecuta el orden de dimensiones
0503: * @throws InfoException
0504: */
0505: public void executeEditOrdenValues() throws InfoException {
0506: Map dimensionOrders = new HashMap();
0507: Map dimensionCaptions = new HashMap();
0508: Iterator iterator;
0509: iterator = tableProperties.getColumnProperties().iterator();
0510: while (iterator.hasNext()) {
0511: ColumnProperties properties = (ColumnProperties) iterator
0512: .next();
0513: String columnName = properties.getColumnName();
0514: dimensionOrders
0515: .put(
0516: columnName,
0517: new Boolean(
0518: properties.getOrder().getType() == DimensionDefinitionOrderType.A_TYPE));
0519: dimensionCaptions.put(columnName, reportResult
0520: .getDimensionFromName(columnName).getCaption());
0521: }
0522: if (DimensionOrderEditor.editDimensionOrder(getFrame(),
0523: dimensionOrders, dimensionCaptions, pivotTableFrame
0524: .getReportGeneratorConfiguration())) {
0525: iterator = tableProperties.getColumnProperties().iterator();
0526: while (iterator.hasNext()) {
0527: ColumnProperties properties = (ColumnProperties) iterator
0528: .next();
0529: String columnName = properties.getColumnName();
0530: if (((Boolean) dimensionOrders.get(columnName))
0531: .booleanValue()) {
0532: properties.setOrder(DimensionDefinitionOrderType.A);
0533: } else {
0534: properties.setOrder(DimensionDefinitionOrderType.D);
0535: }
0536: }
0537: getPivotTableFrame().buildNewQuery(tableProperties);
0538: fillContents(getReportResult());
0539: }
0540: }
0541:
0542: /**
0543: * Ejecuta el editor de Ranking de metrica
0544: * @throws InfoException
0545: */
0546: public void executeEditDimensionValues() throws InfoException {
0547: Map dimensionRankMetrics = new HashMap();
0548: Map fieldCaptions = new HashMap();
0549: List metricNames = new ArrayList();
0550: Iterator iterator;
0551: iterator = tableProperties.getColumnProperties().iterator();
0552: while (iterator.hasNext()) {
0553: ColumnProperties properties = (ColumnProperties) iterator
0554: .next();
0555: String columnName = properties.getColumnName();
0556: String rankMetricName = properties.getRankMetricName();
0557: dimensionRankMetrics.put(columnName, rankMetricName);
0558: fieldCaptions.put(columnName, reportResult
0559: .getDimensionFromName(columnName).getCaption());
0560: }
0561:
0562: iterator = tableProperties.getMetricProperies().iterator();
0563: while (iterator.hasNext()) {
0564: MetricState metricState = (MetricState) iterator.next();
0565: String name = metricState.getName();
0566: metricNames.add(name);
0567: fieldCaptions.put(name, metricState.getCaption());
0568: }
0569:
0570: if (RankMetricEditor.editRankMetrics(getFrame(),
0571: dimensionRankMetrics, metricNames, fieldCaptions,
0572: pivotTableFrame.getReportGeneratorConfiguration())) {
0573: iterator = tableProperties.getColumnProperties().iterator();
0574: while (iterator.hasNext()) {
0575: ColumnProperties properties = (ColumnProperties) iterator
0576: .next();
0577: String columnName = properties.getColumnName();
0578: properties
0579: .setRankMetricName((String) dimensionRankMetrics
0580: .get(columnName));
0581: }
0582: pivotTableFrame.buildNewQuery(tableProperties);
0583: fillContents(getReportResult());
0584: }
0585: }
0586:
0587: /**
0588: * Carga los paramValues
0589: */
0590: private void fillParamValuePopupMenu() {
0591: DrillDownSpec drillDownSpec = null;
0592: Iterator iterator = reportResult.getReportSpec()
0593: .getDrillDownSpecs().iterator();
0594: while (iterator.hasNext()) {
0595: drillDownSpec = (DrillDownSpec) iterator.next();
0596: JMenuItem item = new JMenuItem(drillDownSpec
0597: .getDescription());
0598: popupMenu.add(item);
0599: final DrillDownSpec drillDownSpec1 = drillDownSpec;
0600: item.addActionListener(new ActionListener() {
0601: public void actionPerformed(ActionEvent e) {
0602: try {
0603: pivotTableFrame.drillDown(drillDownSpec1,
0604: getMapDrillDown());
0605: } catch (InfoException e1) {
0606: ShowExceptionMessageDialog
0607: .initExceptionDialogMessage(
0608: LanguageTraslator
0609: .traslate("151"), e1);
0610: }
0611: }
0612: });
0613: }
0614: }
0615:
0616: /**
0617: * Ejecuta el pupupMenu con los ParamValue cargados
0618: * @param e
0619: */
0620: private void fillParamValuePopupMenu(MouseEvent e) {
0621: if (e.getButton() == 3) {
0622: popupMenu.show(datajTable, e.getPoint().x, e.getPoint().y);
0623: }
0624: }
0625:
0626: /**
0627: * Retorna un map con los valores correspondientes a las celdas seleccionadas
0628: * @return
0629: */
0630: private Map getMapDrillDown() {
0631: Map values = new Hashtable();
0632: String dimensionName, value;
0633: Object[] rowsDesc = getRowModel().getValueFrom(
0634: getDatajTable().getSelectedRow());
0635: for (int j = 0; j < getReportResult().getReportQuery()
0636: .getRowDimensions().size(); j++) {
0637: dimensionName = ((QueryDimension) getReportResult()
0638: .getReportQuery().getRowDimensions().get(j))
0639: .getName();
0640: if (rowsDesc[j] != null) {
0641: value = rowsDesc[j].toString();
0642: values.put(dimensionName, value);
0643: }
0644: }
0645:
0646: Object[] columnDesc = getColModel().getValueFrom(
0647: getDatajTable().getSelectedColumn());
0648: for (int j = 0; j < getReportResult().getReportQuery()
0649: .getColumnDimensions().size(); j++) {
0650: dimensionName = ((QueryDimension) getReportResult()
0651: .getReportQuery().getColumnDimensions().get(j))
0652: .getName();
0653: if (columnDesc[j] != null) {
0654: value = columnDesc[j].toString();
0655: values.put(dimensionName, value);
0656: }
0657: }
0658: return values;
0659: }
0660:
0661: /**
0662: * Ejecuta aplicationView , (aplicationView carga vistas previamnete guardadas)
0663: //* @throws InfoException
0664: */
0665: public void executeAplicationView() throws InfoException {
0666: view = new AplicationView(new JFrame(), true, this ,
0667: getPivotTableFrame().getMicroReport());
0668: view.setVisible(true);
0669: view.addWindowListener(new WindowAdapter() {
0670: public void windowClosed(WindowEvent e) {
0671: try {
0672: updateFromView();
0673: } catch (InfoException ex) {
0674: ShowExceptionMessageDialog
0675: .initExceptionDialogMessage(
0676: LanguageTraslator.traslate("214"),
0677: ex);
0678: }
0679:
0680: }
0681: });
0682: }
0683:
0684: /**Actualiza el cubo al aplicar una vista
0685: *
0686: */
0687: private void updateFromView() throws InfoException {
0688: fillContents(reportResult);
0689: setColorConditionManager(tableProperties.getConditionManager());
0690: DefaultTableModel tableDataModel = (DefaultTableModel) getDatajTable()
0691: .getModel();
0692: tableDataModel.fireTableChanged(null);
0693: dataTableHeaderMouseReleased();
0694: maximizarActionPerformed();
0695: rowHeaderjTable.revalidate();
0696: invaildatePanels();
0697: updateMetricCheckBoxes();
0698: }
0699:
0700: public void applyView(String reportViewId) {
0701: PivotTableProperties pivoteTableProperties = getTableProperties();
0702: pivoteTableProperties
0703: .setConditionManager(getColorConditionManager());
0704: try {
0705: reportView = getPivotTableFrame().getReportManager()
0706: .getReportViewFromID(
0707: reportViewId,
0708: reportResult.getReportSpec()
0709: .getDefinitionId(),
0710: getPivotTableFrame().getUserID());
0711: pivoteTableProperties.assignFromView(reportView);
0712: getPivotTableFrame().buildNewQuery(pivoteTableProperties);
0713: updateFromView();
0714: } catch (InfoException e) {
0715: ShowExceptionMessageDialog.initExceptionDialogMessage(
0716: LanguageTraslator.traslate("368"), e);
0717: }
0718: }
0719:
0720: /**
0721: * Actualiza la pivoteTableProperties
0722: */
0723: private void updateTableProperties(String positionName,
0724: String fieldName) {
0725: Iterator iterator = tableProperties.getColumnProperties()
0726: .iterator();
0727: while (iterator.hasNext()) {
0728: ColumnProperties properties = (ColumnProperties) iterator
0729: .next();
0730: if (properties.getColumnName().compareToIgnoreCase(
0731: fieldName) == 0) {
0732: properties.setLocation(positionName);
0733: }
0734: }
0735: rowHeaderDimension = getAllRowColumnProperties();
0736: updateTablePropertiesUbications();
0737:
0738: }
0739:
0740: /**
0741: * Actualiza la pivoteTableProperties
0742: */
0743: private void updateTablePropertiesUbications() {
0744: for (int i = 0; i < tableProperties.getColumnProperties()
0745: .size(); i++) {
0746: ColumnProperties properties = (ColumnProperties) tableProperties
0747: .getColumnProperties().get(i);
0748: Object[] object = (Object[]) changeDimensionLocation
0749: .get(properties.getColumnName());
0750: properties.setUbication(((Integer) object[1]).intValue());
0751: }
0752: rowHeaderDimension = getAllRowColumnProperties();
0753: }
0754:
0755: public void executeSearcher() {
0756: if (getDatajTable().getSelectedColumns().length == 1
0757: && getDatajTable().getSelectedRows().length == 1) {
0758: JFrame subFrame = new JFrame();
0759: DimensionValuesSearcherUI searcherUI = new DimensionValuesSearcherUI(
0760: subFrame, true, reportResult, this , pivotTableFrame
0761: .getReportGeneratorConfiguration());
0762: searcherUI.setVisible(true);
0763: validate();
0764: } else {
0765: JOptionPane.showMessageDialog(this , LanguageTraslator
0766: .traslate("283"));
0767: }
0768: }
0769:
0770: public void executeExcelFormatSerializer() throws IOException {
0771: ExcelFormatSerializer serializer = new ExcelFormatSerializer(
0772: this );
0773: JFileChooser fileChooser = new JFileChooser();
0774: int returnVal = fileChooser.showSaveDialog(this );
0775: if (returnVal == JFileChooser.APPROVE_OPTION) {
0776: String path = fileChooser.getSelectedFile().getPath();
0777: serializer.serializeTo(path);
0778: }
0779: }
0780:
0781: /**
0782: * Ejecuta el semaforo
0783: */
0784: public void executeSemafore() {
0785: ColorConditionUI sem = null;
0786: ColorConditionManager clon = null;
0787: try {
0788:
0789: clon = (ColorConditionManager) colorConditionManager
0790: .clone();
0791: JFrame frame = new JFrame();
0792: sem = new ColorConditionUI(frame, true, clon,
0793: getMetricStates(), pivotTableFrame
0794: .getReportGeneratorConfiguration());
0795: } catch (Exception e) {
0796: InfoException infoException = new InfoException(
0797: LanguageTraslator.traslate("219"));
0798: ShowExceptionMessageDialog.initExceptionDialogMessage(
0799: LanguageTraslator.traslate("219"), infoException);
0800: }
0801: sem.setVisible(true);
0802: setColorConditionManager(clon);
0803: DefaultTableModel tableDataModel = (DefaultTableModel) getDatajTable()
0804: .getModel();
0805: tableDataModel.fireTableChanged(null);
0806: }
0807:
0808: /**
0809: * Carga el valor de todas las metricas y setea pivotTableProperties
0810: * @param states
0811: */
0812: private void loadAllMetrics(Map states) throws InfoException {
0813: java.util.List list = reportResult.getReportQuery()
0814: .getMetrics();
0815: for (int index = 0; index < list.size(); index++) {
0816: QueryMetric queryMetric = (QueryMetric) list.get(index);
0817: ReportMetricSpec metricSpec = reportResult
0818: .getMetricFromName(queryMetric.getName());
0819: if (metricSpec != null) {
0820: MetricState metricState = new MetricState(metricSpec);
0821: metricState.setVisible(queryMetric.getVisible());
0822: states.put(metricSpec.getName(), metricState);
0823: tableProperties.setVisibleMetrics(metricState);
0824: } else {
0825: throw new InfoException(LanguageTraslator
0826: .traslate("377")
0827: + " " + queryMetric.getName());
0828: }
0829: }
0830: }
0831:
0832: /**
0833: *Sincroniza el size de las columnas de rowHeaderjTable con las columnas de datajTable
0834: *
0835: */
0836: private void dataTableHeaderMouseReleased() {
0837: String width = null;
0838: if (pivotTableFrame.isSelected()) {
0839: if (rowHeaderjTable.getTableHeader().isVisible()) {
0840: for (int index = 0; index < datajTable.getTableHeader()
0841: .getColumnModel().getColumnCount(); index++) {
0842: width = Integer.toString(datajTable
0843: .getColumnModel().getColumn(index)
0844: .getPreferredWidth());
0845: datajTable.getTableHeader().getColumnModel()
0846: .getColumn(index).setHeaderValue(
0847: new Integer(index));
0848: columnHeaderjTable.getTableHeader()
0849: .getColumnModel().getColumn(index)
0850: .setPreferredWidth(Integer.parseInt(width));
0851: columnHeaderjTable.getTableHeader()
0852: .getColumnModel().getColumn(index)
0853: .setMinWidth(30);
0854: datajTable.getTableHeader().getColumnModel()
0855: .getColumn(index).setMinWidth(30);
0856: }
0857: datajTable.getTableHeader().setPreferredSize(
0858: new Dimension(0, 16));
0859: datajTable.getTableHeader().revalidate();
0860: } else {
0861: pivotTableFrame.setState(false);
0862: datajTable.getTableHeader().setPreferredSize(
0863: new Dimension(0, 16));
0864: }
0865: }
0866: }
0867:
0868: /**
0869: * Ajusta el tamao de las columnas de la tabla rowHeaderjTable con respecto a los componentes que se encuentran
0870: * en targetP anels
0871: * @param evt
0872: */
0873: private void rowTableHeaderMouseReleased(MouseEvent evt) {
0874: int width = 0;
0875: int heigth = 0;
0876: int col = 0;
0877: if (rowHeaderjTable.getTableHeader().isVisible()) {
0878: col = rowHeaderjTable.columnAtPoint(evt.getPoint());
0879: if (col < 0)
0880: col = 0;
0881: width = rowHeaderjTable.getTableHeader().getColumnModel()
0882: .getColumn(col).getWidth();
0883: for (Iterator iterator = targetPanels.values().iterator(); iterator
0884: .hasNext();) {
0885: JPanel panel1 = (JPanel) iterator.next();
0886: panel1.setMinimumSize(new Dimension(30, (int) panel1
0887: .getPreferredSize().getHeight()));
0888: if (panel1.getName() == DimensionDefinitionLocationType.ROW
0889: .toString()
0890: && panel1.getComponentCount() > 0) {
0891: DragSourcePanel drag = (DragSourcePanel) panel1
0892: .getComponent(col);
0893: drag.setMinimumSize(new Dimension(30, (int) drag
0894: .getPreferredSize().getHeight()));
0895: drag.setPreferredSize(new Dimension(width,
0896: (int) drag.getPreferredSize().getHeight()));
0897: panel1
0898: .setPreferredSize(new Dimension(width,
0899: (int) panel1.getPreferredSize()
0900: .getHeight()));
0901: heigth = (int) panel1.getPreferredSize()
0902: .getHeight();
0903: panel1
0904: .setPreferredSize(new Dimension(width,
0905: heigth));
0906: rowHeaderjTable.getTableHeader().getColumnModel()
0907: .getColumn(col).setMinWidth(30);
0908: rowHeaderjTable.revalidate();
0909: }
0910: }
0911: Rectangle rec = rowHeaderjTable.getCellRect(0,
0912: rowHeaderjTable.getColumnCount(), true);
0913: mainSplit.setDividerLocation(rec.x);
0914: }
0915: }
0916:
0917: /**
0918: * Sincroniza el Scroll horizontal con el JScrollPane(colTableJScroll) y JScrollPane(centerJScrollPane)
0919: *
0920: * @param evt
0921: */
0922: private void horizontalScrollBarAdjustmentValue(AdjustmentEvent evt) {
0923: int widrh = datajTable.getPreferredScrollableViewportSize().width;
0924: float porc = (widrh * 10) / 100;
0925: horizontal.setUnitIncrement((int) porc);
0926: colTableJScroll.getHorizontalScrollBar().setValue(
0927: evt.getAdjustable().getValue());
0928: centerJScrollPane.getHorizontalScrollBar().setValue(
0929: evt.getAdjustable().getValue());
0930: }
0931:
0932: /**
0933: * Sincroniza los JScrollPane leftCenterScrollPane y centerJScrollPane con el SCrollBar vertical
0934: * @param evt
0935: */
0936: private void verticalScrollBarAdjustmentValue(AdjustmentEvent evt) {
0937: leftCenterScrollPane.getVerticalScrollBar().setValue(
0938: evt.getAdjustable().getValue());
0939: centerJScrollPane.getVerticalScrollBar().setValue(
0940: evt.getAdjustable().getValue());
0941: }
0942:
0943: /**
0944: * Metodo utilizado para mostrar los header de las tablas rowHeaderjTable y datajTable para poder realizar los
0945: * resize de las columnas
0946: */
0947: public void maximizarActionPerformed() {
0948: if (pivotTableFrame.isSelected()) {
0949: for (int index = 0; index < rowHeaderjTable
0950: .getTableHeader().getColumnModel().getColumnCount(); index++) {
0951: rowHeaderjTable.getTableHeader().getColumnModel()
0952: .getColumn(index).setHeaderValue(
0953: Integer.toString(index));
0954: rowHeaderjTable.getTableHeader().getColumnModel()
0955: .getColumn(index).setMinWidth(20);
0956: }
0957: for (int index = 0; index < datajTable.getTableHeader()
0958: .getColumnModel().getColumnCount(); index++) {
0959: datajTable.getTableHeader().getColumnModel().getColumn(
0960: index).setHeaderValue(Integer.toString(index));
0961: }
0962: rowHeaderjTable.getTableHeader().setPreferredSize(
0963: new Dimension(0, 18));
0964: datajTable.getTableHeader().setPreferredSize(
0965: new Dimension(0, 16));
0966: rowHeaderjTable.getTableHeader()
0967: .setReorderingAllowed(false);
0968: datajTable.getTableHeader().setReorderingAllowed(false);
0969:
0970: } else {
0971: rowHeaderjTable.getTableHeader().setPreferredSize(
0972: new Dimension(0, 0));
0973: datajTable.getTableHeader().setPreferredSize(
0974: new Dimension(0, 0));
0975: }
0976: rowHeaderjTable.getTableHeader().getColumnModel()
0977: .setColumnMargin(0);
0978: rowHeaderjTable.getTableHeader().updateUI();
0979: datajTable.getTableHeader().getColumnModel().setColumnMargin(0);
0980: datajTable.getTableHeader().updateUI();
0981: }
0982:
0983: /**
0984: * Realiza el update de la tabla rowHeaderjTable , ajustando el ancho de las columnas contra los paneles
0985: * que actuan con propiedades de Drag & Drop
0986: */
0987: private void rowHeaderjTableComponentResized() throws InfoException {
0988: setRowDimensionMap();
0989: setSize();
0990: invaildatePanels();
0991: }
0992:
0993: /**
0994: * realiza el desplazamiento del JScrollPane pageFieldsScrollPane
0995: * @param evt
0996: */
0997: private void pageFieldScrollBarAdjustmentValueChanged(
0998: AdjustmentEvent evt) {
0999: int value = evt.getValue();
1000: pageFieldsScrollPane.getHorizontalScrollBar().setValue(value);
1001: }
1002:
1003: /**
1004: * Setea el size del componente izquierdo del split leftSplitNorthPanel
1005: */
1006: private void setComponentSize() {
1007: Dimension dim = leftSplitNorthPanel.getPreferredSize();
1008: dim.width = columnPanel.getPreferredSize().width;
1009: dim.height += columnPanel.getPreferredSize().height - 5;
1010: leftSplitNorthPanel.setPreferredSize(dim);
1011: }
1012:
1013: /**
1014: * Sincroniza el alto de la tabla columnHeaderjTable con el alto del panel ubicado al norte en el lado izquirdo del split
1015: */
1016: private void resizeComponent() {
1017: Dimension dimension = northPanel.getPreferredSize();
1018: leftSplitNorthPanel.setPreferredSize(dimension);
1019: leftSplitNorthPanel.revalidate();
1020: }
1021:
1022: /**
1023: * Sincroniza a los paneles de southRowFieldDropTarget con el ancho de las columnas de rowHeaderjTable
1024: */
1025:
1026: private void setSize() {
1027: int width = 0;
1028: int index = 0;
1029: rowHeaderjTable.validate();
1030: Iterator iterator = getAllRowColumnProperties().values()
1031: .iterator();
1032: while (iterator.hasNext()) {
1033: ColumnProperties properties = (ColumnProperties) iterator
1034: .next();
1035: JPanel panel = (JPanel) dragPanels.get(properties
1036: .getColumnName());
1037: width = properties.getWidth();
1038: if (index == 0) {
1039: width++;
1040: }
1041: panel.setPreferredSize(new Dimension(width, (int) panel
1042: .getPreferredSize().getHeight()));
1043: ((JPanel) panel.getParent()).revalidate();
1044: panel.revalidate();
1045: rowHeaderjTable.invalidate();
1046: ((HeaderTableUI) rowHeaderjTable.getUI()).resetFinals();
1047: index++;
1048: }
1049: }
1050:
1051: /**
1052: * crea y setea el Split mainSplit , con las dos subSecciones izquierda y derecha
1053: * @return
1054: */
1055: private Component createMainSplitPanel() {
1056: mainSplitPanel = new JPanel();
1057: mainSplit = new JSplitPane();
1058: mainSplit.setLeftComponent(createLeftCenterPanel());
1059: mainSplit.setRightComponent(createRigthCenterPanel());
1060: mainSplitPanel.setLayout(new BorderLayout());
1061: mainSplitPanel.add(mainSplit, BorderLayout.CENTER);
1062: mainSplit.setDividerSize(3);
1063: return mainSplitPanel;
1064: }
1065:
1066: /**
1067: * Genera y setea el lado izquierdo del Split mainSplait
1068: * @return el panel rigthCenterPanel
1069: */
1070: private Component createRigthCenterPanel() {
1071: rigthCenterPanel = new JPanel();
1072: rigthCenterPanel.setLayout(new BorderLayout());
1073: rigthCenterPanel.add(createNorthPanel(), BorderLayout.NORTH);
1074: rigthCenterPanel.add(createCenterJScrollPane(),
1075: BorderLayout.CENTER);
1076: rigthCenterPanel.add(createHorizontalScrollBar(),
1077: BorderLayout.SOUTH);
1078: centerJScrollPane.setHorizontalScrollBar(horizontal);
1079: centerJScrollPane
1080: .setVerticalScrollBar(createVeritcalScrollBar());
1081: return rigthCenterPanel;
1082: }
1083:
1084: /**
1085: * retorna un ScrollBar Verical
1086: * @return vertical
1087: */
1088: private JScrollBar createVeritcalScrollBar() {
1089: vertical = new JScrollBar(JScrollBar.VERTICAL);
1090: return vertical;
1091: }
1092:
1093: /**
1094: * crea y devuelve un panel que contiene el ScrollBar horizontal del lado derecho del plit al al sur
1095: * @return
1096: */
1097: private Component createHorizontalScrollBar() {
1098: horizontal = new JScrollBar(JScrollBar.HORIZONTAL);
1099: JPanel horizontalPanel = new JPanel(new BorderLayout());
1100: horizontalPanel.add(horizontal, BorderLayout.CENTER);
1101: return horizontalPanel;
1102: }
1103:
1104: /**
1105: * Devuelve el panel del lado derecho ubicado al norte en el split
1106: * @return el panel northPanel
1107: */
1108: private Component createNorthPanel() {
1109: northPanel = new JPanel();
1110: northPanel.setLayout(new BorderLayout());
1111: northPanel.add(createNorthJPanel(), BorderLayout.CENTER);
1112: return northPanel;
1113: }
1114:
1115: /**
1116: * retorna el panel ubicado al centro del panel northPanel
1117: * @return
1118: */
1119: private Component createNorthJPanel() {
1120: JPanel component = new JPanel();
1121: component.setLayout(new BorderLayout());
1122: component.add(createEastFiller(), BorderLayout.EAST);
1123: component.add(createColumnHeaderPanel(), BorderLayout.CENTER);
1124: return component;
1125: }
1126:
1127: /**
1128: * Crea dibuja y setea las propiedades la tabla columnHeaderPanel
1129: * @return
1130: */
1131: private Component createColumnHeaderPanel() {
1132: columnHeaderPanel = new JPanel();
1133: columnHeaderPanel.setLayout(new BorderLayout());
1134: columnHeaderPanel.add(createColumnPanel(), BorderLayout.SOUTH);
1135: columnHeaderPanel.add(createColumnDropTarget(),
1136: BorderLayout.NORTH);
1137: return columnHeaderPanel;
1138: }
1139:
1140: /**
1141: * crea el panel que contiene el JScrollPane oculto donde se ubica la tabla columnHeaderjTable
1142: * @return
1143: */
1144: private Component createColumnPanel() {
1145: columnPanel = new JPanel();
1146: columnPanel.setLayout(new BorderLayout());
1147: columnPanel.add(createColTableJScroll(), BorderLayout.CENTER);
1148: return columnPanel;
1149: }
1150:
1151: /**
1152: * Crea el panel que se encuentra sobre la tabla columnHeaderjTable al cual se le podran colocar los paneles con
1153: * propiedades de drag and drop
1154: * @return
1155: */
1156: private Component createColumnDropTarget() {
1157: JComponent panel = createTargetPanel(
1158: DimensionDefinitionLocationType.COLUMN.toString(),
1159: Color.WHITE);
1160: panel.setPreferredSize(new Dimension(0, 15));
1161: return panel;
1162: }
1163:
1164: /**
1165: * Crea el panel utilizado para separar la tabla columnHeaderjTable con el
1166: * @return
1167: */
1168: private Component createEastFiller() {
1169: eastFiller = new JPanel();
1170: eastFiller.setLayout(new BorderLayout());
1171: eastFiller.setPreferredSize(new Dimension(15, 0));
1172: return eastFiller;
1173: }
1174:
1175: /**
1176: * devuelve el scroll ubicado en el centro del lado derecho del split
1177: * @return
1178: */
1179: private Component createCenterJScrollPane() {
1180: centerJScrollPane = new JScrollPane();
1181: centerJScrollPane
1182: .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
1183: centerJScrollPane
1184: .setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
1185: JPanel aux = new JPanel(new BorderLayout());
1186: aux.add(createTableData(), BorderLayout.CENTER);
1187: aux.add(datajTable.getTableHeader(), BorderLayout.NORTH);
1188: centerJScrollPane.getViewport().add(aux);
1189: return centerJScrollPane;
1190: }
1191:
1192: /**
1193: * crea un JScrollPane oculto donde se apoya la tabla columnHeaderjTable
1194: * @return
1195: */
1196: private Component createColTableJScroll() {
1197: colTableJScroll = new JScrollPane();
1198: colTableJScroll
1199: .setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
1200: colTableJScroll
1201: .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
1202: colTableJScroll.setAutoscrolls(true);
1203: JPanel aux = new JPanel();
1204: JViewport view = new JViewport();
1205: aux.setLayout(new BorderLayout());
1206: aux.add(createColumnHeaderTable(), BorderLayout.CENTER);
1207: view.add(aux, BorderLayout.NORTH);
1208: colTableJScroll.setViewport(view);
1209: return colTableJScroll;
1210: }
1211:
1212: /**
1213: * Crea la tabla columnHeaderjTable
1214: * @return
1215: */
1216: private JTable createColumnHeaderTable() {
1217: columnHeaderjTable = new JTable();
1218: columnHeaderjTable.setDefaultRenderer(Object.class,
1219: new HeaderTableRenderer());
1220: columnHeaderjTable
1221: .setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_LAST_COLUMN);
1222: columnHeaderjTable.setUI(new ColumnHeaderTableUI());
1223: columnHeaderjTable.addMouseListener(new MouseAdapter() {
1224: public void mouseReleased(MouseEvent e) {
1225: try {
1226: changeNodeState(e);
1227: } catch (Exception el) {
1228: ShowExceptionMessageDialog
1229: .initExceptionDialogMessage(
1230: LanguageTraslator.traslate("328"),
1231: el);
1232: }
1233: }
1234: });
1235: return columnHeaderjTable;
1236: }
1237:
1238: protected DimensionValueNode getRowsRoot() {
1239: return ((HeaderTableModel) getRowHeaderjTable().getModel())
1240: .getDimensionValueNode();
1241: }
1242:
1243: protected DimensionValueNode getColumnsRoot() {
1244: return ((HeaderTableModel) getColumnHeaderjTable().getModel())
1245: .getDimensionValueNode();
1246: }
1247:
1248: /**
1249: * Lllenar el contenido de las tablas
1250: * @param reportResult
1251: */
1252: public void fillContents(ReportResult reportResult)
1253: throws InfoException {
1254: removeAllPanels();
1255: JTable rowTable = getRowHeaderjTable();
1256: JTable colTable = getColumnHeaderjTable();
1257: JTable dataTable = getDatajTable();
1258: fillComponents();
1259: Vector dataVector = ((CubeReportResult) reportResult)
1260: .getDataVector();
1261: TableModel dataModel;
1262: if (dataVector != null) {
1263: dataModel = new DefaultTableModel(
1264: dataVector,
1265: getColumnsNames(((Vector) dataVector.get(0)).size()));
1266: } else {
1267: dataVector = new Vector();
1268: dataModel = new DefaultTableModel(dataVector, null);
1269: }
1270:
1271: dataTable.setModel(dataModel);
1272: if (dataVector.size() > 0) {
1273: rowTable.setModel(((CubeReportResult) reportResult)
1274: .getRowsModel());
1275: colTable.setModel(((CubeReportResult) reportResult)
1276: .getColumnsModel());
1277: }
1278: /*if (dataVector.size() > 0) {
1279: colModel = HeaderTableModel.newColumnHeaderTableModel(columnsRoot, getWithTotals(), columnsRoot.getDimensionCount(), reportResult);
1280: rowModel = HeaderTableModel.newRowHeaderTableModel(rowsRoot, getWithTotals(), rowsRoot.getDimensionCount(), reportResult);
1281: rowTable.setModel(rowModel);
1282: colTable.setModel(colModel);
1283: } */
1284: DefaultTableModel tableDataModel = (DefaultTableModel) dataTable
1285: .getModel();
1286: tableDataModel.fireTableChanged(null);
1287: if (!getRowHeaderDimension().isEmpty()) {
1288: applyDimensionColumnProperties();
1289: invaildatePanels();
1290: }
1291:
1292: // setSize();
1293: pivotTableFrame.setState(false);
1294: maximizarActionPerformed();
1295: if (getRowHeaderDimension().isEmpty()) {
1296: mainSplit.setDividerLocation(100);
1297: } else {
1298: int heigth = pivotTableFrame.getFrame().getContentPane()
1299: .getPreferredSize().height;
1300: leftCenterPanel.setPreferredSize(new Dimension(
1301: adjustmentSizeSplit(), heigth));
1302: setSize();
1303: invaildatePanels();
1304: }
1305: mainSplit.invalidate();
1306: }
1307:
1308: private void applyDimensionColumnProperties() {
1309: Iterator iterator = tableProperties.getColumnProperties()
1310: .iterator();
1311: int ubication = 0;
1312: while (iterator.hasNext()) {
1313: ColumnProperties properties = (ColumnProperties) iterator
1314: .next();
1315: if (DimensionDefinitionLocationType.ROW.toString()
1316: .compareToIgnoreCase(properties.getLocation()) == 0) {
1317: ubication = properties.getUbication();
1318: if (rowHeaderjTable.getColumnModel().getColumnCount() > 0) {
1319: rowHeaderjTable.getColumnModel().getColumn(
1320: ubication).setPreferredWidth(
1321: properties.getWidth());
1322: }
1323: }
1324: }
1325: }
1326:
1327: /**
1328: * Guarda los width de las columnas pertenecientes a roeHeaderTable
1329: */
1330: private void setRowDimensionMap() throws InfoException {
1331: Map rowDimension = getAllRowColumnProperties();
1332: for (int index = 0; index < rowHeaderjTable.getModel()
1333: .getColumnCount(); index++) {
1334: if (!rowDimension.isEmpty()) {
1335:
1336: JPanel panel = (JPanel) targetPanels
1337: .get(DimensionDefinitionLocationType.ROW
1338: .toString());
1339: DragSourcePanel sourcePanel = (DragSourcePanel) panel
1340: .getComponent(index);
1341: ColumnProperties properties = tableProperties
1342: .getRowColumn(sourcePanel.getName());
1343: properties.setWidth(rowHeaderjTable.getColumnModel()
1344: .getColumn(index).getWidth());
1345: properties.setColumnName(sourcePanel.getName());
1346: ArrayList list = (ArrayList) reportResult
1347: .getReportQuery().getDimensionsByLocation(
1348: DimensionDefinitionLocationType
1349: .valueOf(panel.getName()));
1350: QueryDimension queryDimension = (QueryDimension) list
1351: .get(index);
1352: properties.setOrder(queryDimension.getOrder());
1353: properties
1354: .setLocation(DimensionDefinitionLocationType.ROW
1355: .toString());
1356: rowDimension.put(sourcePanel.getName(), properties);
1357: rowDimension
1358: .put(properties.getColumnName(), properties);
1359: }
1360: }
1361: tableProperties.updateColumnsProperties();
1362: rowHeaderDimension = rowDimension;
1363: }
1364:
1365: /**
1366: * Retorna la posicion donde se ajusta la barra del split
1367: */
1368: private int adjustmentSizeSplit() {
1369: Map rowDimension = getAllRowColumnProperties();
1370: int widthSplit = 0;
1371: if (!rowDimension.isEmpty()) {
1372: Iterator iterator = rowDimension.values().iterator();
1373: while (iterator.hasNext()) {
1374: ColumnProperties properties = (ColumnProperties) iterator
1375: .next();
1376: if (properties != null) {
1377: widthSplit += properties.getWidth() + 2;
1378: }
1379: }
1380: }
1381: return widthSplit;
1382: }
1383:
1384: /**
1385: * Limpia el contenido de todos los paneles de ROW - COLUMN - PAGE
1386: */
1387: private void removeAllPanels() {
1388: Iterator iterator = targetPanels.values().iterator();
1389: while (iterator.hasNext()) {
1390: DropTargetPanel panel = (DropTargetPanel) iterator.next();
1391: if (panel.getComponentCount() > 0) {
1392: panel.removeAllComponents();
1393: }
1394: }
1395: changeDimensionLocation = new HashMap();
1396: dragPanels = new Hashtable();
1397: page = 0;
1398: col = 0;
1399: row = 0;
1400: }
1401:
1402: /**
1403: * Accion de colasado o expandido de un grupo de celdas
1404: * @param e
1405: */
1406: private void changeNodeState(MouseEvent e) throws InfoException {
1407: JTable comp = (JTable) e.getComponent();
1408: int row = comp.rowAtPoint(e.getPoint());
1409: int col = comp.columnAtPoint(e.getPoint());
1410: Rectangle rect = comp.getCellRect(row, col, true);
1411: double cellx = e.getPoint().getX() - rect.getX();
1412: double celly = e.getPoint().getY() - rect.getY();
1413: HeaderTableRenderer renderer = (HeaderTableRenderer) comp
1414: .getDefaultRenderer(Object.class);
1415: int iconWidth = renderer.getIconWidth();
1416: int iconHeight = renderer.getIconHeight();
1417: if (cellx <= iconWidth && celly <= iconHeight) {
1418: HeaderTableModel model = (HeaderTableModel) comp.getModel();
1419: boolean stateChanged = model.changeNodeState(row, col);
1420: if (stateChanged) {
1421: boolean isDistributed = pivotTableFrame
1422: .getReportGeneratorConfiguration()
1423: .getIsDistributed();
1424: Vector dataVector = pivotTableFrame.getReportManager()
1425: .getUpdatedDataModel(
1426: pivotTableFrame.getReportHandle(),
1427: model.getMode(), row, col,
1428: isDistributed);
1429:
1430: TableModel dataModel = new DefaultTableModel(
1431: dataVector,
1432: getColumnsNames(((Vector) dataVector.get(0))
1433: .size()));
1434: getDatajTable().setModel(dataModel);
1435: getDatajTable().revalidate();
1436:
1437: int count;
1438: if (model.getMode() == HeaderTableModel.MODE_ROW) {
1439: ((HeaderTableUI) rowHeaderjTable.getUI())
1440: .resetFinals();
1441: count = dataVector.size();
1442: ((HeaderTableModel) comp.getModel())
1443: .setRowCount(count);
1444: HeaderTableModel tm = ((HeaderTableModel) comp
1445: .getModel());
1446: tm.fireTableChanged(null);
1447: setSize();
1448: } else {
1449: ((HeaderTableUI) columnHeaderjTable.getUI())
1450: .resetFinals();
1451: count = ((Vector) dataVector.get(0)).size();
1452: ((HeaderTableModel) comp.getModel())
1453: .setRowCount(count);
1454: HeaderTableModel tm = ((HeaderTableModel) comp
1455: .getModel());
1456: DefaultTableModel tableDataModel = (DefaultTableModel) datajTable
1457: .getModel();
1458: tableDataModel.fireTableChanged(null);
1459: tm.fireTableChanged(null);
1460: revalidateTable();
1461: }
1462: }
1463: }
1464: }
1465:
1466: /**
1467: * Actualiza los anchos de las columnas de la tabla columnHeaderjTable
1468: */
1469: private void revalidateTable() {
1470: for (int index = 0; index < datajTable.getModel()
1471: .getColumnCount(); index++) {
1472: columnHeaderjTable.getColumnModel().getColumn(index)
1473: .setWidth(
1474: datajTable.getTableHeader()
1475: .getColumnModel().getColumn(index)
1476: .getWidth());
1477: }
1478: }
1479:
1480: /**
1481: * crea y devuelve el panel que contiene a la tabla dataTable en el centro del split del lado derecho
1482: * @return
1483: */
1484: private Component createTableData() {
1485: datajTable = new JTable();
1486: DataTableCellRenderer cellRenderer = new DataTableCellRenderer(
1487: colorConditionManager, getReportResult(), Color.WHITE);
1488: cellRenderer.setHorizontalAlignment(JLabel.RIGHT);
1489: datajTable.setDefaultRenderer(Object.class, cellRenderer);
1490: datajTable
1491: .setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_LAST_COLUMN);
1492: datajTable.setColumnSelectionAllowed(true);
1493: datajTable.setAutoscrolls(false);
1494: datajTable.getTableHeader().setPreferredSize(
1495: new Dimension(0, 0));
1496: datajTable.setDefaultEditor(Object.class, null);
1497: return datajTable;
1498: }
1499:
1500: /**
1501: * Genera un componente el cual se coloca en el centro del JSplitPane mainSplit de lado izquierdo
1502: * @return retorna el componente a agregar
1503: */
1504: private Component createLeftCenterPanel() {
1505: leftCenterPanel = new JPanel();
1506: leftCenterPanel.setLayout(new BorderLayout());
1507: leftCenterPanel.add(createLeftSplitNorthPanel(),
1508: BorderLayout.NORTH);
1509: leftCenterPanel.add(createCenterSplitPanel(),
1510: BorderLayout.CENTER);
1511: leftCenterPanel.add(createSouthFiller(), BorderLayout.SOUTH);
1512: return leftCenterPanel;
1513: }
1514:
1515: /**
1516: * Crea un panel al sur del split del lado derecho
1517: * @return
1518: */
1519: private Component createSouthFiller() {
1520: southFiller = new JPanel();
1521: southFiller.setLayout(new BorderLayout());
1522: southFiller.setPreferredSize(new Dimension(0, 15));
1523: return southFiller;
1524: }
1525:
1526: /**
1527: * Crea el panel central del lado izquierdo del split
1528: * @return
1529: */
1530: private Component createCenterSplitPanel() {
1531: centerSplitNorthPanel = new JPanel();
1532: centerSplitNorthPanel.setLayout(new BorderLayout());
1533: centerSplitNorthPanel.add(createLeftCenterScrollPane(),
1534: BorderLayout.CENTER);
1535: return centerSplitNorthPanel;
1536: }
1537:
1538: /**
1539: * Crea un JScrollPane en el panel central del lado izuiqrdo del split
1540: * @return
1541: */
1542: private Component createLeftCenterScrollPane() {
1543: leftCenterScrollPane = new JScrollPane();
1544: leftCenterScrollPane
1545: .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
1546: leftCenterScrollPane
1547: .setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
1548: leftCenterScrollPane.getViewport().add(createRowHeaderjTable(),
1549: BorderLayout.CENTER);
1550: return leftCenterScrollPane;
1551: }
1552:
1553: /**
1554: * crea la tabla rowHeaderjTable y carga los datos de la misma
1555: * @return rowHeaderjTable
1556: */
1557: private Component createRowHeaderjTable() {
1558: rowHeaderjTable = new JTable();
1559: rowHeaderjTable.setDefaultRenderer(Object.class,
1560: new HeaderTableRenderer());
1561: rowHeaderjTable
1562: .setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
1563: rowHeaderjTable.getTableHeader().setPreferredSize(
1564: new Dimension(0, 0));
1565: rowHeaderjTable.setUI(new RowHeaderTableUI());
1566: rowHeaderjTable.addMouseListener(new MouseAdapter() {
1567: public void mouseReleased(MouseEvent e) {
1568: try {
1569: changeNodeState(e);
1570: } catch (InfoException e1) {
1571: ShowExceptionMessageDialog
1572: .initExceptionDialogMessage(
1573: LanguageTraslator.traslate("328"),
1574: e1);
1575: }
1576: }
1577: });
1578: return rowHeaderjTable;
1579: }
1580:
1581: /**
1582: Crea un panel vacio del lado izquierdo del Split , en la parte suporior del componente
1583: * @return devuelve el panel leftSplitNorthPanel
1584: */
1585: private Component createLeftSplitNorthPanel() {
1586: leftSplitNorthPanel = new JPanel();
1587: leftSplitNorthPanel.setLayout(new BorderLayout());
1588: leftSplitNorthPanel.add(crateSouthRowFieldDropTarget(),
1589: BorderLayout.SOUTH);
1590: return leftSplitNorthPanel;
1591: }
1592:
1593: /**
1594: * Crea un panel al sur del panel vacio leftSplitNorthPanel donde se colocan componente con
1595: * propiedades de Drag and Drop
1596: * @return el panel southRowFieldDropTarget
1597: */
1598:
1599: private Component crateSouthRowFieldDropTarget() {
1600: southRowFieldDropTarget = new JPanel();
1601: southRowFieldDropTarget.setLayout(new BorderLayout());
1602: JComponent comp = (JComponent) crateRowFieldDropTarget();
1603: southRowFieldDropTarget.setPreferredSize(new Dimension(0, 18));
1604: southRowFieldDropTarget.add(comp);
1605: return southRowFieldDropTarget;
1606: }
1607:
1608: /**
1609: * Crea el componente que acepta acciones de Drag and Drop en el panel southRowFieldDropTarget
1610: * @return
1611: */
1612: private Component crateRowFieldDropTarget() {
1613: return createTargetPanel(DimensionDefinitionLocationType.ROW
1614: .toString(), Color.WHITE);
1615: }
1616:
1617: /**
1618: * Genera el panel del Norte donde se colocan paneles con propiedades de Drag and Drop
1619: * @return componente que acepta paneles para drag and drop
1620: */
1621: private Component createPageFieldComponents() {
1622: pageFields = new JPanel();
1623: pageFields.setLayout(new BorderLayout());
1624: pageFields.add(createPageFillerEast(), BorderLayout.EAST);
1625: pageFields.add(createPageFieldsScrollPane(),
1626: BorderLayout.CENTER);
1627: return pageFields;
1628: }
1629:
1630: /**
1631: * Crea el JScrollPane pageFieldsScrollPane al norte del componente pivoteTable
1632: * @return
1633: */
1634: private JComponent createPageFieldsScrollPane() {
1635: pageFieldsScrollPane = new javax.swing.JScrollPane();
1636: pageFieldsScrollPane.setPreferredSize(new Dimension(0, 20));
1637: pageFieldsScrollPane
1638: .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
1639: pageFieldsScrollPane
1640: .setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
1641: pageFieldsScrollPane.getViewport().add(
1642: createPageConteinerComponent(), FlowLayout.LEFT);
1643: return pageFieldsScrollPane;
1644: }
1645:
1646: /**
1647: * Crea el panel ubicado al norte del componente PivoteTable
1648: * @return
1649: */
1650: private Component createPageConteinerComponent() {
1651: pageConteinerComponent = new JPanel();
1652: pageConteinerComponent.setLayout(new BorderLayout());
1653: JComponent comp = createPageFieldDropTarget();
1654: pageConteinerComponent.add(comp, BorderLayout.CENTER);
1655: return pageConteinerComponent;
1656: }
1657:
1658: /**
1659: Crea un panel para ser utilizado con propiedades de Drag and Drop
1660: */
1661:
1662: private JComponent createPageFieldDropTarget() {
1663: return createTargetPanel(DimensionDefinitionLocationType.PAGE
1664: .toString(), Color.WHITE);
1665: }
1666:
1667: /**
1668: * Craa un panel donde se coloca el Scroll el la parte superior derecha del componente
1669: * @return un panel
1670: */
1671: private JComponent createPageFillerEast() {
1672: pageFillerRigth = new JPanel(new BorderLayout());
1673: pageFillerRigth.setPreferredSize(new Dimension(32, 18));
1674: pageFillerRigth.add(createPageFieldScrollBar(),
1675: BorderLayout.CENTER);
1676: return pageFillerRigth;
1677: }
1678:
1679: /**
1680: * crea el JScrollBar el en panel pageFillerRigth
1681: * @return
1682: */
1683: private JComponent createPageFieldScrollBar() {
1684: pageFieldScrollBar = new JScrollBar();
1685: pageFieldScrollBar
1686: .setOrientation(javax.swing.JScrollBar.HORIZONTAL);
1687: pageFieldScrollBar.setUnitIncrement(10);
1688: return pageFieldScrollBar;
1689: }
1690:
1691: /**
1692: * Implementacion del metodo fieldPositionChanged de la interface FieldPositionListener .
1693: *
1694: *
1695: * fieldPositionChanged realiza la acionn de Drop
1696: * @param positionName
1697: * @param fieldName
1698: */
1699: public void fieldPositionChanged(String positionName,
1700: String fieldName, Point location) throws InfoException {
1701: pivotTableFrame.setState(false);
1702: DropTargetPanel panel = (DropTargetPanel) targetPanels
1703: .get(positionName);
1704: DragSourcePanel dpanel = (DragSourcePanel) dragPanels
1705: .get(fieldName);
1706: panel.addFieldPanel(dpanel);
1707: changePositionPanel(fieldName, positionName, location);
1708: changeDimensionLocation.remove(fieldName);
1709: changePosition(panel, positionName);
1710: this .width = 0;
1711:
1712: updateTableProperties(positionName, fieldName);
1713: pivotTableFrame.revalidateReportResult(tableProperties);
1714: fillContents(reportResult);
1715: invaildatePanels();
1716: }
1717:
1718: /**
1719: * Obtiene el indice correspondiente al ArrayLsit de ColumnProperies de una columna determinada
1720: * @param s
1721: * @return
1722: */
1723: public int getColumnPropertiesIndex(String s) {
1724: ArrayList properties = tableProperties.getColumnProperties();
1725: for (int index = 0; index < properties.size(); index++) {
1726: ColumnProperties columnProperties = (ColumnProperties) properties
1727: .get(index);
1728: if (columnProperties.getColumnName().compareToIgnoreCase(s) == 0) {
1729: return index;
1730: }
1731: }
1732: return -1;
1733: }
1734:
1735: /**
1736: * Actualiza la posicion del panael movido a positionName
1737: * @param panel
1738: * @param positionName
1739: */
1740: private void changePosition(DropTargetPanel panel,
1741: String positionName) {
1742: Integer pos = null;
1743: for (int i = 0; i < panel.getComponentCount(); i++) {
1744: DragSourcePanel aux = (DragSourcePanel) panel
1745: .getComponent(i);
1746: Object[] values = (Object[]) changeDimensionLocation
1747: .get(aux.getName());
1748: if (values != null) {
1749: values[1] = new Integer(i);
1750: putObject(aux.getName(), values);
1751: } else {
1752: Object[] val = new Object[3];
1753: if (positionName == DimensionDefinitionLocationType.ROW
1754: .toString()) {
1755: pos = new Integer(
1756: DimensionDefinitionLocationType.ROW_TYPE);
1757: val[0] = pos;
1758: val[1] = new Integer(i);
1759: putObject(aux.getName(), val);
1760:
1761: }
1762: if (positionName == DimensionDefinitionLocationType.COLUMN
1763: .toString()) {
1764: pos = new Integer(
1765: DimensionDefinitionLocationType.COLUMN_TYPE);
1766: val[0] = pos;
1767: val[1] = new Integer(i);
1768: putObject(aux.getName(), val);
1769:
1770: }
1771: if (positionName == DimensionDefinitionLocationType.PAGE
1772: .toString()) {
1773: pos = new Integer(
1774: DimensionDefinitionLocationType.PAGE_TYPE);
1775: val[0] = pos;
1776: val[1] = new Integer(i);
1777: putObject(aux.getName(), val);
1778: }
1779: }
1780: }
1781: }
1782:
1783: /**
1784: * Realiza la accion de Drag & Drop de un panel hacia otro panel
1785: * @param name
1786: * @param position
1787: * @param location
1788: */
1789: private void changePositionPanel(String name, String position,
1790: Point location) {
1791: this .width = 0;
1792: Component[] aux = new Component[2];
1793: JPanel panel1 = (JPanel) targetPanels.get(position);
1794: JPanel source = (JPanel) dragPanels.get(name);
1795: if (panel1.getComponents().length > 1) {
1796: DragSourcePanel drag = null;
1797: for (int index = 0; index < panel1.getComponentCount(); index++) {
1798: drag = (DragSourcePanel) panel1.getComponent(index);
1799: if (index == 0 && drag.getWidth() > location.getX()) {
1800: aux[0] = source;
1801: aux[1] = drag;
1802: Component[] comp = changePositionPanels(panel1
1803: .getComponents(), aux[0], aux[1], index);
1804: panel1.removeAll();
1805: insertComponents(comp, panel1);
1806: return;
1807: } else {
1808: width += drag.getWidth();
1809: if (width < location.getX()) {
1810: aux[0] = source;
1811: aux[1] = drag;
1812: } else {
1813: aux[0] = source;
1814: aux[1] = drag;
1815: Component[] comp = changePositionPanels(panel1
1816: .getComponents(), aux[0], aux[1], index);
1817: panel1.removeAll();
1818: insertComponents(comp, panel1);
1819: return;
1820: }
1821: }
1822: }
1823: }
1824: }
1825:
1826: /**
1827: * Realiza un intercambio de paneles para obtener su posicion actualizada cuando se realiza una accion de
1828: * Drag & Drop
1829: * @param comp
1830: * @param panel1
1831: */
1832: private void insertComponents(Component[] comp, JPanel panel1) {
1833: for (int index = 0; index < comp.length; index++) {
1834: panel1.add(comp[index]);
1835: }
1836: }
1837:
1838: /**
1839: * cambia de posicion los paneles del array de Component para intercambiar las dimensiones
1840: */
1841: private Component[] changePositionPanels(Component[] components,
1842: Component source, Component drag, int locationIndex) {
1843: Component[] aux = new Component[components.length];
1844: int auxIndex = 0;
1845: for (int index = 0; index < components.length; index++) {
1846: if (components[index] == drag) {
1847: aux[index] = source;
1848: auxIndex = index;
1849:
1850: }
1851: }
1852: if (locationIndex == 0) {
1853: System.arraycopy(components, 0, aux, auxIndex + 1,
1854: components.length - 1);
1855: } else {
1856: System.arraycopy(components, 0, aux, 0, locationIndex);
1857: if ((aux.length - 1) - locationIndex == 1) {
1858: aux[aux.length - 1] = drag;
1859: } else {
1860: if ((aux.length - 1) - locationIndex > 0) {
1861: for (int i = locationIndex; i < components.length - 1; i++) {
1862: aux[i + 1] = components[i];
1863: }
1864: }
1865: }
1866: }
1867: return aux;
1868: }
1869:
1870: /**
1871: * Cambia la posicion del panel dentro del changeDimensionValues para poder realizar la nueva querry y ordenar
1872: * los paneles drageables en el lugar apropiado , acomodando las dimensiones
1873: * @param fieldName
1874: * @param location
1875: */
1876: private void changePositionHasTable(String fieldName,
1877: DimensionDefinitionLocationType location) {
1878: Object[] values = new Object[2];
1879: if (location.getType() == DimensionDefinitionLocationType.PAGE_TYPE) {
1880: values[0] = new Integer(location.getType());
1881: values[1] = new Integer(page++);
1882: putObject(fieldName, values);
1883: }
1884: if (location.getType() == DimensionDefinitionLocationType.ROW_TYPE) {
1885: values[0] = new Integer(location.getType());
1886: values[1] = new Integer(row++);
1887: putObject(fieldName, values);
1888: }
1889: if (location.getType() == DimensionDefinitionLocationType.COLUMN_TYPE) {
1890: values[0] = new Integer(location.getType());
1891: values[1] = new Integer(col++);
1892: putObject(fieldName, values);
1893: }
1894: }
1895:
1896: /**
1897: * Verifica si existe el objeto en el HashTable changeDimensionValues, si existe lo borra y lo pone nuevamente ,
1898: * sino , lo ingresa directamente
1899: * @param key
1900: * @param values
1901: */
1902: private void putObject(String key, Object[] values) {
1903: if (changeDimensionLocation.get(key) == null) {
1904: changeDimensionLocation.put(key, values);
1905: } else {
1906: changeDimensionLocation.remove(key);
1907: changeDimensionLocation.put(key, values);
1908: }
1909: }
1910:
1911: /**
1912: * Metodo utilizado para actualizar los componentes de los paneles en los cuales se realizan acciones de Drag and Drop
1913: */
1914: public void invaildatePanels() {
1915: for (Iterator iterator = targetPanels.values().iterator(); iterator
1916: .hasNext();) {
1917: JPanel panel1 = (JPanel) iterator.next();
1918: panel1.invalidate();
1919: panel1.revalidate();
1920: }
1921: ((HeaderTableUI) columnHeaderjTable.getUI()).resetFinals();
1922: ((HeaderTableUI) rowHeaderjTable.getUI()).resetFinals();
1923: resizeComponent();
1924:
1925: getContentPane().repaint();
1926: }
1927:
1928: /**
1929: * Setea el Objeto
1930: * @param s
1931: * @param panel DropTargetPanel para poder realizar acciones de Drag Drop
1932: * @param location
1933: */
1934: private void addDragPanel(String s, DropTargetPanel panel,
1935: DimensionDefinitionLocationType location) {
1936: DragSourcePanel dragPanel = panel.addField(s, this ,
1937: getColumnDescriptionFromName(s));
1938: dragPanel.setBackground(Color.GRAY);
1939: s.trim();
1940: dragPanels.put(s, dragPanel);
1941: changePositionHasTable(s, location);
1942: if (location == DimensionDefinitionLocationType.PAGE) {
1943: int width = dragPanel.getMinimumSize().width;
1944: pageFieldScrollBar.setMaximum(pageFieldScrollBar
1945: .getMaximum()
1946: + width);
1947:
1948: }
1949: }
1950:
1951: /**
1952: * Craga de componentes drageables
1953: */
1954: private void fillComponents() throws InfoException {
1955: DimensionDefinitionLocationType location;
1956: location = DimensionDefinitionLocationType.PAGE;
1957: addFieldsByLocation((DropTargetPanel) targetPanels.get(location
1958: .toString()), location);
1959: location = DimensionDefinitionLocationType.ROW;
1960: addFieldsByLocation((DropTargetPanel) targetPanels.get(location
1961: .toString()), location);
1962: location = DimensionDefinitionLocationType.COLUMN;
1963: addFieldsByLocation((DropTargetPanel) targetPanels.get(location
1964: .toString()), location);
1965: }
1966:
1967: /**
1968: * Genera los paneles con sus valores en las distintas orientaciones(PAGE ROW COLUMN )
1969: */
1970: private void addFieldsByLocation(DropTargetPanel targetPanel,
1971: DimensionDefinitionLocationType location)
1972: throws InfoException {
1973: ArrayList list = (ArrayList) reportResult.getReportQuery()
1974: .getDimensionsByLocation(location);
1975: loadTargetPanel(list, targetPanel);
1976:
1977: }
1978:
1979: /**
1980: * Llena las propiedades de las Columnas de la vista correspondiente
1981: * @param list
1982: * @param location
1983: * @throws InfoException
1984: */
1985: private void fillColumnsProperties(ArrayList list, String location)
1986: throws InfoException {
1987: Iterator iterator = list.iterator();
1988: while (iterator.hasNext()) {
1989: QueryDimension dimension = (QueryDimension) iterator.next();
1990: ColumnProperties properties = new ColumnProperties();
1991: properties.setColumnName(dimension.getName());
1992: properties.setWidth(DEFAULT_COLUMN_WIDTH);
1993: int indexDimension = reportResult.getReportQuery()
1994: .getQueryDimensionFromName(
1995: properties.getColumnName()).getIndex();
1996: properties.setExcludeValue(reportResult.getReportQuery()
1997: .getExcludedValues(indexDimension));
1998: properties.setOrder(reportResult.getReportQuery()
1999: .getQueryDimensionFromName(
2000: properties.getColumnName()).getOrder());
2001: properties.setLocation(location);
2002: properties.setRankMetricName(reportResult.getReportQuery()
2003: .getQueryDimensionFromName(
2004: properties.getColumnName())
2005: .getRankMetricName());
2006: properties.setOrder(reportResult.getReportQuery()
2007: .getQueryDimensionFromName(
2008: properties.getColumnName()).getOrder());
2009: tableProperties.getColumnProperties().add(properties);
2010:
2011: }
2012: }
2013:
2014: /**
2015: * Carga los valores para cada dimension
2016: * @param list
2017: * @param targetPanel
2018: */
2019: private void loadTargetPanel(ArrayList list,
2020: DropTargetPanel targetPanel) throws InfoException {
2021: for (int i = 0; i < list.size(); i++) {
2022: QueryDimension queryDimension = (QueryDimension) list
2023: .get(i);
2024: addDragPanel(queryDimension.getName(), targetPanel,
2025: queryDimension.getLocation());
2026: loadRowTableProperties(queryDimension, targetPanel);
2027: }
2028: rowHeaderDimension = getAllRowColumnProperties();
2029:
2030: }
2031:
2032: /**
2033: * Cargas las propiedaes de la vista
2034: * @param queryDimension
2035: * @param targetPanel
2036: //* @throws InfoException
2037: */
2038: private void loadRowTableProperties(QueryDimension queryDimension,
2039: DropTargetPanel targetPanel) throws InfoException {
2040: int index = getColumnPropertiesIndex(queryDimension.getName());
2041: if (index < 0) {
2042: ColumnProperties properties = tableProperties
2043: .getRowColumn(queryDimension.getName());
2044: properties.setColumnName(queryDimension.getName());
2045: properties.setLocation(targetPanel.getName());
2046: properties.setOrder(queryDimension.getOrder());
2047: properties.setUbication(getComponentIndex(targetPanel,
2048: queryDimension.getName()));
2049: tableProperties.updateColumnsProperties();
2050: } else {
2051: Object[] value = (Object[]) changeDimensionLocation
2052: .get(queryDimension.getName());
2053: ColumnProperties properties = tableProperties
2054: .getRowColumn(queryDimension.getName());
2055: properties.setColumnName(queryDimension.getName());
2056: properties.setLocation(targetPanel.getName());
2057: properties.setOrder(queryDimension.getOrder());
2058: int position = ((Integer) value[1]).intValue();
2059: properties.setUbication(position);
2060: tableProperties.updateColumnsProperties();
2061: }
2062: }
2063:
2064: /**
2065: * Determina la posicion en la cual esta ubicado el panel
2066: * @param targetPanel
2067: * @param name
2068: * @return
2069: */
2070: private int getComponentIndex(DropTargetPanel targetPanel,
2071: String name) {
2072: for (int index = 0; index < targetPanel.getComponentCount(); index++) {
2073: JPanel panel = (JPanel) targetPanel.getComponent(index);
2074: if (panel.getName().compareToIgnoreCase(name) == 0) {
2075: return index;
2076: }
2077: }
2078: return -1;
2079: }
2080:
2081: /**
2082: * Deculeve la descripción de la columna indicada
2083: * @param name
2084: * @return
2085: */
2086: private String getColumnDescriptionFromName(String name) {
2087: if (reportResult != null) {
2088: return reportResult.getDimensionFromName(name).getCaption();
2089: }
2090: return name;
2091:
2092: }
2093:
2094: /**
2095: * Crea un panel para ser utilizado con propiedades de Drag and Drop
2096: * @param s
2097: * @param color
2098: * @return
2099: */
2100: private DropTargetPanel createTargetPanel(String s, Color color) {
2101: DropTargetPanel panel;
2102: panel = new DropTargetPanel(s, mainSplit);
2103: panel.setBackground(color);
2104: panel.setFieldPositionListener(this );
2105: targetPanels.put(s, panel);
2106: return panel;
2107: }
2108:
2109: /**
2110: * Setea el Frame donde se va a poner el componente
2111: * @param frame
2112: */
2113: public void setFrame(JFrame frame) {
2114: this .frame = frame;
2115: this .frame
2116: .setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
2117: }
2118:
2119: /**
2120: * Retorna el Frame donde se va a poner el componente
2121: * @return
2122: */
2123: public JFrame getFrame() {
2124: return frame;
2125: }
2126:
2127: /**
2128: * Devuelve el JSplitPane del componente
2129: * @return
2130: */
2131: public JSplitPane getMainSplit() {
2132: return mainSplit;
2133: }
2134:
2135: /**
2136: * Devuleve el Conteiner donde se apoya el componente en el Frame
2137: * @return
2138: */
2139: public Container getContentPane() {
2140: return contentPane;
2141: }
2142:
2143: /**
2144: * Sete el Conteiner del JFrame donde se va a apoyar el componente
2145: * @param contentPane
2146: */
2147: public void setContentPane(Container contentPane) {
2148: this .contentPane = contentPane;
2149: }
2150:
2151: /**
2152: * Este metodo es utilidazo para imprimir el contenido de las tablas
2153: */
2154: public void printPivoteTable(IReportManager reportManager,
2155: ReportView reportView, Dimension dim) {
2156: try {
2157: ReportUI reportUI = new ReportUI(reportResult, reportResult
2158: .getReportSpec(), reportManager,
2159: getPivotTableFrame()
2160: .getReportGeneratorConfiguration(),
2161: reportView, dim);
2162: if (reportUI.getFrame() != null) {
2163: reportUI.show();
2164: }
2165: } catch (Exception e) {
2166: InfoException infoException = new InfoException(
2167: LanguageTraslator.traslate("220"));
2168: ShowExceptionMessageDialog.initExceptionDialogMessage(
2169: LanguageTraslator.traslate("220"), infoException);
2170: }
2171: }
2172:
2173: private void setQueryDimensionLocationFrom(
2174: String[] rowDimensionNames, ReportQuery query, int type) {
2175: for (int i = 0; i < rowDimensionNames.length; i++) {
2176: try {
2177: query.setDimensionLocationOrder(rowDimensionNames[i],
2178: type);
2179: } catch (InfoException e) {
2180: e.printStackTrace();
2181: }
2182: }
2183: }
2184:
2185: private String[] getDimensionNames(Collection rowDimensions) {
2186: String[] names = new String[rowDimensions.size()];
2187: Iterator iterator = rowDimensions.iterator();
2188: for (int i = 0; iterator.hasNext(); i++) {
2189: ReportDimensionSpec spec = (ReportDimensionSpec) iterator
2190: .next();
2191: names[i] = spec.getName();
2192: }
2193: return names;
2194: }
2195:
2196: /**
2197: * Devuelve la tabla datajTable
2198: * @return
2199: */
2200: public JTable getDatajTable() {
2201: return datajTable;
2202: }
2203:
2204: /**
2205: * Devuelve la tabla rowHeaderjTable
2206: * @return
2207: */
2208: public JTable getRowHeaderjTable() {
2209: return rowHeaderjTable;
2210: }
2211:
2212: /**
2213: * Devuelve la tabla columnHeaderjTable
2214: * @return
2215: */
2216: public JTable getColumnHeaderjTable() {
2217: return columnHeaderjTable;
2218: }
2219:
2220: /**
2221: * Obtiene un objeto ReportResult
2222: * @return
2223: */
2224: public ReportResult getReportResult() {
2225: return reportResult;
2226: }
2227:
2228: /**
2229: * Sete un objeto Reportresult nuevo
2230: * @param reportResult
2231: */
2232: public void setReportResult(ReportResult reportResult)
2233: throws InfoException {
2234: this .reportResult = reportResult;
2235: JTable table = getDatajTable();
2236: if (table != null) {
2237: TableCellRenderer renderer = table
2238: .getDefaultRenderer(Object.class);
2239: if (renderer instanceof DataTableCellRenderer) {
2240: ((DataTableCellRenderer) renderer)
2241: .setReportResult(reportResult);
2242: }
2243: }
2244: if (tableProperties != null) {
2245: tableProperties.setReportResult(reportResult);
2246: }
2247: }
2248:
2249: /**
2250: * Retorna un Map con las ubicaciones de los paneles (ROW - COLUMN - PAGE) y su posicion
2251: * @return
2252: */
2253: public Map getChangeDimensionLocation() {
2254: return changeDimensionLocation;
2255: }
2256:
2257: /**
2258: * Retorna el componente ubicado en la izquierda al centro de la PivoteTable
2259: * @return
2260: */
2261: public Component getLeftCenterPanel() {
2262: return leftCenterPanel;
2263: }
2264:
2265: /**
2266: * Sete la vista vcon o sin totales y contruye una query nueva
2267: * @throws InfoException
2268: */
2269: public void setPivoteTableSinTotales() throws InfoException {
2270: if (getColModel().getWithTotals()
2271: && getRowModel().getWithTotals()) {
2272: withTotals = false;
2273: pivotTableFrame.setState(false);
2274: tableProperties.setWithTotal(withTotals);
2275: pivotTableFrame.buildNewQuery(tableProperties);
2276: fillContents(getReportResult());
2277: } else {
2278: withTotals = true;
2279: pivotTableFrame.setState(false);
2280: tableProperties.setWithTotal(withTotals);
2281: //fillContents(getReportResult());
2282: pivotTableFrame.buildNewQuery(tableProperties);
2283: fillContents(getReportResult());
2284: }
2285: invaildatePanels();
2286: if (getRowHeaderDimension().isEmpty()) {
2287: mainSplit.setDividerLocation(100);
2288: } else {
2289: int heigth = pivotTableFrame.getFrame().getContentPane()
2290: .getPreferredSize().height;
2291: leftCenterPanel.setPreferredSize(new Dimension(
2292: adjustmentSizeSplit(), heigth));
2293: }
2294:
2295: }
2296:
2297: /**
2298: * Retorna el modelo de la tabla ubicada en COLUMN
2299: * @return
2300: */
2301: public HeaderTableModel getColModel() {
2302: return (HeaderTableModel) getColumnHeaderjTable().getModel();
2303: }
2304:
2305: /**
2306: * Retorna el modelo de la tabla ubicada en ROW
2307: * @return
2308: */
2309: public HeaderTableModel getRowModel() {
2310: return (HeaderTableModel) getRowHeaderjTable().getModel();
2311: }
2312:
2313: /**
2314: * Retorna un objeto ColorConditionManager
2315: * @return
2316: */
2317: public ColorConditionManager getColorConditionManager() {
2318: return colorConditionManager;
2319: }
2320:
2321: /**
2322: * Retorna un map , donde se van a ubicar las ColumnProperties pertenecientes a ROW
2323: * @return
2324: */
2325: public Map getRowHeaderDimension() {
2326: if (rowHeaderDimension == null) {
2327: return rowHeaderDimension = new HashMap();
2328: }
2329: return rowHeaderDimension;
2330: }
2331:
2332: /**
2333: * Obtiene un objeto PivotTableProperties
2334: * @return
2335: */
2336: public PivotTableProperties getTableProperties() {
2337: return tableProperties;
2338: }
2339:
2340: /**
2341: * Setea una nueva PivotTableProperties
2342: * @param tableProperties
2343: */
2344: public void setTableProperties(PivotTableProperties tableProperties) {
2345: this .tableProperties = tableProperties;
2346: }
2347:
2348: /**
2349: * Retorna un objeto AplicationView
2350: * @return
2351: */
2352: public AplicationView getView() {
2353: return view;
2354: }
2355:
2356: /**
2357: * Obtiene un objeto PivoteTableFrame
2358: * @return
2359: */
2360:
2361: public PivotTableFrame getPivotTableFrame() {
2362: return pivotTableFrame;
2363: }
2364:
2365: /**
2366: * Sete si se quiere ver la vista con o sin totales
2367: * @param withTotals
2368: */
2369: public void setWithTotals(boolean withTotals) {
2370: this .withTotals = withTotals;
2371: }
2372:
2373: /**
2374: * Construye un vector con los nombres de la columnas
2375: * @param columnCount
2376: * @return
2377: */
2378: protected Vector getColumnsNames(int columnCount) {
2379: Vector names = new Vector(columnCount);
2380: for (int i = 0; i < columnCount; i++) {
2381: names.add(String.valueOf(i));
2382: }
2383: return names;
2384: }
2385:
2386: private boolean getIsReadOnly() {
2387: return (getPivotTableFrame().getMicroReport() != null);
2388: }
2389:
2390: }
|