KickJava   Java API By Example, From Geeks To Geeks.

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


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
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 /**
29  * AxisCategory or SlicerCategory.
30  * Contains a list of HierInfo's. Represents a Query Axis, either visible
31  * (row, column) or slicer.
32  *
33  * @author av
34  */

35 public abstract class AbstractCategory implements Category {
36   HierarchyNavigator navi;
37   String JavaDoc name;
38   String JavaDoc icon;
39   boolean dirty;
40   List JavaDoc items = new ArrayList JavaDoc();
41
42   /**
43    * ctor for visible axis
44    */

45   public AbstractCategory(HierarchyNavigator navi, String JavaDoc name, String JavaDoc icon) {
46     this.navi = navi;
47     this.name = name;
48     this.icon = icon;
49   }
50
51   /**
52    * @see com.tonbeller.jpivot.core.Displayable#getName()
53    */

54   public String JavaDoc getName() {
55     return name;
56   }
57
58   /**
59    * Returns the items.
60    * @return List
61    */

62   public List JavaDoc getItems() {
63     return Collections.unmodifiableList(items);
64   }
65
66   public void addItem(Item item) {
67     HierarchyItem hi = (HierarchyItem) item;
68     // append the hierarchy at the last position,
69
// this makes opening a node of the new hierarchy cheaper
70
// because there is nothing right of it.
71
// items.add(0, hi);
72
items.add(hi);
73     hi.setCategory(this);
74     setDirty(true);
75   }
76
77   public void changeOrder(List JavaDoc 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   /**
89    * @see com.tonbeller.wcf.catedit.Category#getIcon()
90    */

91   public String JavaDoc getIcon() {
92     return icon;
93   }
94
95   /**
96    * Returns the dirty.
97    * @return boolean
98    */

99   public boolean isDirty() {
100     return dirty;
101   }
102
103   /**
104    * Sets the dirty to true
105    * @param dirty The dirty to set
106    */

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   /**
118    * user has clicked on the hyperlink for item
119    */

120   public abstract void itemClicked(RequestContext context, HierarchyItem item);
121
122   /**
123    * simulates an itemClick for the hierarchy
124    */

125   public HierarchyItem findItemFor(Hierarchy hier) {
126     Iterator JavaDoc 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   /**
137    * called before applyChanges to query the needed MemberExpressions
138    */

139   abstract void prepareApplyChanges();
140
141   /**
142    * called after prepareApplyChanges to apply the MemberExpressions
143    */

144   abstract void applyChanges();
145
146   abstract void setSelection(HierarchyItem item, Collection JavaDoc selection);
147   abstract String JavaDoc validateSelection(HierarchyItem item, Collection JavaDoc selection);
148   public abstract boolean isSlicer();
149
150   /**
151    * removes the deleted items from the model
152    */

153   public void deleteDeleted() {
154     MemberDeleter md = navi.getDeleterExtension();
155     if (md == null)
156       return;
157     Iterator JavaDoc it = items.iterator();
158     while (it.hasNext()) {
159       HierarchyItem item = (HierarchyItem) it.next();
160       for (Iterator JavaDoc mi = item.getDeleted().iterator(); mi.hasNext();) {
161         md.delete((Member) mi.next());
162       }
163     }
164   }
165
166 }
167
Popular Tags