-// $Id$
/**
* Copyright (C) 2007 EDIT
* European Distributed Institute of Taxonomy
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
import eu.etaxonomy.cdm.model.name.NonViralName;
+import eu.etaxonomy.cdm.model.name.TaxonNameBase;
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
-import eu.etaxonomy.taxeditor.model.AbstractUtility;
-import eu.etaxonomy.taxeditor.ui.campanula.compatibility.ICdmFormElement;
+import eu.etaxonomy.taxeditor.model.ImageResources;
+import eu.etaxonomy.taxeditor.model.MessagingUtils;
+import eu.etaxonomy.taxeditor.ui.dialog.selection.NameSelectionDialog;
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;
import eu.etaxonomy.taxeditor.ui.section.ITaxonBaseDetailSection;
/**
- * <p>NonViralNameDetailSection class.</p>
- *
* @author n.hoffmann
* @created May 20, 2010
* @version 1.0
implements ITaxonBaseDetailSection {
private TaxonBase taxonBase;
+ boolean nameChoosable = false;
/**
* <p>Constructor for NonViralNameDetailSection.</p>
* @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
* @param parentElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
* @param selectionProvider a {@link org.eclipse.jface.viewers.ISelectionProvider} object.
+ * @param nameChoosable if <code>true</code> adds a button to choose the displayed name
* @param style a int.
*/
public NonViralNameDetailSection(CdmFormFactory formFactory, ConversationHolder conversation,
- ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style) {
+ ICdmFormElement parentElement, ISelectionProvider selectionProvider, boolean nameChoosable, int style) {
super(formFactory, conversation, parentElement, selectionProvider, style);
+ this.nameChoosable = nameChoosable;
}
- /* (non-Javadoc)
- * @see eu.etaxonomy.taxeditor.section.AbstractCdmDetailSection#createToolbar()
- */
@Override
protected Control createToolbar() {
- ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
-
+ ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
+
+ if(nameChoosable ){
+ //choose name
+ Action chooseNameAction = new Action("Choose Name", IAction.AS_PUSH_BUTTON){
+ @Override
+ public void run() {
+ TaxonNameBase taxonName = NameSelectionDialog.select(getShell(), getConversationHolder(), getEntity());
+ if(taxonName!=null){
+ if(taxonName.isInstanceOf(NonViralName.class)){
+ NonViralName nonViralName = HibernateProxyHelper.deproxy(taxonName, NonViralName.class);
+ taxonBase.setName(nonViralName);
+ // taxonBase.getTitleCache();
+ setEntity(nonViralName);
+ firePropertyChangeEvent(NonViralNameDetailSection.this);
+ }
+ else{
+ MessagingUtils.warningDialog("Invalid name", this, "The selected name can not be used for this taxon.");
+ }
+ }
+ }
+ };
+ chooseNameAction.setToolTipText("Choose name for this taxon");
+ chooseNameAction.setImageDescriptor(ImageResources.getImageDescriptor(ImageResources.BROWSE_ICON));
+
+ toolBarManager.add(chooseNameAction);
+ }
+
+ //clone
if(getEntity() != null && checkForMultipleNameUsages(getEntity())){
Action cloneAction = new Action("Clone", IAction.AS_PUSH_BUTTON){
- @Override
- public void run() {
- boolean confirm = AbstractUtility.confirmDialog("Confirm cloning", "Do you really want to clone the name?");
+ @Override
+ public void run() {
+ boolean confirm = MessagingUtils.confirmDialog("Confirm cloning", "Do you really want to clone the name?");
if(confirm){
NonViralName clonedName;
setEntity(clonedName);
taxonBase.setName(clonedName);
taxonBase.generateTitle();
-// EditorUtil.getActiveMultiPageTaxonEditor().r
firePropertyChangeEvent(new CdmPropertyChangeEvent(NonViralNameDetailSection.this, null));
}
}
- /**
- * @param nonViralName
- *
- */
private boolean checkForMultipleNameUsages(NonViralName nonViralName) {
return nonViralName.getTaxonBases().size() != 1;
}
- /* (non-Javadoc)
- * @see eu.etaxonomy.taxeditor.section.AbstractCdmDetailSection#getHeading()
- */
/** {@inheritDoc} */
@Override
public String getHeading() {
return "Name";
}
- /* (non-Javadoc)
- * @see eu.etaxonomy.taxeditor.section.ITaxonDetailSection#setTaxon(eu.etaxonomy.cdm.model.taxon.TaxonBase)
- */
/** {@inheritDoc} */
@Override
public void setTaxonBase(TaxonBase taxon) {
setEntity(name);
}
- /* (non-Javadoc)
- * @see eu.etaxonomy.taxeditor.section.ITaxonDetailSection#getTaxon(eu.etaxonomy.cdm.model.taxon.TaxonBase)
- */
@Override
public TaxonBase getTaxonBase() {
return taxonBase;
}
- /* (non-Javadoc)
- * @see eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection#createCdmDetailElement(eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection, int)
- */
@Override
protected AbstractCdmDetailElement<NonViralName> createCdmDetailElement(AbstractCdmDetailSection<NonViralName> parentElement, int style) {
return formFactory.createNonViralNameDetailElement(parentElement);