001: /*
002: * Copyright (C) 2005 - 2008 JasperSoft Corporation. All rights reserved.
003: * http://www.jaspersoft.com.
004: *
005: * Unless you have purchased a commercial license agreement from JasperSoft,
006: * the following license terms apply:
007: *
008: * This program is free software; you can redistribute it and/or modify
009: * it under the terms of the GNU General Public License version 2 as published by
010: * the Free Software Foundation.
011: *
012: * This program is distributed WITHOUT ANY WARRANTY; and without the
013: * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
014: * See the GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
018: * or write to:
019: *
020: * Free Software Foundation, Inc.,
021: * 59 Temple Place - Suite 330,
022: * Boston, MA USA 02111-1307
023: *
024: *
025: *
026: *
027: * WalkableWrapper.java
028: *
029: * Created on June 20, 2006, 5:14 PM
030: *
031: */
032:
033: package it.businesslogic.ireport.data.olap;
034:
035: import it.businesslogic.ireport.util.Misc;
036: import javax.swing.tree.DefaultMutableTreeNode;
037: import mondrian.olap.*;
038:
039: /**
040: *
041: * @author gtoffoli
042: */
043: public class WalkableWrapper {
044:
045: Object walkable = null;
046: String name = "";
047: private DefaultMutableTreeNode parentNode = null;
048:
049: /** Creates a new instance of WalkableWrapper */
050: public WalkableWrapper(Object obj, DefaultMutableTreeNode parentNode) {
051: this .walkable = obj;
052:
053: this .parentNode = parentNode;
054: if (walkable instanceof QueryAxis) {
055: name = ((QueryAxis) walkable).getAxisName();
056: } else if (walkable instanceof FunCall) {
057: name = ((FunCall) walkable).getFunName();
058: } else if (walkable instanceof Level) {
059: name = ((Level) walkable).getName();
060: } else if (walkable instanceof Hierarchy) {
061: name = ((Hierarchy) walkable).getName();
062: } else if (walkable instanceof Member) {
063: name = ((Member) walkable).getName();
064: } else {
065: name = getWalkable() + " (" + walkable.getClass().getName();
066: }
067: }
068:
069: public boolean isMeasure() {
070: return (walkable instanceof Member)
071: && ((Member) walkable).isMeasure();
072: }
073:
074: public String getExpression() {
075: if (isMeasure()) {
076: int qmarks = parentNode.getChildCount();
077: String s = "Data(" + walkable + "";
078: for (int i = 0; i < qmarks - 1; ++i) {
079: s += ",?";
080: }
081: s += ")";
082: return s;
083: } else if (walkable instanceof Level) {
084: // Find the ancestor dimension...
085: DefaultMutableTreeNode node = getParentNode();
086: DefaultMutableTreeNode nodeParent = (DefaultMutableTreeNode) getParentNode()
087: .getParent();
088: while (nodeParent.getParent() != null) {
089: node = nodeParent;
090: nodeParent = (DefaultMutableTreeNode) nodeParent
091: .getParent();
092: }
093: int axisIndex = nodeParent.getIndex(node);
094:
095: String s = "";
096: switch (axisIndex) {
097: case 0:
098: s = "Columns";
099: break;
100: case 1:
101: s = "Rows";
102: break;
103: case 2:
104: s = "Pages";
105: break;
106: case 3:
107: s = "Chapters";
108: break;
109: case 4:
110: s = "Sections";
111: break;
112: default:
113: s = "Axis(" + axisIndex + ")";
114: }
115:
116: s = s + Misc.string_replace("][", "].[", "" + walkable)
117: + "";
118:
119: return s;
120: } else {
121: return null;
122: }
123:
124: //return walkable+"";
125: }
126:
127: public Object getWalkable() {
128: return walkable;
129: }
130:
131: public void setWalkable(Object w) {
132: walkable = w;
133: }
134:
135: public String toString() {
136: return name;
137:
138: }
139:
140: public DefaultMutableTreeNode getParentNode() {
141: return parentNode;
142: }
143:
144: public void setParentNode(DefaultMutableTreeNode parentNode) {
145: this.parentNode = parentNode;
146: }
147:
148: }
|