Changeset 3132
Legend:
- Unmodified
- Added
- Removed
-
trunk/plugins/visualization/org/pathvisio/visualization/gui/VisualizationDialog.java
r2979 r3132 20 20 import java.awt.Frame; 21 21 22 import javax.swing.JOptionPane; 22 23 import javax.swing.JScrollPane; 23 24 25 import org.pathvisio.debug.Logger; 24 26 import org.pathvisio.gui.swing.dialogs.OkCancelDialog; 25 27 import org.pathvisio.visualization.Visualization; … … 62 64 63 65 protected void okPressed() { 64 visMgr.saveXML(); //Save the settings 66 try 67 { 68 visMgr.saveXML(); //Save the settings 69 } 70 catch (Exception ex) 71 { 72 Logger.log.error ("Couldn't save visualization", ex); 73 JOptionPane.showMessageDialog(this,"Couldn't write modifications to disk.\n" + ex.getMessage() + 74 "\nSee error log for details.", 75 "Couldn't save visualization", JOptionPane.ERROR_MESSAGE); 76 } 65 77 super.okPressed(); 66 78 } -
trunk/src/swing/org/pathvisio/visualization/VisualizationManager.java
r3120 r3132 279 279 public static final String ROOT_XML_ELEMENT = "expression-data-visualizations"; 280 280 281 p ublicInputStream getXmlInput()281 private InputStream getXmlInput() 282 282 { 283 283 File xmlFile = new File(gexManager.getCurrentGex().getDbName() + ".xml"); … … 293 293 } 294 294 295 public OutputStream getXmlOutput() { 296 try { 297 File f = new File(gexManager.getCurrentGex().getDbName() + ".xml"); 298 Logger.log.trace("Visualization settings will be saved to: " + f); 299 OutputStream out = new FileOutputStream(f); 300 return out; 301 } catch(Exception e) { 302 Logger.log.error("Unable to create visualization settings file", e); 303 return null; 304 } 305 } 306 307 public void saveXML() { 295 public void saveXML() throws IOException 296 { 308 297 if(!gexManager.isConnected()) return; 309 298 310 OutputStream out = getXmlOutput(); 299 // write to a temporary file, rename to final file after write was successful. 300 File finalFile = new File(gexManager.getCurrentGex().getDbName() + ".xml"); 301 File tempFile = File.createTempFile(finalFile.getName(), ".tmp", finalFile.getParentFile()); 302 OutputStream out = new FileOutputStream(tempFile); 311 303 312 304 Logger.log.trace("Saving visualizations and color sets to xml: " + out); … … 318 310 319 311 Element vis = new Element(XML_ELEMENT); 320 321 312 for(Visualization v : getVisualizations()) { 322 313 vis.addContent(v.toXML()); … … 325 316 326 317 XMLOutputter xmlOut = new XMLOutputter(Format.getPrettyFormat()); 327 328 try { 329 xmlOut.output(xmlDoc, out); 330 out.close(); 331 } catch(IOException e) { 332 Logger.log.error("Unable to save visualization settings", e); 333 } 318 xmlOut.output(xmlDoc, out); 319 out.close(); 320 321 if (finalFile.exists()) finalFile.delete(); 322 if (!tempFile.renameTo(finalFile)) throw new IOException ("Couldn't rename temporary file"); 334 323 } 335 324 … … 369 358 doc = parser.build(in); 370 359 in.close(); 371 372 360 root = doc.getRootElement(); 373 361 } catch(Exception e) { … … 375 363 root = new Element(ROOT_XML_ELEMENT); 376 364 doc.setRootElement(root); 377 378 365 } 379 366 return doc;
