*/
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 implements IContextListener {
+public class DerivateSearchView extends ViewPart implements IContextListener, ICdmEntitySessionEnabled {
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
*/
@Override
public void createPartControl(Composite parent) {
+
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)
public void setFocus() {
derivateSearchCompositeController.setFocus();
//make sure to bind again if maybe in another view the conversation was unbound
- if(getConversationHolder()!=null && !getConversationHolder().isBound()){
+ if(getConversationHolder()!=null && !getConversationHolder().isClosed() && !getConversationHolder().isBound()){
getConversationHolder().bind();
}
+ if(getCdmEntitySession() != null) {
+ getCdmEntitySession().bind();
+ }
}
/* (non-Javadoc)
@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(){
}
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;
+ }
}