(no commit message)
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / view / detail / CdmSectionPart.java
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.view.detail;
12
13 import org.eclipse.jface.util.IPropertyChangeListener;
14 import org.eclipse.jface.util.PropertyChangeEvent;
15 import org.eclipse.ui.IEditorPart;
16 import org.eclipse.ui.forms.SectionPart;
17
18 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
19 import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
20 import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
21 import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeNotSupportedException;
22 import eu.etaxonomy.cdm.model.occurrence.DerivedUnitBase;
23 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
24 import eu.etaxonomy.taxeditor.model.IElementHasDetails;
25 import eu.etaxonomy.taxeditor.model.PolytomousKeyRelationship;
26 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
27 import eu.etaxonomy.taxeditor.store.StoreUtil;
28 import eu.etaxonomy.taxeditor.ui.element.AbstractCdmFormElement;
29 import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
30 import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
31 import eu.etaxonomy.taxeditor.ui.section.ITaxonBaseDetailSection;
32 import eu.etaxonomy.taxeditor.ui.section.occurrence.IDerivedUnitFacadeDetailSection;
33
34 /**
35 * <p>
36 * CdmSectionPart class.
37 * </p>
38 *
39 * @author n.hoffmann
40 * @created Feb 8, 2010
41 * @version 1.0
42 */
43 public class CdmSectionPart<T> extends SectionPart implements
44 IPropertyChangeListener {
45
46 private final AbstractFormSection<T> formSection;
47
48 /**
49 * <p>
50 * Constructor for CdmSectionPart.
51 * </p>
52 *
53 * @param section
54 * a {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection}
55 * object.
56 * @param <T>
57 * a T object.
58 */
59 public CdmSectionPart(AbstractFormSection<T> section) {
60 super(section);
61 formSection = section;
62 }
63
64 /** {@inheritDoc} */
65 @Override
66 public boolean setFormInput(Object input) {
67 if (input instanceof IElementHasDetails) {
68 input = ((IElementHasDetails) input).getData();
69 }
70 if ((input instanceof TaxonBase)
71 && (formSection instanceof ITaxonBaseDetailSection)) {
72 ((ITaxonBaseDetailSection) formSection)
73 .setTaxonBase((TaxonBase) input);
74 return true;
75 }
76 if ((input instanceof DerivedUnitBase)
77 && (formSection instanceof IDerivedUnitFacadeDetailSection)) {
78
79 try {
80 input = DerivedUnitFacade.NewInstance((DerivedUnitBase) input,
81 PreferencesUtil.getDerivedUnitConfigurator());
82 } catch (DerivedUnitFacadeNotSupportedException e) {
83 StoreUtil.error(getClass(), e);
84 }
85 }
86 if (input instanceof PolytomousKeyRelationship) {
87 input = ((PolytomousKeyRelationship) input).getDestination();
88 }
89
90 formSection.setEntity((T) input);
91
92 return true;
93 }
94
95 /*
96 * (non-Javadoc)
97 *
98 * @see
99 * org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse
100 * .jface.util.PropertyChangeEvent)
101 */
102 /** {@inheritDoc} */
103 @Override
104 public void propertyChange(PropertyChangeEvent event) {
105 if (event != null) {
106
107 Object eventSource = event.getSource();
108
109 if (formSection.equals(eventSource)){
110 markDirty();
111 }
112 if((
113 (eventSource instanceof AbstractCdmFormElement)
114 && formSection.containsFormElement((AbstractCdmFormElement) eventSource))
115 ) {
116 markDirty();
117 }
118 }
119 }
120
121 }