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
;
31 public abstract class AbstractImportWizard
<CONFIG
extends IIoConfigurator
> extends Wizard
implements IImportWizard
{
33 protected final String CONFIGURATION_PAGE
= "CONFIGURATION_PAGE";
35 private GenericConfiguratorWizardPage pageConfiguration
;
36 private NomenclaturalCodeWizardPage pageNomenclaturalCode
;
38 private IWorkbench workbench
;
40 private IStructuredSelection selection
;
44 public void addPages() {
47 addConfiguratorPage();
49 pageNomenclaturalCode
= new NomenclaturalCodeWizardPage((IImportConfigurator
)getConfigurator());
50 this.addPage(pageNomenclaturalCode
);
53 protected void addConfiguratorPage(){
54 pageConfiguration
= GenericConfiguratorWizardPage
.Import(CONFIGURATION_PAGE
, getConfigurator());
55 this.addPage(pageConfiguration
);
59 public void setContainer(IWizardContainer wizardContainer
) {
60 if(existUnsavedEditors()){
61 MessageDialog
.open(MessageDialog
.WARNING
, getShell(), "Unsaved editors", "Please save all open editors before executing " +
62 "an import operation. The import operation will be cancelled", SWT
.NONE
);
65 super.setContainer(wizardContainer
);
70 public void init(IWorkbench workbench
, IStructuredSelection selection
) {
71 this.setWorkbench(workbench
);
72 this.setSelection(selection
);
75 protected boolean existUnsavedEditors(){
76 IWorkbenchPage activePage
= getWorkbench().getActiveWorkbenchWindow().getActivePage();
77 if(activePage
!= null){
78 for (IEditorReference reference
: activePage
.getEditorReferences()) {
79 IEditorPart editor
= reference
.getEditor(false);
89 public boolean canFinish() {
90 return !existUnsavedEditors() && super.canFinish();
93 public abstract CONFIG
getConfigurator();
95 public void setSelection(IStructuredSelection selection
) {
96 this.selection
= selection
;
99 public IStructuredSelection
getSelection() {
103 public void setWorkbench(IWorkbench workbench
) {
104 this.workbench
= workbench
;
107 public IWorkbench
getWorkbench() {