Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Rentz-Reichert2019-10-18 12:15:17 -0400
committerHenrik Rentz-Reichert2019-10-18 12:15:17 -0400
commit0327d439a3964c16ef650d251c8599d2830ab452 (patch)
treebc06bc44dd304f6676caf152779049decbef3a42
parent1537b53a166a6a7f16a37df9ca6686049dceb608 (diff)
downloadorg.eclipse.etrice-0327d439a3964c16ef650d251c8599d2830ab452.tar.gz
org.eclipse.etrice-0327d439a3964c16ef650d251c8599d2830ab452.tar.xz
org.eclipse.etrice-0327d439a3964c16ef650d251c8599d2830ab452.zip
Bug 550882 - [diagram] diagram close with "don't save" does not work
* fixed the bug (for all editors) * removed commented-out code Change-Id: I53f80d00cc297bd6daa36f02d230a5349781f8ea
-rw-r--r--plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/editor/ISaveOnFocusLostEditor.java29
-rw-r--r--plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/editor/SaveOnFocusLostListener.java6
-rw-r--r--plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/editor/SaveOnFocusLostXtextEditor.java36
-rw-r--r--plugins/org.eclipse.etrice.core.config.ui/plugin.xml2
-rw-r--r--plugins/org.eclipse.etrice.core.etmap.ui/plugin.xml2
-rw-r--r--plugins/org.eclipse.etrice.core.etphys.ui/plugin.xml2
-rw-r--r--plugins/org.eclipse.etrice.core.fsm.ui/plugin.xml2
-rw-r--r--plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/editor/RoomEditor.java4
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/editor/AbstractFSMEditor.java8
-rw-r--r--plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/editor/DiagramEditorBase.java19
-rw-r--r--plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/editor/SaveOnFocusLostListener.java29
11 files changed, 102 insertions, 37 deletions
diff --git a/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/editor/ISaveOnFocusLostEditor.java b/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/editor/ISaveOnFocusLostEditor.java
new file mode 100644
index 000000000..79ee499ff
--- /dev/null
+++ b/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/editor/ISaveOnFocusLostEditor.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * Copyright (c) 2019 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+package org.eclipse.etrice.core.common.ui.editor;
+
+import org.eclipse.ui.ISaveablePart2;
+
+/**
+ * @author Henrik Rentz-Reichert
+ *
+ */
+public interface ISaveOnFocusLostEditor extends ISaveablePart2 {
+
+ /**
+ * if this editor is currently being closed (check in {@link #promptToSaveOnClose()}) this should return true
+ * @return
+ */
+ boolean isClosing();
+}
diff --git a/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/editor/SaveOnFocusLostListener.java b/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/editor/SaveOnFocusLostListener.java
index 9910e8857..26fba1d5d 100644
--- a/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/editor/SaveOnFocusLostListener.java
+++ b/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/editor/SaveOnFocusLostListener.java
@@ -65,6 +65,12 @@ public class SaveOnFocusLostListener implements IPartListener {
if (!(editor instanceof IValidatingEditor))
return;
+ if (part instanceof ISaveOnFocusLostEditor) {
+ if (((ISaveOnFocusLostEditor) part).isClosing()) {
+ return;
+ }
+ }
+
boolean save = Platform.getPreferencesService().getBoolean(store, key, true, null);
if (save && editor.isDirty())
diff --git a/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/editor/SaveOnFocusLostXtextEditor.java b/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/editor/SaveOnFocusLostXtextEditor.java
new file mode 100644
index 000000000..cad121a18
--- /dev/null
+++ b/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/editor/SaveOnFocusLostXtextEditor.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Copyright (c) 2019 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+package org.eclipse.etrice.core.common.ui.editor;
+
+import org.eclipse.xtext.ui.editor.XtextEditor;
+
+/**
+ * @author Henrik Rentz-Reichert
+ *
+ */
+public class SaveOnFocusLostXtextEditor extends XtextEditor implements ISaveOnFocusLostEditor {
+
+ private boolean isClosing = false;
+
+ @Override
+ public int promptToSaveOnClose() {
+ isClosing = true;
+ return DEFAULT;
+ }
+
+ @Override
+ public boolean isClosing() {
+ return isClosing;
+ }
+}
diff --git a/plugins/org.eclipse.etrice.core.config.ui/plugin.xml b/plugins/org.eclipse.etrice.core.config.ui/plugin.xml
index aaf986a8f..c656b6b23 100644
--- a/plugins/org.eclipse.etrice.core.config.ui/plugin.xml
+++ b/plugins/org.eclipse.etrice.core.config.ui/plugin.xml
@@ -6,7 +6,7 @@
<extension
point="org.eclipse.ui.editors">
<editor
- class="org.eclipse.etrice.core.ui.ConfigExecutableExtensionFactory:org.eclipse.xtext.ui.editor.XtextEditor"
+ class="org.eclipse.etrice.core.ui.ConfigExecutableExtensionFactory:org.eclipse.etrice.core.common.ui.editor.SaveOnFocusLostXtextEditor"
contributorClass="org.eclipse.ui.editors.text.TextEditorActionContributor"
default="true"
extensions="config"
diff --git a/plugins/org.eclipse.etrice.core.etmap.ui/plugin.xml b/plugins/org.eclipse.etrice.core.etmap.ui/plugin.xml
index 168738a03..8fcc48131 100644
--- a/plugins/org.eclipse.etrice.core.etmap.ui/plugin.xml
+++ b/plugins/org.eclipse.etrice.core.etmap.ui/plugin.xml
@@ -6,7 +6,7 @@
<extension
point="org.eclipse.ui.editors">
<editor
- class="org.eclipse.etrice.core.etmap.ui.ETMapExecutableExtensionFactory:org.eclipse.xtext.ui.editor.XtextEditor"
+ class="org.eclipse.etrice.core.etmap.ui.ETMapExecutableExtensionFactory:org.eclipse.etrice.core.common.ui.editor.SaveOnFocusLostXtextEditor"
contributorClass="org.eclipse.ui.editors.text.TextEditorActionContributor"
default="true"
extensions="etmap"
diff --git a/plugins/org.eclipse.etrice.core.etphys.ui/plugin.xml b/plugins/org.eclipse.etrice.core.etphys.ui/plugin.xml
index 5b7ac28d6..5c74d4506 100644
--- a/plugins/org.eclipse.etrice.core.etphys.ui/plugin.xml
+++ b/plugins/org.eclipse.etrice.core.etphys.ui/plugin.xml
@@ -6,7 +6,7 @@
<extension
point="org.eclipse.ui.editors">
<editor
- class="org.eclipse.etrice.core.etphys.ui.ETPhysExecutableExtensionFactory:org.eclipse.xtext.ui.editor.XtextEditor"
+ class="org.eclipse.etrice.core.etphys.ui.ETPhysExecutableExtensionFactory:org.eclipse.etrice.core.common.ui.editor.SaveOnFocusLostXtextEditor"
contributorClass="org.eclipse.ui.editors.text.TextEditorActionContributor"
default="true"
extensions="etphys"
diff --git a/plugins/org.eclipse.etrice.core.fsm.ui/plugin.xml b/plugins/org.eclipse.etrice.core.fsm.ui/plugin.xml
index bef30644d..7e04f1b21 100644
--- a/plugins/org.eclipse.etrice.core.fsm.ui/plugin.xml
+++ b/plugins/org.eclipse.etrice.core.fsm.ui/plugin.xml
@@ -6,7 +6,7 @@
<extension
point="org.eclipse.ui.editors">
<editor
- class="org.eclipse.etrice.core.fsm.ui.FSMExecutableExtensionFactory:org.eclipse.xtext.ui.editor.XtextEditor"
+ class="org.eclipse.etrice.core.fsm.ui.FSMExecutableExtensionFactory:org.eclipse.etrice.core.common.ui.editor.SaveOnFocusLostXtextEditor"
contributorClass="org.eclipse.ui.editors.text.TextEditorActionContributor"
default="true"
extensions="fsm"
diff --git a/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/editor/RoomEditor.java b/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/editor/RoomEditor.java
index 936e4ec4d..6f8156376 100644
--- a/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/editor/RoomEditor.java
+++ b/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/editor/RoomEditor.java
@@ -16,12 +16,12 @@ import java.util.List;
import org.eclipse.etrice.core.common.ui.editor.IValidatingEditor;
import org.eclipse.etrice.core.common.ui.editor.SaveOnFocusLostListener;
+import org.eclipse.etrice.core.common.ui.editor.SaveOnFocusLostXtextEditor;
import org.eclipse.etrice.core.common.validation.IssueUtils;
import org.eclipse.etrice.core.ui.preferences.RoomPreferenceConstants;
import org.eclipse.help.IContextProvider;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.xtext.resource.XtextResource;
-import org.eclipse.xtext.ui.editor.XtextEditor;
import org.eclipse.xtext.util.CancelIndicator;
import org.eclipse.xtext.util.concurrent.IUnitOfWork;
import org.eclipse.xtext.validation.CheckMode;
@@ -34,7 +34,7 @@ import com.google.inject.Inject;
* @author Henrik Rentz-Reichert
*
*/
-public class RoomEditor extends XtextEditor implements IValidatingEditor {
+public class RoomEditor extends SaveOnFocusLostXtextEditor implements IValidatingEditor {
@Inject
protected IResourceValidator resourceValidator;
diff --git a/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/editor/AbstractFSMEditor.java b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/editor/AbstractFSMEditor.java
index ef90efc44..05cd5b000 100644
--- a/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/editor/AbstractFSMEditor.java
+++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/editor/AbstractFSMEditor.java
@@ -15,7 +15,6 @@
package org.eclipse.etrice.ui.behavior.fsm.editor;
import java.util.ArrayList;
-import java.util.EventObject;
import java.util.Map;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -57,7 +56,6 @@ import com.google.common.base.Function;
public abstract class AbstractFSMEditor extends DiagramEditorBase {
protected DiagnosingModelObserver diagnosingModelObserver;
-
/**
* @param textEditorClass
*/
@@ -296,10 +294,4 @@ public abstract class AbstractFSMEditor extends DiagramEditorBase {
featureProvider.updateIfPossible(updateCtx);
diagramTypeProvider.getDiagramBehavior().refresh();
}
-
- @Override
- public void commandStackChanged(EventObject event) {
- // TODO Auto-generated method stub
- super.commandStackChanged(event);
- }
}
diff --git a/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/editor/DiagramEditorBase.java b/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/editor/DiagramEditorBase.java
index 4c91be7cd..9674a3860 100644
--- a/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/editor/DiagramEditorBase.java
+++ b/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/editor/DiagramEditorBase.java
@@ -14,6 +14,8 @@
package org.eclipse.etrice.ui.common.base.editor;
+import static org.eclipse.ui.PlatformUI.getWorkbench;
+
import java.util.Collection;
import java.util.Map;
@@ -23,6 +25,7 @@ import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature.Setting;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.etrice.core.common.ui.editor.ISaveOnFocusLostEditor;
import org.eclipse.etrice.core.common.ui.linking.GlobalNonPlatformURIEditorOpener;
import org.eclipse.etrice.core.fsm.fSM.ModelComponent;
import org.eclipse.etrice.core.fsm.ui.FSMUiModule;
@@ -45,15 +48,13 @@ import org.eclipse.xtext.resource.XtextResource;
import org.eclipse.xtext.ui.editor.XtextEditor;
import org.eclipse.xtext.util.concurrent.IUnitOfWork;
-import static org.eclipse.ui.PlatformUI.getWorkbench;
-
import com.google.inject.Injector;
/**
* @author Henrik Rentz-Reichert
*
*/
-public abstract class DiagramEditorBase extends DiagramEditor implements IInputUriHolder {
+public abstract class DiagramEditorBase extends DiagramEditor implements IInputUriHolder, ISaveOnFocusLostEditor {
private final static String CONTEXT_ID = "org.eclipse.etrice.ui.common.base.context";
@@ -63,6 +64,8 @@ public abstract class DiagramEditorBase extends DiagramEditor implements IInputU
private SuperClassListener superClassListener;
+ private boolean isClosing = false;
+
public DiagramEditorBase(Object textEditorClass) {
this.textEditorClass = textEditorClass;
@@ -254,4 +257,14 @@ public abstract class DiagramEditorBase extends DiagramEditor implements IInputU
}
+ @Override
+ public int promptToSaveOnClose() {
+ isClosing = true;
+ return DEFAULT;
+ }
+
+ public boolean isClosing() {
+ return isClosing;
+ }
+
}
diff --git a/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/editor/SaveOnFocusLostListener.java b/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/editor/SaveOnFocusLostListener.java
index 6ed93791d..8b6cf8913 100644
--- a/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/editor/SaveOnFocusLostListener.java
+++ b/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/editor/SaveOnFocusLostListener.java
@@ -15,6 +15,7 @@
package org.eclipse.etrice.ui.common.base.editor;
import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.etrice.core.common.ui.editor.ISaveOnFocusLostEditor;
import org.eclipse.etrice.ui.common.base.UIBaseActivator;
import org.eclipse.etrice.ui.common.base.preferences.UIBasePreferenceConstants;
import org.eclipse.jface.preference.IPreferenceStore;
@@ -26,7 +27,7 @@ import org.eclipse.ui.IWorkbenchPart;
* @author Henrik Rentz-Reichert
*
*/
-public class SaveOnFocusLostListener implements IPartListener/*, CommandStackListener*/ {
+public class SaveOnFocusLostListener implements IPartListener {
private final IEditorPart editor;
private final IPreferenceStore store;
@@ -39,7 +40,6 @@ public class SaveOnFocusLostListener implements IPartListener/*, CommandStackLis
public SaveOnFocusLostListener(IEditorPart editor) {
this.editor = editor;
this.store = UIBaseActivator.getDefault().getPreferenceStore();
- //editor.getEditingDomain().getCommandStack().addCommandStackListener(this);
editor.getSite().getPage().addPartListener(this);
}
@@ -62,19 +62,17 @@ public class SaveOnFocusLostListener implements IPartListener/*, CommandStackLis
@Override
public void partDeactivated(IWorkbenchPart part) {
- if(part != editor)
+ if (part != editor)
return;
+ if (part instanceof ISaveOnFocusLostEditor) {
+ if (((ISaveOnFocusLostEditor) part).isClosing()) {
+ return;
+ }
+ }
+
boolean isSaveOnFocus = store.getBoolean(UIBasePreferenceConstants.SAVE_DIAG_ON_FOCUS_LOST);
if (isActive && isSaveOnFocus && editor.isDirty()) {
-// if (editor.getEditingDomain() instanceof TransactionalEditingDomainImpl) {
-// TransactionalEditingDomainImpl ted = (TransactionalEditingDomainImpl) editor.getEditingDomain();
-// if (ted.getActiveTransaction()!=null) {
-// // avoid to run into dead-lock
-// saveAfterCurrentCommand = true;
-// return;
-// }
-// }
editor.doSave(new NullProgressMonitor());
}
}
@@ -82,15 +80,6 @@ public class SaveOnFocusLostListener implements IPartListener/*, CommandStackLis
@Override
public void partOpened(IWorkbenchPart part) {
}
-
-// @Override
-// public void commandStackChanged(EventObject event) {
-//
-// if (saveAfterCurrentCommand) {
-// saveAfterCurrentCommand = false;
-// editor.doSave(new NullProgressMonitor());
-// }
-// }
public void setActive(boolean isActive){
this.isActive = isActive;

Back to the top