From: <mg...@us...> - 2007-05-23 22:59:46
|
Revision: 618 http://svn.sourceforge.net/obo/?rev=618&view=rev Author: mgibson Date: 2007-05-23 15:59:47 -0700 (Wed, 23 May 2007) Log Message: ----------- well this bug took some digging but i nabbed it - undo was all wack - if you did a copy and then edited on the copy undo would actually undo on the original not the copy which was hard to even realize thats what was going on it turns out it was a cloning issue - it was only doing a shallow copy of the hash of char field values - that meant the old char field values for undo were still pointing to the old oricginal characters not the new ones nicole i think this fixes all the undo bugs you put in the tracker item i fiddled with it and it seems so - let me know if you still see undo bugs Modified Paths: -------------- phenote/trunk/src/java/phenote/datamodel/CharFieldValue.java phenote/trunk/src/java/phenote/datamodel/Character.java Modified: phenote/trunk/src/java/phenote/datamodel/CharFieldValue.java =================================================================== --- phenote/trunk/src/java/phenote/datamodel/CharFieldValue.java 2007-05-22 18:48:36 UTC (rev 617) +++ phenote/trunk/src/java/phenote/datamodel/CharFieldValue.java 2007-05-23 22:59:47 UTC (rev 618) @@ -11,7 +11,7 @@ should this be merged with CharField? im forgetting the rationale for having it be separate??? oh wait CharField is the generic field, CharFieldValue is an actual instance of data within the CharField - linked via CharFieldEnum & Character*/ -public class CharFieldValue { +public class CharFieldValue implements Cloneable { private OBOClass oboClassValue=null; private String stringValue=null; @@ -56,6 +56,11 @@ charField = cf; } + CharFieldValue cloneCharFieldValue() { + try { return (CharFieldValue)clone(); } + catch (CloneNotSupportedException x) { return null; } + } + // hmmmmm.... needed if post comp done inframe // public CharFieldValue(OBOClass o,CharacterI c,CharFieldEnum e, boolean isDifferentia) { // this(o,c,e); @@ -69,6 +74,8 @@ return new CharFieldValue((String)null,c,cf); // ""? } + void setCharacter(CharacterI c) { character = c; } + boolean isEmpty() { if (isOboClass) return oboClassValue == null; Modified: phenote/trunk/src/java/phenote/datamodel/Character.java =================================================================== --- phenote/trunk/src/java/phenote/datamodel/Character.java 2007-05-22 18:48:36 UTC (rev 617) +++ phenote/trunk/src/java/phenote/datamodel/Character.java 2007-05-23 22:59:47 UTC (rev 618) @@ -10,7 +10,7 @@ was called a Phenotype which was a misnomer Should the Character datamodel be a generic hash of CharField-CharFieldValues? That can be free text or from ontologies? */ -public class Character implements CharacterI, Cloneable { +public class Character implements CharacterI { private HashMap<CharField,CharFieldValue> charFieldToValue = new HashMap<CharField,CharFieldValue>(); @@ -27,6 +27,7 @@ /** for generic fields its just a map from char field to char field value */ public void setValue(CharField cf, CharFieldValue cfv) { + cfv.setCharacter(this); charFieldToValue.put(cf,cfv); //System.out.println("Char setVal "+cf+" val "+cfv); // setOboEditModel(oboEditAnnotation,cf,cfv); @@ -196,12 +197,19 @@ } public CharacterI cloneCharacter() { - try { - // do OBOClasses clone? do we need to clone them? - Character clone = (Character)clone(); - clone.charFieldToValue = (HashMap<CharField,CharFieldValue>)charFieldToValue.clone(); - return clone; - } catch (CloneNotSupportedException e) { return null; } + //try { + // do OBOClasses clone? do we need to clone them? dont think so - immutable + Character charClone = new Character(); //(Character)clone(); + // WRONG - will use same charFieldVal which points to old char!! +// clone.charFieldToValue =(HashMap<CharField,CharFieldValue>)charFieldToValue.clone(); + // clone.setCharFieldValuesCharacterToSelf(); ??? + for (CharFieldValue v : charFieldToValue.values()) { + CharFieldValue cfvClone = v.cloneCharFieldValue(); + // cfvClone.setCharacter(charClone); done by setValue + charClone.setValue(cfvClone.getCharField(),cfvClone); + } + return charClone; + //} catch (CloneNotSupportedException e) { return null; } } // used by character table panel This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |