0001: /*
0002: * Copyright (C) 2006 JasperSoft http://www.jaspersoft.com
0003: *
0004: * This program is free software; you can redistribute it and/or modify
0005: * it under the terms of the GNU General Public License as published by
0006: * the Free Software Foundation; either version 2 of the License, or
0007: * (at your option) any later version.
0008: *
0009: * This program is distributed WITHOUT ANY WARRANTY; and without the
0010: * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
0011: * See the GNU General Public License for more details.
0012: *
0013: * You should have received a copy of the GNU General Public License
0014: * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
0015: * or write to:
0016: *
0017: * Free Software Foundation, Inc.,
0018: * 59 Temple Place - Suite 330,
0019: * Boston, MA USA 02111-1307
0020: *
0021: *
0022: * ReportRefactor.java
0023: *
0024: * Created on May 4, 2007, 2:45 PM
0025: *
0026: * To change this template, choose Tools | Template Manager
0027: * and open the template in the editor.
0028: */
0029:
0030: package it.businesslogic.ireport.refactoring;
0031:
0032: import it.businesslogic.ireport.Band;
0033: import it.businesslogic.ireport.ChartReportElement2;
0034: import it.businesslogic.ireport.CrosstabReportElement;
0035: import it.businesslogic.ireport.Group;
0036: import it.businesslogic.ireport.HyperLinkableReportElement;
0037: import it.businesslogic.ireport.ImageReportElement;
0038: import it.businesslogic.ireport.JRLinkParameter;
0039: import it.businesslogic.ireport.JRSubreportParameter;
0040: import it.businesslogic.ireport.JRSubreportReturnValue;
0041: import it.businesslogic.ireport.JRVariable;
0042: import it.businesslogic.ireport.Report;
0043: import it.businesslogic.ireport.ReportElement;
0044: import it.businesslogic.ireport.SubDataset;
0045: import it.businesslogic.ireport.SubReportElement;
0046: import it.businesslogic.ireport.TextFieldReportElement;
0047: import it.businesslogic.ireport.chart.AreaPlot;
0048: import it.businesslogic.ireport.chart.Axis;
0049: import it.businesslogic.ireport.chart.Bar3DPlot;
0050: import it.businesslogic.ireport.chart.BarPlot;
0051: import it.businesslogic.ireport.chart.BubblePlot;
0052: import it.businesslogic.ireport.chart.CandlestickPlot;
0053: import it.businesslogic.ireport.chart.CategoryDataset;
0054: import it.businesslogic.ireport.chart.CategorySeries;
0055: import it.businesslogic.ireport.chart.Chart;
0056: import it.businesslogic.ireport.chart.Dataset;
0057: import it.businesslogic.ireport.chart.HighLowDataset;
0058: import it.businesslogic.ireport.chart.HighLowPlot;
0059: import it.businesslogic.ireport.chart.LinePlot;
0060: import it.businesslogic.ireport.chart.MeterInterval;
0061: import it.businesslogic.ireport.chart.MeterPlot;
0062: import it.businesslogic.ireport.chart.MultiAxisPlot;
0063: import it.businesslogic.ireport.chart.Pie3DPlot;
0064: import it.businesslogic.ireport.chart.PieDataset;
0065: import it.businesslogic.ireport.chart.PiePlot;
0066: import it.businesslogic.ireport.chart.Plot;
0067: import it.businesslogic.ireport.chart.ScatterPlot;
0068: import it.businesslogic.ireport.chart.SectionItemHyperlink;
0069: import it.businesslogic.ireport.chart.ThermometerPlot;
0070: import it.businesslogic.ireport.chart.TimePeriodDataset;
0071: import it.businesslogic.ireport.chart.TimePeriodSeries;
0072: import it.businesslogic.ireport.chart.TimeSeries;
0073: import it.businesslogic.ireport.chart.TimeSeriesDataset;
0074: import it.businesslogic.ireport.chart.TimeSeriesPlot;
0075: import it.businesslogic.ireport.chart.ValueDataset;
0076: import it.businesslogic.ireport.chart.XYDataset;
0077: import it.businesslogic.ireport.chart.XYSeries;
0078: import it.businesslogic.ireport.chart.XYZDataset;
0079: import it.businesslogic.ireport.chart.XYZSeries;
0080: import it.businesslogic.ireport.crosstab.CrosstabGroup;
0081: import it.businesslogic.ireport.crosstab.CrosstabParameter;
0082: import it.businesslogic.ireport.gui.MainFrame;
0083: import it.businesslogic.ireport.gui.event.ReportElementChangedEvent;
0084: import it.businesslogic.ireport.gui.event.SubDatasetObjectChangedEvent;
0085: import it.businesslogic.ireport.util.Misc;
0086: import java.util.Vector;
0087:
0088: /**
0089: *
0090: * @author gtoffoli
0091: */
0092: public class ReportRefactor {
0093:
0094: /*
0095: * Replace with newClassType the expression class for textfields in elements having expression as TextFieldExpression...
0096: * Return a set of changed elements...
0097: */
0098: public static java.util.List replaceTextfieldClass(
0099: String expression, String newClassType,
0100: java.util.List elements) {
0101: java.util.List list = new java.util.ArrayList();
0102: if (expression == null)
0103: return list;
0104: for (int i = 0; i < elements.size(); ++i) {
0105: ReportElement re = (ReportElement) elements.get(i);
0106: if (re instanceof TextFieldReportElement) {
0107: if (((TextFieldReportElement) re).getText().trim()
0108: .equals(expression)) {
0109: ((TextFieldReportElement) re)
0110: .setMatchingClassExpression(newClassType,
0111: true);
0112: list.add(re);
0113: }
0114: }
0115: }
0116: return list;
0117: }
0118:
0119: public static boolean updateDatasetRunExpressions(Dataset dataset,
0120: String oldString, String newString) {
0121: boolean add = false;
0122: if (dataset == null)
0123: return false;
0124: // Check in dataset run parameters...
0125: if (dataset.getConnectionExpression().indexOf(oldString) >= 0) {
0126: dataset.setConnectionExpression(Misc.string_replace(
0127: newString, oldString, dataset
0128: .getConnectionExpression()));
0129: add = true;
0130: }
0131:
0132: if (dataset.getDataSourceExpression().indexOf(oldString) >= 0) {
0133: dataset.setDataSourceExpression(Misc.string_replace(
0134: newString, oldString, dataset
0135: .getDataSourceExpression()));
0136: add = true;
0137: }
0138:
0139: if (dataset.getParametersMapExpression().indexOf(oldString) >= 0) {
0140: dataset.setParametersMapExpression(Misc.string_replace(
0141: newString, oldString, dataset
0142: .getParametersMapExpression()));
0143: add = true;
0144: }
0145:
0146: for (int k = 0; k < dataset.getSubreportParameters().size(); ++k) {
0147: JRSubreportParameter para = (JRSubreportParameter) dataset
0148: .getSubreportParameters().get(k);
0149: if (para.getExpression().indexOf(oldString) >= 0) {
0150: para.setExpression(Misc.string_replace(newString,
0151: oldString, para.getExpression()));
0152: add = true;
0153: }
0154: }
0155: return add;
0156: }
0157:
0158: /**
0159: * Update all the strings related to the dataset.
0160: * If the dataset is a plain dataset (not a chart dataset), the only think checked is the IncrementWhenExpression
0161: *
0162: */
0163: public static boolean updateDatasetExpressions(Dataset dataset,
0164: String oldString, String newString) {
0165: boolean add = false;
0166: if (dataset == null)
0167: return false;
0168:
0169: if (dataset.getIncrementWhenExpression().indexOf(oldString) >= 0) {
0170: dataset.setIncrementWhenExpression(Misc.string_replace(
0171: newString, oldString, dataset
0172: .getIncrementWhenExpression()));
0173: add = true;
0174: }
0175:
0176: if (dataset instanceof PieDataset) {
0177: PieDataset ds = (PieDataset) dataset;
0178:
0179: if (ds.getKeyExpression().indexOf(oldString) >= 0) {
0180: ds.setKeyExpression(Misc.string_replace(newString,
0181: oldString, ds.getKeyExpression()));
0182: add = true;
0183: }
0184:
0185: if (ds.getLabelExpression().indexOf(oldString) >= 0) {
0186: ds.setLabelExpression(Misc.string_replace(newString,
0187: oldString, ds.getLabelExpression()));
0188: add = true;
0189: }
0190:
0191: if (ds.getValueExpression().indexOf(oldString) >= 0) {
0192: ds.setValueExpression(Misc.string_replace(newString,
0193: oldString, ds.getValueExpression()));
0194: add = true;
0195: }
0196:
0197: if (updateSectionHyperLink(ds.getSectionHyperLink(),
0198: oldString, newString)) {
0199: add = true;
0200: }
0201:
0202: } else if (dataset instanceof CategoryDataset) {
0203: CategoryDataset ds = (CategoryDataset) dataset;
0204:
0205: for (int k = 0; k < ds.getCategorySeries().size(); ++k) {
0206: CategorySeries series = (CategorySeries) ds
0207: .getCategorySeries().get(k);
0208: if (updateSectionHyperLink(series
0209: .getSectionItemHyperlink(), oldString,
0210: newString)) {
0211: add = true;
0212: }
0213:
0214: if (series.getCategoryExpression().indexOf(oldString) >= 0) {
0215: series.setCategoryExpression(Misc.string_replace(
0216: newString, oldString, series
0217: .getCategoryExpression()));
0218: add = true;
0219: }
0220:
0221: if (series.getLabelExpression().indexOf(oldString) >= 0) {
0222: series.setLabelExpression(Misc.string_replace(
0223: newString, oldString, series
0224: .getLabelExpression()));
0225: add = true;
0226: }
0227:
0228: if (series.getSeriesExpression().indexOf(oldString) >= 0) {
0229: series.setSeriesExpression(Misc.string_replace(
0230: newString, oldString, series
0231: .getSeriesExpression()));
0232: add = true;
0233: }
0234:
0235: if (series.getValueExpression().indexOf(oldString) >= 0) {
0236: series.setValueExpression(Misc.string_replace(
0237: newString, oldString, series
0238: .getValueExpression()));
0239: add = true;
0240: }
0241:
0242: }
0243: } else if (dataset instanceof HighLowDataset) {
0244: HighLowDataset ds = (HighLowDataset) dataset;
0245:
0246: if (updateSectionHyperLink(ds.getItemHyperLink(),
0247: oldString, newString)) {
0248: add = true;
0249: }
0250:
0251: if (ds.getCloseExpression().indexOf(oldString) >= 0) {
0252: ds.setCloseExpression(Misc.string_replace(newString,
0253: oldString, ds.getCloseExpression()));
0254: add = true;
0255: }
0256:
0257: if (ds.getDateExpression().indexOf(oldString) >= 0) {
0258: ds.setDateExpression(Misc.string_replace(newString,
0259: oldString, ds.getDateExpression()));
0260: add = true;
0261: }
0262:
0263: if (ds.getHighExpression().indexOf(oldString) >= 0) {
0264: ds.setHighExpression(Misc.string_replace(newString,
0265: oldString, ds.getHighExpression()));
0266: add = true;
0267: }
0268:
0269: if (ds.getLowExpression().indexOf(oldString) >= 0) {
0270: ds.setLowExpression(Misc.string_replace(newString,
0271: oldString, ds.getLowExpression()));
0272: add = true;
0273: }
0274:
0275: if (ds.getOpenExpression().indexOf(oldString) >= 0) {
0276: ds.setOpenExpression(Misc.string_replace(newString,
0277: oldString, ds.getOpenExpression()));
0278: add = true;
0279: }
0280:
0281: } else if (dataset instanceof TimePeriodDataset) {
0282: TimePeriodDataset ds = (TimePeriodDataset) dataset;
0283:
0284: for (int k = 0; k < ds.getTimePeriodSeries().size(); ++k) {
0285: TimePeriodSeries series = (TimePeriodSeries) ds
0286: .getTimePeriodSeries().get(k);
0287: if (updateSectionHyperLink(series
0288: .getSectionItemHyperlink(), oldString,
0289: newString)) {
0290: add = true;
0291: }
0292:
0293: if (series.getEndDateExpression().indexOf(oldString) >= 0) {
0294: series.setEndDateExpression(Misc.string_replace(
0295: newString, oldString, series
0296: .getEndDateExpression()));
0297: add = true;
0298: }
0299:
0300: if (series.getLabelExpression().indexOf(oldString) >= 0) {
0301: series.setLabelExpression(Misc.string_replace(
0302: newString, oldString, series
0303: .getLabelExpression()));
0304: add = true;
0305: }
0306:
0307: if (series.getSeriesExpression().indexOf(oldString) >= 0) {
0308: series.setSeriesExpression(Misc.string_replace(
0309: newString, oldString, series
0310: .getSeriesExpression()));
0311: add = true;
0312: }
0313:
0314: if (series.getStartDateExpression().indexOf(oldString) >= 0) {
0315: series.setStartDateExpression(Misc.string_replace(
0316: newString, oldString, series
0317: .getStartDateExpression()));
0318: add = true;
0319: }
0320:
0321: if (series.getValueExpression().indexOf(oldString) >= 0) {
0322: series.setValueExpression(Misc.string_replace(
0323: newString, oldString, series
0324: .getValueExpression()));
0325: add = true;
0326: }
0327:
0328: }
0329: } else if (dataset instanceof TimeSeriesDataset) {
0330: TimeSeriesDataset ds = (TimeSeriesDataset) dataset;
0331:
0332: for (int k = 0; k < ds.getTimeSeries().size(); ++k) {
0333: TimeSeries series = (TimeSeries) ds.getTimeSeries()
0334: .get(k);
0335: if (updateSectionHyperLink(series
0336: .getSectionItemHyperlink(), oldString,
0337: newString)) {
0338: add = true;
0339: }
0340:
0341: if (series.getTimePeriodExpression().indexOf(oldString) >= 0) {
0342: series.setTimePeriodExpression(Misc.string_replace(
0343: newString, oldString, series
0344: .getTimePeriodExpression()));
0345: add = true;
0346: }
0347:
0348: if (series.getLabelExpression().indexOf(oldString) >= 0) {
0349: series.setLabelExpression(Misc.string_replace(
0350: newString, oldString, series
0351: .getLabelExpression()));
0352: add = true;
0353: }
0354:
0355: if (series.getSeriesExpression().indexOf(oldString) >= 0) {
0356: series.setSeriesExpression(Misc.string_replace(
0357: newString, oldString, series
0358: .getSeriesExpression()));
0359: add = true;
0360: }
0361:
0362: if (series.getValueExpression().indexOf(oldString) >= 0) {
0363: series.setValueExpression(Misc.string_replace(
0364: newString, oldString, series
0365: .getValueExpression()));
0366: add = true;
0367: }
0368:
0369: }
0370: } else if (dataset instanceof ValueDataset) {
0371: ValueDataset ds = (ValueDataset) dataset;
0372: if (ds.getValueExpression().indexOf(oldString) >= 0) {
0373: ds.setValueExpression(Misc.string_replace(newString,
0374: oldString, ds.getValueExpression()));
0375: add = true;
0376: }
0377: } else if (dataset instanceof XYDataset) {
0378: XYDataset ds = (XYDataset) dataset;
0379:
0380: for (int k = 0; k < ds.getXYSeries().size(); ++k) {
0381: XYSeries series = (XYSeries) ds.getXYSeries().get(k);
0382:
0383: if (updateSectionHyperLink(series
0384: .getSectionItemHyperlink(), oldString,
0385: newString)) {
0386: add = true;
0387: }
0388:
0389: if (series.getLabelExpression().indexOf(oldString) >= 0) {
0390: series.setLabelExpression(Misc.string_replace(
0391: newString, oldString, series
0392: .getLabelExpression()));
0393: add = true;
0394: }
0395:
0396: if (series.getSeriesExpression().indexOf(oldString) >= 0) {
0397: series.setSeriesExpression(Misc.string_replace(
0398: newString, oldString, series
0399: .getSeriesExpression()));
0400: add = true;
0401: }
0402:
0403: if (series.getXValueExpression().indexOf(oldString) >= 0) {
0404: series.setXValueExpression(Misc.string_replace(
0405: newString, oldString, series
0406: .getXValueExpression()));
0407: add = true;
0408: }
0409:
0410: if (series.getYValueExpression().indexOf(oldString) >= 0) {
0411: series.setYValueExpression(Misc.string_replace(
0412: newString, oldString, series
0413: .getYValueExpression()));
0414: add = true;
0415: }
0416:
0417: }
0418: } else if (dataset instanceof XYZDataset) {
0419: XYZDataset ds = (XYZDataset) dataset;
0420:
0421: for (int k = 0; k < ds.getXYZSeries().size(); ++k) {
0422: XYZSeries series = (XYZSeries) ds.getXYZSeries().get(k);
0423:
0424: if (updateSectionHyperLink(series
0425: .getSectionItemHyperlink(), oldString,
0426: newString)) {
0427: add = true;
0428: }
0429:
0430: if (series.getSeriesExpression().indexOf(oldString) >= 0) {
0431: series.setSeriesExpression(Misc.string_replace(
0432: newString, oldString, series
0433: .getSeriesExpression()));
0434: add = true;
0435: }
0436:
0437: if (series.getXValueExpression().indexOf(oldString) >= 0) {
0438: series.setXValueExpression(Misc.string_replace(
0439: newString, oldString, series
0440: .getXValueExpression()));
0441: add = true;
0442: }
0443:
0444: if (series.getYValueExpression().indexOf(oldString) >= 0) {
0445: series.setYValueExpression(Misc.string_replace(
0446: newString, oldString, series
0447: .getYValueExpression()));
0448: add = true;
0449: }
0450:
0451: if (series.getZValueExpression().indexOf(oldString) >= 0) {
0452: series.setZValueExpression(Misc.string_replace(
0453: newString, oldString, series
0454: .getZValueExpression()));
0455: add = true;
0456: }
0457:
0458: }
0459: }
0460:
0461: return add;
0462: }
0463:
0464: /**
0465: * Replace oldString with newString in all the expressions related to the gived subDataset...
0466: * The method can fire required events
0467: *
0468: * Checks for:
0469: *
0470: * - Filter expression
0471: * - Query
0472: * - variables (initial expression and expression)
0473: * - group expressions
0474: *
0475: * If Report instance:
0476: *
0477: * - band print when
0478: * - elements PrintWhenExpression
0479: * - TextFieldReportElement expression
0480: * - ImageReportElement imageExpression
0481: * - SubReportElement connection, subreportExpression, parametersExpressions, returnValue variable names
0482: * - Hyperlinks (anchor, parameters, etc...)
0483: * - Crosstab parameters...
0484: * - Crosstab and Chart datasetRun
0485: *
0486: * TODO:
0487: * - SortFields...
0488: * - Visit all the chart expressions checking the used datasource
0489: * - Explore sub-elements
0490: * - change the class for textfields (if possible)
0491: *
0492: * It throws an event is an element is changed...
0493: *
0494: */
0495: public static void replaceInReportExpressions(String oldString,
0496: String newString, SubDataset subDataset,
0497: Report referenceReport) {
0498: Report report = null;
0499: if (subDataset instanceof Report) {
0500: report = (Report) subDataset;
0501: }
0502:
0503: if (subDataset.getFilterExpression() != null
0504: && subDataset.getFilterExpression().indexOf(oldString) >= 0) {
0505: subDataset.setFilterExpression(Misc.string_replace(
0506: newString, oldString, subDataset
0507: .getFilterExpression()));
0508: if (report != null)
0509: report.incrementReportChanges();
0510: }
0511:
0512: if (subDataset.getQuery() != null
0513: && subDataset.getQuery().indexOf(oldString) >= 0) {
0514: subDataset.setQuery(Misc.string_replace(newString,
0515: oldString, subDataset.getQuery()));
0516: subDataset
0517: .fireSubDatasetObjectChangedListenerSubDatasetObjectChanged(new SubDatasetObjectChangedEvent(
0518: subDataset,
0519: SubDatasetObjectChangedEvent.QUERY,
0520: SubDatasetObjectChangedEvent.MODIFIED,
0521: subDataset.getQuery(), subDataset
0522: .getQuery()));
0523: }
0524:
0525: for (int i = 0; i < subDataset.getVariables().size(); ++i) {
0526: JRVariable var = (JRVariable) subDataset.getVariables()
0527: .get(i);
0528: boolean fireEvent = false;
0529: if (var.getInitialValueExpression().indexOf(oldString) >= 0) {
0530: var.setInitialValueExpression(Misc.string_replace(
0531: newString, oldString, var
0532: .getInitialValueExpression()));
0533: // alert
0534: fireEvent = true;
0535: }
0536:
0537: if (var.getExpression().indexOf(oldString) >= 0) {
0538: var.setExpression(Misc.string_replace(newString,
0539: oldString, var.getExpression()));
0540: // alert
0541: fireEvent = true;
0542: }
0543:
0544: if (fireEvent) {
0545: subDataset
0546: .fireSubDatasetObjectChangedListenerSubDatasetObjectChanged(new SubDatasetObjectChangedEvent(
0547: subDataset,
0548: SubDatasetObjectChangedEvent.VARIABLE,
0549: SubDatasetObjectChangedEvent.MODIFIED,
0550: var, var));
0551: }
0552: }
0553:
0554: for (int i = 0; i < subDataset.getGroups().size(); ++i) {
0555: Group grp = (Group) subDataset.getGroups().get(i);
0556: if (grp.getGroupExpression().indexOf(oldString) >= 0) {
0557: grp.setGroupExpression(Misc.string_replace(newString,
0558: oldString, grp.getGroupExpression()));
0559: }
0560: }
0561:
0562: Vector changedElements = new Vector();
0563:
0564: if (subDataset instanceof Report) {
0565: Report rep = (Report) subDataset;
0566:
0567: for (int i = 0; i < rep.getBands().size(); ++i) {
0568: Band band = (Band) rep.getBands().get(i);
0569: if (band.getPrintWhenExpression().indexOf(oldString) >= 0) {
0570: band.setPrintWhenExpression(Misc.string_replace(
0571: newString, oldString, band
0572: .getPrintWhenExpression()));
0573: }
0574: }
0575:
0576: // Modify elements...
0577:
0578: for (int i = 0; i < rep.getElements().size(); ++i) {
0579: boolean add = false;
0580: ReportElement re = (ReportElement) rep.getElements()
0581: .get(i);
0582: if (re.getPrintWhenExpression().indexOf(oldString) >= 0) {
0583: re.setPrintWhenExpression(Misc.string_replace(
0584: newString, oldString, re
0585: .getPrintWhenExpression()));
0586: add = true;
0587: }
0588:
0589: if (re instanceof TextFieldReportElement) {
0590: TextFieldReportElement tre = (TextFieldReportElement) re;
0591: if (tre.getText().indexOf(oldString) >= 0) {
0592: tre.setText(Misc.string_replace(newString,
0593: oldString, tre.getText()));
0594: add = true;
0595: }
0596: }
0597:
0598: if (re instanceof ImageReportElement) {
0599: ImageReportElement tre = (ImageReportElement) re;
0600: if (tre.getImageExpression().indexOf(oldString) >= 0) {
0601: tre.setImageExpression(Misc.string_replace(
0602: newString, oldString, tre
0603: .getImageExpression()));
0604: add = true;
0605: }
0606: }
0607:
0608: if (re instanceof SubReportElement) {
0609: SubReportElement tre = (SubReportElement) re;
0610: if (tre.getSubreportExpression().indexOf(oldString) >= 0) {
0611: tre.setSubreportExpression(Misc.string_replace(
0612: newString, oldString, tre
0613: .getSubreportExpression()));
0614: add = true;
0615: }
0616:
0617: if (tre.getParametersMapExpression().indexOf(
0618: oldString) >= 0) {
0619: tre
0620: .setParametersMapExpression(Misc
0621: .string_replace(
0622: newString,
0623: oldString,
0624: tre
0625: .getParametersMapExpression()));
0626: add = true;
0627: }
0628:
0629: if (tre.getDataSourceExpression()
0630: .indexOf(oldString) >= 0) {
0631: tre.setDataSourceExpression(Misc
0632: .string_replace(newString, oldString,
0633: tre.getDataSourceExpression()));
0634: add = true;
0635: }
0636:
0637: if (tre.getConnectionExpression()
0638: .indexOf(oldString) >= 0) {
0639: tre.setConnectionExpression(Misc
0640: .string_replace(newString, oldString,
0641: tre.getConnectionExpression()));
0642: add = true;
0643: }
0644:
0645: for (int k = 0; k < tre.getSubreportParameters()
0646: .size(); ++k) {
0647: JRSubreportParameter para = (JRSubreportParameter) tre
0648: .getSubreportParameters().get(k);
0649: if (para.getExpression().indexOf(oldString) >= 0) {
0650: para.setExpression(Misc.string_replace(
0651: newString, oldString, para
0652: .getExpression()));
0653: add = true;
0654: }
0655: }
0656:
0657: for (int k = 0; k < tre.getReturnValues().size(); ++k) {
0658: JRSubreportReturnValue para = (JRSubreportReturnValue) tre
0659: .getReturnValues().get(k);
0660: if (oldString.equals("$V{"
0661: + para.getToVariable() + "}")) {
0662: String nv = newString.substring(3,
0663: newString.length() - 1);
0664: para.setToVariable(nv);
0665: add = true;
0666: }
0667: }
0668: }
0669:
0670: if (re instanceof HyperLinkableReportElement) {
0671: HyperLinkableReportElement tre = (HyperLinkableReportElement) re;
0672: if (tre.getAnchorNameExpression()
0673: .indexOf(oldString) >= 0) {
0674: tre.setAnchorNameExpression(Misc
0675: .string_replace(newString, oldString,
0676: tre.getAnchorNameExpression()));
0677: add = true;
0678: }
0679: if (tre.getHyperlinkAnchorExpression().indexOf(
0680: oldString) >= 0) {
0681: tre
0682: .setHyperlinkAnchorExpression(Misc
0683: .string_replace(
0684: newString,
0685: oldString,
0686: tre
0687: .getHyperlinkAnchorExpression()));
0688: add = true;
0689: }
0690: if (tre.getHyperlinkPageExpression().indexOf(
0691: oldString) >= 0) {
0692: tre
0693: .setHyperlinkPageExpression(Misc
0694: .string_replace(
0695: newString,
0696: oldString,
0697: tre
0698: .getHyperlinkPageExpression()));
0699: add = true;
0700: }
0701: if (tre.getHyperlinkReferenceExpression().indexOf(
0702: oldString) >= 0) {
0703: tre
0704: .setHyperlinkReferenceExpression(Misc
0705: .string_replace(
0706: newString,
0707: oldString,
0708: tre
0709: .getHyperlinkReferenceExpression()));
0710: add = true;
0711: }
0712: for (int k = 0; k < tre.getLinkParameters().size(); ++k) {
0713: JRLinkParameter para = (JRLinkParameter) tre
0714: .getLinkParameters().get(k);
0715: if (para.getExpression().indexOf(oldString) >= 0) {
0716: para.setExpression(Misc.string_replace(
0717: newString, oldString, para
0718: .getExpression()));
0719: add = true;
0720: }
0721: }
0722: }
0723:
0724: if (re instanceof CrosstabReportElement) {
0725: CrosstabReportElement tre = (CrosstabReportElement) re;
0726:
0727: for (int k = 0; k < tre.getCrosstabParameters()
0728: .size(); ++k) {
0729: CrosstabParameter para = (CrosstabParameter) tre
0730: .getCrosstabParameters().get(k);
0731: if (para.getParameterValueExpression().indexOf(
0732: oldString) >= 0) {
0733: para
0734: .setParameterValueExpression(Misc
0735: .string_replace(
0736: newString,
0737: oldString,
0738: para
0739: .getParameterValueExpression()));
0740: add = true;
0741: }
0742: }
0743:
0744: if (updateDatasetRunExpressions(tre.getDataset(),
0745: oldString, newString)) {
0746: add = true;
0747: }
0748:
0749: // if the crosstab uses the main report datasource... update all the other expressions too...
0750: if (!tre.isUseDataset()
0751: || tre.getDataset().getSubDataset() == null) {
0752: if (updateDatasetCrosstabExpressions(tre,
0753: oldString, newString)) {
0754: add = true;
0755: }
0756: }
0757: }
0758:
0759: if (re instanceof ChartReportElement2) {
0760: // Check in the sundat
0761: ChartReportElement2 tre = (ChartReportElement2) re;
0762:
0763: if (updateDatasetRunExpressions(tre.getChart()
0764: .getDataset(), oldString, newString)) {
0765: add = true;
0766: }
0767:
0768: if (tre.getChart().getDataset().getSubDataset() == null) {
0769: // update the dataset run and the chart dataset if we the chart element is the same as the element we are modifying
0770: if (updateDatasetExpressions(tre.getChart()
0771: .getDataset(), oldString, newString)) {
0772: add = true;
0773: }
0774: }
0775: }
0776:
0777: if (add) {
0778: changedElements.add(re);
0779: }
0780: }
0781:
0782: } else {
0783: if (referenceReport != null) {
0784: // check for crosstabs or charts that refers to this dataset...
0785: for (int i = 0; i < referenceReport.getElements()
0786: .size(); ++i) {
0787: boolean add = false;
0788: ReportElement re = (ReportElement) referenceReport
0789: .getElements().get(i);
0790:
0791: if (re instanceof CrosstabReportElement) {
0792: CrosstabReportElement tre = (CrosstabReportElement) re;
0793: if (tre.isUseDataset()
0794: && tre.getDataset().getSubDataset() == subDataset) {
0795: if (updateDatasetCrosstabExpressions(tre,
0796: oldString, newString)) {
0797: add = true;
0798: }
0799: }
0800: } else if (re instanceof ChartReportElement2) {
0801: // Check in the sundat
0802: ChartReportElement2 tre = (ChartReportElement2) re;
0803:
0804: System.out
0805: .println("Checking this chart element...");
0806: if (tre.getChart().getDataset().getSubDataset() == subDataset) {
0807: // update the dataset run and the chart dataset if we the chart element is the same as the element we are modifying
0808: if (updateDatasetExpressions(tre.getChart()
0809: .getDataset(), oldString, newString)) {
0810: add = true;
0811: }
0812: }
0813: }
0814:
0815: if (add) {
0816: changedElements.add(re);
0817: }
0818:
0819: }
0820:
0821: }
0822: }
0823:
0824: if (referenceReport != null && changedElements.size() > 0) {
0825: CrosstabReportElement cre = (referenceReport
0826: .getReportFrame().getSelectedCrosstabEditorPanel() != null) ? referenceReport
0827: .getReportFrame().getSelectedCrosstabEditorPanel()
0828: .getCrosstabElement()
0829: : null;
0830: referenceReport.getReportFrame()
0831: .fireReportListenerReportElementsChanged(
0832: new ReportElementChangedEvent(
0833: referenceReport.getReportFrame(),
0834: cre, changedElements,
0835: ReportElementChangedEvent.CHANGED));
0836:
0837: referenceReport.getReportFrame().repaint();
0838: MainFrame.getMainInstance().getElementPropertiesDialog()
0839: .updateSelection();
0840: }
0841:
0842: }
0843:
0844: /**
0845: * Replace the strings in an SectionItemHyperlink
0846: */
0847: private static boolean updateSectionHyperLink(
0848: SectionItemHyperlink tre, String oldString, String newString) {
0849:
0850: boolean add = false;
0851: if (tre.getHyperlinkAnchorExpression().indexOf(oldString) >= 0) {
0852: tre.setHyperlinkAnchorExpression(Misc.string_replace(
0853: newString, oldString, tre
0854: .getHyperlinkAnchorExpression()));
0855: add = true;
0856: }
0857: if (tre.getHyperlinkPageExpression().indexOf(oldString) >= 0) {
0858: tre.setHyperlinkPageExpression(Misc.string_replace(
0859: newString, oldString, tre
0860: .getHyperlinkPageExpression()));
0861: add = true;
0862: }
0863: if (tre.getHyperlinkReferenceExpression().indexOf(oldString) >= 0) {
0864: tre.setHyperlinkReferenceExpression(Misc.string_replace(
0865: newString, oldString, tre
0866: .getHyperlinkReferenceExpression()));
0867: add = true;
0868: }
0869: for (int k = 0; k < tre.getHyperlinkParameters().size(); ++k) {
0870: JRLinkParameter para = (JRLinkParameter) tre
0871: .getHyperlinkParameters().get(k);
0872: if (para.getExpression().indexOf(oldString) >= 0) {
0873: para.setExpression(Misc.string_replace(newString,
0874: oldString, para.getExpression()));
0875: add = true;
0876: }
0877: }
0878:
0879: return add;
0880: }
0881:
0882: /**
0883: * This method update all the expressions that refers to the params/vars/field of the dataset tied to the crosstab.
0884: * This method should be used when something changes in the crosstab dataset. Please note that a crosstab dataset
0885: * can be a subdataset or the report itself.
0886: *
0887: */
0888: private static boolean updateDatasetCrosstabExpressions(
0889: CrosstabReportElement tre, String oldString,
0890: String newString) {
0891:
0892: // Check into the crosstab
0893: boolean add = false;
0894:
0895: if (updateDatasetExpressions(tre.getDataset(), oldString,
0896: newString)) {
0897: add = true;
0898: }
0899:
0900: for (int i = 0; i < tre.getColumnGroups().size(); ++i) {
0901: CrosstabGroup grp = (CrosstabGroup) tre.getColumnGroups()
0902: .get(i);
0903: if (grp.getBucketExpression().indexOf(oldString) >= 0) {
0904: grp.setBucketExpression(Misc.string_replace(newString,
0905: oldString, grp.getBucketExpression()));
0906: add = true;
0907: }
0908: }
0909:
0910: for (int i = 0; i < tre.getRowGroups().size(); ++i) {
0911: CrosstabGroup grp = (CrosstabGroup) tre.getRowGroups().get(
0912: i);
0913: if (grp.getBucketExpression().indexOf(oldString) >= 0) {
0914: grp.setBucketExpression(Misc.string_replace(newString,
0915: oldString, grp.getBucketExpression()));
0916: add = true;
0917: }
0918: }
0919:
0920: return add;
0921: }
0922:
0923: /**
0924: * This method update all the expressions that refers to the params/vars/field of the dataset tied to the chart.
0925: * This method should be used when something changes in the chart dataset. Please note that a chart dataset
0926: * can be a subdataset or the report itself.
0927: *
0928: * Walk trought all the chart expressions....
0929: * Returns true if at least one expression is changed....
0930: *
0931: * chartElement hyperlink is not updated here (since it uses report dataset as all the other elements, infacts a
0932: * chartElement is automatically treated as HyperLinkableReportElement in replaceInReportExpressions)
0933: *
0934: */
0935: private static boolean updateDatasetChartExpressions(
0936: ChartReportElement2 tre, String oldString, String newString) {
0937:
0938: // Check into the crosstab
0939: boolean add = false;
0940:
0941: if (updateDatasetExpressions(tre.getChart().getDataset(),
0942: oldString, newString)) {
0943: add = true;
0944: }
0945:
0946: Chart chart = tre.getChart();
0947: // hyperlink expressions ignoerd (they are already been checked.
0948: Plot plot = chart.getPlot();
0949:
0950: if (chart.getTitle().getTitleExpression().indexOf(oldString) >= 0) {
0951: chart.getTitle().setTitleExpression(
0952: Misc.string_replace(newString, oldString, chart
0953: .getTitle().getTitleExpression()));
0954: add = true;
0955: }
0956:
0957: if (chart.getSubTitle().getTitleExpression().indexOf(oldString) >= 0) {
0958: chart.getSubTitle().setTitleExpression(
0959: Misc.string_replace(newString, oldString, chart
0960: .getSubTitle().getTitleExpression()));
0961: add = true;
0962: }
0963:
0964: // Let's check inside Plot...
0965: if (chart.getPlot() instanceof AreaPlot) {
0966: AreaPlot pl = (AreaPlot) chart.getPlot();
0967:
0968: if (pl.getCategoryAxisLabelExpression().indexOf(oldString) >= 0) {
0969: pl.setCategoryAxisLabelExpression(Misc.string_replace(
0970: newString, oldString, pl
0971: .getCategoryAxisLabelExpression()));
0972: add = true;
0973: }
0974:
0975: if (pl.getValueAxisLabelExpression().indexOf(oldString) >= 0) {
0976: pl.setValueAxisLabelExpression(Misc.string_replace(
0977: newString, oldString, pl
0978: .getValueAxisLabelExpression()));
0979: add = true;
0980: }
0981: }
0982: if (chart.getPlot() instanceof Bar3DPlot) {
0983: Bar3DPlot pl = (Bar3DPlot) chart.getPlot();
0984: if (pl.getCategoryAxisLabelExpression().indexOf(oldString) >= 0) {
0985: pl.setCategoryAxisLabelExpression(Misc.string_replace(
0986: newString, oldString, pl
0987: .getCategoryAxisLabelExpression()));
0988: add = true;
0989: }
0990:
0991: if (pl.getValueAxisLabelExpression().indexOf(oldString) >= 0) {
0992: pl.setValueAxisLabelExpression(Misc.string_replace(
0993: newString, oldString, pl
0994: .getValueAxisLabelExpression()));
0995: add = true;
0996: }
0997: }
0998: if (chart.getPlot() instanceof BarPlot) {
0999: BarPlot pl = (BarPlot) chart.getPlot();
1000: if (pl.getCategoryAxisLabelExpression().indexOf(oldString) >= 0) {
1001: pl.setCategoryAxisLabelExpression(Misc.string_replace(
1002: newString, oldString, pl
1003: .getCategoryAxisLabelExpression()));
1004: add = true;
1005: }
1006:
1007: if (pl.getValueAxisLabelExpression().indexOf(oldString) >= 0) {
1008: pl.setValueAxisLabelExpression(Misc.string_replace(
1009: newString, oldString, pl
1010: .getValueAxisLabelExpression()));
1011: add = true;
1012: }
1013: }
1014: if (chart.getPlot() instanceof BubblePlot) {
1015: BubblePlot pl = (BubblePlot) chart.getPlot();
1016:
1017: if (pl.getXAxisLabelExpression().indexOf(oldString) >= 0) {
1018: pl.setXAxisLabelExpression(Misc.string_replace(
1019: newString, oldString, pl
1020: .getXAxisLabelExpression()));
1021: add = true;
1022: }
1023:
1024: if (pl.getYAxisLabelExpression().indexOf(oldString) >= 0) {
1025: pl.setYAxisLabelExpression(Misc.string_replace(
1026: newString, oldString, pl
1027: .getYAxisLabelExpression()));
1028: add = true;
1029: }
1030: }
1031: if (chart.getPlot() instanceof CandlestickPlot) {
1032: CandlestickPlot pl = (CandlestickPlot) chart.getPlot();
1033:
1034: if (pl.getTimeAxisLabelExpression().indexOf(oldString) >= 0) {
1035: pl.setTimeAxisLabelExpression(Misc.string_replace(
1036: newString, oldString, pl
1037: .getTimeAxisLabelExpression()));
1038: add = true;
1039: }
1040:
1041: if (pl.getValueAxisLabelExpression().indexOf(oldString) >= 0) {
1042: pl.setValueAxisLabelExpression(Misc.string_replace(
1043: newString, oldString, pl
1044: .getValueAxisLabelExpression()));
1045: add = true;
1046: }
1047: }
1048: if (chart.getPlot() instanceof HighLowPlot) {
1049: HighLowPlot pl = (HighLowPlot) chart.getPlot();
1050: if (pl.getTimeAxisLabelExpression().indexOf(oldString) >= 0) {
1051: pl.setTimeAxisLabelExpression(Misc.string_replace(
1052: newString, oldString, pl
1053: .getTimeAxisLabelExpression()));
1054: add = true;
1055: }
1056:
1057: if (pl.getValueAxisLabelExpression().indexOf(oldString) >= 0) {
1058: pl.setValueAxisLabelExpression(Misc.string_replace(
1059: newString, oldString, pl
1060: .getValueAxisLabelExpression()));
1061: add = true;
1062: }
1063: }
1064: if (chart.getPlot() instanceof LinePlot) {
1065: LinePlot pl = (LinePlot) chart.getPlot();
1066: if (pl.getCategoryAxisLabelExpression().indexOf(oldString) >= 0) {
1067: pl.setCategoryAxisLabelExpression(Misc.string_replace(
1068: newString, oldString, pl
1069: .getCategoryAxisLabelExpression()));
1070: add = true;
1071: }
1072:
1073: if (pl.getValueAxisLabelExpression().indexOf(oldString) >= 0) {
1074: pl.setValueAxisLabelExpression(Misc.string_replace(
1075: newString, oldString, pl
1076: .getValueAxisLabelExpression()));
1077: add = true;
1078: }
1079: }
1080: if (chart.getPlot() instanceof MeterPlot) {
1081: MeterPlot pl = (MeterPlot) chart.getPlot();
1082:
1083: if (pl.getDataRange().getHighExpression()
1084: .indexOf(oldString) >= 0) {
1085: pl.getDataRange().setHighExpression(
1086: Misc.string_replace(newString, oldString, pl
1087: .getDataRange().getHighExpression()));
1088: add = true;
1089: }
1090:
1091: if (pl.getDataRange().getLowExpression().indexOf(oldString) >= 0) {
1092: pl.getDataRange().setLowExpression(
1093: Misc.string_replace(newString, oldString, pl
1094: .getDataRange().getLowExpression()));
1095: add = true;
1096: }
1097:
1098: for (int k = 0; k < pl.getMeterIntervals().size(); ++k) {
1099: MeterInterval mi = (MeterInterval) pl
1100: .getMeterIntervals().get(k);
1101:
1102: if (mi.getDataRange().getHighExpression().indexOf(
1103: oldString) >= 0) {
1104: mi.getDataRange().setHighExpression(
1105: Misc.string_replace(newString, oldString,
1106: pl.getDataRange()
1107: .getHighExpression()));
1108: add = true;
1109: }
1110:
1111: if (mi.getDataRange().getLowExpression().indexOf(
1112: oldString) >= 0) {
1113: mi.getDataRange().setLowExpression(
1114: Misc.string_replace(newString, oldString,
1115: pl.getDataRange()
1116: .getLowExpression()));
1117: add = true;
1118: }
1119: }
1120:
1121: }
1122: if (chart.getPlot() instanceof MultiAxisPlot) {
1123: MultiAxisPlot pl = (MultiAxisPlot) chart.getPlot();
1124: for (int k = 0; k < pl.getAxis().size(); ++k) {
1125: Axis ax = (Axis) pl.getAxis().get(k);
1126: if (ax.getChartReportElement().getChart().getDataset() == chart
1127: .getDataset()) {
1128: if (updateDatasetChartExpressions(ax
1129: .getChartReportElement(), oldString,
1130: newString)) {
1131: add = true;
1132: }
1133: }
1134: }
1135: }
1136: if (chart.getPlot() instanceof Pie3DPlot) {
1137: Pie3DPlot pl = (Pie3DPlot) chart.getPlot();
1138: // Nothing to do
1139: }
1140: if (chart.getPlot() instanceof PiePlot) {
1141: PiePlot pl = (PiePlot) chart.getPlot();
1142: // Nothing to do
1143: }
1144: if (chart.getPlot() instanceof ScatterPlot) {
1145: ScatterPlot pl = (ScatterPlot) chart.getPlot();
1146:
1147: if (pl.getXAxisLabelExpression().indexOf(oldString) >= 0) {
1148: pl.setXAxisLabelExpression(Misc.string_replace(
1149: newString, oldString, pl
1150: .getXAxisLabelExpression()));
1151: add = true;
1152: }
1153:
1154: if (pl.getYAxisLabelExpression().indexOf(oldString) >= 0) {
1155: pl.setYAxisLabelExpression(Misc.string_replace(
1156: newString, oldString, pl
1157: .getYAxisLabelExpression()));
1158: add = true;
1159: }
1160: }
1161: if (chart.getPlot() instanceof ThermometerPlot) {
1162: ThermometerPlot pl = (ThermometerPlot) chart.getPlot();
1163:
1164: // getDataRange
1165: if (pl.getDataRange().getHighExpression()
1166: .indexOf(oldString) >= 0) {
1167: pl.getDataRange().setHighExpression(
1168: Misc.string_replace(newString, oldString, pl
1169: .getDataRange().getHighExpression()));
1170: add = true;
1171: }
1172:
1173: if (pl.getDataRange().getLowExpression().indexOf(oldString) >= 0) {
1174: pl.getDataRange().setLowExpression(
1175: Misc.string_replace(newString, oldString, pl
1176: .getDataRange().getLowExpression()));
1177: add = true;
1178: }
1179:
1180: // getHighRange
1181: if (pl.getHighRange().getHighExpression()
1182: .indexOf(oldString) >= 0) {
1183: pl.getHighRange().setHighExpression(
1184: Misc.string_replace(newString, oldString, pl
1185: .getHighRange().getHighExpression()));
1186: add = true;
1187: }
1188:
1189: if (pl.getHighRange().getLowExpression().indexOf(oldString) >= 0) {
1190: pl.getHighRange().setLowExpression(
1191: Misc.string_replace(newString, oldString, pl
1192: .getHighRange().getLowExpression()));
1193: add = true;
1194: }
1195:
1196: // getHighRange
1197: if (pl.getLowRange().getHighExpression().indexOf(oldString) >= 0) {
1198: pl.getLowRange().setHighExpression(
1199: Misc.string_replace(newString, oldString, pl
1200: .getLowRange().getHighExpression()));
1201: add = true;
1202: }
1203:
1204: if (pl.getLowRange().getLowExpression().indexOf(oldString) >= 0) {
1205: pl.getLowRange().setLowExpression(
1206: Misc.string_replace(newString, oldString, pl
1207: .getLowRange().getLowExpression()));
1208: add = true;
1209: }
1210:
1211: // getMediumRange
1212: if (pl.getMediumRange().getHighExpression().indexOf(
1213: oldString) >= 0) {
1214: pl.getLowRange().setHighExpression(
1215: Misc.string_replace(newString, oldString, pl
1216: .getMediumRange().getHighExpression()));
1217: add = true;
1218: }
1219:
1220: if (pl.getMediumRange().getLowExpression().indexOf(
1221: oldString) >= 0) {
1222: pl.getLowRange().setLowExpression(
1223: Misc.string_replace(newString, oldString, pl
1224: .getMediumRange().getLowExpression()));
1225: add = true;
1226: }
1227:
1228: }
1229: if (chart.getPlot() instanceof TimeSeriesPlot) {
1230: TimeSeriesPlot pl = (TimeSeriesPlot) chart.getPlot();
1231:
1232: if (pl.getTimeAxisLabelExpression().indexOf(oldString) >= 0) {
1233: pl.setTimeAxisLabelExpression(Misc.string_replace(
1234: newString, oldString, pl
1235: .getTimeAxisLabelExpression()));
1236: add = true;
1237: }
1238:
1239: if (pl.getValueAxisLabelExpression().indexOf(oldString) >= 0) {
1240: pl.setValueAxisLabelExpression(Misc.string_replace(
1241: newString, oldString, pl
1242: .getValueAxisLabelExpression()));
1243: add = true;
1244: }
1245: }
1246:
1247: return add;
1248: }
1249:
1250: }
|