2 * Copyright (C) 2013 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.view
.dataimport
.e4
;
11 import java
.util
.ArrayList
;
12 import java
.util
.Collection
;
14 import javax
.annotation
.PostConstruct
;
15 import javax
.annotation
.PreDestroy
;
17 import org
.apache
.log4j
.Logger
;
18 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
19 import org
.eclipse
.e4
.ui
.di
.Focus
;
20 import org
.eclipse
.jface
.viewers
.CheckboxTableViewer
;
21 import org
.eclipse
.jface
.wizard
.IWizard
;
22 import org
.eclipse
.jface
.wizard
.WizardDialog
;
23 import org
.eclipse
.swt
.SWT
;
24 import org
.eclipse
.swt
.events
.SelectionAdapter
;
25 import org
.eclipse
.swt
.events
.SelectionEvent
;
26 import org
.eclipse
.swt
.layout
.GridData
;
27 import org
.eclipse
.swt
.layout
.GridLayout
;
28 import org
.eclipse
.swt
.widgets
.Button
;
29 import org
.eclipse
.swt
.widgets
.Composite
;
30 import org
.eclipse
.swt
.widgets
.Display
;
31 import org
.eclipse
.swt
.widgets
.Event
;
32 import org
.eclipse
.swt
.widgets
.Label
;
33 import org
.eclipse
.swt
.widgets
.Listener
;
34 import org
.eclipse
.swt
.widgets
.Table
;
35 import org
.eclipse
.swt
.widgets
.TableItem
;
36 import org
.eclipse
.swt
.widgets
.Text
;
37 import org
.eclipse
.ui
.IMemento
;
38 import org
.eclipse
.ui
.forms
.widgets
.FormToolkit
;
39 import org
.eclipse
.wb
.swt
.ResourceManager
;
41 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
42 import eu
.etaxonomy
.cdm
.api
.conversation
.IConversationEnabled
;
43 import eu
.etaxonomy
.cdm
.ext
.occurrence
.OccurenceQuery
;
44 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
45 import eu
.etaxonomy
.cdm
.persistence
.hibernate
.CdmDataChangeMap
;
46 import eu
.etaxonomy
.taxeditor
.databaseAdmin
.wizard
.ImportPreferencesWizard
;
47 import eu
.etaxonomy
.taxeditor
.model
.IContextListener
;
48 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasDetails
;
49 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasFactualData
;
50 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasSupplementalData
;
51 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
52 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
.SelectionDialogFactory
;
55 * View which shows a list of "data" that can be imported into the CDM
59 * @param <T> the CDM type that will be handled by this view
61 public abstract class DataImportViewE4
<T
> implements IPartContentHasFactualData
,
62 IConversationEnabled
, IPartContentHasDetails
, IPartContentHasSupplementalData
, IContextListener
, Listener
{
64 protected final Logger logger
= Logger
.getLogger(DataImportViewE4
.class);
66 protected Collection
<T
> results
= new ArrayList
<T
>();
68 protected boolean updated
= false;
70 protected OccurenceQuery query
;
72 private static ConversationHolder conversationHolder
;
74 private SaveImportedSpecimenActionE4 saveImportedSpecimenAction
;
76 private Text textClassification
;
78 private Classification classification
;
80 private Text textReferenceString
;
82 private Button toggleButton
;
84 private Button importButton
;
86 private boolean state
;
88 private Button openConfigurator
;
90 public Classification
getClassification() {
91 return classification
;
94 public void setClassification(Classification classification
) {
95 this.classification
= classification
;
98 private Button btnBrowseClassification
;
100 private Button btnClear
;
102 private final FormToolkit toolkit
= new FormToolkit(Display
.getCurrent());
105 private Composite composite_3
;
108 * Constructs a new DataImportEditor and registers it to listen to context changes
110 public DataImportViewE4() {
111 CdmStore
.getContextManager().addContextListener(this);
115 * Create contents of the view part.
119 public void createPartControl(Composite parent
) {
120 if(CdmStore
.isActive()){
126 parent
.setLayout(new GridLayout(1, false));
127 Composite composite
= new Composite(parent
, SWT
.NONE
);
128 composite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 1, 1));
129 // composite.setBounds(0, 0, 0, 298);
130 composite
.setLayout(new GridLayout(2, false));
132 Composite composite_1
= new Composite(composite
, SWT
.NONE
);
133 // gd_composite_1.widthHint = 280;
134 composite_1
.setLayoutData(new GridData(SWT
.FILL
, SWT
.TOP
, false, false, 1, 1));
135 composite_1
.setLayout(new GridLayout(3, false));
137 Label label
= new Label(composite_1
, SWT
.TOP
);
138 label
.setText("Classification");
139 label
.setLayoutData(new GridData(SWT
.LEFT
, SWT
.CENTER
, false, false, 3, 1));
140 textClassification
= new Text(composite_1
, SWT
.BORDER
);
141 textClassification
.setEnabled(false);
142 GridData gd_textClassification
= new GridData(SWT
.LEFT
, SWT
.CENTER
, false, false, 1, 1);
143 // gd_textClassification.widthHint = 118;
144 textClassification
.setLayoutData(new GridData(SWT
.FILL
, SWT
.LEFT
, true, true));
145 btnBrowseClassification
= new Button(composite_1
, SWT
.NONE
);
146 btnBrowseClassification
.setImage(ResourceManager
.getPluginImage("eu.etaxonomy.taxeditor.store", "icons/open.gif"));
147 btnBrowseClassification
.addListener(SWT
.Selection
, this);
148 btnClear
= new Button(composite_1
, SWT
.NONE
);
149 btnClear
.setImage(ResourceManager
.getPluginImage("eu.etaxonomy.taxeditor.store", "icons/trash.gif"));
150 btnClear
.addListener(SWT
.Selection
, this);
153 Label labelRef
= new Label(composite_1
, SWT
.NONE
);
154 labelRef
.setText("Default import souce reference");
155 labelRef
.setLayoutData(new GridData(SWT
.LEFT
, SWT
.CENTER
, false, false, 3, 1));
156 textReferenceString
= new Text(composite_1
, SWT
.NONE
);
157 textReferenceString
.setEnabled(true);
158 GridData gd_textReferenceString
= new GridData(SWT
.LEFT
, SWT
.CENTER
, true, true, 3, 1);
159 gd_textReferenceString
.widthHint
= 229;
160 textReferenceString
.setLayoutData(gd_textReferenceString
);
163 openConfigurator
= new Button(composite_1
, SWT
.PUSH
);
164 openConfigurator
.setText("Configuration");
165 new Label(composite_1
, SWT
.NONE
);
166 new Label(composite_1
, SWT
.NONE
);
167 openConfigurator
.addSelectionListener(new SelectionAdapter(){
169 public void widgetSelected(SelectionEvent e
) {
171 IWizard wizard
= new ImportPreferencesWizard();
172 WizardDialog dialog
= new WizardDialog(e
.display
.getActiveShell(), wizard
);
177 //checkbox table for result
178 Composite composite_2
= new Composite(composite
, SWT
.NONE
);
179 composite_2
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 1, 1));
180 composite_2
.setLayout(new GridLayout(2, false));
183 CheckboxTableViewer checkboxTableViewer
= CheckboxTableViewer
.newCheckList(composite_2
, SWT
.BORDER
| SWT
.FULL_SELECTION
);
186 table
= checkboxTableViewer
.getTable();
187 table
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 1, 1));
188 toolkit
.paintBordersFor(table
);
190 composite_3
= new Composite(composite_2
, SWT
.NONE
);
191 // gd_composite_3.heightHint = 48;
192 composite_3
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, false, false, 1, 1));
193 toolkit
.paintBordersFor(composite_3
);
194 composite_3
.setLayout(new GridLayout(1, false));
196 toggleButton
= new Button(composite_3
, SWT
.PUSH
);
197 toggleButton
.setText("Toggle");
198 new Label(composite_2
, SWT
.NONE
);
200 Composite composite_4
= new Composite(composite_2
, SWT
.NONE
);
201 composite_4
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, false, false, 1, 1));
202 toolkit
.adapt(composite_4
);
203 toolkit
.paintBordersFor(composite_4
);
205 importButton
= new Button(composite_4
, SWT
.PUSH
);
206 importButton
.setSize(48, 25);
207 importButton
.setText("Import");
208 importButton
.addSelectionListener(new SelectionAdapter(){
210 public void widgetSelected(SelectionEvent e
) {
211 saveImportedSpecimenAction
.run();
214 new Label(composite_2
, SWT
.NONE
);
215 new Label(composite_2
, SWT
.NONE
);
216 new Label(composite_2
, SWT
.NONE
);
217 new Label(composite_2
, SWT
.NONE
);
218 new Label(composite_2
, SWT
.NONE
);
219 new Label(composite_2
, SWT
.NONE
);
220 toggleButton
.addSelectionListener(new SelectionAdapter(){
222 public void widgetSelected(SelectionEvent e
) {
223 state
= state ?
false : true;
224 for (TableItem item
: getTable().getItems()){
225 item
.setChecked(state
);
231 saveImportedSpecimenAction
= new SaveImportedSpecimenActionE4(this);
236 * Initialize the toolbar.
238 private void initializeToolBar() {
240 // IToolBarManager tbm = getViewSite().getActionBars().getToolBarManager();
241 // tbm.add(saveImportedSpecimenAction);
244 public Table
getTable() {
248 public void setQuery(OccurenceQuery query
) {
252 public void setResults(Collection
<T
> results
) {
253 this.results
= results
;
258 public void dispose() {
259 CdmStore
.getContextManager().removeContextListener(this);
263 public void contextRefresh(IProgressMonitor monitor
) {
267 protected void refresh(){
269 if (getTable() != null){
270 getTable().removeAll();
274 TableItem tableItem
= new TableItem(getTable(), SWT
.NONE
);
275 tableItem
.setText(getTextForTableItem(item
));
276 tableItem
.setData(item
);
283 public abstract void query();
286 public void update(CdmDataChangeMap changeEvents
) {
291 * Returns the text label of the given item.
292 * @param item the item for which the label should be returns
293 * @return the label of the item
295 protected abstract String
getTextForTableItem(T item
);
298 public void setFocus() {
299 if(getTable()!=null){
300 getTable().setFocus();
302 //make sure to bind again if maybe in another view the conversation was unbound
303 if(getConversationHolder()!=null && !getConversationHolder().isBound()){
304 getConversationHolder().bind();
309 public void contextAboutToStop(IMemento memento
, IProgressMonitor monitor
) {
313 public void contextStop(IMemento memento
, IProgressMonitor monitor
) {
317 public void contextStart(IMemento memento
, IProgressMonitor monitor
) {
321 private void initConversation(){
322 if(conversationHolder
==null){
323 conversationHolder
= CdmStore
.createConversation();
328 public void workbenchShutdown(IMemento memento
, IProgressMonitor monitor
) {
329 if(getConversationHolder()!=null && getConversationHolder().isBound() && !getConversationHolder().isClosed()) {
330 getConversationHolder().close();
335 * @return the conversationHolder
338 public ConversationHolder
getConversationHolder() {
339 if(CdmStore
.isActive() && conversationHolder
==null){
342 return conversationHolder
;
346 public void handleEvent(Event event
) {
347 if(event
.widget
==btnBrowseClassification
){
348 classification
= SelectionDialogFactory
.getSelectionFromDialog(Classification
.class, event
.widget
.getDisplay().getActiveShell(), null, null);
349 if(classification
!=null){
350 textClassification
.setText(classification
.getTitleCache());
353 else if(event
.widget
==btnClear
){
354 classification
= null;
355 textClassification
.setText("");
359 public String
getReferenceString() {
360 return textReferenceString
.getText();