From 0d4a7a3605734851e348aebd9da1b351d79c78e2 Mon Sep 17 00:00:00 2001 From: Ernst Blecha Date: Wed, 28 Aug 2024 17:23:56 +0200 Subject: [PATCH] add buttons for "Cancel All" and "Overwrite All" to the export --- .../export/ui/wizard/FordiacExportWizard.java | 32 +++++++++++++---- .../fordiac/ide/export/ExportException.java | 36 +++++++++++++++++-- .../eclipse/fordiac/ide/export/Messages.java | 4 +++ .../ide/export/TemplateExportFilter.java | 22 ++++++++++-- .../fordiac/ide/export/messages.properties | 2 ++ 5 files changed, 84 insertions(+), 12 deletions(-) diff --git a/plugins/org.eclipse.fordiac.ide.export.ui/src/org/eclipse/fordiac/ide/export/ui/wizard/FordiacExportWizard.java b/plugins/org.eclipse.fordiac.ide.export.ui/src/org/eclipse/fordiac/ide/export/ui/wizard/FordiacExportWizard.java index c89587ef5d..1eda6445ce 100644 --- a/plugins/org.eclipse.fordiac.ide.export.ui/src/org/eclipse/fordiac/ide/export/ui/wizard/FordiacExportWizard.java +++ b/plugins/org.eclipse.fordiac.ide.export.ui/src/org/eclipse/fordiac/ide/export/ui/wizard/FordiacExportWizard.java @@ -1,6 +1,7 @@ /******************************************************************************* - * Copyright (c) 2008, 2021 Profactor GmbH, TU Wien ACIN, fortiss GmbH, - * Johannes Kepler University Linz + * Copyright (c) 2008 - 2024 Profactor GmbH, TU Wien ACIN, fortiss GmbH, + * Johannes Kepler University Linz + * Primetals Technologies Austria GmbH * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -13,6 +14,7 @@ * - initial API and implementation and/or initial documentation * Alois Zoitl - Extract export process into own class for better code * readability and addressing several sonar issues + * Ernst Blecha - Add "Overwrite All" and "Cancel All" *******************************************************************************/ package org.eclipse.fordiac.ide.export.ui.wizard; @@ -121,8 +123,8 @@ private static class Exporter implements IRunnableWithProgress { private final List exportees; private final String outputDirectory; private final IConfigurationElement conf; - private final boolean overwriteWithoutWarning; - private final boolean enableCMakeLists; + private boolean overwriteWithoutWarning; + private boolean enableCMakeLists; public Exporter(final IConfigurationElement conf, final List exportees, final String outputDirectory, final boolean overwriteWithoutWarning, final boolean enableCMakeLists) { @@ -141,11 +143,25 @@ public void run(final IProgressMonitor monitor) throws InvocationTargetException final IExportFilter filter = createExportFilter(); if (null != filter) { for (final IFile file : exportees) { - exportElement(monitor, filter, file, null); + try { + exportElement(monitor, filter, file, null); + } catch (final ExportException.OverwriteAll e) { + overwriteWithoutWarning = true; + } catch (final ExportException.CancelAll e) { + enableCMakeLists = false; + break; + } catch (final ExportException.UserInteraction e) { + // noop + } monitor.worked(1); } if (enableCMakeLists) { - exportElement(monitor, filter, null, new CMakeListsMarker()); + try { + exportElement(monitor, filter, null, new CMakeListsMarker()); + } catch (final ExportException.UserInteraction e) { + // noop + } + monitor.worked(1); } monitor.worked(1); Display.getDefault().asyncExec(() -> showErrorWarningSummary(filter)); @@ -154,7 +170,7 @@ public void run(final IProgressMonitor monitor) throws InvocationTargetException } private void exportElement(final IProgressMonitor monitor, final IExportFilter filter, final IFile file, - final EObject source) { + final EObject source) throws ExportException.UserInteraction { try { if (source instanceof CMakeListsMarker) { monitor.subTask(Messages.FordiacExportWizard_ExportingCMakeLists); @@ -170,6 +186,8 @@ private void exportElement(final IProgressMonitor monitor, final IExportFilter f monitor.subTask(MessageFormat.format(Messages.FordiacExportWizard_ExportingType, name)); filter.export(file, outputDirectory, overwriteWithoutWarning, source); } + } catch (final ExportException.UserInteraction e) { + throw (e); } catch (final ExportException e) { FordiacLogHelper.logError(e.getMessage(), e); final MessageBox msg = new MessageBox(Display.getDefault().getActiveShell()); diff --git a/plugins/org.eclipse.fordiac.ide.export/src/org/eclipse/fordiac/ide/export/ExportException.java b/plugins/org.eclipse.fordiac.ide.export/src/org/eclipse/fordiac/ide/export/ExportException.java index c4a7ed17a6..16bbcc8353 100644 --- a/plugins/org.eclipse.fordiac.ide.export/src/org/eclipse/fordiac/ide/export/ExportException.java +++ b/plugins/org.eclipse.fordiac.ide.export/src/org/eclipse/fordiac/ide/export/ExportException.java @@ -1,6 +1,6 @@ /******************************************************************************* * Copyright (c) 2009 Profactor GmbH - * + * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -23,11 +23,41 @@ public class ExportException extends Exception { /** * Instantiates a new export exception. - * + * * @param message the message */ public ExportException(final String message) { super(message); } -} + public static class UserInteraction extends ExportException { + + private static final long serialVersionUID = 1L; + + public UserInteraction(final String message) { + super(message); + } + + } + + public static class OverwriteAll extends UserInteraction { + + private static final long serialVersionUID = 1L; + + public OverwriteAll() { + super(Messages.TemplateExportFilter_OVERWRITE_ALL_LABEL_STRING); + } + + } + + public static class CancelAll extends UserInteraction { + + private static final long serialVersionUID = 1L; + + public CancelAll() { + super(Messages.TemplateExportFilter_OVERWRITE_ALL_LABEL_STRING); + } + + } + +} \ No newline at end of file diff --git a/plugins/org.eclipse.fordiac.ide.export/src/org/eclipse/fordiac/ide/export/Messages.java b/plugins/org.eclipse.fordiac.ide.export/src/org/eclipse/fordiac/ide/export/Messages.java index e47b3d7f34..83d40b0e9f 100644 --- a/plugins/org.eclipse.fordiac.ide.export/src/org/eclipse/fordiac/ide/export/Messages.java +++ b/plugins/org.eclipse.fordiac.ide.export/src/org/eclipse/fordiac/ide/export/Messages.java @@ -26,6 +26,8 @@ public final class Messages extends NLS { public static String ExportTemplate_ExportTemplate; + public static String TemplateExportFilter_CANCEL_ALL_LABEL_STRING; + public static String TemplateExportFilter_ErrorDuringTemplateGeneration; public static String TemplateExportFilter_FILE_EXISTS; @@ -54,6 +56,8 @@ public final class Messages extends NLS { public static String TemplateExportFilter_PREFIX_ERRORMESSAGE_WITH_TYPENAME; + public static String TemplateExportFilter_OVERWRITE_ALL_LABEL_STRING; + static { // initialize resource bundle NLS.initializeMessages(BUNDLE_NAME, Messages.class); diff --git a/plugins/org.eclipse.fordiac.ide.export/src/org/eclipse/fordiac/ide/export/TemplateExportFilter.java b/plugins/org.eclipse.fordiac.ide.export/src/org/eclipse/fordiac/ide/export/TemplateExportFilter.java index 37ad83f364..cdd39f1fd7 100644 --- a/plugins/org.eclipse.fordiac.ide.export/src/org/eclipse/fordiac/ide/export/TemplateExportFilter.java +++ b/plugins/org.eclipse.fordiac.ide.export/src/org/eclipse/fordiac/ide/export/TemplateExportFilter.java @@ -3,6 +3,7 @@ * 2020 Andrea Zoitl * 2020 Johannes Kepler University Linz * 2022 Martin Erich Jobst + * 2024 Primetals Technologies Austria GmbH * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -18,6 +19,7 @@ * - externalized all translatable strings * Ernst Blecha * - improved error handling and handling of forceOverwrite + * - Add "Overwrite All" and "Cancel All" *******************************************************************************/ package org.eclipse.fordiac.ide.export; @@ -51,15 +53,21 @@ public abstract class TemplateExportFilter extends ExportFilter { // Prepare the button labels private static final String[] BUTTON_LABELS = new String[] { // Messages.TemplateExportFilter_OVERWRITE_LABEL_STRING, // + Messages.TemplateExportFilter_OVERWRITE_ALL_LABEL_STRING, // Messages.TemplateExportFilter_MERGE_LABEL_STRING, // + Messages.TemplateExportFilter_CANCEL_ALL_LABEL_STRING, // JFaceResources.getString(IDialogLabelKeys.CANCEL_LABEL_KEY)// }; // extract the button ids from the label-array (avoid magic numbers) private static final int BUTTON_OVERWRITE = Arrays.asList(BUTTON_LABELS) .indexOf(Messages.TemplateExportFilter_OVERWRITE_LABEL_STRING); + private static final int BUTTON_OVERWRITE_ALL = Arrays.asList(BUTTON_LABELS) + .indexOf(Messages.TemplateExportFilter_OVERWRITE_ALL_LABEL_STRING); private static final int BUTTON_MERGE = Arrays.asList(BUTTON_LABELS) .indexOf(Messages.TemplateExportFilter_MERGE_LABEL_STRING); + private static final int BUTTON_CANCEL_ALL = Arrays.asList(BUTTON_LABELS) + .indexOf(Messages.TemplateExportFilter_CANCEL_ALL_LABEL_STRING); protected TemplateExportFilter() { } @@ -75,7 +83,7 @@ private static List reformat(final String name, final List messa @Override public final void export(final IFile typeFile, final String destination, final boolean forceOverwrite) - throws ExportException { + throws ExportException.UserInteraction { this.export(typeFile, destination, forceOverwrite, null); } @@ -99,7 +107,7 @@ private static String stringsToTextualList(final List list) { @Override public void export(final IFile typeFile, final String destination, final boolean forceOverwrite, EObject source) - throws ExportException { + throws ExportException.UserInteraction { if (source == null && typeFile != null && TypeLibraryManager.INSTANCE.getTypeEntryForFile(typeFile) == null) { getWarnings().add(MessageFormat.format(Messages.TemplateExportFilter_PREFIX_ERRORMESSAGE_WITH_TYPENAME, typeFile.getFullPath(), Messages.TemplateExportFilter_FILE_IGNORED)); @@ -153,6 +161,16 @@ public void export(final IFile typeFile, final String destination, final boolean openMergeEditor(writtenFiles); } } + + if (res == BUTTON_OVERWRITE_ALL) { + throw (new ExportException.OverwriteAll()); + } + if (res == BUTTON_CANCEL_ALL) { + throw (new ExportException.CancelAll()); + } + + } catch (final ExportException.UserInteraction e) { + throw (e); } catch (final Exception t) { FordiacLogHelper.logError(Messages.TemplateExportFilter_ErrorDuringTemplateGeneration, t); this.getErrors().add(t.getMessage() != null ? t.getMessage() diff --git a/plugins/org.eclipse.fordiac.ide.export/src/org/eclipse/fordiac/ide/export/messages.properties b/plugins/org.eclipse.fordiac.ide.export/src/org/eclipse/fordiac/ide/export/messages.properties index c5015d95ed..83f6621891 100644 --- a/plugins/org.eclipse.fordiac.ide.export/src/org/eclipse/fordiac/ide/export/messages.properties +++ b/plugins/org.eclipse.fordiac.ide.export/src/org/eclipse/fordiac/ide/export/messages.properties @@ -14,6 +14,7 @@ ExportTemplate_ExportTemplate=ExportTemplate [{0}] +TemplateExportFilter_CANCEL_ALL_LABEL_STRING=Cancel All TemplateExportFilter_ErrorDuringTemplateGeneration=Error during template generation TemplateExportFilter_FILE_EXISTS=File Exists TemplateExportFilter_FILE_IGNORED=File was ignored during export. @@ -28,3 +29,4 @@ TemplateExportFilter_NO_DIFFERENCES_TITLE=No Differences TemplateExportFilter_OVERWRITE_LABEL_STRING=Overwrite TemplateExportFilter_OVERWRITE_REQUEST=Overwrite {0}?\nMerge will create a backup of the original file and open an editor to merge the files manually\! TemplateExportFilter_PREFIX_ERRORMESSAGE_WITH_TYPENAME={0}: {1} +TemplateExportFilter_OVERWRITE_ALL_LABEL_STRING=Overwrite All