KickJava   Java API By Example, From Geeks To Geeks.

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


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.HashSet JavaDoc;
16 import java.util.Iterator JavaDoc;
17
18 import com.tonbeller.jpivot.olap.model.Member;
19 import com.tonbeller.jpivot.olap.navi.DrillExpandMember;
20
21 /**
22  * Created on 22.10.2002
23  *
24  * @author av
25  */

26 public class TestDrillExpandMember extends TestExtensionSupport implements DrillExpandMember {
27
28   HashSet JavaDoc expanded = new HashSet JavaDoc();
29
30   protected TestOlapModel model() {
31     return (TestOlapModel) super.getModel();
32   }
33
34   /**
35    * @see com.tonbeller.jpivot.olap.navi.DrillExpand#canExpand(Member)
36    */

37   public boolean canExpand(Member member) {
38     TestMember tm = (TestMember) member;
39     return tm.hasChildren() && !expanded.contains(member);
40   }
41
42   /**
43    * @see com.tonbeller.jpivot.olap.navi.DrillExpand#canCollapse(Member)
44    */

45   public boolean canCollapse(Member member) {
46     TestMember tm = (TestMember) member;
47     return tm.hasChildren() && expanded.contains(member);
48   }
49
50   /**
51    * @see com.tonbeller.jpivot.olap.navi.DrillExpand#expand(Member)
52    */

53
54   public void expand(Member member) {
55     expanded.add(member);
56     TestMember tm = (TestMember) member;
57     for (Iterator JavaDoc it = tm.getChildMember().iterator(); it.hasNext();)
58        ((TestMember) it.next()).setVisible(true);
59     TestOlapModelUtils.rebuildAxis(model(), tm);
60     fireModelChanged();
61   }
62
63   public void collapse(Member member) {
64     recurseCollapse((TestMember) member);
65     TestOlapModelUtils.rebuildAxis(model(), (TestMember)member);
66     fireModelChanged();
67   }
68
69
70   private void recurseCollapse(TestMember tm) {
71     if (!expanded.contains(tm))
72       return;
73     expanded.remove(tm);
74     for (Iterator JavaDoc it = tm.getChildMember().iterator(); it.hasNext();) {
75       TestMember child = (TestMember) it.next();
76       recurseCollapse(child);
77       child.setVisible(false);
78     }
79   }
80
81
82 }
83
Popular Tags