-// $Id$
/**
* Copyright (C) 2009 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.taxon;
+import org.apache.commons.lang3.StringUtils;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Control;
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
+import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
+import eu.etaxonomy.cdm.model.name.TaxonName;
+import eu.etaxonomy.cdm.model.taxon.Taxon;
+import eu.etaxonomy.cdm.model.taxon.TaxonBase;
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
+import eu.etaxonomy.taxeditor.event.EventUtility;
+import eu.etaxonomy.taxeditor.event.WorkbenchEventConstants;
+import eu.etaxonomy.taxeditor.model.ImageResources;
+import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonBaseSelectionDialog;
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.CdmFormFactory.DetailType;
+import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection;
+import eu.etaxonomy.taxeditor.ui.section.ITaxonBaseDetailSection;
/**
* @author n.hoffmann
* @date Dec 1, 2011
*
*/
-public class TaxonRelationshipDetailSection extends AbstractCdmDetailSection<TaxonRelationship>{
+public class TaxonRelationshipDetailSection extends AbstractCdmDetailSection<TaxonRelationship> implements ITaxonBaseDetailSection {
+ Taxon taxon;
+ TaxonName name;
+ boolean taxonChoosable = false;
public TaxonRelationshipDetailSection(CdmFormFactory formFactory,
ConversationHolder conversation, ICdmFormElement parentElement,
- ISelectionProvider selectionProvider, int style) {
- super(formFactory, conversation, parentElement, selectionProvider, style);
+ ISelectionProvider selectionProvider, int style, boolean taxonChoosable) {
+ super(formFactory, conversation, parentElement, selectionProvider, style);
+ this.taxonChoosable = taxonChoosable;
}
@Override
- protected DetailType getDetailType() {
- return DetailType.TAXON_RELATIONSHIP;
+ public String getHeading() {
+
+ return getEntity() != null ? StringUtils.replace( getEntity().getType().getLabel(), "for", ""): "Taxon Relation";
}
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection#createCdmDetailElement(eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection, int)
+ */
@Override
- public String getHeading() {
- return "Taxon Relationship";
+ protected AbstractCdmDetailElement<TaxonRelationship> createCdmDetailElement(AbstractCdmDetailSection<TaxonRelationship> parentElement, int style) {
+ return formFactory.createTaxonRelationshipDetailElement(parentElement);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void setTaxonBase(TaxonBase taxon) {
+ this.taxon = (Taxon)taxon;
+ TaxonName name = HibernateProxyHelper.deproxy(taxon.getName());
+ setName(name);
+ }
+
+ @Override
+ public TaxonBase getTaxonBase() {
+ return taxon;
+ }
+
+ private void setName(TaxonName name){
+ this.name = name;
+ }
+
+ @Override
+ protected Control createToolbar() {
+ ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
+
+ if(taxonChoosable){
+ //choose name
+ Action chooseTaxonAction = new Action("Choose Taxon", IAction.AS_PUSH_BUTTON){
+ @Override
+ public void run() {
+ Taxon taxon = TaxonBaseSelectionDialog.selectTaxon(getShell(), //getConversationHolder(),
+ getEntity().getFromTaxon());
+ if(taxon!=null){
+ taxon = HibernateProxyHelper.deproxy(taxon);
+ name = taxon.getName();
+ TaxonRelationship rel = getEntity();
+ rel.setFromTaxon(taxon);
+ taxon.addTaxonRelation(rel);
+ setEntity(rel);
+ setTaxonBase(taxon);
+// firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
+ detailElement.firePropertyChangeEvent(new CdmPropertyChangeEvent(detailElement, null));
+ EventUtility.postEvent(WorkbenchEventConstants.REFRESH_DETAILS, true);
+ EventUtility.postEvent(WorkbenchEventConstants.REFRESH_SUPPLEMENTAL, true);
+ EventUtility.postEvent(WorkbenchEventConstants.REFRESH_NAME_EDITOR, rel.getToTaxon());
+ ((TaxonRelationshipDetailElement)detailElement).getTaxonElement().setSelected(true);;
+
+
+ }
+ }
+ };
+ chooseTaxonAction.setToolTipText("Choose taxon for this Relationship");
+ chooseTaxonAction.setImageDescriptor(ImageResources.getImageDescriptor(ImageResources.BROWSE_ICON));
+
+ toolBarManager.add(chooseTaxonAction);
+ }
+ return toolBarManager.createControl(this);
}
+
+
}