Project

General

Profile

Download (5.53 KB) Statistics
| Branch: | Tag: | Revision:
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.ui.selection;
12

    
13
import org.eclipse.core.runtime.IStatus;
14
import org.eclipse.jface.wizard.Wizard;
15
import org.eclipse.jface.wizard.WizardDialog;
16
import org.eclipse.swt.events.SelectionEvent;
17
import org.eclipse.swt.events.SelectionListener;
18

    
19
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
20
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeNotSupportedException;
21
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
22
import eu.etaxonomy.cdm.model.agent.Institution;
23
import eu.etaxonomy.cdm.model.agent.Person;
24
import eu.etaxonomy.cdm.model.agent.Team;
25
import eu.etaxonomy.cdm.model.common.ICdmBase;
26
import eu.etaxonomy.cdm.model.common.User;
27
import eu.etaxonomy.cdm.model.name.NonViralName;
28
import eu.etaxonomy.cdm.model.occurrence.Collection;
29
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
30
import eu.etaxonomy.cdm.model.reference.Reference;
31
import eu.etaxonomy.taxeditor.model.TextHelper;
32
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
33
import eu.etaxonomy.taxeditor.store.StoreUtil;
34
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
35
import eu.etaxonomy.taxeditor.ui.section.agent.InstitutionWizardPage;
36
import eu.etaxonomy.taxeditor.ui.section.agent.PersonWizardPage;
37
import eu.etaxonomy.taxeditor.ui.section.agent.TeamWizardPage;
38
import eu.etaxonomy.taxeditor.ui.section.name.NonViralNameWizardPage;
39
import eu.etaxonomy.taxeditor.ui.section.occurrence.CollectionWizardPage;
40
import eu.etaxonomy.taxeditor.ui.section.occurrence.DerivedUnitBaseWizardPage;
41
import eu.etaxonomy.taxeditor.ui.section.occurrence.FieldUnitWizardPage;
42
import eu.etaxonomy.taxeditor.ui.section.occurrence.GatheringEventWizardPage;
43
import eu.etaxonomy.taxeditor.ui.section.occurrence.GeneralWizardPage;
44
import eu.etaxonomy.taxeditor.ui.section.reference.ReferenceWizardPage;
45
import eu.etaxonomy.taxeditor.ui.section.user.UserDetailWizardPage;
46

    
47
/**
48
 * <p>
49
 * EditFromSelectionWizard class.
50
 * </p>
51
 * 
52
 * @author n.hoffmann
53
 * @created Jun 1, 2010
54
 * @version 1.0
55
 */
56
public class EditFromSelectionWizard extends Wizard implements
57
		SelectionListener {
58

    
59
	private final EntitySelectionElement selectionElement;
60

    
61
	/**
62
	 * <p>
63
	 * Constructor for EditFromSelectionWizard.
64
	 * </p>
65
	 * 
66
	 * @param selectionElement
67
	 *            a
68
	 *            {@link eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement}
69
	 *            object.
70
	 */
71
	public EditFromSelectionWizard(EntitySelectionElement selectionElement) {
72
		this.selectionElement = selectionElement;
73
		this.setWindowTitle(String.format("Edit %s", TextHelper.deproxyClassName(selectionElement.getEntity().getClass())));
74
	}
75

    
76
	/** {@inheritDoc} */
77
	@Override
78
	public void addPages() {
79

    
80
		CdmFormFactory formFactory = selectionElement.getFormFactory();
81
		ICdmBase entity = (ICdmBase) HibernateProxyHelper
82
				.deproxy(selectionElement.getEntity());
83

    
84
		if (entity instanceof Reference) {
85
			addPage(new ReferenceWizardPage(formFactory,
86
					selectionElement.getConversationHolder(),
87
					(Reference) entity));
88
		} else if (entity instanceof Team) {
89
			addPage(new TeamWizardPage(formFactory,
90
					selectionElement.getConversationHolder(), (Team) entity));
91
		} else if (entity instanceof Person) {
92
			addPage(new PersonWizardPage(formFactory,
93
					selectionElement.getConversationHolder(), (Person) entity));
94
		} else if (entity instanceof NonViralName) {
95
			addPage(new NonViralNameWizardPage(formFactory,
96
					selectionElement.getConversationHolder(),
97
					(NonViralName) entity));
98
		} else if (entity instanceof DerivedUnit) {
99

    
100
			DerivedUnitFacade facade;
101
			try {
102
				facade = DerivedUnitFacade.NewInstance(
103
						(DerivedUnit) entity,
104
						PreferencesUtil.getDerivedUnitConfigurator());
105
			} catch (DerivedUnitFacadeNotSupportedException e) {
106
				// we should never get here
107
				throw new IllegalStateException();
108
			}
109

    
110
			addPage(new GeneralWizardPage(formFactory,
111
					selectionElement.getConversationHolder(), facade));
112
			addPage(new GatheringEventWizardPage(formFactory,
113
					selectionElement.getConversationHolder(), facade));
114
			addPage(new FieldUnitWizardPage(formFactory,
115
					selectionElement.getConversationHolder(), facade));
116
			addPage(new DerivedUnitBaseWizardPage(formFactory,
117
					selectionElement.getConversationHolder(), facade));
118
		} else if (entity instanceof Collection) {
119
			addPage(new CollectionWizardPage(formFactory,
120
					selectionElement.getConversationHolder(),
121
					(Collection) entity));
122
		} else if (entity instanceof Institution) {
123
			addPage(new InstitutionWizardPage(formFactory,
124
					selectionElement.getConversationHolder(),
125
					(Institution) entity));
126
		} else if (entity instanceof User) {
127
			addPage(new UserDetailWizardPage(formFactory, 
128
					selectionElement.getConversationHolder(), 
129
					(User) entity));
130
		} else {
131
			StoreUtil.warningDialog("Missing interface", this,
132
					"No detail element for current selection");
133
		} 
134

    
135
	}
136

    
137
	/*
138
	 * (non-Javadoc)
139
	 * 
140
	 * @see org.eclipse.jface.wizard.Wizard#performFinish()
141
	 */
142
	/** {@inheritDoc} */
143
	@Override
144
	public boolean performFinish() {
145
		return true;
146
	}
147

    
148
	/** {@inheritDoc} */
149
	@Override
150
	public void widgetSelected(SelectionEvent e) {
151
		WizardDialog dialog = new WizardDialog(selectionElement.getShell(),
152
				this);
153
		if (dialog.open() == IStatus.OK) {
154
			selectionElement.updateFromWizard();
155
		}
156
	}
157

    
158
	/** {@inheritDoc} */
159
	@Override
160
	public void widgetDefaultSelected(SelectionEvent e) {
161
	}
162
}
(1-1/4)