import eu.etaxonomy.cdm.api.application.CdmApplicationState;
import eu.etaxonomy.cdm.api.application.CdmChangeEvent;
import eu.etaxonomy.cdm.api.application.CdmChangeEvent.Action;
-import eu.etaxonomy.cdm.api.service.IClassificationService;
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
-import eu.etaxonomy.cdm.api.service.ITaxonService;
import eu.etaxonomy.cdm.api.service.UpdateResult;
import eu.etaxonomy.cdm.model.common.CdmBase;
-import eu.etaxonomy.cdm.model.name.TaxonName;
+import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
import eu.etaxonomy.cdm.model.reference.Reference;
import eu.etaxonomy.cdm.model.taxon.Classification;
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
import eu.etaxonomy.cdm.persistence.dto.MergeResult;
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
import eu.etaxonomy.taxeditor.model.MessagingUtils;
+import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
import eu.etaxonomy.taxeditor.store.CdmStore;
import eu.etaxonomy.taxeditor.ui.section.classification.TaxonNodeDetailElement;
import eu.etaxonomy.taxeditor.ui.section.classification.TaxonNodeWizardPage;
* @created Sep 15, 2009
* @version 1.0
*/
-public class NewTaxonNodeWizard extends AbstractNewEntityWizard<ITaxonTreeNode>{
+public class NewTaxonNodeWizard extends AbstractNewEntityWizard<TaxonNode>{
private TaxonNodeWizardPage taxonNodePage;
private boolean openEmptyEditor;
parentNodeUuid = parent.getUuid();
}
- /*
- * for (HybridRelationship rel : childRelations){
- TaxonName name = rel.getHybridName();
- TaxonName parentName = rel.getParentName();
- nameService.saveOrUpdate(rel.getHybridName());
- nameService.save(rel.getParentName());
- }
- */
+
UpdateResult result;
- if (!taxon.getName().getHybridChildRelations().isEmpty() || !taxon.getName().getHybridParentRelations().isEmpty()){
- Set<TaxonName> parentNames = new HashSet<>();
- Set<TaxonName> childNames = new HashSet<>();
-// for (HybridRelationship hybridRelationship: taxon.getName().getHybridChildRelations()){
-// if (hybridRelationship.getParentName() != taxon.getName()){
-// if (!hybridRelationship.getParentName().isPersited()){
-// parentNames.add(hybridRelationship.getParentName());
-// }
-// }else {//if (hybridRelationship.getHybridName() != taxon.getName()){
-// if (!hybridRelationship.getHybridName().isPersited()){
-// childNames.add(hybridRelationship.getHybridName());
-// }
-// }
-// for (HybridRelationship rel : taxon.getName().getHybridChildRelations()){
-// TaxonName name = rel.getHybridName();
-// TaxonName parentName = rel.getParentName();
-// CdmStore.getService(INameService.class).save(rel.getHybridName());
-// CdmStore.getService(INameService.class).save(rel.getParentName());
-// }
-
-// }
-
-// for (HybridRelationship hybridRelationship: taxon.getName().getHybridParentRelations()){
-// if (hybridRelationship.getParentName() != taxon.getName()){
-// if (!hybridRelationship.getParentName().isPersited()){
-// parentNames.add(hybridRelationship.getParentName());
-// }
-// }else {//if (hybridRelationship.getHybridName() != taxon.getName()){
-// if (!hybridRelationship.getHybridName().isPersited()){
-// childNames.add(hybridRelationship.getHybridName());
-// }
-// }
-//
-// }
-// CdmStore.getService(INameService.class).save(childNames);
-// CdmStore.getService(INameService.class).save(parentNames);
-
- }
+
if (taxon.getId() == 0){
- result = CdmStore.getService(ITaxonNodeService.class).createNewTaxonNode(parentNodeUuid, taxon, parent.getReference(), parent.getMicroReference());
+ //getEntity().setTaxon(taxon);
+ result = CdmStore.getService(ITaxonNodeService.class).saveNewTaxonNode(getEntity());
+
}else{
result = CdmStore.getService(ITaxonNodeService.class).createNewTaxonNode(parentNodeUuid, taxon.getUuid(), parent.getReference(), parent.getMicroReference());
}
}
@Override
- protected ITaxonTreeNode createNewEntity() {
+ protected TaxonNode createNewEntity() {
if(getSelection() != null){
Object selectedObject = getSelection().getFirstElement();
if(selectedObject instanceof TaxonNodeDto){
TaxonNodeDto taxonNodeDto = (TaxonNodeDto) selectedObject;
TaxonNode node = CdmStore.getService(ITaxonNodeService.class).load(taxonNodeDto.getUuid());
- if(node.getTaxon()!=null){
- //FIXME this taxon is not used. Do we need this call?
- Taxon taxon = (Taxon) CdmStore.getService(ITaxonService.class).load(node.getTaxon().getUuid());
- }
- else if(node.getClassification()!=null){
- return CdmStore.getService(IClassificationService.class).load(node.getClassification().getUuid());
- }
- return node;
+ Reference sec = node.getTaxon() != null? node.getTaxon().getSec():null;
+ Taxon newTaxon = Taxon.NewInstance(TaxonNameFactory.NewNameInstance(PreferencesUtil.getPreferredNomenclaturalCode(), null), sec);
+ TaxonNode child = node.addChildTaxon(newTaxon, null, null);
+// if(node.getTaxon()!=null){
+// //FIXME this taxon is not used. Do we need this call?
+// Taxon taxon = (Taxon) CdmStore.getService(ITaxonService.class).load(node.getTaxon().getUuid());
+// }
+// else if(node.getClassification()!=null){
+// return CdmStore.getService(IClassificationService.class).load(node.getClassification().getUuid());
+// }
+ return child;
- } else if(selectedObject instanceof Classification){
- return (Classification)selectedObject;
}
}
* @created Sep 27, 2010
* @version 1.0
*/
-public class TaxonNodeDetailElement extends AbstractCdmDetailElement<ITaxonTreeNode> {
+public class TaxonNodeDetailElement extends AbstractCdmDetailElement<TaxonNode> {
private boolean createNew = false;
private TaxonNodeSelectionElement selection_parentTaxonNode;
- private ITaxonTreeNode parentTreeNode;
+ private TaxonNode parentTreeNode;
private EntitySelectionElement<Taxon> selection_reuseExistingTaxon;
private EntitySelectionElement<Reference> selection_SecRef;
/** {@inheritDoc} */
@Override
protected void createControls(ICdmFormElement formElement,
- ITaxonTreeNode entity, int style) {
+ TaxonNode entity, int style) {
+ taxon = entity.getTaxon();
if (isCreateNew()){
// selection_classification = formFactory
// .createSelectionElement(Classification.class,//getConversationHolder(),
// formElement, "Classification",
// null, EntitySelectionElement.DELETABLE, style);
selection_parentTaxonNode = formFactory
- .createTaxonNodeSelectionElement(getConversationHolder(), formElement, "Parent", null,
+ .createTaxonNodeSelectionElement(getConversationHolder(), formElement, "Parent", parentTreeNode,
EntitySelectionElement.DELETABLE, style);
// selection_reuseExistingTaxon = formFactory
selection_reuseExistingName = formFactory
.createSelectionElement(TaxonName.class,//getConversationHolder(),
formElement,
- "Reuse existing name", null,
+ "Reuse existing name", taxon.getName(),
EntitySelectionElement.DELETABLE, style);
selection_SecRef = formFactory
.createSelectionElement(Reference.class,//getConversationHolder(),
- formElement, "Secundum Reference", null,
+ formElement, "Secundum Reference", taxon.getSec(),
EntitySelectionElement.DELETABLE, style);
if (isCreateNew()){
}
}else{
- TextWithLabelElement textClassification = formFactory.createTextWithLabelElement(formElement,"Classification", ((TaxonNode)entity).getClassification().getTitleCache(), style);
+ TextWithLabelElement textClassification = formFactory.createTextWithLabelElement(formElement,"Classification", entity.getClassification().getTitleCache(), style);
textClassification.setEnabled(false);
- TextWithLabelElement textTaxon = formFactory.createTextWithLabelElement(formElement,"Taxon", ((TaxonNode)entity).getTaxon().getTitleCache(), style);
+ TextWithLabelElement textTaxon = formFactory.createTextWithLabelElement(formElement,"Taxon", taxon.getTitleCache(), style);
textTaxon.setEnabled(false);
TextWithLabelElement textTaxonSec = formFactory.createTextWithLabelElement(formElement,"Secundum Reference", "", style);
- if (((TaxonNode)entity).getTaxon().getSec() != null){
- textTaxonSec.setText(((TaxonNode)entity).getTaxon().getSec().getTitleCache());
+ if (entity.getTaxon().getSec() != null){
+ textTaxonSec.setText(taxon.getSec().getTitleCache());
}
textTaxonSec.setEnabled(false);
if (!isCreateNew()){
selection_Ref.setEntity(entity.getReference());
}
- if (entity instanceof TaxonNode) {
+ parentTreeNode = entity.getParent();
+ if (entity instanceof TaxonNode && parentTreeNode.getTaxon() != null) {
checkbox_publish = formFactory.createCheckbox(formElement,
- "Taxon is public", ((TaxonNode)entity).getTaxon().isPublish(), style);
+ "Taxon is public", parentTreeNode.getTaxon().isPublish(), style);
}else{
checkbox_publish = formFactory.createCheckbox(formElement,
"Taxon is public", true, style);
}
checkbox_publish.setEnabled(isCreateNew());
if(isCreateNew()){
- setParentTreeNode(entity);
- CdmPreference defaultPublish = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.DefaultBehaviourForPublishFlag);
+ setParentTreeNode(entity.getParent());
+ CdmPreference defaultPublish = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.DefaultBehaviourForPublishFlag);
if (defaultPublish != null && defaultPublish.getValue().equals(PublishEnum.Publish.getKey())){
checkbox_publish.setSelection(true);
} else if (defaultPublish != null && defaultPublish.getValue().equals(PublishEnum.NotPublish.getKey())){
checkbox_publish.setSelection(false);
}else{
- if(this.getParentTreeNode() != null && this.getParentTreeNode().isInstanceOf(TaxonNode.class)){
+ if(this.getParentTreeNode() != null && this.getParentTreeNode().isInstanceOf(TaxonNode.class) && ((TaxonNode)this.getParentTreeNode()).getTaxon() != null){
checkbox_publish.setSelection(((TaxonNode)this.getParentTreeNode()).getTaxon().isPublish());
}else{
checkbox_publish.setSelection(true);
}
if (entity instanceof TaxonNode) {
checkbox_unplaced = formFactory.createCheckbox(formElement,
- "Taxon is unplaced", ((TaxonNode)entity).isUnplaced(), style);
+ "Taxon is unplaced", entity.isUnplaced(), style);
}else{
checkbox_unplaced = formFactory.createCheckbox(formElement,
"Taxon is unplaced", false, style);
if (entity instanceof TaxonNode) {
checkbox_excluded = formFactory.createCheckbox(formElement,
- "Taxon is excluded", ((TaxonNode)entity).isExcluded(), style);
- multiLanguageTextExcludedNotes = formFactory.createMultiLanguageTextElement(formElement, "Excluded Notes", ((TaxonNode)entity).getExcludedNote(), 50, style);
- multiLanguageTextExcludedNotes.setEnabled(((TaxonNode) entity).isExcluded());
+ "Taxon is excluded", entity.isExcluded(), style);
+ multiLanguageTextExcludedNotes = formFactory.createMultiLanguageTextElement(formElement, "Excluded Notes", entity.getExcludedNote(), 50, style);
+ multiLanguageTextExcludedNotes.setEnabled(entity.isExcluded());
}else{
checkbox_excluded = formFactory.createCheckbox(formElement,
"Taxon is excluded", false, style);
}
if (!isCreateNew()){
selectionNodeAgentRelation = formFactory.createTaxonNodeAgentRelationCollectionSection(formElement, getConversationHolder(), style);
- selectionNodeAgentRelation.setEntity((TaxonNode)entity);
+ selectionNodeAgentRelation.setEntity(entity);
selectionNodeAgentRelation.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
}
// checkbox_openInEditor = formFactory.createCheckbox(formElement,
private void preFillTaxonName() {
if(getEntity() instanceof TaxonNode ){
- TaxonNode node = (TaxonNode)getEntity();
+ TaxonNode node = parentTreeNode;
if(node.getTaxon()!=null){
Taxon taxon = HibernateProxyHelper.deproxy(node.getTaxon(), Taxon.class);
if(taxon.getName()!=null){
/** {@inheritDoc} */
@Override
public void handleEvent(Object eventSource) {
- if (eventSource == selection_classification) {
- setClassification(selection_classification.getEntity());
- } else if (eventSource == selection_parentTaxonNode) {
- setParentTreeNode(selection_parentTaxonNode.getEntity());
+ if (eventSource == selection_parentTaxonNode) {
+ setParentTreeNode(selection_parentTaxonNode.getEntity());
} else if (eventSource == selection_reuseExistingTaxon) {
boolean enabled = selection_reuseExistingTaxon.getEntity() == null;
selection_reuseExistingName.setEnabled(enabled);
} else if (eventSource == selection_reuseExistingName) {
boolean enabled = selection_reuseExistingName.getEntity() == null;
- setTaxon(selection_reuseExistingName.getEntity());
+ setTaxon(HibernateProxyHelper.deproxy(selection_reuseExistingName.getEntity()));
if (selection_reuseExistingTaxon != null){
selection_reuseExistingTaxon.setEnabled(enabled);
}
textNewTaxonName.setEnabled(enabled);
-
complete = !textNewTaxonName.getText().isEmpty();
}
if (!isCreateNew()){
if (eventSource == selection_Ref) {
- ((TaxonNode) getEntity()).setReference(selection_Ref.getEntity());
+ getEntity().setReference(selection_Ref.getEntity());
}else if (eventSource == selection_SecRef) {
- ((TaxonNode) getEntity()).getTaxon().setSec(selection_SecRef.getEntity());
+ taxon.setSec(selection_SecRef.getEntity());
}else if (eventSource == microReference) {
- ((TaxonNode) getEntity()).setMicroReference(microReference.getText());
+ getEntity().setMicroReference(microReference.getText());
} else if (eventSource == checkbox_publish) {
- ((TaxonNode)getEntity()).getTaxon().setPublish(checkbox_publish.getSelection());
+ taxon.setPublish(checkbox_publish.getSelection());
}
}
if (eventSource == checkbox_excluded) {
excluded = checkbox_excluded.getSelection();
- if (!isCreateNew()){
- ((TaxonNode)getEntity()).setExcluded(excluded);
- }
+
+ getEntity().setExcluded(excluded);
+
multiLanguageTextExcludedNotes.setEnabled(excluded);
}
if (eventSource == checkbox_unplaced) {
unplaced = checkbox_unplaced.getSelection();
- if (!isCreateNew()){
- ((TaxonNode)getEntity()).setUnplaced(unplaced);
- }
+ getEntity().setUnplaced(unplaced);
+
}
if (eventSource == textNewTaxonName) {
boolean enabled = CdmUtils.isBlank(textNewTaxonName.getText());
private void setClassification(Classification classification) {
this.classification = classification;
- setParentTreeNode(classification);
+ //setParentTreeNode(classification);
}
- private void setParentTreeNode(ITaxonTreeNode parentTreeNode) {
+ private void setParentTreeNode(TaxonNode parentTreeNode) {
this.parentTreeNode = parentTreeNode;
- if (parentTreeNode instanceof Classification) {
- classification = (Classification) parentTreeNode;
+ if (parentTreeNode.getTaxon() == null) {
+ classification = parentTreeNode.getClassification();
if (selection_classification != null){
selection_classification.setEntity(classification);
}
- selection_parentTaxonNode.setEntity(null);
+ selection_parentTaxonNode.setEntity(classification.getRootNode());
selection_parentTaxonNode.setClassification(classification);
selection_SecRef.setEntity(classification.getReference());
- } else if (parentTreeNode instanceof TaxonNode) {
+ } else {
classification = HibernateProxyHelper
- .deproxy(((TaxonNode) parentTreeNode).getClassification());
+ .deproxy(parentTreeNode.getClassification());
if (selection_classification != null){
selection_classification.setEntity(classification);
}
selection_parentTaxonNode.setEntity(HibernateProxyHelper
- .deproxy((TaxonNode) parentTreeNode));
+ .deproxy(parentTreeNode));
selection_parentTaxonNode.setClassification(classification);
- selection_SecRef.setEntity(((TaxonNode)parentTreeNode).getTaxon().getSec());
- } else if(parentTreeNode == null){
- this.parentTreeNode = classification;
+ selection_SecRef.setEntity(parentTreeNode.getTaxon().getSec());
+
}
}
- private void setTreeNode(ITaxonTreeNode treeNode) {
+ private void setTreeNode(TaxonNode treeNode) {
classification = HibernateProxyHelper
- .deproxy(((TaxonNode) treeNode).getClassification());
+ .deproxy(treeNode.getClassification());
if (isCreateNew()){
//selection_classification.setEntity(classification);
- selection_parentTaxonNode.setEntity(((TaxonNode) treeNode).getParent());
- selection_parentTaxonNode.setClassification(((TaxonNode) treeNode).getParent().getClassification());
- selection_SecRef.setEntity(((TaxonNode)treeNode).getTaxon().getSec());
+ selection_parentTaxonNode.setEntity(treeNode.getParent());
+ selection_parentTaxonNode.setClassification(treeNode.getParent().getClassification());
+ selection_SecRef.setEntity(treeNode.getTaxon().getSec());
}
}
private void setTaxon(Taxon taxon) {
this.taxon = taxon;
+ getEntity().setTaxon(taxon);
if (isCreateNew()){
textNewTaxonName.setText(taxon.getName().getTitleCache());
}
if (textNewTaxonName.getText() == null || !taxonName.getTitleCache().trim().equals(textNewTaxonName.getText().trim())){
textNewTaxonName.setText(taxonName.getTitleCache());
}
+ getEntity().setTaxon(taxon);
// if (!taxonName.getTitleCache().trim().equals(textNewTaxonName.getText().trim())){
// textNewTaxonName.setText(taxonName.getTitleCache());
// }
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
import eu.etaxonomy.cdm.common.CdmUtils;
import eu.etaxonomy.cdm.model.name.INonViralName;
+import eu.etaxonomy.cdm.model.name.TaxonName;
import eu.etaxonomy.cdm.model.reference.Reference;
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
import eu.etaxonomy.cdm.model.taxon.Taxon;
* @author n.hoffmann
* @created Sep 15, 2009
*/
-public class TaxonNodeWizardPage extends AbstractCdmEntityWizardPage<ITaxonTreeNode> implements Listener{
+public class TaxonNodeWizardPage extends AbstractCdmEntityWizardPage<TaxonNode> implements Listener{
private final IWizardPageListener wizardPageListener;
private final boolean isCreateNew;
* @param closeOnEnterListener
*/
public TaxonNodeWizardPage(CdmFormFactory formFactory,
- ConversationHolder conversation, ITaxonTreeNode entity, IWizardPageListener closeOnEnterListener, boolean isCreateNew) {
+ ConversationHolder conversation, TaxonNode entity, IWizardPageListener closeOnEnterListener, boolean isCreateNew) {
super(formFactory, conversation, entity);
this.wizardPageListener = closeOnEnterListener;
setTitle("Edit taxon node");
public TaxonNodeDetailElement createElement(ICdmFormElement rootElement) {
TaxonNodeDetailElement detailElement = formFactory.createTaxonNodeDetailElement(rootElement, this.isCreateNew);
detailElement.setEntity(entity);
+
formFactory.addPropertyChangeListener(this);
if (isCreateNew){
detailElement.getMainControl().addListener(SWT.KeyDown, this);
}
public Taxon createTaxon() {
+ Taxon taxon;
+ String taxonName = ((TaxonNodeDetailElement) getDetailElement()).getTaxonName();
+ Reference reference = ((TaxonNodeDetailElement) getDetailElement()).getReference();
+ if (parseHandler == null){
+ parseHandler = ParseHandler.NewInstance(null);
+ }
+ final INonViralName parseReferencedName = parseHandler.parseAndResolveDuplicates(taxonName);
if (((TaxonNodeDetailElement) getDetailElement()).getTaxon() == null){
- String taxonName = ((TaxonNodeDetailElement) getDetailElement()).getTaxonName();
- Reference reference = ((TaxonNodeDetailElement) getDetailElement()).getReference();
- if (parseHandler == null){
- parseHandler = ParseHandler.NewInstance(null);
- }
- final INonViralName parseReferencedName = parseHandler.parseAndResolveDuplicates(taxonName);
-
- Taxon taxon = Taxon.NewInstance(parseReferencedName, reference);
- taxon.setPublish( ((TaxonNodeDetailElement) getDetailElement()).is_publish());
+ taxon = Taxon.NewInstance(parseReferencedName, reference);
- return taxon;
} else{
- return ((TaxonNodeDetailElement) getDetailElement()).getTaxon();
+ taxon = ((TaxonNodeDetailElement) getDetailElement()).getTaxon();
+ if (taxon.getName().getId() == 0){
+ taxon.setName((TaxonName) parseReferencedName);
+ }
+
}
+ taxon.setPublish( ((TaxonNodeDetailElement) getDetailElement()).is_publish());
+
+ return taxon;
}
public TaxonNode getTaxonNode(){
- return (TaxonNode) ((TaxonNodeDetailElement) getDetailElement()).getEntity();
+ return ((TaxonNodeDetailElement) getDetailElement()).getEntity();
}
/** {@inheritDoc} */