Project

General

Profile

Download (2.98 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
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.
8
*/
9

    
10
package eu.etaxonomy.taxeditor.io.wizard;
11

    
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;
22

    
23
import eu.etaxonomy.cdm.io.common.IImportConfigurator;
24
import eu.etaxonomy.cdm.io.common.IIoConfigurator;
25

    
26
/**
27
 * @author n.hoffmann
28
 * @created 24.06.2009
29
 * @version 1.0
30
 */
31
public abstract class AbstractImportWizard<CONFIG extends IIoConfigurator> extends Wizard implements IImportWizard {
32

    
33
	protected final String CONFIGURATION_PAGE = "CONFIGURATION_PAGE";
34

    
35
	private GenericConfiguratorWizardPage pageConfiguration;
36
	private NomenclaturalCodeWizardPage pageNomenclaturalCode;
37

    
38
	private IWorkbench workbench;
39

    
40
	private IStructuredSelection selection;
41

    
42
	/** {@inheritDoc} */
43
	@Override
44
	public void addPages() {
45
		super.addPages();
46
		
47
		addConfiguratorPage();
48

    
49
		pageNomenclaturalCode = new NomenclaturalCodeWizardPage((IImportConfigurator)getConfigurator());
50
		this.addPage(pageNomenclaturalCode);
51
	}
52
	
53
	protected void addConfiguratorPage(){
54
		pageConfiguration = GenericConfiguratorWizardPage.Import(CONFIGURATION_PAGE, getConfigurator());
55
		this.addPage(pageConfiguration);
56
	}
57

    
58
	@Override
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);
63
		}
64
		else{
65
		    super.setContainer(wizardContainer);
66
		}
67
	}
68

    
69
	@Override
70
	public void init(IWorkbench workbench, IStructuredSelection selection) {
71
		this.setWorkbench(workbench);
72
		this.setSelection(selection);
73
	}
74

    
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);
80
				if(editor.isDirty()){
81
					return true;
82
				}
83
			}
84
		}
85
		return false;
86
	}
87

    
88
	@Override
89
	public boolean canFinish() {
90
	    return !existUnsavedEditors() && super.canFinish();
91
	}
92

    
93
	public abstract CONFIG getConfigurator();
94

    
95
	public void setSelection(IStructuredSelection selection) {
96
		this.selection = selection;
97
	}
98

    
99
	public IStructuredSelection getSelection() {
100
		return selection;
101
	}
102

    
103
	public void setWorkbench(IWorkbench workbench) {
104
		this.workbench = workbench;
105
	}
106

    
107
	public IWorkbench getWorkbench() {
108
		return workbench;
109
	}
110
}
(7-7/26)