-// $Id$
/**
* Copyright (C) 2007 EDIT
- * European Distributed Institute of Taxonomy
+ * 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.ui.section.name;
-import java.util.Arrays;
-
-import eu.etaxonomy.cdm.model.name.NonViralName;
-import eu.etaxonomy.taxeditor.model.AuthorHelper;
+import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
+import eu.etaxonomy.cdm.model.name.INonViralName;
+import eu.etaxonomy.cdm.model.name.IZoologicalName;
+import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
+import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
+import eu.etaxonomy.taxeditor.event.EventUtility;
+import eu.etaxonomy.taxeditor.event.WorkbenchEventConstants;
+import eu.etaxonomy.taxeditor.preference.NameDetailsConfigurator;
+import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
import eu.etaxonomy.taxeditor.ui.element.CdmPropertyChangeEvent;
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
-import eu.etaxonomy.taxeditor.ui.element.IEnableableFormElement;
+import eu.etaxonomy.taxeditor.ui.element.NumberWithLabelElement;
+import eu.etaxonomy.taxeditor.ui.element.ToggleableTextElement;
import eu.etaxonomy.taxeditor.ui.section.AbstractIdentifiableEntityDetailElement;
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
-import eu.etaxonomy.taxeditor.ui.selection.NomenclaturalAuthorTeamSelectionElement;
-import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
-import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
/**
- * <p>
* AuthorshipDetailElement class.
- * </p>
- *
+ *
* @author n.hoffmann
* @created Mar 4, 2010
- * @version 1.0
*/
-public class AuthorshipDetailElement extends
- AbstractIdentifiableEntityDetailElement<NonViralName> implements
- IEnableableFormElement {
+public class AuthorshipDetailElement
+ extends AbstractIdentifiableEntityDetailElement<INonViralName> {
- private NomenclaturalAuthorTeamSelectionElement selection_exBasionymAuthorTeam;
- private NomenclaturalAuthorTeamSelectionElement selection_basionymAuthorTeam;
- private NomenclaturalAuthorTeamSelectionElement selection_exCombinationAuthorTeam;
- private NomenclaturalAuthorTeamSelectionElement selection_combinationAuthorTeam;
+ @SuppressWarnings("rawtypes")
+ private EntitySelectionElement<TeamOrPersonBase> selectionExBasionymAuthor;
+ @SuppressWarnings("rawtypes")
+ private EntitySelectionElement<TeamOrPersonBase> selectionBasionymAuthor;
+ @SuppressWarnings("rawtypes")
+ private EntitySelectionElement<TeamOrPersonBase> selectionExCombinationAuthor;
+ @SuppressWarnings("rawtypes")
+ private EntitySelectionElement<TeamOrPersonBase> selectionCombinationAuthor;
+ @SuppressWarnings("rawtypes")
+ private EntitySelectionElement<TeamOrPersonBase> selectionInCombinationAuthor;
+ @SuppressWarnings("rawtypes")
+ private EntitySelectionElement<TeamOrPersonBase> selectionInBasionymAuthor;
- /**
- * <p>
+ private NumberWithLabelElement text_publicationYear;
+ private NumberWithLabelElement text_originalPublicationYear;
+
+ /**
* Constructor for AuthorshipDetailElement.
- * </p>
- *
- * @param cdmFormFactory
- * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
- * object.
- * @param formElement
- * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
- * object.
- * @param style
- * a int.
*/
public AuthorshipDetailElement(CdmFormFactory cdmFormFactory,
ICdmFormElement formElement, int style) {
super(cdmFormFactory, formElement);
}
- /** {@inheritDoc} */
@Override
protected void createControls(ICdmFormElement formElement,
- NonViralName entity, int style) {
- toggleable_cache = formFactory.createToggleableTextField(this,
+ INonViralName entity, int style) {
+ NameDetailsConfigurator config = PreferencesUtil.getPreferredNameDetailsConfiguration();
+ if (config == null || config.isAuthorCacheActivated()){
+ toggleable_cache = formFactory.createToggleableTextField(this,
"Authorship Cache", entity.getAuthorshipCache(),
entity.isProtectedAuthorshipCache(), style);
-
- //TODO RL
- if(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.IS_RL)){
- toggleable_cache.setVisible(false);
- }
- selection_combinationAuthorTeam = formFactory.createNomenclaturalAuthorTeamSelectionElement(
- getConversationHolder(),
- formElement, "Author",
- AuthorHelper.getAuthor(entity.getCombinationAuthorTeam()),
- EntitySelectionElement.ALL, style);
- addElement(selection_combinationAuthorTeam);
- selection_exCombinationAuthorTeam = formFactory.createNomenclaturalAuthorTeamSelectionElement(
- getConversationHolder(),
- formElement, "Ex Author",
- AuthorHelper.getAuthor(entity.getExCombinationAuthorTeam()),
- EntitySelectionElement.ALL, style);
- addElement(selection_exCombinationAuthorTeam);
- selection_basionymAuthorTeam = formFactory.createNomenclaturalAuthorTeamSelectionElement(
- getConversationHolder(),
- formElement, "Basionym Author",
- AuthorHelper.getAuthor(entity.getBasionymAuthorTeam()),
- EntitySelectionElement.ALL, style);
- addElement(selection_basionymAuthorTeam);
- selection_exBasionymAuthorTeam = formFactory.createNomenclaturalAuthorTeamSelectionElement(
- getConversationHolder(),
- formElement, "Ex Basionym Author",
- AuthorHelper.getAuthor(entity.getExBasionymAuthorTeam()),
- EntitySelectionElement.ALL, style);
- addElement(selection_exBasionymAuthorTeam);
+ addElement(toggleable_cache);
+ }
+ NomenclaturalCode code = entity.getNameType();
+
+ if (config == null || config.isAuthorshipSectionActivated()){
+ selectionCombinationAuthor = formFactory.createSelectionElementWithAbbreviatedTitle(TeamOrPersonBase.class,
+ formElement, "Author",
+ entity.getCombinationAuthorship(),
+ EntitySelectionElement.DELETABLE | EntitySelectionElement.SELECTABLE | EntitySelectionElement.EDITABLE, style);
+ addElement(selectionCombinationAuthor);
+ selectionExCombinationAuthor = formFactory.createSelectionElementWithAbbreviatedTitle(TeamOrPersonBase.class,
+ formElement, "Ex Author",
+ entity.getExCombinationAuthorship(),
+ EntitySelectionElement.DELETABLE | EntitySelectionElement.SELECTABLE | EntitySelectionElement.EDITABLE, style);
+ addElement(selectionExCombinationAuthor);
+ if ((config == null || config.isInAuthorshipActivated())&& (getEntity().getNameType().isFungus() || getEntity().getNameType().isZoological())) {
+ selectionInCombinationAuthor = formFactory.createSelectionElementWithAbbreviatedTitle(TeamOrPersonBase.class,
+ formElement, "In Author",
+ entity.getInCombinationAuthorship(),
+ EntitySelectionElement.DELETABLE | EntitySelectionElement.SELECTABLE | EntitySelectionElement.EDITABLE, style);
+ addElement(selectionInCombinationAuthor);
+ }
+ if (code != null){
+ if (code.equals(NomenclaturalCode.ICZN)){
+ text_publicationYear = formFactory.createFloatTextWithLabelElement(formElement, "Publication Year", ((IZoologicalName)entity).getPublicationYear(), style);
+ }
+ }
+ selectionBasionymAuthor = formFactory.createSelectionElementWithAbbreviatedTitle(TeamOrPersonBase.class,
+ formElement, "Basionym Author", entity.getBasionymAuthorship(),
+ EntitySelectionElement.DELETABLE | EntitySelectionElement.SELECTABLE | EntitySelectionElement.EDITABLE, style);
+ addElement(selectionBasionymAuthor);
+ selectionExBasionymAuthor = formFactory.createSelectionElementWithAbbreviatedTitle(TeamOrPersonBase.class,
+ formElement, "Ex Basionym Author",entity.getExBasionymAuthorship(),
+ EntitySelectionElement.DELETABLE | EntitySelectionElement.SELECTABLE | EntitySelectionElement.EDITABLE, style);
+
+ addElement(selectionExBasionymAuthor);
+ if ((config == null || config.isInAuthorshipActivated()) && (getEntity().getNameType().isFungus() || getEntity().getNameType().isZoological())) {
+ selectionInBasionymAuthor = formFactory.createSelectionElementWithAbbreviatedTitle(TeamOrPersonBase.class,
+ formElement, "In Basionym Author",
+ entity.getInBasionymAuthorship(),
+ EntitySelectionElement.DELETABLE | EntitySelectionElement.SELECTABLE | EntitySelectionElement.EDITABLE, style);
+ addElement(selectionInBasionymAuthor);
+ }
+ if (code != null && code.equals(NomenclaturalCode.ICZN)){
+ text_originalPublicationYear = formFactory.createFloatTextWithLabelElement(formElement, "Orig. Publication Year", ((IZoologicalName)entity).getOriginalPublicationYear(), style);
+ }
+ }
+
+ //put to Cache
+ registerCacheRelevance(selectionCombinationAuthor);
+ registerCacheRelevance(selectionBasionymAuthor);
+ registerCacheRelevance(selectionExCombinationAuthor);
+ registerCacheRelevance(selectionExBasionymAuthor);
+ registerCacheRelevance(text_publicationYear);
+ registerCacheRelevance(text_originalPublicationYear);
+
+ registerCacheRelevance(toggleable_cache, cacheRelevanceHelper.getDependenciesArray());
+
}
- /** {@inheritDoc} */
- @Override
+ @Override
+ public void addDependsOnCache(ToggleableTextElement toggleElement) {
+ super.addDependsOnCache(toggleElement);
+ //register my cache on higher cache (if not null yet)
+ registerCacheRelevance(toggleable_cache, toggleElement);
+ }
+
+ @Override
public void updateContent() {
if (getEntity() == null) {
- setEntity(NonViralName.NewInstance(null));
+ setEntity(TaxonNameFactory.NewNonViralInstance(null));
}
-
- super.updateContent();
- toggleable_cache.setEnabled(getEntity().isProtectedAuthorshipCache());
- if (this.isIrrelevant()) {
- setIrrelevant(isIrrelevant());
- } else {
- setIrrelevant(toggleable_cache.getState(),
- Arrays.asList(new Object[] { toggleable_cache }));
+ super.updateContent();
+ if (toggleable_cache != null){
+ toggleable_cache.setCacheEnabled(getEntity().isProtectedAuthorshipCache());
+ updateCacheRelevance();
}
}
- /** {@inheritDoc} */
@Override
public void handleEvent(Object eventSource) {
if (eventSource == toggleable_cache) {
getEntity().setAuthorshipCache(toggleable_cache.getText(),
toggleable_cache.getState());
- if (!isIrrelevant()){
- setIrrelevant(toggleable_cache.getState(),
- Arrays.asList(new Object[] { toggleable_cache }));
- }
- } else if (eventSource == selection_combinationAuthorTeam) {
- getEntity().setCombinationAuthorTeam(
- selection_combinationAuthorTeam.getSelection());
- } else if (eventSource == selection_exCombinationAuthorTeam) {
- getEntity().setExCombinationAuthorTeam(
- selection_exCombinationAuthorTeam.getSelection());
- } else if (eventSource == selection_basionymAuthorTeam) {
- getEntity().setBasionymAuthorTeam(
- selection_basionymAuthorTeam.getSelection());
- } else if (eventSource == selection_exBasionymAuthorTeam) {
- getEntity().setExBasionymAuthorTeam(
- selection_exBasionymAuthorTeam.getSelection());
- }
+ updateCacheRelevance();
+ } else if (eventSource == selectionCombinationAuthor) {
+ getEntity().setCombinationAuthorship(
+ selectionCombinationAuthor.getSelection());
+ } else if (eventSource == selectionExCombinationAuthor) {
+ getEntity().setExCombinationAuthorship(
+ selectionExCombinationAuthor.getSelection());
+ } else if (eventSource == selectionBasionymAuthor) {
+ getEntity().setBasionymAuthorship(
+ selectionBasionymAuthor.getSelection());
+ } else if (eventSource == selectionExBasionymAuthor) {
+ getEntity().setExBasionymAuthorship(
+ selectionExBasionymAuthor.getSelection());
+ } else if (eventSource == text_originalPublicationYear) {
+ ((IZoologicalName)getEntity()).setOriginalPublicationYear(text_originalPublicationYear.getInteger());
+ } else if (eventSource == text_publicationYear) {
+ ((IZoologicalName)getEntity()).setPublicationYear(text_publicationYear.getInteger());
+ }else if (eventSource == selectionInCombinationAuthor) {
+ (getEntity()).setInCombinationAuthorship(selectionInCombinationAuthor.getEntity());
+ }else if (eventSource == selectionInBasionymAuthor) {
+ getEntity().setInBasionymAuthorship(selectionInBasionymAuthor.getEntity());
+ }
// if (eventSource != toggleable_cache) {
// toggleable_cache.setText(getEntity().getAuthorshipCache());
// }
-// we have to notify the parent if this is embedded in the nonviral name
-// section
-// maybe we can handle this a little bit more elegant
+// we have to notify the parent if this is embedded in the nonviral name
+// section
+// maybe we can handle this a little bit more elegant
// if (getParentElement() instanceof AbstractCdmDetailSection)
firePropertyChangeEvent(new CdmPropertyChangeEvent(
getParentElement(), null));
+ EventUtility.postEvent(WorkbenchEventConstants.REFRESH_NAME_EDITOR, this.getEntity());
}
-
+
@Override
public void updateToggleableCacheField() {
- if(! getEntity().isProtectedAuthorshipCache()){
- toggleable_cache.setText(getEntity().getAuthorshipCache());
- }
+ if (toggleable_cache != null){
+ if(! getEntity().isProtectedAuthorshipCache()){
+ toggleable_cache.setText(getEntity().getAuthorshipCache());
+ }
+ }
+ }
+
+ @Override
+ public void fillFields() {
+ /*
+ toggleable_cache.setText(getEntity().getAuthorshipCache());
+ toggleable_cache.setSelected(getEntity().isProtectedAuthorshipCache());
+ selectionExBasionymAuthor.setEntity(getEntity().getExBasionymAuthorship());
+ selectionBasionymAuthor.setEntity(getEntity().getBasionymAuthorship());
+ selectionExCombinationAuthor.setEntity(getEntity().getExCombinationAuthorship());
+ selectionCombinationAuthor.setEntity(getEntity().getCombinationAuthorship());
+ if (text_originalPublicationYear != null) {
+
+ }
+ if (text_publicationYear != null) {
+ text_publicationYear.setNumber(((IZoologicalName)getEntity()).getPublicationYear());
+ text_originalPublicationYear.setNumber(((IZoologicalName)getEntity()).getOriginalPublicationYear());
+ }
+
+ */
+
+
}
-}
+}
\ No newline at end of file