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