diff options
Diffstat (limited to 'java/src/IceGridGUI/Application/Editable.java')
-rw-r--r-- | java/src/IceGridGUI/Application/Editable.java | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/java/src/IceGridGUI/Application/Editable.java b/java/src/IceGridGUI/Application/Editable.java new file mode 100644 index 00000000000..294e0ad2b9b --- /dev/null +++ b/java/src/IceGridGUI/Application/Editable.java @@ -0,0 +1,107 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2011 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +package IceGridGUI.Application; + +class Editable implements Cloneable +{ + Editable(boolean brandNew) + { + _isNew = brandNew; + } + + boolean isNew() + { + return _isNew; + } + + boolean isModified() + { + return _modified; + } + + void markModified() + { + _modified = true; + } + + void commit() + { + _isNew = false; + _modified = false; + _removedElements.clear(); + } + + void markNew() + { + _isNew = true; + } + + void removeElement(String id, Editable editable, Class forClass) + { + if(!editable.isNew()) + { + java.util.TreeSet<String> set = _removedElements.get(forClass); + if(set == null) + { + set = new java.util.TreeSet<String>(); + _removedElements.put(forClass, set); + } + set.add(id); + } + } + + String[] removedElements(Class forClass) + { + java.util.TreeSet<String> set = _removedElements.get(forClass); + if(set == null) + { + return new String[0]; + } + else + { + return set.toArray(new String[0]); + } + } + + Editable save() + { + try + { + Editable result = (Editable)clone(); + java.util.HashMap<Class, java.util.TreeSet<String>> removedElements = + new java.util.HashMap<Class, java.util.TreeSet<String>>(); + for(java.util.Map.Entry<Class, java.util.TreeSet<String>> p : result._removedElements.entrySet()) + { + java.util.TreeSet<String> val = new java.util.TreeSet<String>(p.getValue()); + removedElements.put(p.getKey(), val); + } + result._removedElements = removedElements; + return result; + } + catch(CloneNotSupportedException e) + { + assert false; + return null; + } + } + + void restore(Editable clone) + { + _isNew = clone._isNew; + _modified = clone._modified; + _removedElements = clone._removedElements; + } + + private boolean _isNew = false; + private boolean _modified = false; + + private java.util.HashMap<Class, java.util.TreeSet<String>> _removedElements = + new java.util.HashMap<Class, java.util.TreeSet<String>>(); +} |