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
|
/* (non-Javadoc)
|
43
|
* @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
|
44
|
*/
|
45
|
@Override
|
46
|
public void createPartControl(Composite parent) {
|
47
|
derivateSearchCompositeController = new DerivateSearchCompositeController(parent, this);
|
48
|
getSite().setSelectionProvider(derivateSearchCompositeController.getResultViewer());
|
49
|
derivateSearchCompositeController.setEnabled(CdmStore.isActive());
|
50
|
|
51
|
//create context menu
|
52
|
MenuManager menuManager = new MenuManager();
|
53
|
getSite().registerContextMenu(menuManager, derivateSearchCompositeController.getResultViewer());
|
54
|
Control control = derivateSearchCompositeController.getResultViewer().getControl();
|
55
|
Menu menu = menuManager.createContextMenu(control);
|
56
|
control.setMenu(menu);
|
57
|
}
|
58
|
|
59
|
/* (non-Javadoc)
|
60
|
* @see org.eclipse.ui.part.WorkbenchPart#setFocus()
|
61
|
*/
|
62
|
@Override
|
63
|
public void setFocus() {
|
64
|
derivateSearchCompositeController.setFocus();
|
65
|
//make sure to bind again if maybe in another view the conversation was unbound
|
66
|
if(getConversationHolder()!=null && !getConversationHolder().isClosed() && !getConversationHolder().isBound()){
|
67
|
getConversationHolder().bind();
|
68
|
}
|
69
|
}
|
70
|
|
71
|
/* (non-Javadoc)
|
72
|
* @see eu.etaxonomy.taxeditor.model.IContextListener#contextAboutToStop(org.eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
|
73
|
*/
|
74
|
@Override
|
75
|
public void contextAboutToStop(IMemento memento, IProgressMonitor monitor) {
|
76
|
}
|
77
|
|
78
|
/* (non-Javadoc)
|
79
|
* @see eu.etaxonomy.taxeditor.model.IContextListener#contextStop(org.eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
|
80
|
*/
|
81
|
@Override
|
82
|
public void contextStop(IMemento memento, IProgressMonitor monitor) {
|
83
|
derivateSearchCompositeController.setEnabled(false);
|
84
|
derivateSearchCompositeController.reset();
|
85
|
}
|
86
|
|
87
|
/* (non-Javadoc)
|
88
|
* @see eu.etaxonomy.taxeditor.model.IContextListener#contextStart(org.eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
|
89
|
*/
|
90
|
@Override
|
91
|
public void contextStart(IMemento memento, IProgressMonitor monitor) {
|
92
|
derivateSearchCompositeController.setEnabled(true);
|
93
|
}
|
94
|
|
95
|
/* (non-Javadoc)
|
96
|
* @see eu.etaxonomy.taxeditor.model.IContextListener#contextRefresh(org.eclipse.core.runtime.IProgressMonitor)
|
97
|
*/
|
98
|
@Override
|
99
|
public void contextRefresh(IProgressMonitor monitor) {
|
100
|
initConversation();
|
101
|
}
|
102
|
|
103
|
private void initConversation(){
|
104
|
if(conversationHolder==null){
|
105
|
conversationHolder = CdmStore.createConversation();
|
106
|
derivateSearchCompositeController.setConversation(conversationHolder);
|
107
|
}
|
108
|
}
|
109
|
|
110
|
/* (non-Javadoc)
|
111
|
* @see eu.etaxonomy.taxeditor.model.IContextListener#workbenchShutdown(org.eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
|
112
|
*/
|
113
|
@Override
|
114
|
public void workbenchShutdown(IMemento memento, IProgressMonitor monitor) {
|
115
|
}
|
116
|
|
117
|
/**
|
118
|
* @return the conversationHolder
|
119
|
*/
|
120
|
public ConversationHolder getConversationHolder() {
|
121
|
if(CdmStore.isActive() && conversationHolder==null){
|
122
|
initConversation();
|
123
|
}
|
124
|
return conversationHolder;
|
125
|
}
|
126
|
}
|