KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > jpivot > olap > query > DrillExpandPositionExt


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.olap.query;
14
15 import com.tonbeller.jpivot.core.ExtensionSupport;
16 import com.tonbeller.jpivot.olap.model.Member;
17 import com.tonbeller.jpivot.olap.model.Position;
18 import com.tonbeller.jpivot.olap.navi.DrillExpandPosition;
19
20 /**
21  * @author hh
22  */

23 public class DrillExpandPositionExt extends ExtensionSupport implements DrillExpandPosition {
24
25   /**
26    * Constructor sets ID
27    */

28   public DrillExpandPositionExt() {
29     super.setId(DrillExpandPosition.ID);
30   }
31
32   /**
33    * @see com.tonbeller.jpivot.olap.navi.DrillExpand#canExpand(Member)
34    * @param position position to be expanded
35    * @param member member to be expanded
36    * @return true if the member can be expanded
37    */

38   public boolean canExpand(Position position, Member member) {
39     QueryAdapter.QueryAdapterHolder model = (QueryAdapter.QueryAdapterHolder) getModel();
40     Member[] pathMembers = memberPath(position, member);
41     return model.getQueryAdapter().canExpand(pathMembers);
42   }
43
44   /**
45    * @see com.tonbeller.jpivot.olap.navi.DrillExpand#canCollapse(Member)
46    * @param position position to be expanded
47    * @return true if the member can be expanded
48    */

49   public boolean canCollapse(Position position, Member member) {
50     QueryAdapter.QueryAdapterHolder model = (QueryAdapter.QueryAdapterHolder) getModel();
51     Member[] pathMembers = memberPath(position, member);
52     return model.getQueryAdapter().canCollapse(pathMembers);
53
54   }
55
56   /**
57    * @see com.tonbeller.jpivot.olap.navi.DrillExpand#expand(Member)
58    * @param position position to be expanded
59    * @param member member to be expanded
60    */

61   public void expand(Position position, Member member) {
62
63     QueryAdapter.QueryAdapterHolder model = (QueryAdapter.QueryAdapterHolder) getModel();
64     Member[] pathMembers = memberPath(position, member);
65     model.getQueryAdapter().expand(pathMembers);
66   }
67
68   /**
69    * @see com.tonbeller.jpivot.olap.navi.DrillExpand#expand(Member)
70    * @param position position to be collapsed
71    * @param position member to be collapsed
72    */

73   public void collapse(Position position, Member member) {
74     QueryAdapter.QueryAdapterHolder model = (QueryAdapter.QueryAdapterHolder) getModel();
75     Member[] pathMembers = memberPath(position, member);
76     model.getQueryAdapter().collapse(pathMembers);
77   }
78
79   /**
80     * determine path to member
81     * @param position
82     * @param member
83     * @return path to Member
84     */

85   private Member[] memberPath(Position position, Member member) {
86     Member[] posMembers = position.getMembers();
87     int pathlen = 0;
88     for (int i = 0; i < posMembers.length; i++) {
89       if (posMembers[i].equals(member)) {
90         pathlen = i + 1;
91         break;
92       }
93     }
94     if (pathlen == 0)
95       return null; // should not occur
96
Member[] pathMembers = new Member[pathlen];
97     for (int i = 0; i < pathlen; i++) {
98       pathMembers[i] = posMembers[i];
99     }
100     return pathMembers;
101   }
102
103 } // End DrillExpandPositionExt
104
Popular Tags