3 * Copyright (C) 2013 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.editor
.view
.dataimport
;
12 import java
.util
.Collection
;
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
;
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
;
40 * Editor which shows a list of "data" that can be imported into the CDM
45 public abstract class DataImportEditor
<T
> extends EditorPart
implements IPartContentHasFactualData
, IDirtyMarkableSelectionProvider
,
46 IConversationEnabled
, IPartContentHasDetails
, IPartContentHasSupplementalData
, IContextListener
{
48 private ConversationHolder conversation
;
50 private TableViewer tableViewer
;
53 * Constructs a new DataImportEditor and registers it to listen to context changes
55 public DataImportEditor() {
59 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
62 public void createPartControl(Composite parent
) {
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
);
69 // Propagate selection from viewer
70 getSite().setSelectionProvider(tableViewer
);
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
);
81 * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
84 public void setFocus() {
85 //make sure to bind again if maybe in another view the conversation was unbound
86 if(!conversation
.isBound()){
93 * @see org.eclipse.ui.texteditor.AbstractTextEditor#init(org.eclipse.ui.IEditorSite, org.eclipse.ui.IEditorInput)
96 public void init(IEditorSite site
, IEditorInput input
) throws PartInitException
{
97 CdmStore
.getContextManager().addContextListener(this);
100 setPartName(input
.getName());
101 setTitleToolTip(input
.getName());
102 conversation
= ((DataImportEditorInput
<T
>)input
).getConversationHolder();
106 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.AnnotatedLineEditor#dispose()
109 public void dispose() {
111 CdmStore
.getContextManager().removeContextListener(this);
115 * @see eu.etaxonomy.taxeditor.model.IContextListener#contextAboutToStop(org.eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
118 public void contextAboutToStop(IMemento memento
, IProgressMonitor monitor
) {
123 * @see eu.etaxonomy.taxeditor.model.IContextListener#contextStop(org.eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
126 public void contextStop(IMemento memento
, IProgressMonitor monitor
) {
131 * @see eu.etaxonomy.taxeditor.model.IContextListener#contextStart(org.eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
134 public void contextStart(IMemento memento
, IProgressMonitor monitor
) {
139 * @see eu.etaxonomy.taxeditor.model.IContextListener#contextRefresh(org.eclipse.core.runtime.IProgressMonitor)
142 public void contextRefresh(IProgressMonitor monitor
) {
143 IEditorInput editorInput
= getEditorInput();
144 setInput(editorInput
);
145 if(editorInput
instanceof DataImportEditorInput
){
146 tableViewer
.getTable().removeAll();
147 Collection
<T
> results
= ((DataImportEditorInput
<T
>) editorInput
).getResults();
150 TableItem tableItem
= new TableItem(tableViewer
.getTable(), SWT
.NONE
);
151 tableItem
.setText(getTextForTableItem(item
));
152 tableItem
.setData(item
);
158 protected abstract String
getTextForTableItem(T item
);
161 * @see eu.etaxonomy.taxeditor.model.IContextListener#workbenchShutdown(org.eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
164 public void workbenchShutdown(IMemento memento
, IProgressMonitor monitor
) {
165 if(conversation
!=null &&!conversation
.isClosed()) {
166 conversation
.close();
171 * @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
174 public void update(CdmDataChangeMap changeEvents
) {
179 * @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder()
182 public ConversationHolder
getConversationHolder() {
187 * @see eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider#changed(java.lang.Object)
190 public void changed(Object element
) {
195 * @see org.eclipse.ui.part.EditorPart#doSave(org.eclipse.core.runtime.IProgressMonitor)
198 public void doSave(IProgressMonitor monitor
) {
202 * @see org.eclipse.ui.part.EditorPart#doSaveAs()
205 public void doSaveAs() {
209 * @see org.eclipse.ui.part.EditorPart#isDirty()
212 public boolean isDirty() {
217 * @see org.eclipse.ui.part.EditorPart#isSaveAsAllowed()
220 public boolean isSaveAsAllowed() {