2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.io
.wizard
;
12 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
13 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
14 import org
.eclipse
.jface
.wizard
.IWizardContainer
;
15 import org
.eclipse
.jface
.wizard
.Wizard
;
16 import org
.eclipse
.swt
.SWT
;
17 import org
.eclipse
.ui
.IEditorPart
;
18 import org
.eclipse
.ui
.IEditorReference
;
19 import org
.eclipse
.ui
.IImportWizard
;
20 import org
.eclipse
.ui
.IWorkbench
;
21 import org
.eclipse
.ui
.IWorkbenchPage
;
23 import eu
.etaxonomy
.cdm
.io
.common
.IImportConfigurator
;
24 import eu
.etaxonomy
.cdm
.io
.common
.IIoConfigurator
;
25 import eu
.etaxonomy
.taxeditor
.l10n
.Messages
;
32 public abstract class AbstractImportWizard
<CONFIG
extends IIoConfigurator
> extends Wizard
implements IImportWizard
{
34 protected final String CONFIGURATION_PAGE
= "CONFIGURATION_PAGE";
36 protected GenericConfiguratorWizardPage pageConfiguration
;
37 private NomenclaturalCodeWizardPage pageNomenclaturalCode
;
39 private IWorkbench workbench
;
41 private IStructuredSelection selection
;
45 public void addPages() {
48 addConfiguratorPage();
50 pageNomenclaturalCode
= new NomenclaturalCodeWizardPage((IImportConfigurator
)getConfigurator());
51 this.addPage(pageNomenclaturalCode
);
54 protected void addConfiguratorPage(){
55 pageConfiguration
= GenericConfiguratorWizardPage
.Import(CONFIGURATION_PAGE
, getConfigurator(), null, Messages
.AbstractImportWizard_ConfigurationLabel
);
56 this.addPage(pageConfiguration
);
60 public void setContainer(IWizardContainer wizardContainer
) {
61 if(existUnsavedEditors()){
62 MessageDialog
.open(MessageDialog
.WARNING
, getShell(), "Unsaved editors", "Please save all open editors before executing " +
63 "an import operation. The import operation will be cancelled", SWT
.NONE
);
66 super.setContainer(wizardContainer
);
71 public void init(IWorkbench workbench
, IStructuredSelection selection
) {
72 this.setWorkbench(workbench
);
73 this.setSelection(selection
);
76 protected boolean existUnsavedEditors(){
77 IWorkbenchPage activePage
= getWorkbench().getActiveWorkbenchWindow().getActivePage();
78 if(activePage
!= null){
79 for (IEditorReference reference
: activePage
.getEditorReferences()) {
80 IEditorPart editor
= reference
.getEditor(false);
90 public boolean canFinish() {
91 return !existUnsavedEditors() && super.canFinish();
94 public abstract CONFIG
getConfigurator();
96 public void setSelection(IStructuredSelection selection
) {
97 this.selection
= selection
;
100 public IStructuredSelection
getSelection() {
104 public void setWorkbench(IWorkbench workbench
) {
105 this.workbench
= workbench
;
108 public IWorkbench
getWorkbench() {