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