1 13 package com.tonbeller.jpivot.table; 14 15 import java.util.ArrayList ; 16 import java.util.List ; 17 18 import org.w3c.dom.Element ; 19 20 import com.tonbeller.jpivot.olap.model.Member; 21 import com.tonbeller.jpivot.olap.model.Property; 22 import com.tonbeller.jpivot.olap.navi.MemberProperties; 23 import com.tonbeller.jpivot.table.span.PropertyConfig; 24 import com.tonbeller.jpivot.table.span.PropertyUtils; 25 import com.tonbeller.jpivot.table.span.ScopedPropertyMetaSet; 26 import com.tonbeller.wcf.controller.RequestContext; 27 28 33 public class SlicerBuilderImpl extends PartBuilderSupport implements SlicerBuilder { 34 35 ScopedPropertyMetaSet visible; 36 MemberProperties extension; 37 PropertyConfig propertyConfig; 38 39 public void startBuild(RequestContext context) { 40 propertyConfig = table.getPropertyConfig(); 41 42 extension = getExtension(); 43 if (extension == null) { 44 visible = null; 46 return; 47 } 48 49 List list = propertyConfig.getVisiblePropertyMetas(); 50 if (list == null) { 51 visible = null; 52 return; 53 } 54 visible = new ScopedPropertyMetaSet(extension); 55 visible.addAll(list); 56 } 57 58 public void stopBuild() { 59 visible = null; 60 extension = null; 61 propertyConfig = null; 62 } 63 64 public Element build(Member m) { 65 Element e = table.elem("member"); 66 e.setAttribute("level", m.getLevel().getLabel()); 67 e.setAttribute("caption", m.getLabel()); 68 e.setAttribute("depth", Integer.toString(m.getRootDistance())); 69 addMemberProperties(e, m); 70 return e; 71 } 72 73 private void addMemberProperties(Element e, Member m) { 74 if (!propertyConfig.isShowProperties()) 75 return; 76 77 Property[] props = visibleProperties(m); 78 PropertyUtils.addProperties(e, props); 79 } 80 81 private Property[] visibleProperties(Member m) { 82 Property[] src = m.getProperties(); 83 String scope = null; 84 if (extension != null) 85 scope = extension.getPropertyScope(m); 86 List list = new ArrayList (); 87 for (int i = 0; i < src.length; i++) { 88 Property p = src[i]; 89 if (PropertyUtils.isInline(p.getName())) 90 continue; 91 if (scope != null && visible != null) { 92 if (visible.contains(scope, p.getName())) 93 list.add(p); 94 } 95 else 96 list.add(p); 97 } 98 return (Property[])list.toArray(new Property[list.size()]); 99 } 100 101 MemberProperties getExtension() { 102 return (MemberProperties) table.getOlapModel().getExtension(MemberProperties.ID); 103 } 104 105 public boolean isAvailable() { 106 return getExtension() != null; 107 } 108 109 } | Popular Tags |