From: <mg...@us...> - 2006-11-08 21:21:17
|
Revision: 190 http://svn.sourceforge.net/obo/?rev=190&view=rev Author: mgibson Date: 2006-11-08 13:04:05 -0800 (Wed, 08 Nov 2006) Log Message: ----------- bulk copy is working! CompoundTransaction has .makeCopyTrans that makes a bunch of new AddTransactions as children from char list passed in that it clones - editModel on AddTransaction adds char to char list woops i realize i didnt send it to editManager - not needed now - but for undo editManager needs for tracking edits. CharTablePanel selects rows that have been copied to Modified Paths: -------------- phenote/trunk/src/java/phenote/dataadapter/CharacterListManager.java phenote/trunk/src/java/phenote/datamodel/CharacterList.java phenote/trunk/src/java/phenote/datamodel/CharacterListI.java phenote/trunk/src/java/phenote/datamodel/Ontology.java phenote/trunk/src/java/phenote/edit/CharChangeEvent.java phenote/trunk/src/java/phenote/edit/CompoundTransaction.java phenote/trunk/src/java/phenote/edit/EditManager.java phenote/trunk/src/java/phenote/edit/TransactionI.java phenote/trunk/src/java/phenote/edit/UpdateTransaction.java phenote/trunk/src/java/phenote/gui/CharacterTableModel.java phenote/trunk/src/java/phenote/gui/CharacterTablePanel.java phenote/trunk/src/java/phenote/gui/field/CharFieldGui.java Added Paths: ----------- phenote/trunk/src/java/phenote/edit/AddTransaction.java Modified: phenote/trunk/src/java/phenote/dataadapter/CharacterListManager.java =================================================================== --- phenote/trunk/src/java/phenote/dataadapter/CharacterListManager.java 2006-11-07 22:48:39 UTC (rev 189) +++ phenote/trunk/src/java/phenote/dataadapter/CharacterListManager.java 2006-11-08 21:04:05 UTC (rev 190) @@ -1,5 +1,6 @@ package phenote.dataadapter; // I think this makes more sense in dataadapter than datamodel ? +// actually should go in edit package maybe? import java.util.ArrayList; import java.util.List; Modified: phenote/trunk/src/java/phenote/datamodel/CharacterList.java =================================================================== --- phenote/trunk/src/java/phenote/datamodel/CharacterList.java 2006-11-07 22:48:39 UTC (rev 189) +++ phenote/trunk/src/java/phenote/datamodel/CharacterList.java 2006-11-08 21:04:05 UTC (rev 190) @@ -16,6 +16,7 @@ public CharacterI get(int i) { return characterList.get(i); } public void add(CharacterI c) { characterList.add(c); } public void remove(int i) { characterList.remove(i); } + public void remove(CharacterI c) { characterList.remove(c); } public int size() { return characterList.size(); } public List<CharacterI> getList() { return characterList; } Modified: phenote/trunk/src/java/phenote/datamodel/CharacterListI.java =================================================================== --- phenote/trunk/src/java/phenote/datamodel/CharacterListI.java 2006-11-07 22:48:39 UTC (rev 189) +++ phenote/trunk/src/java/phenote/datamodel/CharacterListI.java 2006-11-08 21:04:05 UTC (rev 190) @@ -11,6 +11,7 @@ public CharacterI get(int i); public void add(CharacterI c); public void remove(int i); + public void remove(CharacterI c); public int size(); public List<CharacterI> getList(); public boolean equals(CharacterListI cl); Modified: phenote/trunk/src/java/phenote/datamodel/Ontology.java =================================================================== --- phenote/trunk/src/java/phenote/datamodel/Ontology.java 2006-11-07 22:48:39 UTC (rev 189) +++ phenote/trunk/src/java/phenote/datamodel/Ontology.java 2006-11-08 21:04:05 UTC (rev 190) @@ -55,7 +55,7 @@ public String getVersion() { // this is wrong - this just says file name loaded from. obo file puts version in // remark field but doesnt seem to be way to get that from obo session?? - return oboSession.getLoadRemark(); + return oboSession.getCurrentHistory().getVersion(); } private void makeSortedLists(OBOSession oboSession) { Added: phenote/trunk/src/java/phenote/edit/AddTransaction.java =================================================================== --- phenote/trunk/src/java/phenote/edit/AddTransaction.java (rev 0) +++ phenote/trunk/src/java/phenote/edit/AddTransaction.java 2006-11-08 21:04:05 UTC (rev 190) @@ -0,0 +1,33 @@ +package phenote.edit; + +import phenote.datamodel.CharacterI; +import phenote.datamodel.CharacterListI; +// does char list manager belong in edit package? +import phenote.dataadapter.CharacterListManager; +import phenote.datamodel.CharField; + +/** For adding a character (not a char subpart - thats an update) */ + +public class AddTransaction implements TransactionI { + + private CharacterI addChar; + + public AddTransaction(CharacterI chr) { + addChar = chr; + } + + public void editModel() { + getCharList().add(addChar); + } + + public void undo() { getCharList().remove(addChar); } + + // should char list be passed in? charlistMan part of edit pkg? + private CharacterListI getCharList() { + return CharacterListManager.inst().getCharacterList(); + } + + /** this is for update trans - return false */ + public boolean isUpdateForCharField(CharField cf) { return false; } + +} Modified: phenote/trunk/src/java/phenote/edit/CharChangeEvent.java =================================================================== --- phenote/trunk/src/java/phenote/edit/CharChangeEvent.java 2006-11-07 22:48:39 UTC (rev 189) +++ phenote/trunk/src/java/phenote/edit/CharChangeEvent.java 2006-11-08 21:04:05 UTC (rev 190) @@ -7,21 +7,24 @@ /** This actually is for a CharField change - rename this CharFieldChangeEvent? */ public class CharChangeEvent extends EventObject { - // UpdateTrans -> Transaction? - private UpdateTransaction transaction; + // UpdateTrans -> Transaction? yes! + //private UpdateTransaction transaction; + private TransactionI transaction; // boolean undo??? or in trans? of just editManager? - CharChangeEvent(Object source, UpdateTransaction ut) { + CharChangeEvent(Object source, TransactionI t) { super(source); - transaction = ut; + transaction = t; } - public String getValueString() { // getNewVal, getOldVal??? - // if undo return ut.getOldValue().getName()??? - return transaction.getNewValueString(); - } +// public String getValueString() { // getNewVal, getOldVal??? +// // if undo return ut.getOldValue().getName()??? +// return transaction.getNewValueString(); +// } - public boolean isForCharField(CharField cf) { - return transaction.getCharFieldEnum() == cf.getCharFieldEnum(); + public boolean isUpdateForCharField(CharField cf) { + //return transaction.getCharFieldEnum() == cf.getCharFieldEnum(); + //if (!transaction.isUpdate()) return false; + return transaction.isUpdateForCharField(cf); } } Modified: phenote/trunk/src/java/phenote/edit/CompoundTransaction.java =================================================================== --- phenote/trunk/src/java/phenote/edit/CompoundTransaction.java 2006-11-07 22:48:39 UTC (rev 189) +++ phenote/trunk/src/java/phenote/edit/CompoundTransaction.java 2006-11-08 21:04:05 UTC (rev 190) @@ -5,22 +5,60 @@ import org.geneontology.oboedit.datamodel.OBOClass; +import phenote.datamodel.CharField; import phenote.datamodel.CharFieldEnum; import phenote.datamodel.CharacterI; public class CompoundTransaction implements TransactionI { // for now we just have UpdateTransactions - later will have Add & Del trans - List<UpdateTransaction> childTransactions = new ArrayList<UpdateTransaction>(); + List<TransactionI> childTransactions = new ArrayList<TransactionI>(); + /** for bulk updates of string/free text */ public CompoundTransaction(List<CharacterI>chars,CharFieldEnum e, String newVal) { for (CharacterI ch : chars) childTransactions.add(new UpdateTransaction(ch,e,newVal)); } + /** bulk updates of terms */ public CompoundTransaction(List<CharacterI>chars,CharFieldEnum e, OBOClass newVal) { for (CharacterI ch : chars) childTransactions.add(new UpdateTransaction(ch,e,newVal)); } - List<UpdateTransaction> getTransactions() { return childTransactions; } + private CompoundTransaction() {} + + private void addTransaction(TransactionI trans) { + childTransactions.add(trans); + } + + public static CompoundTransaction makeCopyTrans(List<CharacterI> charsToCopy) { + CompoundTransaction copyTrans = new CompoundTransaction(); + for (CharacterI c : charsToCopy) { + CharacterI copy = c.cloneCharacter(); + AddTransaction at = new AddTransaction(copy); + copyTrans.addTransaction(at); + } + return copyTrans; + } + + /** just call editModel on kids */ + public void editModel() { + for (TransactionI childTrans : childTransactions) + childTrans.editModel(); + } + + List<TransactionI> getTransactions() { return childTransactions; } + +// /** assumes all transactions have same enum which is true at moment */ +// public CharFieldEnum getCharFieldEnum() { +// return firstChild().getCharFieldEnum(); +// } + + /** queries 1st child for this. assumes all transactions have same charfield/update + status which is true at moment (change if need) */ + public boolean isUpdateForCharField(CharField cf) { + return firstChild().isUpdateForCharField(cf); + } + + private TransactionI firstChild() { return childTransactions.get(0); } } Modified: phenote/trunk/src/java/phenote/edit/EditManager.java =================================================================== --- phenote/trunk/src/java/phenote/edit/EditManager.java 2006-11-07 22:48:39 UTC (rev 189) +++ phenote/trunk/src/java/phenote/edit/EditManager.java 2006-11-08 21:04:05 UTC (rev 190) @@ -40,15 +40,21 @@ private void updateModelUpdateTrans(Object src, UpdateTransaction ut) { ut.editModel(); CharChangeEvent e = new CharChangeEvent(src,ut); - for (CharChangeListener l : charListeners) - l.charChanged(e); + fireChangeEvent(e); } - public void updateModel(Object source, CompoundTransaction ct) { + public void updateModel(Object src, CompoundTransaction ct) { transactionList.add(ct); - for (UpdateTransaction ut : ct.getTransactions()) - updateModelUpdateTrans(source,ut); + //for (TransactionI t : ct.getTransactions()) + //updateModelUpdateTrans(source,t); + ct.editModel(); + fireChangeEvent(new CharChangeEvent(src,ct)); // or should we send out a char change event with a char list?? probably } + private void fireChangeEvent(CharChangeEvent e) { + for (CharChangeListener l : charListeners) + l.charChanged(e); + } + } Modified: phenote/trunk/src/java/phenote/edit/TransactionI.java =================================================================== --- phenote/trunk/src/java/phenote/edit/TransactionI.java 2006-11-07 22:48:39 UTC (rev 189) +++ phenote/trunk/src/java/phenote/edit/TransactionI.java 2006-11-08 21:04:05 UTC (rev 190) @@ -1,7 +1,14 @@ package phenote.edit; +import phenote.datamodel.CharField; // interface? class? public interface TransactionI { + public void editModel(); + + ///** this is actually update sepcific - but thats ok i think */ + //public CharFieldEnum getCharFieldEnum(); + public boolean isUpdateForCharField(CharField cf); + //public String getValueString(); } Modified: phenote/trunk/src/java/phenote/edit/UpdateTransaction.java =================================================================== --- phenote/trunk/src/java/phenote/edit/UpdateTransaction.java 2006-11-07 22:48:39 UTC (rev 189) +++ phenote/trunk/src/java/phenote/edit/UpdateTransaction.java 2006-11-08 21:04:05 UTC (rev 190) @@ -2,6 +2,7 @@ import org.geneontology.oboedit.datamodel.OBOClass; +import phenote.datamodel.CharField; import phenote.datamodel.CharFieldEnum; import phenote.datamodel.CharFieldValue; import phenote.datamodel.CharacterI; @@ -60,7 +61,11 @@ String getNewValueString() { return newValue.getName(); } - CharFieldEnum getCharFieldEnum() { + public boolean isUpdateForCharField(CharField cf) { + return getCharFieldEnum() == cf.getCharFieldEnum(); + } + + private CharFieldEnum getCharFieldEnum() { return newValue.getCharFieldEnum(); } Modified: phenote/trunk/src/java/phenote/gui/CharacterTableModel.java =================================================================== --- phenote/trunk/src/java/phenote/gui/CharacterTableModel.java 2006-11-07 22:48:39 UTC (rev 189) +++ phenote/trunk/src/java/phenote/gui/CharacterTableModel.java 2006-11-08 21:04:05 UTC (rev 190) @@ -9,6 +9,7 @@ import phenote.datamodel.CharacterI; import phenote.datamodel.CharacterListI; import phenote.datamodel.CharFieldEnum; +import phenote.edit.CompoundTransaction; import phenote.dataadapter.CharacterListManager; import phenote.config.Config; @@ -68,14 +69,24 @@ return addCharacter(new Character()); } - /** returns row # of new copied into row */ - int copyRow(int rowToCopy) { - if (!hasRows()) - return -1; // err msg? - CharacterI copy = getCharacter(rowToCopy).cloneCharacter(); - return addCharacter(copy); +// /** returns row # of new copied into row */ +// int copyRow(int rowToCopy) { +// if (!hasRows()) +// return -1; // err msg? +// CharacterI copy = getCharacter(rowToCopy).cloneCharacter(); +// return addCharacter(copy); +// } + + /** return int[]? of all new rows to be selected? yes i think so */ + RowInterval copyChars(List<CharacterI> charsToCopy) { + CompoundTransaction ct = CompoundTransaction.makeCopyTrans(charsToCopy); + ct.editModel(); // clones & adds char to char list + fireTableRowsInserted(getRowCount(),getRowCount()); // updates table view + int rowEnd = getRowCount() - 1; // -1 -> 0 based + int rowStart = rowEnd - charsToCopy.size() + 1; // +1 inclusive + return new RowInterval(rowStart,rowEnd); // fix this - return int[]! } - + /** Returns row # of row inserted */ private int addCharacter(CharacterI character) { //++rowCount; @@ -127,6 +138,13 @@ } } + +class RowInterval { + RowInterval(int start,int end) { startRow = start; endRow = end; } + int startRow; + int endRow; +} + //--rowCount; // hmmmmm - this cant be hardwired, needs to work with config // not sure how to do this.... Modified: phenote/trunk/src/java/phenote/gui/CharacterTablePanel.java =================================================================== --- phenote/trunk/src/java/phenote/gui/CharacterTablePanel.java 2006-11-07 22:48:39 UTC (rev 189) +++ phenote/trunk/src/java/phenote/gui/CharacterTablePanel.java 2006-11-08 21:04:05 UTC (rev 190) @@ -130,6 +130,18 @@ charJTable.setRowSelectionInterval(row,row); } + private void selectRows(RowInterval selRows) { + int start = selRows.startRow, end = selRows.endRow; + if (charJTable != null && start >= 0 && end < charJTable.getRowCount()) + charJTable.setRowSelectionInterval(start,end); + } + +// private void selectRows(int start, int end) { +// if (charJTable != null && start >= 0 && end < charJTable.getRowCount()) +// charJTable.setRowSelectionInterval(start,end); +// System.out.println("sel start "+start+" end "+end+" ? "+(charJTable != null && start >= 0 && end < charJTable.getRowCount())); +// } + // used internally and by test phenote - should use sel man? CharacterI getSelectedCharacter() { return characterTableModel.getCharacter(getSelectedRow()); @@ -171,6 +183,7 @@ // bug/issue - if last row is deleted should create new blank one... public void actionPerformed(ActionEvent e) { int selectRow = 0; + RowInterval selectRows=null; if (e.getActionCommand().equals("New")) { selectRow = characterTableModel.addNewBlankRow(); scrollToNewLastRowOnRepaint = true;//scrollToLastRow(); // scroll to new row @@ -179,7 +192,8 @@ return; // no rows to copy or delete } else if (e.getActionCommand().equals("Copy")) { - selectRow = characterTableModel.copyRow(getSelectedRow()); + //selectRow = characterTableModel.copyRow(getSelectedRow()); + selectRows = characterTableModel.copyChars(getSelectedChars()); scrollToNewLastRowOnRepaint = true;//scrollToLastRow(); // scroll to new row } else if (e.getActionCommand().equals("Delete")) { @@ -203,7 +217,10 @@ //fieldPanel.clear(); // SelectionManager.clearCharacterSelection() selectRow = characterTableModel.addNewBlankRow(); // sr should be 0 } - selectRow(selectRow); + if (selectRows != null) // multi select + selectRows(selectRows); + else // single row select + selectRow(selectRow); repaint(); // check whether enable/disable del & copy buttons - disable w no rows // doesnt happen in sandbox actually - or shouldnt Modified: phenote/trunk/src/java/phenote/gui/field/CharFieldGui.java =================================================================== --- phenote/trunk/src/java/phenote/gui/field/CharFieldGui.java 2006-11-07 22:48:39 UTC (rev 189) +++ phenote/trunk/src/java/phenote/gui/field/CharFieldGui.java 2006-11-08 21:04:05 UTC (rev 190) @@ -102,7 +102,7 @@ private class FieldCharChangeListener implements CharChangeListener { public void charChanged(CharChangeEvent e) { // check charField is this char field - if (e.getSource() != CharFieldGui.this && e.isForCharField(charField)) + if (e.getSource() != CharFieldGui.this && e.isUpdateForCharField(charField)) // i think all we need to do is setText to synch with model // for complist dont we also need to set its model (not just text??) //setText(e.getValueString()); // might as well just synch with model This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |