import java.util.Set;
import java.util.UUID;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.operations.IOperationHistory;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Status;
import org.eclipse.e4.ui.di.UISynchronize;
+import org.eclipse.ui.ide.undo.WorkspaceUndoUtil;
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
-import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
import eu.etaxonomy.taxeditor.editor.CdmEntitySessionInput;
import eu.etaxonomy.taxeditor.editor.ChooseFromMultipleAcceptedTaxaDialog;
import eu.etaxonomy.taxeditor.editor.ChooseFromMultipleTaxonNodesDialog;
-import eu.etaxonomy.taxeditor.editor.EditorUtil;
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
+import eu.etaxonomy.taxeditor.model.AbstractUtility;
import eu.etaxonomy.taxeditor.model.DataChangeBridge;
import eu.etaxonomy.taxeditor.model.MessagingUtils;
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
-import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
+import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
import eu.etaxonomy.taxeditor.store.CdmStore;
+import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
/**
private List<TaxonName> toSaveNewNames = new ArrayList<>();
- private Set<AbstractPostTaxonOperation> operations = new HashSet<>();
+ private Set<AbstractPostOperation> operations = new HashSet<>();
private TaxonEditorInputDataChangeBehaviourE4 dataChangeBehavior;
Taxon taxon = CdmBase.deproxy(taxonBase, Taxon.class);
setInitiallySelectedTaxonBase(taxon);
- if (taxon.getTaxonNodes().size() == 0 && taxon.isMisapplication()){
+ if ( taxon.isMisapplication() || taxon.isProparteSynonym()){
// TODO get accepted taxon
MessagingUtils.info(Messages.TaxonEditorInput_OPEN_MISSAPPLIED_NAME);
Set<Taxon> acceptedTaxa = new HashSet<Taxon>();
Set<TaxonRelationship> relations = taxon.getRelationsFromThisTaxon();
for(TaxonRelationship relation : relations){
- if(relation.getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR())){
+ if(relation.getType().isAnyMisappliedName() || relation.getType().isAnySynonym()){
acceptedTaxa.add(relation.getToTaxon());
}
}
+ if (taxon.getTaxonNodes().size() > 0){
+ acceptedTaxa.add(taxon);
+ }
setInputForRelatedTaxa(conversation, acceptedTaxa);
}else{
if(taxa.size() == 1){
Taxon taxon = taxa.iterator().next();
Set<TaxonNode> nodes = taxon.getTaxonNodes();
- TaxonNode taxonNode = ChooseFromMultipleTaxonNodesDialog.choose(nodes);
+ TaxonNode taxonNode = null;
+ if (nodes.size()>1){
+ taxonNode = ChooseFromMultipleTaxonNodesDialog.choose(nodes);
+ }else if (nodes.size()==1){
+ taxonNode = nodes.iterator().next();
+ }else{
+ MessagingUtils.warningDialog(INCORRECT_STATE,TaxonEditorInputE4.class,Messages.TaxonEditorInput_TAXON_NOT_IN_CLASSIFICATION);
+ }
init(taxonNode);
}else if(taxa.size() > 1){
Iterator<Taxon> taxonIterator = taxa.iterator();
return initiallySelectedTaxonBase;
}
- public Set<AbstractPostTaxonOperation> getOperations() {
- return operations;
- }
-
- public void setOperations(Set<AbstractPostTaxonOperation> operations) {
- this.operations = operations;
- }
-
- public void addOperation(AbstractPostTaxonOperation operation) {
+ public void addOperation(AbstractPostOperation operation) {
this.operations.add(operation);
}
}
toDeletes.clear();
for(AbstractPostOperation entry:operations){
- EditorUtil.executeOperation(entry,sync);
+ IStatus status = Status.CANCEL_STATUS;
+ final IAdaptable uiInfoAdapter = WorkspaceUndoUtil
+ .getUIInfoAdapter(AbstractUtility.getShell());
+ String operationlabel = entry.getLabel();
+ try {
+ entry.addContext(IOperationHistory.GLOBAL_UNDO_CONTEXT);
+ status = entry.execute(new NullProgressMonitor(), uiInfoAdapter);
+ } catch (ExecutionException e) {
+
+ MessagingUtils.operationDialog(AbstractUtility.class, e, TaxeditorStorePlugin.PLUGIN_ID, operationlabel, null);
+
+ }
+
+ String statusString = status.equals(Status.OK_STATUS) ? "completed"
+ : "cancelled";
+
+ IPostOperationEnabled postOperationEnabled = entry
+ .getPostOperationEnabled();
+ if (postOperationEnabled != null) {
+ postOperationEnabled.onComplete();
+ }
+
+
+ //AbstractUtility.executeOperation(entry,sync);
}
- operations.clear();
+ operations.clear();
for (Synonym syn: toSaveNewSynonyms){
for (HybridRelationship rel : syn.getName().getHybridChildRelations()){
// if (!rel.getParentName().isPersited()) {
CdmStore.getService(ITaxonNodeService.class).merge(taxonNode, true);
+
}
/**