From: Patrick Plitzner Date: Mon, 26 Oct 2015 15:58:17 +0000 (+0100) Subject: Fix session problems with remoting X-Git-Tag: 3.12.0^2~62^2~7^2~30 X-Git-Url: https://dev.e-taxonomy.eu/gitweb/taxeditor.git/commitdiff_plain/1b9e4990975e2144af305581f55958585adb653c Fix session problems with remoting --- diff --git a/eu.etaxonomy.taxeditor.editor/plugin.xml b/eu.etaxonomy.taxeditor.editor/plugin.xml index 1d1c2e147..18537cde8 100644 --- a/eu.etaxonomy.taxeditor.editor/plugin.xml +++ b/eu.etaxonomy.taxeditor.editor/plugin.xml @@ -1055,6 +1055,12 @@ icon="icons/synced.gif" label="Link with Editor" style="toggle"> + + + + diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateView.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateView.java index 33acf9fae..7414396f1 100644 --- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateView.java +++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateView.java @@ -31,6 +31,7 @@ import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Menu; import org.eclipse.swt.widgets.Tree; import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IMemento; import org.eclipse.ui.ISaveablePart2; import org.eclipse.ui.IWorkbenchPart; @@ -47,6 +48,7 @@ import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap; import eu.etaxonomy.taxeditor.editor.EditorUtil; import eu.etaxonomy.taxeditor.editor.Messages; import eu.etaxonomy.taxeditor.editor.view.derivate.searchFilter.DerivateSearchCompositeController; +import eu.etaxonomy.taxeditor.model.IContextListener; import eu.etaxonomy.taxeditor.model.IPartContentHasDetails; import eu.etaxonomy.taxeditor.model.IPartContentHasFactualData; import eu.etaxonomy.taxeditor.model.IPartContentHasMedia; @@ -62,7 +64,7 @@ import eu.etaxonomy.taxeditor.view.derivateSearch.DerivateLabelProvider; * */ public class DerivateView extends AbstractCdmViewPart implements IPartContentHasFactualData, ISaveablePart2, - IPartContentHasDetails, IPartContentHasSupplementalData, IPartContentHasMedia { + IPartContentHasDetails, IPartContentHasSupplementalData, IPartContentHasMedia, IContextListener { public static final String ID = "eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView"; //$NON-NLS-1$ public static final String YOU_NEED_TO_SAVE_BEFORE_PERFORMING_THIS_ACTION = Messages.DerivateView_YOU_NEED_TO_SAVE; @@ -125,6 +127,13 @@ public class DerivateView extends AbstractCdmViewPart implements IPartContentHas * Default constructor */ public DerivateView() { + init(); + } + + /** + * + */ + private void init() { this.derivateToRootEntityMap = new HashMap, SpecimenOrObservationBase>(); this.rootElements = new HashSet>(); @@ -134,6 +143,8 @@ public class DerivateView extends AbstractCdmViewPart implements IPartContentHas if (CdmStore.isActive()) { cdmEntitySession = CdmStore.getCurrentSessionManager().newSession(this, true); } + //listen to context changes + CdmStore.getContextManager().addContextListener(this); } @Override @@ -195,6 +206,19 @@ public class DerivateView extends AbstractCdmViewPart implements IPartContentHas if (!conversation.isBound()) { conversation.bind(); } + /* + * If the active session is not the session of the Derivate Editor then we will + * save it, bind temporarily to our session and rebind to the original session. + * This happens e.g. if a selection change happens in the taxon editor and + * "Link with editor" is enabled. The selection change event and thus the + * loading in updateRootEntities() happens in the session of the taxon + * editor. + */ + ICdmEntitySession previousCdmEntitySession = CdmStore.getCurrentSessionManager().getActiveSession(); + if(cdmEntitySession != null) { + cdmEntitySession.bind(); + } + if(derivativeUuids!=null){ this.derivateToRootEntityMap = new HashMap, SpecimenOrObservationBase>(); this.rootElements = new HashSet>(); @@ -219,6 +243,7 @@ public class DerivateView extends AbstractCdmViewPart implements IPartContentHas } viewer.setInput(rootElements); refreshTree(); + previousCdmEntitySession.bind(); } } @@ -250,10 +275,6 @@ public class DerivateView extends AbstractCdmViewPart implements IPartContentHas public void doSaveAs() { } - public Set> getRootElements() { - return rootElements; - } - @Override public String getTitleToolTip() { return Messages.DerivateView_DERIVATIVE_EDITOR; @@ -280,7 +301,7 @@ public class DerivateView extends AbstractCdmViewPart implements IPartContentHas public void setFocus() { viewer.getControl().setFocus(); //make sure to bind again if maybe in another view the conversation was unbound - if(!conversation.isBound()){ + if(conversation!=null && !conversation.isBound()){ conversation.bind(); } if(cdmEntitySession != null) { @@ -450,6 +471,14 @@ public class DerivateView extends AbstractCdmViewPart implements IPartContentHas } } + /** + * {@inheritDoc} + */ + @Override + public List> getRootEntities() { + return new ArrayList>(rootElements); + } + @Override public void createViewer(Composite parent) { // TODO Auto-generated method stub @@ -468,7 +497,47 @@ public class DerivateView extends AbstractCdmViewPart implements IPartContentHas public void toggleListenToSelectionChange() { listenToSelectionChange = !listenToSelectionChange; - derivateSearchCompositeController.setEnabled(listenToSelectionChange); + derivateSearchCompositeController.setEnabled(!listenToSelectionChange); + } + + /** + * {@inheritDoc} + */ + @Override + public void contextAboutToStop(IMemento memento, IProgressMonitor monitor) { + } + + /** + * {@inheritDoc} + */ + @Override + public void contextStop(IMemento memento, IProgressMonitor monitor) { + derivateSearchCompositeController.setEnabled(false); + viewer.setInput(null); + } + + /** + * {@inheritDoc} + */ + @Override + public void contextStart(IMemento memento, IProgressMonitor monitor) { + init(); + derivateSearchCompositeController.setEnabled(!listenToSelectionChange); + refreshTree(); + } + + /** + * {@inheritDoc} + */ + @Override + public void contextRefresh(IProgressMonitor monitor) { + } + + /** + * {@inheritDoc} + */ + @Override + public void workbenchShutdown(IMemento memento, IProgressMonitor monitor) { } } diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/AbstractCdmViewPart.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/AbstractCdmViewPart.java index 27be236e3..f9cedbdb8 100644 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/AbstractCdmViewPart.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/AbstractCdmViewPart.java @@ -186,7 +186,7 @@ public abstract class AbstractCdmViewPart extends ViewPart implements ISelection } @Override - public List getRootEntities() { + public List getRootEntities() { return Arrays.asList((CdmBase)getViewer().getInput()); }