X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.g3d%2Fsrc%2Forg%2Fsimantics%2Fg3d%2Fwizard%2FModelExportWizard.java;h=b5e684da6496b3829e0cac5978b5e409134ca955;hb=53d55c24c779745f188bdb18d32f71d20acb61b2;hp=9eddcd44c957b387cf76fb801b0b008e8eee4138;hpb=f36217aeeb09c0c46f99886ee99772156ce9cfe6;p=simantics%2F3d.git diff --git a/org.simantics.g3d/src/org/simantics/g3d/wizard/ModelExportWizard.java b/org.simantics.g3d/src/org/simantics/g3d/wizard/ModelExportWizard.java index 9eddcd44..b5e684da 100644 --- a/org.simantics.g3d/src/org/simantics/g3d/wizard/ModelExportWizard.java +++ b/org.simantics.g3d/src/org/simantics/g3d/wizard/ModelExportWizard.java @@ -42,149 +42,149 @@ public abstract class ModelExportWizard extends Wizard i private static final int MAX_RECENT_EXPORT_PATHS = 10; Deque recentExportPaths; - boolean overwrite; - - T exportModel; - - protected abstract T createExportModel(Deque recentExportPaths); - - protected abstract ModelExportWizardPage createExportPage(T exportModel); - - protected abstract IPersistentPreferenceStore getPreferenceStore(); - - protected abstract IRunnableWithProgress createExportRunnable(T exportModel); - - protected abstract String getExportLocationId(); - protected abstract String getExportOverwriteId(); - - @Override + boolean overwrite; + + T exportModel; + + protected abstract T createExportModel(Deque recentExportPaths); + + protected abstract ModelExportWizardPage createExportPage(T exportModel); + + protected abstract IPersistentPreferenceStore getPreferenceStore(); + + protected abstract IRunnableWithProgress createExportRunnable(T exportModel); + + protected abstract String getExportLocationId(); + protected abstract String getExportOverwriteId(); + + @Override public void init(IWorkbench workbench, IStructuredSelection selection) { readPreferences(); - ISessionContext ctx = Simantics.getSessionContext(); - if (ctx == null) - return; - IProject project = ctx.getHint(ProjectKeys.KEY_PROJECT); - if (project == null) - return; - - exportModel = createExportModel(recentExportPaths); - exportModel.setSelection(selection.getFirstElement()); - exportModel.setOverwrite(overwrite); + ISessionContext ctx = Simantics.getSessionContext(); + if (ctx == null) + return; + IProject project = ctx.getHint(ProjectKeys.KEY_PROJECT); + if (project == null) + return; + + exportModel = createExportModel(recentExportPaths); + exportModel.setSelection(selection.getFirstElement()); + exportModel.setOverwrite(overwrite); } - - @Override + + @Override public void addPages() { super.addPages(); if (exportModel != null) { addPage(createExportPage(exportModel)); } } - - - + + + @Override public boolean performFinish() { - try { - recentExportPaths.addFirst(exportModel.getExportLocation().getAbsolutePath()); - removeDuplicates(recentExportPaths); - if (recentExportPaths.size() > MAX_RECENT_EXPORT_PATHS) - recentExportPaths.pollLast(); + try { + recentExportPaths.addFirst(exportModel.getExportLocation().getAbsolutePath()); + removeDuplicates(recentExportPaths); + if (recentExportPaths.size() > MAX_RECENT_EXPORT_PATHS) + recentExportPaths.pollLast(); - writePreferences(); - } catch (IOException e) { - ErrorLogger.defaultLogError("Failed to write preferences", e); - } - - if (exportModel.usesFile()) { + writePreferences(); + } catch (IOException e) { + ErrorLogger.defaultLogError("Failed to write preferences", e); + } + + if (exportModel.usesFile()) { - File outputFile = exportModel.getExportLocation(); - - if (outputFile.exists()) { - if (!outputFile.isFile()) { - MessageDialog.openError(getShell(), "File Problem", "Output target is not a file " + outputFile.getAbsolutePath()); - return false; - } - if (!exportModel.isOverwrite()) { - boolean ok = MessageDialog.openConfirm(getShell(), "Overwrite", "A file by the name " + outputFile.getAbsolutePath() + " contains files.\n\nDo you want to overwrite the files?"); - if (!ok) { - return false; - } - if (!outputFile.delete()) { - MessageDialog.openError(getShell(), "Delete Problem", "Could not overwrite previously existing file " + outputFile.getAbsolutePath()); - return false; - } - } - } - } else { - File outputFolder = exportModel.getExportLocation(); - - if (outputFolder.exists()) { - if (!outputFolder.isDirectory()) { - MessageDialog.openError(getShell(), "Folder Problem", "Output target is not a folder " + outputFolder.getAbsolutePath()); - return false; - } - String files[] = outputFolder.list(); - if (files.length > 0) { - if (!exportModel.isOverwrite()) { - boolean ok = MessageDialog.openConfirm(getShell(), "Overwrite", "A folder by the name " + outputFolder.getAbsolutePath() + " contains files.\n\nDo you want to overwrite the files?"); - if (!ok) { - return false; - } - } - } + File outputFile = exportModel.getExportLocation(); + + if (outputFile.exists()) { + if (!outputFile.isFile()) { + MessageDialog.openError(getShell(), "File Problem", "Output target is not a file " + outputFile.getAbsolutePath()); + return false; + } + if (!exportModel.isOverwrite()) { + boolean ok = MessageDialog.openConfirm(getShell(), "Overwrite", "A file by the name " + outputFile.getAbsolutePath() + " contains files.\n\nDo you want to overwrite the files?"); + if (!ok) { + return false; + } + if (!outputFile.delete()) { + MessageDialog.openError(getShell(), "Delete Problem", "Could not overwrite previously existing file " + outputFile.getAbsolutePath()); + return false; + } + } + } + } else { + File outputFolder = exportModel.getExportLocation(); + + if (outputFolder.exists()) { + if (!outputFolder.isDirectory()) { + MessageDialog.openError(getShell(), "Folder Problem", "Output target is not a folder " + outputFolder.getAbsolutePath()); + return false; + } + String files[] = outputFolder.list(); + if (files.length > 0) { + if (!exportModel.isOverwrite()) { + boolean ok = MessageDialog.openConfirm(getShell(), "Overwrite", "A folder by the name " + outputFolder.getAbsolutePath() + " contains files.\n\nDo you want to overwrite the files?"); + if (!ok) { + return false; + } + } + } - } else { - if (!outputFolder.mkdir()) { - MessageDialog.openError(getShell(), "Folder Problem", "Could not create new folder " + outputFolder); - return false; - } - } - } + } else { + if (!outputFolder.mkdir()) { + MessageDialog.openError(getShell(), "Folder Problem", "Could not create new folder " + outputFolder); + return false; + } + } + } - try { - getContainer().run(true, true,createExportRunnable(exportModel)); - } catch (InvocationTargetException e) { - Throwable t = e.getTargetException(); - WizardPage cp = (WizardPage) getContainer().getCurrentPage(); - if (t instanceof IOException) { - ErrorLogger.defaultLogError("An I/O problem occurred while exporting the model. See exception for details.", t); - cp.setErrorMessage("An I/O problem occurred while exporting the model.\n\nMessage: " + e.getMessage()); - } else { - ErrorLogger.defaultLogError("Unexpected exception while exporting the model. See exception for details.", t); - cp.setErrorMessage("Unexpected exception while exporting the model. See error log for details.\n\nMessage: " + e.getMessage()); - } - return false; - } catch (InterruptedException e) { - ExceptionUtils.logAndShowError(e); - return false; - } + try { + getContainer().run(true, true,createExportRunnable(exportModel)); + } catch (InvocationTargetException e) { + Throwable t = e.getTargetException(); + WizardPage cp = (WizardPage) getContainer().getCurrentPage(); + if (t instanceof IOException) { + ErrorLogger.defaultLogError("An I/O problem occurred while exporting the model. See exception for details.", t); + cp.setErrorMessage("An I/O problem occurred while exporting the model.\n\nMessage: " + e.getMessage()); + } else { + ErrorLogger.defaultLogError("Unexpected exception while exporting the model. See exception for details.", t); + cp.setErrorMessage("Unexpected exception while exporting the model. See error log for details.\n\nMessage: " + e.getMessage()); + } + return false; + } catch (InterruptedException e) { + ExceptionUtils.logAndShowError(e); + return false; + } - return true; + return true; } private boolean readPreferences() { - IPreferenceStore store = getPreferenceStore(); + IPreferenceStore store = getPreferenceStore(); - String recentPathsPref = store.getString(getExportLocationId()); - recentExportPaths = decodePaths(recentPathsPref); - overwrite = store.getBoolean(getExportOverwriteId()); + String recentPathsPref = store.getString(getExportLocationId()); + recentExportPaths = decodePaths(recentPathsPref); + overwrite = store.getBoolean(getExportOverwriteId()); - return true; - } + return true; + } private void writePreferences() throws IOException { - IPersistentPreferenceStore store = getPreferenceStore(); + IPersistentPreferenceStore store = getPreferenceStore(); - store.putValue(getExportLocationId(), encodePaths(recentExportPaths)); - store.setValue(getExportOverwriteId(), exportModel.isOverwrite()); + store.putValue(getExportLocationId(), encodePaths(recentExportPaths)); + store.setValue(getExportOverwriteId(), exportModel.isOverwrite()); - if (store.needsSaving()) - store.save(); - } + if (store.needsSaving()) + store.save(); + } private static final String TAG_PATH = "path"; private static final String ATTR_NAME = "name";