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
;
28 * <p>Abstract AbstractImportWizard class.</p>
34 public abstract class AbstractImportWizard
<CONFIG
extends IIoConfigurator
> extends Wizard
implements IImportWizard
{
36 protected final String CONFIGURATION_PAGE
= "CONFIGURATION_PAGE";
38 private GenericConfiguratorWizardPage pageConfiguration
;
39 private NomenclaturalCodeWizardPage pageNomenclaturalCode
;
41 private IWorkbench workbench
;
43 private IStructuredSelection selection
;
47 * @see org.eclipse.jface.wizard.Wizard#addPages()
51 public void addPages() {
54 pageConfiguration
= GenericConfiguratorWizardPage
.Import(CONFIGURATION_PAGE
, getConfigurator());
55 this.addPage(pageConfiguration
);
57 pageNomenclaturalCode
= new NomenclaturalCodeWizardPage((IImportConfigurator
)getConfigurator());
58 this.addPage(pageNomenclaturalCode
);
64 * @see org.eclipse.jface.wizard.Wizard#setContainer(org.eclipse.jface.wizard.IWizardContainer)
67 public void setContainer(IWizardContainer wizardContainer
) {
68 if(existUnsavedEditors()){
69 MessageDialog
.open(MessageDialog
.WARNING
, getShell(), "Unsaved editors", "Please save all open editors before executing " +
70 "an import operation. The import operation will be cancelled", SWT
.NONE
);
73 super.setContainer(wizardContainer
);
78 * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
81 public void init(IWorkbench workbench
, IStructuredSelection selection
) {
82 this.setWorkbench(workbench
);
83 this.setSelection(selection
);
86 protected boolean existUnsavedEditors(){
87 IWorkbenchPage activePage
= getWorkbench().getActiveWorkbenchWindow().getActivePage();
88 if(activePage
!= null){
89 for (IEditorReference reference
: activePage
.getEditorReferences()) {
90 IEditorPart editor
= reference
.getEditor(false);
100 * @see org.eclipse.jface.wizard.Wizard#canFinish()
103 public boolean canFinish() {
104 return !existUnsavedEditors();
108 * <p>getConfigurator</p>
110 * @return a CONFIG object.
112 public abstract CONFIG
getConfigurator();
115 * @param selection the selection to set
117 public void setSelection(IStructuredSelection selection
) {
118 this.selection
= selection
;
122 * @return the selection
124 public IStructuredSelection
getSelection() {
129 * @param workbench the workbench to set
131 public void setWorkbench(IWorkbench workbench
) {
132 this.workbench
= workbench
;
136 * @return the workbench
138 public IWorkbench
getWorkbench() {