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