1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
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.
|
8
|
*/
|
9
|
package eu.etaxonomy.taxeditor.io.e4.in;
|
10
|
|
11
|
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
|
12
|
import org.eclipse.e4.core.contexts.IEclipseContext;
|
13
|
import org.eclipse.e4.ui.workbench.modeling.EPartService;
|
14
|
import org.eclipse.jface.dialogs.MessageDialog;
|
15
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
16
|
import org.eclipse.jface.wizard.IWizardContainer;
|
17
|
import org.eclipse.jface.wizard.Wizard;
|
18
|
import org.eclipse.swt.SWT;
|
19
|
|
20
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator;
|
21
|
import eu.etaxonomy.cdm.io.common.IIoConfigurator;
|
22
|
import eu.etaxonomy.taxeditor.l10n.Messages;
|
23
|
|
24
|
/**
|
25
|
* @author pplitzner
|
26
|
* @since Oct 5, 2017
|
27
|
*
|
28
|
* @param <CONFIG>
|
29
|
*/
|
30
|
public abstract class AbstractImportWizard<CONFIG extends IIoConfigurator> extends Wizard {
|
31
|
|
32
|
protected GenericConfiguratorWizardPageE4 pageConfiguration;
|
33
|
private NomenclaturalCodeWizardPageE4 pageNomenclaturalCode;
|
34
|
|
35
|
protected IStructuredSelection selection;
|
36
|
|
37
|
protected IEclipseContext context;
|
38
|
|
39
|
private EPartService partService;
|
40
|
|
41
|
public AbstractImportWizard(IEclipseContext context, EPartService partService) {
|
42
|
this(context, partService, null);
|
43
|
}
|
44
|
|
45
|
public AbstractImportWizard(IEclipseContext context, EPartService partService, IStructuredSelection selection) {
|
46
|
this.context = context;
|
47
|
this.partService = partService;
|
48
|
this.selection = selection;
|
49
|
}
|
50
|
|
51
|
@Override
|
52
|
public void addPages() {
|
53
|
super.addPages();
|
54
|
|
55
|
addConfiguratorPage();
|
56
|
|
57
|
pageNomenclaturalCode = ContextInjectionFactory.make(NomenclaturalCodeWizardPageE4.class, context);
|
58
|
pageNomenclaturalCode.setConfigurator((IImportConfigurator)getConfigurator());
|
59
|
this.addPage(pageNomenclaturalCode);
|
60
|
}
|
61
|
|
62
|
protected void addConfiguratorPage(){
|
63
|
pageConfiguration = ContextInjectionFactory.make(GenericConfiguratorWizardPageE4.class, context);
|
64
|
pageConfiguration.initImport(getConfigurator(), null, Messages.AbstractImportWizard_ConfigurationLabel);
|
65
|
this.addPage(pageConfiguration);
|
66
|
}
|
67
|
|
68
|
@Override
|
69
|
public void setContainer(IWizardContainer wizardContainer) {
|
70
|
if(existUnsavedEditors() && wizardContainer!=null){
|
71
|
MessageDialog.open(MessageDialog.WARNING, getShell(), "Unsaved editors", "Please save all open editors before executing " +
|
72
|
"an import operation. The import operation will be cancelled", SWT.NONE);
|
73
|
}
|
74
|
else{
|
75
|
super.setContainer(wizardContainer);
|
76
|
}
|
77
|
}
|
78
|
|
79
|
public abstract void init();
|
80
|
|
81
|
protected boolean existUnsavedEditors(){
|
82
|
return !partService.getDirtyParts().isEmpty();
|
83
|
}
|
84
|
|
85
|
@Override
|
86
|
public boolean canFinish() {
|
87
|
return !existUnsavedEditors() && super.canFinish();
|
88
|
}
|
89
|
|
90
|
public abstract CONFIG getConfigurator();
|
91
|
|
92
|
public void setSelection(IStructuredSelection selection) {
|
93
|
this.selection = selection;
|
94
|
}
|
95
|
|
96
|
public IStructuredSelection getSelection() {
|
97
|
return selection;
|
98
|
}
|
99
|
}
|