KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openi > xmla > 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 org.openi.xmla.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.Dimension;
24 import com.tonbeller.jpivot.olap.model.Member;
25 import com.tonbeller.jpivot.olap.model.OlapException;
26 import com.tonbeller.jpivot.olap.model.OlapUtils;
27 import com.tonbeller.jpivot.olap.navi.ChangeSlicer;
28 import com.tonbeller.tbutils.res.Resources;
29 import com.tonbeller.wcf.catedit.Item;
30 import com.tonbeller.wcf.controller.RequestContext;
31 import com.tonbeller.wcf.selection.SelectionModel;
32
33 /**
34  * Created on 09.12.2002
35  *
36  * @author av
37  */

38 class SlicerCategory extends AbstractCategory {
39   public SlicerCategory(HierarchyNavigator navi, String JavaDoc name, String JavaDoc icon) throws OlapException {
40     super(navi, name, icon);
41
42     Set JavaDoc slicerDims = OlapUtils.getSlicerDimensions(navi.getOlapModel());
43     for (Iterator JavaDoc it = slicerDims.iterator(); it.hasNext();) {
44       Dimension dim = (Dimension) it.next();
45       HierarchyItem hi = new HierarchyItem(this, dim.getHierarchies()[0]);
46       items.add(hi);
47     }
48     Collections.sort(items);
49   }
50
51   /**
52    * calls HierarchyNavigator.itemClicked with the appropriate selection model
53    */

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

106   public void addItem(Item item) {
107     super.addItem(item);
108     Collections.sort(items);
109   }
110
111   public boolean isSlicer() {
112     return true;
113   }
114
115 }
116
Popular Tags