3 * Copyright (C) 2013 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.view
.derivateSearch
;
12 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
13 import org
.eclipse
.jface
.action
.MenuManager
;
14 import org
.eclipse
.swt
.widgets
.Composite
;
15 import org
.eclipse
.swt
.widgets
.Control
;
16 import org
.eclipse
.swt
.widgets
.Menu
;
17 import org
.eclipse
.ui
.IMemento
;
18 import org
.eclipse
.ui
.part
.ViewPart
;
20 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
21 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
22 import eu
.etaxonomy
.taxeditor
.model
.IContextListener
;
23 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
26 * This view allows to search for and filter {@link SpecimenOrObservationBase}s and display
27 * the results in a list. The results can be selected and opened in an editor.
29 public class DerivateSearchView
extends ViewPart
implements IContextListener
{
31 public static final String ID
= "eu.etaxonomy.taxeditor.view.derivateSearch.DerivateSearchView";
32 private DerivateSearchCompositeController derivateSearchCompositeController
;
33 private ConversationHolder conversationHolder
;
36 * Constructs a new DerivateSearchView and registers it to listen to context changes
38 public DerivateSearchView() {
39 CdmStore
.getContextManager().addContextListener(this);
43 public void createPartControl(Composite parent
) {
44 derivateSearchCompositeController
= new DerivateSearchCompositeController(parent
, this);
45 getSite().setSelectionProvider(derivateSearchCompositeController
.getResultViewer());
46 derivateSearchCompositeController
.setEnabled(CdmStore
.isActive());
49 MenuManager menuManager
= new MenuManager();
50 getSite().registerContextMenu(menuManager
, derivateSearchCompositeController
.getResultViewer());
51 Control control
= derivateSearchCompositeController
.getResultViewer().getControl();
52 Menu menu
= menuManager
.createContextMenu(control
);
53 control
.setMenu(menu
);
57 public void setFocus() {
58 derivateSearchCompositeController
.setFocus();
59 //make sure to bind again if maybe in another view the conversation was unbound
60 if(getConversationHolder()!=null && !getConversationHolder().isClosed() && !getConversationHolder().isBound()){
61 getConversationHolder().bind();
66 public void contextAboutToStop(IMemento memento
, IProgressMonitor monitor
) {
70 public void contextStop(IMemento memento
, IProgressMonitor monitor
) {
71 derivateSearchCompositeController
.setEnabled(false);
72 derivateSearchCompositeController
.reset();
76 public void contextStart(IMemento memento
, IProgressMonitor monitor
) {
77 derivateSearchCompositeController
.setEnabled(true);
81 public void contextRefresh(IProgressMonitor monitor
) {
85 private void initConversation(){
86 if(conversationHolder
==null){
87 conversationHolder
= CdmStore
.createConversation();
88 derivateSearchCompositeController
.setConversation(conversationHolder
);
93 public void workbenchShutdown(IMemento memento
, IProgressMonitor monitor
) {
96 public ConversationHolder
getConversationHolder() {
97 if(CdmStore
.isActive() && conversationHolder
==null){
100 return conversationHolder
;
107 public void dispose() {
108 if(conversationHolder
!=null){
109 conversationHolder
.close();