diff options
| author | Laurent Fasani | 2017-07-20 10:24:10 +0000 |
|---|---|---|
| committer | Laurent Fasani | 2017-07-20 10:24:10 +0000 |
| commit | bf04067666748a77f4f6069fe32fc4cfe457e615 (patch) | |
| tree | 476d0e38740c466b1c489f5bae97de383adc931c | |
| parent | 2859e112dc085588611a61e1f7b59f885590371a (diff) | |
| download | org.eclipse.sirius-bf04067666748a77f4f6069fe32fc4cfe457e615.tar.gz org.eclipse.sirius-bf04067666748a77f4f6069fe32fc4cfe457e615.tar.xz org.eclipse.sirius-bf04067666748a77f4f6069fe32fc4cfe457e615.zip | |
[516669] Delegate the rep deletion check to UICallBack
* It will allow to delete representation in junit test without prompting
a user action
Bug: 516669
Change-Id: Ie59428e11e402adca6d6081e0fd42a178f0e006c
Signed-off-by: Laurent Fasani <laurent.fasani@obeo.fr>
5 files changed, 69 insertions, 70 deletions
diff --git a/plugins/org.eclipse.sirius.ui/plugin.properties b/plugins/org.eclipse.sirius.ui/plugin.properties index 37a841ff18..ca29e449d8 100644 --- a/plugins/org.eclipse.sirius.ui/plugin.properties +++ b/plugins/org.eclipse.sirius.ui/plugin.properties @@ -31,6 +31,10 @@ AbstractExportRepresentationsAsImagesDialog_htmlExport = Export to HTML AbstractExportRepresentationsAsImagesDialog_imageFormatLabel = &Image Format: AbstractExportRepresentationsAsImagesDialog_invalidFolderPathError = Folder is not a valid path AbstractSWTCallback_askForDetailName_canceled = Cancel +AbstractSWTCallback_DeleteRepresentationAction_message = Are you sure you want to delete the selected representation? +AbstractSWTCallback_DeleteRepresentationAction_message_plural = Are you sure you want to delete the selected representations? +AbstractSWTCallback_DeleteRepresentationAction_title = Delete representation +AbstractSWTCallback_DeleteRepresentationAction_title_plural = Delete representations AbstractSWTCallback_loadResourceError = error loading EMF resource AbstractSWTCallback_models = Models for "{0}" AbstractSWTCallback_modelsAndRepresentations = Models and Representations for "{0}" @@ -102,11 +106,7 @@ DefaultDialectEditorDialogFactory_title = Deleted root element DeleteRepresentationAction_closeEditorsTask = Associated editor closing DeleteRepresentationAction_deleteRepresentationTask = Representation deletion DeleteRepresentationAction_deleteRepresentationTask_plural = Representations deletion -DeleteRepresentationAction_message = Are you sure you want to delete the selected representation? -DeleteRepresentationAction_message_plural = Are you sure you want to delete the selected representations? DeleteRepresentationAction_name = Delete -DeleteRepresentationAction_title = Delete representation -DeleteRepresentationAction_title_plural = Delete representations DesignerControlAction_controlTask = Control resources DesignerControlAction_saveDialogTitle = Representations file DesignerControlAction_savingTask = Session saving diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/api/command/AbstractSWTCallback.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/api/command/AbstractSWTCallback.java index 7ff1459bbc..a025ded06b 100644 --- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/api/command/AbstractSWTCallback.java +++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/api/command/AbstractSWTCallback.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2016 THALES GLOBAL SERVICES and others. + * Copyright (c) 2010, 2017 THALES GLOBAL SERVICES and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -15,6 +15,7 @@ import java.text.MessageFormat; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.Set; import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.IProgressMonitor; @@ -57,6 +58,7 @@ import org.eclipse.sirius.ui.tools.api.views.ViewHelper; import org.eclipse.sirius.ui.tools.internal.selection.TypedVariableValueDialog; import org.eclipse.sirius.viewpoint.DAnalysisSessionEObject; import org.eclipse.sirius.viewpoint.DRepresentation; +import org.eclipse.sirius.viewpoint.DRepresentationDescriptor; import org.eclipse.sirius.viewpoint.DRepresentationElement; import org.eclipse.sirius.viewpoint.SiriusPlugin; import org.eclipse.sirius.viewpoint.description.TypedVariable; @@ -242,6 +244,18 @@ public abstract class AbstractSWTCallback implements UICallBack { MessageFormat.format(org.eclipse.sirius.viewpoint.provider.Messages.AbstractSWTCallback_shouldClose_message, resource.getURI())); } + @Override + public boolean shouldDeleteRepresentation(Set<DRepresentationDescriptor> repDescriptors) { + String deleteRepresenationDialogTitle = org.eclipse.sirius.viewpoint.provider.Messages.AbstractSWTCallback_DeleteRepresentationAction_title; + String deletionMessage = org.eclipse.sirius.viewpoint.provider.Messages.AbstractSWTCallback_DeleteRepresentationAction_message; + if (repDescriptors.size() >= 2) { + deleteRepresenationDialogTitle = org.eclipse.sirius.viewpoint.provider.Messages.AbstractSWTCallback_DeleteRepresentationAction_title_plural; + deletionMessage = org.eclipse.sirius.viewpoint.provider.Messages.AbstractSWTCallback_DeleteRepresentationAction_message_plural; + } + Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); + return MessageDialog.openConfirm(shell, deleteRepresenationDialogTitle, deletionMessage); + } + /** * Convenience method to open a simple Yes/No question dialog. * @@ -249,8 +263,7 @@ public abstract class AbstractSWTCallback implements UICallBack { * the dialog's title, or <code>null</code> if none * @param message * the message - * @return <code>true</code> if the user presses the Yes button, - * <code>false</code> otherwise + * @return <code>true</code> if the user presses the Yes button, <code>false</code> otherwise */ private boolean openQuestion(final String title, final String message) { if (inUIThread()) { @@ -271,14 +284,12 @@ public abstract class AbstractSWTCallback implements UICallBack { * Return an expression describing what is saving : * <UL> * <LI>"Models" if only semantic files have been modified,</LI> - * <LI>"Representations" if only representations files have been modified, - * </LI> + * <LI>"Representations" if only representations files have been modified,</LI> * <LI>"Models and Representations" if both.</LI> * </UL> * suffixed with : * <UL> - * <LI>"project's session name" if the session has a second segment (that is - * the project name).</LI> + * <LI>"project's session name" if the session has a second segment (that is the project name).</LI> * <LI>"toPlatformString URI" if the session uses a InMemoryQuery</LI> * <LI>"the toString URI" otherwise.</LI> * </UL> diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/action/DeleteRepresentationAction.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/action/DeleteRepresentationAction.java index 7eeb05a3a6..bd65e136e6 100644 --- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/action/DeleteRepresentationAction.java +++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/action/DeleteRepresentationAction.java @@ -25,7 +25,6 @@ import org.eclipse.core.runtime.Status; import org.eclipse.emf.common.command.Command; import org.eclipse.emf.ecore.EObject; import org.eclipse.jface.action.Action; -import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.dialogs.ProgressMonitorDialog; import org.eclipse.jface.operation.IRunnableContext; import org.eclipse.jface.operation.IRunnableWithProgress; @@ -41,6 +40,7 @@ import org.eclipse.sirius.ui.business.api.session.SessionUIManager; import org.eclipse.sirius.viewpoint.DRepresentation; import org.eclipse.sirius.viewpoint.DRepresentationDescriptor; import org.eclipse.sirius.viewpoint.DView; +import org.eclipse.sirius.viewpoint.SiriusPlugin; import org.eclipse.sirius.viewpoint.provider.Messages; import org.eclipse.sirius.viewpoint.provider.SiriusEditPlugin; import org.eclipse.swt.widgets.Shell; @@ -79,15 +79,9 @@ public class DeleteRepresentationAction extends Action { public void run() { Map<DRepresentationDescriptor, Session> representation2Session = getRepresentations(); final Map<Session, Set<DRepresentationDescriptor>> session2DRepresentations = getSession2Representations(representation2Session); - String deleteRepresenationDialogTitle = Messages.DeleteRepresentationAction_title; - String deletionMessage = Messages.DeleteRepresentationAction_message; - if (representation2Session.size() >= 2) { - deleteRepresenationDialogTitle = Messages.DeleteRepresentationAction_title_plural; - deletionMessage = Messages.DeleteRepresentationAction_message_plural; - } try { Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); - boolean deletionConfirmation = MessageDialog.openConfirm(shell, deleteRepresenationDialogTitle, deletionMessage); + boolean deletionConfirmation = SiriusPlugin.getDefault().getUiCallback().shouldDeleteRepresentation(representation2Session.keySet()); if (deletionConfirmation) { IRunnableContext context = new ProgressMonitorDialog(shell); IRunnableWithProgress editorClosingRunnable = new IRunnableWithProgress() { diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/viewpoint/provider/Messages.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/viewpoint/provider/Messages.java index c1f9d02782..753d31cdca 100644 --- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/viewpoint/provider/Messages.java +++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/viewpoint/provider/Messages.java @@ -83,6 +83,18 @@ public final class Messages { public static String AbstractSWTCallback_askForDetailName_canceled; @TranslatableMessage + public static String AbstractSWTCallback_DeleteRepresentationAction_message; + + @TranslatableMessage + public static String AbstractSWTCallback_DeleteRepresentationAction_message_plural; + + @TranslatableMessage + public static String AbstractSWTCallback_DeleteRepresentationAction_title; + + @TranslatableMessage + public static String AbstractSWTCallback_DeleteRepresentationAction_title_plural; + + @TranslatableMessage public static String AbstractSWTCallback_loadResourceError; @TranslatableMessage @@ -298,21 +310,9 @@ public final class Messages { public static String DeleteRepresentationAction_deleteRepresentationTask_plural; @TranslatableMessage - public static String DeleteRepresentationAction_message; - - @TranslatableMessage - public static String DeleteRepresentationAction_message_plural; - - @TranslatableMessage public static String DeleteRepresentationAction_name; @TranslatableMessage - public static String DeleteRepresentationAction_title; - - @TranslatableMessage - public static String DeleteRepresentationAction_title_plural; - - @TranslatableMessage public static String DesignerControlAction_controlTask; @TranslatableMessage diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/api/command/ui/UICallBack.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/api/command/ui/UICallBack.java index a97bc98d18..66459c44db 100644 --- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/api/command/ui/UICallBack.java +++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/api/command/ui/UICallBack.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2016 THALES GLOBAL SERVICES. + * Copyright (c) 2007, 2017 THALES GLOBAL SERVICES. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -12,6 +12,7 @@ package org.eclipse.sirius.tools.api.command.ui; import java.util.Collection; import java.util.List; +import java.util.Set; import org.eclipse.core.resources.IFile; import org.eclipse.emf.common.notify.AdapterFactory; @@ -22,12 +23,12 @@ import org.eclipse.sirius.business.api.migration.AirdResourceVersionMismatchExce import org.eclipse.sirius.business.api.session.Session; import org.eclipse.sirius.common.tools.api.util.TreeItemWrapper; import org.eclipse.sirius.viewpoint.DRepresentation; +import org.eclipse.sirius.viewpoint.DRepresentationDescriptor; import org.eclipse.sirius.viewpoint.description.TypedVariable; import org.eclipse.sirius.viewpoint.description.tool.SelectModelElementVariable; /** - * This interface is called when one need a UI callback, for variables - * selection, or any other user interface stuff. + * This interface is called when one need a UI callback, for variables selection, or any other user interface stuff. * * @author cbrun */ @@ -42,8 +43,7 @@ public interface UICallBack { * the variable to select. * @return a Collection of selected EObjects. * @throws InterruptedException - * when the process is interrupted (for instance the user - * pressed "cancel".) + * when the process is interrupted (for instance the user pressed "cancel".) */ Collection<EObject> askForVariableValues(EObject model, SelectModelElementVariable variable) throws InterruptedException; @@ -54,8 +54,7 @@ public interface UICallBack { * the default name. * @return the name that has been inputed by the user. * @throws InterruptedException - * when the process is interrupted (for instance the user - * pressed "cancel".) + * when the process is interrupted (for instance the user pressed "cancel".) */ String askForDetailName(String defaultName) throws InterruptedException; @@ -68,8 +67,7 @@ public interface UICallBack { * the documentation of the future representation * @return the name that has been inputed by the user. * @throws InterruptedException - * when the process is interrupted (for instance the user - * pressed "cancel".) + * when the process is interrupted (for instance the user pressed "cancel".) * @deprecated Replaced by {@link #askForDetailName(String, String, String)} * */ @@ -82,32 +80,27 @@ public interface UICallBack { * @param defaultName * the default name. * @param representationDescriptionName - * the name of the representation description used for the future - * representation + * the name of the representation description used for the future representation * @param representationDescriptionDoc * the documentation of the future representation * @return the name that has been inputed by the user. * @throws InterruptedException - * when the process is interrupted (for instance the user - * pressed "cancel".) + * when the process is interrupted (for instance the user pressed "cancel".) */ String askForDetailName(String defaultName, String representationDescriptionName, String representationDescriptionDoc) throws InterruptedException; /** - * Called when the user interface should prompt for a selection of EObject - * instances. + * Called when the user interface should prompt for a selection of EObject instances. * * @param message * the message to display. * @param input * the tree of objects as input. * @param factory - * the adapter factory to provides labels and icons for the - * objects. + * the adapter factory to provides labels and icons for the objects. * @return a list of the selected {@link EObject}. * @throws InterruptedException - * when the process is interrupted (for instance the user - * pressed "cancel".) + * when the process is interrupted (for instance the user pressed "cancel".) */ Collection<EObject> askForEObjects(String message, TreeItemWrapper input, AdapterFactory factory) throws InterruptedException; @@ -119,12 +112,10 @@ public interface UICallBack { * @param input * the tree of objects as input. * @param factory - * the adapter factory to provides labels and icons for the - * objects. + * the adapter factory to provides labels and icons for the objects. * @return the selected {@link EObject}. * @throws InterruptedException - * when the process is interrupted (for instance the user - * pressed "cancel".) + * when the process is interrupted (for instance the user pressed "cancel".) */ EObject askForEObject(String message, TreeItemWrapper input, AdapterFactory factory) throws InterruptedException; @@ -152,8 +143,7 @@ public interface UICallBack { void openRepresentation(Session openedSession, DRepresentation representation); /** - * Load a resource in the resource set associated to the editing domain - * given as parameter. + * Load a resource in the resource set associated to the editing domain given as parameter. * * @param file * the file @@ -179,15 +169,13 @@ public interface UICallBack { * * @param resource * the externally deleted resource. - * @return <code>true</code> if the resource should be removed from the - * session. + * @return <code>true</code> if the resource should be removed from the session. * @since 0.9.0 */ boolean shouldRemove(Resource resource); /** - * Called when the user interface should prompt for a choice. The deleted - * resource contains session critical data. + * Called when the user interface should prompt for a choice. The deleted resource contains session critical data. * * @param session * the current session. @@ -199,6 +187,17 @@ public interface UICallBack { boolean shouldClose(Session session, Resource resource); /** + * Called when the user interface should prompt for a choice about the representation deletion. + * + * @param repDescriptors + * the representationDescriptors being deleted. + * @return <code>true</code> if the session should be closed. + */ + default boolean shouldDeleteRepresentation(Set<DRepresentationDescriptor> repDescriptors) { + return true; + }; + + /** * Session name to display while saving this. * * @param session @@ -218,29 +217,24 @@ public interface UICallBack { void openError(String title, String message); /** - * Open an UI to ask the user the value corresponding to each TypedVariable - * of typedVariableList. </br> + * Open an UI to ask the user the value corresponding to each TypedVariable of typedVariableList. </br> * The returned list has the same size as typedVariableList * * @param typedVariableList * the list of variable for which to get the values * @param defaultValues - * the default values used to initialize UI. This list must have - * the typedVariableList size. + * the default values used to initialize UI. This list must have the typedVariableList size. * @return the value provided by the user * @throws InterruptedException - * when the process is interrupted (for instance the user - * pressed "cancel".) + * when the process is interrupted (for instance the user pressed "cancel".) */ List<String> askForTypedVariable(List<TypedVariable> typedVariableList, List<String> defaultValues) throws InterruptedException;; /** - * Ask to end-user if he wants to open the session ignoring the resource - * version mismatch or not. + * Ask to end-user if he wants to open the session ignoring the resource version mismatch or not. * * @param e - * the {@link AirdResourceVersionMismatchException} holding - * mismatch informations + * the {@link AirdResourceVersionMismatchException} holding mismatch informations * * @return true to reopen session false otherwise * @since 4.0 |
