diff options
| author | Mathieu Cartaud | 2018-07-12 14:02:40 +0000 |
|---|---|---|
| committer | Pierre Guilet | 2018-08-07 15:41:54 +0000 |
| commit | 58c75bfa8ff4b5bf149e61050b88ce679030cf6d (patch) | |
| tree | ab0f81ddc61afe93395c1e2873160c058e3ddb29 | |
| parent | 867c7e76722e3c095144f086d70fb99414b70ffa (diff) | |
| download | org.eclipse.sirius-58c75bfa8ff4b5bf149e61050b88ce679030cf6d.tar.gz org.eclipse.sirius-58c75bfa8ff4b5bf149e61050b88ce679030cf6d.tar.xz org.eclipse.sirius-58c75bfa8ff4b5bf149e61050b88ce679030cf6d.zip | |
[536995] Add information and save abilities to resource migration
Resources (odesign and aird) migration now opens a dialog to warn user
about the migration and asks him if he want to save the changes or not.
To have the dialog open, two conditions must be completed:
- The new migration preference in the Sirius panel (in Eclipse
preferences) must be selected
- The dialog will only open on migration launched by direct action of
the user (i.e opening a diagram, unfolding the modeling project, etc.).
Other action will not open the dialog to avoid breaking the workflow
(i.e. session migration launched by a M2Doc generation, etc.)
Bug: 536995
Change-Id: Ib749f070cf452b3dad688ecf379f9ee0a59bfd7c
Signed-off-by: Mathieu Cartaud <mathieu.cartaud@obeo.fr>
28 files changed, 506 insertions, 172 deletions
diff --git a/plugins/org.eclipse.sirius.common.ui/META-INF/MANIFEST.MF b/plugins/org.eclipse.sirius.common.ui/META-INF/MANIFEST.MF index edf46eb070..29bdd02a79 100644 --- a/plugins/org.eclipse.sirius.common.ui/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.sirius.common.ui/META-INF/MANIFEST.MF @@ -11,7 +11,8 @@ Require-Bundle: org.eclipse.emf.edit.ui;bundle-version="2.8.0", org.eclipse.emf.workspace;bundle-version="1.5.1", com.google.guava;bundle-version="[15.0,22.0)", org.eclipse.core.expressions;bundle-version="3.3.0", - org.eclipse.sirius.ecore.extender;bundle-version="2.0.0" + org.eclipse.sirius.ecore.extender;bundle-version="2.0.0", + org.eclipse.sirius;bundle-version="6.0.0" Export-Package: org.eclipse.sirius.common.ui;version="2.1.0", org.eclipse.sirius.common.ui.business.api.views.properties.tabbed;version="2.0.4", org.eclipse.sirius.common.ui.business.internal.views.properties.tabbed;x-internal:=true;version="2.0.4", diff --git a/plugins/org.eclipse.sirius.common.ui/plugin.properties b/plugins/org.eclipse.sirius.common.ui/plugin.properties index 410885b01a..920b9c4919 100644 --- a/plugins/org.eclipse.sirius.common.ui/plugin.properties +++ b/plugins/org.eclipse.sirius.common.ui/plugin.properties @@ -1,5 +1,5 @@ # ==================================================================== -# Copyright (c) 2007, 2008 THALES GLOBAL SERVICES +# Copyright (c) 2007, 2018 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 @@ -40,6 +40,7 @@ RenameDialog_askNewName_caseInsensitive = Enter new name (case insensitive): RenameDialog_askNewName_caseSensitive = Enter new name (case sensitive): RenameDialog_errorNameClash = New name must be different RenameDialog_title = Rename representation +MigrationUIUtil_askToSaveChanges = {0} have been modified by automatic migration. Save changes? SWTUtil_askToSaveChanges = {0} have been modified. Save changes? SWTUtil_askToSaveChanges_openElseWhere = {0} have been modified, but are still open elsewhere with identical changes. Closing this will not lose those changes. Save changes now anyway? SWTUtil_saveDialog_title = Save diff --git a/plugins/org.eclipse.sirius.common.ui/src/org/eclipse/sirius/common/ui/Messages.java b/plugins/org.eclipse.sirius.common.ui/src/org/eclipse/sirius/common/ui/Messages.java index a4a7e3efd6..1f03846495 100644 --- a/plugins/org.eclipse.sirius.common.ui/src/org/eclipse/sirius/common/ui/Messages.java +++ b/plugins/org.eclipse.sirius.common.ui/src/org/eclipse/sirius/common/ui/Messages.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015 Obeo. + * Copyright (c) 2015, 2018 Obeo. * 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 @@ -54,7 +54,7 @@ public final class Messages { @TranslatableMessage public static String EObjectSelectionWizard_title; - + @TranslatableMessage public static String FolderSelectionDialog_title; @@ -69,7 +69,7 @@ public final class Messages { @TranslatableMessage public static String ModelElementChooserDialog_title; - + @TranslatableMessage public static String NewFileDialog_message; @@ -104,14 +104,17 @@ public final class Messages { public static String SWTUtil_askToSaveChanges; @TranslatableMessage + public static String MigrationUIUtil_askToSaveChanges; + + @TranslatableMessage public static String SWTUtil_askToSaveChanges_openElseWhere; @TranslatableMessage public static String SWTUtil_saveDialog_title; - + @TranslatableMessage public static String SelectFilesWizardPage_title; - + @TranslatableMessage public static String SelectFilesWizardPage_notEnoughFiles; diff --git a/plugins/org.eclipse.sirius.common.ui/src/org/eclipse/sirius/common/ui/tools/api/util/SWTUtil.java b/plugins/org.eclipse.sirius.common.ui/src/org/eclipse/sirius/common/ui/tools/api/util/SWTUtil.java index 41ee801e77..a388ca4b05 100644 --- a/plugins/org.eclipse.sirius.common.ui/src/org/eclipse/sirius/common/ui/tools/api/util/SWTUtil.java +++ b/plugins/org.eclipse.sirius.common.ui/src/org/eclipse/sirius/common/ui/tools/api/util/SWTUtil.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2015 THALES GLOBAL SERVICES. + * Copyright (c) 2007, 2018 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 @@ -117,8 +117,7 @@ public final class SWTUtil { } /** - * Utility method to create a {@link PageBook} widget dispose it when the - * parent will be disposed. + * Utility method to create a {@link PageBook} widget dispose it when the parent will be disposed. * * @param parent * the parent widget @@ -136,8 +135,8 @@ public final class SWTUtil { } /** - * Utility method to create a {@link PageBook} widget with the SWT.NONE - * style and dispose it when the parent will be disposed. + * Utility method to create a {@link PageBook} widget with the SWT.NONE style and dispose it when the parent will be + * disposed. * * @param parent * the parent widget @@ -148,8 +147,7 @@ public final class SWTUtil { } /** - * Utility method to create a {@link FilteredTree} widget and dispose it - * when the parent will be disposed. + * Utility method to create a {@link FilteredTree} widget and dispose it when the parent will be disposed. * * @param parent * the parent widget @@ -170,14 +168,13 @@ public final class SWTUtil { } /** - * Utility method to create a composite widget which fill horizontally and - * dispose it when the parent will be disposed. + * Utility method to create a composite widget which fill horizontally and dispose it when the parent will be + * disposed. * * @param parent * the parent widget * @param columns - * the number of columns in the grid layout for the new - * composite. + * the number of columns in the grid layout for the new composite. * @param equalColumns * make columns equals width * @return the new composite widget @@ -187,14 +184,13 @@ public final class SWTUtil { } /** - * Utility method to create a composite widget which fill vertically and - * dispose it when the parent will be disposed. + * Utility method to create a composite widget which fill vertically and dispose it when the parent will be + * disposed. * * @param parent * the parent widget * @param columns - * the number of columns in the grid layout for the new - * composite. + * the number of columns in the grid layout for the new composite. * @param equalColumns * make columns equals width * @return the new composite widget @@ -204,14 +200,13 @@ public final class SWTUtil { } /** - * Utility method to create a composite widget which fill both horizontally - * and vertically, and dispose it when the parent will be disposed. + * Utility method to create a composite widget which fill both horizontally and vertically, and dispose it when the + * parent will be disposed. * * @param parent * the parent widget * @param columns - * the number of columns in the grid layout for the new - * composite. + * the number of columns in the grid layout for the new composite. * @param equalColumns * make columns equals width * @return the new composite widget @@ -221,14 +216,12 @@ public final class SWTUtil { } /** - * Utility method to create a composite widget and dispose it when the - * parent will be disposed. + * Utility method to create a composite widget and dispose it when the parent will be disposed. * * @param parent * the parent widget * @param columns - * the number of columns in the grid layout for the new - * composite. + * the number of columns in the grid layout for the new composite. * @param equalColumns * make columns equals width * @return the new composite widget @@ -261,14 +254,12 @@ public final class SWTUtil { } /** - * Utility method to create a composite widget and dispose it when the - * parent will be disposed. + * Utility method to create a composite widget and dispose it when the parent will be disposed. * * @param parent * the parent widget * @param columns - * the number of columns in the grid layout for the new - * composite. + * the number of columns in the grid layout for the new composite. * @param equalColumns * make columns equals width * @param layoutData @@ -306,17 +297,15 @@ public final class SWTUtil { } /** - * Show a dialog to ask the user to save or not the content of the Session. - * The window's return codes can be ISaveablePart2.CANCEL, - * ISaveablePart2.YES or ISaveablePart2.NO. + * Show a dialog to ask the user to save or not the content of the Session. The window's return codes can be + * ISaveablePart2.CANCEL, ISaveablePart2.YES or ISaveablePart2.NO. * * @param objectToSave * the object to save * @param label * the name of the element to save or any other label * @param canCancel - * <code>true</code> if the save can be cancel, - * <code>false</code> otherwise + * <code>true</code> if the save can be cancel, <code>false</code> otherwise * @return the return code */ public static int showSaveDialog(final Object objectToSave, final String label, final boolean canCancel) { @@ -324,32 +313,75 @@ public final class SWTUtil { } /** - * Show a dialog to ask the user to save or not the content of the Session. - * The window's return codes can be ISaveablePart2.CANCEL, - * ISaveablePart2.YES or ISaveablePart2.NO. + * Show a dialog to ask the user to save or not the content of the Session. The window's return codes can be + * ISaveablePart2.CANCEL, ISaveablePart2.YES or ISaveablePart2.NO. + * + * @param objectToSave + * the object to save + * @param message + * the message to display in the dialog + * @param canCancel + * <code>true</code> if the save can be cancel, <code>false</code> otherwise + * @return the return code + */ + public static int showSaveDialogWithMessage(final Object objectToSave, final String message, final boolean canCancel) { + return showSaveDialogWithMessage(objectToSave, message, canCancel, false, false); + } + + /** + * Show a dialog to ask the user to save or not the content of the Session. The window's return codes can be + * ISaveablePart2.CANCEL, ISaveablePart2.YES or ISaveablePart2.NO. * * @param objectToSave * the object to save * @param label - * the name of the element to save or any other label + * the name of the element to save or any other label. This label will be used to customize defined + * message value. * @param canCancel - * <code>true</code> if the save can be cancel, - * <code>false</code> otherwise + * <code>true</code> if the save can be cancel, <code>false</code> otherwise * @param stillOpenElsewhere - * <code>true</code> the object to save is open elsewhere, prompt - * if IWorkbenchPreferenceConstants. + * <code>true</code> the object to save is open elsewhere, prompt if IWorkbenchPreferenceConstants. * PROMPT_WHEN_SAVEABLE_STILL_OPEN, <code>false</code> otherwise * @param onlyIfCustomFound - * force to return ISaveablePart2.DEFAULT if no - * saveDialogExtension was found. + * force to return ISaveablePart2.DEFAULT if no saveDialogExtension was found. * * @return the return code */ public static int showSaveDialog(final Object objectToSave, final String label, final boolean canCancel, final boolean stillOpenElsewhere, final boolean onlyIfCustomFound) { + // Provide a dialog allowing the user to change the + // preference if several editors are opened + final String message; + if (stillOpenElsewhere) { + message = MessageFormat.format(Messages.SWTUtil_askToSaveChanges_openElseWhere, label); + } else { + message = MessageFormat.format(Messages.SWTUtil_askToSaveChanges, label); + } + return showSaveDialogWithMessage(objectToSave, message, canCancel, stillOpenElsewhere, onlyIfCustomFound); + } + /** + * Show a dialog to ask the user to save or not the content of the Session. The window's return codes can be + * ISaveablePart2.CANCEL, ISaveablePart2.YES or ISaveablePart2.NO. + * + * @param objectToSave + * the object to save + * @param message + * the message to display in the dialog + * @param canCancel + * <code>true</code> if the save can be cancel, <code>false</code> otherwise + * @param stillOpenElsewhere + * <code>true</code> the object to save is open elsewhere, prompt if IWorkbenchPreferenceConstants. + * PROMPT_WHEN_SAVEABLE_STILL_OPEN, <code>false</code> otherwise + * @param onlyIfCustomFound + * force to return ISaveablePart2.DEFAULT if no saveDialogExtension was found. + * + * @return the return code + */ + public static int showSaveDialogWithMessage(final Object objectToSave, final String message, final boolean canCancel, final boolean stillOpenElsewhere, final boolean onlyIfCustomFound) { final RunnableWithResult runnable = new RunnableWithResult() { private int result = ISaveablePart2.DEFAULT; + @Override public void run() { // Case 1 : an ISaveDialogExtension has been contributed boolean customSaveDialogProvided = false; @@ -357,7 +389,7 @@ public final class SWTUtil { ISaveDialogExtension saveDialogExtension = saveDialogExtensionDescriptor.getSaveDialogExtension(); if (saveDialogExtension.isSaveDialogFor(objectToSave)) { // we use it to build the save dialog - result = showProvidedSaveDialog(saveDialogExtension, objectToSave, label, canCancel, stillOpenElsewhere); + result = showProvidedSaveDialog(saveDialogExtension, objectToSave, message, canCancel, stillOpenElsewhere); customSaveDialogProvided = true; } } @@ -365,10 +397,11 @@ public final class SWTUtil { // Case 2 : no custom save dialog is provided // we build a default save dialog if (!customSaveDialogProvided && !onlyIfCustomFound) { - result = showStandardSaveDialog(label, canCancel, stillOpenElsewhere); + result = showStandardSaveDialog(message, canCancel, stillOpenElsewhere); } } + @Override public int getResult() { return result; } @@ -379,32 +412,29 @@ public final class SWTUtil { } /** - * Shows a dialog to ask the user to save or not the content of the Session, - * using the given saveDialogExtension, that may define new buttons and - * additional behavior. The window's return codes can be - * ISaveablePart2.CANCEL, ISaveablePart2.YES or ISaveablePart2.NO. + * Shows a dialog to ask the user to save or not the content of the Session, using the given saveDialogExtension, + * that may define new buttons and additional behavior. The window's return codes can be ISaveablePart2.CANCEL, + * ISaveablePart2.YES or ISaveablePart2.NO. * * * @param saveDialogExtension - * the {@link ISaveDialogExtension} to use for showing this save - * window + * the {@link ISaveDialogExtension} to use for showing this save window * @param objectToSave * the object to save - * @param label - * the label of the window + * @param message + * the message to display in the dialog * @param canCancel * indicates whether user can cancel this save action or not * @param stillOpenElsewhere - * <code>true</code> the object to save is open elsewhere, - * <code>false</code> otherwise + * <code>true</code> the object to save is open elsewhere, <code>false</code> otherwise * @return the return code */ - private static int showProvidedSaveDialog(ISaveDialogExtension saveDialogExtension, Object objectToSave, String label, final boolean canCancel, boolean stillOpenElsewhere) { + private static int showProvidedSaveDialog(ISaveDialogExtension saveDialogExtension, Object objectToSave, String message, final boolean canCancel, boolean stillOpenElsewhere) { // Step 1: getting the save buttons Map<String, Integer> buttons = saveDialogExtension.getButtons(stillOpenElsewhere); // Step 2 :opening window - int temporaryResult = openSaveDialog(label, canCancel, buttons, stillOpenElsewhere); + int temporaryResult = openSaveDialog(message, canCancel, buttons, stillOpenElsewhere); // Step 3 : using save contribution to compute additional actions // according to the selected choice @@ -413,18 +443,15 @@ public final class SWTUtil { } /** - * Show a dialog to ask the user to save or not the content of the Session. - * The window's return codes can be ISaveablePart2.CANCEL, - * ISaveablePart2.YES or ISaveablePart2.NO. + * Show a dialog to ask the user to save or not the content of the Session. The window's return codes can be + * ISaveablePart2.CANCEL, ISaveablePart2.YES or ISaveablePart2.NO. * * @param label * the name of the element to save or any other label * @param canCancel - * <code>true</code> if the save can be cancel, - * <code>false</code> otherwise + * <code>true</code> if the save can be cancel, <code>false</code> otherwise * @param stillOpenElsewhere - * <code>true</code> the object to save is open elsewhere, - * <code>false</code> otherwise + * <code>true</code> the object to save is open elsewhere, <code>false</code> otherwise * @return the return code */ private static int showStandardSaveDialog(final String label, final boolean canCancel, boolean stillOpenElsewhere) { @@ -439,7 +466,7 @@ public final class SWTUtil { return temporaryResult; } - private static int openSaveDialog(String label, final boolean canCancel, Map<String, Integer> buttons, boolean stillOpenElsewhere) { + private static int openSaveDialog(String message, final boolean canCancel, Map<String, Integer> buttons, boolean stillOpenElsewhere) { int choice = ISaveablePart2.YES; // Get user preference for still open beahvior @@ -450,7 +477,7 @@ public final class SWTUtil { } else { final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (window != null && buttons != null) { - final MessageDialog dialog = createSaveDialog(label, canCancel, buttons, stillOpenElsewhere, window); + final MessageDialog dialog = createSaveDialog(message, canCancel, buttons, stillOpenElsewhere, window); choice = dialog.open(); @@ -488,22 +515,15 @@ public final class SWTUtil { return choice; } - private static MessageDialog createSaveDialog(String label, final boolean canCancel, Map<String, Integer> buttons, boolean stillOpenElsewhere, final IWorkbenchWindow window) { + private static MessageDialog createSaveDialog(String message, final boolean canCancel, Map<String, Integer> buttons, boolean stillOpenElsewhere, final IWorkbenchWindow window) { final MessageDialog dialog; if (canCancel) { buttons.put(IDialogConstants.CANCEL_LABEL, IDialogConstants.CANCEL_ID); } - // Provide a dialog allowing the user to change the - // preference if several editors are opened - final String message; - if (stillOpenElsewhere) { - message = MessageFormat.format(Messages.SWTUtil_askToSaveChanges, label); - } else { - message = MessageFormat.format(Messages.SWTUtil_askToSaveChanges_openElseWhere, label); - } dialog = new SiriusMessageDialogWithToggle(window.getShell(), Messages.SWTUtil_saveDialog_title, null, message, MessageDialog.QUESTION, buttons, 0, WorkbenchMessages.EditorManager_closeWithoutPromptingOption, false, stillOpenElsewhere) { + @Override protected int getShellStyle() { return getSaveDialogStyle(canCancel); } @@ -552,6 +572,7 @@ public final class SWTUtil { this.composite = composite; } + @Override public void widgetDisposed(final DisposeEvent e) { if (composite != null && !composite.isDisposed()) { composite.dispose(); @@ -561,8 +582,8 @@ public final class SWTUtil { } /** - * Get the number of lines needed to display the <code>text</code> according - * to the default font and the specified width. + * Get the number of lines needed to display the <code>text</code> according to the default font and the specified + * width. * * @param text * The text to display @@ -575,6 +596,7 @@ public final class SWTUtil { RunnableWithResult runnable = new RunnableWithResult() { int nbLines = 1; + @Override public void run() { Shell shell = new Shell(Display.getCurrent()); Label label = new Label(shell, SWT.NONE); @@ -583,6 +605,7 @@ public final class SWTUtil { shell.dispose(); } + @Override public int getResult() { return nbLines; } @@ -602,6 +625,7 @@ public final class SWTUtil { RunnableWithResult runnable = new RunnableWithResult() { int height; + @Override public void run() { Shell shell = new Shell(Display.getCurrent()); Label label = new Label(shell, SWT.NONE); @@ -612,6 +636,7 @@ public final class SWTUtil { shell.dispose(); } + @Override public int getResult() { return height; } @@ -621,8 +646,8 @@ public final class SWTUtil { } /** - * Get the number of lines needed to display the <code>text</code> according - * to the default font and the specified width. + * Get the number of lines needed to display the <code>text</code> according to the default font and the specified + * width. * * @param control * The control used to compute the text size @@ -648,15 +673,13 @@ public final class SWTUtil { } /** - * Compute a new text to display, correctly truncated and with "..." at end - * if needed. + * Compute a new text to display, correctly truncated and with "..." at end if needed. * * @param textValue * The text to display * @param control - * The control used to display text. The parent of this control - * is used to get the maximum width and height available to - * display text. + * The control used to display text. The parent of this control is used to get the maximum width and + * height available to display text. * @param heightOfOneLine * The height in pixel of one line * @return the new text to display. diff --git a/plugins/org.eclipse.sirius.common.ui/src/org/eclipse/sirius/common/ui/tools/internal/preference/CommonPreferenceInitializer.java b/plugins/org.eclipse.sirius.common.ui/src/org/eclipse/sirius/common/ui/tools/internal/preference/CommonPreferenceInitializer.java index 8d0c5d8878..85c7df3fe0 100644 --- a/plugins/org.eclipse.sirius.common.ui/src/org/eclipse/sirius/common/ui/tools/internal/preference/CommonPreferenceInitializer.java +++ b/plugins/org.eclipse.sirius.common.ui/src/org/eclipse/sirius/common/ui/tools/internal/preference/CommonPreferenceInitializer.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2008, 2009 THALES GLOBAL SERVICES. + * Copyright (c) 2007, 2008, 2009, 2018 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 @@ -37,6 +37,7 @@ public class CommonPreferenceInitializer extends AbstractPreferenceInitializer { preferenceStore.setDefault(CommonPreferencesConstants.PREF_GROUP_BY_CONTAINING_FEATURE, false); preferenceStore.setDefault(CommonPreferencesConstants.PREF_GROUP_TRIGGER, 10000); preferenceStore.setDefault(CommonPreferencesConstants.PREF_GROUP_SIZE, 100); + preferenceStore.setDefault(CommonPreferencesConstants.PREF_ASK_TO_SAVE_RESOURCE_AFTER_MIGRATION, false); } /** diff --git a/plugins/org.eclipse.sirius.common.ui/src/org/eclipse/sirius/common/ui/tools/internal/util/MigrationUIUtil.java b/plugins/org.eclipse.sirius.common.ui/src/org/eclipse/sirius/common/ui/tools/internal/util/MigrationUIUtil.java new file mode 100644 index 0000000000..48c9f57c70 --- /dev/null +++ b/plugins/org.eclipse.sirius.common.ui/src/org/eclipse/sirius/common/ui/tools/internal/util/MigrationUIUtil.java @@ -0,0 +1,113 @@ +/******************************************************************************* + * Copyright (c) 2018 Obeo. + * 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.sirius.common.ui.tools.internal.util; + +import java.text.MessageFormat; + +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.xmi.XMLResource; +import org.eclipse.sirius.business.api.session.Session; +import org.eclipse.sirius.business.internal.migration.AbstractSiriusMigrationService; +import org.eclipse.sirius.common.tools.api.constant.CommonPreferencesConstants; +import org.eclipse.sirius.common.ui.Messages; +import org.eclipse.sirius.common.ui.SiriusTransPlugin; +import org.eclipse.sirius.common.ui.tools.api.util.SWTUtil; +import org.eclipse.ui.ISaveablePart2; + +/** + * Utility class used for displaying UI elements about resource migration. + * + * @author mcartaud + * + */ +public final class MigrationUIUtil { + + private MigrationUIUtil() { + // Prevent instantiation + } + + /** + * Test if the resource has been automatically migrated. If it is the case and this is due to a direct user action, + * ask user if he want to save the resource + * + * @param resource + * The resource to test + * @return <code>true</code> if the user want to save the session, <code>false</code> otherwise + */ + public static boolean shouldMigratedElementBeSaved(Resource resource) { + String migrateFrom = hasBeenMigratedFrom(resource); + if (migrateFrom != null && shouldUserBeWarnedAboutMigration(resource)) { + return doAskUserIfElementShouldBeSaved(resource); + } + return false; + } + + /** + * Test if the session resource has been automatically migrated. If it is the case and this is due to a direct user + * action, ask user if he want to save the session + * + * @param session + * The session to test + * @return <code>true</code> if the user want to save the session, <code>false</code> otherwise + */ + public static boolean shouldMigratedElementBeSaved(Session session) { + for (Resource resource : session.getAllSessionResources()) { + String migrateFrom = hasBeenMigratedFrom(resource); + if (migrateFrom != null && shouldUserBeWarnedAboutMigration(resource)) { + return doAskUserIfElementShouldBeSaved(resource); + } + } + return false; + } + + private static boolean doAskUserIfElementShouldBeSaved(Resource resource) { + String message = MessageFormat.format(Messages.MigrationUIUtil_askToSaveChanges, resource.getURI().lastSegment()); + return SWTUtil.showSaveDialogWithMessage(resource, message, true) == ISaveablePart2.YES; + } + + /** + * Test if the given resource has been migrated due to a direct user action. + * + * @param resource + * The given resource + * @return <code>true</code> if the resource as been migrated because of a direct user action, <code>false</code> + * otherwise + */ + public static boolean hasBeenMigratedAndUserShouldBeWarned(Resource resource) { + return hasBeenMigratedFrom(resource) != null && shouldUserBeWarnedAboutMigration(resource); + } + + private static String hasBeenMigratedFrom(Resource resource) { + String migrateFrom = null; + if (resource instanceof XMLResource) { + Object result = ((XMLResource) resource).getDefaultLoadOptions().get(AbstractSiriusMigrationService.OPTION_RESOURCE_MIGRATION_LOADEDVERSION); + if (result instanceof String) { + migrateFrom = (String) result; + } + } + return migrateFrom; + } + + private static boolean shouldUserBeWarnedAboutMigration(Resource resource) { + boolean prefAskToSave = SiriusTransPlugin.getPlugin().getPreferenceStore().getBoolean(CommonPreferencesConstants.PREF_ASK_TO_SAVE_RESOURCE_AFTER_MIGRATION); + boolean directUserAction = false; + if (resource instanceof XMLResource) { + Object option = ((XMLResource) resource).getDefaultLoadOptions().get(AbstractSiriusMigrationService.OPTION_RESOURCE_NON_BATCH_MIGRATION); + if (option instanceof Boolean) { + directUserAction = (boolean) option; + } else if (option instanceof String) { + directUserAction = Boolean.parseBoolean((String) option); + } + } + return prefAskToSave && directUserAction; + } + +} diff --git a/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/constant/CommonPreferencesConstants.java b/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/constant/CommonPreferencesConstants.java index 8df1e9e6b2..a7b141976e 100644 --- a/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/constant/CommonPreferencesConstants.java +++ b/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/constant/CommonPreferencesConstants.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011 THALES GLOBAL SERVICES. + * Copyright (c) 2011, 2018 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 @@ -20,8 +20,7 @@ package org.eclipse.sirius.common.tools.api.constant; public interface CommonPreferencesConstants { /** - * Says if the file edit validation should be done as soon as a command is - * executed or not. + * Says if the file edit validation should be done as soon as a command is executed or not. */ String PREF_DEFENSIVE_EDIT_VALIDATION = "DEFENSIVE_VALIDATE_EDIT"; //$NON-NLS-1$ @@ -36,8 +35,7 @@ public interface CommonPreferencesConstants { String PREF_GROUP_ENABLE = "GROUP_ENABLE"; //$NON-NLS-1$ /** - * Says if the grouping strategy uses the containing feature instead of the - * basic hierarchy. + * Says if the grouping strategy uses the containing feature instead of the basic hierarchy. */ String PREF_GROUP_BY_CONTAINING_FEATURE = "GROUP_BY_CONTAINING_FEATURE"; //$NON-NLS-1$ @@ -51,4 +49,9 @@ public interface CommonPreferencesConstants { */ String PREF_GROUP_SIZE = "GROUP_SIZE"; //$NON-NLS-1$ + /** + * Ask user if he want to save migrated resources. + */ + String PREF_ASK_TO_SAVE_RESOURCE_AFTER_MIGRATION = "ASK_TO_SAVE_RESOURCE_AFTER_MIGRATION"; //$NON-NLS-1$ + } diff --git a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html index c7fbb94cbc..d3d8901d02 100644 --- a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html +++ b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html @@ -16,6 +16,12 @@ <a href="#sirius6.1.0">Changes in Sirius 6.1.0</a> <ol style="list-style: disc;"> <li> + <a href="#UserVisibleChanges">User-Visible Changes</a> + </li> + <li> + <a href="#SpecifierVisibleChanges">Specifier-Visible Changes</a> + </li> + <li> <a href="#DeveloperVisibleChanges">Developer-Visible Changes</a> </li> </ol> @@ -24,10 +30,10 @@ <a href="#sirius6.0.0">Changes in Sirius 6.0.0</a> <ol style="list-style: disc;"> <li> - <a href="#UserVisibleChanges">User-Visible Changes</a> + <a href="#UserVisibleChanges2">User-Visible Changes</a> </li> <li> - <a href="#SpecifierVisibleChanges">Specifier-Visible Changes</a> + <a href="#SpecifierVisibleChanges2">Specifier-Visible Changes</a> </li> <li> <a href="#DeveloperVisibleChanges2">Developer-Visible Changes</a> @@ -38,7 +44,7 @@ <a href="#sirius5.1.1">Changes in Sirius 5.1.1</a> <ol style="list-style: disc;"> <li> - <a href="#UserVisibleChanges2">User-Visible Changes</a> + <a href="#UserVisibleChanges3">User-Visible Changes</a> </li> <li> <a href="#DeveloperVisibleChanges3">Developer-Visible Changes</a> @@ -49,10 +55,10 @@ <a href="#sirius5.1.0">Changes in Sirius 5.1.0</a> <ol style="list-style: disc;"> <li> - <a href="#UserVisibleChanges3">User-Visible Changes</a> + <a href="#UserVisibleChanges4">User-Visible Changes</a> </li> <li> - <a href="#SpecifierVisibleChanges2">Specifier-Visible Changes</a> + <a href="#SpecifierVisibleChanges3">Specifier-Visible Changes</a> </li> <li> <a href="#DeveloperVisibleChanges4">Developer-Visible Changes</a> @@ -66,13 +72,13 @@ <a href="#sirius5.0.0">Changes in Sirius 5.0.0</a> <ol style="list-style: disc;"> <li> - <a href="#UserVisibleChanges4">User-Visible Changes</a> + <a href="#UserVisibleChanges5">User-Visible Changes</a> </li> <li> <a href="#DeveloperVisibleChanges5">Developer-Visible Changes</a> </li> <li> - <a href="#SpecifierVisibleChanges3">Specifier-Visible Changes</a> + <a href="#SpecifierVisibleChanges4">Specifier-Visible Changes</a> </li> </ol> </li> @@ -83,14 +89,33 @@ <a href="Release_Notes_Previous.html">the release notes from previous versions</a> for details about older releases. </p> <h2 id="sirius6.1.0">Changes in Sirius 6.1.0</h2> + <h3 id="UserVisibleChanges">User-Visible Changes</h3> + <ul> + <li><span class="label label-success">Added</span> A new preference has been added in the Sirius preference panel. It allows Sirius to ask the user if he wants to save session resources after an automatic migration. If the new preference is ticked, the pop-up will only appear for session opening caused by a direct action of the user (i.e. opening a diagram or unfolding the resources in the model explorer).</li> + </ul> + <h3 id="SpecifierVisibleChanges">Specifier-Visible Changes</h3> <h3 id="DeveloperVisibleChanges">Developer-Visible Changes</h3> <ul> <li><span class="label label-info">Modified</span> Upgraded ELK version from 0.3.0 to 0.4.0, see the <a href="https://projects.eclipse.org/projects/modeling.elk/releases/0.4.0">ELK documentation</a> for the list of changes in that version. </li> + <li><span class="label label-success">Added</span> Mechanism to ask user input on opening of a session with migrated resources if the session opening comes from a direct user action + <ul> + <li>New available UI callback ( + <code>org.eclipse.sirius.tools.api.command.ui.UICallBack.askUserAndSaveMigratedSession(session)</code>) used to ask user if he wants to save the resources after migration and save them if necessary. + </li> + <li>New method to open session when this is due to a direct user action ( + <code>org.eclipse.sirius.business.api.session.SessionManager.openSession(sessionResourceURI, monitor, uiCallback, isDirectUserActionLoading)</code>). Previous version calls this new version with the value false for + <code>isDirectUserActionLoading</code> parameter + </li> + <li>New system preference to know if user want to be asked to save resources after automatic migration + <code>org.eclipse.sirius.common.tools.api.constant.CommonPreferencesConstants.PREF_ASK_TO_SAVE_RESOURCE_AFTER_MIGRATION</code> + </li> + </ul> + </li> </ul> <h2 id="sirius6.0.0">Changes in Sirius 6.0.0</h2> - <h3 id="UserVisibleChanges">User-Visible Changes</h3> + <h3 id="UserVisibleChanges2">User-Visible Changes</h3> <ul> <li><span class="label label-success">Added</span> A new feature allows user to insert vertical blank space in sequence diagram. You can refer to the <a href="user/sequences/Sequence%20Diagrams.html#insert_vertical_blank_space">user documentation </a> for more details. @@ -115,7 +140,7 @@ <p> <img border="0" src="images/color_palette.png"/> </p> - <h3 id="SpecifierVisibleChanges">Specifier-Visible Changes</h3> + <h3 id="SpecifierVisibleChanges2">Specifier-Visible Changes</h3> <ul> <li><span class="label label-success">Added</span> An action is added in main toolbar to reload the VSM of installed plug-ins that may have changed. Refer to the <a href="specifier/general/Specifying_Viewpoints.html#reloadVSM">specifier documentation</a> for details. @@ -290,7 +315,7 @@ </ul> <h4 id="TranslationKeysChanges">Translation Keys Changes</h4> <h2 id="sirius5.1.1">Changes in Sirius 5.1.1</h2> - <h3 id="UserVisibleChanges2">User-Visible Changes</h3> + <h3 id="UserVisibleChanges3">User-Visible Changes</h3> <ul> <li><span class="label label-info">Modified</span> When exporting a diagram as an image, it is now possible to choose an image size level. Before this, a preference called <em>AutoScale</em> was available and when it was enable, the diagram was scaled to the maximum size safely allowed by the system. Now, a new preference named @@ -375,7 +400,7 @@ </ul> <p>testcase.</p> <h2 id="sirius5.1.0">Changes in Sirius 5.1.0</h2> - <h3 id="UserVisibleChanges3">User-Visible Changes</h3> + <h3 id="UserVisibleChanges4">User-Visible Changes</h3> <ul> <li><span class="label label-success">Added</span> When exporting a diagram as an image, it is now possible to choose whether or not the diagram should be scaled. If disabled, the diagram will be exported with its normal size (equivalent to a 100% zoom level). If auto-scaling is enabled, the diagram will be scaled to the maximum size safely allowed by the system (this can be different on different OSes). Note that when auto-scaling is enabled, the image files produced may be larger than without. When exporting very large diagrams it is also possible that the diagram will be scaled <em>down</em> (i.e. with a zoom level smaller than 100%). Enabling auto-scaling can be chosen on a case by case basis from the export dialog; the initial value in the dialog can be controlled by a new preference available in the @@ -424,7 +449,7 @@ <a href="developer/extensions-provide_custom_bundled_image_shape.html#bundleImageShape">bundleImageShape</a> ), opening or refreshing a diagram will not display exception anymore when the bundleImageShape extension is not valid. A warning is now displayed in the Error Log view to inform user of which attribute of the extension is not correct. </li> </ul> - <h3 id="SpecifierVisibleChanges2">Specifier-Visible Changes</h3> + <h3 id="SpecifierVisibleChanges3">Specifier-Visible Changes</h3> <ul> <li><span class="label label-success">Added</span> An <a href="./user/general/Modeling%20Project.html#Migration">automatic migration</a> has been added in this version to fix diagram with edge labels corrupted (see @@ -699,7 +724,7 @@ <a href="user/general/Aird_Editor.html">the aird editor</a>. </p> <h2 id="sirius5.0.0">Changes in Sirius 5.0.0</h2> - <h3 id="UserVisibleChanges4">User-Visible Changes</h3> + <h3 id="UserVisibleChanges5">User-Visible Changes</h3> <ul> <li><span class="label label-success">Added</span> An new <em>aird editor</em> is available on @@ -724,7 +749,7 @@ <li><span class="label label-info">Modified</span> Decorators on diagram elements are drawn on top of other figures. If there is an overlap between a decorator of a figure A and another figure B that is over figure A, when user clicks on the decorator, the figure B is now selected (before it was the parent figure A).</li> </ul> <h3 id="DeveloperVisibleChanges5">Developer-Visible Changes</h3> - <h3 id="SpecifierVisibleChanges3">Specifier-Visible Changes</h3> + <h3 id="SpecifierVisibleChanges4">Specifier-Visible Changes</h3> <ul> <li><span class="label label-success">Added</span> It is now possible to automatically create one or several pre-configured widget(s) in a group if its domain class and if the meta-models of the properties view containing it have been specified. The widget(s) created will be infered from the features in the domain class (e.g. a properly configured <em>Checkbox</em> widget will be created for boolean attributes). diff --git a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile index 9d0f16b6c9..86634d41e5 100644 --- a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile +++ b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile @@ -6,9 +6,19 @@ This document contains the release notes for recent major releases of Sirius. Se h2(#sirius6.1.0). Changes in Sirius 6.1.0 +h3. User-Visible Changes + +* <span class="label label-success">Added</span> A new preference has been added in the Sirius preference panel. It allows Sirius to ask the user if he wants to save session resources after an automatic migration. If the new preference is ticked, the pop-up will only appear for session opening caused by a direct action of the user (i.e. opening a diagram or unfolding the resources in the model explorer). + +h3. Specifier-Visible Changes + h3. Developer-Visible Changes * <span class="label label-info">Modified</span> Upgraded ELK version from 0.3.0 to 0.4.0, see the "ELK documentation":https://projects.eclipse.org/projects/modeling.elk/releases/0.4.0 for the list of changes in that version. +* <span class="label label-success">Added</span> Mechanism to ask user input on opening of a session with migrated resources if the session opening comes from a direct user action +** New available UI callback (@org.eclipse.sirius.tools.api.command.ui.UICallBack.askUserAndSaveMigratedSession(session)@) used to ask user if he wants to save the resources after migration and save them if necessary. +** New method to open session when this is due to a direct user action (@org.eclipse.sirius.business.api.session.SessionManager.openSession(sessionResourceURI, monitor, uiCallback, isDirectUserActionLoading)@). Previous version calls this new version with the value false for @isDirectUserActionLoading@ parameter +** New system preference to know if user want to be asked to save resources after automatic migration @org.eclipse.sirius.common.tools.api.constant.CommonPreferencesConstants.PREF_ASK_TO_SAVE_RESOURCE_AFTER_MIGRATION@ h2(#sirius6.0.0). Changes in Sirius 6.0.0 diff --git a/plugins/org.eclipse.sirius.doc/doc/developer/extensions-provide_save_dialog.html b/plugins/org.eclipse.sirius.doc/doc/developer/extensions-provide_save_dialog.html index 5b5e319d59..30a41ca7b5 100644 --- a/plugins/org.eclipse.sirius.doc/doc/developer/extensions-provide_save_dialog.html +++ b/plugins/org.eclipse.sirius.doc/doc/developer/extensions-provide_save_dialog.html @@ -62,7 +62,7 @@ public class CustomSaveDialogExtension { } public Collection<String> getButtons() { - return new ArrayList<String>(Arrays.asList("Save", "Make something special", "Discard")); + return new ArrayList<String>(Arrays.asList("Save", "Make something special", "Discard")); } public int reactToValue(Object objectToSave, int temporaryResult) { diff --git a/plugins/org.eclipse.sirius.doc/doc/user/general/Modeling Project.html b/plugins/org.eclipse.sirius.doc/doc/user/general/Modeling Project.html index ae3fb179ba..affbf9cff8 100644 --- a/plugins/org.eclipse.sirius.doc/doc/user/general/Modeling Project.html +++ b/plugins/org.eclipse.sirius.doc/doc/user/general/Modeling Project.html @@ -158,7 +158,17 @@ <a href="../../Release_Notes.html">release notes</a> for more details. </p> <h3 id="Migration">Migration of Existing Representation Files</h3> - <p>Representation files are now automatically migrated when opened. This migration is transparent for the end-user. While a representation file is not saved, the automatic migration will be replayed at the next opening.</p> + <p>By default, representation and design files are now automatically migrated when opened. This migration is transparent for the end-user. While a representation file is not saved, the automatic migration will be replayed at the next opening.</p> + <p>You can activate a preference to be asked to save resources when a migration has been done. It is available in Sirius preferences page:</p> + <img border="0" src="images/migrationPreference.png"/> + <p>When checked, a dialog asking you to save migrated resources is shown in the following situations if a migration was necessary:</p> + <ul> + <li>When you open or expand a modeling project not yet loaded.</li> + <li>When you open the session by double clicking on the aird or VSM or by using the contextual menu + <em>open</em>. + </li> + <li>When you open your bundle whereas a Sirius editor was opened previously.</li> + </ul> <h3 id="UICHanges">User Interface Changes</h3> <p>You will notice some radical changes in the user interface. The most important change is the disappearance of the <em>Model Content</em> view. It has been replaced with a streamlined UI which integrates directly into the Eclipse explorer view. The notion of “Local Session” has disappeared from the user interface; its management has been made as transparent as possible so you do not have to deal with it except in some very specific circumstances. diff --git a/plugins/org.eclipse.sirius.doc/doc/user/general/Modeling Project.textile b/plugins/org.eclipse.sirius.doc/doc/user/general/Modeling Project.textile index f5d199d741..444723f54b 100644 --- a/plugins/org.eclipse.sirius.doc/doc/user/general/Modeling Project.textile +++ b/plugins/org.eclipse.sirius.doc/doc/user/general/Modeling Project.textile @@ -31,7 +31,16 @@ New users can skip this section safely. For users of previous version who have e h3(#Migration). Migration of Existing Representation Files -Representation files are now automatically migrated when opened. This migration is transparent for the end-user. While a representation file is not saved, the automatic migration will be replayed at the next opening. +By default, representation and design files are now automatically migrated when opened. This migration is transparent for the end-user. While a representation file is not saved, the automatic migration will be replayed at the next opening. + +You can activate a preference to be asked to save resources when a migration has been done. It is available in Sirius preferences page: + + !images/migrationPreference.png! + +When checked, a dialog asking you to save migrated resources is shown in the following situations if a migration was necessary: +* When you open or expand a modeling project not yet loaded. +* When you open the session by double clicking on the aird or VSM or by using the contextual menu _open_. +* When you open your bundle whereas a Sirius editor was opened previously. h3(#UICHanges). User Interface Changes diff --git a/plugins/org.eclipse.sirius.doc/doc/user/general/images/migrationPreference.png b/plugins/org.eclipse.sirius.doc/doc/user/general/images/migrationPreference.png Binary files differnew file mode 100644 index 0000000000..6f0160221f --- /dev/null +++ b/plugins/org.eclipse.sirius.doc/doc/user/general/images/migrationPreference.png diff --git a/plugins/org.eclipse.sirius.editor/src/org/eclipse/sirius/editor/tools/internal/presentation/CustomSiriusEditor.java b/plugins/org.eclipse.sirius.editor/src/org/eclipse/sirius/editor/tools/internal/presentation/CustomSiriusEditor.java index c33313ee8c..ccef0d4d52 100644 --- a/plugins/org.eclipse.sirius.editor/src/org/eclipse/sirius/editor/tools/internal/presentation/CustomSiriusEditor.java +++ b/plugins/org.eclipse.sirius.editor/src/org/eclipse/sirius/editor/tools/internal/presentation/CustomSiriusEditor.java @@ -61,11 +61,13 @@ import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.ViewerFilter; import org.eclipse.sirius.business.api.helper.SiriusUtil; import org.eclipse.sirius.business.api.logger.MarkerRuntimeLogger; +import org.eclipse.sirius.business.internal.migration.AbstractSiriusMigrationService; import org.eclipse.sirius.business.internal.migration.description.VSMExtendedMetaData; import org.eclipse.sirius.business.internal.migration.description.VSMMigrationService; import org.eclipse.sirius.business.internal.migration.description.VSMResourceHandler; import org.eclipse.sirius.business.internal.migration.description.VSMVersionSAXParser; import org.eclipse.sirius.common.ui.tools.api.editor.IEObjectNavigable; +import org.eclipse.sirius.common.ui.tools.internal.util.MigrationUIUtil; import org.eclipse.sirius.editor.Messages; import org.eclipse.sirius.editor.editorPlugin.SiriusEditor; import org.eclipse.sirius.editor.editorPlugin.SiriusEditorPlugin; @@ -421,6 +423,14 @@ public class CustomSiriusEditor extends SiriusEditor implements IEObjectNavigabl resource = editingDomain.getResourceSet().getResource(resourceURI, false); } + if (resource instanceof XMLResource) { + ((XMLResource) resource).getDefaultLoadOptions().put(AbstractSiriusMigrationService.OPTION_RESOURCE_NON_BATCH_MIGRATION, true); + } + + if (MigrationUIUtil.shouldMigratedElementBeSaved(resource)) { + doSave(new NullProgressMonitor()); + } + Diagnostic diagnostic = analyzeResourceProblems(resource, exception); if (diagnostic.getSeverity() != Diagnostic.OK) { resourceToDiagnosticMap.put(resource, analyzeResourceProblems(resource, exception)); @@ -472,7 +482,7 @@ public class CustomSiriusEditor extends SiriusEditor implements IEObjectNavigabl boolean first = true; for (Resource resource : editingDomain.getResourceSet().getResources()) { if ((first || !resource.getContents().isEmpty() || isPersisted(resource)) && !editingDomain.isReadOnly(resource)) { - if (resource.isTrackingModification() && !resource.isModified()) { + if (!MigrationUIUtil.hasBeenMigratedAndUserShouldBeWarned(resource) && resource.isTrackingModification() && !resource.isModified()) { continue; } try { diff --git a/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/SessionEditor.java b/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/SessionEditor.java index d4fb9ebcba..af8aeb75ee 100644 --- a/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/SessionEditor.java +++ b/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/SessionEditor.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2017 Obeo. + * Copyright (c) 2017, 2018 Obeo. * 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 @@ -368,7 +368,7 @@ public class SessionEditor extends SharedHeaderFormEditor implements ITabbedProp public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { SubMonitor subMonitor = SubMonitor.convert(monitor, 1); subMonitor.beginTask(MessageFormat.format(Messages.UI_SessionEditor_session_loading_task_title, new Object[0]), 1); - session = SessionManager.INSTANCE.openSession(sessionResourceURIFinal, subMonitor, SiriusEditPlugin.getPlugin().getUiCallback()); + session = SessionManager.INSTANCE.openSession(sessionResourceURIFinal, subMonitor, SiriusEditPlugin.getPlugin().getUiCallback(), true); session.addListener(SessionEditor.this); final IEditingSession editingSession = SessionUIManager.INSTANCE.getOrCreateUISession(session); diff --git a/plugins/org.eclipse.sirius.ui/plugin.properties b/plugins/org.eclipse.sirius.ui/plugin.properties index dc66d3bbf3..f493da11f4 100644 --- a/plugins/org.eclipse.sirius.ui/plugin.properties +++ b/plugins/org.eclipse.sirius.ui/plugin.properties @@ -341,6 +341,8 @@ SiriusPreferencePage_refreshGroup = Refresh SiriusPreferencePage_refreshOnRepresentationOpening = Do refresh on representation opening SiriusPreferencePage_sessionEditorGroup=Aird editor SiriusPreferencePage_autoSessionEditorOpening=Automatically open the aird editor when an aird file is loaded +SiriusPreferencePage_migrationGroup=Migration +SiriusPreferencePage_askUserToSaveAfterMigration=Ask to save resources for migrations directly initiated by user SiriusRepresentationWithInactiveStatusLabelProvider_viewpointItem_tooltip=Viewpoint SiriusRepresentationWithInactiveStatusLabelProvider_representationDescriptionItem_tooltip=Representation Type SiriusUncontrolHandler_uncontrolRepresentationsMessage = Do you want to uncontrol representations in addition to the semantic elements? diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/api/session/SessionEditorInput.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/api/session/SessionEditorInput.java index e662703f5e..f09e3262cd 100644 --- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/api/session/SessionEditorInput.java +++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/api/session/SessionEditorInput.java @@ -280,7 +280,7 @@ public class SessionEditorInput extends URIEditorInput { private static Session openSession(URI sessionModelURI, boolean restore, Session sessionFromURI) { Session session = sessionFromURI; if (session == null && restore) { - session = SessionManager.INSTANCE.openSession(sessionModelURI, new NullProgressMonitor(), SiriusEditPlugin.getPlugin().getUiCallback()); + session = SessionManager.INSTANCE.openSession(sessionModelURI, new NullProgressMonitor(), SiriusEditPlugin.getPlugin().getUiCallback(), true); } if (session != null && session.isOpen()) { 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 a025ded06b..be231a70fc 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, 2017 THALES GLOBAL SERVICES and others. + * Copyright (c) 2010, 2018 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 @@ -18,6 +18,7 @@ import java.util.List; import java.util.Set; import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.NullProgressMonitor; @@ -50,6 +51,7 @@ import org.eclipse.sirius.common.ui.SiriusTransPlugin; import org.eclipse.sirius.common.ui.tools.api.selection.EMFMessageDialog; import org.eclipse.sirius.common.ui.tools.api.selection.EObjectSelectionWizard; import org.eclipse.sirius.common.ui.tools.api.util.EclipseUIUtil; +import org.eclipse.sirius.common.ui.tools.internal.util.MigrationUIUtil; import org.eclipse.sirius.tools.api.command.ui.UICallBack; import org.eclipse.sirius.ui.business.api.dialect.DialectUIManager; import org.eclipse.sirius.ui.business.api.resource.LoadEMFResourceRunnableWithProgress; @@ -67,6 +69,7 @@ import org.eclipse.sirius.viewpoint.provider.SiriusEditPlugin; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.actions.WorkspaceModifyOperation; import com.google.common.collect.Iterables; @@ -379,4 +382,25 @@ public abstract class AbstractSWTCallback implements UICallBack { return false; } + @Override + public void askUserAndSaveMigratedSession(Session session) { + if (MigrationUIUtil.shouldMigratedElementBeSaved(session)) { + PlatformUI.getWorkbench().getDisplay().asyncExec(() -> { + try { + new ProgressMonitorDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell()).run(false, false, new WorkspaceModifyOperation() { + @Override + protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException { + session.save(monitor); + } + }); + } catch (InvocationTargetException e) { + SiriusEditPlugin.getPlugin().getLog().log(new Status(IStatus.ERROR, SiriusEditPlugin.ID, e.getLocalizedMessage(), e)); + } catch (InterruptedException e) { + SiriusEditPlugin.getPlugin().getLog().log(new Status(IStatus.ERROR, SiriusEditPlugin.ID, e.getLocalizedMessage(), e)); + } + }); + + } + } + } diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/preference/SiriusPreferencePage.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/preference/SiriusPreferencePage.java index 96e8a44f78..6d667feec3 100644 --- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/preference/SiriusPreferencePage.java +++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/preference/SiriusPreferencePage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2015 THALES GLOBAL SERVICES and others. + * Copyright (c) 2008, 2018 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 @@ -53,6 +53,8 @@ public class SiriusPreferencePage extends FieldEditorPreferencePage implements I private BooleanFieldEditor autoSessionEditorOpening; + private BooleanFieldEditor askUserToSaveAfterMigration; + private IntegerFieldEditor groupTrigger; private IntegerFieldEditor groupSize; @@ -72,6 +74,7 @@ public class SiriusPreferencePage extends FieldEditorPreferencePage implements I addProfilingField(parent); addGroupTreeItemsField(parent); addSessionEditorFields(parent); + addMigrationFields(parent); } private void addFilesFields(Composite parent) { @@ -90,12 +93,21 @@ public class SiriusPreferencePage extends FieldEditorPreferencePage implements I private void addSessionEditorFields(Composite parent) { Composite refreshComposite = createGroup(parent, Messages.SiriusPreferencePage_sessionEditorGroup); - autoSessionEditorOpening = new BooleanFieldEditor(SessionEditorUIPreferencesKeys.PREF_OPEN_SESSION_EDITOR_ON_SESSION_OPEN.name(), - Messages.SiriusPreferencePage_autoSessionEditorOpening, new Composite(refreshComposite, SWT.NONE)); + autoSessionEditorOpening = new BooleanFieldEditor(SessionEditorUIPreferencesKeys.PREF_OPEN_SESSION_EDITOR_ON_SESSION_OPEN.name(), Messages.SiriusPreferencePage_autoSessionEditorOpening, + new Composite(refreshComposite, SWT.NONE)); addField(autoSessionEditorOpening); } + private void addMigrationFields(Composite parent) { + Composite migrationComposite = createGroup(parent, Messages.SiriusPreferencePage_migrationGroup); + + askUserToSaveAfterMigration = new BooleanFieldEditor(CommonPreferencesConstants.PREF_ASK_TO_SAVE_RESOURCE_AFTER_MIGRATION, Messages.SiriusPreferencePage_askUserToSaveAfterMigration, + new Composite(migrationComposite, SWT.NONE)); + addField(askUserToSaveAfterMigration); + + } + private void addRefreshFields(Composite parent) { Composite refreshComposite = createGroup(parent, Messages.SiriusPreferencePage_refreshGroup); @@ -177,6 +189,9 @@ public class SiriusPreferencePage extends FieldEditorPreferencePage implements I groupSize.setPreferenceStore(SiriusTransPlugin.getPlugin().getPreferenceStore()); groupSize.load(); + + askUserToSaveAfterMigration.setPreferenceStore(SiriusTransPlugin.getPlugin().getPreferenceStore()); + askUserToSaveAfterMigration.load(); } } diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/modelingproject/OpenRepresentationsFileJob.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/modelingproject/OpenRepresentationsFileJob.java index 0844311a99..ca85bd1981 100644 --- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/modelingproject/OpenRepresentationsFileJob.java +++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/modelingproject/OpenRepresentationsFileJob.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2017 THALES GLOBAL SERVICES and others. + * Copyright (c) 2011, 2018 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 @@ -63,14 +63,33 @@ public class OpenRepresentationsFileJob extends AbstractRepresentationsFileJob { private URI representationsFileURI; /** + * <code>True</code> if this session opening comes from a direct user action, </code>false<code> otherwise. + */ + private final boolean isDirectUserActionLoading; + + /** * Constructor to open only one representations file. * * @param representationsFileURI * The URI of the representations file to open. */ public OpenRepresentationsFileJob(final URI representationsFileURI) { + this(representationsFileURI, false); + } + + /** + * Constructor to open only one representations file. + * + * @param representationsFileURI + * The URI of the representations file to open. + * @param isDirectUserActionLoading + * <code>true</code> if this session opening comes from a direct user action, </code>false<code> + * otherwise + */ + public OpenRepresentationsFileJob(final URI representationsFileURI, final boolean isDirectUserActionLoading) { super(OpenRepresentationsFileJob.JOB_LABEL); this.representationsFileURI = representationsFileURI; + this.isDirectUserActionLoading = isDirectUserActionLoading; // During the execution of this job, some refresh can occurs on files of // this project but also on file of other projects according to // dependencies of this session, so the scheduling rule must include the @@ -92,8 +111,23 @@ public class OpenRepresentationsFileJob extends AbstractRepresentationsFileJob { * <code>true</code> if this job is a user-initiated job, and <code>false</code> otherwise. */ public static void scheduleNewWhenPossible(URI representationsFileURI, boolean user) { + scheduleNewWhenPossible(representationsFileURI, user, false); + } + + /** + * Launch this job when all other openRepresentationFile's job are finished. + * + * @param representationsFileURI + * The URI of the representations file to open. + * @param user + * <code>true</code> if this job is a user-initiated job, and <code>false</code> otherwise. + * @param isDirectUserActionLoading + * <code>true</code> if this session opening comes from a direct user action, </code>false<code> + * otherwise + */ + public static void scheduleNewWhenPossible(URI representationsFileURI, boolean user, boolean isDirectUserActionLoading) { // Schedule a new job for this representations file. - Job job = new OpenRepresentationsFileJob(representationsFileURI); + Job job = new OpenRepresentationsFileJob(representationsFileURI, isDirectUserActionLoading); job.setUser(user); job.setPriority(Job.SHORT); job.schedule(); @@ -153,7 +187,7 @@ public class OpenRepresentationsFileJob extends AbstractRepresentationsFileJob { if (SiriusUtil.SESSION_RESOURCE_EXTENSION.equals(representationsFileURI.fileExtension())) { subMonitor.worked(1); subMonitor.subTask(MessageFormat.format(Messages.OpenRepresentationsFileJob_loadReferencedModelsTask, representationsFileURI.lastSegment())); - session = SessionManager.INSTANCE.openSession(representationsFileURI, subMonitor.newChild(14), SiriusEditPlugin.getPlugin().getUiCallback()); + session = SessionManager.INSTANCE.openSession(representationsFileURI, subMonitor.newChild(14), SiriusEditPlugin.getPlugin().getUiCallback(), isDirectUserActionLoading); if (session != null) { Set<ISessionFileLoadingListener> sessionFileLoadingListeners = SiriusEditPlugin.getPlugin().getSessionFileLoadingListeners(); for (ISessionFileLoadingListener sessionFileLoadingListener : sessionFileLoadingListeners) { diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/modelingproject/manager/ModelingProjectManagerImpl.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/modelingproject/manager/ModelingProjectManagerImpl.java index f5a58140a9..84714d2e5b 100644 --- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/modelingproject/manager/ModelingProjectManagerImpl.java +++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/modelingproject/manager/ModelingProjectManagerImpl.java @@ -189,12 +189,12 @@ public class ModelingProjectManagerImpl implements ModelingProjectManager { // Launch the silently job to open the representations files for (URI representationsFilesURI : tempRepresentationsFilesURIs) { if (alreadyInUserWorkspaceModifyOperation) { - WorkspaceJob job = new OpenRepresentationsFileJob(representationsFilesURI); + WorkspaceJob job = new OpenRepresentationsFileJob(representationsFilesURI, true); job.setUser(user); job.setPriority(Job.SHORT); job.runInWorkspace(new NullProgressMonitor()); } else { - OpenRepresentationsFileJob.scheduleNewWhenPossible(representationsFilesURI, user); + OpenRepresentationsFileJob.scheduleNewWhenPossible(representationsFilesURI, user, true); } } } 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 9d4301af55..9b10d0dfbf 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 @@ -1007,6 +1007,12 @@ public final class Messages { public static String SiriusRepresentationWithInactiveStatusLabelProvider_viewpointItem_tooltip; @TranslatableMessage + public static String SiriusPreferencePage_migrationGroup; + + @TranslatableMessage + public static String SiriusPreferencePage_askUserToSaveAfterMigration; + + @TranslatableMessage public static String SiriusRepresentationWithInactiveStatusLabelProvider_representationDescriptionItem_tooltip; @TranslatableMessage diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/session/SessionManager.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/session/SessionManager.java index ca686352ac..f9ba59a5dc 100644 --- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/session/SessionManager.java +++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/session/SessionManager.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2017 THALES GLOBAL SERVICES. + * Copyright (c) 2007, 2018 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 @@ -143,7 +143,9 @@ public interface SessionManager { /** * Try to open a session. If the session is already opened, it returns the opened session. If there is a version - * mismatch, the user may be asked if he wants to open the session anyway. + * mismatch, the user may be asked if he wants to open the session anyway. Call the method + * openSession(sessionResourceURI, monitor, uiCallback, isDirectUserActionLoading) with the value false for + * isDirectUserActionLoading. * * @param sessionResourceURI * a session Resource {@link URI} @@ -156,4 +158,23 @@ public interface SessionManager { */ Session openSession(URI sessionResourceURI, IProgressMonitor monitor, UICallBack uiCallback); + /** + * Try to open a session. If the session is already opened, it returns the opened session. If there is a version + * mismatch, the user may be asked if he wants to open the session anyway. + * + * @param sessionResourceURI + * a session Resource {@link URI} + * @param monitor + * a {@link IProgressMonitor} to show progression of Session getting, especially if there is a resource + * loading + * @param uiCallback + * used to let the user choose if he wants to open the session anyway in case of version mismatch + * @param isDirectUserActionLoading + * <code>true</code> if the session opening comes from a direct user action (open diagram, unfold model + * explorer, etc.), <code>false</code> otherwise + * @return the opened session + * @since 6.1.0 + */ + Session openSession(URI sessionResourceURI, IProgressMonitor monitor, UICallBack uiCallback, boolean isDirectUserActionLoading); + } diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/migration/AbstractSiriusMigrationService.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/migration/AbstractSiriusMigrationService.java index 4b6c9f3de7..bd398e91b5 100644 --- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/migration/AbstractSiriusMigrationService.java +++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/migration/AbstractSiriusMigrationService.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012, 2015 THALES GLOBAL SERVICES and others. + * Copyright (c) 2012, 2018 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 @@ -37,8 +37,7 @@ import org.osgi.framework.Version; import org.xml.sax.Attributes; /** - * Abstract migration service. Provides services to load and delegate to - * migration participants. + * Abstract migration service. Provides services to load and delegate to migration participants. * * @author fbarbin * @@ -46,13 +45,18 @@ import org.xml.sax.Attributes; public abstract class AbstractSiriusMigrationService implements IMigrationParticipant { /** - * This option is passed during a resource load if a migration should be - * done. The value contains a string representation of the loaded version. - * The value can be null if the resource was created before the current + * This option is passed during a resource load if a migration should be done. The value contains a string + * representation of the loaded version. The value can be null if the resource was created before the current * migration mechanism. */ public static final String OPTION_RESOURCE_MIGRATION_LOADEDVERSION = "RESOURCE_MIGRATION_LOADEDVERSION"; //$NON-NLS-1$ + /** + * This option is passed during a resource load to inform if the migration has been triggered from a user action or + * not. + */ + public static final String OPTION_RESOURCE_NON_BATCH_MIGRATION = "RESOURCE_NON_BATCH_MIGRATION"; //$NON-NLS-1$ + // This migration way was introduced with 6.5.0.201208161001 version // for both VSM and representations files. private static final Version FIRST_VERSION = new Version("6.5.0.201208161001"); //$NON-NLS-1$ @@ -63,14 +67,12 @@ public abstract class AbstractSiriusMigrationService implements IMigrationPartic private List<IMigrationParticipant> delegatesParticipants = new ArrayList<IMigrationParticipant>(); /** - * The last Sirius version where a migration participant is added (computed - * from the delegatesParticipants list). + * The last Sirius version where a migration participant is added (computed from the delegatesParticipants list). */ private Version lastMigrationVersion; /** - * Loads contributions {@link IMigrationParticipant} from extension point - * <code>org.eclipse.sirius.migration</code>. + * Loads contributions {@link IMigrationParticipant} from extension point <code>org.eclipse.sirius.migration</code>. */ protected void loadContributions() { delegatesParticipants.clear(); @@ -265,16 +267,15 @@ public abstract class AbstractSiriusMigrationService implements IMigrationPartic * * @param loadedVersion * the version of current loading model. - * @return true if loaded version is less than the last Sirius version with - * migration, false otherwise. + * @return true if loaded version is less than the last Sirius version with migration, false otherwise. */ public boolean isMigrationNeeded(Version loadedVersion) { return getLastMigrationVersion().compareTo(loadedVersion) > 0; } /** - * Return the EPackage to use for the given namespace found in the given - * version, by asking to the migration participants. + * Return the EPackage to use for the given namespace found in the given version, by asking to the migration + * participants. * * @param namespace * the nsURI of the package we are looking for. @@ -307,15 +308,14 @@ public abstract class AbstractSiriusMigrationService implements IMigrationPartic } /** - * Allows to update the created object just after its creation (the - * attribute values are not yet loaded from XML file). + * Allows to update the created object just after its creation (the attribute values are not yet loaded from XML + * file). * * @param newObject * the new created object * @param loadedVersion * the version of current loading model - * @return An EObject with updated values or the EObject itself if this - * migration has nothing to do. + * @return An EObject with updated values or the EObject itself if this migration has nothing to do. */ @Override public EObject updateCreatedObject(EObject newObject, String loadedVersion) { @@ -327,24 +327,20 @@ public abstract class AbstractSiriusMigrationService implements IMigrationPartic } /** - * Called after the processing of an XML end tag. This method is useful for - * migration logic which needs to access XML Attributes which are not mapped - * with the Ecore model in any way. + * Called after the processing of an XML end tag. This method is useful for migration logic which needs to access + * XML Attributes which are not mapped with the Ecore model in any way. * * @param doneObject * the current Object in the parsing stack. * @param xmlAttributes * the xml attributes of the tag which just got closed. * @param uri - * The Namespace URI, or the empty string if the element has no - * Namespace URI or if Namespace processing is not being - * performed. + * The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing + * is not being performed. * @param localName - * the local name (without prefix), or the empty string if - * Namespace processing is not being performed. + * the local name (without prefix), or the empty string if Namespace processing is not being performed. * @param qName - * the qualified XML name (with prefix), or the empty string if - * qualified names are not available. + * the qualified XML name (with prefix), or the empty string if qualified names are not available. * @param loadedVersion * the version of current loading model * diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/migration/resource/MigrationUtil.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/migration/resource/MigrationUtil.java index e20baa8148..83a15bad41 100644 --- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/migration/resource/MigrationUtil.java +++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/migration/resource/MigrationUtil.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2016 THALES GLOBAL SERVICES. + * Copyright (c) 2018 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 @@ -48,8 +48,7 @@ import org.eclipse.sirius.viewpoint.SiriusPlugin; public final class MigrationUtil { /** - * Temporary variable to indicate that we want ignore version mismatch at - * session opening, waiting for Bug 456326. + * Temporary variable to indicate that we want ignore version mismatch at session opening, waiting for Bug 456326. * * @provisional */ @@ -291,8 +290,7 @@ public final class MigrationUtil { * the feature owner * @param entry * the current FeatureMap.Entry of unknown feature to handle - * @return true if the unknown feature represented by entry must be - * deleted in the resource + * @return true if the unknown feature represented by entry must be deleted in the resource */ protected abstract boolean handleFeature(EObject owner, FeatureMap.Entry entry); } diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/SessionManagerImpl.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/SessionManagerImpl.java index d5085be52d..356be38bf2 100644 --- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/SessionManagerImpl.java +++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/SessionManagerImpl.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2015 THALES GLOBAL SERVICES. + * Copyright (c) 2008, 2018 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 @@ -36,6 +36,7 @@ import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.util.EcoreUtil; +import org.eclipse.emf.ecore.xmi.XMLResource; import org.eclipse.sirius.business.api.logger.MarkerRuntimeLogger; import org.eclipse.sirius.business.api.migration.AirdResourceVersionMismatchException; import org.eclipse.sirius.business.api.query.URIQuery; @@ -44,6 +45,7 @@ import org.eclipse.sirius.business.api.session.SessionListener; import org.eclipse.sirius.business.api.session.SessionManager; import org.eclipse.sirius.business.api.session.SessionManagerListener; import org.eclipse.sirius.business.api.session.factory.SessionFactory; +import org.eclipse.sirius.business.internal.migration.AbstractSiriusMigrationService; import org.eclipse.sirius.business.internal.migration.resource.MigrationUtil; import org.eclipse.sirius.business.internal.session.danalysis.SessionLazyCrossReferencer; import org.eclipse.sirius.common.tools.api.util.EclipseUtil; @@ -379,6 +381,11 @@ public class SessionManagerImpl extends SessionManagerEObjectImpl implements Ses @Override public Session openSession(URI sessionResourceURI, IProgressMonitor monitor, UICallBack uiCallback) { + return openSession(sessionResourceURI, monitor, uiCallback, false); + } + + @Override + public Session openSession(URI sessionResourceURI, IProgressMonitor monitor, UICallBack uiCallback, boolean isDirectUserActionLoading) { SubMonitor subMonitor = SubMonitor.convert(monitor, 100); Session session = this.getSession(sessionResourceURI, subMonitor.newChild(30)); @@ -400,6 +407,12 @@ public class SessionManagerImpl extends SessionManagerEObjectImpl implements Ses } } } + for (Resource resource : session.getAllSessionResources()) { + if (resource instanceof XMLResource) { + ((XMLResource) resource).getDefaultLoadOptions().put(AbstractSiriusMigrationService.OPTION_RESOURCE_NON_BATCH_MIGRATION, isDirectUserActionLoading); + } + } + uiCallback.askUserAndSaveMigratedSession(session); subMonitor.done(); return session; diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/api/command/ui/NoUICallback.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/api/command/ui/NoUICallback.java index fe18e7f99c..6d6df2b2f2 100644 --- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/api/command/ui/NoUICallback.java +++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/api/command/ui/NoUICallback.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2016 THALES GLOBAL SERVICES. + * Copyright (c) 2009, 2018 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 @@ -30,8 +30,7 @@ import org.eclipse.sirius.viewpoint.description.tool.SelectModelElementVariable; /** * This will return default values for the UI-dependent tools. * - * @author Laurent Goubet - * <a href="mailto:laurent.goubet@obeo.fr">laurent.goubet@obeo.fr</a> + * @author Laurent Goubet <a href="mailto:laurent.goubet@obeo.fr">laurent.goubet@obeo.fr</a> */ public class NoUICallback implements UICallBack { /** @@ -53,8 +52,7 @@ public class NoUICallback implements UICallBack { /** * {@inheritDoc} * - * @see org.eclipse.sirius.tools.api.command.ui.UICallBack#askForDetailName(java.lang.String, - * java.lang.String) + * @see org.eclipse.sirius.tools.api.command.ui.UICallBack#askForDetailName(java.lang.String, java.lang.String) */ @Override public String askForDetailName(String defaultName, String representationDescription) throws InterruptedException { @@ -126,8 +124,7 @@ public class NoUICallback implements UICallBack { /** * {@inheritDoc} * - * @see org.eclipse.sirius.tools.api.command.ui.UICallBack#shouldClose(Session, - * Resource) + * @see org.eclipse.sirius.tools.api.command.ui.UICallBack#shouldClose(Session, Resource) */ @Override public boolean shouldClose(Session session, Resource resource) { @@ -167,8 +164,7 @@ public class NoUICallback implements UICallBack { /** * {@inheritDoc} * - * @see org.eclipse.sirius.tools.api.command.ui.UICallBack#openError(java.lang - * .String, java.lang.String) + * @see org.eclipse.sirius.tools.api.command.ui.UICallBack#openError(java.lang .String, java.lang.String) */ @Override public void openError(String title, String message) { @@ -184,4 +180,9 @@ public class NoUICallback implements UICallBack { public boolean askSessionReopeningWithResourceVersionMismatch(AirdResourceVersionMismatchException e) { return false; } + + @Override + public void askUserAndSaveMigratedSession(Session session) { + // Do nothing + } } 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 66459c44db..603ed96816 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, 2017 THALES GLOBAL SERVICES. + * Copyright (c) 2007, 2018 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 @@ -21,6 +21,9 @@ import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.edit.domain.EditingDomain; import org.eclipse.sirius.business.api.migration.AirdResourceVersionMismatchException; import org.eclipse.sirius.business.api.session.Session; +// CHECKSTYLE:OFF +import org.eclipse.sirius.common.tools.api.constant.CommonPreferencesConstants; +//CHECKSTYLE:ON import org.eclipse.sirius.common.tools.api.util.TreeItemWrapper; import org.eclipse.sirius.viewpoint.DRepresentation; import org.eclipse.sirius.viewpoint.DRepresentationDescriptor; @@ -240,4 +243,16 @@ public interface UICallBack { * @since 4.0 */ boolean askSessionReopeningWithResourceVersionMismatch(AirdResourceVersionMismatchException e); + + /** + * If the session is migrated automatically at opening, ask user if he wants to save it, and save it if necessary. + * The pop-up will only open if the resource has the load option + * {@link AbstractSiriusMigrationService.OPTION_RESOURCE_NON_BATCH_MIGRATION)} and the Eclipse preference + * {@link CommonPreferencesConstants.PREF_ASK_TO_SAVE_RESOURCE_AFTER_MIGRATION} set to true. + * + * @param session + * The used session + * @since 6.1.0 + */ + void askUserAndSaveMigratedSession(Session session); } |
