3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
11 package eu
.etaxonomy
.taxeditor
.io
.wizard
;
13 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
14 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
15 import org
.eclipse
.jface
.wizard
.IWizardContainer
;
16 import org
.eclipse
.jface
.wizard
.Wizard
;
17 import org
.eclipse
.jface
.wizard
.WizardDialog
;
18 import org
.eclipse
.swt
.SWT
;
19 import org
.eclipse
.ui
.IEditorPart
;
20 import org
.eclipse
.ui
.IEditorReference
;
21 import org
.eclipse
.ui
.IImportWizard
;
22 import org
.eclipse
.ui
.IWorkbench
;
23 import org
.eclipse
.ui
.IWorkbenchPage
;
25 import eu
.etaxonomy
.cdm
.io
.common
.IImportConfigurator
;
26 import eu
.etaxonomy
.cdm
.io
.common
.IIoConfigurator
;
29 * <p>Abstract AbstractImportWizard class.</p>
35 public abstract class AbstractImportWizard
<CONFIG
extends IIoConfigurator
> extends Wizard
implements IImportWizard
{
37 protected final String CONFIGURATION_PAGE
= "CONFIGURATION_PAGE";
39 private GenericConfiguratorWizardPage pageConfiguration
;
40 private NomenclaturalCodeWizardPage pageNomenclaturalCode
;
42 private IWorkbench workbench
;
44 private IStructuredSelection selection
;
48 * @see org.eclipse.jface.wizard.Wizard#addPages()
52 public void addPages() {
55 pageConfiguration
= GenericConfiguratorWizardPage
.Import(CONFIGURATION_PAGE
, getConfigurator());
56 this.addPage(pageConfiguration
);
58 pageNomenclaturalCode
= new NomenclaturalCodeWizardPage((IImportConfigurator
)getConfigurator());
59 this.addPage(pageNomenclaturalCode
);
65 * @see org.eclipse.jface.wizard.Wizard#setContainer(org.eclipse.jface.wizard.IWizardContainer)
68 public void setContainer(IWizardContainer wizardContainer
) {
69 super.setContainer(wizardContainer
);
70 checkForUnsavedEditors();
74 * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
77 public void init(IWorkbench workbench
, IStructuredSelection selection
) {
78 this.setWorkbench(workbench
);
79 this.setSelection(selection
);
82 protected void checkForUnsavedEditors(){
83 IWorkbenchPage activePage
= getWorkbench().getActiveWorkbenchWindow().getActivePage();
85 if(activePage
!= null){
86 for (IEditorReference reference
: activePage
.getEditorReferences()) {
87 IEditorPart editor
= reference
.getEditor(false);
90 MessageDialog
.open(MessageDialog
.WARNING
, getShell(), "Unsaved editors", "Please save all open editors before executing " +
91 "an import operation. The import operation will be cancelled", SWT
.NONE
);
94 if(getContainer() instanceof WizardDialog
){
95 ((WizardDialog
)getContainer()).close();
104 * <p>getConfigurator</p>
106 * @return a CONFIG object.
108 public abstract CONFIG
getConfigurator();
111 * @param selection the selection to set
113 public void setSelection(IStructuredSelection selection
) {
114 this.selection
= selection
;
118 * @return the selection
120 public IStructuredSelection
getSelection() {
125 * @param workbench the workbench to set
127 public void setWorkbench(IWorkbench workbench
) {
128 this.workbench
= workbench
;
132 * @return the workbench
134 public IWorkbench
getWorkbench() {