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;
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;
*
*/
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;
* Default constructor
*/
public DerivateView() {
+ init();
+ }
+
+ /**
+ *
+ */
+ private void init() {
this.derivateToRootEntityMap = new HashMap<SpecimenOrObservationBase<?>, SpecimenOrObservationBase<?>>();
this.rootElements = new HashSet<SpecimenOrObservationBase<?>>();
if (CdmStore.isActive()) {
cdmEntitySession = CdmStore.getCurrentSessionManager().newSession(this, true);
}
+ //listen to context changes
+ CdmStore.getContextManager().addContextListener(this);
}
@Override
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<?>, SpecimenOrObservationBase<?>>();
this.rootElements = new HashSet<SpecimenOrObservationBase<?>>();
}
viewer.setInput(rootElements);
refreshTree();
+ previousCdmEntitySession.bind();
}
}
public void doSaveAs() {
}
- public Set<SpecimenOrObservationBase<?>> getRootElements() {
- return rootElements;
- }
-
@Override
public String getTitleToolTip() {
return Messages.DerivateView_DERIVATIVE_EDITOR;
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) {
}
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public List<SpecimenOrObservationBase<?>> getRootEntities() {
+ return new ArrayList<SpecimenOrObservationBase<?>>(rootElements);
+ }
+
@Override
public void createViewer(Composite parent) {
// TODO Auto-generated method stub
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) {
}
}