001: /*
002: * Copyright 2006-2007 Pentaho Corporation. All rights reserved.
003: * This software was developed by Pentaho Corporation and is provided under the terms
004: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
005: * this file except in compliance with the license. If you need a copy of the license,
006: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt.
007: *
008: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
009: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
010: * the license for the specific language governing your rights and limitations.
011: *
012: * Additional Contributor(s): Martin Schmid gridvision engineering GmbH
013: */
014: package org.pentaho.reportdesigner.crm.report.model;
015:
016: import org.gjt.xpp.XmlPullNode;
017: import org.jetbrains.annotations.NotNull;
018: import org.jetbrains.annotations.Nullable;
019: import org.pentaho.reportdesigner.crm.report.PropertyKeys;
020: import org.pentaho.reportdesigner.crm.report.model.functions.ExpressionRegistry;
021: import org.pentaho.reportdesigner.crm.report.reportexporter.ReportCreationException;
022: import org.pentaho.reportdesigner.crm.report.reportexporter.ReportVisitor;
023: import org.pentaho.reportdesigner.lib.client.undo.Undo;
024: import org.pentaho.reportdesigner.lib.client.undo.UndoEntry;
025: import org.pentaho.reportdesigner.lib.common.xml.XMLContext;
026: import org.pentaho.reportdesigner.lib.common.xml.XMLWriter;
027:
028: import java.io.IOException;
029: import java.util.ArrayList;
030:
031: /**
032: * User: Martin
033: * Date: 20.10.2005
034: * Time: 16:03:02
035: */
036: public class BandToplevelItemReportElement extends
037: BandToplevelReportElement {
038: @NotNull
039: private RowBandingDefinition rowBandingDefinition;
040:
041: public BandToplevelItemReportElement() {
042: setName("Band" + System.identityHashCode(this ));
043: rowBandingDefinition = new RowBandingDefinition();
044: }
045:
046: @NotNull
047: public RowBandingDefinition getRowBandingDefinition() {
048: return rowBandingDefinition;
049: }
050:
051: public void setRowBandingDefinition(@NotNull
052: final RowBandingDefinition rowBandingDefinition) {
053: final RowBandingDefinition oldRowBandingDefinition = this .rowBandingDefinition;
054: this .rowBandingDefinition = rowBandingDefinition;
055:
056: Undo undo = getUndo();
057: if (undo != null && !undo.isInProgress()) {
058: undo.startTransaction(PropertyKeys.ROW_BANDING_DEFINITION);
059: undo.add(new UndoEntry() {
060: public void undo() {
061: setRowBandingDefinition(oldRowBandingDefinition);
062: }
063:
064: public void redo() {
065: setRowBandingDefinition(rowBandingDefinition);
066: }
067: });
068: undo.endTransaction();
069: }
070:
071: firePropertyChange(PropertyKeys.ROW_BANDING_DEFINITION,
072: oldRowBandingDefinition, rowBandingDefinition);
073:
074: }
075:
076: public void accept(@Nullable
077: Object parent, @NotNull
078: ReportVisitor reportVisitor) throws ReportCreationException {
079: Object newParent = reportVisitor.visit(parent, this );
080:
081: ArrayList<ReportElement> children = new ArrayList<ReportElement>(
082: getChildren());
083: for (ReportElement reportElement : children) {
084: reportElement.accept(newParent, reportVisitor);
085: }
086: }
087:
088: protected void externalizeElements(@NotNull
089: XMLWriter xmlWriter, @NotNull
090: XMLContext xmlContext) throws IOException {
091: super .externalizeElements(xmlWriter, xmlContext);
092:
093: xmlWriter.startElement(PropertyKeys.ROW_BANDING_DEFINITION);
094: rowBandingDefinition.externalizeObject(xmlWriter, xmlContext);
095: xmlWriter.closeElement(PropertyKeys.ROW_BANDING_DEFINITION);
096: }
097:
098: protected void readElement(@NotNull
099: ExpressionRegistry expressions, @NotNull
100: XmlPullNode node, @NotNull
101: XMLContext xmlContext) throws Exception {
102: super .readElement(expressions, node, xmlContext);
103:
104: if (PropertyKeys.ROW_BANDING_DEFINITION.equals(node
105: .getRawName())) {
106: rowBandingDefinition = new RowBandingDefinition();
107: rowBandingDefinition.readObject(node, xmlContext);
108: }
109: }
110: }
|