Skip to content
Snippets Groups Projects
Commit a8e6a439 authored by Simon Barner's avatar Simon Barner
Browse files

Add methods confirmInUIThread() and askSaveDirtyTopLevelElement()

* confirmInUIThread() and askQuestionInUIThread() are synchronized now,
  since they both use a shared static variable

Issue-ref: 4264
Issue-URL: af3#4264



Signed-off-by: default avatarSimon Barner <barner@fortiss.org>
parent 29b169c6
No related branches found
No related tags found
1 merge request!2274264: Add methods confirmInUIThread() and askSaveDirtyTopLevelElement()
Pipeline #41536 passed
Pipeline: maven-releng

#41537

    ......@@ -5,7 +5,7 @@ DragAndDropUtils.java 7aab91518aa12d76533a345bf6ed0be9ac7ff0e5 GREEN
    EObjectSelectionUtils.java 128cf8f96c6b9478171dff3deda662d5934f5f44 GREEN
    HierarchicalNameViewerComparator.java 199d82e392d4e437810cc65c0fc521dab52038e0 GREEN
    KernelUIUtils.java dd58b2c618b7c847aa8cfa2d3bd9956b40b73cdd GREEN
    MessageUtilsExtended.java a08055b2f0005eebfa91662374d9ec4ce4f78aab GREEN
    MessageUtilsExtended.java 4af07e44027b71afc1909f3e21b853bccb2cbd56 YELLOW
    ObservableUtils.java 34abfd1dfaf9c0acbb31caf1f525e7b39416c116 GREEN
    PropertiesConstantUtils.java 59b1a1e4d594bb98db3aa396f2ff6474ba405920 GREEN
    SelectionUtils.java 33aec7cccccb28e5568140cf8e5443ce0f9f59f7 GREEN
    ......
    ......@@ -20,8 +20,13 @@ import static org.conqat.ide.commons.ui.dialog.MessageUtils.showError;
    import static org.conqat.ide.commons.ui.dialog.MessageUtils.showInfo;
    import static org.conqat.ide.commons.ui.dialog.MessageUtils.showWarning;
    import java.io.IOException;
    import org.conqat.ide.commons.ui.dialog.MessageUtils;
    import org.eclipse.core.runtime.CoreException;
    import org.eclipse.core.runtime.NullProgressMonitor;
    import org.eclipse.swt.widgets.Display;
    import org.fortiss.tooling.kernel.extension.data.ITopLevelElement;
    /**
    * This class contains additional methods w.r.t. {@link MessageUtils}.
    ......@@ -34,11 +39,18 @@ public class MessageUtilsExtended {
    private static boolean tempQuestionResult;
    /** Asks question in the UI thread (and block). */
    public static boolean askQuestionInUIThread(final String title, final String message) {
    public synchronized static boolean askQuestionInUIThread(final String title,
    final String message) {
    syncExec(() -> tempQuestionResult = askQuestion(title, message));
    return tempQuestionResult;
    }
    /** Get configuration in the UI thread (and block). */
    public synchronized static boolean confirmInUIThread(final String title, final String message) {
    syncExec(() -> tempQuestionResult = MessageUtils.confirm(title, message));
    return tempQuestionResult;
    }
    /** Opens a error dialog in the UI thread (and block). */
    public static void showErrorInUIThread(final String title, final String message) {
    syncExec(() -> showError(title, message));
    ......@@ -58,4 +70,31 @@ public class MessageUtilsExtended {
    private static void syncExec(Runnable runnable) {
    Display.getDefault().syncExec(runnable);
    }
    /**
    * Opens a dialog to confirm if a dirty {@link ITopLevelElement} should be saved (no-op if the
    * {@link ITopLevelElement} is not dirty).
    *
    * @return {@code true} if the model is not dirty (either in the first place, or not anymore
    * (after successfully saving).
    */
    public static boolean askSaveDirtyTopLevelElement(ITopLevelElement topelement) {
    if(!topelement.isDirty()) {
    return true;
    }
    if(!confirmInUIThread("Save required",
    "For the selected action, the model may not contain unsaved changes.\n\nOK to save and continue?")) {
    return false;
    }
    try {
    topelement.doSave(new NullProgressMonitor());
    } catch(CoreException | IOException e) {
    showErrorInUIThread("Failed to save project \"" + topelement.getSaveableName(),
    e.getMessage());
    return false;
    }
    return true;
    }
    }
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment