1 13 package com.tonbeller.jpivot.core; 14 15 import java.util.ArrayList ; 16 import java.util.Collection ; 17 import java.util.HashMap ; 18 import java.util.Iterator ; 19 import java.util.Locale ; 20 import java.util.Map ; 21 22 26 27 public class ModelSupport implements Model { 28 29 private Collection listeners = new ArrayList (); 30 private Map extensionMap = new HashMap (); 31 private Locale locale; 32 private Model decoratedModel; 33 34 public ModelSupport() { 35 decoratedModel = this; 36 } 37 38 41 public void destroy() { 42 listeners.clear(); 43 extensionMap.clear(); 44 locale = null; 45 decoratedModel = null; 46 } 47 48 51 public Extension getExtension(String id) { 52 return (Extension) extensionMap.get(id); 53 } 54 55 59 public Map getExtensions() { 60 return extensionMap; 61 } 62 63 66 public void addExtension(Extension extension) { 67 extensionMap.put(extension.getId(), extension); 68 extension.setModel(this); 69 decoratedModel = extension.decorate(decoratedModel); 70 } 71 72 75 public Object getBookmarkState(int levelOfDetail) { 76 return null; 77 } 78 79 82 public void setBookmarkState(Object state) { 83 } 84 85 88 public void addModelChangeListener(ModelChangeListener l) { 89 listeners.add(l); 90 } 91 92 95 public void removeModelChangeListener(ModelChangeListener l) { 96 listeners.remove(l); 97 } 98 99 public void fireModelChanged() { 100 fireModelChanged(new ModelChangeEvent(this)); 101 } 102 103 public void fireModelChanged(ModelChangeEvent e) { 104 Iterator it = listeners.iterator(); 105 while (it.hasNext()) 106 ((ModelChangeListener) it.next()).modelChanged(e); 107 } 108 109 public void fireStructureChanged() { 110 fireStructureChanged(new ModelChangeEvent(this)); 111 } 112 113 public void fireStructureChanged(ModelChangeEvent e) { 114 Iterator it = listeners.iterator(); 115 while (it.hasNext()) 116 ((ModelChangeListener) it.next()).structureChanged(e); 117 } 118 119 123 public Locale getLocale() { 124 if (locale == null) 125 return Locale.getDefault(); 126 return locale; 127 } 128 129 133 public void setLocale(Locale locale) { 134 this.locale = locale; 135 } 136 137 140 public Model getTopDecorator() { 141 return decoratedModel; 142 } 143 144 public Model getRootModel() { 145 return this; 146 } 147 } 148 | Popular Tags |