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:
032: /**
033: * User: Martin
034: * Date: 27.10.2005
035: * Time: 09:00:29
036: */
037: public class ResourceLabelReportElement extends TextReportElement {
038: @NotNull
039: private String resourceBase;
040: @NotNull
041: private String resourceKey;
042: @NotNull
043: private String nullString;
044:
045: public ResourceLabelReportElement() {
046: resourceBase = "";
047: resourceKey = "resource"
048: + FieldNameFactory.getInstance().getNextFreeNumber(
049: "resourceKey");//NON-NLS;
050: nullString = "";
051: setName("ResourceLabel@" + System.identityHashCode(this ));
052: }
053:
054: @NotNull
055: public String getResourceBase() {
056: return resourceBase;
057: }
058:
059: public void setResourceBase(@NotNull
060: final String resourceBase) {
061: final String oldResourceBase = this .resourceBase;
062: this .resourceBase = resourceBase;
063:
064: Undo undo = getUndo();
065: if (undo != null && !undo.isInProgress()) {
066: undo.startTransaction(PropertyKeys.RESOURCE_BASE);
067: undo.add(new UndoEntry() {
068: public void undo() {
069: setResourceBase(oldResourceBase);
070: }
071:
072: public void redo() {
073: setResourceBase(resourceBase);
074: }
075: });
076: undo.endTransaction();
077: }
078:
079: firePropertyChange(PropertyKeys.RESOURCE_BASE, oldResourceBase,
080: resourceBase);
081: }
082:
083: @NotNull
084: public String getResourceKey() {
085: return resourceKey;
086: }
087:
088: public void setResourceKey(@NotNull
089: final String resourceKey) {
090: final String oldResourceKey = this .resourceKey;
091: this .resourceKey = resourceKey;
092:
093: Undo undo = getUndo();
094: if (undo != null && !undo.isInProgress()) {
095: undo.startTransaction(PropertyKeys.RESOURCE_KEY);
096: undo.add(new UndoEntry() {
097: public void undo() {
098: setResourceKey(oldResourceKey);
099: }
100:
101: public void redo() {
102: setResourceKey(resourceKey);
103: }
104: });
105: undo.endTransaction();
106: }
107:
108: firePropertyChange(PropertyKeys.RESOURCE_KEY, oldResourceKey,
109: resourceKey);
110: }
111:
112: @NotNull
113: public String getNullString() {
114: return nullString;
115: }
116:
117: public void setNullString(@NotNull
118: final String nullString) {
119: //noinspection ConstantConditions
120: if (nullString == null) {
121: throw new IllegalArgumentException(
122: "nullString must not be null");
123: }
124:
125: final String oldNullString = this .nullString;
126: this .nullString = nullString;
127:
128: Undo undo = getUndo();
129: if (undo != null && !undo.isInProgress()) {
130: undo.startTransaction(PropertyKeys.PAGE_BREAK_BEFORE);
131: undo.add(new UndoEntry() {
132: public void undo() {
133: setNullString(oldNullString);
134: }
135:
136: public void redo() {
137: setNullString(nullString);
138: }
139: });
140: undo.endTransaction();
141: }
142:
143: firePropertyChange(PropertyKeys.NULL_STRING, oldNullString,
144: nullString);
145: }
146:
147: @NotNull
148: public String getPaintText() {
149: return getResourceKey();
150: }
151:
152: public void accept(@Nullable
153: Object parent, @NotNull
154: ReportVisitor reportVisitor) throws ReportCreationException {
155: /*Object newParent = */
156: reportVisitor.visit(parent, this );
157: }
158:
159: protected void externalizeElements(@NotNull
160: XMLWriter xmlWriter, @NotNull
161: XMLContext xmlContext) throws IOException {
162: super .externalizeElements(xmlWriter, xmlContext);
163:
164: xmlWriter.writeProperty(PropertyKeys.RESOURCE_BASE,
165: resourceBase);
166: xmlWriter.writeProperty(PropertyKeys.RESOURCE_KEY, resourceKey);
167: xmlWriter.writeProperty(PropertyKeys.NULL_STRING, nullString);
168: }
169:
170: protected void readElement(@NotNull
171: ExpressionRegistry expressions, @NotNull
172: XmlPullNode node, @NotNull
173: XMLContext xmlContext) throws Exception {
174: super.readElement(expressions, node, xmlContext);
175:
176: if (XMLConstants.PROPERTY.equals(node.getRawName())
177: && PropertyKeys.RESOURCE_BASE
178: .equals(node
179: .getAttributeValueFromRawName(XMLConstants.NAME))) {
180: resourceBase = XMLUtils.readProperty(
181: PropertyKeys.RESOURCE_BASE, node);
182: } else if (XMLConstants.PROPERTY.equals(node.getRawName())
183: && PropertyKeys.RESOURCE_KEY
184: .equals(node
185: .getAttributeValueFromRawName(XMLConstants.NAME))) {
186: resourceKey = XMLUtils.readProperty(
187: PropertyKeys.RESOURCE_KEY, node);
188: } else if (XMLConstants.PROPERTY.equals(node.getRawName())
189: && PropertyKeys.NULL_STRING
190: .equals(node
191: .getAttributeValueFromRawName(XMLConstants.NAME))) {
192: nullString = XMLUtils.readProperty(
193: PropertyKeys.NULL_STRING, node);
194: }
195: }
196: }
|