Skip to content

Commit

Permalink
add buttons for "Cancel All" and "Overwrite All" to the export
Browse files Browse the repository at this point in the history
  • Loading branch information
ernstblechaPT committed Sep 17, 2024
1 parent 50259bb commit 0d4a7a3
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;

Expand Down Expand Up @@ -121,8 +123,8 @@ private static class Exporter implements IRunnableWithProgress {
private final List<IFile> 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<IFile> exportees, final String outputDirectory,
final boolean overwriteWithoutWarning, final boolean enableCMakeLists) {
Expand All @@ -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));
Expand All @@ -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);
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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);
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;

Expand Down Expand Up @@ -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() {
}
Expand All @@ -75,7 +83,7 @@ private static List<String> reformat(final String name, final List<String> 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);
}

Expand All @@ -99,7 +107,7 @@ private static String stringsToTextualList(final List<String> 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));
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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

0 comments on commit 0d4a7a3

Please sign in to comment.