import eu.etaxonomy.cdm.model.taxon.Synonym;
import eu.etaxonomy.cdm.model.taxon.Taxon;
+import eu.etaxonomy.cdm.model.taxon.TaxonNode;
import eu.etaxonomy.taxeditor.editor.EditorUtil;
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
*/
public class SwapSynonymAndAcceptedHandlerE4 implements IPostOperationEnabled {
- private TaxonNameEditorE4 editor;
- private Taxon taxon;
- private EPartService partService;
- private MPart activePart;
- private MApplication application;
- private EModelService modelService;
+ protected TaxonNameEditorE4 editor;
+ protected Taxon taxon;
+ protected EPartService partService;
+ protected MPart activePart;
+ protected MApplication application;
+ protected EModelService modelService;
@Execute
public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart,
// Redraw existing editor
// ((IPostOperationEnabled) editor).postOperation(null);
- editor.save(AbstractUtility.getMonitor());
+ // editor.save(AbstractUtility.getMonitor());
partService.hidePart(activePart);
if (objectAffectedByOperation instanceof Taxon) {
taxon = (Taxon) objectAffectedByOperation;
}
+
+
return true;
}
@Override
public void run() {
try {
- EditorUtil.openTaxonBaseE4(taxon.getUuid(), modelService, partService, application);
+ TaxonNode node;
+ if (!taxon.getTaxonNodes().isEmpty()) {
+ node = taxon.getTaxonNodes().iterator().next();
+ } else {
+ node = null;
+ }
+ if (node != null){
+ EditorUtil.openTaxonNodeE4((node).getUuid(), modelService, partService, application);
+ }
} catch (Exception e) {
MessagingUtils.warningDialog(Messages.SwapSynonymAndAcceptedHandler_COULD_NOT_OPEN, this,
e.getMessage());
import javax.inject.Named;
-import org.eclipse.e4.core.di.annotations.CanExecute;
import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.e4.ui.di.UISynchronize;
import org.eclipse.e4.ui.model.application.MApplication;
import org.eclipse.e4.ui.workbench.modeling.EModelService;
import org.eclipse.e4.ui.workbench.modeling.EPartService;
import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import eu.etaxonomy.cdm.model.taxon.Synonym;
-import eu.etaxonomy.cdm.model.taxon.Taxon;
import eu.etaxonomy.taxeditor.editor.EditorUtil;
-import eu.etaxonomy.taxeditor.editor.l10n.Messages;
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
-import eu.etaxonomy.taxeditor.editor.name.handler.NameEditorMenuPropertyTester;
import eu.etaxonomy.taxeditor.editor.name.operation.SwapSynonymAndAcceptedOperation;
import eu.etaxonomy.taxeditor.model.AbstractUtility;
-import eu.etaxonomy.taxeditor.model.MessagingUtils;
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
/**
* @since Aug 28, 2017
*
*/
-public class SwapSynonymAndAcceptedSetNameInSourceHandlerE5 implements IPostOperationEnabled {
+public class SwapSynonymAndAcceptedSetNameInSourceHandlerE5 extends SwapSynonymAndAcceptedHandlerE4 implements IPostOperationEnabled {
- private TaxonNameEditorE4 editor;
- private Taxon taxon;
- private EPartService partService;
- private MPart activePart;
- private MApplication application;
- private EModelService modelService;
+
+
+ @Override
@Execute
public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart,
@Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection,
}
- @CanExecute
- public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
- MHandledMenuItem menuItem){
- boolean canExecute = false;
- if(selection.size()==1){
- Object selectedElement = selection.getFirstElement();
- canExecute = NameEditorMenuPropertyTester.isSynonym(selectedElement);
- }
- menuItem.setVisible(canExecute);
- return canExecute;
- }
-
- @Override
- public boolean postOperation(Object objectAffectedByOperation) {
- // Redraw existing editor
- // ((IPostOperationEnabled) editor).postOperation(null);
- editor.save(AbstractUtility.getMonitor());
- partService.hidePart(activePart);
-
- if (objectAffectedByOperation instanceof Taxon) {
- taxon = (Taxon) objectAffectedByOperation;
- }
- return true;
- }
-
- @Override
- public boolean onComplete() {
- Display display = Display.getCurrent();
- display.asyncExec(new Runnable() {
- @Override
- public void run() {
- try {
- EditorUtil.openTaxonBaseE4(taxon.getUuid(), modelService, partService, application);
- } catch (Exception e) {
- MessagingUtils.warningDialog(Messages.SwapSynonymAndAcceptedHandler_COULD_NOT_OPEN, this,
- e.getMessage());
- }
-
- }
- });
- return true;
- }
}
package eu.etaxonomy.taxeditor.editor.name.operation;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.operations.IUndoContext;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
+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.hibernate.HibernateProxyHelper;
import eu.etaxonomy.cdm.model.taxon.Synonym;
import eu.etaxonomy.cdm.model.taxon.SynonymType;
import eu.etaxonomy.cdm.model.taxon.Taxon;
+import eu.etaxonomy.cdm.model.taxon.TaxonNode;
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
import eu.etaxonomy.taxeditor.model.MessagingUtils;
import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
// TODO store the old relationship for undo reasons
private SynonymType synonymType;
+ private List<TaxonNode> nodes;
+
private boolean setNameInSource;
/**
super(Messages.SwapSynonymAndAcceptedOperation_SWAP_SYN_ACC_TAXON, undoContext, taxon, postOperationEnabled, cdmEntitySessionEnabled);
this.setNameInSource = setNameInSource;
this.synonym = synonym;
+ this.nodes = new ArrayList(taxon.getTaxonNodes());
+
+
}
/** {@inheritDoc} */
monitor.worked(20);
UpdateResult result = CdmStore.getService(ITaxonService.class).swapSynonymAndAcceptedTaxon(synonym.getUuid(), element.getUuid(), setNameInSource);//TODO
+ //Taxon taxon = (Taxon)result.getCdmEntity();
+ List<String> propertyPath = new ArrayList<>();
+ propertyPath.add("synonyms");
+ Taxon taxon = (Taxon) CdmStore.getService(ITaxonService.class).load(result.getCdmEntity().getUuid(), propertyPath);
+ List<UUID> nodeUuids = new ArrayList<>();
+ for (TaxonNode node: nodes){
+ nodeUuids.add(node.getUuid());
+ }
+ //nodes = CdmStore.getService(ITaxonNodeService.class).load(nodeUuids, null);
+ List<TaxonNode> parents = new ArrayList<>();
+ for (TaxonNode node: nodes){
+ TaxonNode parent = HibernateProxyHelper.deproxy(node.getParent(), TaxonNode.class);
+ TaxonNode newTaxonNode = parent.addChildTaxon(taxon, null, null);
+ parents.add(parent);
+ CdmStore.getService(ITaxonNodeService.class).saveNewTaxonNode(newTaxonNode);
+
+ }
monitor.worked(40);
- return postExecute(element);
+ return postExecute(taxon);
}
/** {@inheritDoc} */