import org.eclipse.jface.viewers.TreeSelection;
import org.eclipse.swt.widgets.Shell;
+import eu.etaxonomy.cdm.model.metadata.SecReferenceHandlingEnum;
+import eu.etaxonomy.cdm.model.reference.Reference;
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
+import eu.etaxonomy.taxeditor.model.AbstractUtility;
+import eu.etaxonomy.taxeditor.model.MessagingUtils;
import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
import eu.etaxonomy.taxeditor.navigation.l10n.Messages;
import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigatorLabels;
import eu.etaxonomy.taxeditor.navigation.navigator.operation.MoveTaxonOperation;
import eu.etaxonomy.taxeditor.operation.e4.CdmHandlerE4;
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
+import eu.etaxonomy.taxeditor.ui.dialog.selection.ReferenceSelectionDialog;
import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonNodeSelectionDialog;
/**
private TaxonNavigatorE4 navigator;
private UUID classificationUuid = null;
boolean isPublish = true;
+ SecReferenceHandlingEnum secHandling;
+ UUID newSecUuid;
+ private Set<UUID> oldTaxonSecUUIDs = new HashSet<>();
public MoveTaxonNodeHandlerE4() {
super(TaxonNavigatorLabels.MOVE_TAXON_LABEL);
obj = iter.next();
if(obj instanceof TaxonNodeDto) {
oldTaxonNodeUUIDs.add(((TaxonNodeDto)obj).getUuid());
+ oldTaxonSecUUIDs.add(((TaxonNodeDto)obj).getSecUuid());
isPublish &= ((TaxonNodeDto)obj).isPublish();
if (classificationUuid == null){
classificationUuid = ((TaxonNodeDto)obj).getClassificationUUID();
Messages.RemotingMoveTaxonNodeHandler_DIFFERENT_PUBLISH_MESSAGE);
}
+ secHandling = PreferencesUtil.getSecReferenceHandlingPreference();
+ newSecUuid = null;
+ UUID parentTaxonSecUuid= parentTaxonNode.getTaxon() != null && parentTaxonNode.getTaxon().getSec() != null ? parentTaxonNode.getTaxon().getSec().getUuid(): null;
+ if (secHandling.equals(SecReferenceHandlingEnum.AlwaysSelect) || (oldTaxonSecUUIDs.size() > 1 && secHandling.equals(SecReferenceHandlingEnum.KeepOrSelect)) || (oldTaxonSecUUIDs.size() == 1 && secHandling.equals(SecReferenceHandlingEnum.KeepOrSelect) && !oldTaxonSecUUIDs.contains(parentTaxonSecUuid))){
+ //The moved nodes have different secundum references
+ String message = null;
+ String[] options = null;
+ if (secHandling.equals(SecReferenceHandlingEnum.AlwaysSelect) && (parentTaxonSecUuid != null && oldTaxonSecUUIDs.contains(parentTaxonSecUuid))){
+ message = Messages.TreeNodeDropAdapter_Select_Sec_Reference_Handling_message_always_select;
+ options = new String[]{Messages.RemotingChangeAcceptedTaxonToSynonymHandler_Select_Sec_Reference_Keep, Messages.RemotingChangeAcceptedTaxonToSynonymHandler_Select_Sec_Reference_Select};
+ }else {
+ message = Messages.TreeNodeDropAdapter_Select_Sec_Reference_Handling_message;
+ options = new String[]{Messages.RemotingChangeAcceptedTaxonToSynonymHandler_Select_Sec_Reference_Keep, Messages.RemotingChangeAcceptedTaxonToSynonymHandler_Select_Sec_Reference_Select, Messages.TreeNodeDropAdapter_Select_Sec_Reference_Parent, };
+ }
+ int result = MessagingUtils.confirmDialog(Messages.RemotingChangeAcceptedTaxonToSynonymHandler_Select_Sec_Reference_Handling_title, message, options);
+
+// int result = MessagingUtils.confirmDialog(Messages.RemotingChangeAcceptedTaxonToSynonymHandler_Select_Sec_Reference_Handling_title, Messages.RemotingChangeAcceptedTaxonToSynonymHandler_Select_Sec_Reference_Handling_message,
+// new String[]{Messages.RemotingChangeAcceptedTaxonToSynonymHandler_Select_Sec_Reference_Keep, Messages.RemotingChangeAcceptedTaxonToSynonymHandler_Select_Sec_Reference_Parent, Messages.RemotingChangeAcceptedTaxonToSynonymHandler_Select_Sec_Reference_Select});
+ if (result == 1){
+ //select new reference
+ Reference sec = ReferenceSelectionDialog.select(AbstractUtility.getShell(), null);
+ newSecUuid = sec != null? sec.getUuid(): null;
+ }else if (result == 2){
+ //use parent sec
+ secHandling = SecReferenceHandlingEnum.UseNewParentSec;
+ newSecUuid = parentTaxonSecUuid;
+ }else if (result == 0){
+ //keep sec (also homotypic synonyms with different sec will keep the secundum)
+ secHandling = SecReferenceHandlingEnum.KeepOrWarn;
+ }else{
+ return null;
+ }
+ }
+
if(parentTaxonNode != null){
false,
oldTaxonNodeUUIDs,
parentTaxonNode.getUuid(),
- moveToNewParent);
+ moveToNewParent,
+ secHandling,
+ newSecUuid);
}
return null;