summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Roldan Betancort2008-12-19 07:41:19 (EST)
committerVictor Roldan Betancort2008-12-19 07:41:19 (EST)
commitb342286c537eb742352e7da8d48a41d2182c8795 (patch)
treea1a14cc03c8677ecc6acbf58b7c39ec1ad74cd58
parent55e502264d0c0ea02fed296bebbc8a2354bf69bb (diff)
downloadcdo-b342286c537eb742352e7da8d48a41d2182c8795.zip
cdo-b342286c537eb742352e7da8d48a41d2182c8795.tar.gz
cdo-b342286c537eb742352e7da8d48a41d2182c8795.tar.bz2
[244129] [UI] Show warning when closing a session/transaction with uncommitted changes
https://bugs.eclipse.org/bugs/show_bug.cgi?id=244129
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/SharedIcons.java12
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/actions/CloseSessionAction.java23
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/actions/CloseViewAction.java20
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/editor/CDOEditor.java24
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/editor/CDOEditorInput.java8
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOTransaction.java3
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOUtil.java25
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOTransactionImpl.java6
8 files changed, 111 insertions, 10 deletions
diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/SharedIcons.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/SharedIcons.java
index e5ccfa9..8b18638 100644
--- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/SharedIcons.java
+++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/SharedIcons.java
@@ -4,9 +4,10 @@
* 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:
* Eike Stepper - initial API and implementation
+ * Victor Roldan Betancort - maintenance
**************************************************************************/
package org.eclipse.emf.cdo.internal.ui;
@@ -70,6 +71,15 @@ public class SharedIcons
createDescriptor(key);
image = REGISTRY.get(key);
}
+
+ // For some reason, sometimes images get disposed.
+ // In that case, create and put in registry again.
+ if (image.isDisposed())
+ {
+ REGISTRY.remove(key);
+ createDescriptor(key);
+ image = REGISTRY.get(key);
+ }
return image;
}
diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/actions/CloseSessionAction.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/actions/CloseSessionAction.java
index e443966..ee81775 100644
--- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/actions/CloseSessionAction.java
+++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/actions/CloseSessionAction.java
@@ -4,15 +4,19 @@
* 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:
* Eike Stepper - initial API and implementation
+ * Victor Roldan Betancort - maintenance
**************************************************************************/
package org.eclipse.emf.cdo.internal.ui.actions;
import org.eclipse.emf.cdo.CDOSession;
+import org.eclipse.emf.cdo.util.CDOUtil;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.ui.IWorkbenchPage;
/**
@@ -30,8 +34,23 @@ public final class CloseSessionAction extends SessionAction
}
@Override
+ protected void preRun() throws Exception
+ {
+ if (CDOUtil.isSessionDirty(getSession()))
+ {
+ MessageDialog dialog = new MessageDialog(getShell(), TITLE, null,
+ "You have uncommitted changes. Do you want to discard them?", MessageDialog.QUESTION, new String[] {
+ IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL }, 0);
+ if (dialog.open() != MessageDialog.OK)
+ {
+ cancel();
+ }
+ }
+ }
+
+ @Override
protected void doRun(IProgressMonitor progressMonitor) throws Exception
{
getSession().close();
- }
+ }
}
diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/actions/CloseViewAction.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/actions/CloseViewAction.java
index 85f20a5..e677bd1 100644
--- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/actions/CloseViewAction.java
+++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/actions/CloseViewAction.java
@@ -4,15 +4,18 @@
* 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:
* Eike Stepper - initial API and implementation
+ * Victor Roldan Betancort - maintenance
**************************************************************************/
package org.eclipse.emf.cdo.internal.ui.actions;
import org.eclipse.emf.cdo.CDOView;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.ui.IWorkbenchPage;
/**
@@ -30,6 +33,21 @@ public final class CloseViewAction extends ViewAction
}
@Override
+ protected void preRun() throws Exception
+ {
+ if (getView().isDirty())
+ {
+ MessageDialog dialog = new MessageDialog(getShell(), TITLE, null,
+ "You have uncommitted changes. Do you want to discard them?", MessageDialog.QUESTION, new String[] {
+ IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL }, 0);
+ if (dialog.open() != MessageDialog.OK)
+ {
+ cancel();
+ }
+ }
+ }
+
+ @Override
protected void doRun(IProgressMonitor progressMonitor) throws Exception
{
getView().close();
diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/editor/CDOEditor.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/editor/CDOEditor.java
index 156c4ea..853db6c 100644
--- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/editor/CDOEditor.java
+++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/editor/CDOEditor.java
@@ -2146,9 +2146,29 @@ public class CDOEditor extends MultiPageEditorPart implements IEditingDomainProv
public void dispose()
{
updateProblemIndication = false;
- eventHandler.dispose();
+
+ if (!view.isClosed())
+ {
+ try
+ {
+ eventHandler.dispose();
+ }
+ catch (Exception ex)
+ {
+ OM.LOG.error(ex);
+ }
+
+ try
+ {
+ adapterFactory.dispose();
+ }
+ catch (Exception ex)
+ {
+ OM.LOG.error(ex);
+ }
+ }
+
getSite().getPage().removePartListener(partListener);
- adapterFactory.dispose();
if (getActionBarContributor().getActiveEditor() == this)
{
diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/editor/CDOEditorInput.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/editor/CDOEditorInput.java
index c39bf24..75219fc 100644
--- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/editor/CDOEditorInput.java
+++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/editor/CDOEditorInput.java
@@ -4,9 +4,10 @@
* 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:
* Eike Stepper - initial API and implementation
+ * Victor Roldan Betancort - maintenance
**************************************************************************/
package org.eclipse.emf.cdo.internal.ui.editor;
@@ -87,6 +88,11 @@ public class CDOEditorInput extends PlatformObject implements IEditorInput
public String getToolTipText()
{
+ if (view.isClosed())
+ {
+ return "View closed";
+ }
+
CDOSession session = view.getSession();
String repositoryName = session.repository().getName();
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOTransaction.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOTransaction.java
index beec706..8e2f851 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOTransaction.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOTransaction.java
@@ -40,7 +40,8 @@ public interface CDOTransaction extends CDOView, CDOUserTransaction
public long getLastCommitTime();
/**
- * Returns <code>true</code> if this transaction contains local modifications, <code>false</code> otherwise.
+ * Returns <code>true</code> if this transaction is not closed and contains uncommitted changes, <code>false</code>
+ * otherwise.
*
* @since 2.0
*/
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOUtil.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOUtil.java
index c1a232e..bf388a0 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOUtil.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOUtil.java
@@ -4,17 +4,20 @@
* 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:
* Eike Stepper - initial API and implementation
* Simon McDuff - maintenance
+ * Victor Roldan Betancort - maintenance
**************************************************************************/
package org.eclipse.emf.cdo.util;
import org.eclipse.emf.cdo.CDOCollectionLoadingPolicy;
import org.eclipse.emf.cdo.CDOObject;
import org.eclipse.emf.cdo.CDORevisionPrefetchingPolicy;
+import org.eclipse.emf.cdo.CDOSession;
import org.eclipse.emf.cdo.CDOSessionConfiguration;
+import org.eclipse.emf.cdo.CDOTransaction;
import org.eclipse.emf.cdo.CDOView;
import org.eclipse.emf.cdo.CDOViewSet;
import org.eclipse.emf.cdo.CDOXATransaction;
@@ -300,4 +303,24 @@ public final class CDOUtil
return result;
}
+
+ /**
+ * Returns <code>true</code> if the given {@link CDOSession session} contains a dirty {@link CDOTransaction
+ * transaction}, <code>false</code> otherwise.
+ *
+ * @since 2.0
+ * @see CDOTransaction
+ */
+ public static boolean isSessionDirty(CDOSession session)
+ {
+ for (CDOView view : session.getElements())
+ {
+ if (view.isDirty())
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOTransactionImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOTransactionImpl.java
index 08425ea..c7b6187 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOTransactionImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOTransactionImpl.java
@@ -215,7 +215,11 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa
@Override
public boolean isDirty()
{
- checkOpen();
+ if (isClosed())
+ {
+ return false;
+ }
+
return dirty;
}