Project

General

Profile

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