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 /plugins/infra/core
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 'plugins/infra/core')
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/META-INF/MANIFEST.MF2
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/plugin.xml42
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/internal/commands/PageLayoutStorageState.java120
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/internal/commands/TogglePageLayoutStorageHandler.java79
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/internal/preferences/EditorPreferencePage.java52
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/internal/preferences/EditorPreferences.java88
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/internal/preferences/Messages.java37
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/internal/preferences/YesNo.java21
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/internal/preferences/messages.properties18
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/sasheditor/SashLayoutCommandFactory.java141
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/sasheditor/SashModel.java41
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/sasheditor/SashModelUtils.java27
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/Messages.java34
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/SaveLayoutBeforeClose.java84
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/messages.properties15
15 files changed, 794 insertions, 7 deletions
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/META-INF/MANIFEST.MF b/plugins/infra/core/org.eclipse.papyrus.infra.core/META-INF/MANIFEST.MF
index 8ed371c6049..6dbb35181a3 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/META-INF/MANIFEST.MF
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/META-INF/MANIFEST.MF
@@ -8,6 +8,8 @@ Export-Package: org.eclipse.papyrus.infra.core,
org.eclipse.papyrus.infra.core.extension,
org.eclipse.papyrus.infra.core.extension.commands,
org.eclipse.papyrus.infra.core.extension.diagrameditor,
+ org.eclipse.papyrus.infra.core.internal.commands;x-internal:=true,
+ org.eclipse.papyrus.infra.core.internal.preferences;x-internal:=true,
org.eclipse.papyrus.infra.core.language,
org.eclipse.papyrus.infra.core.lifecycleevents,
org.eclipse.papyrus.infra.core.listenerservice,
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/plugin.xml b/plugins/infra/core/org.eclipse.papyrus.infra.core/plugin.xml
index 7a1ae21bd95..2879ff91084 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/plugin.xml
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/plugin.xml
@@ -139,6 +139,20 @@
</with>
</visibleWhen>
</command>
+ <command
+ commandId="org.eclipse.papyrus.infra.core.commands.privatePageLayout"
+ label="Private Page Layout"
+ style="toggle"
+ tooltip="Store editor page layout privately, not shared in the DI file">
+ <visibleWhen>
+ <with
+ variable="activeEditorId">
+ <equals
+ value="org.eclipse.papyrus.infra.core.papyrusEditor">
+ </equals>
+ </with>
+ </visibleWhen>
+ </command>
</menuContribution>
</extension>
<extension
@@ -164,6 +178,15 @@
id="org.eclipse.papyrus.infra.core.sasheditor.command.tabdoubleclick"
name="Rename diagram">
</command>
+ <command
+ id="org.eclipse.papyrus.infra.core.commands.privatePageLayout"
+ name="Private Page Layout"
+ description="Store editor page layout privately, not shared in the DI file">
+ <state
+ id="org.eclipse.ui.commands.toggleState"
+ class="org.eclipse.papyrus.infra.core.internal.commands.PageLayoutStorageState">
+ </state>
+ </command>
</extension>
<extension
point="org.eclipse.ui.handlers">
@@ -179,6 +202,10 @@
class="org.eclipse.papyrus.infra.core.sasheditor.di.contentprovider.commands.CloseOtherDiagramsCommand"
commandId="org.eclipse.papyrus.infra.core.commands.closeothersdiagrams">
</handler>
+ <handler
+ class="org.eclipse.papyrus.infra.core.internal.commands.TogglePageLayoutStorageHandler"
+ commandId="org.eclipse.papyrus.infra.core.commands.privatePageLayout">
+ </handler>
</extension>
<extension
point="org.eclipse.papyrus.infra.core.model">
@@ -404,5 +431,20 @@
priority="10"
startKind="startup">
</service>
+ </extension>
+ <extension
+ point="org.eclipse.core.runtime.preferences">
+ <initializer
+ class="org.eclipse.papyrus.infra.core.internal.preferences.EditorPreferences$Initializer">
+ </initializer>
+ </extension>
+ <extension
+ point="org.eclipse.ui.preferencePages">
+ <page
+ category="org.eclipse.papyrus.infra.core.sasheditor.preferences.generalcategory"
+ class="org.eclipse.papyrus.infra.core.internal.preferences.EditorPreferencePage"
+ id="org.eclipse.papyrus.infra.core.editorPrefs"
+ name="Editor">
+ </page>
</extension>
</plugin>
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/internal/commands/PageLayoutStorageState.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/internal/commands/PageLayoutStorageState.java
new file mode 100644
index 00000000000..876c75a8651
--- /dev/null
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/internal/commands/PageLayoutStorageState.java
@@ -0,0 +1,120 @@
+/*****************************************************************************
+ * Copyright (c) 2015 Christian W. Damus 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Christian W. Damus - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.core.internal.commands;
+
+import java.lang.ref.Reference;
+import java.lang.ref.WeakReference;
+
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.jface.commands.ToggleState;
+import org.eclipse.papyrus.infra.core.editor.IMultiDiagramEditor;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.core.resource.sasheditor.SashModel;
+import org.eclipse.papyrus.infra.core.resource.sasheditor.SashModelUtils;
+import org.eclipse.ui.IPartListener;
+import org.eclipse.ui.IPartService;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * The boolean toggle state of the private page layout storage menu item.
+ */
+public class PageLayoutStorageState extends ToggleState implements IPartListener {
+
+ private IPartService partService = null;
+
+ private Reference<IMultiDiagramEditor> activeEditor;
+
+ public PageLayoutStorageState() {
+ super();
+
+ IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+
+ if (window != null) {
+ partService = window.getPartService();
+ if (partService != null) {
+ partService.addPartListener(this);
+ update(partService.getActivePart());
+ }
+ }
+ }
+
+ @Override
+ public void dispose() {
+ if (partService != null) {
+ partService.removePartListener(this);
+ }
+
+ super.dispose();
+ }
+
+ @Override
+ public void partDeactivated(IWorkbenchPart part) {
+ if ((activeEditor != null) && (activeEditor.get() == part)) {
+ update(null);
+ }
+ }
+
+ @Override
+ public void partActivated(IWorkbenchPart part) {
+ update(part);
+ }
+
+ private void update(IWorkbenchPart part) {
+ // Default state is private storage
+ boolean state = true;
+
+ activeEditor = null;
+
+ if (part instanceof IMultiDiagramEditor) {
+ IMultiDiagramEditor editor = (IMultiDiagramEditor) part;
+ activeEditor = new WeakReference<>(editor);
+ state = isPrivateLayout(editor);
+ }
+
+ // Fires notification if changed from previous state
+ setValue(state);
+ }
+
+ // I am a computed value, actually
+ @Override
+ public Object getValue() {
+ IMultiDiagramEditor editor = (activeEditor == null) ? null : activeEditor.get();
+ return (editor != null) ? isPrivateLayout(editor) : super.getValue();
+ }
+
+ boolean isPrivateLayout(IMultiDiagramEditor editor) {
+ ModelSet modelSet = (ModelSet) editor.getAdapter(EditingDomain.class).getResourceSet();
+ SashModel sashModel = SashModelUtils.getSashModel(modelSet);
+
+ // The default is private layout
+ return (sashModel == null) || !sashModel.isLegacyMode();
+ }
+
+ @Override
+ public void partBroughtToTop(IWorkbenchPart part) {
+ // Pass
+ }
+
+ @Override
+ public void partClosed(IWorkbenchPart part) {
+ // Pass
+ }
+
+ @Override
+ public void partOpened(IWorkbenchPart part) {
+ // Pass
+ }
+}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/internal/commands/TogglePageLayoutStorageHandler.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/internal/commands/TogglePageLayoutStorageHandler.java
new file mode 100644
index 00000000000..c9b86cd0fe8
--- /dev/null
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/internal/commands/TogglePageLayoutStorageHandler.java
@@ -0,0 +1,79 @@
+/*****************************************************************************
+ * Copyright (c) 2015 Christian W. Damus 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Christian W. Damus - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.core.internal.commands;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.transaction.RollbackException;
+import org.eclipse.papyrus.infra.core.Activator;
+import org.eclipse.papyrus.infra.core.editor.IMultiDiagramEditor;
+import org.eclipse.papyrus.infra.core.resource.sasheditor.SashLayoutCommandFactory;
+import org.eclipse.papyrus.infra.core.services.SaveLayoutBeforeClose;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.core.utils.TransactionHelper;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.eclipse.ui.statushandlers.StatusManager;
+
+/**
+ * Command handler for the private page-layout storage toggle menu.
+ */
+public class TogglePageLayoutStorageHandler extends AbstractHandler {
+
+ public TogglePageLayoutStorageHandler() {
+ super();
+ }
+
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ IEditorPart active = HandlerUtil.getActiveEditor(event);
+ if (active instanceof IMultiDiagramEditor) {
+ IMultiDiagramEditor editor = (IMultiDiagramEditor) active;
+
+ // Toggle the storage of the layout
+ togglePrivatePageLayout(editor);
+
+ // And then save the layout immediately if the editor is not dirty
+ // (if it is dirty, then the layout will be saved when the editor
+ // is saved; saving it now would possibly result in inconsistencies)
+ try {
+ SaveLayoutBeforeClose save = editor.getServicesRegistry().getService(SaveLayoutBeforeClose.class);
+ save.saveBeforeClose(editor);
+ } catch (ServiceException e) {
+ // Doesn't matter; we'll just have to rely on the normal editor save
+ }
+ }
+
+ return null;
+ }
+
+ public void togglePrivatePageLayout(IMultiDiagramEditor editor) {
+ Command command = new SashLayoutCommandFactory(editor).createTogglePrivateLayoutCommand();
+ EditingDomain domain = editor.getAdapter(EditingDomain.class);
+
+ // Don't execute on the undo history because the changes in the sash model
+ // are never tracked for undo/redo
+ try {
+ TransactionHelper.run(domain, () -> command.execute());
+ } catch (RollbackException e) {
+ StatusManager.getManager().handle(e.getStatus());
+ } catch (InterruptedException e) {
+ Activator.log.error("Failed to execute page layout toggle command", e); //$NON-NLS-1$
+ }
+ }
+
+}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/internal/preferences/EditorPreferencePage.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/internal/preferences/EditorPreferencePage.java
new file mode 100644
index 00000000000..92b999ae38b
--- /dev/null
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/internal/preferences/EditorPreferencePage.java
@@ -0,0 +1,52 @@
+/*****************************************************************************
+ * Copyright (c) 2015 Christian W. Damus 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Christian W. Damus - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.core.internal.preferences;
+
+import org.eclipse.jface.preference.FieldEditorPreferencePage;
+import org.eclipse.jface.preference.RadioGroupFieldEditor;
+import org.eclipse.papyrus.infra.core.Activator;
+import org.eclipse.swt.SWT;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+
+/**
+ * The preference page for Papyrus Editor general preferences.
+ */
+public class EditorPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
+
+ public EditorPreferencePage() {
+ super(Messages.EditorPreferencePage_0, SWT.FLAT);
+
+ setDescription(Messages.EditorPreferencePage_5);
+ }
+
+ @Override
+ public void init(IWorkbench workbench) {
+ setPreferenceStore(Activator.getDefault().getPreferenceStore());
+ }
+
+ @Override
+ protected void createFieldEditors() {
+ addField(new RadioGroupFieldEditor(EditorPreferences.PREF_CONVERT_SHARED_LAYOUT,
+ Messages.EditorPreferencePage_1,
+ 1,
+ new String[][] {
+ { Messages.EditorPreferencePage_2, YesNo.PROMPT.name() },
+ { Messages.EditorPreferencePage_3, YesNo.NO.name() },
+ { Messages.EditorPreferencePage_4, YesNo.YES.name() },
+ },
+ getFieldEditorParent()));
+ }
+
+}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/internal/preferences/EditorPreferences.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/internal/preferences/EditorPreferences.java
new file mode 100644
index 00000000000..e77d40263d0
--- /dev/null
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/internal/preferences/EditorPreferences.java
@@ -0,0 +1,88 @@
+/*****************************************************************************
+ * Copyright (c) 2015 Christian W. Damus 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Christian W. Damus - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.core.internal.preferences;
+
+import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.papyrus.infra.core.Activator;
+
+/**
+ * Accessor for the Papyrus Editor preferences.
+ */
+public class EditorPreferences {
+ public static final String PREF_CONVERT_SHARED_LAYOUT = "convertSharedLayout"; //$NON-NLS-1$
+
+ private static final EditorPreferences INSTANCE = new EditorPreferences();
+ private final IPreferenceStore store;
+
+ private EditorPreferences() {
+ super();
+
+ store = Activator.getDefault().getPreferenceStore();
+ }
+
+ public static EditorPreferences getInstance() {
+ return INSTANCE;
+ }
+
+ /**
+ * Queries whether the user prefers to migrate shared editor layout to private storage
+ * always, never, or interactively pop up a dialog to ask (the default).
+ *
+ * @return the shared layout conversion on first open preference, which is never
+ * {@code null} and defaults to {@link YesNo#PROMPT}
+ */
+ public YesNo getConvertSharedPageLayoutToPrivate() {
+ return YesNo.valueOf(store.getString(PREF_CONVERT_SHARED_LAYOUT));
+ }
+
+ /**
+ * Sets whether the editor will always, never, or ask the user to migrate shared
+ * (in the {@code *.di} resource) page layout into the private storage ({@code *.sash} resource}
+ * on the first opening of a Papyrus model in the workspace that uses the shared
+ * storage (usually from pre-1.0 release).
+ *
+ * @param convert
+ * the preference setting to assign, or {@code null} for the default, which
+ * is {@link YesNo#PROMPT}
+ */
+ public void setConvertSharedPageLayoutToPrivate(YesNo convert) {
+ if (convert == null) {
+ convert = YesNo.PROMPT;
+ }
+
+ store.setValue(PREF_CONVERT_SHARED_LAYOUT, convert.name());
+ }
+
+ //
+ // Nested types
+ //
+
+ /**
+ * Initializer of defaults for the editor preferences.
+ */
+ public static class Initializer extends AbstractPreferenceInitializer {
+
+ public Initializer() {
+ super();
+ }
+
+ @Override
+ public void initializeDefaultPreferences() {
+ IPreferenceStore store = Activator.getDefault().getPreferenceStore();
+
+ store.setDefault(PREF_CONVERT_SHARED_LAYOUT, YesNo.PROMPT.name());
+ }
+ }
+}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/internal/preferences/Messages.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/internal/preferences/Messages.java
new file mode 100644
index 00000000000..6556ba36b19
--- /dev/null
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/internal/preferences/Messages.java
@@ -0,0 +1,37 @@
+/*****************************************************************************
+ * Copyright (c) 2015 Christian W. Damus 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Christian W. Damus - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.core.internal.preferences;
+
+import org.eclipse.osgi.util.NLS;
+
+/**
+ * Translatable strings.
+ */
+class Messages extends NLS {
+ private static final String BUNDLE_NAME = "org.eclipse.papyrus.infra.core.internal.preferences.messages"; //$NON-NLS-1$
+ public static String EditorPreferencePage_0;
+ public static String EditorPreferencePage_1;
+ public static String EditorPreferencePage_2;
+ public static String EditorPreferencePage_3;
+ public static String EditorPreferencePage_4;
+ public static String EditorPreferencePage_5;
+
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/internal/preferences/YesNo.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/internal/preferences/YesNo.java
new file mode 100644
index 00000000000..cd697bca280
--- /dev/null
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/internal/preferences/YesNo.java
@@ -0,0 +1,21 @@
+/*****************************************************************************
+ * Copyright (c) 2015 Christian W. Damus 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Christian W. Damus - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.core.internal.preferences;
+
+/**
+ * A tri-state boolean-ish preference data type with a "prompt the user" value.
+ */
+public enum YesNo {
+ PROMPT, NO, YES;
+}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/internal/preferences/messages.properties b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/internal/preferences/messages.properties
new file mode 100644
index 00000000000..a34a57ddfbe
--- /dev/null
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/internal/preferences/messages.properties
@@ -0,0 +1,18 @@
+#
+# Copyright (c) 2015 Christian W. Damus 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
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+# Christian W. Damus - Initial API and implementation
+#
+
+EditorPreferencePage_0=General Editor Settings
+EditorPreferencePage_1=Convert shared storage of editor layout to private:
+EditorPreferencePage_2=Ask each time
+EditorPreferencePage_3=Never
+EditorPreferencePage_4=Always
+EditorPreferencePage_5=General settings for the Papyrus multi-diagram editor.
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/sasheditor/SashLayoutCommandFactory.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/sasheditor/SashLayoutCommandFactory.java
new file mode 100644
index 00000000000..bbd6b52c8c1
--- /dev/null
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/sasheditor/SashLayoutCommandFactory.java
@@ -0,0 +1,141 @@
+/*****************************************************************************
+ * Copyright (c) 2015 Christian W. Damus 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Christian W. Damus - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.core.resource.sasheditor;
+
+import org.eclipse.emf.common.command.AbstractCommand;
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.command.UnexecutableCommand;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.papyrus.infra.core.editor.IMultiDiagramEditor;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.core.sashwindows.di.SashWindowsMngr;
+import org.eclipse.papyrus.infra.core.sashwindows.di.util.DiUtils;
+
+/**
+ * A factory for commands that manipulate the configuration of the sash editor layout.
+ */
+public class SashLayoutCommandFactory {
+ private final IMultiDiagramEditor editor;
+
+ public SashLayoutCommandFactory(IMultiDiagramEditor editor) {
+ super();
+
+ this.editor = editor;
+ }
+
+ /**
+ * Creates a command that toggles whether the sash model is stored in the private
+ * workspace metadata area or in the shared {@code *.di} file.
+ *
+ * @return a toggle command for the private layout storage
+ */
+ public Command createTogglePrivateLayoutCommand() {
+ Command result = UnexecutableCommand.INSTANCE;
+
+ ModelSet modelSet = (ModelSet) editor.getAdapter(EditingDomain.class).getResourceSet();
+ org.eclipse.papyrus.infra.core.resource.sasheditor.SashModel sashModel = SashModelUtils.getSashModel(modelSet);
+ if (sashModel != null) {
+ result = new AbstractToggleCommand("Toggle Private Editor Layout") {
+
+ @Override
+ public void execute() {
+ SashWindowsMngr toMove = DiUtils.lookupSashWindowsMngr(sashModel.getResource());
+
+ // We don't record changes in the sash model for undo/redo,
+ // so we cannot assume that any changes to the current page selections
+ // are undoable in the usual way
+ if (!sashModel.isLegacyMode()) {
+ Resource sashResource = toMove.eResource();
+ URI sharedURI = sashModel.getSharedResourceURI();
+
+ // Move the contents into the DI model. If the DI resource isn't loaded,
+ // give up because something is seriously wrong in that case
+ Resource diResource = modelSet.getResource(sharedURI, false);
+ if ((diResource != null) && diResource.isLoaded()) {
+ SashWindowsMngr toReplace = DiUtils.lookupSashWindowsMngr(diResource);
+ if (toReplace != null) {
+ EcoreUtil.replace(toReplace, toMove);
+ } else {
+ diResource.getContents().add(0, toMove);
+ }
+
+ if (sashResource.getContents().isEmpty()) {
+ // Schedule deletion on save
+ modelSet.getResourcesToDeleteOnSave().add(sashResource.getURI());
+ }
+ }
+ } else {
+ Resource sashResource;
+ URI privateURI = sashModel.getPrivateResourceURI();
+
+ // Move the contents into the sash model. If the sash resource isn't loaded
+ // or doesn't exist, it will have to be handled
+ if (modelSet.getURIConverter().exists(privateURI, null)) {
+ sashResource = modelSet.getResource(privateURI, true);
+ } else {
+ sashResource = modelSet.createResource(privateURI);
+ }
+
+ // In case we had marked it for deletion, earlier
+ modelSet.getResourcesToDeleteOnSave().remove(privateURI);
+
+ SashWindowsMngr toReplace = DiUtils.lookupSashWindowsMngr(sashResource);
+ if (toReplace != null) {
+ EcoreUtil.replace(toReplace, toMove);
+ } else {
+ sashResource.getContents().add(0, toMove);
+ }
+ }
+
+ // Re-load from the new resource. Snippets might find this odd, but
+ // it would be even more odd for there to be any snippets on this model
+ sashModel.loadModel(modelSet.getURIWithoutExtension());
+ }
+ };
+ }
+
+ return result;
+ }
+
+ //
+ // Nested types
+ //
+
+ private static abstract class AbstractToggleCommand extends AbstractCommand {
+
+ AbstractToggleCommand(String label) {
+ super(label);
+ }
+
+ @Override
+ protected boolean prepare() {
+ // Nothing to prepare
+ return true;
+ }
+
+ @Override
+ public void undo() {
+ // It's a toggle, so yeah, just execute again
+ execute();
+ }
+
+ @Override
+ public void redo() {
+ execute();
+ }
+ }
+}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/sasheditor/SashModel.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/sasheditor/SashModel.java
index 66f60602180..479066b57c6 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/sasheditor/SashModel.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/sasheditor/SashModel.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2009, 2014 CEA LIST and others.
+ * Copyright (c) 2009, 2015 CEA LIST, Christian W. Damus, and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -11,6 +11,7 @@
* Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Rewrite the sash model - store in the plugin's PreferenceStore (Bug 429239)
* Christian W. Damus (CEA) - bug 429242
* Christian W. Damus (CEA) - bug 436468
+ * Christian W. Damus - bug 434983
*
*****************************************************************************/
package org.eclipse.papyrus.infra.core.resource.sasheditor;
@@ -107,7 +108,19 @@ public class SashModel extends EMFLogicalModel implements IModel {
@Override
protected boolean isRelatedResource(Resource resource) {
- return resource != null && this.resource == resource; // We only handle the main Sash resource. Imported *.sash are not relevant
+ boolean result = false;
+
+ if (resource != null) {
+ // We only handle the main Sash resource. Imported *.sash are not relevant
+ if (resource == getResource()) {
+ result = true;
+ } else if (getModelManager().getURIWithoutExtension() != null) {
+ // We can only calculate these related URIs if the ModelSet is initialized
+ result = resource.getURI().equals(getPrivateResourceURI()) || resource.getURI().equals(getSharedResourceURI());
+ }
+ }
+
+ return result;
}
/**
@@ -222,4 +235,28 @@ public class SashModel extends EMFLogicalModel implements IModel {
return saveOptions;
}
+ public boolean isLegacyMode() {
+ return isLegacy(getURI().trimFileExtension());
+ }
+
+ /**
+ * Gets the URI of the sash-model resource in the user private area, irrespective
+ * of whether that actually is the resource that currently stores the sash model.
+ *
+ * @return the private sash-model resource URI
+ */
+ public URI getPrivateResourceURI() {
+ return getSashModelStoreURI(getModelManager().getURIWithoutExtension());
+ }
+
+ /**
+ * Gets the URI of the sash-model resource in the shared (collocated with the user model)
+ * area, irrespective of whether that actually is the resource that currently stores the
+ * sash model.
+ *
+ * @return the shared sash-model resource URI
+ */
+ public URI getSharedResourceURI() {
+ return getModelManager().getURIWithoutExtension().appendFileExtension(DiModel.MODEL_FILE_EXTENSION);
+ }
}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/sasheditor/SashModelUtils.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/sasheditor/SashModelUtils.java
index 27b68b39c34..e085e5c8324 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/sasheditor/SashModelUtils.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/sasheditor/SashModelUtils.java
@@ -1,11 +1,24 @@
-/**
+/*****************************************************************************
+ * Copyright (c) 2011, 2015 LIFL, CEA LIST, Christian W. Damus, 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * LIFL - Initial API and implementation
+ * Christian W. Damus - bug 434983
+ *
+ *****************************************************************************/
package org.eclipse.papyrus.infra.core.resource.sasheditor;
import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.papyrus.infra.core.resource.ModelSet;
import org.eclipse.papyrus.infra.core.resource.ModelUtils;
+import org.eclipse.papyrus.infra.core.sashwindows.di.DiPackage;
+import org.eclipse.papyrus.infra.core.sashwindows.di.SashWindowsMngr;
import org.eclipse.papyrus.infra.core.services.ServiceException;
import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
import org.eclipse.papyrus.infra.core.utils.ServiceUtilsForActionHandlers;
@@ -118,4 +131,14 @@ public class SashModelUtils {
return SashModelUtils.getSashModel(modelSet).getResourceURI();
}
+ public static SashWindowsMngr getSashWindowsMngr(ModelSet modelSet) {
+ SashWindowsMngr result = null;
+
+ SashModel model = getSashModel(modelSet);
+ if (model != null) {
+ result = (SashWindowsMngr) EcoreUtil.getObjectByType(model.getResource().getContents(), DiPackage.Literals.SASH_WINDOWS_MNGR);
+ }
+
+ return result;
+ }
}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/Messages.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/Messages.java
new file mode 100644
index 00000000000..eb79ec467f9
--- /dev/null
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/Messages.java
@@ -0,0 +1,34 @@
+/*****************************************************************************
+ * Copyright (c) 2015 Christian W. Damus 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Christian W. Damus - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.core.services;
+
+import org.eclipse.osgi.util.NLS;
+
+/**
+ * Translatable strings.
+ */
+class Messages extends NLS {
+ private static final String BUNDLE_NAME = "org.eclipse.papyrus.infra.core.services.messages"; //$NON-NLS-1$
+ public static String SaveLayoutBeforeClose_0;
+ public static String SaveLayoutBeforeClose_1;
+ public static String SaveLayoutBeforeClose_2;
+
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/SaveLayoutBeforeClose.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/SaveLayoutBeforeClose.java
index c03bd9cdc6c..4ac4f1c4437 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/SaveLayoutBeforeClose.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/SaveLayoutBeforeClose.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2014 CEA LIST.
+ * Copyright (c) 2014, 2015 CEA LIST, Christian W. Damus, and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -8,13 +8,20 @@
*
* Contributors:
* Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ * Christian W. Damus - bug 434983
*****************************************************************************/
package org.eclipse.papyrus.infra.core.services;
import java.io.IOException;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialogWithToggle;
import org.eclipse.papyrus.infra.core.Activator;
import org.eclipse.papyrus.infra.core.editor.IMultiDiagramEditor;
+import org.eclipse.papyrus.infra.core.internal.commands.TogglePageLayoutStorageHandler;
+import org.eclipse.papyrus.infra.core.internal.preferences.EditorPreferences;
+import org.eclipse.papyrus.infra.core.internal.preferences.YesNo;
import org.eclipse.papyrus.infra.core.lifecycleevents.DoSaveEvent;
import org.eclipse.papyrus.infra.core.lifecycleevents.ILifeCycleEventsProvider;
import org.eclipse.papyrus.infra.core.lifecycleevents.LifeCycleEventsProvider;
@@ -70,7 +77,7 @@ public class SaveLayoutBeforeClose implements IService {
@Override
public void postDisplay(IMultiDiagramEditor editor) {
- // Nothing
+ checkSharedLayout(editor);
}
@Override
@@ -82,7 +89,7 @@ public class SaveLayoutBeforeClose implements IService {
lifecycleManager.addEditorLifecycleEventsListener(lifecycleListener);
}
- protected void saveBeforeClose(IMultiDiagramEditor editor) {
+ public void saveBeforeClose(IMultiDiagramEditor editor) {
if (editor.isDirty()) {
return; // User explicitly quit without saving. Do nothing (And if user wants to save during exit, the sashmodel will be saved anyway)
}
@@ -124,6 +131,77 @@ public class SaveLayoutBeforeClose implements IService {
}
}
+ private void checkSharedLayout(IMultiDiagramEditor editor) {
+ try {
+ ModelSet modelSet = registry.getService(ModelSet.class);
+ SashModel sashModel = (SashModel) modelSet.getModel(SashModel.MODEL_ID);
+
+ if (sashModel.isLegacyMode()) {
+ // Have we ever created the private sash model file?
+ URI privateURI = sashModel.getPrivateResourceURI();
+ if (!modelSet.getURIConverter().exists(privateURI, null)) {
+ // Prompt the user
+ promptToEnablePrivateStorage(editor);
+ }
+ }
+ } catch (ServiceException ex) {
+ // Shared layout doesn't matter if there's no model-set
+ }
+ }
+
+ private void promptToEnablePrivateStorage(IMultiDiagramEditor editor) {
+ YesNo preference = EditorPreferences.getInstance().getConvertSharedPageLayoutToPrivate();
+
+ if (preference == YesNo.PROMPT) {
+ MessageDialogWithToggle dlg = MessageDialogWithToggle.openYesNoCancelQuestion(editor.getSite().getShell(),
+ Messages.SaveLayoutBeforeClose_0,
+ Messages.SaveLayoutBeforeClose_1,
+ Messages.SaveLayoutBeforeClose_2, false, null, null);
+
+ switch (dlg.getReturnCode()) {
+ case IDialogConstants.YES_ID:
+ preference = YesNo.YES;
+ break;
+ case IDialogConstants.NO_ID:
+ preference = YesNo.NO;
+ break;
+ default:
+ // User cancelled
+ preference = YesNo.PROMPT;
+ break;
+ }
+
+ if (dlg.getToggleState()) {
+ EditorPreferences.getInstance().setConvertSharedPageLayoutToPrivate(preference);
+ }
+ }
+
+ switch (preference) {
+ case YES:
+ // Change the storage to private
+ new TogglePageLayoutStorageHandler().togglePrivatePageLayout(editor);
+
+ // And save the new layout scheme
+ saveBeforeClose(editor);
+ break;
+ case NO:
+ // Just create the empty resource and save it
+ try {
+ ModelSet modelSet = editor.getServicesRegistry().getService(ModelSet.class);
+ SashModel sashModel = (SashModel) modelSet.getModel(SashModel.MODEL_ID);
+ modelSet.createResource(sashModel.getPrivateResourceURI());
+ saveBeforeClose(editor);
+ } catch (ServiceException e) {
+ // Without a model-set, much else is going wrong, so there's no need to deal
+ // with this here
+ }
+ break;
+ default:
+ // User cancelled
+ break;
+ }
+ }
+
@Override
public void disposeService() throws ServiceException {
registry = null;
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/messages.properties b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/messages.properties
new file mode 100644
index 00000000000..a6f77150932
--- /dev/null
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/messages.properties
@@ -0,0 +1,15 @@
+#
+# Copyright (c) 2015 Christian W. Damus 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
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+# Christian W. Damus - Initial API and implementation
+#
+
+SaveLayoutBeforeClose_0=Editor Layout Storage
+SaveLayoutBeforeClose_1=This model stores the editor page layout in the DI resource, which if managed in a source control system will share the layout with others. Convert to local (private) storage of the page layout?
+SaveLayoutBeforeClose_2=Remember my decision

Back to the top