package eu.etaxonomy.taxeditor.ui.section.taxon;
import org.apache.commons.lang.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.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.section.AbstractCdmDetailElement;
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection;
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) {
+ ISelectionProvider selectionProvider, int style, boolean taxonChoosable) {
super(formFactory, conversation, parentElement, selectionProvider, style);
+ this.taxonChoosable = taxonChoosable;
}
@Override
public String getHeading() {
-
+
return getEntity() != null ? StringUtils.replace( getEntity().getType().getLabel(), "for", ""): "Taxon Relation";
}
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);
+ }
+
+
+
}