1 package com.tonbeller.jpivot.table; 2 3 import java.util.ArrayList ; 4 import java.util.Iterator ; 5 import java.util.List ; 6 7 import org.w3c.dom.Element ; 8 9 import com.tonbeller.jpivot.olap.model.Alignable; 10 import com.tonbeller.jpivot.table.SpanBuilder.SBContext; 11 import com.tonbeller.jpivot.table.span.Span; 12 import com.tonbeller.wcf.popup.MenuItem; 13 import com.tonbeller.wcf.popup.MenuItemSupport; 14 import com.tonbeller.wcf.popup.PopUp; 15 16 public class AxisHeaderBuilderSupport implements AxisHeaderBuilder { 17 18 private SpanBuilder spanBuilder; 19 20 public AxisHeaderBuilderSupport(SpanBuilder spanBuilder) { 21 this.spanBuilder = spanBuilder; 22 } 23 24 class MySBContext implements SBContext { 25 Element captionElem; 26 String captionLabel; 27 List clickables = new ArrayList (); 28 29 public void setCaption(Element elem, String label) { 30 this.captionElem = elem; 31 this.captionLabel = label; 32 } 33 public void addClickable(String href, String label) { 34 MenuItemSupport mis = new MenuItemSupport(href); 35 mis.setLabel(label); 36 clickables.add(mis); 37 } 38 39 void render() { 40 if (clickables.isEmpty()) 41 return; 42 43 if (clickables.size() == 1) { 44 MenuItem mi = (MenuItem) clickables.get(0); 45 captionElem.setAttribute("href", mi.getHref()); 46 return; 47 } 48 49 PopUp pu = new PopUp(); 50 pu.setLabel(captionLabel); 51 for (Iterator it = clickables.iterator(); it.hasNext();) { 52 MenuItem mi = (MenuItem) it.next(); 53 pu.addItem(mi); 54 } 55 Element e = pu.render(captionElem.getOwnerDocument()); 56 captionElem.appendChild(e); 57 } 58 59 } 60 61 public void build(Element row, Span span, int rowspan, int colspan, boolean even, boolean memberIndent) { 62 MySBContext sbctx = new MySBContext(); 63 Element elem = spanBuilder.build(sbctx, span, even); 64 sbctx.render(); 65 elem.setAttribute("rowspan", Integer.toString(rowspan)); 66 elem.setAttribute("colspan", Integer.toString(colspan)); 67 68 if (elem.getAttribute("style").length() == 0) { 70 String style; 72 if (colspan > 1 || rowspan > 1) 73 style = "span"; 74 else if (even) 75 style = "even"; 76 else 77 style = "odd"; 78 if (isRightAligned(span)) 79 style = style + "-right"; 80 elem.setAttribute("style", style); 81 } 82 83 if (memberIndent && span.isMember()) { 85 elem.setAttribute("indent", Integer.toString(span.getIndent())); 86 } 87 88 row.appendChild(elem); 89 } 90 91 private boolean isRightAligned(Span span) { 92 Object obj = span.getObject(); 93 if (obj instanceof Alignable) 94 return ((Alignable) obj).getAlignment() == Alignable.Alignment.RIGHT; 95 return false; 96 } 97 98 } 99 | Popular Tags |