1 13 package org.openi.xmla.navigator.hierarchy; 14 15 import java.util.ArrayList ; 16 import java.util.Collection ; 17 import java.util.List ; 18 import java.util.Set ; 19 20 import org.apache.log4j.Logger; 21 22 import com.tonbeller.jpivot.olap.model.Dimension; 23 import com.tonbeller.jpivot.olap.model.Hierarchy; 24 import com.tonbeller.jpivot.olap.model.Member; 25 import com.tonbeller.jpivot.olap.model.OlapUtils; 26 import com.tonbeller.jpivot.olap.navi.ChangeSlicer; 27 import com.tonbeller.jpivot.olap.navi.PlaceMembersOnAxes; 28 import com.tonbeller.wcf.catedit.Item; 29 import com.tonbeller.wcf.controller.RequestContext; 30 import com.tonbeller.wcf.controller.RequestListener; 31 import com.tonbeller.wcf.utils.DomUtils; 32 33 42 public class HierarchyItem implements Item, RequestListener, Comparable { 43 44 private static final Logger logger = Logger.getLogger(HierarchyItem.class); 45 46 private HierarchyNavigator navigator; 48 49 private AbstractCategory category; 51 52 private Hierarchy hierarchy; 54 55 private List axisSelection; 57 private boolean axisSelectionDirty; 58 59 private List slicerSelection; 61 private boolean slicerSelectionDirty; 62 63 private List deleted = new ArrayList (); 65 66 private Object expression; 68 69 private String id = DomUtils.randomId(); 70 71 private Dimension dimension; 72 73 public String getId() { 74 return id; 75 } 76 77 public HierarchyItem(AbstractCategory category, Hierarchy hierarchy) { 78 this.category = category; 79 this.hierarchy = hierarchy; 80 this.dimension = hierarchy.getDimension(); 81 this.navigator = category.getNavigator(); 82 navigator.getTempDispatcher().addRequestListener(id, null, this); 83 } 84 85 void initializeSlicerSelection() { 86 ChangeSlicer slicerExtension = navigator.getSlicerExtension(); 87 slicerSelection = new ArrayList (); 88 if (slicerExtension != null) { 89 Member[] members = slicerExtension.getSlicer(); 90 loop : for (int i = 0; i < members.length; i++) { 91 if (members[i].getLevel().getHierarchy().equals(hierarchy)) { 92 slicerSelection.add(members[i]); 93 break loop; 94 } 95 } 96 } 97 } 98 99 void initializeAxisSelection() { 100 PlaceMembersOnAxes memberExtension = navigator.getMemberExtension(); 101 axisSelection = new ArrayList (); 102 if (memberExtension != null) { 103 List members = memberExtension.findVisibleMembers(hierarchy); 104 axisSelection.addAll(members); 105 } 106 } 107 108 private void clear() { 109 axisSelection = null; 110 slicerSelection = null; 111 deleted.clear(); 112 expression = null; 113 } 114 115 119 public void setCategory(AbstractCategory category) { 120 this.category = category; 121 } 122 123 public AbstractCategory getCategory() { 124 return category; 125 } 126 127 131 public Hierarchy getHierarchy() { 132 return hierarchy; 133 } 134 135 138 public Dimension getDimension() { 139 return dimension; 140 } 141 142 public String getLabel() { 143 return hierarchy.getLabel(); 144 } 145 146 149 public void request(RequestContext context) throws Exception { 150 category.itemClicked(context, this); 151 } 152 153 157 public List getAxisSelection() { 158 if (axisSelection == null) 159 initializeAxisSelection(); 160 return axisSelection; 161 } 162 163 167 public List getSlicerSelection() { 168 if (slicerSelection == null) 169 initializeSlicerSelection(); 170 return slicerSelection; 171 } 172 173 177 public void setAxisSelection(Collection selection) { 178 clear(); 179 updateHierarchy(selection); 180 if (axisSelection == null) 181 axisSelection = new ArrayList (); 182 else 183 axisSelection.clear(); 184 axisSelection.addAll(selection); 185 axisSelectionDirty = true; 186 category.setDirty(true); 187 expression = null; 188 } 189 190 194 public void setSlicerSelection(Collection selection) { 195 clear(); 196 updateHierarchy(selection); 197 if (slicerSelection == null) 198 slicerSelection = new ArrayList (); 199 else 200 slicerSelection.clear(); 201 slicerSelection.addAll(selection); 202 slicerSelectionDirty = true; 203 category.setDirty(true); 204 expression = null; 205 } 206 207 private void updateHierarchy(Collection selection) { 208 if (selection == null || selection.isEmpty()) 209 hierarchy = dimension.getHierarchies()[0]; 210 else { 211 Member m = (Member) selection.iterator().next(); 212 hierarchy = m.getLevel().getHierarchy(); 213 if (!hierarchy.getDimension().equals(dimension)) 214 logger.error("invalid dimension in " + hierarchy.getLabel()); 215 } 216 217 } 218 219 223 public boolean isAxisSelectionDirty() { 224 return axisSelectionDirty; 225 } 226 227 231 public boolean isSlicerSelectionDirty() { 232 return slicerSelectionDirty; 233 } 234 235 239 public void setAxisSelectionDirty(boolean axisSelectionDirty) { 240 this.axisSelectionDirty = axisSelectionDirty; 241 } 242 243 247 public void setSlicerSelectionDirty(boolean slicerSelectionDirty) { 248 this.slicerSelectionDirty = slicerSelectionDirty; 249 } 250 251 public void setSelection(Collection selection) { 252 category.setSelection(this, selection); 253 } 254 259 public String validateSelection(Collection selection) { 260 return category.validateSelection(this, selection); 261 } 262 263 266 public int compareTo(Object arg) { 267 HierarchyItem that = (HierarchyItem) arg; 268 return this.hierarchy.getLabel().compareTo(that.getHierarchy().getLabel()); 269 } 270 271 274 public void removeFromSelection(Set deleted) { 275 if (axisSelection != null) 276 axisSelection.removeAll(deleted); 277 if (slicerSelection != null) 278 slicerSelection.removeAll(deleted); 279 } 280 281 285 public Collection getDeleted() { 286 return deleted; 287 } 288 289 293 public void setDeleted(Collection c) { 294 deleted.clear(); 295 deleted.addAll(c); 296 } 297 298 public Object getExpression() { 299 return expression; 300 } 301 302 public void setExpression(Object object) { 303 clear(); 304 expression = object; 305 category.setDirty(true); 306 } 307 308 public boolean isMovable() { 309 return !OlapUtils.isSingleRecord(hierarchy); 310 } 311 312 public boolean isClickable() { 313 return navigator.getHierarchyItemClickHandler() != null; 314 } 315 316 } 317 | Popular Tags |