1 13 package com.tonbeller.jpivot.navigator.hierarchy; 14 15 import java.util.ArrayList ; 16 import java.util.Collection ; 17 import java.util.Collections ; 18 import java.util.Iterator ; 19 import java.util.List ; 20 import java.util.Set ; 21 22 import com.tonbeller.jpivot.navigator.member.MemberSelectionModel; 23 import com.tonbeller.jpivot.olap.model.Hierarchy; 24 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 39 class SlicerCategory extends AbstractCategory { 40 public SlicerCategory(HierarchyNavigator navi, String name, String icon) throws OlapException { 41 super(navi, name, icon); 42 43 47 Set slicerHiers = OlapUtils.getSlicerHierarchies(navi.getOlapModel()); 48 for (Iterator 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 60 public void itemClicked(RequestContext context, HierarchyItem item) { 61 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 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 memberList = new ArrayList (); 93 for (Iterator 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 validateSelection(HierarchyItem item, Collection selection) { 106 if (selection.size() > 1) { 107 Resources res = getNavigator().getRes(); 108 return res.getString("selection.mustSelectOneOrLess"); 109 } 110 return null; 111 } 112 113 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 |