}
@Override
protected WorkflowWizard createWorkflowWizard(Workflow workflow,
java.util.Map<Class<? extends State>, WorkflowWizardPageProvider> map) {
CatalogExportWizard catalogExportWizard = new CatalogExportWizard(
workflow, map) {
@Override
protected boolean performFinish(IProgressMonitor monitor) {
boolean result = super.performFinish(monitor);
replaceExportedLayers(state);
try {
editor.getMap().getEditManagerInternal()
.commitTransaction();
editor.setDirty(false);
} catch (IOException e) {
ProjectUIPlugin.log("failed committing transaction", e); //$NON-NLS-1$
MessageDialog.openError(editor.getSite().getShell(), Messages.MapSaveStrategy_error_title, Messages.MapSaveStrategy_error_messages);
}
return result;
}
private void replaceExportedLayers(
final ExportResourceSelectionState layerState) {
List<Data> exportedLayers = layerState.getExportData();
for (Data data : exportedLayers) {
Collection<IGeoResource> exported = data
.getExportedResources();
replaceLayer(data.getResource(), exported);
}
}
private void replaceLayer(IGeoResource resource,
Collection<IGeoResource> exported) {
List<Layer> layers = MapPaletteSaveStrategy.this.editor.getMap()
.getLayersInternal();
Layer found;
do {
found = null;
for (Layer layer : layers) {
if (URLUtils.urlEquals(layer.getID(), resource
.getIdentifier(), false)) {
found = layer;
break;
}
}
if (found != null) {
layers.addAll(layers.indexOf(found), toLayers(found,
exported));
layers.remove(found);
}
} while (found != null);
}
private Collection<Layer> toLayers(Layer found,
Collection<IGeoResource> exported) {
LayerFactory layerFactory = MapPaletteSaveStrategy.this.editor
.getMap().getLayerFactory();
Collection<Layer> newLayers = new ArrayList<Layer>();
for (IGeoResource exportedResource : exported) {
try {
Layer createLayer = layerFactory
.createLayer(exportedResource);
StyleBlackboard clone = (StyleBlackboard) found
.getStyleBlackboard().clone();
createLayer.setStyleBlackboard(clone);
newLayers.add(createLayer);
} catch (IOException e) {
throw (RuntimeException) new RuntimeException()
.initCause(e);
}
}
return newLayers;
}
};
catalogExportWizard.setSelectExportedInCatalog(false);
return catalogExportWizard;
}