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 org
.eclipse
.core
.runtime
.IProgressMonitor
;
13 import org
.eclipse
.jface
.action
.MenuManager
;
14 import org
.eclipse
.jface
.viewers
.TableViewer
;
15 import org
.eclipse
.swt
.SWT
;
16 import org
.eclipse
.swt
.widgets
.Composite
;
17 import org
.eclipse
.swt
.widgets
.Control
;
18 import org
.eclipse
.swt
.widgets
.Menu
;
19 import org
.eclipse
.swt
.widgets
.Table
;
20 import org
.eclipse
.swt
.widgets
.TableItem
;
21 import org
.eclipse
.ui
.IEditorInput
;
22 import org
.eclipse
.ui
.IEditorSite
;
23 import org
.eclipse
.ui
.IMemento
;
24 import org
.eclipse
.ui
.PartInitException
;
25 import org
.eclipse
.ui
.part
.EditorPart
;
27 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
28 import eu
.etaxonomy
.cdm
.api
.conversation
.IConversationEnabled
;
29 import eu
.etaxonomy
.cdm
.model
.common
.IIdentifiableEntity
;
30 import eu
.etaxonomy
.cdm
.persistence
.hibernate
.CdmDataChangeMap
;
31 import eu
.etaxonomy
.taxeditor
.model
.IContextListener
;
32 import eu
.etaxonomy
.taxeditor
.model
.IDirtyMarkableSelectionProvider
;
33 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasDetails
;
34 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasFactualData
;
35 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasSupplementalData
;
36 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
39 * Editor which shows a list of "data" that can be imported into the CDM
44 public abstract class DataImportEditor
<T
extends IIdentifiableEntity
> extends EditorPart
implements IPartContentHasFactualData
, IDirtyMarkableSelectionProvider
,
45 IConversationEnabled
, IPartContentHasDetails
, IPartContentHasSupplementalData
, IContextListener
{
47 private ConversationHolder conversation
;
49 private TableViewer tableViewer
;
52 * Constructs a new DataImportEditor with a new {@link ConversationHolder}
54 public DataImportEditor() {
55 CdmStore
.getContextManager().addContextListener(this);
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 BioCase 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
);
79 IEditorInput editorInput
= getEditorInput();
80 if(editorInput
instanceof DataImportEditorInput
){
81 for(T specimen
:((DataImportEditorInput
<T
>) editorInput
).getResults()){
82 TableItem tableItem
= new TableItem(table
, SWT
.NONE
);
83 tableItem
.setText(specimen
.generateTitle());
84 tableItem
.setData(specimen
);
90 * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
93 public void setFocus() {
94 //make sure to bind again if maybe in another view the conversation was unbound
95 if(!conversation
.isBound()){
102 * @see org.eclipse.ui.texteditor.AbstractTextEditor#init(org.eclipse.ui.IEditorSite, org.eclipse.ui.IEditorInput)
105 public void init(IEditorSite site
, IEditorInput input
) throws PartInitException
{
108 setPartName(input
.getName());
109 setTitleToolTip(input
.getName());
110 conversation
= ((DataImportEditorInput
)input
).getConversationHolder();
114 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.AnnotatedLineEditor#dispose()
117 public void dispose() {
119 CdmStore
.getContextManager().removeContextListener(this);
123 * @see eu.etaxonomy.taxeditor.model.IContextListener#contextAboutToStop(org.eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
126 public void contextAboutToStop(IMemento memento
, IProgressMonitor monitor
) {
131 * @see eu.etaxonomy.taxeditor.model.IContextListener#contextStop(org.eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
134 public void contextStop(IMemento memento
, IProgressMonitor monitor
) {
139 * @see eu.etaxonomy.taxeditor.model.IContextListener#contextStart(org.eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
142 public void contextStart(IMemento memento
, IProgressMonitor monitor
) {
147 * @see eu.etaxonomy.taxeditor.model.IContextListener#contextRefresh(org.eclipse.core.runtime.IProgressMonitor)
150 public void contextRefresh(IProgressMonitor monitor
) {
151 setInput(getEditorInput());
155 * @see eu.etaxonomy.taxeditor.model.IContextListener#workbenchShutdown(org.eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
158 public void workbenchShutdown(IMemento memento
, IProgressMonitor monitor
) {
159 if(conversation
!=null &&!conversation
.isClosed()) {
160 conversation
.close();
165 * @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
168 public void update(CdmDataChangeMap changeEvents
) {
173 * @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder()
176 public ConversationHolder
getConversationHolder() {
181 * @see eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider#changed(java.lang.Object)
184 public void changed(Object element
) {
189 * @see org.eclipse.ui.part.EditorPart#doSave(org.eclipse.core.runtime.IProgressMonitor)
192 public void doSave(IProgressMonitor monitor
) {
196 * @see org.eclipse.ui.part.EditorPart#doSaveAs()
199 public void doSaveAs() {
203 * @see org.eclipse.ui.part.EditorPart#isDirty()
206 public boolean isDirty() {
211 * @see org.eclipse.ui.part.EditorPart#isSaveAsAllowed()
214 public boolean isSaveAsAllowed() {