Add unimplemented methods
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / view / derivateSearch / DerivateSearchView.java
1 // $Id$
2 /**
3 * Copyright (C) 2013 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
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.
9 */
10 package eu.etaxonomy.taxeditor.view.derivateSearch;
11
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;
19
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;
24
25 /**
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.
28 */
29 public class DerivateSearchView extends ViewPart implements IContextListener {
30
31 public static final String ID = "eu.etaxonomy.taxeditor.view.derivateSearch.DerivateSearchView";
32 private DerivateSearchCompositeController derivateSearchCompositeController;
33 private ConversationHolder conversationHolder;
34
35 /**
36 * Constructs a new DerivateSearchView and registers it to listen to context changes
37 */
38 public DerivateSearchView() {
39 CdmStore.getContextManager().addContextListener(this);
40 }
41
42 @Override
43 public void createPartControl(Composite parent) {
44 derivateSearchCompositeController = new DerivateSearchCompositeController(parent, this);
45 getSite().setSelectionProvider(derivateSearchCompositeController.getResultViewer());
46 derivateSearchCompositeController.setEnabled(CdmStore.isActive());
47
48 //create context menu
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);
54 }
55
56 @Override
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();
62 }
63 }
64
65 @Override
66 public void contextAboutToStop(IMemento memento, IProgressMonitor monitor) {
67 }
68
69 @Override
70 public void contextStop(IMemento memento, IProgressMonitor monitor) {
71 derivateSearchCompositeController.setEnabled(false);
72 derivateSearchCompositeController.reset();
73 }
74
75 @Override
76 public void contextStart(IMemento memento, IProgressMonitor monitor) {
77 derivateSearchCompositeController.setEnabled(true);
78 }
79
80 @Override
81 public void contextRefresh(IProgressMonitor monitor) {
82 initConversation();
83 }
84
85 private void initConversation(){
86 if(conversationHolder==null){
87 conversationHolder = CdmStore.createConversation();
88 derivateSearchCompositeController.setConversation(conversationHolder);
89 }
90 }
91
92 @Override
93 public void workbenchShutdown(IMemento memento, IProgressMonitor monitor) {
94 }
95
96 public ConversationHolder getConversationHolder() {
97 if(CdmStore.isActive() && conversationHolder==null){
98 initConversation();
99 }
100 return conversationHolder;
101 }
102
103 /**
104 * {@inheritDoc}
105 */
106 @Override
107 public void dispose() {
108 if(conversationHolder!=null){
109 conversationHolder.close();
110 }
111 }
112 }