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.swt.widgets.Composite;
|
14
|
import org.eclipse.ui.IMemento;
|
15
|
import org.eclipse.ui.part.ViewPart;
|
16
|
|
17
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
18
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
19
|
import eu.etaxonomy.taxeditor.model.IContextListener;
|
20
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
21
|
|
22
|
/**
|
23
|
* This view allows to search for and filter {@link SpecimenOrObservationBase}s and display
|
24
|
* the results in a list. The results can be selected and opened in an editor.
|
25
|
*/
|
26
|
public class DerivateSearchView extends ViewPart implements IContextListener {
|
27
|
|
28
|
public static final String ID = "eu.etaxonomy.taxeditor.view.derivateSearch.DerivateSearchView";
|
29
|
private DerivateSearchCompositeController derivateSearchCompositeController;
|
30
|
private ConversationHolder conversationHolder;
|
31
|
|
32
|
/**
|
33
|
* Constructs a new DerivateSearchView and registers it to listen to context changes
|
34
|
*/
|
35
|
public DerivateSearchView() {
|
36
|
CdmStore.getContextManager().addContextListener(this);
|
37
|
}
|
38
|
|
39
|
/* (non-Javadoc)
|
40
|
* @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
|
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
|
|
49
|
/* (non-Javadoc)
|
50
|
* @see org.eclipse.ui.part.WorkbenchPart#setFocus()
|
51
|
*/
|
52
|
@Override
|
53
|
public void setFocus() {
|
54
|
derivateSearchCompositeController.setFocus();
|
55
|
//make sure to bind again if maybe in another view the conversation was unbound
|
56
|
if(getConversationHolder()!=null && !getConversationHolder().isBound()){
|
57
|
getConversationHolder().bind();
|
58
|
}
|
59
|
}
|
60
|
|
61
|
/* (non-Javadoc)
|
62
|
* @see eu.etaxonomy.taxeditor.model.IContextListener#contextAboutToStop(org.eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
|
63
|
*/
|
64
|
@Override
|
65
|
public void contextAboutToStop(IMemento memento, IProgressMonitor monitor) {
|
66
|
}
|
67
|
|
68
|
/* (non-Javadoc)
|
69
|
* @see eu.etaxonomy.taxeditor.model.IContextListener#contextStop(org.eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
|
70
|
*/
|
71
|
@Override
|
72
|
public void contextStop(IMemento memento, IProgressMonitor monitor) {
|
73
|
derivateSearchCompositeController.setEnabled(false);
|
74
|
derivateSearchCompositeController.reset();
|
75
|
}
|
76
|
|
77
|
/* (non-Javadoc)
|
78
|
* @see eu.etaxonomy.taxeditor.model.IContextListener#contextStart(org.eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
|
79
|
*/
|
80
|
@Override
|
81
|
public void contextStart(IMemento memento, IProgressMonitor monitor) {
|
82
|
derivateSearchCompositeController.setEnabled(true);
|
83
|
}
|
84
|
|
85
|
/* (non-Javadoc)
|
86
|
* @see eu.etaxonomy.taxeditor.model.IContextListener#contextRefresh(org.eclipse.core.runtime.IProgressMonitor)
|
87
|
*/
|
88
|
@Override
|
89
|
public void contextRefresh(IProgressMonitor monitor) {
|
90
|
initConversation();
|
91
|
}
|
92
|
|
93
|
private void initConversation(){
|
94
|
if(conversationHolder==null){
|
95
|
conversationHolder = CdmStore.createConversation();
|
96
|
derivateSearchCompositeController.setConversation(conversationHolder);
|
97
|
}
|
98
|
}
|
99
|
|
100
|
/* (non-Javadoc)
|
101
|
* @see eu.etaxonomy.taxeditor.model.IContextListener#workbenchShutdown(org.eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
|
102
|
*/
|
103
|
@Override
|
104
|
public void workbenchShutdown(IMemento memento, IProgressMonitor monitor) {
|
105
|
if(getConversationHolder()!=null && getConversationHolder().isBound() && !getConversationHolder().isClosed()) {
|
106
|
getConversationHolder().close();
|
107
|
}
|
108
|
}
|
109
|
|
110
|
/**
|
111
|
* @return the conversationHolder
|
112
|
*/
|
113
|
public ConversationHolder getConversationHolder() {
|
114
|
if(CdmStore.isActive() && conversationHolder==null){
|
115
|
initConversation();
|
116
|
}
|
117
|
return conversationHolder;
|
118
|
}
|
119
|
}
|