View Javadoc

1   package org.catacomb.druid.xtext.data;
2   
3   import org.catacomb.druid.xtext.base.DocStore;
4   
5   import java.util.ArrayList;
6   import java.util.Collection;
7   import java.util.HashMap;
8   import java.util.Set;
9   
10  public class PageDataStore {
11  
12  
13      HashMap<XType, ArrayList<XItem>> itemHM;
14  
15      ArrayList<XRelation> relations;
16      HashMap<XRelationType, ArrayList<XRelation>> relationHM;
17  
18      DocStore docStore;
19  
20      public PageDataStore(DocStore ds) {
21          docStore = ds;
22          itemHM = new HashMap<XType, ArrayList<XItem>>();
23          relationHM = new HashMap<XRelationType, ArrayList<XRelation>>();
24          relations = new ArrayList<XRelation>();
25      }
26  
27  
28  
29      public void addItem(XType xt, String text) {
30          XItem xit = new XItem(xt, text);
31          addItem(xit);
32      }
33  
34  
35  
36      public void addItem(XItem xit) {
37          if (itemHM.containsKey(xit.getType())) {
38              (itemHM.get(xit.getType())).add(xit);
39          } else {
40              ArrayList<XItem> al = new ArrayList<XItem>();
41              al.add(xit);
42              itemHM.put(xit.getType(), al);
43          }
44  
45          reportChange();
46  
47      }
48  
49  
50      public void reportChange() {
51          docStore.pageDataChanged();
52      }
53  
54  
55  
56      public Set<XType> getTypes() {
57          return itemHM.keySet();
58      }
59  
60      public ArrayList<XItem> getList(XType xt) {
61          return itemHM.get(xt);
62      }
63  
64      public Collection<ArrayList<XItem>> getLists() {
65          return itemHM.values();
66      }
67  
68  
69      public void addRelation(XRelation xr) {
70          relations.add(xr);
71          if (relationHM.containsKey(xr.getRelationType())) {
72              (relationHM.get(xr.getRelationType())).add(xr);
73          } else {
74              ArrayList<XRelation> al = new ArrayList<XRelation>();
75              al.add(xr);
76              relationHM.put(xr.getRelationType(), al);
77          }
78          reportChange();
79  
80      }
81  
82  
83      public ArrayList<XRelation> getRelations() {
84          return relations;
85      }
86  
87  
88      public boolean hasRelations() {
89          return (relations.size() > 0);
90      }
91  
92  }