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 21 import com.tonbeller.jpivot.olap.model.Hierarchy; 22 import com.tonbeller.jpivot.olap.model.Member; 23 import com.tonbeller.jpivot.olap.navi.MemberDeleter; 24 import com.tonbeller.wcf.catedit.Category; 25 import com.tonbeller.wcf.catedit.Item; 26 import com.tonbeller.wcf.controller.RequestContext; 27 28 35 public abstract class AbstractCategory implements Category { 36 HierarchyNavigator navi; 37 String name; 38 String icon; 39 boolean dirty; 40 List items = new ArrayList (); 41 42 45 public AbstractCategory(HierarchyNavigator navi, String name, String icon) { 46 this.navi = navi; 47 this.name = name; 48 this.icon = icon; 49 } 50 51 54 public String getName() { 55 return name; 56 } 57 58 62 public List getItems() { 63 return Collections.unmodifiableList(items); 64 } 65 66 public void addItem(Item item) { 67 HierarchyItem hi = (HierarchyItem) item; 68 items.add(hi); 73 hi.setCategory(this); 74 setDirty(true); 75 } 76 77 public void changeOrder(List items) { 78 this.items.clear(); 79 this.items.addAll(items); 80 setDirty(true); 81 } 82 83 public void removeItem(Item item) { 84 items.remove(item); 85 setDirty(true); 86 } 87 88 91 public String getIcon() { 92 return icon; 93 } 94 95 99 public boolean isDirty() { 100 return dirty; 101 } 102 103 107 public void setDirty(boolean dirty) { 108 this.dirty = dirty; 109 if (dirty) 110 navi.setEditing(true); 111 } 112 113 HierarchyNavigator getNavigator() { 114 return navi; 115 } 116 117 120 public abstract void itemClicked(RequestContext context, HierarchyItem item); 121 122 125 public HierarchyItem findItemFor(Hierarchy hier) { 126 Iterator it = items.iterator(); 127 while (it.hasNext()) { 128 HierarchyItem item = (HierarchyItem) it.next(); 129 if (hier.equals(item.getHierarchy())) { 130 return item; 131 } 132 } 133 return null; 134 } 135 136 139 abstract void prepareApplyChanges(); 140 141 144 abstract void applyChanges(); 145 146 abstract void setSelection(HierarchyItem item, Collection selection); 147 abstract String validateSelection(HierarchyItem item, Collection selection); 148 public abstract boolean isSlicer(); 149 150 153 public void deleteDeleted() { 154 MemberDeleter md = navi.getDeleterExtension(); 155 if (md == null) 156 return; 157 Iterator it = items.iterator(); 158 while (it.hasNext()) { 159 HierarchyItem item = (HierarchyItem) it.next(); 160 for (Iterator mi = item.getDeleted().iterator(); mi.hasNext();) { 161 md.delete((Member) mi.next()); 162 } 163 } 164 } 165 166 } 167 | Popular Tags |