use of au.gov.asd.tac.constellation.graph.attribute.ZonedDateTimeAttributeDescription in project constellation by constellation-app.
the class VisualGraphOpener method openGraph.
/**
* Open a graph file into a VisualTopComponent.
* <p>
* A check is done to see if the file to be opened is already open. If it
* is, that TopComponent is made active, rather than opening the file again.
*
* @param gdo The GraphDataObject to read from.
*/
@Override
public void openGraph(final GraphDataObject gdo) {
for (TopComponent tc : TopComponent.getRegistry().getOpened()) {
if (tc instanceof VisualGraphTopComponent) {
// Get the VisualTopComponent's GraphDataObject from its Lookup.
// Two DataObjects are equivalent if their primary files are equal.
final GraphDataObject existingGdo = tc.getLookup().lookupAll(GraphDataObject.class).iterator().next();
if (gdo.equals(existingGdo)) {
tc.requestActive();
return;
}
}
}
// The file isn't already open.
// Check to see if there is a more recent autosave for this file.
// If there is, ask the user if they want to open it.
final File f = FileUtil.toFile(gdo.getPrimaryFile());
final Properties props = AutosaveUtilities.getAutosave(f);
if (props != null) {
final String dtprop = props.getProperty(AutosaveUtilities.DT);
if (dtprop != null) {
final ZonedDateTimeAttributeDescription datetimeAttributeDescription = new ZonedDateTimeAttributeDescription();
final ZonedDateTime zdtAutosave = datetimeAttributeDescription.convertFromString(dtprop);
final long dtFile = f.lastModified();
final long zdtAutosaveSeconds = zdtAutosave.toEpochSecond() * 1000;
if (zdtAutosaveSeconds > dtFile) {
final String dateTime = new Date(zdtAutosaveSeconds).toString();
final String dtf = new Date(dtFile).toString();
final String msg = Bundle.MSG_Autosave(f.getPath(), dtf, dateTime);
final NotifyDescriptor nd = new NotifyDescriptor(msg, "Open autosaved file?", NotifyDescriptor.YES_NO_OPTION, NotifyDescriptor.QUESTION_MESSAGE, null, null);
if (DialogDisplayer.getDefault().notify(nd) == NotifyDescriptor.YES_OPTION) {
// The user wants the more recent autosaved version.
// Backup the current actual file and replace it with the autosave file.
final File autosaved = new File(AutosaveUtilities.getAutosaveDir(), props.getProperty(AutosaveUtilities.ID) + FileExtensionConstants.STAR);
try {
AutosaveUtilities.copyFile(autosaved, f);
} catch (final IOException ex) {
LOGGER.log(Level.WARNING, "Copying autosaved file", ex);
}
}
AutosaveUtilities.deleteAutosave(props.getProperty(AutosaveUtilities.ID));
}
}
}
// The file isn't already open, so open it.
new GraphFileOpener(gdo, null, null).execute();
}
Aggregations