Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaxime Porhel2018-07-16 10:12:59 +0000
committerMaxime Porhel2018-07-18 14:39:50 +0000
commitd06a283bcbec85e73dcb8fa27d24a19264d2fd7d (patch)
treef4f399b98819311f6ae1b23aee0af0ec7074e81f
parentd0ba85821262e1e7aa6361a5c8c5a40610339829 (diff)
downloadorg.eclipse.sirius-d06a283bcbec85e73dcb8fa27d24a19264d2fd7d.tar.gz
org.eclipse.sirius-d06a283bcbec85e73dcb8fa27d24a19264d2fd7d.tar.xz
org.eclipse.sirius-d06a283bcbec85e73dcb8fa27d24a19264d2fd7d.zip
[537112] Improve configurability of the 'save when no editor'
- Allow sublasses of SaveSessionWhenNoDialectEditorsListener to provide their own impementation of SaveSessionJob - Allow sublasses of SaveSessionJob to customize the save operation done by the job. Bug: 537112 Cherry-picked-from: 537111 Change-Id: I3bfd5cd418745a4e259bc0e47fa2201e11a00757 Signed-off-by: Maxime Porhel <maxime.porhel@obeo.fr>
-rw-r--r--plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/internal/session/SaveSessionWhenNoDialectEditorsListener.java15
-rw-r--r--plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/danalysis/SaveSessionJob.java58
2 files changed, 49 insertions, 24 deletions
diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/internal/session/SaveSessionWhenNoDialectEditorsListener.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/internal/session/SaveSessionWhenNoDialectEditorsListener.java
index 045a389865..83e9df506e 100644
--- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/internal/session/SaveSessionWhenNoDialectEditorsListener.java
+++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/internal/session/SaveSessionWhenNoDialectEditorsListener.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011, 2016 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
@@ -143,7 +143,7 @@ public class SaveSessionWhenNoDialectEditorsListener implements ResourceSyncClie
if (SessionStatus.DIRTY.equals(session.getStatus())) {
if (saveSessionJob == null || saveSessionJob.getState() == Job.NONE) {
preSave();
- saveSessionJob = new SaveSessionJob(session);
+ saveSessionJob = createSaveSessionJob(session);
saveSessionJob.schedule();
}
}
@@ -151,6 +151,17 @@ public class SaveSessionWhenNoDialectEditorsListener implements ResourceSyncClie
}
/**
+ * Create the job that will save the session.
+ *
+ * @param aSession
+ * the session to save
+ * @return a save session job to schedule
+ */
+ protected SaveSessionJob createSaveSessionJob(Session aSession) {
+ return new SaveSessionJob(aSession);
+ }
+
+ /**
* This method allows to do some treatments before saving.
*
* WARNING : Be careful not to break default Sirius saving behavior when overriding this method.
diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/danalysis/SaveSessionJob.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/danalysis/SaveSessionJob.java
index 5d72594346..8584b5e437 100644
--- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/danalysis/SaveSessionJob.java
+++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/danalysis/SaveSessionJob.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012, 2015 THALES GLOBAL SERVICES.
+ * Copyright (c) 2012, 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
@@ -47,30 +47,11 @@ public class SaveSessionJob extends Job {
@Override
public IStatus run(IProgressMonitor monitor) {
+ IStatus result = Status.OK_STATUS;
try {
monitor.beginTask(Messages.SaveSessionJob_sessionSavingMsg, IProgressMonitor.UNKNOWN);
if (session != null && session.isOpen() && SessionStatus.DIRTY == session.getStatus()) {
- if (session instanceof DAnalysisSessionImpl) {
- /*
- * We can never know when the job will be scheduled, and it
- * might happen after the editing domain is disposed. Even
- * testing the state of the editing domain at the beginning
- * of the save is not enough, as it can be disposed by
- * another thread during the save, in which case the
- * commit() will throw an NPE and part of the DASI.doSave()
- * will not be executed, even if the files are actually
- * saved.
- */
- boolean exclusiveSetting = ((DAnalysisSessionImpl) session).isSaveInExclusiveTransaction();
- ((DAnalysisSessionImpl) session).setSaveInExclusiveTransaction(false);
- try {
- session.save(monitor);
- } finally {
- ((DAnalysisSessionImpl) session).setSaveInExclusiveTransaction(exclusiveSetting);
- }
- } else {
- session.save(monitor);
- }
+ result = performSave(monitor);
monitor.worked(1);
}
} finally {
@@ -79,6 +60,39 @@ public class SaveSessionJob extends Job {
// kept by the ProgressManager.
session = null;
}
+ return result;
+ }
+
+ /**
+ * Perform the save operation.
+ *
+ * Callers must ensure that session is not null, open and has a SessionStatus.DIRTY status before calling this
+ * method.
+ *
+ * WARNING : Be careful not to break default Sirius saving behavior when overriding this method.
+ *
+ * @param monitor
+ * the progress monitor to associate to this operation.
+ * @return resulting status of the run. The result must not be null
+ */
+ protected IStatus performSave(IProgressMonitor monitor) {
+ if (session instanceof DAnalysisSessionImpl) {
+ /*
+ * We can never know when the job will be scheduled, and it might happen after the editing domain is
+ * disposed. Even testing the state of the editing domain at the beginning of the save is not enough, as it
+ * can be disposed by another thread during the save, in which case the commit() will throw an NPE and part
+ * of the DASI.doSave() will not be executed, even if the files are actually saved.
+ */
+ boolean exclusiveSetting = ((DAnalysisSessionImpl) session).isSaveInExclusiveTransaction();
+ ((DAnalysisSessionImpl) session).setSaveInExclusiveTransaction(false);
+ try {
+ session.save(monitor);
+ } finally {
+ ((DAnalysisSessionImpl) session).setSaveInExclusiveTransaction(exclusiveSetting);
+ }
+ } else {
+ session.save(monitor);
+ }
return Status.OK_STATUS;
}

Back to the top