Revision f82960da
Added by Katja Luther over 4 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/e4/handler/SwapSynonymAndAcceptedHandlerE4.java | ||
---|---|---|
26 | 26 |
|
27 | 27 |
import eu.etaxonomy.cdm.model.taxon.Synonym; |
28 | 28 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
29 |
import eu.etaxonomy.cdm.model.taxon.TaxonNode; |
|
29 | 30 |
import eu.etaxonomy.taxeditor.editor.EditorUtil; |
30 | 31 |
import eu.etaxonomy.taxeditor.editor.l10n.Messages; |
31 | 32 |
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4; |
... | ... | |
43 | 44 |
*/ |
44 | 45 |
public class SwapSynonymAndAcceptedHandlerE4 implements IPostOperationEnabled { |
45 | 46 |
|
46 |
private TaxonNameEditorE4 editor;
|
|
47 |
private Taxon taxon;
|
|
48 |
private EPartService partService;
|
|
49 |
private MPart activePart;
|
|
50 |
private MApplication application;
|
|
51 |
private EModelService modelService;
|
|
47 |
protected TaxonNameEditorE4 editor;
|
|
48 |
protected Taxon taxon;
|
|
49 |
protected EPartService partService;
|
|
50 |
protected MPart activePart;
|
|
51 |
protected MApplication application;
|
|
52 |
protected EModelService modelService;
|
|
52 | 53 |
|
53 | 54 |
@Execute |
54 | 55 |
public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart, |
... | ... | |
95 | 96 |
// Redraw existing editor |
96 | 97 |
// ((IPostOperationEnabled) editor).postOperation(null); |
97 | 98 |
|
98 |
editor.save(AbstractUtility.getMonitor()); |
|
99 |
// editor.save(AbstractUtility.getMonitor());
|
|
99 | 100 |
partService.hidePart(activePart); |
100 | 101 |
|
101 | 102 |
if (objectAffectedByOperation instanceof Taxon) { |
102 | 103 |
taxon = (Taxon) objectAffectedByOperation; |
103 | 104 |
} |
105 |
|
|
106 |
|
|
104 | 107 |
return true; |
105 | 108 |
} |
106 | 109 |
|
... | ... | |
111 | 114 |
@Override |
112 | 115 |
public void run() { |
113 | 116 |
try { |
114 |
EditorUtil.openTaxonBaseE4(taxon.getUuid(), modelService, partService, application); |
|
117 |
TaxonNode node; |
|
118 |
if (!taxon.getTaxonNodes().isEmpty()) { |
|
119 |
node = taxon.getTaxonNodes().iterator().next(); |
|
120 |
} else { |
|
121 |
node = null; |
|
122 |
} |
|
123 |
if (node != null){ |
|
124 |
EditorUtil.openTaxonNodeE4((node).getUuid(), modelService, partService, application); |
|
125 |
} |
|
115 | 126 |
} catch (Exception e) { |
116 | 127 |
MessagingUtils.warningDialog(Messages.SwapSynonymAndAcceptedHandler_COULD_NOT_OPEN, this, |
117 | 128 |
e.getMessage()); |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/e4/handler/SwapSynonymAndAcceptedSetNameInSourceHandlerE5.java | ||
---|---|---|
11 | 11 |
|
12 | 12 |
import javax.inject.Named; |
13 | 13 |
|
14 |
import org.eclipse.e4.core.di.annotations.CanExecute; |
|
15 | 14 |
import org.eclipse.e4.core.di.annotations.Execute; |
16 | 15 |
import org.eclipse.e4.ui.di.UISynchronize; |
17 | 16 |
import org.eclipse.e4.ui.model.application.MApplication; |
... | ... | |
21 | 20 |
import org.eclipse.e4.ui.workbench.modeling.EModelService; |
22 | 21 |
import org.eclipse.e4.ui.workbench.modeling.EPartService; |
23 | 22 |
import org.eclipse.jface.viewers.IStructuredSelection; |
24 |
import org.eclipse.swt.widgets.Display; |
|
25 | 23 |
import org.eclipse.swt.widgets.Shell; |
26 | 24 |
|
27 | 25 |
import eu.etaxonomy.cdm.model.taxon.Synonym; |
28 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
|
29 | 26 |
import eu.etaxonomy.taxeditor.editor.EditorUtil; |
30 |
import eu.etaxonomy.taxeditor.editor.l10n.Messages; |
|
31 | 27 |
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4; |
32 |
import eu.etaxonomy.taxeditor.editor.name.handler.NameEditorMenuPropertyTester; |
|
33 | 28 |
import eu.etaxonomy.taxeditor.editor.name.operation.SwapSynonymAndAcceptedOperation; |
34 | 29 |
import eu.etaxonomy.taxeditor.model.AbstractUtility; |
35 |
import eu.etaxonomy.taxeditor.model.MessagingUtils; |
|
36 | 30 |
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled; |
37 | 31 |
|
38 | 32 |
/** |
... | ... | |
41 | 35 |
* @since Aug 28, 2017 |
42 | 36 |
* |
43 | 37 |
*/ |
44 |
public class SwapSynonymAndAcceptedSetNameInSourceHandlerE5 implements IPostOperationEnabled { |
|
38 |
public class SwapSynonymAndAcceptedSetNameInSourceHandlerE5 extends SwapSynonymAndAcceptedHandlerE4 implements IPostOperationEnabled {
|
|
45 | 39 |
|
46 |
private TaxonNameEditorE4 editor; |
|
47 |
private Taxon taxon; |
|
48 |
private EPartService partService; |
|
49 |
private MPart activePart; |
|
50 |
private MApplication application; |
|
51 |
private EModelService modelService; |
|
52 | 40 |
|
41 |
|
|
42 |
|
|
43 |
@Override |
|
53 | 44 |
@Execute |
54 | 45 |
public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart, |
55 | 46 |
@Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection, |
... | ... | |
78 | 69 |
|
79 | 70 |
} |
80 | 71 |
|
81 |
@CanExecute |
|
82 |
public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection, |
|
83 |
MHandledMenuItem menuItem){ |
|
84 |
boolean canExecute = false; |
|
85 |
if(selection.size()==1){ |
|
86 |
Object selectedElement = selection.getFirstElement(); |
|
87 |
canExecute = NameEditorMenuPropertyTester.isSynonym(selectedElement); |
|
88 |
} |
|
89 |
menuItem.setVisible(canExecute); |
|
90 |
return canExecute; |
|
91 |
} |
|
92 |
|
|
93 |
@Override |
|
94 |
public boolean postOperation(Object objectAffectedByOperation) { |
|
95 |
// Redraw existing editor |
|
96 |
// ((IPostOperationEnabled) editor).postOperation(null); |
|
97 | 72 |
|
98 |
editor.save(AbstractUtility.getMonitor()); |
|
99 |
partService.hidePart(activePart); |
|
100 |
|
|
101 |
if (objectAffectedByOperation instanceof Taxon) { |
|
102 |
taxon = (Taxon) objectAffectedByOperation; |
|
103 |
} |
|
104 |
return true; |
|
105 |
} |
|
106 |
|
|
107 |
@Override |
|
108 |
public boolean onComplete() { |
|
109 |
Display display = Display.getCurrent(); |
|
110 |
display.asyncExec(new Runnable() { |
|
111 |
@Override |
|
112 |
public void run() { |
|
113 |
try { |
|
114 |
EditorUtil.openTaxonBaseE4(taxon.getUuid(), modelService, partService, application); |
|
115 |
} catch (Exception e) { |
|
116 |
MessagingUtils.warningDialog(Messages.SwapSynonymAndAcceptedHandler_COULD_NOT_OPEN, this, |
|
117 |
e.getMessage()); |
|
118 |
} |
|
119 |
|
|
120 |
} |
|
121 |
}); |
|
122 |
return true; |
|
123 |
} |
|
124 | 73 |
} |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/operation/SwapSynonymAndAcceptedOperation.java | ||
---|---|---|
9 | 9 |
|
10 | 10 |
package eu.etaxonomy.taxeditor.editor.name.operation; |
11 | 11 |
|
12 |
import java.util.ArrayList; |
|
13 |
import java.util.List; |
|
14 |
import java.util.UUID; |
|
15 |
|
|
12 | 16 |
import org.eclipse.core.commands.ExecutionException; |
13 | 17 |
import org.eclipse.core.commands.operations.IUndoContext; |
14 | 18 |
import org.eclipse.core.runtime.IAdaptable; |
15 | 19 |
import org.eclipse.core.runtime.IProgressMonitor; |
16 | 20 |
import org.eclipse.core.runtime.IStatus; |
17 | 21 |
|
22 |
import eu.etaxonomy.cdm.api.service.ITaxonNodeService; |
|
18 | 23 |
import eu.etaxonomy.cdm.api.service.ITaxonService; |
19 | 24 |
import eu.etaxonomy.cdm.api.service.UpdateResult; |
25 |
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper; |
|
20 | 26 |
import eu.etaxonomy.cdm.model.taxon.Synonym; |
21 | 27 |
import eu.etaxonomy.cdm.model.taxon.SynonymType; |
22 | 28 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
29 |
import eu.etaxonomy.cdm.model.taxon.TaxonNode; |
|
23 | 30 |
import eu.etaxonomy.taxeditor.editor.l10n.Messages; |
24 | 31 |
import eu.etaxonomy.taxeditor.model.MessagingUtils; |
25 | 32 |
import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation; |
... | ... | |
39 | 46 |
// TODO store the old relationship for undo reasons |
40 | 47 |
private SynonymType synonymType; |
41 | 48 |
|
49 |
private List<TaxonNode> nodes; |
|
50 |
|
|
42 | 51 |
private boolean setNameInSource; |
43 | 52 |
|
44 | 53 |
/** |
... | ... | |
56 | 65 |
super(Messages.SwapSynonymAndAcceptedOperation_SWAP_SYN_ACC_TAXON, undoContext, taxon, postOperationEnabled, cdmEntitySessionEnabled); |
57 | 66 |
this.setNameInSource = setNameInSource; |
58 | 67 |
this.synonym = synonym; |
68 |
this.nodes = new ArrayList(taxon.getTaxonNodes()); |
|
69 |
|
|
70 |
|
|
59 | 71 |
} |
60 | 72 |
|
61 | 73 |
/** {@inheritDoc} */ |
... | ... | |
66 | 78 |
monitor.worked(20); |
67 | 79 |
|
68 | 80 |
UpdateResult result = CdmStore.getService(ITaxonService.class).swapSynonymAndAcceptedTaxon(synonym.getUuid(), element.getUuid(), setNameInSource);//TODO |
81 |
//Taxon taxon = (Taxon)result.getCdmEntity(); |
|
82 |
List<String> propertyPath = new ArrayList<>(); |
|
83 |
propertyPath.add("synonyms"); |
|
84 |
Taxon taxon = (Taxon) CdmStore.getService(ITaxonService.class).load(result.getCdmEntity().getUuid(), propertyPath); |
|
85 |
List<UUID> nodeUuids = new ArrayList<>(); |
|
86 |
for (TaxonNode node: nodes){ |
|
87 |
nodeUuids.add(node.getUuid()); |
|
88 |
} |
|
89 |
//nodes = CdmStore.getService(ITaxonNodeService.class).load(nodeUuids, null); |
|
90 |
List<TaxonNode> parents = new ArrayList<>(); |
|
91 |
for (TaxonNode node: nodes){ |
|
92 |
TaxonNode parent = HibernateProxyHelper.deproxy(node.getParent(), TaxonNode.class); |
|
93 |
TaxonNode newTaxonNode = parent.addChildTaxon(taxon, null, null); |
|
94 |
parents.add(parent); |
|
95 |
CdmStore.getService(ITaxonNodeService.class).saveNewTaxonNode(newTaxonNode); |
|
96 |
|
|
97 |
} |
|
69 | 98 |
|
70 | 99 |
monitor.worked(40); |
71 | 100 |
|
72 |
return postExecute(element);
|
|
101 |
return postExecute(taxon);
|
|
73 | 102 |
} |
74 | 103 |
|
75 | 104 |
/** {@inheritDoc} */ |
Also available in: Unified diff
fix #8526: fix problem swap synonym and taxon