use of au.gov.asd.tac.constellation.graph.file.io.GraphJsonWriter in project constellation by constellation-app.
the class SaveTemplatePlugin method saveTemplate.
private void saveTemplate(final GraphReadMethods graph, final String templateName) throws PluginException {
final Preferences prefs = NbPreferences.forModule(ApplicationPreferenceKeys.class);
final String userDir = ApplicationPreferenceKeys.getUserDir(prefs);
final File templateDir = new File(userDir, TEMPLATE_DIR);
final File oldTemplate = new File(templateDir, NewSchemaGraphAction.getTemplateNames().get(templateName) + "/" + templateName);
if (oldTemplate.exists()) {
final boolean oldTemplateIsDeleted = oldTemplate.delete();
if (!oldTemplateIsDeleted) {
// TODO: Handle case where file not successfully deleted
}
}
if (!templateDir.exists()) {
templateDir.mkdir();
}
if (!templateDir.isDirectory()) {
final String msg = String.format("Can't create template directory '%s'.", templateDir);
final NotifyDescriptor nd = new NotifyDescriptor.Message(msg, NotifyDescriptor.ERROR_MESSAGE);
DialogDisplayer.getDefault().notify(nd);
return;
}
final File schemaDir = new File(templateDir, graph.getSchema().getFactory().getName());
if (!schemaDir.exists()) {
schemaDir.mkdir();
}
if (!schemaDir.isDirectory()) {
final String msg = String.format("Can't create template directory '%s'.", schemaDir);
final NotifyDescriptor nd = new NotifyDescriptor.Message(msg, NotifyDescriptor.ERROR_MESSAGE);
DialogDisplayer.getDefault().notify(nd);
return;
}
final File saveFile = new File(schemaDir, templateName);
try {
new GraphJsonWriter().writeTemplateToZip(graph, saveFile.getPath(), new HandleIoProgress("Saving Template..."));
} catch (IOException ex) {
throw new PluginException(this, PluginNotificationLevel.ERROR, "Failed to save template", ex);
}
}
use of au.gov.asd.tac.constellation.graph.file.io.GraphJsonWriter in project constellation by constellation-app.
the class ExportToJsonPlugin method read.
@Override
public void read(final GraphReadMethods rg, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
final String filename = parameters.getParameters().get(FILE_NAME_PARAMETER_ID).getStringValue();
try {
new GraphJsonWriter().writeGraphFile(rg, filename, new HandleIoProgress("Exporting..."));
ConstellationLoggerHelper.exportPropertyBuilder(this, GraphRecordStoreUtilities.getVertices(rg, false, false, false).getAll(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL), new File(filename), ConstellationLoggerHelper.SUCCESS);
} catch (final IOException ex) {
LOGGER.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
}
}
Aggregations