Search in sources :

Example 6 with GraphJsonWriter

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);
    }
}
Also used : NotifyDescriptor(org.openide.NotifyDescriptor) GraphJsonWriter(au.gov.asd.tac.constellation.graph.file.io.GraphJsonWriter) HandleIoProgress(au.gov.asd.tac.constellation.utilities.gui.HandleIoProgress) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) IOException(java.io.IOException) Preferences(java.util.prefs.Preferences) NbPreferences(org.openide.util.NbPreferences) File(java.io.File)

Example 7 with GraphJsonWriter

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);
    }
}
Also used : GraphJsonWriter(au.gov.asd.tac.constellation.graph.file.io.GraphJsonWriter) HandleIoProgress(au.gov.asd.tac.constellation.utilities.gui.HandleIoProgress) IOException(java.io.IOException) File(java.io.File)

Aggregations

GraphJsonWriter (au.gov.asd.tac.constellation.graph.file.io.GraphJsonWriter)7 File (java.io.File)5 TextIoProgress (au.gov.asd.tac.constellation.utilities.gui.TextIoProgress)4 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)3 HandleIoProgress (au.gov.asd.tac.constellation.utilities.gui.HandleIoProgress)3 IOException (java.io.IOException)3 WritableGraph (au.gov.asd.tac.constellation.graph.WritableGraph)2 Graph (au.gov.asd.tac.constellation.graph.Graph)1 GraphReadMethods (au.gov.asd.tac.constellation.graph.GraphReadMethods)1 GraphNode (au.gov.asd.tac.constellation.graph.node.GraphNode)1 PluginException (au.gov.asd.tac.constellation.plugins.PluginException)1 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 Date (java.util.Date)1 Properties (java.util.Properties)1 Preferences (java.util.prefs.Preferences)1 NotifyDescriptor (org.openide.NotifyDescriptor)1 NbPreferences (org.openide.util.NbPreferences)1