Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian W. Damus2015-11-27 20:59:46 +0000
committerChristian W. Damus2015-12-02 18:01:18 +0000
commit09d56589be181c7088207733d1a54814eb54e47e (patch)
tree1e457c0be135b37a4bf4ba8750556d0934294383 /tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org
parent1d9a947ab6fefce2145a6cbab15ace445b2830a4 (diff)
downloadorg.eclipse.papyrus-09d56589be181c7088207733d1a54814eb54e47e.tar.gz
org.eclipse.papyrus-09d56589be181c7088207733d1a54814eb54e47e.tar.xz
org.eclipse.papyrus-09d56589be181c7088207733d1a54814eb54e47e.zip
Bug 434983: [SashEditor] Provide a mechanism to move the editor layout model to either the *.di (Legacy) or hidden *.sash resource (1.0)
https://bugs.eclipse.org/bugs/show_bug.cgi?id=434983 Implement new actions in the editor's drop-down tool menu for selection of the the sash-editor page layout storage mode (private or shared). Also prompt on first opening of a legacy-mode (shared layout) model to make it private, as determined by the non-existence of a private *.sash resource, with a corresponding preference page. Rather than introduce a new service for the purpose, add the handling of first-open of a model in the SaveBeforeCloseService, which already has an editor lifecycle listener for managing persistence of the page layout, and this is another aspect of that persistence management function. Don't rename it as SashModelPersistenceService because it is public API. Change-Id: I64ec33c6471a16d711426644dba84981e85b2cba
Diffstat (limited to 'tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org')
-rw-r--r--tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/EditorUtils.java71
-rw-r--r--tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/PapyrusEditorFixture.java36
2 files changed, 79 insertions, 28 deletions
diff --git a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/EditorUtils.java b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/EditorUtils.java
index 43a386cb2a8..82737a957e5 100644
--- a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/EditorUtils.java
+++ b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/EditorUtils.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2012 CEA LIST.
+ * Copyright (c) 2012, 2015 CEA LIST, Christian W. Damus, and others.
*
*
* All rights reserved. This program and the accompanying materials
@@ -9,6 +9,7 @@
*
* Contributors:
* Vincent Lorenzo (CEA LIST) Vincent.Lorenzo@cea.fr - Initial API and implementation
+ * Christian W. Damus - bug 434983
*
*****************************************************************************/
package org.eclipse.papyrus.junit.utils;
@@ -31,24 +32,26 @@ import org.junit.Assert;
public class EditorUtils {
private EditorUtils() {
- //to prevent instanciation
+ // to prevent instanciation
}
/**
*
* @param file
- * a file
+ * a file
* @return
- * the opened editor for this file
+ * the opened editor for this file
* @throws PartInitException
*/
public static final IEditorPart openEditor(final IFile file) throws PartInitException {
- GenericUtils.closeIntroPart();
- final IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
- IEditorPart editor = null;
- editor = IDE.openEditor(activePage, file);
- Assert.assertNotNull(editor);
- return editor;
+ return withoutLayoutStoragePopup(() -> {
+ GenericUtils.closeIntroPart();
+ final IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+ IEditorPart editor = null;
+ editor = IDE.openEditor(activePage, file);
+ Assert.assertNotNull(editor);
+ return editor;
+ });
}
/**
@@ -59,12 +62,48 @@ public class EditorUtils {
* @throws PartInitException
*/
public static final IMultiDiagramEditor openPapyrusEditor(final IFile file) throws PartInitException {
- GenericUtils.closeIntroPart();
- final IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
- IEditorPart editor = null;
- editor = IDE.openEditor(activePage, file, PapyrusMultiDiagramEditor.EDITOR_ID);
- Assert.assertNotNull(editor);
- return (IMultiDiagramEditor)editor;
+ return withoutLayoutStoragePopup(() -> {
+ GenericUtils.closeIntroPart();
+ final IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+ IEditorPart editor = null;
+ editor = IDE.openEditor(activePage, file, PapyrusMultiDiagramEditor.EDITOR_ID);
+ Assert.assertNotNull(editor);
+ return (IMultiDiagramEditor) editor;
+ });
}
+ /**
+ * Opens an editor without the possibility of it showing a prompt dialog to convert
+ * DI-file storage of the page layout to private sash-file storage.
+ */
+ @SuppressWarnings("restriction")
+ private static <E extends IEditorPart> E withoutLayoutStoragePopup(EditorOpener<E> editorOpener) throws PartInitException {
+ E result;
+ boolean posted = false;
+
+ org.eclipse.papyrus.infra.core.internal.preferences.YesNo originalPreference = org.eclipse.papyrus.infra.core.internal.preferences.EditorPreferences.getInstance().getConvertSharedPageLayoutToPrivate();
+ org.eclipse.papyrus.infra.core.internal.preferences.EditorPreferences.getInstance().setConvertSharedPageLayoutToPrivate(org.eclipse.papyrus.infra.core.internal.preferences.YesNo.NO);
+
+ try {
+ result = editorOpener.openEditor();
+ result.getSite().getShell().getDisplay().asyncExec(() -> org.eclipse.papyrus.infra.core.internal.preferences.EditorPreferences.getInstance().setConvertSharedPageLayoutToPrivate(originalPreference));
+ posted = true;
+ } finally {
+ if (!posted) {
+ // Revert now because the editor failed to open and we won't be reverting asynchronously
+ org.eclipse.papyrus.infra.core.internal.preferences.EditorPreferences.getInstance().setConvertSharedPageLayoutToPrivate(originalPreference);
+ }
+ }
+
+ return result;
+ }
+
+ //
+ // Nested types
+ //
+
+ @FunctionalInterface
+ private interface EditorOpener<E extends IEditorPart> {
+ E openEditor() throws PartInitException;
+ }
}
diff --git a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/PapyrusEditorFixture.java b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/PapyrusEditorFixture.java
index 58c941d61f2..3be5de43202 100644
--- a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/PapyrusEditorFixture.java
+++ b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/PapyrusEditorFixture.java
@@ -10,6 +10,7 @@
* Christian W. Damus (CEA) - Initial API and implementation
* Christian W. Damus - bug 433206
* Christian W. Damus - bug 465416
+ * Christian W. Damus - bug 434983
*
*/
package org.eclipse.papyrus.junit.utils.rules;
@@ -80,13 +81,13 @@ import org.eclipse.papyrus.infra.core.sasheditor.editor.IPageVisitor;
import org.eclipse.papyrus.infra.core.sasheditor.editor.ISashWindowsContainer;
import org.eclipse.papyrus.infra.core.services.ServiceException;
import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
-import org.eclipse.papyrus.infra.core.utils.AdapterUtils;
import org.eclipse.papyrus.infra.core.utils.ServiceUtils;
import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationModel;
import org.eclipse.papyrus.infra.nattable.common.editor.AbstractEMFNattableEditor;
import org.eclipse.papyrus.infra.nattable.common.modelresource.PapyrusNattableModel;
import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager;
import org.eclipse.papyrus.infra.nattable.model.nattable.Table;
+import org.eclipse.papyrus.infra.tools.util.PlatformHelper;
import org.eclipse.papyrus.infra.tools.util.TypeUtils;
import org.eclipse.papyrus.junit.utils.EditorUtils;
import org.eclipse.papyrus.junit.utils.JUnitUtils;
@@ -115,7 +116,6 @@ import org.junit.runner.Description;
import org.osgi.framework.Bundle;
import org.osgi.framework.FrameworkUtil;
-import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.common.collect.Iterators;
@@ -132,6 +132,9 @@ public class PapyrusEditorFixture extends AbstractModelFixture<TransactionalEdit
private final List<String> excludedTypeView = Arrays.asList(new String[] { "Note" });
+ @SuppressWarnings("restriction")
+ private org.eclipse.papyrus.infra.core.internal.preferences.YesNo initialEditorLayoutStorageMigrationPreference;
+
private IMultiDiagramEditor editor;
private DiagramEditorWithFlyOutPalette activeDiagramEditor;
@@ -167,11 +170,17 @@ public class PapyrusEditorFixture extends AbstractModelFixture<TransactionalEdit
return result;
}
+ @SuppressWarnings("restriction")
@Override
protected void starting(Description description) {
testClass = description.getTestClass();
testDescription = description;
+ // Ensure that we won't see a dialog prompting the user to migrate page layout
+ // storage from the DI file to the workspace-private sash file
+ initialEditorLayoutStorageMigrationPreference = org.eclipse.papyrus.infra.core.internal.preferences.EditorPreferences.getInstance().getConvertSharedPageLayoutToPrivate();
+ org.eclipse.papyrus.infra.core.internal.preferences.EditorPreferences.getInstance().setConvertSharedPageLayoutToPrivate(org.eclipse.papyrus.infra.core.internal.preferences.YesNo.NO);
+
if (hasRequiredViews()) {
openRequiredViews();
}
@@ -214,11 +223,12 @@ public class PapyrusEditorFixture extends AbstractModelFixture<TransactionalEdit
}
}
}
- //nothing to do for table
+ // nothing to do for table
}
});
}
+ @SuppressWarnings("restriction")
@Override
protected void finished(Description description) {
try {
@@ -243,6 +253,8 @@ public class PapyrusEditorFixture extends AbstractModelFixture<TransactionalEdit
editor = null;
activeDiagramEditor = null;
+ org.eclipse.papyrus.infra.core.internal.preferences.EditorPreferences.getInstance().setConvertSharedPageLayoutToPrivate(initialEditorLayoutStorageMigrationPreference);
+
try {
if (hasRequiredViews()) {
closeRequiredViews();
@@ -502,7 +514,7 @@ public class PapyrusEditorFixture extends AbstractModelFixture<TransactionalEdit
public PapyrusEditorFixture activateDiagram(IMultiDiagramEditor editor, final String name) {
activate(editor);
- final ISashWindowsContainer sashContainer = AdapterUtils.adapt(editor, ISashWindowsContainer.class, null);
+ final ISashWindowsContainer sashContainer = PlatformHelper.getAdapter(editor, ISashWindowsContainer.class);
final org.eclipse.papyrus.infra.core.sasheditor.editor.IPage[] select = { null };
sashContainer.visit(new IPageVisitor() {
@@ -532,7 +544,7 @@ public class PapyrusEditorFixture extends AbstractModelFixture<TransactionalEdit
public PapyrusEditorFixture activateTable(IMultiDiagramEditor editor, final String name) {
activate(editor);
- final ISashWindowsContainer sashContainer = AdapterUtils.adapt(editor, ISashWindowsContainer.class, null);
+ final ISashWindowsContainer sashContainer = PlatformHelper.getAdapter(editor, ISashWindowsContainer.class);
final org.eclipse.papyrus.infra.core.sasheditor.editor.IPage[] select = { null };
sashContainer.visit(new IPageVisitor() {
@@ -576,7 +588,7 @@ public class PapyrusEditorFixture extends AbstractModelFixture<TransactionalEdit
public PapyrusEditorFixture activateDiagram(IMultiDiagramEditor editor, final DiagramEditPart diagram) {
activate(editor);
- final ISashWindowsContainer sashContainer = AdapterUtils.adapt(editor, ISashWindowsContainer.class, null);
+ final ISashWindowsContainer sashContainer = PlatformHelper.getAdapter(editor, ISashWindowsContainer.class);
final org.eclipse.papyrus.infra.core.sasheditor.editor.IPage[] select = { null };
sashContainer.visit(new IPageVisitor() {
@@ -642,7 +654,7 @@ public class PapyrusEditorFixture extends AbstractModelFixture<TransactionalEdit
activateTable(editor, name);
} catch (Exception e) {
- throw new IllegalStateException("Cannot initialize test", e); //NON-NLS-1
+ throw new IllegalStateException("Cannot initialize test", e); // NON-NLS-1
}
return this;
@@ -718,16 +730,16 @@ public class PapyrusEditorFixture extends AbstractModelFixture<TransactionalEdit
return getActiveDiagramEditor().getDiagramEditPart();
}
- public INattableModelManager getActiveTableManager(){
+ public INattableModelManager getActiveTableManager() {
return (INattableModelManager) getActiveTableEditor().getAdapter(INattableModelManager.class);
}
-
+
public DiagramEditPart getDiagram(String name) {
return getDiagram(editor, name);
}
public DiagramEditPart getDiagram(IMultiDiagramEditor editor, final String name) {
- final ISashWindowsContainer sashContainer = AdapterUtils.adapt(editor, ISashWindowsContainer.class, null);
+ final ISashWindowsContainer sashContainer = PlatformHelper.getAdapter(editor, ISashWindowsContainer.class);
final org.eclipse.papyrus.infra.core.sasheditor.editor.IPage[] matchedPage = { null };
sashContainer.visit(new IPageVisitor() {
@@ -826,8 +838,8 @@ public class PapyrusEditorFixture extends AbstractModelFixture<TransactionalEdit
public EditPart findEditPart(EditPart scope, EObject modelElement) {
EditPart result = null;
- Optional<View> view = AdapterUtils.adapt(scope, View.class);
- if (view.isPresent() && (view.get().getElement() == modelElement)) {
+ View view = PlatformHelper.getAdapter(scope, View.class);
+ if ((view != null) && (view.getElement() == modelElement)) {
result = scope;
}

Back to the top