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.editor.view.dataimport;
|
11
|
|
12
|
import java.util.ArrayList;
|
13
|
import java.util.Collection;
|
14
|
|
15
|
import org.apache.log4j.Logger;
|
16
|
import org.eclipse.core.runtime.IProgressMonitor;
|
17
|
import org.eclipse.jface.action.IMenuManager;
|
18
|
import org.eclipse.jface.action.IToolBarManager;
|
19
|
import org.eclipse.jface.viewers.CheckboxTableViewer;
|
20
|
import org.eclipse.swt.SWT;
|
21
|
import org.eclipse.swt.widgets.Composite;
|
22
|
import org.eclipse.swt.widgets.Display;
|
23
|
import org.eclipse.swt.widgets.Table;
|
24
|
import org.eclipse.swt.widgets.TableItem;
|
25
|
import org.eclipse.ui.IMemento;
|
26
|
import org.eclipse.ui.forms.widgets.FormToolkit;
|
27
|
import org.eclipse.ui.part.ViewPart;
|
28
|
|
29
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
30
|
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
|
31
|
import eu.etaxonomy.cdm.ext.occurrence.OccurenceQuery;
|
32
|
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
|
33
|
import eu.etaxonomy.taxeditor.model.IContextListener;
|
34
|
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
|
35
|
import eu.etaxonomy.taxeditor.model.IPartContentHasFactualData;
|
36
|
import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
|
37
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
38
|
|
39
|
/**
|
40
|
* View which shows a list of "data" that can be imported into the CDM
|
41
|
* @author pplitzner
|
42
|
* @date Sep 3, 2014
|
43
|
*
|
44
|
* @param <T> the CDM type that will be handled by this view
|
45
|
*/
|
46
|
|
47
|
public abstract class DataImportView<T> extends ViewPart implements IPartContentHasFactualData,
|
48
|
IConversationEnabled, IPartContentHasDetails, IPartContentHasSupplementalData, IContextListener{
|
49
|
|
50
|
protected final Logger logger = Logger.getLogger(DataImportView.class);
|
51
|
|
52
|
protected Collection<T> results = new ArrayList<T>();
|
53
|
|
54
|
protected OccurenceQuery query;
|
55
|
|
56
|
private static ConversationHolder conversationHolder;
|
57
|
|
58
|
private SaveImportedSpecimenAction saveImportedSpecimenAction;
|
59
|
|
60
|
private final FormToolkit toolkit = new FormToolkit(Display.getCurrent());
|
61
|
|
62
|
private Table table;
|
63
|
|
64
|
/**
|
65
|
* Constructs a new DataImportEditor and registers it to listen to context changes
|
66
|
*/
|
67
|
public DataImportView() {
|
68
|
CdmStore.getContextManager().addContextListener(this);
|
69
|
if(CdmStore.isActive()){
|
70
|
initConversation();
|
71
|
}
|
72
|
}
|
73
|
|
74
|
/**
|
75
|
* Create contents of the view part.
|
76
|
* @param parent
|
77
|
*/
|
78
|
@Override
|
79
|
public void createPartControl(Composite parent) {
|
80
|
|
81
|
CheckboxTableViewer checkboxTableViewer = CheckboxTableViewer.newCheckList(parent, SWT.BORDER | SWT.FULL_SELECTION);
|
82
|
table = checkboxTableViewer.getTable();
|
83
|
toolkit.paintBordersFor(table);
|
84
|
|
85
|
createActions();
|
86
|
initializeToolBar();
|
87
|
initializeMenu();
|
88
|
}
|
89
|
|
90
|
/**
|
91
|
* Create the actions.
|
92
|
*/
|
93
|
private void createActions() {
|
94
|
saveImportedSpecimenAction = new SaveImportedSpecimenAction();
|
95
|
}
|
96
|
|
97
|
/**
|
98
|
* Initialize the toolbar.
|
99
|
*/
|
100
|
private void initializeToolBar() {
|
101
|
IToolBarManager tbm = getViewSite().getActionBars().getToolBarManager();
|
102
|
tbm.add(saveImportedSpecimenAction);
|
103
|
}
|
104
|
|
105
|
/**
|
106
|
* Initialize the menu.
|
107
|
*/
|
108
|
private void initializeMenu() {
|
109
|
IMenuManager manager = getViewSite().getActionBars().getMenuManager();
|
110
|
}
|
111
|
|
112
|
public Table getTable() {
|
113
|
return table;
|
114
|
}
|
115
|
|
116
|
/**
|
117
|
* @param query the query to set
|
118
|
*/
|
119
|
public void setQuery(OccurenceQuery query) {
|
120
|
this.query = query;
|
121
|
}
|
122
|
|
123
|
/**
|
124
|
* @param results the results to set
|
125
|
*/
|
126
|
public void setResults(Collection<T> results) {
|
127
|
this.results = results;
|
128
|
}
|
129
|
|
130
|
/* (non-Javadoc)
|
131
|
* @see eu.etaxonomy.taxeditor.annotatedlineeditor.AnnotatedLineEditor#dispose()
|
132
|
*/
|
133
|
@Override
|
134
|
public void dispose() {
|
135
|
super.dispose();
|
136
|
CdmStore.getContextManager().removeContextListener(this);
|
137
|
}
|
138
|
|
139
|
/* (non-Javadoc)
|
140
|
* @see eu.etaxonomy.taxeditor.model.IContextListener#contextRefresh(org.eclipse.core.runtime.IProgressMonitor)
|
141
|
*/
|
142
|
@Override
|
143
|
public void contextRefresh(IProgressMonitor monitor) {
|
144
|
refresh();
|
145
|
}
|
146
|
|
147
|
protected void refresh(){
|
148
|
getTable().removeAll();
|
149
|
for(T item:results){
|
150
|
TableItem tableItem = new TableItem(getTable(), SWT.NONE);
|
151
|
tableItem.setText(getTextForTableItem(item));
|
152
|
tableItem.setData(item);
|
153
|
}
|
154
|
}
|
155
|
|
156
|
public abstract void query();
|
157
|
|
158
|
|
159
|
/* (non-Javadoc)
|
160
|
* @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
|
161
|
*/
|
162
|
@Override
|
163
|
public void update(CdmDataChangeMap changeEvents) {
|
164
|
//nothing
|
165
|
}
|
166
|
|
167
|
/**
|
168
|
* Returns the text label of the given item.
|
169
|
* @param item the item for which the label should be returns
|
170
|
* @return the label of the item
|
171
|
*/
|
172
|
protected abstract String getTextForTableItem(T item);
|
173
|
|
174
|
/* (non-Javadoc)
|
175
|
* @see org.eclipse.ui.part.WorkbenchPart#setFocus()
|
176
|
*/
|
177
|
@Override
|
178
|
public void setFocus() {
|
179
|
getTable().setFocus();
|
180
|
//make sure to bind again if maybe in another view the conversation was unbound
|
181
|
if(getConversationHolder()!=null && !getConversationHolder().isBound()){
|
182
|
getConversationHolder().bind();
|
183
|
}
|
184
|
}
|
185
|
|
186
|
/* (non-Javadoc)
|
187
|
* @see eu.etaxonomy.taxeditor.model.IContextListener#contextAboutToStop(org.eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
|
188
|
*/
|
189
|
@Override
|
190
|
public void contextAboutToStop(IMemento memento, IProgressMonitor monitor) {
|
191
|
}
|
192
|
|
193
|
/* (non-Javadoc)
|
194
|
* @see eu.etaxonomy.taxeditor.model.IContextListener#contextStop(org.eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
|
195
|
*/
|
196
|
@Override
|
197
|
public void contextStop(IMemento memento, IProgressMonitor monitor) {
|
198
|
// derivateSearchCompositeController.setEnabled(false);
|
199
|
// derivateSearchCompositeController.reset();
|
200
|
}
|
201
|
|
202
|
/* (non-Javadoc)
|
203
|
* @see eu.etaxonomy.taxeditor.model.IContextListener#contextStart(org.eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
|
204
|
*/
|
205
|
@Override
|
206
|
public void contextStart(IMemento memento, IProgressMonitor monitor) {
|
207
|
initConversation();
|
208
|
// derivateSearchCompositeController.setEnabled(true);
|
209
|
}
|
210
|
|
211
|
private void initConversation(){
|
212
|
if(conversationHolder==null){
|
213
|
conversationHolder = CdmStore.createConversation();
|
214
|
}
|
215
|
}
|
216
|
|
217
|
/* (non-Javadoc)
|
218
|
* @see eu.etaxonomy.taxeditor.model.IContextListener#workbenchShutdown(org.eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
|
219
|
*/
|
220
|
@Override
|
221
|
public void workbenchShutdown(IMemento memento, IProgressMonitor monitor) {
|
222
|
if(getConversationHolder()!=null && getConversationHolder().isBound() && !getConversationHolder().isClosed()) {
|
223
|
getConversationHolder().close();
|
224
|
}
|
225
|
}
|
226
|
|
227
|
/**
|
228
|
* @return the conversationHolder
|
229
|
*/
|
230
|
@Override
|
231
|
public ConversationHolder getConversationHolder() {
|
232
|
if(CdmStore.isActive() && conversationHolder==null){
|
233
|
initConversation();
|
234
|
}
|
235
|
return conversationHolder;
|
236
|
}
|
237
|
|
238
|
}
|