// $Id$
/**
-* Copyright (C) 2013 EDIT
-* European Distributed Institute of Taxonomy
-* http://www.e-taxonomy.eu
-*
-* The contents of this file are subject to the Mozilla Public License Version 1.1
-* See LICENSE.TXT at the top of this package for the full license terms.
-*/
+ * Copyright (C) 2013 EDIT
+ * European Distributed Institute of Taxonomy
+ * http://www.e-taxonomy.eu
+ *
+ * The contents of this file are subject to the Mozilla Public License Version 1.1
+ * See LICENSE.TXT at the top of this package for the full license terms.
+ */
package eu.etaxonomy.taxeditor.view.derivateSearch;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.action.MenuManager;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.ui.IMemento;
import org.eclipse.ui.part.ViewPart;
+import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
+import eu.etaxonomy.cdm.model.common.CdmBase;
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
+import eu.etaxonomy.taxeditor.model.IContextListener;
+import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
+import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
+import eu.etaxonomy.taxeditor.store.CdmStore;
/**
* This view allows to search for and filter {@link SpecimenOrObservationBase}s and display
* the results in a list. The results can be selected and opened in an editor.
*/
-public class DerivateSearchView extends ViewPart {
+public class DerivateSearchView extends ViewPart implements IContextListener, ICdmEntitySessionEnabled {
- public static final String ID = "eu.etaxonomy.taxeditor.ui.campanula.derivatesearch.DerivateSearchView";
+ public static final String ID = "eu.etaxonomy.taxeditor.view.derivateSearch.DerivateSearchView";
private DerivateSearchCompositeController derivateSearchCompositeController;
+ private ConversationHolder conversationHolder;
+ private ICdmEntitySession cdmEntitySession;
+ /**
+ * Constructs a new DerivateSearchView and registers it to listen to context changes
+ */
public DerivateSearchView() {
+ CdmStore.getContextManager().addContextListener(this);
}
/* (non-Javadoc)
*/
@Override
public void createPartControl(Composite parent) {
- derivateSearchCompositeController = new DerivateSearchCompositeController(parent);
- getSite().setSelectionProvider(derivateSearchCompositeController.getDerivateSearchComposite().getResultViewer());
+
+ derivateSearchCompositeController = new DerivateSearchCompositeController(parent, this);
+ getSite().setSelectionProvider(derivateSearchCompositeController.getResultViewer());
+ derivateSearchCompositeController.setEnabled(CdmStore.isActive());
+
+ //create context menu
+ MenuManager menuManager = new MenuManager();
+ getSite().registerContextMenu(menuManager, derivateSearchCompositeController.getResultViewer());
+ Control control = derivateSearchCompositeController.getResultViewer().getControl();
+ Menu menu = menuManager.createContextMenu(control);
+ control.setMenu(menu);
}
/* (non-Javadoc)
*/
@Override
public void setFocus() {
- derivateSearchCompositeController.getDerivateSearchComposite().getResultViewer().getControl().setFocus();
+ derivateSearchCompositeController.setFocus();
+ //make sure to bind again if maybe in another view the conversation was unbound
+ if(getConversationHolder()!=null && !getConversationHolder().isClosed() && !getConversationHolder().isBound()){
+ getConversationHolder().bind();
+ }
+ if(getCdmEntitySession() != null) {
+ getCdmEntitySession().bind();
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.model.IContextListener#contextAboutToStop(org.eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
+ */
+ @Override
+ public void contextAboutToStop(IMemento memento, IProgressMonitor monitor) {
+ }
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.model.IContextListener#contextStop(org.eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
+ */
+ @Override
+ public void contextStop(IMemento memento, IProgressMonitor monitor) {
+ derivateSearchCompositeController.setEnabled(false);
+ derivateSearchCompositeController.reset();
+ }
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.model.IContextListener#contextStart(org.eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
+ */
+ @Override
+ public void contextStart(IMemento memento, IProgressMonitor monitor) {
+ derivateSearchCompositeController.setEnabled(true);
+ }
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.model.IContextListener#contextRefresh(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ @Override
+ public void contextRefresh(IProgressMonitor monitor) {
+ initConversation();
+ initSession();
+ }
+
+ private void initSession() {
+ if(CdmStore.isActive() && cdmEntitySession == null) {
+ cdmEntitySession = CdmStore.getCurrentSessionManager().newSession(this, true);
+ }
+ }
+
+ private void initConversation(){
+ if(conversationHolder==null){
+ conversationHolder = CdmStore.createConversation();
+ derivateSearchCompositeController.setConversation(conversationHolder);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.model.IContextListener#workbenchShutdown(org.eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
+ */
+ @Override
+ public void workbenchShutdown(IMemento memento, IProgressMonitor monitor) {
+ }
+
+ /**
+ * @return the conversationHolder
+ */
+ public ConversationHolder getConversationHolder() {
+ if(CdmStore.isActive() && conversationHolder==null){
+ initConversation();
+ }
+ return conversationHolder;
+ }
+
+ @Override
+ public void dispose() {
+ cdmEntitySession.dispose();
+ super.dispose();
+ }
+
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getCdmEntitySession()
+ */
+ @Override
+ public ICdmEntitySession getCdmEntitySession() {
+ initSession();
+ return cdmEntitySession;
+ }
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getRootEntities()
+ */
+ @Override
+ public <T extends CdmBase> Collection<T> getRootEntities() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getPropertyPathsMap()
+ */
+ @Override
+ public Map<Object, List<String>> getPropertyPathsMap() {
+ // TODO Auto-generated method stub
+ return null;
}
}