KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2   Dejar un solo constructor de Column Properties , no esta actualizxada y por lo tanto falla los exclude value , aunque puede tener otras consecuencias
3 */

4
5 package com.calipso.reportgenerator.userinterface;
6
7 import com.calipso.reportgenerator.reportdefinitions.types.DimensionDefinitionLocationType;
8 import com.calipso.reportgenerator.reportdefinitions.types.DimensionDefinitionOrderType;
9 import com.calipso.reportgenerator.reportdefinitions.ReportView;
10 import com.calipso.reportgenerator.userinterface.DimensionValuesSearcherUI;
11 import com.calipso.reportgenerator.common.*;
12 import javax.swing.*;
13 import javax.swing.table.DefaultTableModel JavaDoc;
14 import java.awt.*;
15 import java.awt.event.*;
16 import java.util.*;
17 import java.util.List JavaDoc;
18 import java.io.IOException JavaDoc;
19 import javax.swing.table.*;
20 import com.calipso.reportgenerator.common.InfoException;
21
22 /**
23  * Esta clase define el componente a visualizar
24  *
25  */

26 public class PivotTable extends JComponent implements FieldPositionListener {
27
28   private Container contentPane;
29   private JPanel pageFields;
30   private JPanel pageFillerRigth;
31   private JScrollPane pageFieldsScrollPane;
32   private JScrollPane centerJScrollPane;
33   private JScrollPane leftCenterScrollPane;
34   private JScrollPane colTableJScroll;
35   private JScrollBar pageFieldScrollBar;
36   private JSplitPane mainSplit;
37   private JPanel mainSplitPanel;
38   private JPanel leftCenterPanel;
39   private JPanel rigthCenterPanel;
40   private JPanel leftSplitNorthPanel;
41   private JPanel centerSplitNorthPanel;
42   private JPanel southRowFieldDropTarget;
43   private JPanel columnPanel;
44   private JPanel southFiller;
45   private JPanel eastFiller;
46   private JPanel columnHeaderPanel;
47   private JPanel northPanel;
48   private JTable datajTable;
49   private JTable rowHeaderjTable;
50   private JTable columnHeaderjTable;
51   private JPanel pageConteinerComponent;
52   private JFrame frame;
53   private JButton maximizar;
54   private JScrollBar horizontal;
55   private JScrollBar vertical;
56   private ReportResult reportResult;
57   private PivotTableFrame pivotTableFrame;
58   private Map changeDimensionLocation;
59   private boolean withTotals;
60   private int page;
61   private int row;
62   private int col;
63   private Map dragPanels;
64   private Map targetPanels;
65   private ColorConditionManager colorConditionManager;
66   private int width;
67   private Map metricStates;
68   private Map rowHeaderDimension;
69   private PivotTableProperties tableProperties;
70   private AplicationView view;
71   private JPanel metrics;
72   private JPopupMenu popupMenu;
73   private final int DEFAULT_COLUMN_WIDTH = 75;
74   private ReportView reportView;
75
76
77   /**
78    * Inicializa un objeto PivoteTable
79    * @param pivotTableFrame
80    */

81   public PivotTable(PivotTableFrame pivotTableFrame, ReportView reportView) throws InfoException {
82     col = 0;
83     row = 0;
84     page = 0;
85     width = 0;
86     this.reportView = reportView;
87     this.pivotTableFrame = pivotTableFrame;
88     this.maximizar = pivotTableFrame.getMaximizar();
89     this.colorConditionManager = new ColorConditionManager();
90     if (this.reportView== null){
91       tableProperties = new PivotTableProperties();
92       tableProperties.setConditionManager(this.colorConditionManager);
93       tableProperties.setWithTotal(true);
94       setReportResult(pivotTableFrame.getReportResult());
95       initTableProperties();
96       withTotals = true;
97     }else {
98       tableProperties = new PivotTableProperties();
99       tableProperties.setConditionManager(this.colorConditionManager);
100       tableProperties.setWithTotal(reportView.getVisibleTotals());
101       withTotals = reportView.getVisibleTotals();
102       setReportResult(pivotTableFrame.getReportResult());
103       initTableProperties();
104       tableProperties.assignFromView(reportView);
105     }
106     this.changeDimensionLocation = new Hashtable();
107     setContentPane(pivotTableFrame.getPivotPanel());
108     setFrame(pivotTableFrame.getFrame());
109     initComponents();
110     setColorConditionManager(this.colorConditionManager);
111     setComponentSize();
112     setRowSize();
113     setDefaultSize();
114     if (getRowHeaderDimension().isEmpty()) {
115       mainSplit.setDividerLocation(100);
116     }
117     else{
118       mainSplit.setDividerLocation(adjustmentSizeSplit());
119     }
120   }
121
122   /**
123    * Iniocializa el objeto PivotTablePropertie
124    //* @throws InfoException
125    */

126
127   private void initTableProperties() throws InfoException {
128     try {
129       ArrayList rowList = (ArrayList) reportResult.getReportQuery().getDimensionsByLocation(DimensionDefinitionLocationType.ROW);
130       fillColumnsProperties(rowList, DimensionDefinitionLocationType.ROW.toString());
131
132       ArrayList pageList = (ArrayList) reportResult.getReportQuery().getDimensionsByLocation(DimensionDefinitionLocationType.PAGE);
133       fillColumnsProperties(pageList, DimensionDefinitionLocationType.PAGE.toString());
134
135       ArrayList columnList = (ArrayList) reportResult.getReportQuery().getDimensionsByLocation(DimensionDefinitionLocationType.COLUMN);
136       fillColumnsProperties(columnList, DimensionDefinitionLocationType.COLUMN.toString());
137     }
138     catch (Exception JavaDoc e) {
139       throw new InfoException(LanguageTraslator.traslate("227"));
140
141     }
142     getMetricStates();
143
144   }
145
146
147   /**
148    * Sete el ancho por default de cada columnPrropertie
149    */

150   private void setDefaultSize() {
151
152     for (int index = 0; index < tableProperties.getColumnProperties().size(); index++) {
153       ColumnProperties properties = (ColumnProperties) tableProperties.getColumnProperties().get(index);
154       if (properties.getLocation().compareToIgnoreCase("PAGE") == 0) {
155         properties.setWidth(DEFAULT_COLUMN_WIDTH);
156       }
157       else {
158         if (properties.getLocation().compareToIgnoreCase("COLUMN") == 0) {
159           properties.setWidth(DEFAULT_COLUMN_WIDTH);
160         }
161       }
162     }
163   }
164
165   /**
166    * Sete las propiedades por default de cada ColumnPropertie de la vista
167    */

168   private void setRowSize() {
169     Map map = getRowHeaderDimension();
170     Iterator iterator = map.values().iterator();
171     int index = 0;
172     while (iterator.hasNext()) {
173       ColumnProperties properties = (ColumnProperties) iterator.next();
174       JPanel panel = (JPanel) dragPanels.get(properties.getColumnName());
175       panel.getPreferredSize().width = DEFAULT_COLUMN_WIDTH;
176       panel.setMinimumSize(panel.getPreferredSize());
177       panel.setMaximumSize(panel.getPreferredSize());
178       tableProperties.getColumnProperties().remove(properties);
179       properties.setWidth(DEFAULT_COLUMN_WIDTH);
180       rowHeaderjTable.getColumnModel().getColumn(index).setPreferredWidth(DEFAULT_COLUMN_WIDTH);
181       tableProperties.getColumnProperties().add(properties);
182       index++;
183     }
184     rowHeaderDimension = map;
185     mainSplit.setDividerLocation(DEFAULT_COLUMN_WIDTH * index);
186     mainSplit.setMinimumSize(new Dimension(100, 0));
187     mainSplit.invalidate();
188     invaildatePanels();
189   }
190
191   /**
192    * Retona un map , con todas las columnProperties ubicadas en ROW
193    * @return
194    */

195   private Map getAllRowColumnProperties() {
196     Map map = new HashMap();
197     for (int index = 0; index < tableProperties.getColumnProperties().size(); index++) {
198       ColumnProperties properties = (ColumnProperties) tableProperties.getColumnProperties().get(index);
199       if (properties.getLocation().compareToIgnoreCase("ROW") == 0) {
200         Object JavaDoc[] objects = (Object JavaDoc[]) changeDimensionLocation.get(properties.getColumnName());
201         if (objects != null) {
202           properties.setUbication(((Integer JavaDoc) objects[1]).intValue());
203         }
204         map.put(properties.getColumnName(), properties);
205       }
206     }
207     return map;
208   }
209
210   /**
211    * Seta el objeto ColorConditionManager
212    * @param colorConditionManager
213    */

214   private void setColorConditionManager(ColorConditionManager colorConditionManager) {
215     this.colorConditionManager = colorConditionManager;
216     tableProperties.setConditionManager(colorConditionManager);
217     ((DataTableCellRenderer) getDatajTable().getDefaultRenderer(Object JavaDoc.class)).setColorConditionManager(colorConditionManager);
218   }
219
220   /**
221    * Metodo de creacion de los componente de la PivoteTable
222    */

223   private void initComponents() throws InfoException {
224     dragPanels = new Hashtable();
225     targetPanels = new Hashtable();
226     popupMenu = new JPopupMenu();
227     fillParamValuePopupMenu();
228     getContentPane().add(createPageFieldComponents(), BorderLayout.NORTH);
229     getContentPane().add(createMainSplitPanel(), BorderLayout.CENTER);
230     getContentPane().add(createMetricsPanel(), BorderLayout.SOUTH);
231     fillContents(getReportResult());
232     createEvent();
233   }
234
235   /**
236    * Crea el panel donde se colocan los checkBox de metrica
237    * @return
238    */

239   private Component createMetricsPanel() {
240     metrics = new JPanel();
241     metrics.setLayout(new javax.swing.BoxLayout JavaDoc(metrics, javax.swing.BoxLayout.X_AXIS));
242     List JavaDoc list = getReportResult().getReportQuery().getMetrics();
243     for (int index = 0; index < list.size(); index++) {
244       QueryMetric metric = (QueryMetric) list.get(index);
245       if(metric.getVisible()) {
246         final JCheckBox checkBox = new JCheckBox(getReportResult().getMetricFromName(metric.getName()).getCaption(), true);
247         checkBox.setName(metric.getName());
248         metrics.add(checkBox);
249         checkBox.addActionListener(new ActionListener() {
250           public void actionPerformed(ActionEvent e) {
251             try {
252               setMetricsProperties(checkBox);
253             }
254             catch (InfoException e1) {
255               ShowExceptionMessageDialog.initExceptionDialogMessage(LanguageTraslator.traslate("137"), e1);
256             }
257           }
258         });
259       } else {
260         final JCheckBox checkBox = new JCheckBox(getReportResult().getMetricFromName(metric.getName()).getCaption(), false);
261         checkBox.setName(metric.getName());
262         metrics.add(checkBox);
263         checkBox.addActionListener(new ActionListener() {
264           public void actionPerformed(ActionEvent e) {
265             try {
266               setMetricsProperties(checkBox);
267             }
268             catch (InfoException e1) {
269               ShowExceptionMessageDialog.initExceptionDialogMessage(LanguageTraslator.traslate("137"), e1);
270             }
271           }
272         });
273       }
274     }
275     JScrollPane pane = new JScrollPane(metrics);
276     pane.setSize(new Dimension(getPreferredSize().width, 50));
277     pane.setPreferredSize(new Dimension(getPreferredSize().width, 50));
278     pane.setMaximumSize(new Dimension(getPreferredSize().width, 50));
279     pane.setMinimumSize(new Dimension(getPreferredSize().width, 50));
280     return pane;
281   }
282
283   /**
284    * Setea las propiedades de las distintas metricas
285    * @param checkBox
286
287    */

288   private void setMetricsProperties(JCheckBox checkBox) throws InfoException {
289     String JavaDoc name = checkBox.getName();
290     ((MetricState) getMetricStates().get(name)).setVisible(checkBox.isSelected());
291     {
292       pivotTableFrame.updateQuerry((MetricState) metricStates.get(checkBox.getName()), checkBox, tableProperties);
293       if (!tableProperties.getMetricProperies().contains(getMetricStates().get(name))) {
294         tableProperties.getMetricProperies().add(getMetricStates().get(name));
295       }
296       else {
297         tableProperties.getMetricProperies().remove(getMetricStates().get(name));
298         tableProperties.getMetricProperies().add(getMetricStates().get(name));
299       }
300       fillContents(reportResult);
301       resizeComponent();
302
303
304     }
305   }
306
307   /**
308    * Actualiza el estado de los checkBox correspondiente a las metricas
309    //* @throws InfoException
310    */

311   public void updateMetricCheckBoxes() throws InfoException {
312     String JavaDoc name;
313     for (int i = 0; i < metrics.getComponentCount(); i++) {
314       JCheckBox jCheckBox = (JCheckBox) metrics.getComponents()[i];
315       name = jCheckBox.getName();
316       jCheckBox.setSelected(reportResult.getReportQuery().getQueryMetricFromName(name).getVisible());
317     }
318   }
319
320   /**
321    * Retorna un map con los estados de las metricas
322    * @return
323    */

324   public Map getMetricStates() throws InfoException{
325     if (metricStates == null) {
326       metricStates = new HashMap();
327       loadAllMetrics(metricStates);
328     }
329     return metricStates;
330   }
331
332   /**
333    * Metodo de publicacion de eventos de PivoteTable
334    *
335    */

336   private void createEvent() {
337
338     pageFieldScrollBar.addAdjustmentListener(new java.awt.event.AdjustmentListener JavaDoc() {
339       public void adjustmentValueChanged(java.awt.event.AdjustmentEvent JavaDoc evt) {
340         pageFieldScrollBarAdjustmentValueChanged(evt);
341       }
342     });
343     rowHeaderjTable.addComponentListener(new java.awt.event.ComponentAdapter JavaDoc() {
344       public void componentResized(java.awt.event.ComponentEvent JavaDoc evt) {
345         try {
346           rowHeaderjTableComponentResized();
347         }
348         catch (InfoException e) {
349           ShowExceptionMessageDialog.initExceptionDialogMessage(LanguageTraslator.traslate("214"), e);
350         }
351       }
352     });
353     /*maximizar.addActionListener(new java.awt.event.ActionListener() {
354       public void actionPerformed(java.awt.event.ActionEvent evt) {
355         maximizarActionPerformed();
356       }
357     });*/

358     horizontal.addAdjustmentListener(new java.awt.event.AdjustmentListener JavaDoc() {
359       public void adjustmentValueChanged(java.awt.event.AdjustmentEvent JavaDoc evt) {
360         horizontalScrollBarAdjustmentValue(evt);
361       }
362     });
363     vertical.addAdjustmentListener(new java.awt.event.AdjustmentListener JavaDoc() {
364       public void adjustmentValueChanged(java.awt.event.AdjustmentEvent JavaDoc evt) {
365         verticalScrollBarAdjustmentValue(evt);
366       }
367     });
368     rowHeaderjTable.getTableHeader().addMouseListener(new java.awt.event.MouseAdapter JavaDoc() {
369       public void mouseReleased(java.awt.event.MouseEvent JavaDoc evt) {
370         rowTableHeaderMouseReleased(evt);
371       }
372     });
373     datajTable.getTableHeader().addMouseListener(new java.awt.event.MouseAdapter JavaDoc() {
374       public void mouseReleased(java.awt.event.MouseEvent JavaDoc evt) {
375         dataTableHeaderMouseReleased();
376       }
377     });
378
379     /*pivotTableFrame.getColorIndicator().addActionListener(new java.awt.event.ActionListener() {
380       public void actionPerformed(java.awt.event.ActionEvent evt) {
381         executeSemafore();
382       }
383     });*/

384
385     /*pivotTableFrame.getExcel().addActionListener(new java.awt.event.ActionListener() {
386       public void actionPerformed(java.awt.event.ActionEvent evt) {
387         executeExcelFormatSerializer();
388       }
389     });
390
391     pivotTableFrame.getSearcher().addActionListener(new java.awt.event.ActionListener() {
392       public void actionPerformed(java.awt.event.ActionEvent evt) {
393         executeSearcher();
394       }
395     });
396
397     pivotTableFrame.getViewBtn().addActionListener(new ActionListener() {
398       public void actionPerformed(ActionEvent e) {
399         executeViewBtn();
400       }
401     }); */

402     datajTable.addMouseListener(new MouseAdapter() {
403       public void mouseClicked(MouseEvent e) {
404         fillParamValuePopupMenu(e);
405       }
406     });
407     /*pivotTableFrame.getEditDimensionValueBtn().addActionListener(new ActionListener() {
408       public void actionPerformed(ActionEvent e) {
409         try {
410           executeEditDimensionValues();
411         }
412         catch (InfoException e1) {
413           ShowExceptionMessageDialog.initExceptionDialogMessage(LanguageTraslator.traslate("214"), e1);
414         }
415       }
416     });*/

417     /*pivotTableFrame.getOrdenBtn().addActionListener(new ActionListener() {
418       public void actionPerformed(ActionEvent e) {
419         try {
420           executeEditOrdenValues();
421         }
422         catch (InfoException e1) {
423           ShowExceptionMessageDialog.initExceptionDialogMessage(LanguageTraslator.traslate("214"), e1);
424         }
425       }
426     });*/

427   }
428
429   public void executeViewBtn() {
430     try {
431       fillComponents();
432       executeAplicationView();
433     }
434     catch (InfoException e1) {
435       ShowExceptionMessageDialog.initExceptionDialogMessage(LanguageTraslator.traslate("214"), e1);
436
437     }
438   }
439
440   /**
441    * Ejecuta el orden de dimensiones
442    * @throws InfoException
443    */

444   public void executeEditOrdenValues() throws InfoException {
445     Map dimensionOrders = new HashMap();
446     Map dimensionCaptions = new HashMap();
447     Iterator iterator;
448     iterator = tableProperties.getColumnProperties().iterator();
449     while (iterator.hasNext()) {
450       ColumnProperties properties = (ColumnProperties) iterator.next();
451       String JavaDoc columnName = properties.getColumnName();
452       dimensionOrders.put(columnName, new Boolean JavaDoc(properties.getOrder().getType() == DimensionDefinitionOrderType.A_TYPE));
453       dimensionCaptions.put(columnName, reportResult.getDimensionFromName(columnName).getCaption());
454     }
455     if (DimensionOrderEditor.editDimensionOrder(getFrame(), dimensionOrders, dimensionCaptions, pivotTableFrame.getReportGeneratorConfiguration())) {
456       iterator = tableProperties.getColumnProperties().iterator();
457       while (iterator.hasNext()) {
458         ColumnProperties properties = (ColumnProperties) iterator.next();
459         String JavaDoc columnName = properties.getColumnName();
460         if (((Boolean JavaDoc) dimensionOrders.get(columnName)).booleanValue()) {
461           properties.setOrder(DimensionDefinitionOrderType.A);
462         }
463         else {
464           properties.setOrder(DimensionDefinitionOrderType.D);
465         }
466       }
467       getPivotTableFrame().buildNewQuery(tableProperties);
468       fillContents(getReportResult());
469     }
470   }
471
472   /**
473    * Ejecuta el editor de Ranking de metrica
474    * @throws InfoException
475    */

476   public void executeEditDimensionValues() throws InfoException {
477     Map dimensionRankMetrics = new HashMap();
478     Map fieldCaptions = new HashMap();
479     List JavaDoc metricNames = new ArrayList();
480     Iterator iterator;
481     iterator = tableProperties.getColumnProperties().iterator();
482     while (iterator.hasNext()) {
483       ColumnProperties properties = (ColumnProperties) iterator.next();
484       String JavaDoc columnName = properties.getColumnName();
485       String JavaDoc rankMetricName = properties.getRankMetricName();
486       dimensionRankMetrics.put(columnName, rankMetricName);
487       fieldCaptions.put(columnName, reportResult.getDimensionFromName(columnName).getCaption());
488     }
489
490     iterator = tableProperties.getMetricProperies().iterator();
491     while (iterator.hasNext()) {
492       MetricState metricState = (MetricState) iterator.next();
493       String JavaDoc name = metricState.getName();
494       metricNames.add(name);
495       fieldCaptions.put(name, metricState.getCaption());
496     }
497
498     if (RankMetricEditor.editRankMetrics(getFrame(), dimensionRankMetrics, metricNames, fieldCaptions, pivotTableFrame.getReportGeneratorConfiguration())) {
499       iterator = tableProperties.getColumnProperties().iterator();
500       while (iterator.hasNext()) {
501         ColumnProperties properties = (ColumnProperties) iterator.next();
502         String JavaDoc columnName = properties.getColumnName();
503         properties.setRankMetricName((String JavaDoc) dimensionRankMetrics.get(columnName));
504       }
505       pivotTableFrame.buildNewQuery(tableProperties);
506       fillContents(getReportResult());
507     }
508   }
509
510
511   /**
512    * Carga los paramValues
513    */

514   private void fillParamValuePopupMenu() {
515     DrillDownSpec drillDownSpec = null;
516     Iterator iterator = reportResult.getReportSpec().getDrillDownSpecs().iterator();
517     while (iterator.hasNext()) {
518       drillDownSpec = (DrillDownSpec) iterator.next();
519       JMenuItem item = new JMenuItem(drillDownSpec.getDescription());
520       popupMenu.add(item);
521       final DrillDownSpec drillDownSpec1 = drillDownSpec;
522       item.addActionListener(new ActionListener() {
523         public void actionPerformed(ActionEvent e) {
524           try {
525             pivotTableFrame.drillDown(drillDownSpec1, getMapDrillDown());
526           }
527           catch (InfoException e1) {
528             ShowExceptionMessageDialog.initExceptionDialogMessage(LanguageTraslator.traslate("151"), e1);
529           }
530         }
531       });
532     }
533   }
534
535   /**
536    * Ejecuta el pupupMenu con los ParamValue cargados
537    * @param e
538    */

539   private void fillParamValuePopupMenu(MouseEvent e) {
540     if (e.getButton() == 3) {
541       popupMenu.show(datajTable, e.getPoint().x, e.getPoint().y);
542     }
543   }
544
545   /**
546    * Retorna un map con los valores correspondientes a las celdas seleccionadas
547    * @return
548    */

549   private Map getMapDrillDown() {
550     Map values = new Hashtable();
551     String JavaDoc dimensionName, value;
552     Object JavaDoc[] rowsDesc = getRowModel().getValueFrom(getDatajTable().getSelectedRow());
553     for (int j = 0; j < getReportResult().getReportQuery().getRowDimensions().size(); j++) {
554       dimensionName = ((QueryDimension) getReportResult().getReportQuery().getRowDimensions().get(j)).getName();
555       if (rowsDesc[j] != null) {
556         value = rowsDesc[j].toString();
557         values.put(dimensionName, value);
558       }
559     }
560
561     Object JavaDoc[] columnDesc = getColModel().getValueFrom(getDatajTable().getSelectedColumn());
562     for (int j = 0; j < getReportResult().getReportQuery().getColumnDimensions().size(); j++) {
563       dimensionName = ((QueryDimension) getReportResult().getReportQuery().getColumnDimensions().get(j)).getName();
564       if (columnDesc[j] != null) {
565         value = columnDesc[j].toString();
566         values.put(dimensionName, value);
567       }
568     }
569     return values;
570   }
571
572   /**
573    * Ejecuta aplicationView , (aplicationView carga vistas previamnete guardadas)
574    //* @throws InfoException
575    */

576   public void executeAplicationView() throws InfoException {
577     view = new AplicationView(new JFrame(), true, this, getPivotTableFrame().getMicroReport());
578     view.setVisible(true);
579     view.addWindowListener(new WindowAdapter() {
580       public void windowClosed(WindowEvent e) {
581         try {
582           updateFromView();
583         }
584         catch (InfoException ex) {
585           ShowExceptionMessageDialog.initExceptionDialogMessage(LanguageTraslator.traslate("214"), ex);
586         }
587
588       }
589     });
590   }
591
592   /**Actualiza el cubo al aplicar una vista
593    *
594    */

595   private void updateFromView() throws InfoException {
596     fillContents(reportResult);
597     setColorConditionManager(tableProperties.getConditionManager());
598     DefaultTableModel JavaDoc tableDataModel = (DefaultTableModel JavaDoc) getDatajTable().getModel();
599     tableDataModel.fireTableChanged(null);
600     dataTableHeaderMouseReleased();
601     maximizarActionPerformed();
602     rowHeaderjTable.revalidate();
603     invaildatePanels();
604     updateMetricCheckBoxes();
605   }
606
607   public void applyView(String JavaDoc reportViewId) {
608     PivotTableProperties pivoteTableProperties = getTableProperties();
609     pivoteTableProperties.setConditionManager(getColorConditionManager());
610     try {
611       reportView = getPivotTableFrame().getReportManager().getReportViewFromID(reportViewId,reportResult.getReportSpec().getDefinitionId(),getPivotTableFrame().getUserID());
612       pivoteTableProperties.assignFromView(reportView);
613       getPivotTableFrame().buildNewQuery(pivoteTableProperties);
614       updateFromView();
615     } catch (InfoException e) {
616       ShowExceptionMessageDialog.initExceptionDialogMessage(LanguageTraslator.traslate("368"), e);
617     }
618   }
619   /**
620    * Actualiza la pivoteTableProperties
621    */

622   private void updateTableProperties(String JavaDoc positionName, String JavaDoc fieldName) {
623     Iterator iterator = tableProperties.getColumnProperties().iterator();
624     while (iterator.hasNext()) {
625       ColumnProperties properties = (ColumnProperties) iterator.next();
626       if (properties.getColumnName().compareToIgnoreCase(fieldName) == 0) {
627         properties.setLocation(positionName);
628       }
629     }
630     rowHeaderDimension = getAllRowColumnProperties();
631     updateTablePropertiesUbications();
632
633   }
634
635   /**
636    * Actualiza la pivoteTableProperties
637    */

638   private void updateTablePropertiesUbications() {
639     for (int i = 0; i < tableProperties.getColumnProperties().size(); i++) {
640       ColumnProperties properties = (ColumnProperties) tableProperties.getColumnProperties().get(i);
641       Object JavaDoc[] object = (Object JavaDoc[]) changeDimensionLocation.get(properties.getColumnName());
642       properties.setUbication(((Integer JavaDoc) object[1]).intValue());
643     }
644     rowHeaderDimension = getAllRowColumnProperties();
645   }
646
647   public void executeSearcher() {
648     if(getDatajTable().getSelectedColumns().length == 1 && getDatajTable().getSelectedRows().length == 1) {
649       JFrame subFrame = new JFrame();
650       DimensionValuesSearcherUI searcherUI = new DimensionValuesSearcherUI(subFrame, true, reportResult, this, pivotTableFrame.getReportGeneratorConfiguration());
651       searcherUI.setVisible(true);
652       validate();
653     } else {
654       JOptionPane.showMessageDialog(this, LanguageTraslator.traslate("283"));
655     }
656   }
657
658   public void executeExcelFormatSerializer() throws IOException JavaDoc {
659     ExcelFormatSerializer serializer = new ExcelFormatSerializer(this);
660     JFileChooser fileChooser = new JFileChooser();
661     int returnVal = fileChooser.showSaveDialog(this);
662     if(returnVal == JFileChooser.APPROVE_OPTION) {
663       String JavaDoc path = fileChooser.getSelectedFile().getPath();
664       serializer.serializeTo(path);
665     }
666   }
667
668   /**
669    * Ejecuta el semaforo
670    */

671   public void executeSemafore() {
672     ColorConditionUI sem = null;
673     ColorConditionManager clon = null;
674     try {
675
676       clon = (ColorConditionManager) colorConditionManager.clone();
677       JFrame frame = new JFrame();
678       sem = new ColorConditionUI(frame, true, clon, getMetricStates(), pivotTableFrame.getReportGeneratorConfiguration());
679     }
680     catch (Exception JavaDoc e) {
681       InfoException infoException = new InfoException(LanguageTraslator.traslate("219"));
682       ShowExceptionMessageDialog.initExceptionDialogMessage(LanguageTraslator.traslate("219"), infoException);
683     }
684     sem.setVisible(true);
685     setColorConditionManager(clon);
686     DefaultTableModel JavaDoc tableDataModel = (DefaultTableModel JavaDoc) getDatajTable().getModel();
687     tableDataModel.fireTableChanged(null);
688   }
689
690
691   /**
692    * Carga el valor de todas las metricas y setea pivotTableProperties
693    * @param states
694    */

695   private void loadAllMetrics(Map states) throws InfoException{
696     java.util.List JavaDoc list = reportResult.getReportQuery().getMetrics();
697     for (int index = 0; index < list.size(); index++) {
698       QueryMetric queryMetric = (QueryMetric) list.get(index);
699       ReportMetricSpec metricSpec = reportResult.getMetricFromName(queryMetric.getName());
700       if(metricSpec!=null){
701         MetricState metricState = new MetricState(metricSpec);
702         metricState.setVisible(queryMetric.getVisible());
703         states.put(metricSpec.getName(), metricState);
704         tableProperties.setVisibleMetrics(metricState);
705       }else{
706         throw new InfoException(LanguageTraslator.traslate("377") + " " + queryMetric.getName());
707       }
708     }
709   }
710
711   /**
712    *Sincroniza el size de las columnas de rowHeaderjTable con las columnas de datajTable
713    *
714    */

715   private void dataTableHeaderMouseReleased() {
716     String JavaDoc width = null;
717     if (pivotTableFrame.isSelected()) {
718       if (rowHeaderjTable.getTableHeader().isVisible()) {
719         for (int index = 0; index < datajTable.getTableHeader().getColumnModel().getColumnCount(); index++) {
720           width = Integer.toString(datajTable.getColumnModel().getColumn(index).getPreferredWidth());
721           datajTable.getTableHeader().getColumnModel().getColumn(index).
722               setHeaderValue(new Integer JavaDoc(index));
723           columnHeaderjTable.getTableHeader().getColumnModel().getColumn(index).setPreferredWidth(Integer.parseInt(width));
724           columnHeaderjTable.getTableHeader().getColumnModel().getColumn(index).setMinWidth(30);
725           datajTable.getTableHeader().getColumnModel().getColumn(index).setMinWidth(30);
726         }
727         datajTable.getTableHeader().setPreferredSize(new Dimension(0, 16));
728         datajTable.getTableHeader().revalidate();
729       }
730       else {
731         pivotTableFrame.setState(false);
732         datajTable.getTableHeader().setPreferredSize(new Dimension(0, 16));
733       }
734     }
735   }
736
737   /**
738    * Ajusta el tamao de las columnas de la tabla rowHeaderjTable con respecto a los componentes que se encuentran
739    * en targetP anels
740    * @param evt
741    */

742   private void rowTableHeaderMouseReleased(MouseEvent evt) {
743     int width = 0;
744     int heigth = 0;
745     int col = 0;
746     if (rowHeaderjTable.getTableHeader().isVisible()) {
747       col = rowHeaderjTable.columnAtPoint(evt.getPoint());
748       if (col < 0)
749         col = 0;
750       width = rowHeaderjTable.getTableHeader().getColumnModel().getColumn(col).getWidth();
751       for (Iterator iterator = targetPanels.values().iterator(); iterator.hasNext();) {
752         JPanel panel1 = (JPanel) iterator.next();
753         panel1.setMinimumSize(new Dimension(30, (int) panel1.getPreferredSize().getHeight()));
754         if (panel1.getName() == DimensionDefinitionLocationType.ROW.toString() && panel1.getComponentCount() > 0) {
755           DragSourcePanel drag = (DragSourcePanel) panel1.getComponent(col);
756           drag.setMinimumSize(new Dimension(30, (int) drag.getPreferredSize().getHeight()));
757           drag.setPreferredSize(new Dimension(width, (int) drag.getPreferredSize().getHeight()));
758           panel1.setPreferredSize(new Dimension(width, (int) panel1.getPreferredSize().getHeight()));
759           heigth = (int) panel1.getPreferredSize().getHeight();
760           panel1.setPreferredSize(new Dimension(width, heigth));
761           rowHeaderjTable.getTableHeader().getColumnModel().getColumn(col).setMinWidth(30);
762           rowHeaderjTable.revalidate();
763         }
764       }
765       Rectangle rec = rowHeaderjTable.getCellRect(0, rowHeaderjTable.getColumnCount(), true);
766       mainSplit.setDividerLocation(rec.x);
767     }
768   }
769
770   /**
771    * Sincroniza el Scroll horizontal con el JScrollPane(colTableJScroll) y JScrollPane(centerJScrollPane)
772    *
773    * @param evt
774    */

775   private void horizontalScrollBarAdjustmentValue(AdjustmentEvent evt) {
776     int widrh = datajTable.getPreferredScrollableViewportSize().width;
777     float porc = (widrh * 10) / 100;
778     horizontal.setUnitIncrement((int) porc);
779     colTableJScroll.getHorizontalScrollBar().setValue(evt.getAdjustable().getValue());
780     centerJScrollPane.getHorizontalScrollBar().setValue(evt.getAdjustable().getValue());
781   }
782
783   /**
784    * Sincroniza los JScrollPane leftCenterScrollPane y centerJScrollPane con el SCrollBar vertical
785    * @param evt
786    */

787   private void verticalScrollBarAdjustmentValue(AdjustmentEvent evt) {
788     leftCenterScrollPane.getVerticalScrollBar().setValue(evt.getAdjustable().getValue());
789     centerJScrollPane.getVerticalScrollBar().setValue(evt.getAdjustable().getValue());
790   }
791
792
793   /**
794    * Metodo utilizado para mostrar los header de las tablas rowHeaderjTable y datajTable para poder realizar los
795    * resize de las columnas
796    */

797   public void maximizarActionPerformed() {
798     if (pivotTableFrame.isSelected()) {
799       for (int index = 0; index < rowHeaderjTable.getTableHeader().getColumnModel().getColumnCount(); index++) {
800         rowHeaderjTable.getTableHeader().getColumnModel().getColumn(index).
801             setHeaderValue(Integer.toString(index));
802         rowHeaderjTable.getTableHeader().getColumnModel().getColumn(index).setMinWidth(20);
803       }
804       for (int index = 0; index < datajTable.getTableHeader().getColumnModel().getColumnCount(); index++) {
805         datajTable.getTableHeader().getColumnModel().getColumn(index).
806             setHeaderValue(Integer.toString(index));
807       }
808       rowHeaderjTable.getTableHeader().setPreferredSize(new Dimension(0, 18));
809       datajTable.getTableHeader().setPreferredSize(new Dimension(0, 16));
810       rowHeaderjTable.getTableHeader().setReorderingAllowed(false);
811       datajTable.getTableHeader().setReorderingAllowed(false);
812
813     }
814     else {
815       rowHeaderjTable.getTableHeader().setPreferredSize(new Dimension(0, 0));
816       datajTable.getTableHeader().setPreferredSize(new Dimension(0, 0));
817     }
818     rowHeaderjTable.getTableHeader().getColumnModel().setColumnMargin(0);
819     rowHeaderjTable.getTableHeader().updateUI();
820     datajTable.getTableHeader().getColumnModel().setColumnMargin(0);
821     datajTable.getTableHeader().updateUI();
822   }
823
824   /**
825    * Realiza el update de la tabla rowHeaderjTable , ajustando el ancho de las columnas contra los paneles
826    * que actuan con propiedades de Drag & Drop
827    */

828   private void rowHeaderjTableComponentResized() throws InfoException {
829     setRowDimensionMap();
830     setSize();
831     invaildatePanels();
832   }
833
834   /**
835    * realiza el desplazamiento del JScrollPane pageFieldsScrollPane
836    * @param evt
837    */

838   private void pageFieldScrollBarAdjustmentValueChanged(AdjustmentEvent evt) {
839     int value = evt.getValue();
840     pageFieldsScrollPane.getHorizontalScrollBar().setValue(value);
841   }
842
843   /**
844    * Setea el size del componente izquierdo del split leftSplitNorthPanel
845    */

846   private void setComponentSize() {
847     Dimension dim = leftSplitNorthPanel.getPreferredSize();
848     dim.width = columnPanel.getPreferredSize().width;
849     dim.height += columnPanel.getPreferredSize().height - 5;
850     leftSplitNorthPanel.setPreferredSize(dim);
851   }
852
853   /**
854    * Sincroniza el alto de la tabla columnHeaderjTable con el alto del panel ubicado al norte en el lado izquirdo del split
855    */

856   private void resizeComponent() {
857     Dimension dimension = northPanel.getPreferredSize();
858     leftSplitNorthPanel.setPreferredSize(dimension);
859     leftSplitNorthPanel.revalidate();
860   }
861
862   /**
863    * Sincroniza a los paneles de southRowFieldDropTarget con el ancho de las columnas de rowHeaderjTable
864    */

865
866   private void setSize() {
867     int width = 0;
868     int index = 0;
869     rowHeaderjTable.validate();
870     Iterator iterator = getAllRowColumnProperties().values().iterator();
871     while (iterator.hasNext()) {
872       ColumnProperties properties = (ColumnProperties) iterator.next();
873       JPanel panel = (JPanel) dragPanels.get(properties.getColumnName());
874       width = properties.getWidth();
875       if (index == 0) {
876         width++;
877       }
878       panel.setPreferredSize(new Dimension(width, (int) panel.getPreferredSize().getHeight()));
879       ((JPanel) panel.getParent()).revalidate();
880       panel.revalidate();
881       rowHeaderjTable.invalidate();
882       ((HeaderTableUI)rowHeaderjTable.getUI()).resetFinals();
883       index++;
884     }
885   }
886
887   /**
888    * crea y setea el Split mainSplit , con las dos subSecciones izquierda y derecha
889    * @return
890    */

891   private Component createMainSplitPanel() {
892     mainSplitPanel = new JPanel();
893     mainSplit = new JSplitPane();
894     mainSplit.setLeftComponent(createLeftCenterPanel());
895     mainSplit.setRightComponent(createRigthCenterPanel());
896     mainSplitPanel.setLayout(new BorderLayout());
897     mainSplitPanel.add(mainSplit, BorderLayout.CENTER);
898     mainSplit.setDividerSize(3);
899     return mainSplitPanel;
900   }
901
902   /**
903    * Genera y setea el lado izquierdo del Split mainSplait
904    * @return el panel rigthCenterPanel
905    */

906   private Component createRigthCenterPanel() {
907     rigthCenterPanel = new JPanel();
908     rigthCenterPanel.setLayout(new BorderLayout());
909     rigthCenterPanel.add(createNorthPanel(), BorderLayout.NORTH);
910     rigthCenterPanel.add(createCenterJScrollPane(), BorderLayout.CENTER);
911     rigthCenterPanel.add(createHorizontalScrollBar(), BorderLayout.SOUTH);
912     centerJScrollPane.setHorizontalScrollBar(horizontal);
913     centerJScrollPane.setVerticalScrollBar(createVeritcalScrollBar());
914     return rigthCenterPanel;
915   }
916
917   /**
918    * retorna un ScrollBar Verical
919    * @return vertical
920    */

921   private JScrollBar createVeritcalScrollBar() {
922     vertical = new JScrollBar(JScrollBar.VERTICAL);
923     return vertical;
924   }
925
926   /**
927    * crea y devuelve un panel que contiene el ScrollBar horizontal del lado derecho del plit al al sur
928    * @return
929    */

930   private Component createHorizontalScrollBar() {
931     horizontal = new JScrollBar(JScrollBar.HORIZONTAL);
932     JPanel horizontalPanel = new JPanel(new BorderLayout());
933     horizontalPanel.add(horizontal, BorderLayout.CENTER);
934     return horizontalPanel;
935   }
936
937   /**
938    * Devuelve el panel del lado derecho ubicado al norte en el split
939    * @return el panel northPanel
940    */

941   private Component createNorthPanel() {
942     northPanel = new JPanel();
943     northPanel.setLayout(new BorderLayout());
944     northPanel.add(createNorthJPanel(), BorderLayout.CENTER);
945     return northPanel;
946   }
947
948   /**
949    * retorna el panel ubicado al centro del panel northPanel
950    * @return
951    */

952   private Component createNorthJPanel() {
953     JPanel component = new JPanel();
954     component.setLayout(new BorderLayout());
955     component.add(createEastFiller(), BorderLayout.EAST);
956     component.add(createColumnHeaderPanel(), BorderLayout.CENTER);
957     return component;
958   }
959
960   /**
961    * Crea dibuja y setea las propiedades la tabla columnHeaderPanel
962    * @return
963    */

964   private Component createColumnHeaderPanel() {
965     columnHeaderPanel = new JPanel();
966     columnHeaderPanel.setLayout(new BorderLayout());
967     columnHeaderPanel.add(createColumnPanel(), BorderLayout.SOUTH);
968     columnHeaderPanel.add(createColumnDropTarget(), BorderLayout.NORTH);
969     return columnHeaderPanel;
970   }
971
972   /**
973    * crea el panel que contiene el JScrollPane oculto donde se ubica la tabla columnHeaderjTable
974    * @return
975    */

976   private Component createColumnPanel() {
977     columnPanel = new JPanel();
978     columnPanel.setLayout(new BorderLayout());
979     columnPanel.add(createColTableJScroll(), BorderLayout.CENTER);
980     return columnPanel;
981   }
982
983   /**
984    * Crea el panel que se encuentra sobre la tabla columnHeaderjTable al cual se le podran colocar los paneles con
985    * propiedades de drag and drop
986    * @return
987    */

988   private Component createColumnDropTarget() {
989     JComponent panel = createTargetPanel(DimensionDefinitionLocationType.COLUMN.toString(), Color.WHITE);
990     panel.setPreferredSize(new Dimension(0, 15));
991     return panel;
992   }
993
994   /**
995    * Crea el panel utilizado para separar la tabla columnHeaderjTable con el
996    * @return
997    */

998   private Component createEastFiller() {
999     eastFiller = new JPanel();
1000    eastFiller.setLayout(new BorderLayout());
1001    eastFiller.setPreferredSize(new Dimension(15, 0));
1002    return eastFiller;
1003  }
1004
1005  /**
1006   * devuelve el scroll ubicado en el centro del lado derecho del split
1007   * @return
1008   */

1009  private Component createCenterJScrollPane() {
1010    centerJScrollPane = new JScrollPane();
1011    centerJScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
1012    centerJScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
1013    JPanel aux = new JPanel(new BorderLayout());
1014    aux.add(createTableData(), BorderLayout.CENTER);
1015    aux.add(datajTable.getTableHeader(), BorderLayout.NORTH);
1016    centerJScrollPane.getViewport().add(aux);
1017    return centerJScrollPane;
1018  }
1019
1020  /**
1021   * crea un JScrollPane oculto donde se apoya la tabla columnHeaderjTable
1022   * @return
1023   */

1024  private Component createColTableJScroll() {
1025    colTableJScroll = new JScrollPane();
1026    colTableJScroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
1027    colTableJScroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
1028    colTableJScroll.setAutoscrolls(true);
1029    JPanel aux = new JPanel();
1030    JViewport view = new JViewport();
1031    aux.setLayout(new BorderLayout());
1032    aux.add(createColumnHeaderTable(), BorderLayout.CENTER);
1033    view.add(aux, BorderLayout.NORTH);
1034    colTableJScroll.setViewport(view);
1035    return colTableJScroll;
1036  }
1037
1038  /**
1039   * Crea la tabla columnHeaderjTable
1040   * @return
1041   */

1042  private JTable createColumnHeaderTable() {
1043    columnHeaderjTable = new JTable();
1044    columnHeaderjTable.setDefaultRenderer(Object JavaDoc.class, new HeaderTableRenderer());
1045    columnHeaderjTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_LAST_COLUMN);
1046    columnHeaderjTable.setUI(new ColumnHeaderTableUI());
1047    columnHeaderjTable.addMouseListener(new MouseAdapter() {
1048      public void mouseReleased(MouseEvent e) {
1049        try {
1050          changeNodeState(e);
1051        } catch (Exception JavaDoc el) {
1052          ShowExceptionMessageDialog.initExceptionDialogMessage(LanguageTraslator.traslate("328"),el);
1053        }
1054      }
1055    });
1056    return columnHeaderjTable;
1057  }
1058
1059
1060  protected DimensionValueNode getRowsRoot(){
1061    return ((HeaderTableModel)getRowHeaderjTable().getModel()).getDimensionValueNode();
1062  }
1063
1064  protected DimensionValueNode getColumnsRoot(){
1065    return ((HeaderTableModel)getColumnHeaderjTable().getModel()).getDimensionValueNode();
1066  }
1067
1068  /**
1069   * Lllenar el contenido de las tablas
1070   * @param reportResult
1071   */

1072  public void fillContents(ReportResult reportResult) throws InfoException {
1073    removeAllPanels();
1074    JTable rowTable = getRowHeaderjTable();
1075    JTable colTable = getColumnHeaderjTable();
1076    JTable dataTable = getDatajTable();
1077    fillComponents();
1078    Vector dataVector = ((CubeReportResult)reportResult).getDataVector();
1079    TableModel JavaDoc dataModel;
1080    if (dataVector!= null){
1081      dataModel = new DefaultTableModel JavaDoc(dataVector,getColumnsNames(((Vector)dataVector.get(0)).size()));
1082    }else{
1083      dataVector = new Vector();
1084      dataModel = new DefaultTableModel JavaDoc(dataVector,null);
1085    }
1086
1087    dataTable.setModel(dataModel);
1088    if (dataVector.size() > 0) {
1089      rowTable.setModel(((CubeReportResult)reportResult).getRowsModel());
1090      colTable.setModel(((CubeReportResult)reportResult).getColumnsModel());
1091    }
1092    /*if (dataVector.size() > 0) {
1093      colModel = HeaderTableModel.newColumnHeaderTableModel(columnsRoot, getWithTotals(), columnsRoot.getDimensionCount(), reportResult);
1094      rowModel = HeaderTableModel.newRowHeaderTableModel(rowsRoot, getWithTotals(), rowsRoot.getDimensionCount(), reportResult);
1095      rowTable.setModel(rowModel);
1096      colTable.setModel(colModel);
1097    } */

1098    DefaultTableModel JavaDoc tableDataModel = (DefaultTableModel JavaDoc) dataTable.getModel();
1099    tableDataModel.fireTableChanged(null);
1100    if (!getRowHeaderDimension().isEmpty()) {
1101      applyDimensionColumnProperties();
1102      invaildatePanels();
1103    }
1104
1105 // setSize();
1106
pivotTableFrame.setState(false);
1107    maximizarActionPerformed();
1108    if (getRowHeaderDimension().isEmpty()) {
1109      mainSplit.setDividerLocation(100);
1110    }
1111    else {
1112      int heigth = pivotTableFrame.getFrame().getContentPane().getPreferredSize().height;
1113      leftCenterPanel.setPreferredSize(new Dimension(adjustmentSizeSplit(),heigth));
1114      setSize();
1115      invaildatePanels();
1116    }
1117    mainSplit.invalidate();
1118  }
1119
1120  private void applyDimensionColumnProperties() {
1121    Iterator iterator = tableProperties.getColumnProperties().iterator();
1122    int ubication = 0;
1123    while (iterator.hasNext()) {
1124      ColumnProperties properties = (ColumnProperties) iterator.next();
1125      if (DimensionDefinitionLocationType.ROW.toString().compareToIgnoreCase(properties.getLocation()) == 0) {
1126        ubication = properties.getUbication();
1127        if (rowHeaderjTable.getColumnModel().getColumnCount() >0 ){
1128          rowHeaderjTable.getColumnModel().getColumn(ubication).setPreferredWidth(properties.getWidth());
1129        }
1130      }
1131    }
1132  }
1133
1134  /**
1135   * Guarda los width de las columnas pertenecientes a roeHeaderTable
1136   */

1137  private void setRowDimensionMap() throws InfoException {
1138    Map rowDimension = getAllRowColumnProperties();
1139    for (int index = 0; index < rowHeaderjTable.getModel().getColumnCount(); index++) {
1140      if (!rowDimension.isEmpty()) {
1141
1142        JPanel panel = (JPanel) targetPanels.get(DimensionDefinitionLocationType.ROW.toString());
1143        DragSourcePanel sourcePanel = (DragSourcePanel) panel.getComponent(index);
1144        ColumnProperties properties = tableProperties.getRowColumn(sourcePanel.getName());
1145        properties.setWidth(rowHeaderjTable.getColumnModel().getColumn(index).getWidth());
1146        properties.setColumnName(sourcePanel.getName());
1147        ArrayList list = (ArrayList) reportResult.getReportQuery().getDimensionsByLocation(DimensionDefinitionLocationType.valueOf(panel.getName()));
1148        QueryDimension queryDimension = (QueryDimension) list.get(index);
1149        properties.setOrder(queryDimension.getOrder());
1150        properties.setLocation(DimensionDefinitionLocationType.ROW.toString());
1151        rowDimension.put(sourcePanel.getName(), properties);
1152        rowDimension.put(properties.getColumnName(), properties);
1153      }
1154    }
1155    tableProperties.updateColumnsProperties();
1156    rowHeaderDimension = rowDimension;
1157  }
1158
1159  /**
1160   * Retorna la posicion donde se ajusta la barra del split
1161   */

1162  private int adjustmentSizeSplit() {
1163    Map rowDimension = getAllRowColumnProperties();
1164    int widthSplit = 0;
1165    if (!rowDimension.isEmpty()) {
1166      Iterator iterator = rowDimension.values().iterator();
1167      while (iterator.hasNext()) {
1168        ColumnProperties properties = (ColumnProperties) iterator.next();
1169        if (properties != null) {
1170          widthSplit += properties.getWidth() + 2;
1171        }
1172      }
1173    }
1174    return widthSplit;
1175  }
1176
1177
1178  /**
1179   * Limpia el contenido de todos los paneles de ROW - COLUMN - PAGE
1180   */

1181  private void removeAllPanels() {
1182    Iterator iterator = targetPanels.values().iterator();
1183    while (iterator.hasNext()) {
1184      DropTargetPanel panel = (DropTargetPanel) iterator.next();
1185      if (panel.getComponentCount() > 0) {
1186        panel.removeAllComponents();
1187      }
1188    }
1189    changeDimensionLocation = new HashMap();
1190    dragPanels = new Hashtable();
1191    page = 0;
1192    col = 0;
1193    row = 0;
1194  }
1195
1196  /**
1197   * Accion de colasado o expandido de un grupo de celdas
1198   * @param e
1199   */

1200  private void changeNodeState(MouseEvent e) throws InfoException {
1201    JTable comp = (JTable) e.getComponent();
1202    int row = comp.rowAtPoint(e.getPoint());
1203    int col = comp.columnAtPoint(e.getPoint());
1204    Rectangle rect = comp.getCellRect(row, col, true);
1205    double cellx = e.getPoint().getX() - rect.getX();
1206    double celly = e.getPoint().getY() - rect.getY();
1207    HeaderTableRenderer renderer = (HeaderTableRenderer) comp.getDefaultRenderer(Object JavaDoc.class);
1208    int iconWidth = renderer.getIconWidth();
1209    int iconHeight = renderer.getIconHeight();
1210    if (cellx <= iconWidth && celly <= iconHeight) {
1211      HeaderTableModel model = (HeaderTableModel) comp.getModel();
1212      boolean stateChanged = model.changeNodeState(row, col);
1213      if (stateChanged) {
1214        boolean isDistributed = pivotTableFrame.getReportGeneratorConfiguration().getIsDistributed();
1215        Vector dataVector = pivotTableFrame.getReportManager().getUpdatedDataModel(pivotTableFrame.getReportHandle(), model.getMode(), row, col, isDistributed);
1216
1217        TableModel JavaDoc dataModel = new DefaultTableModel JavaDoc(dataVector,getColumnsNames(((Vector)dataVector.get(0)).size()));
1218        getDatajTable().setModel(dataModel);
1219        getDatajTable().revalidate();
1220
1221        int count;
1222        if (model.getMode() == HeaderTableModel.MODE_ROW) {
1223          ((HeaderTableUI)rowHeaderjTable.getUI()).resetFinals();
1224          count = dataVector.size();
1225          ((HeaderTableModel) comp.getModel()).setRowCount(count);
1226          HeaderTableModel tm = ((HeaderTableModel) comp.getModel());
1227          tm.fireTableChanged(null);
1228          setSize();
1229        }
1230        else {
1231          ((HeaderTableUI)columnHeaderjTable.getUI()).resetFinals();
1232          count = ((Vector)dataVector.get(0)).size();
1233          ((HeaderTableModel) comp.getModel()).setRowCount(count);
1234          HeaderTableModel tm = ((HeaderTableModel) comp.getModel());
1235          DefaultTableModel JavaDoc tableDataModel = (DefaultTableModel JavaDoc) datajTable.getModel();
1236          tableDataModel.fireTableChanged(null);
1237          tm.fireTableChanged(null);
1238          revalidateTable();
1239        }
1240      }
1241    }
1242  }
1243
1244
1245  /**
1246   * Actualiza los anchos de las columnas de la tabla columnHeaderjTable
1247   */

1248  private void revalidateTable() {
1249    for (int index = 0; index < datajTable.getModel().getColumnCount(); index++) {
1250      columnHeaderjTable.getColumnModel().getColumn(index).setWidth(datajTable.getTableHeader().getColumnModel().getColumn(index).getWidth());
1251    }
1252  }
1253
1254  /**
1255   * crea y devuelve el panel que contiene a la tabla dataTable en el centro del split del lado derecho
1256   * @return
1257   */

1258  private Component createTableData() {
1259    datajTable = new JTable();
1260    DataTableCellRenderer cellRenderer = new DataTableCellRenderer(colorConditionManager, getReportResult(), Color.WHITE);
1261    cellRenderer.setHorizontalAlignment(JLabel.RIGHT);
1262    datajTable.setDefaultRenderer(Object JavaDoc.class, cellRenderer);
1263    datajTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_LAST_COLUMN);
1264    datajTable.setColumnSelectionAllowed(true);
1265    datajTable.setAutoscrolls(false);
1266    datajTable.getTableHeader().setPreferredSize(new Dimension(0, 0));
1267    datajTable.setDefaultEditor(Object JavaDoc.class, null);
1268    return datajTable;
1269  }
1270
1271  /**
1272   * Genera un componente el cual se coloca en el centro del JSplitPane mainSplit de lado izquierdo
1273   * @return retorna el componente a agregar
1274   */

1275  private Component createLeftCenterPanel() {
1276    leftCenterPanel = new JPanel();
1277    leftCenterPanel.setLayout(new BorderLayout());
1278    leftCenterPanel.add(createLeftSplitNorthPanel(), BorderLayout.NORTH);
1279    leftCenterPanel.add(createCenterSplitPanel(), BorderLayout.CENTER);
1280    leftCenterPanel.add(createSouthFiller(), BorderLayout.SOUTH);
1281    return leftCenterPanel;
1282  }
1283
1284  /**
1285   * Crea un panel al sur del split del lado derecho
1286   * @return
1287   */

1288  private Component createSouthFiller() {
1289    southFiller = new JPanel();
1290    southFiller.setLayout(new BorderLayout());
1291    southFiller.setPreferredSize(new Dimension(0, 15));
1292    return southFiller;
1293  }
1294
1295  /**
1296   * Crea el panel central del lado izquierdo del split
1297   * @return
1298   */

1299  private Component createCenterSplitPanel() {
1300    centerSplitNorthPanel = new JPanel();
1301    centerSplitNorthPanel.setLayout(new BorderLayout());
1302    centerSplitNorthPanel.add(createLeftCenterScrollPane(), BorderLayout.CENTER);
1303    return centerSplitNorthPanel;
1304  }
1305
1306  /**
1307   * Crea un JScrollPane en el panel central del lado izuiqrdo del split
1308   * @return
1309   */

1310  private Component createLeftCenterScrollPane() {
1311    leftCenterScrollPane = new JScrollPane();
1312    leftCenterScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
1313    leftCenterScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
1314    leftCenterScrollPane.getViewport().add(createRowHeaderjTable(), BorderLayout.CENTER);
1315    return leftCenterScrollPane;
1316  }
1317
1318  /**
1319   * crea la tabla rowHeaderjTable y carga los datos de la misma
1320   * @return rowHeaderjTable
1321   */

1322  private Component createRowHeaderjTable() {
1323    rowHeaderjTable = new JTable();
1324    rowHeaderjTable.setDefaultRenderer(Object JavaDoc.class, new HeaderTableRenderer());
1325    rowHeaderjTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
1326    rowHeaderjTable.getTableHeader().setPreferredSize(new Dimension(0, 0));
1327    rowHeaderjTable.setUI(new RowHeaderTableUI());
1328    rowHeaderjTable.addMouseListener(new MouseAdapter() {
1329      public void mouseReleased(MouseEvent e) {
1330        try {
1331          changeNodeState(e);
1332        } catch (InfoException e1) {
1333          ShowExceptionMessageDialog.initExceptionDialogMessage(LanguageTraslator.traslate("328"), e1);
1334        }
1335      }
1336    });
1337    return rowHeaderjTable;
1338  }
1339
1340  /**
1341   Crea un panel vacio del lado izquierdo del Split , en la parte suporior del componente
1342   * @return devuelve el panel leftSplitNorthPanel
1343   */

1344  private Component createLeftSplitNorthPanel() {
1345    leftSplitNorthPanel = new JPanel();
1346    leftSplitNorthPanel.setLayout(new BorderLayout());
1347    leftSplitNorthPanel.add(crateSouthRowFieldDropTarget(), BorderLayout.SOUTH);
1348    return leftSplitNorthPanel;
1349  }
1350
1351  /**
1352   * Crea un panel al sur del panel vacio leftSplitNorthPanel donde se colocan componente con
1353   * propiedades de Drag and Drop
1354   * @return el panel southRowFieldDropTarget
1355   */

1356
1357  private Component crateSouthRowFieldDropTarget() {
1358    southRowFieldDropTarget = new JPanel();
1359    southRowFieldDropTarget.setLayout(new BorderLayout());
1360    JComponent comp = (JComponent) crateRowFieldDropTarget();
1361    southRowFieldDropTarget.setPreferredSize(new Dimension(0, 18));
1362    southRowFieldDropTarget.add(comp);
1363    return southRowFieldDropTarget;
1364  }
1365
1366  /**
1367   * Crea el componente que acepta acciones de Drag and Drop en el panel southRowFieldDropTarget
1368   * @return
1369   */

1370  private Component crateRowFieldDropTarget() {
1371    return createTargetPanel(DimensionDefinitionLocationType.ROW.toString(), Color.WHITE);
1372  }
1373
1374
1375  /**
1376   * Genera el panel del Norte donde se colocan paneles con propiedades de Drag and Drop
1377   * @return componente que acepta paneles para drag and drop
1378   */

1379  private Component createPageFieldComponents() {
1380    pageFields = new JPanel();
1381    pageFields.setLayout(new BorderLayout());
1382    pageFields.add(createPageFillerEast(), BorderLayout.EAST);
1383    pageFields.add(createPageFieldsScrollPane(), BorderLayout.CENTER);
1384    return pageFields;
1385  }
1386
1387  /**
1388   * Crea el JScrollPane pageFieldsScrollPane al norte del componente pivoteTable
1389   * @return
1390   */

1391  private JComponent createPageFieldsScrollPane() {
1392    pageFieldsScrollPane = new javax.swing.JScrollPane JavaDoc();
1393    pageFieldsScrollPane.setPreferredSize(new Dimension(0, 20));
1394    pageFieldsScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
1395    pageFieldsScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
1396    pageFieldsScrollPane.getViewport().add(createPageConteinerComponent(), FlowLayout.LEFT);
1397    return pageFieldsScrollPane;
1398  }
1399
1400  /**
1401   * Crea el panel ubicado al norte del componente PivoteTable
1402   * @return
1403   */

1404  private Component createPageConteinerComponent() {
1405    pageConteinerComponent = new JPanel();
1406    pageConteinerComponent.setLayout(new BorderLayout());
1407    JComponent comp = createPageFieldDropTarget();
1408    pageConteinerComponent.add(comp, BorderLayout.CENTER);
1409    return pageConteinerComponent;
1410  }
1411
1412  /**
1413   Crea un panel para ser utilizado con propiedades de Drag and Drop
1414   */

1415
1416  private JComponent createPageFieldDropTarget() {
1417    return createTargetPanel(DimensionDefinitionLocationType.PAGE.toString(), Color.WHITE);
1418  }
1419
1420  /**
1421   * Craa un panel donde se coloca el Scroll el la parte superior derecha del componente
1422   * @return un panel
1423   */

1424  private JComponent createPageFillerEast() {
1425    pageFillerRigth = new JPanel(new BorderLayout());
1426    pageFillerRigth.setPreferredSize(new Dimension(32, 18));
1427    pageFillerRigth.add(createPageFieldScrollBar(), BorderLayout.CENTER);
1428    return pageFillerRigth;
1429  }
1430
1431
1432  /**
1433   * crea el JScrollBar el en panel pageFillerRigth
1434   * @return
1435   */

1436  private JComponent createPageFieldScrollBar() {
1437    pageFieldScrollBar = new JScrollBar();
1438    pageFieldScrollBar.setOrientation(javax.swing.JScrollBar.HORIZONTAL);
1439    pageFieldScrollBar.setUnitIncrement(10);
1440    return pageFieldScrollBar;
1441  }
1442
1443  /**
1444   * Implementacion del metodo fieldPositionChanged de la interface FieldPositionListener .
1445   *
1446   *
1447   * fieldPositionChanged realiza la acionn de Drop
1448   * @param positionName
1449   * @param fieldName
1450   */

1451  public void fieldPositionChanged(String JavaDoc positionName, String JavaDoc fieldName, Point location) throws InfoException {
1452    pivotTableFrame.setState(false);
1453    DropTargetPanel panel = (DropTargetPanel) targetPanels.get(positionName);
1454    DragSourcePanel dpanel = (DragSourcePanel) dragPanels.get(fieldName);
1455    panel.addFieldPanel(dpanel);
1456    changePositionPanel(fieldName, positionName, location);
1457    changeDimensionLocation.remove(fieldName);
1458    changePosition(panel, positionName);
1459    this.width = 0;
1460
1461    updateTableProperties(positionName, fieldName);
1462    pivotTableFrame.revalidateReportResult(tableProperties);
1463    fillContents(reportResult);
1464    invaildatePanels();
1465  }
1466
1467  /**
1468   * Obtiene el indice correspondiente al ArrayLsit de ColumnProperies de una columna determinada
1469   * @param s
1470   * @return
1471   */

1472  public int getColumnPropertiesIndex(String JavaDoc s) {
1473    ArrayList properties = tableProperties.getColumnProperties();
1474    for (int index = 0; index < properties.size(); index++) {
1475      ColumnProperties columnProperties = (ColumnProperties) properties.get(index);
1476      if (columnProperties.getColumnName().compareToIgnoreCase(s) == 0) {
1477        return index;
1478      }
1479    }
1480    return -1;
1481  }
1482
1483  /**
1484   * Actualiza la posicion del panael movido a positionName
1485   * @param panel
1486   * @param positionName
1487   */

1488  private void changePosition(DropTargetPanel panel, String JavaDoc positionName) {
1489    Integer JavaDoc pos = null;
1490    for (int i = 0; i < panel.getComponentCount(); i++) {
1491      DragSourcePanel aux = (DragSourcePanel) panel.getComponent(i);
1492      Object JavaDoc[] values = (Object JavaDoc[]) changeDimensionLocation.get(aux.getName());
1493      if (values != null) {
1494        values[1] = new Integer JavaDoc(i);
1495        putObject(aux.getName(), values);
1496      }
1497      else {
1498        Object JavaDoc[] val = new Object JavaDoc[3];
1499        if (positionName == DimensionDefinitionLocationType.ROW.toString()) {
1500          pos = new Integer JavaDoc(DimensionDefinitionLocationType.ROW_TYPE);
1501          val[0] = pos;
1502          val[1] = new Integer JavaDoc(i);
1503          putObject(aux.getName(), val);
1504
1505        }
1506        if (positionName == DimensionDefinitionLocationType.COLUMN.toString()) {
1507          pos = new Integer JavaDoc(DimensionDefinitionLocationType.COLUMN_TYPE);
1508          val[0] = pos;
1509          val[1] = new Integer JavaDoc(i);
1510          putObject(aux.getName(), val);
1511
1512        }
1513        if (positionName == DimensionDefinitionLocationType.PAGE.toString()) {
1514          pos = new Integer JavaDoc(DimensionDefinitionLocationType.PAGE_TYPE);
1515          val[0] = pos;
1516          val[1] = new Integer JavaDoc(i);
1517          putObject(aux.getName(), val);
1518        }
1519      }
1520    }
1521  }
1522
1523  /**
1524   * Realiza la accion de Drag & Drop de un panel hacia otro panel
1525   * @param name
1526   * @param position
1527   * @param location
1528   */

1529  private void changePositionPanel(String JavaDoc name, String JavaDoc position, Point location) {
1530    this.width = 0;
1531    Component[] aux = new Component[2];
1532    JPanel panel1 = (JPanel) targetPanels.get(position);
1533    JPanel source = (JPanel) dragPanels.get(name);
1534    if (panel1.getComponents().length > 1) {
1535      DragSourcePanel drag = null;
1536      for (int index = 0; index < panel1.getComponentCount(); index++) {
1537        drag = (DragSourcePanel) panel1.getComponent(index);
1538        if (index == 0 && drag.getWidth() > location.getX()) {
1539          aux[0] = source;
1540          aux[1] = drag;
1541          Component[] comp = changePositionPanels(panel1.getComponents(), aux[0], aux[1], index);
1542          panel1.removeAll();
1543          insertComponents(comp, panel1);
1544          return;
1545        }
1546        else {
1547          width += drag.getWidth();
1548          if (width < location.getX()) {
1549            aux[0] = source;
1550            aux[1] = drag;
1551          }
1552          else {
1553            aux[0] = source;
1554            aux[1] = drag;
1555            Component[] comp = changePositionPanels(panel1.getComponents(), aux[0], aux[1], index);
1556            panel1.removeAll();
1557            insertComponents(comp, panel1);
1558            return;
1559          }
1560        }
1561      }
1562    }
1563  }
1564
1565  /**
1566   * Realiza un intercambio de paneles para obtener su posicion actualizada cuando se realiza una accion de
1567   * Drag & Drop
1568   * @param comp
1569   * @param panel1
1570   */

1571  private void insertComponents(Component[] comp, JPanel panel1) {
1572    for (int index = 0; index < comp.length; index++) {
1573      panel1.add(comp[index]);
1574    }
1575  }
1576
1577  /**
1578   * cambia de posicion los paneles del array de Component para intercambiar las dimensiones
1579   */

1580  private Component[] changePositionPanels(Component[] components, Component source, Component drag, int locationIndex) {
1581    Component[] aux = new Component[components.length];
1582    int auxIndex = 0;
1583    for (int index = 0; index < components.length; index++) {
1584      if (components[index] == drag) {
1585        aux[index] = source;
1586        auxIndex = index;
1587
1588      }
1589    }
1590    if (locationIndex == 0) {
1591      System.arraycopy(components, 0, aux, auxIndex + 1, components.length - 1);
1592    }
1593    else {
1594      System.arraycopy(components, 0, aux, 0, locationIndex);
1595      if ((aux.length - 1) - locationIndex == 1) {
1596        aux[aux.length - 1] = drag;
1597      }
1598      else {
1599        if ((aux.length - 1) - locationIndex > 0) {
1600          for (int i = locationIndex; i < components.length - 1; i++) {
1601            aux[i + 1] = components[i];
1602          }
1603        }
1604      }
1605    }
1606    return aux;
1607  }
1608
1609
1610  /**
1611   * Cambia la posicion del panel dentro del changeDimensionValues para poder realizar la nueva querry y ordenar
1612   * los paneles drageables en el lugar apropiado , acomodando las dimensiones
1613   * @param fieldName
1614   * @param location
1615   */

1616  private void changePositionHasTable(String JavaDoc fieldName, DimensionDefinitionLocationType location) {
1617    Object JavaDoc[] values = new Object JavaDoc[2];
1618    if (location.getType() == DimensionDefinitionLocationType.PAGE_TYPE) {
1619      values[0] = new Integer JavaDoc(location.getType());
1620      values[1] = new Integer JavaDoc(page++);
1621      putObject(fieldName, values);
1622    }
1623    if (location.getType() == DimensionDefinitionLocationType.ROW_TYPE) {
1624      values[0] = new Integer JavaDoc(location.getType());
1625      values[1] = new Integer JavaDoc(row++);
1626      putObject(fieldName, values);
1627    }
1628    if (location.getType() == DimensionDefinitionLocationType.COLUMN_TYPE) {
1629      values[0] = new Integer JavaDoc(location.getType());
1630      values[1] = new Integer JavaDoc(col++);
1631      putObject(fieldName, values);
1632    }
1633  }
1634
1635  /**
1636   * Verifica si existe el objeto en el HashTable changeDimensionValues, si existe lo borra y lo pone nuevamente ,
1637   * sino , lo ingresa directamente
1638   * @param key
1639   * @param values
1640   */

1641  private void putObject(String JavaDoc key, Object JavaDoc[] values) {
1642    if (changeDimensionLocation.get(key) == null) {
1643      changeDimensionLocation.put(key, values);
1644    }
1645    else {
1646      changeDimensionLocation.remove(key);
1647      changeDimensionLocation.put(key, values);
1648    }
1649  }
1650
1651  /**
1652   * Metodo utilizado para actualizar los componentes de los paneles en los cuales se realizan acciones de Drag and Drop
1653   */

1654  public void invaildatePanels() {
1655    for (Iterator iterator = targetPanels.values().iterator(); iterator.hasNext();) {
1656      JPanel panel1 = (JPanel) iterator.next();
1657      panel1.invalidate();
1658      panel1.revalidate();
1659    }
1660    ((HeaderTableUI)columnHeaderjTable.getUI()).resetFinals();
1661    ((HeaderTableUI)rowHeaderjTable.getUI()).resetFinals();
1662    resizeComponent();
1663
1664    getContentPane().repaint();
1665  }
1666
1667  /**
1668   * Setea el Objeto
1669   * @param s
1670   * @param panel DropTargetPanel para poder realizar acciones de Drag Drop
1671   * @param location
1672   */

1673  private void addDragPanel(String JavaDoc s, DropTargetPanel panel, DimensionDefinitionLocationType location) {
1674    DragSourcePanel dragPanel = panel.addField(s, this, getColumnDescriptionFromName(s));
1675    dragPanel.setBackground(Color.GRAY);
1676    s.trim();
1677    dragPanels.put(s, dragPanel);
1678    changePositionHasTable(s, location);
1679    if (location == DimensionDefinitionLocationType.PAGE) {
1680      int width = dragPanel.getMinimumSize().width;
1681      pageFieldScrollBar.setMaximum(pageFieldScrollBar.getMaximum() + width);
1682
1683    }
1684  }
1685
1686  /**
1687   * Craga de componentes drageables
1688   */

1689  private void fillComponents() throws InfoException {
1690    DimensionDefinitionLocationType location;
1691    location = DimensionDefinitionLocationType.PAGE;
1692    addFieldsByLocation((DropTargetPanel) targetPanels.get(location.toString()), location);
1693    location = DimensionDefinitionLocationType.ROW;
1694    addFieldsByLocation((DropTargetPanel) targetPanels.get(location.toString()), location);
1695    location = DimensionDefinitionLocationType.COLUMN;
1696    addFieldsByLocation((DropTargetPanel) targetPanels.get(location.toString()), location);
1697  }
1698
1699  /**
1700   * Genera los paneles con sus valores en las distintas orientaciones(PAGE ROW COLUMN )
1701   */

1702  private void addFieldsByLocation(DropTargetPanel targetPanel, DimensionDefinitionLocationType location) throws InfoException {
1703    ArrayList list = (ArrayList) reportResult.getReportQuery().getDimensionsByLocation(location);
1704    loadTargetPanel(list, targetPanel);
1705
1706  }
1707
1708  /**
1709   * Llena las propiedades de las Columnas de la vista correspondiente
1710   * @param list
1711   * @param location
1712   * @throws InfoException
1713   */

1714  private void fillColumnsProperties(ArrayList list, String JavaDoc location) throws InfoException {
1715    Iterator iterator = list.iterator();
1716    while (iterator.hasNext()) {
1717      QueryDimension dimension = (QueryDimension) iterator.next();
1718      ColumnProperties properties = new ColumnProperties();
1719      properties.setColumnName(dimension.getName());
1720      properties.setWidth(DEFAULT_COLUMN_WIDTH);
1721      int indexDimension = reportResult.getReportQuery().getQueryDimensionFromName(properties.getColumnName()).getIndex();
1722      properties.setExcludeValue(reportResult.getReportQuery().getExcludedValues(indexDimension));
1723      properties.setOrder(reportResult.getReportQuery().getQueryDimensionFromName(properties.getColumnName()).getOrder());
1724      properties.setLocation(location);
1725      properties.setRankMetricName(reportResult.getReportQuery().getQueryDimensionFromName(properties.getColumnName()).getRankMetricName());
1726      properties.setOrder(reportResult.getReportQuery().getQueryDimensionFromName(properties.getColumnName()).getOrder());
1727      tableProperties.getColumnProperties().add(properties);
1728
1729    }
1730  }
1731
1732  /**
1733   * Carga los valores para cada dimension
1734   * @param list
1735   * @param targetPanel
1736   */

1737  private void loadTargetPanel(ArrayList list, DropTargetPanel targetPanel) throws InfoException {
1738    for (int i = 0; i < list.size(); i++) {
1739      QueryDimension queryDimension = (QueryDimension) list.get(i);
1740      addDragPanel(queryDimension.getName(), targetPanel, queryDimension.getLocation());
1741      loadRowTableProperties(queryDimension, targetPanel);
1742    }
1743    rowHeaderDimension = getAllRowColumnProperties();
1744
1745  }
1746
1747  /**
1748   * Cargas las propiedaes de la vista
1749   * @param queryDimension
1750   * @param targetPanel
1751   //* @throws InfoException
1752   */

1753  private void loadRowTableProperties(QueryDimension queryDimension, DropTargetPanel targetPanel) throws InfoException {
1754    int index = getColumnPropertiesIndex(queryDimension.getName());
1755    if (index < 0) {
1756      ColumnProperties properties = tableProperties.getRowColumn(queryDimension.getName());
1757      properties.setColumnName(queryDimension.getName());
1758      properties.setLocation(targetPanel.getName());
1759      properties.setOrder(queryDimension.getOrder());
1760      properties.setUbication(getComponentIndex(targetPanel, queryDimension.getName()));
1761      tableProperties.updateColumnsProperties();
1762    }
1763    else {
1764      Object JavaDoc[] value = (Object JavaDoc[]) changeDimensionLocation.get(queryDimension.getName());
1765      ColumnProperties properties = tableProperties.getRowColumn(queryDimension.getName());
1766      properties.setColumnName(queryDimension.getName());
1767      properties.setLocation(targetPanel.getName());
1768      properties.setOrder(queryDimension.getOrder());
1769      int position = ((Integer JavaDoc) value[1]).intValue();
1770      properties.setUbication(position);
1771      tableProperties.updateColumnsProperties();
1772    }
1773  }
1774
1775
1776  /**
1777   * Determina la posicion en la cual esta ubicado el panel
1778   * @param targetPanel
1779   * @param name
1780   * @return
1781   */

1782  private int getComponentIndex(DropTargetPanel targetPanel, String JavaDoc name) {
1783    for (int index = 0; index < targetPanel.getComponentCount(); index++) {
1784      JPanel panel = (JPanel) targetPanel.getComponent(index);
1785      if (panel.getName().compareToIgnoreCase(name) == 0) {
1786        return index;
1787      }
1788    }
1789    return -1;
1790  }
1791
1792  /**
1793   * Deculeve la descripción de la columna indicada
1794   * @param name
1795   * @return
1796   */

1797  private String JavaDoc getColumnDescriptionFromName(String JavaDoc name) {
1798    if (reportResult != null) {
1799      return reportResult.getDimensionFromName(name).getCaption();
1800    }
1801    return name;
1802
1803  }
1804
1805  /**
1806   * Crea un panel para ser utilizado con propiedades de Drag and Drop
1807   * @param s
1808   * @param color
1809   * @return
1810   */

1811  private DropTargetPanel createTargetPanel(String JavaDoc s, Color color) {
1812    DropTargetPanel panel;
1813    panel = new DropTargetPanel(s, mainSplit);
1814    panel.setBackground(color);
1815    panel.setFieldPositionListener(this);
1816    targetPanels.put(s, panel);
1817    return panel;
1818  }
1819
1820  /**
1821   * Setea el Frame donde se va a poner el componente
1822   * @param frame
1823   */

1824  public void setFrame(JFrame frame) {
1825    this.frame = frame;
1826    this.frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
1827  }
1828
1829  /**
1830   * Retorna el Frame donde se va a poner el componente
1831   * @return
1832   */

1833  public JFrame getFrame() {
1834    return frame;
1835  }
1836
1837  /**
1838   * Devuelve el JSplitPane del componente
1839   * @return
1840   */

1841  public JSplitPane getMainSplit() {
1842    return mainSplit;
1843  }
1844
1845  /**
1846   * Devuleve el Conteiner donde se apoya el componente en el Frame
1847   * @return
1848   */

1849  public Container getContentPane() {
1850    return contentPane;
1851  }
1852
1853  /**
1854   * Sete el Conteiner del JFrame donde se va a apoyar el componente
1855   * @param contentPane
1856   */

1857  public void setContentPane(Container contentPane) {
1858    this.contentPane = contentPane;
1859  }
1860
1861  /**
1862   * Este metodo es utilidazo para imprimir el contenido de las tablas
1863   */

1864  public void printPivoteTable(IReportManager reportManager, ReportView reportView,Dimension dim) {
1865    try {
1866      ReportUI reportUI = new ReportUI(reportResult, reportResult.getReportSpec(), reportManager, getPivotTableFrame().getReportGeneratorConfiguration(), reportView, dim);
1867      if(reportUI.getFrame()!=null){
1868        reportUI.show();
1869      }
1870    }
1871    catch (Exception JavaDoc e) {
1872      InfoException infoException = new InfoException(LanguageTraslator.traslate("220"));
1873      ShowExceptionMessageDialog.initExceptionDialogMessage(LanguageTraslator.traslate("220"), infoException);
1874    }
1875  }
1876
1877  private void setQueryDimensionLocationFrom(String JavaDoc [] rowDimensionNames, ReportQuery query, int type) {
1878    for(int i = 0 ; i < rowDimensionNames.length ; i++) {
1879      try {
1880        query.setDimensionLocationOrder(rowDimensionNames[i], type);
1881      } catch (InfoException e) {
1882        e.printStackTrace();
1883      }
1884    }
1885  }
1886
1887  private String JavaDoc[] getDimensionNames(Collection rowDimensions) {
1888    String JavaDoc [] names = new String JavaDoc[rowDimensions.size()];
1889    Iterator iterator = rowDimensions.iterator();
1890    for(int i = 0 ; iterator.hasNext() ; i++) {
1891      ReportDimensionSpec spec = (ReportDimensionSpec) iterator.next();
1892      names[i] = spec.getName();
1893    }
1894    return names;
1895  }
1896
1897  /**
1898   * Devuelve la tabla datajTable
1899   * @return
1900   */

1901  public JTable getDatajTable() {
1902    return datajTable;
1903  }
1904
1905  /**
1906   * Devuelve la tabla rowHeaderjTable
1907   * @return
1908   */

1909  public JTable getRowHeaderjTable() {
1910    return rowHeaderjTable;
1911  }
1912
1913  /**
1914   * Devuelve la tabla columnHeaderjTable
1915   * @return
1916   */

1917  public JTable getColumnHeaderjTable() {
1918    return columnHeaderjTable;
1919  }
1920
1921  /**
1922   * Obtiene un objeto ReportResult
1923   * @return
1924   */

1925  public ReportResult getReportResult() {
1926    return reportResult;
1927  }
1928
1929  /**
1930   * Sete un objeto Reportresult nuevo
1931   * @param reportResult
1932   */

1933  public void setReportResult(ReportResult reportResult) throws InfoException {
1934    this.reportResult = reportResult;
1935    JTable table = getDatajTable();
1936    if (table != null) {
1937      TableCellRenderer renderer = table.getDefaultRenderer(Object JavaDoc.class);
1938      if (renderer instanceof DataTableCellRenderer) {
1939        ((DataTableCellRenderer) renderer).setReportResult(reportResult);
1940      }
1941    }
1942    if (tableProperties != null) {
1943      tableProperties.setReportResult(reportResult);
1944    }
1945  }
1946
1947  /**
1948   * Retorna un Map con las ubicaciones de los paneles (ROW - COLUMN - PAGE) y su posicion
1949   * @return
1950   */

1951  public Map getChangeDimensionLocation() {
1952    return changeDimensionLocation;
1953  }
1954
1955  /**
1956   * Retorna el componente ubicado en la izquierda al centro de la PivoteTable
1957   * @return
1958   */

1959  public Component getLeftCenterPanel() {
1960    return leftCenterPanel;
1961  }
1962
1963  /**
1964   * Sete la vista vcon o sin totales y contruye una query nueva
1965   * @throws InfoException
1966   */

1967  public void setPivoteTableSinTotales() throws InfoException {
1968    if (getColModel().getWithTotals() && getRowModel().getWithTotals()) {
1969      withTotals = false;
1970      pivotTableFrame.setState(false);
1971      tableProperties.setWithTotal(withTotals);
1972      pivotTableFrame.buildNewQuery(tableProperties);
1973      fillContents(getReportResult());
1974    }
1975    else {
1976      withTotals = true;
1977      pivotTableFrame.setState(false);
1978      tableProperties.setWithTotal(withTotals);
1979      //fillContents(getReportResult());
1980
pivotTableFrame.buildNewQuery(tableProperties);
1981      fillContents(getReportResult());
1982    }
1983    invaildatePanels();
1984    if (getRowHeaderDimension().isEmpty()) {
1985      mainSplit.setDividerLocation(100);
1986    }
1987    else {
1988      int heigth = pivotTableFrame.getFrame().getContentPane().getPreferredSize().height;
1989      leftCenterPanel.setPreferredSize(new Dimension(adjustmentSizeSplit(),heigth));
1990    }
1991
1992  }
1993
1994
1995  /**
1996   * Retorna el modelo de la tabla ubicada en COLUMN
1997   * @return
1998   */

1999  public HeaderTableModel getColModel() {
2000    return (HeaderTableModel) getColumnHeaderjTable().getModel();
2001  }
2002
2003  /**
2004   * Retorna el modelo de la tabla ubicada en ROW
2005   * @return
2006   */

2007  public HeaderTableModel getRowModel() {
2008    return (HeaderTableModel) getRowHeaderjTable().getModel();
2009  }
2010
2011  /**
2012   * Retorna un objeto ColorConditionManager
2013   * @return
2014   */

2015  public ColorConditionManager getColorConditionManager() {
2016    return colorConditionManager;
2017  }
2018
2019  /**
2020   * Retorna un map , donde se van a ubicar las ColumnProperties pertenecientes a ROW
2021   * @return
2022   */

2023  public Map getRowHeaderDimension() {
2024    if (rowHeaderDimension == null) {
2025      return rowHeaderDimension = new HashMap();
2026    }
2027    return rowHeaderDimension;
2028  }
2029
2030  /**
2031   * Obtiene un objeto PivotTableProperties
2032   * @return
2033   */

2034  public PivotTableProperties getTableProperties() {
2035    return tableProperties;
2036  }
2037
2038  /**
2039   * Setea una nueva PivotTableProperties
2040   * @param tableProperties
2041   */

2042  public void setTableProperties(PivotTableProperties tableProperties) {
2043    this.tableProperties = tableProperties;
2044  }
2045
2046  /**
2047   * Retorna un objeto AplicationView
2048   * @return
2049   */

2050  public AplicationView getView() {
2051    return view;
2052  }
2053
2054
2055  /**
2056   * Obtiene un objeto PivoteTableFrame
2057   * @return
2058   */

2059
2060  public PivotTableFrame getPivotTableFrame() {
2061    return pivotTableFrame;
2062  }
2063
2064  /**
2065   * Sete si se quiere ver la vista con o sin totales
2066   * @param withTotals
2067   */

2068  public void setWithTotals(boolean withTotals) {
2069    this.withTotals = withTotals;
2070  }
2071
2072  /**
2073   * Construye un vector con los nombres de la columnas
2074   * @param columnCount
2075   * @return
2076   */

2077  protected Vector getColumnsNames(int columnCount){
2078    Vector names = new Vector(columnCount);
2079    for (int i = 0; i < columnCount; i++) {
2080      names.add(String.valueOf(i));
2081    }
2082    return names;
2083  }
2084
2085  private boolean getIsReadOnly(){
2086    return (getPivotTableFrame().getMicroReport()!=null);
2087  }
2088
2089
2090}
Popular Tags