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();
}
}
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("");
}
}
Aggregations