0001: package com.calipso.reportgenerator.userinterface;
0002:
0003: import com.calipso.reportgenerator.reportdefinitions.types.DimensionDefinitionLocationType;
0004: import com.calipso.reportgenerator.reportdefinitions.types.ReportDefinitionReportTypeType;
0005: import com.calipso.reportgenerator.reportdefinitions.types.DrillDownDefinitionTypeType;
0006: import com.calipso.reportgenerator.reportdefinitions.ReportDefinition;
0007: import com.calipso.reportgenerator.reportdefinitions.ReportSourceDefinition;
0008: import com.calipso.reportgenerator.reportdefinitions.ReportView;
0009: import com.calipso.reportgenerator.userinterface.dinamicchart.ChartPivotTable;
0010: import com.calipso.reportgenerator.userinterface.dinamicchart.ChartPivotFrame;
0011: import com.calipso.reportgenerator.common.*;
0012:
0013: import javax.swing.*;
0014: import javax.swing.table.DefaultTableModel;
0015: import java.awt.*;
0016: import java.awt.event.WindowAdapter;
0017: import java.awt.event.ActionListener;
0018: import java.awt.event.ActionEvent;
0019: import java.util.*;
0020: import java.util.zip.ZipOutputStream;
0021: import java.io.File;
0022:
0023: import com.calipso.reportgenerator.common.InfoException;
0024:
0025: /**
0026: * Esta clase muestra el cubo en un frame propio
0027: */
0028: public class PivotTableFrame extends ReportFrame implements
0029: ActionListener, IReportFrame {
0030:
0031: private ReportViewerToolBar toolBar;
0032: private JFrame frame;
0033: private PivotTable pivotTable;
0034: private JPanel bottomPanel;
0035: private JButton printButton;
0036: private JButton exportMicroReportButton;
0037: private JButton graphicButton;
0038: private JPanel pivotPanel;
0039: private JButton maximizar;
0040: private JButton semaforo;
0041: private JButton searcher;
0042: private JButton excel;
0043: private JButton viewBtn;
0044: private JButton editDimensionValueBtn;
0045: private boolean state;
0046: private int reportHandle;
0047: private IReportFrame parent;
0048: private String userID;
0049: private Map params;
0050: private JButton ordenBtn;
0051: private JPanel centerPanel;
0052: private JPanel boxPanel;
0053: private int WIDTH = 90;
0054: private int HEIGTH = 26;
0055: private ReportSpec reportSpec;
0056: private boolean fromMicroReport = false;
0057: private MicroReport microReport;
0058: private ReportGeneratorConfiguration reportGeneratorConfiguration;
0059: private ReportView reportView;
0060: private boolean autoRefresh = true;
0061:
0062: /**
0063: * Inicializa
0064: * @param reportDefId
0065: * @param reportManager
0066: */
0067: public PivotTableFrame(IReportFrame parent, String reportDefId,
0068: IReportManager reportManager, Map params, String userId,
0069: ReportGeneratorConfiguration reportGeneratorConfiguration)
0070: throws InfoException {
0071: this .reportGeneratorConfiguration = reportGeneratorConfiguration;
0072: this .parent = parent;
0073: this .params = params;
0074: this .setUserID(userId);
0075: this .reportSpec = reportManager.getReportSpec(reportDefId);
0076: if (reportSpec.getCached()) {
0077: reportHandle = reportManager.PrepareReport(reportDefId);
0078: } else {
0079: reportHandle = reportManager.PrepareReport(reportDefId,
0080: params);
0081: }
0082: super .reportManager = reportManager;
0083: ReportQuery query = reportManager.getDefaultReportQuery(
0084: reportHandle, getUserID());
0085: query.setParamValues(params);
0086: super .reportResult = reportManager.ExecReportQuery(
0087: reportHandle, query);
0088: initComponents();
0089: }
0090:
0091: public PivotTableFrame(IReportFrame parent, String reportDefId,
0092: IReportManager reportManager, Map params, String userId,
0093: String reportViewID,
0094: ReportGeneratorConfiguration reportGeneratorConfiguration)
0095: throws InfoException {
0096: this .reportGeneratorConfiguration = reportGeneratorConfiguration;
0097: this .params = params;
0098: this .parent = parent;
0099: this .setUserID(userId);
0100: this .reportSpec = reportManager.getReportSpec(reportDefId);
0101: if (reportSpec.getCached()) {
0102: reportHandle = reportManager.PrepareReport(reportDefId);
0103: } else {
0104: reportHandle = reportManager.PrepareReport(reportDefId,
0105: params);
0106: }
0107: super .reportManager = reportManager;
0108: reportView = reportManager.getReportViewFromID(reportViewID,
0109: reportDefId, userId);
0110: super .reportResult = reportManager.ExecReportQuery(
0111: reportHandle, reportView);
0112: initComponents();
0113: }
0114:
0115: public PivotTableFrame(IReportFrame parent,
0116: MicroReport microReport, IReportManager reportManager,
0117: String userId,
0118: ReportGeneratorConfiguration reportGeneratorConfiguration)
0119: throws InfoException {
0120: this .reportGeneratorConfiguration = reportGeneratorConfiguration;
0121: this .parent = parent;
0122: this .microReport = microReport;
0123: fromMicroReport = true;
0124: this .reportView = microReport.getReportView();
0125: this .setUserID(userId);
0126: microReport.getReportSourceDefinition().setCached(true);
0127: microReport.getReportSourceDefinition()
0128: .setIncrementalDimension("");
0129: this .reportSpec = reportManager.getReportSpec(microReport
0130: .getReportDefinition(), microReport
0131: .getReportSourceDefinition());
0132: reportHandle = reportManager.PrepareReport(microReport);
0133: super .reportManager = reportManager;
0134: //TODO: el MicroReport puede tener n vistas, con lo cual esto no seria lo mas correcto.
0135: super .reportResult = reportManager.ExecReportQuery(
0136: reportHandle, microReport.getReportView());
0137: initComponents();
0138: }
0139:
0140: public PivotTableFrame(IReportFrame parent,
0141: MicroReport microReport, IReportManager reportManager,
0142: String userId,
0143: ReportGeneratorConfiguration reportGeneratorConfiguration,
0144: Map params) throws InfoException {
0145: this .reportGeneratorConfiguration = reportGeneratorConfiguration;
0146: this .parent = parent;
0147: this .microReport = microReport;
0148: fromMicroReport = true;
0149: this .reportView = microReport.getReportView();
0150: this .setUserID(userId);
0151: microReport.getReportSourceDefinition().setCached(true);
0152: microReport.getReportSourceDefinition()
0153: .setIncrementalDimension("");
0154: this .reportSpec = reportManager.getReportSpec(microReport
0155: .getReportDefinition(), microReport
0156: .getReportSourceDefinition());
0157: reportHandle = reportManager.PrepareReport(microReport);
0158: super .reportManager = reportManager;
0159: super .reportResult = reportManager.ExecReportQuery(
0160: reportHandle, params);
0161: initComponents();
0162: }
0163:
0164: /**
0165: * Inicializa los componentes del cubo
0166: */
0167:
0168: private void initComponents() throws InfoException {
0169: state = false;
0170: getFrame().getContentPane().setLayout(new BorderLayout());
0171: getFrame().getContentPane().add(createCenterPanelAplication(),
0172: BorderLayout.CENTER);
0173: pivotTable = new PivotTable(this , reportView);
0174: frame.addWindowListener(new WindowAdapter() {
0175: public void windowClosing() {
0176: System.exit(0);
0177: }
0178: });
0179:
0180: /*getGraphicButton().addActionListener(new java.awt.event.ActionListener() {
0181: public void actionPerformed(java.awt.event.ActionEvent evt) {
0182: doGraphics();
0183: }
0184: });*/
0185:
0186: /*getSinTotales().addActionListener(new java.awt.event.ActionListener() {
0187: public void actionPerformed(java.awt.event.ActionEvent evt) {
0188: try {
0189: pivotTable.setPivoteTableSinTotales();
0190: }
0191: catch (Exception e) {
0192: ShowExceptionMessageDialog.initExceptionDialogMessage(LanguageTraslator.traslate("103"), e);
0193: }
0194: }
0195: });*/
0196:
0197: /*getPrintButton().addActionListener(new java.awt.event.ActionListener() {
0198: public void actionPerformed(java.awt.event.ActionEvent evt) {
0199: printPivotTable();
0200:
0201: }
0202: });*/
0203:
0204: /*getExportMicroReportButton().addActionListener(new java.awt.event.ActionListener() {
0205: public void actionPerformed(java.awt.event.ActionEvent evt) {
0206: exportMicroReport();
0207: }
0208: });*/
0209:
0210: /*maximizar.addActionListener(new java.awt.event.ActionListener() {
0211: public void actionPerformed(java.awt.event.ActionEvent evt) {
0212: maximizarActionPerformed();
0213: }
0214: });*/
0215:
0216: frame.pack();
0217: java.awt.Dimension screenSize = java.awt.Toolkit
0218: .getDefaultToolkit().getScreenSize();
0219: frame.setSize(new java.awt.Dimension(700, 450));
0220: frame.setLocation((screenSize.width - 700) / 2,
0221: (screenSize.height - 450) / 2);
0222: }
0223:
0224: public void doGraphics() {
0225: ChartUI chart = new ChartUI(pivotTable,
0226: reportGeneratorConfiguration);
0227: chart.setVisible(true);
0228: }
0229:
0230: public void printPivotTable(Dimension dim) {
0231: pivotTable.printPivoteTable(reportManager, reportView, dim);
0232: }
0233:
0234: public void exportMicroReport() {
0235: JFileChooser fileChooser = new JFileChooser();
0236: int mode = fileChooser.showSaveDialog(null);
0237: if (mode == JFileChooser.APPROVE_OPTION) {
0238: File file = fileChooser.getSelectedFile();
0239: try {
0240: ReportDefinition reportDefinition = this .reportManager
0241: .getReportDefinitionFromID(reportSpec
0242: .getDefinitionId());
0243: ReportSourceDefinition reportSourceDefinition = this .reportManager
0244: .getReportSourceDefinitionFromID(reportDefinition
0245: .getReportSource());
0246: ReportView reportView = pivotTable.getTableProperties()
0247: .getReportView(reportDefinition.getId(),
0248: getUserID(), "");
0249: MicroReport microReport = new MicroReport(reportManager
0250: .getMatrix(reportHandle),
0251: reportSourceDefinition, reportDefinition,
0252: reportView, "", userID,
0253: getViews(reportDefinition.getId()), params);
0254: ZipOutputStream zipOutputStream = microReport.getZip(
0255: file.getPath(), reportGeneratorConfiguration
0256: .isCsvSerialized());
0257: zipOutputStream.close();
0258: } catch (Exception e) {
0259: ShowExceptionMessageDialog.initExceptionDialogMessage(
0260: LanguageTraslator.traslate("267"), e);
0261: }
0262: }
0263: }
0264:
0265: /**
0266: * Devuleve un map con los view para el reporte para el usuario
0267: * @return
0268: */
0269: public Map getViews(String reportDefinitionId) throws InfoException {
0270: Map map = reportManager.getReportViews(reportDefinitionId,
0271: userID);
0272: Map returnMap = new HashMap();
0273: String reportName;
0274: for (int i = 0; i < map.size(); i++) {
0275: reportName = map.values().toArray()[i].toString();
0276: returnMap.put(reportName, reportManager
0277: .getReportViewFromID(reportName,
0278: reportDefinitionId, userID));
0279: }
0280: return returnMap;
0281: }
0282:
0283: private JButton getExportMicroReportButton() {
0284: return exportMicroReportButton;
0285: }
0286:
0287: private Component createCenterPanelAplication() {
0288: centerPanel = new JPanel(new BorderLayout());
0289: //centerPanel.add(createEastBoxPanel(), BorderLayout.WEST);
0290: centerPanel.add(createPivoteTablePanel(), BorderLayout.CENTER);
0291: centerPanel.add(createBottomPanel(), BorderLayout.SOUTH);
0292: return centerPanel;
0293: }
0294:
0295: private Component createBottomPanel() {
0296: bottomPanel = new JPanel();
0297: //bottomPanel.setPreferredSize(new Dimension(100, 10));
0298: return bottomPanel;
0299: }
0300:
0301: private Component createPivoteTablePanel() {
0302: pivotPanel = new JPanel();
0303: pivotPanel.setLayout(new BorderLayout());
0304: //pivotPanel.setPreferredSize(new Dimension(700,450));
0305: return pivotPanel;
0306: }
0307:
0308: private Component createEastBoxPanel() {
0309: boxPanel = new javax.swing.JPanel();
0310: boxPanel.setLayout(new javax.swing.BoxLayout(boxPanel,
0311: javax.swing.BoxLayout.Y_AXIS));
0312: //boxPanel.add(createJButtonResize());
0313: //boxPanel.add(createJButtonSinTotals());
0314: boxPanel.add(createJButtonView());
0315: boxPanel.add(createJButtonSemaforo());
0316: boxPanel.add(createJButtonSearcher());
0317: boxPanel.add(createJButtonExcel());
0318: boxPanel.add(createJButtonGraphic());
0319: boxPanel.add(createJButtonEditDimensionValues());
0320: boxPanel.add(createJButtonOrden());
0321: boxPanel.add(createJButtonPrint());
0322: boxPanel.add(createJButtonExportMicroReport());
0323: return boxPanel;
0324: }
0325:
0326: public void maximizarActionPerformed() {
0327: if (state) {
0328: state = false;
0329: } else {
0330: state = true;
0331: }
0332:
0333: }
0334:
0335: private JButton createJButtonPrint() {
0336: this .printButton = makeNavigationButton("print16", "IMPRIMIR",
0337: "Imprime la definicion actual", "");
0338: printButton
0339: .setMaximumSize(new java.awt.Dimension(WIDTH, HEIGTH));
0340: printButton
0341: .setMinimumSize(new java.awt.Dimension(WIDTH, HEIGTH));
0342: printButton.setPreferredSize(new java.awt.Dimension(WIDTH,
0343: HEIGTH));
0344: return printButton;
0345: }
0346:
0347: private JButton createJButtonExportMicroReport() {
0348: this .exportMicroReportButton = makeNavigationButton("save16",
0349: "EXPORTAR", "Guarda en disco la definicion actual", "");
0350: exportMicroReportButton.setMaximumSize(new java.awt.Dimension(
0351: WIDTH, HEIGTH));
0352: exportMicroReportButton.setMinimumSize(new java.awt.Dimension(
0353: WIDTH, HEIGTH));
0354: exportMicroReportButton
0355: .setPreferredSize(new java.awt.Dimension(WIDTH, HEIGTH));
0356: return exportMicroReportButton;
0357: }
0358:
0359: private JButton createJButtonGraphic() {
0360: this .graphicButton = makeNavigationButton("GRAFICO", "GRAFICO",
0361: "Realiza graficos estadisticos", "");
0362: graphicButton.setMaximumSize(new java.awt.Dimension(WIDTH,
0363: HEIGTH));
0364: graphicButton.setMinimumSize(new java.awt.Dimension(WIDTH,
0365: HEIGTH));
0366: graphicButton.setPreferredSize(new java.awt.Dimension(WIDTH,
0367: HEIGTH));
0368: return graphicButton;
0369: }
0370:
0371: /*private JButton createJButtonSinTotals() {
0372: sinTotales = new JButton(LanguageTraslator.traslate("135"));
0373: sinTotales.setMaximumSize(new java.awt.Dimension(WIDTH, HEIGTH));
0374: sinTotales.setMinimumSize(new java.awt.Dimension(WIDTH, HEIGTH));
0375: sinTotales.setPreferredSize(new java.awt.Dimension(WIDTH, HEIGTH));
0376: return sinTotales;
0377: }*/
0378:
0379: /*private JButton createJButtonResize() {
0380: maximizar = new JButton(LanguageTraslator.traslate("136"));
0381: maximizar.setMaximumSize(new java.awt.Dimension(WIDTH, HEIGTH));
0382: maximizar.setMinimumSize(new java.awt.Dimension(WIDTH, HEIGTH));
0383: maximizar.setPreferredSize(new java.awt.Dimension(WIDTH, HEIGTH));
0384: return maximizar;
0385: }*/
0386:
0387: private JButton createJButtonSearcher() {
0388: searcher = makeNavigationButton("search", "BUSCAR",
0389: "Busca valores para las dimensiones", "");
0390: searcher.setMaximumSize(new java.awt.Dimension(WIDTH, HEIGTH));
0391: searcher.setMinimumSize(new java.awt.Dimension(WIDTH, HEIGTH));
0392: searcher
0393: .setPreferredSize(new java.awt.Dimension(WIDTH, HEIGTH));
0394: return searcher;
0395: }
0396:
0397: private JButton makeNavigationButton(String imageName,
0398: String actionCommand, String toolTipText, String altText) {
0399:
0400: String imgLocation = reportGeneratorConfiguration
0401: .getImagesPath()
0402: + "\\" + imageName + ".gif";
0403:
0404: //Create and initialize the button.
0405:
0406: JButton button = new JButton(
0407: new ImageIcon(imgLocation, altText));
0408: button.setActionCommand(actionCommand);
0409: button.setToolTipText(toolTipText);
0410: button.addActionListener(this );
0411: if (imgLocation != null) {
0412: button.setIcon(new ImageIcon(imgLocation, altText));
0413: } else {
0414: button.setText(altText);
0415: }
0416:
0417: return button;
0418: }
0419:
0420: private JButton createJButtonExcel() {
0421: excel = makeNavigationButton("EXCEL", "EXCEL",
0422: "Importa a excel los valores de la tabla", "");
0423: excel.setMaximumSize(new java.awt.Dimension(WIDTH, HEIGTH));
0424: excel.setMinimumSize(new java.awt.Dimension(WIDTH, HEIGTH));
0425: excel.setPreferredSize(new java.awt.Dimension(WIDTH, HEIGTH));
0426: return excel;
0427: }
0428:
0429: private JButton createJButtonSemaforo() {
0430: semaforo = makeNavigationButton("SEMAFORO1", "SEMAFORO",
0431: "Semaforizacion de valores", "");
0432: semaforo.setMaximumSize(new java.awt.Dimension(WIDTH, HEIGTH));
0433: semaforo.setMinimumSize(new java.awt.Dimension(WIDTH, HEIGTH));
0434: semaforo
0435: .setPreferredSize(new java.awt.Dimension(WIDTH, HEIGTH));
0436: return semaforo;
0437: }
0438:
0439: private JButton createJButtonView() {
0440: viewBtn = makeNavigationButton("PERFILES3", "PERFILES",
0441: "Establece perfiles de usuario", "");
0442: viewBtn.setMaximumSize(new java.awt.Dimension(WIDTH, HEIGTH));
0443: viewBtn.setMinimumSize(new java.awt.Dimension(WIDTH, HEIGTH));
0444: viewBtn.setPreferredSize(new java.awt.Dimension(WIDTH, HEIGTH));
0445: return viewBtn;
0446: }
0447:
0448: private JButton createJButtonEditDimensionValues() {
0449: editDimensionValueBtn = makeNavigationButton("RANKING",
0450: "RANKING",
0451: "Realiza un ranking en base a una dimension", "");
0452: editDimensionValueBtn.setMaximumSize(new java.awt.Dimension(
0453: WIDTH, HEIGTH));
0454: editDimensionValueBtn.setMinimumSize(new java.awt.Dimension(
0455: WIDTH, HEIGTH));
0456: editDimensionValueBtn.setPreferredSize(new java.awt.Dimension(
0457: WIDTH, HEIGTH));
0458: return editDimensionValueBtn;
0459: }
0460:
0461: private JButton createJButtonOrden() {
0462: ordenBtn = makeNavigationButton("ORDEN", "ORDEN",
0463: "Ordena en forma ascendente o descendente", "");
0464: ordenBtn.setMaximumSize(new java.awt.Dimension(WIDTH, HEIGTH));
0465: ordenBtn.setMinimumSize(new java.awt.Dimension(WIDTH, HEIGTH));
0466: ordenBtn
0467: .setPreferredSize(new java.awt.Dimension(WIDTH, HEIGTH));
0468: return ordenBtn;
0469: }
0470:
0471: public void updateQuerry(MetricState state, JCheckBox checkBox,
0472: PivotTableProperties tableProperties) throws InfoException {
0473: ReportQuery reportQuery = getReportManager()
0474: .getDefaultReportQuery(reportHandle);
0475: //ReportQuery reportQuery = getReportResult().getReportQuery();
0476: reportQuery.getQueryMetricFromName(state.getName()).setVisible(
0477: state.getVisible());
0478:
0479: try {
0480: //reportQuery = updateDimensionLocation(tableProperties, reportQuery);
0481: reportQuery = buildNewQueryExcludeValue(tableProperties,
0482: reportQuery, false, false);
0483: //reportQuery = updateVisibleMetrics(tableProperties, reportQuery);
0484: //reportQuery.setVisibleTotals(tableProperties.isWithTotal());
0485: pivotPanel.setCursor(new Cursor(Cursor.WAIT_CURSOR));
0486: if (isAutoRefresh()) {
0487: reportResult = getReportManager().ExecReportQuery(
0488: reportHandle, reportQuery);
0489: pivotTable.setReportResult(reportResult);
0490: } else {
0491: pivotTable.setReportResult(new CubeReportResult(
0492: reportResult.getReportSpec(), reportQuery,
0493: null, null, null));
0494: }
0495:
0496: parent.getToolBar().getBtSizes().setSelected(false);
0497: parent.getToolBar().setBtTotalsState(false);
0498: pivotPanel.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
0499: } catch (Exception e) {
0500: reportQuery.getQueryMetricFromName(state.getName())
0501: .setVisible(true);
0502: pivotTable.setVisible(false);
0503: checkBox.setSelected(true);
0504: if (isAutoRefresh()) {
0505: reportResult = getReportManager().ExecReportQuery(
0506: reportHandle, reportQuery);
0507: pivotTable.setReportResult(reportResult);
0508: } else {
0509: pivotTable.setReportResult(new CubeReportResult(
0510: reportResult.getReportSpec(), reportQuery,
0511: null, null, null));
0512: }
0513:
0514: pivotPanel.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
0515: ShowExceptionMessageDialog.initExceptionDialogMessage(
0516: LanguageTraslator.traslate("137"), e);
0517:
0518: }
0519: }
0520:
0521: /**
0522: * Devuelve el Frame
0523: * @return
0524: */
0525: public JFrame getFrame() {
0526: if (frame == null) {
0527: frame = new JFrame();
0528: //frame.getContentPane().setLayout(new BorderLayout());
0529: frame.setTitle(reportResult.getReportSpec().getTitle());
0530: frame.setName("Cube");
0531: }
0532: return frame;
0533: }
0534:
0535: /**
0536: * Muestra el cubo
0537: */
0538: public void show() {
0539: getFrame().setVisible(true);
0540: }
0541:
0542: public JButton getMaximizar() {
0543: return maximizar;
0544: }
0545:
0546: public void setMaximizar(JButton maximizar) {
0547: this .maximizar = maximizar;
0548: }
0549:
0550: public ReportResult getReportResult() {
0551: return reportResult;
0552: }
0553:
0554: public JPanel getPivotPanel() {
0555: return pivotPanel;
0556: }
0557:
0558: public Map getParams() {
0559: return params;
0560: }
0561:
0562: public void setParams(Map params) {
0563: this .params = params;
0564: }
0565:
0566: /**
0567: * Luego de un drag and drop regenera la query
0568: */
0569: public void revalidateReportResult(
0570: PivotTableProperties tableProperties) {
0571: if (reportManager != null) {
0572: try {
0573: buildNewQuery(tableProperties);
0574: } catch (Exception e) {
0575: ShowExceptionMessageDialog.initExceptionDialogMessage(
0576: LanguageTraslator.traslate("214"), e);
0577: }
0578: }
0579: }
0580:
0581: /**
0582: * Construye la nueva query a partir de las nuevas posiciones de las dimensiones y la ejecuta.
0583: */
0584: public void buildNewQuery(PivotTableProperties tableProperties)
0585: throws InfoException {
0586: System.gc();
0587: ReportQuery reportQuery = getReportManager()
0588: .getDefaultReportQuery(reportHandle);
0589: //ReportQuery reportQuery = getReportResult().getReportQuery();
0590: //reportQuery = updateDimensionLocation(tableProperties, reportQuery);
0591: reportQuery = buildNewQueryExcludeValue(tableProperties,
0592: reportQuery, false, true);
0593: //reportQuery = updateVisibleMetrics(tableProperties, reportQuery);
0594: //reportQuery.setVisibleTotals(tableProperties.isWithTotal());
0595: pivotPanel.setCursor(new Cursor(Cursor.WAIT_CURSOR));
0596: if (isAutoRefresh()) {
0597: reportResult = getReportManager().ExecReportQuery(
0598: reportHandle, reportQuery);
0599: pivotTable.setWithTotals(tableProperties.isWithTotal());
0600: pivotTable.setReportResult(reportResult);
0601: } else {
0602: pivotTable.setWithTotals(tableProperties.isWithTotal());
0603: pivotTable.setReportResult(new CubeReportResult(
0604: reportResult.getReportSpec(), reportQuery, null,
0605: null, null));
0606: }
0607: parent.getToolBar().getBtSizes().setSelected(false);
0608: parent.getToolBar().setBtSizesState(false);
0609: pivotPanel.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
0610: }
0611:
0612: private ReportQuery updateDimensionLocation(
0613: PivotTableProperties tableProperties,
0614: ReportQuery reportQuery) throws InfoException {
0615: ColumnProperties columnProperties;
0616: DimensionDefinitionLocationType location = DimensionDefinitionLocationType.PAGE;
0617: QueryDimension queryDimension;
0618: for (int i = 0; i < tableProperties.getColumnProperties()
0619: .size(); i++) {
0620: columnProperties = (ColumnProperties) tableProperties
0621: .getColumnProperties().get(i);
0622: if (columnProperties.getLocation().equalsIgnoreCase(
0623: DimensionDefinitionLocationType.PAGE.toString())) {
0624: location = DimensionDefinitionLocationType.PAGE;
0625: } else if (columnProperties.getLocation().equalsIgnoreCase(
0626: DimensionDefinitionLocationType.ROW.toString())) {
0627: location = DimensionDefinitionLocationType.ROW;
0628: }
0629: if (columnProperties.getLocation().equalsIgnoreCase(
0630: DimensionDefinitionLocationType.COLUMN.toString())) {
0631: location = DimensionDefinitionLocationType.COLUMN;
0632: }
0633: queryDimension = reportQuery
0634: .getQueryDimensionFromName(columnProperties
0635: .getColumnName());
0636: queryDimension.setLocation(location);
0637: queryDimension.setLocationOrder(columnProperties
0638: .getUbication());
0639: queryDimension.setRankMetricName(columnProperties
0640: .getRankMetricName());
0641: queryDimension.setOrder(columnProperties.getOrder());
0642: }
0643: return reportQuery;
0644: }
0645:
0646: /**
0647: * Actualiza los valores de metricas visibles de la reportquery de acuerdo a la pivot table properties
0648: * @param tableProperties
0649: * @param reportQuery
0650: */
0651: private ReportQuery updateVisibleMetrics(
0652: PivotTableProperties tableProperties,
0653: ReportQuery reportQuery) throws InfoException {
0654: MetricState metricState;
0655: for (int i = 0; i < tableProperties.getMetricProperies().size(); i++) {
0656: metricState = (MetricState) tableProperties
0657: .getMetricProperies().get(i);
0658: reportQuery.getQueryMetricFromName(metricState.getName())
0659: .setVisible(metricState.getVisible());
0660: }
0661: return reportQuery;
0662: }
0663:
0664: public ReportQuery buildNewQueryExcludeValue(
0665: PivotTableProperties tableProperties,
0666: ReportQuery reportQuery, boolean executeQuery,
0667: boolean updateMetrics) {
0668: try {
0669: Iterator iterator = tableProperties.getMetricProperies()
0670: .iterator();
0671: while (iterator.hasNext()) {
0672: MetricState state = (MetricState) iterator.next();
0673: reportQuery.getQueryMetricFromName(state.getName())
0674: .setVisible(state.getVisible());
0675: }
0676: reportQuery = updateDimensionLocation(tableProperties,
0677: reportQuery);
0678: if (updateMetrics) {
0679: reportQuery = updateVisibleMetrics(tableProperties,
0680: reportQuery);
0681: }
0682: reportQuery.setVisibleTotals(tableProperties.isWithTotal());
0683: updateDimensionValues(tableProperties, reportQuery);
0684: if (reportView == null) {
0685: reportQuery.setParamValues(params);
0686: }
0687: if (executeQuery == true) {
0688: pivotPanel.setCursor(new Cursor(Cursor.WAIT_CURSOR));
0689: if (isAutoRefresh()) {
0690: reportResult = getReportManager().ExecReportQuery(
0691: reportHandle, reportQuery);
0692: pivotTable.setReportResult(reportResult);
0693: } else {
0694: pivotTable.setReportResult(new CubeReportResult(
0695: reportResult.getReportSpec(), reportQuery,
0696: null, null, null));
0697: }
0698:
0699: parent.getToolBar().getBtSizes().setSelected(false);
0700: parent.getToolBar().setBtSizesState(false);
0701: pivotPanel.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
0702: }
0703: } catch (Exception e) {
0704: ShowExceptionMessageDialog.initExceptionDialogMessage(
0705: LanguageTraslator.traslate("214"), e);
0706: }
0707: return reportQuery;
0708: }
0709:
0710: private void updateDimensionValues(
0711: PivotTableProperties tableProperties,
0712: ReportQuery reportQuery) throws InfoException {
0713: Iterator iterator = tableProperties.getColumnProperties()
0714: .iterator();
0715: while (iterator.hasNext()) {
0716: ColumnProperties properties = (ColumnProperties) iterator
0717: .next();
0718: int dimensionIndex = reportQuery.getQueryDimensionFromName(
0719: properties.getColumnName()).getIndex();
0720: reportQuery.setExcludedValues(dimensionIndex, properties
0721: .getExcludeValue());
0722: }
0723: }
0724:
0725: /**
0726: * Devuelve el administrador de reportes
0727: * @return
0728: */
0729: public IReportManager getReportManager() {
0730: return reportManager;
0731: }
0732:
0733: public PivotTable getPivotTable() {
0734: return pivotTable;
0735: }
0736:
0737: public void setPivotTable(PivotTable pivotTable) {
0738: this .pivotTable = pivotTable;
0739: }
0740:
0741: public JButton getPrintButton() {
0742: return printButton;
0743: }
0744:
0745: public JButton getGraphicButton() {
0746: return graphicButton;
0747: }
0748:
0749: public boolean isSelected() {
0750: return state;
0751: }
0752:
0753: public void setState(boolean state) {
0754: this .state = state;
0755: }
0756:
0757: public JButton getSemaforo() {
0758: return semaforo;
0759: }
0760:
0761: public JButton getSearcher() {
0762: return searcher;
0763: }
0764:
0765: public JButton getViewBtn() {
0766: return viewBtn;
0767: }
0768:
0769: public String getUserID() {
0770: return userID;
0771: }
0772:
0773: public void setUserID(String userID) {
0774: this .userID = userID;
0775: }
0776:
0777: public int getReportHandle() {
0778: return reportHandle;
0779: }
0780:
0781: /**
0782: * ejecuta un drilldown segun la definición
0783: * @param drillDownDefinition
0784: */
0785: public void drillDown(DrillDownSpec drillDownDefinition,
0786: Map cubeValues) throws InfoException {
0787: if (validDrillDownValues(drillDownDefinition, cubeValues)) {
0788: Map params = getDrillDownParams(drillDownDefinition,
0789: cubeValues);
0790: switch (drillDownDefinition.getType().getType()) {
0791: case DrillDownDefinitionTypeType.MICROREPORT_TYPE:
0792: executeExportedReport(params, drillDownDefinition
0793: .getTargetReportDefinitionID(), getUserID());
0794: break;
0795: case DrillDownDefinitionTypeType.STATICWEB_TYPE:
0796: params = ReportFilterBuilder.mergeParamValues(
0797: getParams(), params);
0798: executeWebDrillDown(params, drillDownDefinition
0799: .getTargetReportDefinitionID(), reportSpec
0800: .getDefinitionId(), userID);
0801: break;
0802: default:
0803: ReportSpec reportSpec = getReportManager()
0804: .getReportSpec(
0805: drillDownDefinition
0806: .getTargetReportDefinitionID());
0807: String reportDefinitionId = drillDownDefinition
0808: .getTargetReportDefinitionID();
0809: try {
0810: if (reportSpec.getReportType().getType() == ReportDefinitionReportTypeType.CUBE_TYPE) {
0811: if ((!reportDefinitionId.equals(""))
0812: && (!getUserID().equals(""))) {
0813: PivotTableFrame pivotTableFrame = null;
0814: toolBar = new ReportViewerToolBar(
0815: JToolBar.HORIZONTAL);
0816: toolBar.drillDownExecuted();
0817: pivotTableFrame = new PivotTableFrame(this ,
0818: reportDefinitionId,
0819: getReportManager(), params,
0820: getUserID(),
0821: getReportGeneratorConfiguration());
0822: toolBar.setPivotTableFrame(pivotTableFrame);
0823: pivotTableFrame.getFrame().getContentPane()
0824: .add(toolBar,
0825: BorderLayout.PAGE_START);
0826: pivotTableFrame.show();
0827: }
0828: } else if (reportSpec.getReportType().getType() == ReportDefinitionReportTypeType.CHARTCUBE_TYPE) {
0829: ChartPivotTable chartPivotTable = new ChartPivotTable(
0830: reportSpec, getReportManager(), params,
0831: userID, reportDefinitionId, this );
0832: chartPivotTable.paintComponents(true);
0833: ChartPivotFrame chartPivotFrame = new ChartPivotFrame();
0834: chartPivotFrame.show(chartPivotTable);
0835: } else if (reportSpec.getReportType().getType() == ReportDefinitionReportTypeType.ACCUM_TYPE) {
0836: ReportResult reportResult = getReportManager()
0837: .ExecReportQuery(
0838: reportSpec.getDefinitionId(),
0839: params);
0840: ReportUI reportUI = null;
0841: String reportView = "";
0842: ReportView view = null;
0843: if (reportView != null
0844: && !reportView.equalsIgnoreCase("")) {
0845: view = getReportManager()
0846: .getReportViewFromID(
0847: reportView,
0848: reportSpec
0849: .getDefinitionId(),
0850: getUserID());
0851: }
0852: reportUI = new ReportUI(reportResult,
0853: reportResult.getReportSpec(),
0854: getReportManager(),
0855: getReportGeneratorConfiguration(),
0856: view, this .getFrame().getSize());
0857: if (reportUI != null) {
0858: reportUI.show();
0859: }
0860: }
0861: } catch (Exception e) {
0862: throw new InfoException("151", e);
0863: }
0864: }
0865: } else {
0866: String dimSourceNames = "";
0867: for (int i = 0; (i < drillDownDefinition
0868: .getDimensionBindSpecs().size()); i++) {
0869: String dimName = ((DimensionBindSpec) drillDownDefinition
0870: .getDimensionBindSpecs().get(i))
0871: .getSourceDimensionName();
0872: dimSourceNames = dimSourceNames
0873: + " "
0874: + getReportResult().getReportSpec()
0875: .getDimensionFromName(dimName)
0876: .getCaption();
0877: }
0878: throw new InfoException(LanguageTraslator.traslate("416")
0879: + " " + dimSourceNames);
0880: }
0881:
0882: }
0883:
0884: private void executeWebDrillDown(Map params, String urlBase,
0885: String reportId, String user) throws InfoException {
0886: String url = getUrl(urlBase, params, reportId, user);
0887: try {
0888: BrowserLauncher.openURL(url);
0889: } catch (Exception e) {
0890: throw new InfoException(LanguageTraslator.traslate("464"),
0891: e);
0892: }
0893: }
0894:
0895: private String getUrl(String baseUrl, Map params,
0896: String definitionId, String user) {
0897: String url = baseUrl;
0898: url += ("ReportDefinition=" + definitionId + "&");
0899: url += ("User=" + user);
0900: Iterator it = params.entrySet().iterator();
0901: while (it.hasNext()) {
0902: url += "&";
0903: Map.Entry entry = (Map.Entry) it.next();
0904: url += (entry.getKey().toString().trim() + "=" + entry
0905: .getValue().toString().trim());
0906: }
0907: return url;
0908: }
0909:
0910: private boolean validDrillDownValues(
0911: DrillDownSpec drillDownDefinition, Map cubeValues) {
0912: boolean returnValue = true;
0913: for (int i = 0; ((i < drillDownDefinition
0914: .getDimensionBindSpecs().size()) && (returnValue)); i++) {
0915: String dimSourceName = ((DimensionBindSpec) drillDownDefinition
0916: .getDimensionBindSpecs().get(i))
0917: .getSourceDimensionName();
0918: if (!(cubeValues.containsKey(dimSourceName))) {
0919: returnValue = false;
0920: }
0921:
0922: }
0923: return returnValue;
0924: }
0925:
0926: /**
0927: * Devuelve los parámetros cargados según el mapeo
0928: * @param drillDownSpec
0929: * @return
0930: */
0931: private Map getDrillDownParams(DrillDownSpec drillDownSpec,
0932: Map cubeValues) {
0933: Map params = new Hashtable();
0934:
0935: addFromParameter(params, drillDownSpec);
0936: addFromDimension(params, drillDownSpec, cubeValues);
0937: return params;
0938: }
0939:
0940: /**
0941: * Carga los parámetros a partir de los valores de las dimensiones
0942: * @param params
0943: * @param drillDownSpec
0944: * @param cubeValues
0945: */
0946: private void addFromDimension(Map params,
0947: DrillDownSpec drillDownSpec, Map cubeValues) {
0948: String sourceDimensionName;
0949: DimensionBindSpec dimensionBind;
0950: String filterName;
0951: for (int i = 0; i < drillDownSpec.getDimensionBindSpecs()
0952: .size(); i++) {
0953: dimensionBind = (DimensionBindSpec) drillDownSpec
0954: .getDimensionBindSpecs().toArray()[i];
0955: sourceDimensionName = dimensionBind
0956: .getSourceDimensionName();
0957: filterName = dimensionBind.getTargetFilterName()
0958: + dimensionBind.getTargetParameterName();
0959: if (cubeValues.containsKey(sourceDimensionName)) {
0960: params.put(filterName, cubeValues
0961: .get(sourceDimensionName));
0962: }
0963: }
0964: }
0965:
0966: /**
0967: * Carga los parámetros de acuerdo a los mapeos de parámetro a parámetro
0968: * @param params
0969: * @param drillDownSpec
0970: */
0971: private void addFromParameter(Map params,
0972: DrillDownSpec drillDownSpec) {
0973: String sourceName, targetName;
0974: for (int i = 0; i < drillDownSpec.getParameterBindSpecs()
0975: .size(); i++) {
0976: ParameterBindSpec parameterBindSpec = (ParameterBindSpec) drillDownSpec
0977: .getParameterBindSpecs().toArray()[i];
0978: sourceName = parameterBindSpec.getSourceFilterName()
0979: + parameterBindSpec.getSourceParameterName();
0980: targetName = parameterBindSpec.getTargetFilterName()
0981: + parameterBindSpec.getTargetParameterName();
0982: params.put(targetName, getReportResult().getReportSpec()
0983: .getParamValues(false).get(sourceName));
0984: }
0985: }
0986:
0987: public JButton getEditDimensionValueBtn() {
0988: return editDimensionValueBtn;
0989: }
0990:
0991: public JButton getOrdenBtn() {
0992: return ordenBtn;
0993: }
0994:
0995: public boolean getFromMicroReport() {
0996: return fromMicroReport;
0997: }
0998:
0999: public MicroReport getMicroReport() {
1000: return microReport;
1001: }
1002:
1003: public JPanel getCenterPanel() {
1004: return centerPanel;
1005: }
1006:
1007: public ReportGeneratorConfiguration getReportGeneratorConfiguration() {
1008: return reportGeneratorConfiguration;
1009: }
1010:
1011: public JButton getExcel() {
1012: return excel;
1013: }
1014:
1015: public void actionPerformed(ActionEvent e) {
1016: if (e.getActionCommand().equals("BUSCAR")) {
1017:
1018: }
1019: }
1020:
1021: public ReportViewerToolBar getToolBar() {
1022: return toolBar;
1023: }
1024:
1025: public Frame owner() {
1026: return parent.owner();
1027: }
1028:
1029: public void setAutoRefresh(boolean value) throws InfoException {
1030: autoRefresh = value;
1031: if (!autoRefresh) {
1032: pivotTable.getDatajTable()
1033: .setModel(new DefaultTableModel());
1034: pivotTable.getRowHeaderjTable().setModel(
1035: new DefaultTableModel());
1036: pivotTable.getColumnHeaderjTable().setModel(
1037: new DefaultTableModel());
1038: } else {
1039: buildNewQuery(pivotTable.getTableProperties());
1040: pivotTable.fillContents(reportResult);
1041: pivotTable.invaildatePanels();
1042: }
1043: }
1044:
1045: public boolean isAutoRefresh() {
1046: return autoRefresh;
1047: }
1048:
1049: /**
1050: * Ecuta un reporte que está exportado a micro report. Lo busca según los parámetros que se pasan en el repositorio de microreport
1051: * @param params
1052: * @param reportDefinitionID
1053: * @param userID
1054: */
1055: private void executeExportedReport(Map params,
1056: String reportDefinitionID, String userID)
1057: throws InfoException {
1058: MicroReport microReport = null;
1059: try {
1060: microReport = getReportManager().getMicroReport(
1061: reportDefinitionID, params);
1062: } catch (InfoException e) {
1063: throw new InfoException(LanguageTraslator.traslate("462"),
1064: e);
1065: }
1066: toolBar = new ReportViewerToolBar(JToolBar.HORIZONTAL);
1067: toolBar.drillDownExecuted();
1068: PivotTableFrame pivotTableFrame2 = null;
1069: try {
1070: pivotTableFrame2 = new PivotTableFrame(this , microReport,
1071: getReportManager(), getUserID(),
1072: getReportGeneratorConfiguration(), params);
1073: } catch (InfoException e) {
1074: throw new InfoException(LanguageTraslator.traslate("463"),
1075: e);
1076: }
1077: toolBar.setPivotTableFrame(pivotTableFrame2);
1078: pivotTableFrame2.getFrame().getContentPane().add(toolBar,
1079: BorderLayout.PAGE_START);
1080: pivotTableFrame2.show();
1081: }
1082:
1083: public void launchInfoPage() throws Exception {
1084: String infoPage = reportSpec.getInfoPage();
1085: if (infoPage == null || infoPage.equals("")) {
1086: JOptionPane.showMessageDialog(getPivotTable(),
1087: LanguageTraslator.traslate("531"),
1088: LanguageTraslator.traslate("532"),
1089: JOptionPane.WARNING_MESSAGE);
1090: } else {
1091: BrowserLauncher.openURL(infoPage);
1092: }
1093: }
1094: }
|