From: <ba...@us...> - 2009-01-29 19:44:28
|
Revision: 2395 http://obo.svn.sourceforge.net/obo/?rev=2395&view=rev Author: balhoff Date: 2009-01-29 19:44:25 +0000 (Thu, 29 Jan 2009) Log Message: ----------- Added warning panel to be displayed when a file is opened which contains references to secondary IDs. Also fixed a bug which set the active file path to a file which the user cancelled opening. Modified Paths: -------------- phenex/trunk/lib/obdapi.jar phenex/trunk/lib/oboedit.jar phenex/trunk/lib/phenote.jar phenex/trunk/src/org/phenoscape/app/DocumentController.java phenex/trunk/src/org/phenoscape/io/NeXMLReader.java phenex/trunk/src/org/phenoscape/model/PhenoscapeController.java Added Paths: ----------- phenex/trunk/src/org/phenoscape/app/UserCancelledReadException.java Modified: phenex/trunk/lib/obdapi.jar =================================================================== (Binary files differ) Modified: phenex/trunk/lib/oboedit.jar =================================================================== (Binary files differ) Modified: phenex/trunk/lib/phenote.jar =================================================================== (Binary files differ) Modified: phenex/trunk/src/org/phenoscape/app/DocumentController.java =================================================================== --- phenex/trunk/src/org/phenoscape/app/DocumentController.java 2009-01-29 16:31:15 UTC (rev 2394) +++ phenex/trunk/src/org/phenoscape/app/DocumentController.java 2009-01-29 19:44:25 UTC (rev 2395) @@ -52,7 +52,12 @@ this.getUndoController().markChangesSaved(); } catch (IOException e) { log().error("Failed to load file data", e); - this.runFileReadErrorMessage(file, e.getLocalizedMessage()); + if (e instanceof UserCancelledReadException) { + // user cancelled file load, don't show an error message + return; + } else { + this.runFileReadErrorMessage(file, e.getLocalizedMessage()); + } } } } @@ -69,8 +74,13 @@ this.getUndoController().discardAllEdits(); this.getUndoController().markChangesSaved(); } catch (IOException e) { - log().error("Failed to load file data", e); - this.runFileReadErrorMessage(file, e.getLocalizedMessage()); + if (e instanceof UserCancelledReadException) { + // user cancelled file load, don't show an error message + return; + } else { + log().error("Failed to load file data", e); + this.runFileReadErrorMessage(file, e.getLocalizedMessage()); + } } } } Added: phenex/trunk/src/org/phenoscape/app/UserCancelledReadException.java =================================================================== --- phenex/trunk/src/org/phenoscape/app/UserCancelledReadException.java (rev 0) +++ phenex/trunk/src/org/phenoscape/app/UserCancelledReadException.java 2009-01-29 19:44:25 UTC (rev 2395) @@ -0,0 +1,15 @@ +package org.phenoscape.app; + +import java.io.IOException; + +public class UserCancelledReadException extends IOException { + + public UserCancelledReadException() { + super(); + } + + public UserCancelledReadException(String s) { + super(s); + } + +} Modified: phenex/trunk/src/org/phenoscape/io/NeXMLReader.java =================================================================== --- phenex/trunk/src/org/phenoscape/io/NeXMLReader.java 2009-01-29 16:31:15 UTC (rev 2394) +++ phenex/trunk/src/org/phenoscape/io/NeXMLReader.java 2009-01-29 19:44:25 UTC (rev 2395) @@ -3,11 +3,12 @@ import java.io.File; import java.io.IOException; import java.io.Reader; -import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.UUID; import org.apache.log4j.Logger; @@ -52,7 +53,8 @@ private final DataSet data = new DataSet(); private final NexmlDocument xmlDoc; private final OBOSession session; - private final List<String> danglers = new ArrayList<String>(); + private final Set<String> danglers = new HashSet<String>(); + private final Set<String> secondaryIDs = new HashSet<String>(); private String charactersBlockID = UUID.randomUUID().toString(); public NeXMLReader(File aFile, OBOSession session) throws XmlException, IOException { @@ -89,9 +91,23 @@ /** * Returns the list of IDs referenced in the file that were not found in the OBOSession. */ - public List<String> getDanglersList() { + public Collection<String> getDanglersList() { return this.danglers; } + + /** + * Returns true if the reader had to find any referenced terms via a secondary ID. + */ + public boolean didMigrateSecondaryIDs() { + return !this.secondaryIDs.isEmpty(); + } + + /** + * Returns the list of IDs referenced in the file that were found to be secondary IDs. + */ + public Collection<String> getMigratedSecondaryIDsList() { + return this.secondaryIDs; + } private void parseNeXML() { final Dict metadata = NeXMLUtil.findOrCreateMetadataDict(this.xmlDoc); @@ -145,6 +161,7 @@ newState.addPhenotype(((PhenoXMLPhenotypeWrapper)phenotype).getPhenotype()); } this.danglers.addAll(adapter.getDanglersList()); + this.secondaryIDs.addAll(adapter.getMigratedSecondaryIDsList()); } catch (XmlException e) { log().error("Failed to parse OBO phenotype", e); } @@ -269,6 +286,7 @@ if (object instanceof OBOClass) { final OBOClass term = (OBOClass)object; if (term.getSecondaryIDs().contains(id)) { + this.secondaryIDs.add(id); return term; } } Modified: phenex/trunk/src/org/phenoscape/model/PhenoscapeController.java =================================================================== --- phenex/trunk/src/org/phenoscape/model/PhenoscapeController.java 2009-01-29 16:31:15 UTC (rev 2394) +++ phenex/trunk/src/org/phenoscape/model/PhenoscapeController.java 2009-01-29 19:44:25 UTC (rev 2395) @@ -3,6 +3,7 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import java.util.UUID; @@ -15,6 +16,7 @@ import org.bbop.framework.GUIManager; import org.biojava.bio.seq.io.ParseException; import org.nexml.x10.NexmlDocument; +import org.phenoscape.app.UserCancelledReadException; import org.phenoscape.app.DocumentController; import org.phenoscape.io.CharacterTabReader; import org.phenoscape.io.NEXUSReader; @@ -152,8 +154,16 @@ final NeXMLReader reader = new NeXMLReader(aFile, this.getOntologyController().getOBOSession()); if (reader.didCreateDanglers()) { final boolean result = this.runDanglerAlert(aFile, reader.getDanglersList()); - if (!result) { return; } + if (!result) { + throw new UserCancelledReadException(); + } } + if (reader.didMigrateSecondaryIDs()) { + final boolean result = this.runSecondaryIDAlert(aFile, reader.getMigratedSecondaryIDsList()); + if (!result) { + throw new UserCancelledReadException(); + } + } this.xmlDoc = reader.getXMLDoc(); this.charactersBlockID = reader.getCharactersBlockID(); this.dataSet.getCharacters().clear(); //TODO this is not well encapsulated @@ -298,13 +308,19 @@ } } - private boolean runDanglerAlert(File file, List<String> danglerIDs) { + private boolean runDanglerAlert(File file, Collection<String> danglerIDs) { final String[] options = {"Continue Opening", "Cancel"}; final String message = "The file \"" + file.getName() + "\" contains references to ontology term IDs which could not be found. You can safely edit other values in the file, but fields referring to \"dangling\" terms should not be edited. Proceed with caution."; final int result = JOptionPane.showOptionDialog(null, message, "Missing Terms", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]); return result == JOptionPane.YES_OPTION; } + private boolean runSecondaryIDAlert(File file, Collection<String> secondaryIDs) { + final String[] options = {"Continue Opening", "Cancel"}; + final String message = "The file \"" + file.getName() + "\" contains references to some ontology terms by secondary IDs. When you save this file, these term references will be migrated to each term's primary ID."; + final int result = JOptionPane.showOptionDialog(null, message, "Secondary Identifiers", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]); + return result == JOptionPane.YES_OPTION; + } private Logger log() { return Logger.getLogger(this.getClass()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |