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