1 13 package org.openi.xmla.navigator.hierarchy; 14 15 import java.util.Collection ; 16 import java.util.Iterator ; 17 18 import com.tonbeller.jpivot.navigator.member.MemberSelectionModel; 19 import com.tonbeller.jpivot.olap.model.Axis; 20 import com.tonbeller.jpivot.olap.model.Hierarchy; 21 import com.tonbeller.jpivot.olap.model.Member; 22 import com.tonbeller.jpivot.olap.navi.PlaceHierarchiesOnAxes; 23 import com.tonbeller.jpivot.olap.navi.PlaceMembersOnAxes; 24 import com.tonbeller.tbutils.res.Resources; 25 import com.tonbeller.wcf.controller.RequestContext; 26 import com.tonbeller.wcf.selection.SelectionModel; 27 28 29 34 class AxisCategory extends AbstractCategory { 35 36 Axis axis; 40 41 44 public AxisCategory(HierarchyNavigator navi, Axis axis, String name, String icon) { 45 super(navi, name, icon); 46 this.axis = axis; 47 48 Hierarchy[] hiers = axis.getHierarchies(); 49 for (int i = 0; i < hiers.length; i++) { 50 Hierarchy hier = hiers[i]; 51 HierarchyItem hi = new HierarchyItem(this, hier); 52 items.add(hi); 53 } 54 } 55 56 59 public void itemClicked(RequestContext context, HierarchyItem item) { 60 MemberSelectionModel selection = new MemberSelectionModel(); 62 if (navi.getMemberExtension() == null) 63 selection.setMode(SelectionModel.NO_SELECTION); 64 else 65 selection.setMode(SelectionModel.MULTIPLE_SELECTION); 66 67 selection.setSelection(item.getAxisSelection()); 68 navi.itemClicked(context, item, selection, true); 69 } 70 71 void setSelection(HierarchyItem item, Collection selection) { 72 item.setAxisSelection(selection); 73 } 74 75 String validateSelection(HierarchyItem item, Collection selection) { 76 Resources res = getNavigator().getRes(); 77 if (selection.size() < 1) 78 return res.getString("selection.mustSelectOneOrMore"); 79 Hierarchy hier = null; 80 for (Iterator it = selection.iterator(); it.hasNext();) { 81 Member m = (Member) it.next(); 82 Hierarchy mh = m.getLevel().getHierarchy(); 83 if (hier == null) 84 hier = mh; 85 else { 86 if (!hier.equals(mh)) 87 return res.getString("selection.multipleHierarchies"); 88 } 89 } 90 return null; 91 } 92 93 96 public boolean isOrderSignificant() { 97 return true; 98 } 99 100 Object [] memberExpressions; 101 102 void prepareApplyChanges() { 103 if (!isDirty()) 104 return; 105 setDirty(false); 106 107 PlaceHierarchiesOnAxes hierExtension = navi.getHierarchyExtension(); 108 PlaceMembersOnAxes memberExtension = navi.getMemberExtension(); 109 if (hierExtension == null) 110 return; 111 112 memberExpressions = new Object [getItems().size()]; 113 Iterator it = getItems().iterator(); 114 for (int i = 0; i < memberExpressions.length; i++) { 115 HierarchyItem hi = (HierarchyItem)it.next(); 116 if (hi.getExpression() != null) 117 memberExpressions[i] = hi.getExpression(); 118 else if (hi.isAxisSelectionDirty() && memberExtension != null) 119 memberExpressions[i] = memberExtension.createMemberExpression(hi.getAxisSelection()); 120 else 121 memberExpressions[i] = hierExtension.createMemberExpression(hi.getHierarchy()); 122 } 123 } 124 125 void applyChanges() { 126 PlaceHierarchiesOnAxes hierExtension = navi.getHierarchyExtension(); 127 if (hierExtension == null) 128 return; 129 if (memberExpressions != null) { 130 hierExtension.setQueryAxis((Axis)axis.getRootDecoree(), memberExpressions); 131 memberExpressions = null; 132 } 133 } 134 135 136 public boolean isEmptyAllowed() { 137 return false; 138 } 139 140 public boolean isSlicer() { 141 return false; 142 } 143 144 } 145 | Popular Tags |