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.XMLConstants;
026: import org.pentaho.reportdesigner.lib.common.xml.XMLContext;
027: import org.pentaho.reportdesigner.lib.common.xml.XMLUtils;
028: import org.pentaho.reportdesigner.lib.common.xml.XMLWriter;
029:
030: import java.io.IOException;
031: import java.util.ArrayList;
032:
033: /**
034: * User: Martin
035: * Date: 20.10.2005
036: * Time: 16:03:02
037: */
038: public class BandToplevelPageReportElement extends
039: BandToplevelReportElement {
040: private boolean displayOnFirstPage;
041: private boolean displayOnLastPage;
042:
043: public BandToplevelPageReportElement() {
044: setName("Band" + System.identityHashCode(this ));
045: }
046:
047: public boolean isDisplayOnFirstPage() {
048: return displayOnFirstPage;
049: }
050:
051: public void setDisplayOnFirstPage(final boolean displayOnFirstPage) {
052: final boolean oldDisplayOnFirstPage = this .displayOnFirstPage;
053: this .displayOnFirstPage = displayOnFirstPage;
054:
055: Undo undo = getUndo();
056: if (undo != null && !undo.isInProgress()) {
057: undo.startTransaction(PropertyKeys.DISPLAY_ON_FIRST_PAGE);
058: undo.add(new UndoEntry() {
059: public void undo() {
060: setDisplayOnFirstPage(oldDisplayOnFirstPage);
061: }
062:
063: public void redo() {
064: setDisplayOnFirstPage(displayOnFirstPage);
065: }
066: });
067: undo.endTransaction();
068: }
069:
070: firePropertyChange(PropertyKeys.DISPLAY_ON_FIRST_PAGE, Boolean
071: .valueOf(oldDisplayOnFirstPage), Boolean
072: .valueOf(displayOnFirstPage));
073: }
074:
075: public boolean isDisplayOnLastPage() {
076: return displayOnLastPage;
077: }
078:
079: public void setDisplayOnLastPage(final boolean displayOnLastPage) {
080: final boolean oldDisplayOnLastPage = this .displayOnLastPage;
081: this .displayOnLastPage = displayOnLastPage;
082:
083: Undo undo = getUndo();
084: if (undo != null && !undo.isInProgress()) {
085: undo.startTransaction(PropertyKeys.DISPLAY_ON_LAST_PAGE);
086: undo.add(new UndoEntry() {
087: public void undo() {
088: setDisplayOnLastPage(oldDisplayOnLastPage);
089: }
090:
091: public void redo() {
092: setDisplayOnLastPage(displayOnLastPage);
093: }
094: });
095: undo.endTransaction();
096: }
097:
098: firePropertyChange(PropertyKeys.DISPLAY_ON_LAST_PAGE, Boolean
099: .valueOf(oldDisplayOnLastPage), Boolean
100: .valueOf(displayOnLastPage));
101: }
102:
103: public void accept(@Nullable
104: Object parent, @NotNull
105: ReportVisitor reportVisitor) throws ReportCreationException {
106: Object newParent = reportVisitor.visit(parent, this );
107:
108: ArrayList<ReportElement> children = new ArrayList<ReportElement>(
109: getChildren());
110: for (ReportElement reportElement : children) {
111: reportElement.accept(newParent, reportVisitor);
112: }
113: }
114:
115: protected void externalizeElements(@NotNull
116: XMLWriter xmlWriter, @NotNull
117: XMLContext xmlContext) throws IOException {
118: super .externalizeElements(xmlWriter, xmlContext);
119:
120: xmlWriter.writeProperty(PropertyKeys.DISPLAY_ON_FIRST_PAGE,
121: String.valueOf(displayOnFirstPage));
122: xmlWriter.writeProperty(PropertyKeys.DISPLAY_ON_LAST_PAGE,
123: String.valueOf(displayOnLastPage));
124: }
125:
126: protected void readElement(@NotNull
127: ExpressionRegistry expressions, @NotNull
128: XmlPullNode node, @NotNull
129: XMLContext xmlContext) throws Exception {
130: super.readElement(expressions, node, xmlContext);
131:
132: if (XMLConstants.PROPERTY.equals(node.getRawName())
133: && PropertyKeys.DISPLAY_ON_FIRST_PAGE
134: .equals(node
135: .getAttributeValueFromRawName(XMLConstants.NAME))) {
136: displayOnFirstPage = Boolean.parseBoolean(XMLUtils
137: .readProperty(PropertyKeys.DISPLAY_ON_FIRST_PAGE,
138: node));
139: } else if (XMLConstants.PROPERTY.equals(node.getRawName())
140: && PropertyKeys.DISPLAY_ON_LAST_PAGE
141: .equals(node
142: .getAttributeValueFromRawName(XMLConstants.NAME))) {
143: displayOnLastPage = Boolean.parseBoolean(XMLUtils
144: .readProperty(PropertyKeys.DISPLAY_ON_LAST_PAGE,
145: node));
146: }
147: }
148: }
|