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
.swt
.SWT
;
18 import org
.eclipse
.ui
.IEditorPart
;
19 import org
.eclipse
.ui
.IEditorReference
;
20 import org
.eclipse
.ui
.IImportWizard
;
21 import org
.eclipse
.ui
.IWorkbench
;
22 import org
.eclipse
.ui
.IWorkbenchPage
;
24 import eu
.etaxonomy
.cdm
.io
.common
.IImportConfigurator
;
25 import eu
.etaxonomy
.cdm
.io
.common
.IIoConfigurator
;
32 public abstract class AbstractImportWizard
<CONFIG
extends IIoConfigurator
> extends Wizard
implements IImportWizard
{
34 protected final String CONFIGURATION_PAGE
= "CONFIGURATION_PAGE";
36 private GenericConfiguratorWizardPage pageConfiguration
;
37 private NomenclaturalCodeWizardPage pageNomenclaturalCode
;
39 private IWorkbench workbench
;
41 private IStructuredSelection selection
;
45 public void addPages() {
48 pageConfiguration
= GenericConfiguratorWizardPage
.Import(CONFIGURATION_PAGE
, getConfigurator());
49 this.addPage(pageConfiguration
);
51 pageNomenclaturalCode
= new NomenclaturalCodeWizardPage((IImportConfigurator
)getConfigurator());
52 this.addPage(pageNomenclaturalCode
);
58 public void setContainer(IWizardContainer wizardContainer
) {
59 if(existUnsavedEditors()){
60 MessageDialog
.open(MessageDialog
.WARNING
, getShell(), "Unsaved editors", "Please save all open editors before executing " +
61 "an import operation. The import operation will be cancelled", SWT
.NONE
);
64 super.setContainer(wizardContainer
);
69 public void init(IWorkbench workbench
, IStructuredSelection selection
) {
70 this.setWorkbench(workbench
);
71 this.setSelection(selection
);
74 protected boolean existUnsavedEditors(){
75 IWorkbenchPage activePage
= getWorkbench().getActiveWorkbenchWindow().getActivePage();
76 if(activePage
!= null){
77 for (IEditorReference reference
: activePage
.getEditorReferences()) {
78 IEditorPart editor
= reference
.getEditor(false);
88 public boolean canFinish() {
89 return !existUnsavedEditors() && super.canFinish();
92 public abstract CONFIG
getConfigurator();
94 public void setSelection(IStructuredSelection selection
) {
95 this.selection
= selection
;
98 public IStructuredSelection
getSelection() {
102 public void setWorkbench(IWorkbench workbench
) {
103 this.workbench
= workbench
;
106 public IWorkbench
getWorkbench() {