@Override public Presentation getCurrent() { checkLoad(); return current; }
@Override public Presentation getPresentation(Object id) { checkLoad(); return presentations.get(id); }
@Override public Collection<Object> getPresentationIds() { checkLoad(); return Collections.unmodifiableCollection(presentations.keySet()); }
@Override public void setCurrent(Presentation p) { checkLoad(); if (p == null) { Object old = current; current = null; fireCurrentPresentationChanged(old); } else if (presentations.containsKey(p.getId())) { Object old = current; current = p; fireCurrentPresentationChanged(old); } else { throw new IllegalStateException(String.format("Invalid presentation: %s", p.getId())); } }
@Override public void add(Presentation p) { checkLoad(); presentations.put(p.getId(), p); if (PersistenceHelper.isNew(p)) { needToUpdate.add(p); if (BooleanUtils.isTrue(p.getDefault())) { def = p; } } firePresentationsSetChanged(); }
@Override public void remove(Presentation p) { checkLoad(); if (presentations.remove(p.getId()) != null) { if (PersistenceHelper.isNew(p)) { needToUpdate.remove(p); } else { needToUpdate.remove(p); needToRemove.add(p); } if (p.equals(def)) { def = null; } if (p.equals(current)) { current = null; } firePresentationsSetChanged(); } }
@Override public void modify(Presentation p) { checkLoad(); if (presentations.containsKey(p.getId())) { needToUpdate.add(p); if (BooleanUtils.isTrue(p.getDefault())) { setDefault(p); } else if (def != null && def.getId().equals(p.getId())) { setDefault(null); } } else { throw new IllegalStateException(String.format("Invalid presentation: %s", p.getId())); } }
@Override public void setDefault(Presentation p) { checkLoad(); if (p == null) { Object old = def; def = null; fireDefaultPresentationChanged(old); } else if (presentations.containsKey(p.getId())) { Object old = def; if (def != null) { def.setDefault(false); } p.setDefault(true); def = p; fireDefaultPresentationChanged(old); } else { throw new IllegalStateException(String.format("Invalid presentation: %s", p.getId())); } }