KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > jpivot > navigator > hierarchy > SlicerCategory


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.ArrayList JavaDoc;
16 import java.util.Collection JavaDoc;
17 import java.util.Collections 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.navigator.member.MemberSelectionModel;
23 import com.tonbeller.jpivot.olap.model.Hierarchy;
24 //import com.tonbeller.jpivot.olap.model.Dimension;
25
import com.tonbeller.jpivot.olap.model.Member;
26 import com.tonbeller.jpivot.olap.model.OlapException;
27 import com.tonbeller.jpivot.olap.model.OlapUtils;
28 import com.tonbeller.jpivot.olap.navi.ChangeSlicer;
29 import com.tonbeller.tbutils.res.Resources;
30 import com.tonbeller.wcf.catedit.Item;
31 import com.tonbeller.wcf.controller.RequestContext;
32 import com.tonbeller.wcf.selection.SelectionModel;
33
34 /**
35  * Created on 09.12.2002
36  *
37  * @author av
38  */

39 class SlicerCategory extends AbstractCategory {
40   public SlicerCategory(HierarchyNavigator navi, String JavaDoc name, String JavaDoc icon) throws OlapException {
41     super(navi, name, icon);
42
43     /* Take active hierarchies instead of active
44      dimensions, to remember the slicer on a hierarchy that is
45      not the default (first)
46      */

47     Set JavaDoc slicerHiers = OlapUtils.getSlicerHierarchies(navi.getOlapModel());
48     for (Iterator JavaDoc it = slicerHiers.iterator(); it.hasNext();) {
49       Hierarchy hier = (Hierarchy) it.next();
50       HierarchyItem hi = new HierarchyItem(this, hier);
51       items.add(hi);
52     }
53
54     Collections.sort(items);
55   }
56
57   /**
58    * calls HierarchyNavigator.itemClicked with the appropriate selection model
59    */

60   public void itemClicked(RequestContext context, HierarchyItem item) {
61     // create a selection model
62
MemberSelectionModel selection = new MemberSelectionModel();
63     if (navi.getSlicerExtension() == null)
64       selection.setMode(SelectionModel.NO_SELECTION);
65     else
66       selection.setMode(SelectionModel.SINGLE_SELECTION);
67
68     selection.setOrderedSelection(item.getSlicerSelection());
69     navi.itemClicked(context, item, selection, false);
70   }
71
72   void setSelection(HierarchyItem item, Collection JavaDoc selection) {
73     item.setSlicerSelection(selection);
74   }
75
76   public boolean isOrderSignificant() {
77     return false;
78   }
79
80   void prepareApplyChanges() {
81   }
82
83   void applyChanges() {
84     if (!isDirty())
85       return;
86     setDirty(false);
87
88     ChangeSlicer slicerExtension = navi.getSlicerExtension();
89     if (slicerExtension == null)
90       return;
91
92     List JavaDoc memberList = new ArrayList JavaDoc();
93     for (Iterator JavaDoc it = items.iterator(); it.hasNext();) {
94       HierarchyItem hi = (HierarchyItem) it.next();
95       memberList.addAll(hi.getSlicerSelection());
96     }
97     Member[] memberArr = (Member[]) memberList.toArray(new Member[memberList.size()]);
98     slicerExtension.setSlicer(memberArr);
99   }
100
101   public boolean isEmptyAllowed() {
102     return true;
103   }
104
105   String JavaDoc validateSelection(HierarchyItem item, Collection JavaDoc selection) {
106     if (selection.size() > 1) {
107       Resources res = getNavigator().getRes();
108       return res.getString("selection.mustSelectOneOrLess");
109     }
110     return null;
111   }
112
113   /**
114    * adds an item and sorts the list
115    */

116   public void addItem(Item item) {
117     super.addItem(item);
118     Collections.sort(items);
119   }
120
121   public boolean isSlicer() {
122     return true;
123   }
124
125 }
126
127          
128
Popular Tags