Project

General

Profile

Download (3.1 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
import eu.etaxonomy.taxeditor.l10n.Messages;
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
	protected 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
		addConfiguratorPage();
49

    
50
		pageNomenclaturalCode = new NomenclaturalCodeWizardPage((IImportConfigurator)getConfigurator());
51
		this.addPage(pageNomenclaturalCode);
52
	}
53

    
54
	protected void addConfiguratorPage(){
55
		pageConfiguration = GenericConfiguratorWizardPage.Import(CONFIGURATION_PAGE, getConfigurator(), null, Messages.AbstractImportWizard_ConfigurationLabel);
56
		this.addPage(pageConfiguration);
57
	}
58

    
59
	@Override
60
	public void setContainer(IWizardContainer wizardContainer) {
61
		if(existUnsavedEditors()){
62
		    MessageDialog.open(MessageDialog.WARNING, getShell(), "Unsaved editors", "Please save all open editors before executing " +
63
		            "an import operation. The import operation will be cancelled", SWT.NONE);
64
		}
65
		else{
66
		    super.setContainer(wizardContainer);
67
		}
68
	}
69

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

    
76
	protected boolean existUnsavedEditors(){
77
		IWorkbenchPage activePage = getWorkbench().getActiveWorkbenchWindow().getActivePage();
78
		if(activePage != null){
79
			for (IEditorReference reference : activePage.getEditorReferences()) {
80
				IEditorPart editor = reference.getEditor(false);
81
				if (editor!= null){
82
					if(editor.isDirty()){
83
						return true;
84
					}
85
				}
86
			}
87
		}
88
		return false;
89
	}
90

    
91
	@Override
92
	public boolean canFinish() {
93
		return !existUnsavedEditors() && super.canFinish();
94
	}
95

    
96
	public abstract CONFIG getConfigurator();
97

    
98
	public void setSelection(IStructuredSelection selection) {
99
		this.selection = selection;
100
	}
101

    
102
	public IStructuredSelection getSelection() {
103
		return selection;
104
	}
105

    
106
	public void setWorkbench(IWorkbench workbench) {
107
		this.workbench = workbench;
108
	}
109

    
110
	public IWorkbench getWorkbench() {
111
		return workbench;
112
	}
113
}
(7-7/30)