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