1 13 package com.tonbeller.jpivot.test.olap; 14 15 import java.util.ArrayList ; 16 import java.util.Arrays ; 17 import java.util.HashSet ; 18 import java.util.Iterator ; 19 import java.util.List ; 20 import java.util.Set ; 21 22 import com.tonbeller.jpivot.olap.model.Hierarchy; 23 import com.tonbeller.jpivot.olap.model.Member; 24 import com.tonbeller.jpivot.olap.model.Position; 25 import com.tonbeller.jpivot.olap.navi.DrillReplace; 26 27 32 public class TestDrillReplace extends TestExtensionSupport implements DrillReplace { 33 34 37 public boolean canDrillDown(Member member) { 38 return ((TestMember)member).hasChildren(); 39 } 40 41 44 public boolean canDrillUp(Hierarchy hier) { 45 TestAxis axis = TestOlapModelUtils.findAxis(model(), hier); 46 int memberIndex = TestOlapModelUtils.indexOf(axis.getHierarchies(), hier); 47 for (Iterator it = axis.getPositions().iterator(); it.hasNext();) { 48 Member m = ((Position)it.next()).getMembers()[memberIndex]; 49 if (m.getRootDistance() > 0) 50 return true; 51 } 52 return false; 53 } 54 55 58 public void drillDown(Member member) { 59 TestMember tm = (TestMember)member; 60 TestOlapModelUtils.setVisible(tm.getChildMember()); 61 TestOlapModelUtils.rebuildAxis(model(), (TestMember)member); 62 fireModelChanged(); 63 } 64 65 68 public void drillUp(Hierarchy hier) { 69 Set parents = new HashSet (); 70 List memberList = new ArrayList (); 71 TestAxis axis = TestOlapModelUtils.findAxis(model(), hier); 72 int memberIndex = TestOlapModelUtils.indexOf(axis.getHierarchies(), hier); 73 loop: for (Iterator it = axis.getPositions().iterator(); it.hasNext();) { 74 TestPosition position = (TestPosition)it.next(); 75 TestMember member = (TestMember)position.getMembers()[memberIndex]; 76 77 TestMember parent = member.getParentMember(); 78 if (parent == null) 79 continue loop; 81 Object key = parent.getParentMember(); 83 if (key == null) key = hier; 85 if (parents.contains(key)) 86 continue loop; 87 parents.add(key); 88 89 TestMember grandpa = parent.getParentMember(); 91 if (grandpa == null) { 92 Member[] members = ((TestHierarchy)hier).getRootMembers(); 93 memberList.addAll(Arrays.asList(members)); 94 } 95 else 96 memberList.addAll(grandpa.getChildMember()); 97 } 98 99 TestOlapModelUtils.setVisible(memberList); 100 TestOlapModelUtils.rebuildAxis(model(), axis); 101 fireModelChanged(); 102 103 } 104 105 } 106 | Popular Tags |