// $Id$
/**
-* Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy
-* http://www.e-taxonomy.eu
-*
-* The contents of this file are subject to the Mozilla Public License Version 1.1
-* See LICENSE.TXT at the top of this package for the full license terms.
-*/
+ * Copyright (C) 2007 EDIT
+ * European Distributed Institute of Taxonomy
+ * http://www.e-taxonomy.eu
+ *
+ * The contents of this file are subject to the Mozilla Public License Version 1.1
+ * See LICENSE.TXT at the top of this package for the full license terms.
+ */
package eu.etaxonomy.taxeditor.view.detail;
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeNotSupportedException;
-import eu.etaxonomy.cdm.model.occurrence.DerivedUnitBase;
+import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
+import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
import eu.etaxonomy.taxeditor.model.IElementHasDetails;
+import eu.etaxonomy.taxeditor.model.PolytomousKeyRelationship;
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
import eu.etaxonomy.taxeditor.store.StoreUtil;
-import eu.etaxonomy.taxeditor.ui.forms.AbstractFormSection;
-import eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement;
+import eu.etaxonomy.taxeditor.ui.campanula.compatibility.ICdmFormElement;
+import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
import eu.etaxonomy.taxeditor.ui.section.ITaxonBaseDetailSection;
+import eu.etaxonomy.taxeditor.ui.section.key.GeographicalScopeDetailSection;
+import eu.etaxonomy.taxeditor.ui.section.key.PolytomousKeyDetailSection;
+import eu.etaxonomy.taxeditor.ui.section.key.ScopeRestrictionSection;
+import eu.etaxonomy.taxeditor.ui.section.key.TaxonomicScopeSection;
import eu.etaxonomy.taxeditor.ui.section.occurrence.IDerivedUnitFacadeDetailSection;
/**
- * <p>CdmSectionPart class.</p>
+ * <p>
+ * CdmSectionPart class.
+ * </p>
*
* @author n.hoffmann
* @created Feb 8, 2010
* @version 1.0
*/
-public class CdmSectionPart<T> extends SectionPart implements IPropertyChangeListener{
-
- private AbstractFormSection<T> formSection;
-
+public class CdmSectionPart<T> extends SectionPart implements
+ IPropertyChangeListener {
+
+ private final AbstractFormSection<T> formSection;
+
/**
- * <p>Constructor for CdmSectionPart.</p>
+ * <p>
+ * Constructor for CdmSectionPart.
+ * </p>
*
- * @param section a {@link eu.etaxonomy.taxeditor.ui.forms.AbstractFormSection} object.
- * @param <T> a T object.
+ * @param section
+ * a {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection}
+ * object.
+ * @param <T>
+ * a T object.
*/
public CdmSectionPart(AbstractFormSection<T> section) {
super(section);
formSection = section;
}
-
+
/** {@inheritDoc} */
@Override
public boolean setFormInput(Object input) {
- if(input instanceof IElementHasDetails){
+ //FIXME (CM): Need to fix this part of the design.
+ //The design seems to be locked to the idea that only one
+ // entity (either from the navigator or the editor) drives
+ // the detail view. In the case of multiple inputs the only workaround
+ // is checking the type and extracting relevant objects.
+ if (input instanceof IElementHasDetails) {
input = ((IElementHasDetails) input).getData();
}
- if((input instanceof TaxonBase) && (formSection instanceof ITaxonBaseDetailSection)){
- ((ITaxonBaseDetailSection) formSection).setTaxonBase((TaxonBase) input);
+ if ((input instanceof TaxonBase)
+ && (formSection instanceof ITaxonBaseDetailSection)) {
+ ((ITaxonBaseDetailSection) formSection)
+ .setTaxonBase((TaxonBase) input);
return true;
}
- if((input instanceof DerivedUnitBase) && (formSection instanceof IDerivedUnitFacadeDetailSection)){
-
+ if ((input instanceof DerivedUnit)
+ && (formSection instanceof IDerivedUnitFacadeDetailSection)) {
+
try {
- input = DerivedUnitFacade.NewInstance((DerivedUnitBase) input, PreferencesUtil.getDerivedUnitConfigurator());
+ input = DerivedUnitFacade.NewInstance((DerivedUnit) input,
+ PreferencesUtil.getDerivedUnitConfigurator());
} catch (DerivedUnitFacadeNotSupportedException e) {
StoreUtil.error(getClass(), e);
}
}
-
+ if (input instanceof PolytomousKeyRelationship) {
+ input = ((PolytomousKeyRelationship) input).getDestination();
+ }
+
+ if ((input instanceof PolytomousKeyNode) &&
+ (formSection instanceof PolytomousKeyDetailSection ||
+ formSection instanceof GeographicalScopeDetailSection ||
+ formSection instanceof ScopeRestrictionSection ||
+ formSection instanceof TaxonomicScopeSection)) {
+ input = ((PolytomousKeyNode)input).getKey();
+ }
+
+
formSection.setEntity((T) input);
-
+
return true;
}
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse
+ * .jface.util.PropertyChangeEvent)
*/
/** {@inheritDoc} */
+ @Override
public void propertyChange(PropertyChangeEvent event) {
- if (event != null){
-
+ if (event != null) {
+
Object eventSource = event.getSource();
-
- if(formSection.equals(eventSource)
- || (eventSource instanceof ICdmFormElement && formSection.containsFormElement((ICdmFormElement)eventSource))){
+
+ if (formSection.equals(eventSource)){
+ markDirty();
+ }
+ if((
+ (eventSource instanceof ICdmFormElement)
+ && formSection.containsFormElement((ICdmFormElement) eventSource))
+ ) {
markDirty();
}
}
}
-
-
-
+
}