KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openi > xmla > navigator > hierarchy > AxisCategory


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 org.openi.xmla.navigator.hierarchy;
14
15 import java.util.Collection JavaDoc;
16 import java.util.Iterator JavaDoc;
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
29 /**
30  * represents a visible query axis.
31  *
32  * @author av
33  */

34 class AxisCategory extends AbstractCategory {
35
36   // AVTASK the axis may have changed if a ModelChangeEvent was received.
37
// This means, that we are calling the navigation code with an invalid
38
// axis object that is not part of the current result.
39
Axis axis;
40
41   /**
42    * ctor for visible axis
43    */

44   public AxisCategory(HierarchyNavigator navi, Axis axis, String JavaDoc name, String JavaDoc icon) {
45     super(navi, name, icon);
46     this.axis = axis;
47
48     Hierarchy[] hiers = axis.getHierarchies();
49     for (int i = 0; i < hiers.length; i++) {
50       Hierarchy hier = hiers[i];
51       HierarchyItem hi = new HierarchyItem(this, hier);
52       items.add(hi);
53     }
54   }
55
56   /**
57    * calls HierarchyNavigator.hierarchyItemClicked with the appropriate selection model
58    */

59   public void itemClicked(RequestContext context, HierarchyItem item) {
60     // create a selection model
61
MemberSelectionModel selection = new MemberSelectionModel();
62     if (navi.getMemberExtension() == null)
63       selection.setMode(SelectionModel.NO_SELECTION);
64     else
65       selection.setMode(SelectionModel.MULTIPLE_SELECTION);
66
67     selection.setSelection(item.getAxisSelection());
68     navi.itemClicked(context, item, selection, true);
69   }
70
71   void setSelection(HierarchyItem item, Collection JavaDoc selection) {
72     item.setAxisSelection(selection);
73   }
74
75   String JavaDoc validateSelection(HierarchyItem item, Collection JavaDoc selection) {
76     Resources res = getNavigator().getRes();
77     if (selection.size() < 1)
78       return res.getString("selection.mustSelectOneOrMore");
79     Hierarchy hier = null;
80     for (Iterator JavaDoc it = selection.iterator(); it.hasNext();) {
81       Member m = (Member) it.next();
82       Hierarchy mh = m.getLevel().getHierarchy();
83       if (hier == null)
84         hier = mh;
85       else {
86         if (!hier.equals(mh))
87           return res.getString("selection.multipleHierarchies");
88       }
89     }
90     return null;
91   }
92
93   /**
94    * returns true;
95    */

96   public boolean isOrderSignificant() {
97     return true;
98   }
99
100   Object JavaDoc[] memberExpressions;
101
102   void prepareApplyChanges() {
103     if (!isDirty())
104       return;
105     setDirty(false);
106
107     PlaceHierarchiesOnAxes hierExtension = navi.getHierarchyExtension();
108     PlaceMembersOnAxes memberExtension = navi.getMemberExtension();
109     if (hierExtension == null)
110       return;
111
112     memberExpressions = new Object JavaDoc[getItems().size()];
113     Iterator JavaDoc it = getItems().iterator();
114     for (int i = 0; i < memberExpressions.length; i++) {
115       HierarchyItem hi = (HierarchyItem)it.next();
116       if (hi.getExpression() != null)
117         memberExpressions[i] = hi.getExpression();
118       else if (hi.isAxisSelectionDirty() && memberExtension != null)
119         memberExpressions[i] = memberExtension.createMemberExpression(hi.getAxisSelection());
120       else
121         memberExpressions[i] = hierExtension.createMemberExpression(hi.getHierarchy());
122     }
123   }
124
125   void applyChanges() {
126     PlaceHierarchiesOnAxes hierExtension = navi.getHierarchyExtension();
127     if (hierExtension == null)
128       return;
129     if (memberExpressions != null) {
130       hierExtension.setQueryAxis((Axis)axis.getRootDecoree(), memberExpressions);
131       memberExpressions = null;
132     }
133   }
134
135
136   public boolean isEmptyAllowed() {
137     return false;
138   }
139
140   public boolean isSlicer() {
141     return false;
142   }
143
144 }
145
Popular Tags