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.jface.wizard.WizardDialog;
|
18
|
import org.eclipse.swt.SWT;
|
19
|
import org.eclipse.ui.IEditorPart;
|
20
|
import org.eclipse.ui.IEditorReference;
|
21
|
import org.eclipse.ui.IImportWizard;
|
22
|
import org.eclipse.ui.IWorkbench;
|
23
|
import org.eclipse.ui.IWorkbenchPage;
|
24
|
|
25
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator;
|
26
|
import eu.etaxonomy.cdm.io.common.IIoConfigurator;
|
27
|
|
28
|
/**
|
29
|
* <p>Abstract AbstractImportWizard class.</p>
|
30
|
*
|
31
|
* @author n.hoffmann
|
32
|
* @created 24.06.2009
|
33
|
* @version 1.0
|
34
|
*/
|
35
|
public abstract class AbstractImportWizard<CONFIG extends IIoConfigurator> extends Wizard implements IImportWizard {
|
36
|
|
37
|
protected final String CONFIGURATION_PAGE = "CONFIGURATION_PAGE";
|
38
|
|
39
|
private GenericConfiguratorWizardPage pageConfiguration;
|
40
|
private NomenclaturalCodeWizardPage pageNomenclaturalCode;
|
41
|
|
42
|
private IWorkbench workbench;
|
43
|
|
44
|
private IStructuredSelection selection;
|
45
|
|
46
|
|
47
|
/* (non-Javadoc)
|
48
|
* @see org.eclipse.jface.wizard.Wizard#addPages()
|
49
|
*/
|
50
|
/** {@inheritDoc} */
|
51
|
@Override
|
52
|
public void addPages() {
|
53
|
super.addPages();
|
54
|
|
55
|
pageConfiguration = GenericConfiguratorWizardPage.Import(CONFIGURATION_PAGE, getConfigurator());
|
56
|
this.addPage(pageConfiguration);
|
57
|
|
58
|
pageNomenclaturalCode = new NomenclaturalCodeWizardPage((IImportConfigurator)getConfigurator());
|
59
|
this.addPage(pageNomenclaturalCode);
|
60
|
|
61
|
|
62
|
}
|
63
|
|
64
|
/* (non-Javadoc)
|
65
|
* @see org.eclipse.jface.wizard.Wizard#setContainer(org.eclipse.jface.wizard.IWizardContainer)
|
66
|
*/
|
67
|
@Override
|
68
|
public void setContainer(IWizardContainer wizardContainer) {
|
69
|
super.setContainer(wizardContainer);
|
70
|
checkForUnsavedEditors();
|
71
|
}
|
72
|
|
73
|
/* (non-Javadoc)
|
74
|
* @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
|
75
|
*/
|
76
|
@Override
|
77
|
public void init(IWorkbench workbench, IStructuredSelection selection) {
|
78
|
this.setWorkbench(workbench);
|
79
|
this.setSelection(selection);
|
80
|
}
|
81
|
|
82
|
protected void checkForUnsavedEditors(){
|
83
|
IWorkbenchPage activePage = getWorkbench().getActiveWorkbenchWindow().getActivePage();
|
84
|
|
85
|
if(activePage != null){
|
86
|
for (IEditorReference reference : activePage.getEditorReferences()) {
|
87
|
IEditorPart editor = reference.getEditor(false);
|
88
|
if(editor.isDirty()){
|
89
|
|
90
|
MessageDialog.open(MessageDialog.WARNING, getShell(), "Unsaved editors", "Please save all open editors before executing " +
|
91
|
"an import operation. The import operation will be cancelled", SWT.NONE);
|
92
|
|
93
|
performCancel();
|
94
|
if(getContainer() instanceof WizardDialog){
|
95
|
((WizardDialog)getContainer()).close();
|
96
|
}
|
97
|
|
98
|
}
|
99
|
}
|
100
|
}
|
101
|
}
|
102
|
|
103
|
/**
|
104
|
* <p>getConfigurator</p>
|
105
|
*
|
106
|
* @return a CONFIG object.
|
107
|
*/
|
108
|
public abstract CONFIG getConfigurator();
|
109
|
|
110
|
/**
|
111
|
* @param selection the selection to set
|
112
|
*/
|
113
|
public void setSelection(IStructuredSelection selection) {
|
114
|
this.selection = selection;
|
115
|
}
|
116
|
|
117
|
/**
|
118
|
* @return the selection
|
119
|
*/
|
120
|
public IStructuredSelection getSelection() {
|
121
|
return selection;
|
122
|
}
|
123
|
|
124
|
/**
|
125
|
* @param workbench the workbench to set
|
126
|
*/
|
127
|
public void setWorkbench(IWorkbench workbench) {
|
128
|
this.workbench = workbench;
|
129
|
}
|
130
|
|
131
|
/**
|
132
|
* @return the workbench
|
133
|
*/
|
134
|
public IWorkbench getWorkbench() {
|
135
|
return workbench;
|
136
|
}
|
137
|
}
|