1 23 24 package org.objectweb.fractal.gui.history.model; 25 26 import org.objectweb.fractal.api.control.BindingController; 27 28 import org.objectweb.fractal.gui.model.ClientInterface; 29 import org.objectweb.fractal.gui.model.Component; 30 import org.objectweb.fractal.gui.model.Configuration; 31 import org.objectweb.fractal.gui.model.ConfigurationListener; 32 import org.objectweb.fractal.gui.model.Interface; 33 import org.objectweb.fractal.gui.model.ServerInterface; 34 35 import java.util.ArrayList ; 36 import java.util.List ; 37 import java.util.Map ; 38 import java.util.HashMap ; 39 import java.util.Iterator ; 40 41 44 45 public class BasicHistoryManager 46 implements HistoryManager, ConfigurationListener, BindingController 47 { 48 49 54 55 public final static String CONFIGURATION_BINDING = "configuration"; 56 57 61 62 public final static String HISTORY_LISTENERS_BINDING = "history-listeners"; 63 64 67 68 private final static int MAX_HISTORY = 50; 69 70 73 74 private Configuration configuration; 75 76 79 80 private Map historyListeners; 81 82 86 87 private List previousRoots; 88 89 94 95 private List nextRoots; 96 97 100 101 private boolean isGoingPrevious; 102 103 106 107 private boolean isGoingNext; 108 109 112 113 public BasicHistoryManager () { 114 previousRoots = new ArrayList (); 115 nextRoots = new ArrayList (); 116 historyListeners = new HashMap (); 117 } 118 119 123 public String [] listFc () { 124 int size = historyListeners.size(); 125 String [] names = new String [size + 1]; 126 historyListeners.keySet().toArray(names); 127 names[size] = CONFIGURATION_BINDING; 128 return names; 129 } 130 131 public Object lookupFc (final String clientItfName) { 132 if (CONFIGURATION_BINDING.equals(clientItfName)) { 133 return configuration; 134 } else if (clientItfName.startsWith(HISTORY_LISTENERS_BINDING)) { 135 return historyListeners.get(clientItfName); 136 } 137 return null; 138 } 139 140 public void bindFc ( 141 final String clientItfName, 142 final Object serverItf) 143 { 144 if (CONFIGURATION_BINDING.equals(clientItfName)) { 145 configuration = (Configuration)serverItf; 146 } else if (clientItfName.startsWith(HISTORY_LISTENERS_BINDING)) { 147 historyListeners.put(clientItfName, serverItf); 148 } 149 } 150 151 public void unbindFc (final String clientItfName) { 152 if (CONFIGURATION_BINDING.equals(clientItfName)) { 153 configuration = null; 154 } else if (clientItfName.startsWith(HISTORY_LISTENERS_BINDING)) { 155 historyListeners.remove(clientItfName); 156 } 157 } 158 159 163 public void changeCountChanged (Component component, long changeCount) { 164 } 166 167 public void rootComponentChanged (final Component oldModel) { 168 if (oldModel == null) { 169 return; 170 } 171 if (oldModel.getRootComponent() != 172 configuration.getRootComponent().getRootComponent()) 173 { 174 clear(); 175 return; 176 } 177 if (isGoingPrevious) { 178 nextRoots.add(oldModel); 179 if (nextRoots.size() == 1) { 180 notifyListeners(); 181 } 182 } else { 183 int size = previousRoots.size(); 184 if (size >= MAX_HISTORY) { 185 previousRoots.remove(0); 186 } 187 previousRoots.add(oldModel); 188 if (!isGoingNext) { 189 nextRoots.clear(); 190 } 191 if (previousRoots.size() == 1 || !isGoingNext) { 192 notifyListeners(); 193 } 194 } 195 } 196 197 public void nameChanged (final Component component, final String oldValue) { 198 } 200 201 public void typeChanged (final Component component, final String oldValue) { 202 } 204 205 public void implementationChanged ( 206 final Component component, 207 final String oldValue) { 208 } 210 211 public void interfaceNameChanged (final Interface i, final String oldValue) { 212 } 214 215 public void interfaceSignatureChanged ( 216 final Interface i, 217 final String oldValue) 218 { 219 } 221 222 public void interfaceContingencyChanged ( 223 final Interface i, 224 final boolean oldValue) 225 { 226 } 228 229 public void interfaceCardinalityChanged ( 230 final Interface i, 231 final boolean oldValue) 232 { 233 } 235 236 public void clientInterfaceAdded ( 237 final Component component, 238 final ClientInterface i, 239 final int index) 240 { 241 } 243 244 public void clientInterfaceRemoved ( 245 final Component component, 246 final ClientInterface i, 247 final int index) 248 { 249 } 251 252 public void serverInterfaceAdded ( 253 final Component component, 254 final ServerInterface i, 255 final int index) 256 { 257 } 259 260 public void serverInterfaceRemoved ( 261 final Component component, 262 final ServerInterface i, 263 final int index) 264 { 265 } 267 268 public void interfaceBound ( 269 final ClientInterface citf, 270 final ServerInterface sitf) 271 { 272 } 274 275 public void interfaceRebound ( 276 final ClientInterface citf, 277 final ServerInterface oldSitf) 278 { 279 } 281 282 public void interfaceUnbound ( 283 final ClientInterface citf, 284 final ServerInterface sitf) 285 { 286 } 288 289 public void attributeControllerChanged ( 290 final Component component, 291 final String oldValue) 292 { 293 } 295 296 public void attributeChanged ( 297 final Component component, 298 final String attributeName, 299 final String oldValue) 300 { 301 } 303 304 public void templateControllerDescriptorChanged ( 305 final Component component, 306 final String oldValue) 307 { 308 } 310 311 public void componentControllerDescriptorChanged ( 312 final Component component, 313 final String oldValue) 314 { 315 } 317 318 public void subComponentAdded ( 319 final Component parent, 320 final Component child, 321 final int index) 322 { 323 } 325 326 public void subComponentRemoved ( 327 final Component parent, 328 final Component child, 329 final int index) 330 { 331 } 333 334 338 public boolean canGoPrevious () { 339 return previousRoots.size() > 0; 340 } 341 342 public void goPrevious () { 343 isGoingPrevious = true; 344 try { 345 Component root = (Component)previousRoots.remove(previousRoots.size()-1); 346 configuration.setRootComponent(root); 347 } finally { 348 isGoingPrevious = false; 349 } 350 if (previousRoots.size() == 0) { 351 notifyListeners(); 352 } 353 } 354 355 public boolean canGoNext () { 356 return nextRoots.size() > 0; 357 } 358 359 public void goNext () { 360 isGoingNext = true; 361 try { 362 Component root = (Component)nextRoots.remove(nextRoots.size() - 1); 363 configuration.setRootComponent(root); 364 } finally { 365 isGoingNext = false; 366 } 367 if (nextRoots.size() == 0) { 368 notifyListeners(); 369 } 370 } 371 372 public void clear () { 373 nextRoots.clear(); 374 previousRoots.clear(); 375 notifyListeners(); 376 } 377 378 382 385 386 private void notifyListeners () { 387 Iterator i = historyListeners.values().iterator(); 388 while (i.hasNext()) { 389 ((HistoryListener)i.next()).historyStateChanged(); 390 } 391 } 392 } 393 | Popular Tags |