KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > jpivot > test > olap > TestDrillReplace


1 /*
2  * ====================================================================
3  * This software is subject to the terms of the Common Public License
4  * Agreement, available at the following URL:
5  * http://www.opensource.org/licenses/cpl.html .
6  * Copyright (C) 2003-2004 TONBELLER AG.
7  * All Rights Reserved.
8  * You must accept the terms of that agreement to use this software.
9  * ====================================================================
10  *
11  *
12  */

13 package com.tonbeller.jpivot.test.olap;
14
15 import java.util.ArrayList JavaDoc;
16 import java.util.Arrays JavaDoc;
17 import java.util.HashSet JavaDoc;
18 import java.util.Iterator JavaDoc;
19 import java.util.List JavaDoc;
20 import java.util.Set JavaDoc;
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 /**
28  * Created on 03.12.2002
29  *
30  * @author av
31  */

32 public class TestDrillReplace extends TestExtensionSupport implements DrillReplace {
33
34   /**
35    * @see com.tonbeller.jpivot.olap.navi.DrillReplace#canDrillDown(Member)
36    */

37   public boolean canDrillDown(Member member) {
38     return ((TestMember)member).hasChildren();
39   }
40
41   /**
42    * @see com.tonbeller.jpivot.olap.navi.DrillReplace#canDrillUp(Hierarchy)
43    */

44   public boolean canDrillUp(Hierarchy hier) {
45     TestAxis axis = TestOlapModelUtils.findAxis(model(), hier);
46     int memberIndex = TestOlapModelUtils.indexOf(axis.getHierarchies(), hier);
47     for (Iterator JavaDoc 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   /**
56    * @see com.tonbeller.jpivot.olap.navi.DrillReplace#drillDown(Member)
57    */

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   /**
66    * @see com.tonbeller.jpivot.olap.navi.DrillReplace#drillUp(Hierarchy)
67    */

68   public void drillUp(Hierarchy hier) {
69     Set JavaDoc parents = new HashSet JavaDoc();
70     List JavaDoc memberList = new ArrayList JavaDoc();
71     TestAxis axis = TestOlapModelUtils.findAxis(model(), hier);
72     int memberIndex = TestOlapModelUtils.indexOf(axis.getHierarchies(), hier);
73     loop: for (Iterator JavaDoc 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; // this was a root member
80

81       // avoid duplicate parents (and children)
82
Object JavaDoc key = parent.getParentMember();
83       if (key == null) // root
84
key = hier;
85       if (parents.contains(key))
86         continue loop;
87       parents.add(key);
88
89       // add children of grandpa
90
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