1
|
/**
|
2
|
* Copyright (C) 2013 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.taxeditor.view.dataimport;
|
10
|
|
11
|
import java.util.Collection;
|
12
|
|
13
|
import org.apache.log4j.Logger;
|
14
|
import org.eclipse.core.runtime.IProgressMonitor;
|
15
|
import org.eclipse.jface.action.MenuManager;
|
16
|
import org.eclipse.jface.viewers.TableViewer;
|
17
|
import org.eclipse.swt.SWT;
|
18
|
import org.eclipse.swt.widgets.Composite;
|
19
|
import org.eclipse.swt.widgets.Control;
|
20
|
import org.eclipse.swt.widgets.Menu;
|
21
|
import org.eclipse.swt.widgets.Table;
|
22
|
import org.eclipse.swt.widgets.TableItem;
|
23
|
import org.eclipse.ui.IEditorInput;
|
24
|
import org.eclipse.ui.IEditorSite;
|
25
|
import org.eclipse.ui.IMemento;
|
26
|
import org.eclipse.ui.PartInitException;
|
27
|
import org.eclipse.ui.part.EditorPart;
|
28
|
|
29
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
30
|
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
|
31
|
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
|
32
|
import eu.etaxonomy.taxeditor.model.IContextListener;
|
33
|
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
|
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
|
* Editor which shows a list of "data" that can be imported into the CDM
|
41
|
* @author pplitzner
|
42
|
* @date 20.09.2013
|
43
|
*
|
44
|
*/
|
45
|
public abstract class DataImportEditor<T> extends EditorPart implements IPartContentHasFactualData, IDirtyMarkable,
|
46
|
IConversationEnabled, IPartContentHasDetails, IPartContentHasSupplementalData, IContextListener{
|
47
|
|
48
|
protected Logger logger = Logger.getLogger(DataImportEditor.class);
|
49
|
|
50
|
private ConversationHolder conversation;
|
51
|
|
52
|
private TableViewer tableViewer;
|
53
|
|
54
|
/**
|
55
|
* Constructs a new DataImportEditor and registers it to listen to context changes
|
56
|
*/
|
57
|
public DataImportEditor() {
|
58
|
}
|
59
|
|
60
|
/* (non-Javadoc)
|
61
|
* @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
|
62
|
*/
|
63
|
@Override
|
64
|
public void createPartControl(Composite parent) {
|
65
|
|
66
|
Table table = new Table(parent, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
|
67
|
table.setHeaderVisible(true);//TODO: set header title as query
|
68
|
table.setLinesVisible(true);
|
69
|
tableViewer = new TableViewer(table);
|
70
|
|
71
|
// Propagate selection from viewer
|
72
|
getSite().setSelectionProvider(tableViewer);
|
73
|
|
74
|
//create context menu
|
75
|
MenuManager menuManager = new MenuManager();
|
76
|
getSite().registerContextMenu(menuManager, tableViewer);
|
77
|
Control control = tableViewer.getControl();
|
78
|
Menu menu = menuManager.createContextMenu(control);
|
79
|
control.setMenu(menu);
|
80
|
}
|
81
|
|
82
|
/* (non-Javadoc)
|
83
|
* @see org.eclipse.ui.part.WorkbenchPart#setFocus()
|
84
|
*/
|
85
|
@Override
|
86
|
public void setFocus() {
|
87
|
tableViewer.getControl().setFocus();
|
88
|
//make sure to bind again if maybe in another view the conversation was unbound
|
89
|
if(!conversation.isBound()){
|
90
|
conversation.bind();
|
91
|
}
|
92
|
}
|
93
|
|
94
|
|
95
|
/* (non-Javadoc)
|
96
|
* @see org.eclipse.ui.texteditor.AbstractTextEditor#init(org.eclipse.ui.IEditorSite, org.eclipse.ui.IEditorInput)
|
97
|
*/
|
98
|
@Override
|
99
|
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
|
100
|
CdmStore.getContextManager().addContextListener(this);
|
101
|
setSite(site);
|
102
|
setInput(input);
|
103
|
setPartName(input.getName());
|
104
|
setTitleToolTip(input.getName());
|
105
|
conversation = ((DataImportEditorInput<T>)input).getConversationHolder();
|
106
|
}
|
107
|
|
108
|
/* (non-Javadoc)
|
109
|
* @see eu.etaxonomy.taxeditor.annotatedlineeditor.AnnotatedLineEditor#dispose()
|
110
|
*/
|
111
|
@Override
|
112
|
public void dispose() {
|
113
|
super.dispose();
|
114
|
CdmStore.getContextManager().removeContextListener(this);
|
115
|
}
|
116
|
|
117
|
/* (non-Javadoc)
|
118
|
* @see eu.etaxonomy.taxeditor.model.IContextListener#contextAboutToStop(org.eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
|
119
|
*/
|
120
|
@Override
|
121
|
public void contextAboutToStop(IMemento memento, IProgressMonitor monitor) {
|
122
|
//nothing
|
123
|
}
|
124
|
|
125
|
/* (non-Javadoc)
|
126
|
* @see eu.etaxonomy.taxeditor.model.IContextListener#contextStop(org.eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
|
127
|
*/
|
128
|
@Override
|
129
|
public void contextStop(IMemento memento, IProgressMonitor monitor) {
|
130
|
//nothing
|
131
|
}
|
132
|
|
133
|
/* (non-Javadoc)
|
134
|
* @see eu.etaxonomy.taxeditor.model.IContextListener#contextStart(org.eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
|
135
|
*/
|
136
|
@Override
|
137
|
public void contextStart(IMemento memento, IProgressMonitor monitor) {
|
138
|
//nothing
|
139
|
}
|
140
|
|
141
|
/* (non-Javadoc)
|
142
|
* @see eu.etaxonomy.taxeditor.model.IContextListener#contextRefresh(org.eclipse.core.runtime.IProgressMonitor)
|
143
|
*/
|
144
|
@Override
|
145
|
public void contextRefresh(IProgressMonitor monitor) {
|
146
|
IEditorInput editorInput = getEditorInput();
|
147
|
setInput(editorInput);
|
148
|
if(editorInput instanceof DataImportEditorInput){
|
149
|
tableViewer.getTable().removeAll();
|
150
|
Collection<T> results = ((DataImportEditorInput<T>) editorInput).getResults();
|
151
|
if(results!=null){
|
152
|
for(T item:results){
|
153
|
TableItem tableItem = new TableItem(tableViewer.getTable(), SWT.NONE);
|
154
|
tableItem.setText(getTextForTableItem(item));
|
155
|
tableItem.setData(item);
|
156
|
}
|
157
|
}
|
158
|
}
|
159
|
}
|
160
|
|
161
|
/**
|
162
|
* Returns the text label of the given item.
|
163
|
* @param item the item for which the label should be returnes
|
164
|
* @return the label of the item
|
165
|
*/
|
166
|
protected abstract String getTextForTableItem(T item);
|
167
|
|
168
|
/* (non-Javadoc)
|
169
|
* @see eu.etaxonomy.taxeditor.model.IContextListener#workbenchShutdown(org.eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
|
170
|
*/
|
171
|
@Override
|
172
|
public void workbenchShutdown(IMemento memento, IProgressMonitor monitor) {
|
173
|
if(conversation!=null && conversation.isBound() && !conversation.isClosed()) {
|
174
|
conversation.close();
|
175
|
}
|
176
|
}
|
177
|
|
178
|
/* (non-Javadoc)
|
179
|
* @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
|
180
|
*/
|
181
|
@Override
|
182
|
public void update(CdmDataChangeMap changeEvents) {
|
183
|
//nothing
|
184
|
}
|
185
|
|
186
|
/* (non-Javadoc)
|
187
|
* @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder()
|
188
|
*/
|
189
|
@Override
|
190
|
public ConversationHolder getConversationHolder() {
|
191
|
return conversation;
|
192
|
}
|
193
|
|
194
|
/* (non-Javadoc)
|
195
|
* @see eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider#changed(java.lang.Object)
|
196
|
*/
|
197
|
@Override
|
198
|
public void changed(Object element) {
|
199
|
// cannot be changed
|
200
|
}
|
201
|
|
202
|
/* (non-Javadoc)
|
203
|
* @see eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider#forceDirty()
|
204
|
*/
|
205
|
@Override
|
206
|
public void forceDirty() {
|
207
|
// cannot be dirty
|
208
|
}
|
209
|
|
210
|
/* (non-Javadoc)
|
211
|
* @see org.eclipse.ui.part.EditorPart#doSave(org.eclipse.core.runtime.IProgressMonitor)
|
212
|
*/
|
213
|
@Override
|
214
|
public void doSave(IProgressMonitor monitor) {
|
215
|
}
|
216
|
|
217
|
/* (non-Javadoc)
|
218
|
* @see org.eclipse.ui.part.EditorPart#doSaveAs()
|
219
|
*/
|
220
|
@Override
|
221
|
public void doSaveAs() {
|
222
|
}
|
223
|
|
224
|
/* (non-Javadoc)
|
225
|
* @see org.eclipse.ui.part.EditorPart#isDirty()
|
226
|
*/
|
227
|
@Override
|
228
|
public boolean isDirty() {
|
229
|
return false;
|
230
|
}
|
231
|
|
232
|
/* (non-Javadoc)
|
233
|
* @see org.eclipse.ui.part.EditorPart#isSaveAsAllowed()
|
234
|
*/
|
235
|
@Override
|
236
|
public boolean isSaveAsAllowed() {
|
237
|
return false;
|
238
|
}
|
239
|
|
240
|
}
|