Search in sources :

Example 1 with ProjectWriter

use of eu.esdihumboldt.hale.common.core.io.project.ProjectWriter in project hale by halestudio.

the class ProjectServiceImpl method save.

/**
 * @see ProjectService#save()
 */
@Override
public void save() {
    File projectFile;
    IOConfiguration saveConfig;
    synchronized (this) {
        projectFile = this.projectFile;
        saveConfig = main.getSaveConfiguration();
    }
    if (projectFile != null || canSaveTo(projectLocation)) {
        Collection<IOProviderDescriptor> providers = HaleIO.getProviderFactories(ProjectWriter.class);
        // use configuration from previous save if possible
        if (saveConfig != null) {
            // get provider ...
            ProjectWriter writer = null;
            for (IOProviderDescriptor factory : providers) {
                if (factory.getIdentifier().equals(saveConfig.getProviderId())) {
                    /*
						 * Check if the content type the project was loaded with
						 * is supported for saving.
						 * 
						 * Example for a changed content type: A saved project
						 * archive may have been extracted and the internal XML
						 * project file loaded.
						 */
                    if (projectLoadContentType != null) {
                        if (factory.getSupportedTypes() == null || !factory.getSupportedTypes().contains(projectLoadContentType)) {
                            log.warn("Project cannot be saved with the same settings it was originally saved with, as the content type has changed.");
                            break;
                        }
                    }
                    try {
                        writer = (ProjectWriter) factory.createExtensionObject();
                    } catch (Exception e) {
                        log.error("Could not create project writer", e);
                    }
                }
            }
            if (writer != null) {
                // configure provider
                writer.loadConfiguration(saveConfig.getProviderConfiguration());
                // moved externally)
                if (projectFile != null) {
                    writer.setTarget(new FileIOSupplier(projectFile));
                } else {
                    writer.setTarget(new NoStreamOutputSupplier(projectLocation));
                }
                ListenableFuture<IOReport> result = ProjectResourcesUtil.executeProvider(writer, saveProjectAdvisor, true, null);
                PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            IOReport report = result.get();
                            if (!report.isSuccess()) {
                                log.userError("The project could not be saved. Please check the report for more details.");
                            }
                        } catch (InterruptedException | ExecutionException e) {
                            log.userError("The project could not be saved.", e);
                        }
                    }
                });
            } else {
                log.info("The project cannot be saved because the format the project was saved with is not available or has changed.");
                // use save as instead
                saveAs();
            }
        } else if (projectFile != null) {
            // use I/O provider and content type mechanisms to try saving
            // the project file
            ProjectWriter writer = HaleIO.findIOProvider(ProjectWriter.class, new FileIOSupplier(projectFile), projectFile.getAbsolutePath());
            if (writer != null) {
                ProjectResourcesUtil.executeProvider(writer, saveProjectAdvisor, null);
            } else {
                log.error("The project cannot be saved because the format is not available.");
                // use save as instead
                saveAs();
            }
        } else {
            saveAs();
        }
    } else {
        saveAs();
    }
}
Also used : IOProviderDescriptor(eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor) IOConfiguration(eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration) ProjectWriter(eu.esdihumboldt.hale.common.core.io.project.ProjectWriter) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) FileIOSupplier(eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier) NoStreamOutputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.NoStreamOutputSupplier) ProjectFile(eu.esdihumboldt.hale.common.core.io.project.model.ProjectFile) File(java.io.File) InvocationTargetException(java.lang.reflect.InvocationTargetException) ExecutionException(java.util.concurrent.ExecutionException)

Example 2 with ProjectWriter

use of eu.esdihumboldt.hale.common.core.io.project.ProjectWriter in project hale by halestudio.

the class AbstractProjectDetailsPage method updateFields.

private void updateFields() {
    ProjectWriter writer = getWizard().getProvider();
    if (writer != null && writer.getProject() != null) {
        ProjectInfo p = writer.getProject();
        name.setStringValue(p.getName());
        author.setStringValue(p.getAuthor());
        description.setText((p.getDescription() == null) ? ("") : (p.getDescription()));
    } else {
        name.setStringValue("");
        author.setStringValue("");
        description.setText("");
    }
}
Also used : ProjectWriter(eu.esdihumboldt.hale.common.core.io.project.ProjectWriter) ProjectInfo(eu.esdihumboldt.hale.common.core.io.project.ProjectInfo)

Aggregations

ProjectWriter (eu.esdihumboldt.hale.common.core.io.project.ProjectWriter)2 IOProviderDescriptor (eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor)1 ProjectInfo (eu.esdihumboldt.hale.common.core.io.project.ProjectInfo)1 IOConfiguration (eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration)1 ProjectFile (eu.esdihumboldt.hale.common.core.io.project.model.ProjectFile)1 IOReport (eu.esdihumboldt.hale.common.core.io.report.IOReport)1 FileIOSupplier (eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier)1 NoStreamOutputSupplier (eu.esdihumboldt.hale.common.core.io.supplier.NoStreamOutputSupplier)1 File (java.io.File)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ExecutionException (java.util.concurrent.ExecutionException)1