KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > jpivot > 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 com.tonbeller.jpivot.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  * represents a visible query axis.
30  *
31  * @author av
32  */

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

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

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

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