1 5 package com.tonbeller.jpivot.table.navi; 6 7 import org.apache.log4j.Logger; 8 9 import com.tonbeller.jpivot.olap.model.Dimension; 10 import com.tonbeller.jpivot.olap.model.Expression; 11 import com.tonbeller.jpivot.olap.model.Hierarchy; 12 import com.tonbeller.jpivot.olap.model.Level; 13 import com.tonbeller.jpivot.olap.model.Member; 14 import com.tonbeller.jpivot.olap.model.OlapModel; 15 import com.tonbeller.jpivot.olap.navi.ExpressionParser; 16 import com.tonbeller.jpivot.olap.navi.ExpressionParser.InvalidSyntaxException; 17 import com.tonbeller.jpivot.table.ClickableMember; 18 import com.tonbeller.jpivot.table.TableComponent; 19 import com.tonbeller.wcf.controller.RequestContext; 20 21 public abstract class AbstractClickableMember implements ClickableMember { 22 private static final Logger logger = Logger.getLogger(AbstractClickableMember.class); 23 24 boolean suppressAllMember = true; 25 boolean suppressCalcMember = true; 26 boolean suppressMeasures = true; 27 28 31 private Expression expression; 32 33 36 protected ExpressionParser parser; 37 38 42 private String uniqueName; 43 44 protected AbstractClickableMember(String uniqueName) { 45 this.uniqueName = uniqueName; 46 } 47 48 protected boolean match(Member member) { 49 if (suppressCalcMember && member.isCalculated()) 50 return false; 51 if (suppressAllMember && member.isAll()) 52 return false; 53 if (suppressMeasures && member.getLevel().getHierarchy().getDimension().isMeasure()) 54 return false; 55 56 if (empty(uniqueName)) 58 return true; 59 60 if (parser == null || expression == null) 61 return false; 62 if (expression instanceof Level) 63 return expression.equals(member.getLevel()); 64 if (expression instanceof Hierarchy) 65 return expression.equals(member.getLevel().getHierarchy()); 66 if (expression instanceof Dimension) 67 return expression.equals(member.getLevel().getHierarchy().getDimension()); 68 throw new IllegalArgumentException ("unknown type: " + uniqueName); 69 } 70 71 private boolean empty(String s) { 72 return s == null || s.length() == 0; 73 } 74 75 public void startRendering(RequestContext context, TableComponent table) { 76 expression = null; 77 parser = null; 78 OlapModel model = table.getOlapModel(); 79 80 if (empty(uniqueName)) 82 return; 83 84 parser = (ExpressionParser) model.getExtension(ExpressionParser.ID); 85 if (parser != null) { 86 try { 87 expression = parser.lookupLevel(uniqueName); 90 if (expression == null) 91 expression = parser.lookupHierarchy(uniqueName); 92 if (expression == null) 93 expression = parser.lookupDimension(uniqueName); 94 } catch (InvalidSyntaxException e) { 95 logger.warn(null, e); 98 } 99 } 100 } 101 102 public void stopRendering() { 103 parser = null; 104 expression = null; 105 } 106 107 protected boolean isSuppressAllMember() { 108 return suppressAllMember; 109 } 110 111 protected void setSuppressAllMember(boolean suppressAllMember) { 112 this.suppressAllMember = suppressAllMember; 113 } 114 115 protected boolean isSuppressCalcMember() { 116 return suppressCalcMember; 117 } 118 119 protected void setSuppressCalcMember(boolean suppressCalcMember) { 120 this.suppressCalcMember = suppressCalcMember; 121 } 122 123 protected boolean isSuppressMeasures() { 124 return suppressMeasures; 125 } 126 127 protected void setSuppressMeasures(boolean suppressMeasures) { 128 this.suppressMeasures = suppressMeasures; 129 } 130 131 } 132 | Popular Tags |