1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2007 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
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.
|
9
|
*/
|
10
|
|
11
|
package eu.etaxonomy.taxeditor.io.wizard;
|
12
|
|
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;
|
23
|
|
24
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator;
|
25
|
import eu.etaxonomy.cdm.io.common.IIoConfigurator;
|
26
|
|
27
|
/**
|
28
|
* @author n.hoffmann
|
29
|
* @created 24.06.2009
|
30
|
* @version 1.0
|
31
|
*/
|
32
|
public abstract class AbstractImportWizard<CONFIG extends IIoConfigurator> extends Wizard implements IImportWizard {
|
33
|
|
34
|
protected final String CONFIGURATION_PAGE = "CONFIGURATION_PAGE";
|
35
|
|
36
|
private GenericConfiguratorWizardPage pageConfiguration;
|
37
|
private NomenclaturalCodeWizardPage pageNomenclaturalCode;
|
38
|
|
39
|
private IWorkbench workbench;
|
40
|
|
41
|
private IStructuredSelection selection;
|
42
|
|
43
|
/** {@inheritDoc} */
|
44
|
@Override
|
45
|
public void addPages() {
|
46
|
super.addPages();
|
47
|
|
48
|
pageConfiguration = GenericConfiguratorWizardPage.Import(CONFIGURATION_PAGE, getConfigurator());
|
49
|
this.addPage(pageConfiguration);
|
50
|
|
51
|
pageNomenclaturalCode = new NomenclaturalCodeWizardPage((IImportConfigurator)getConfigurator());
|
52
|
this.addPage(pageNomenclaturalCode);
|
53
|
|
54
|
|
55
|
}
|
56
|
|
57
|
@Override
|
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);
|
62
|
}
|
63
|
else{
|
64
|
super.setContainer(wizardContainer);
|
65
|
}
|
66
|
}
|
67
|
|
68
|
@Override
|
69
|
public void init(IWorkbench workbench, IStructuredSelection selection) {
|
70
|
this.setWorkbench(workbench);
|
71
|
this.setSelection(selection);
|
72
|
}
|
73
|
|
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);
|
79
|
if(editor.isDirty()){
|
80
|
return true;
|
81
|
}
|
82
|
}
|
83
|
}
|
84
|
return false;
|
85
|
}
|
86
|
|
87
|
@Override
|
88
|
public boolean canFinish() {
|
89
|
return !existUnsavedEditors() && super.canFinish();
|
90
|
}
|
91
|
|
92
|
public abstract CONFIG getConfigurator();
|
93
|
|
94
|
public void setSelection(IStructuredSelection selection) {
|
95
|
this.selection = selection;
|
96
|
}
|
97
|
|
98
|
public IStructuredSelection getSelection() {
|
99
|
return selection;
|
100
|
}
|
101
|
|
102
|
public void setWorkbench(IWorkbench workbench) {
|
103
|
this.workbench = workbench;
|
104
|
}
|
105
|
|
106
|
public IWorkbench getWorkbench() {
|
107
|
return workbench;
|
108
|
}
|
109
|
}
|