Revision cedc4ff1
Added by Katja Luther about 6 years ago
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/e4/handler/RemotingChangeAcceptedTaxonToSynonymHandlerE4.java | ||
---|---|---|
23 | 23 |
import org.eclipse.jface.viewers.TreeSelection; |
24 | 24 |
import org.eclipse.swt.widgets.Shell; |
25 | 25 |
|
26 |
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
|
26 |
import eu.etaxonomy.cdm.api.service.IClassificationService;
|
|
27 | 27 |
import eu.etaxonomy.cdm.model.taxon.Classification; |
28 | 28 |
import eu.etaxonomy.cdm.model.taxon.TaxonNode; |
29 |
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto; |
|
29 | 30 |
import eu.etaxonomy.taxeditor.editor.EditorUtil; |
30 | 31 |
import eu.etaxonomy.taxeditor.navigation.l10n.Messages; |
31 | 32 |
import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigatorLabels; |
32 | 33 |
import eu.etaxonomy.taxeditor.navigation.navigator.operation.RemotingChangeAcceptedTaxonToSynonymOperation; |
33 | 34 |
import eu.etaxonomy.taxeditor.operation.e4.RemotingCdmHandlerE4; |
35 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
|
34 | 36 |
import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonNodeSelectionDialog; |
35 | 37 |
|
36 | 38 |
/** |
... | ... | |
42 | 44 |
public class RemotingChangeAcceptedTaxonToSynonymHandlerE4 extends RemotingCdmHandlerE4 { |
43 | 45 |
|
44 | 46 |
|
45 |
private Set<TaxonNode> oldTaxonNodes = new HashSet(); |
|
47 |
private Set<TaxonNodeDto> oldTaxonNodes = new HashSet();
|
|
46 | 48 |
private Classification classification; |
47 | 49 |
|
48 | 50 |
public RemotingChangeAcceptedTaxonToSynonymHandlerE4() { |
... | ... | |
74 | 76 |
oldTaxonNodes = new HashSet<>(); |
75 | 77 |
while(it.hasNext()){ |
76 | 78 |
Object obj = it.next(); |
77 |
if(obj instanceof TaxonNode && ((TaxonNode)obj).hasTaxon()) {
|
|
78 |
oldTaxonNodes.add((TaxonNode)obj); |
|
79 |
nextClassification = HibernateProxyHelper.deproxy(((TaxonNode)obj).getClassification(), Classification.class);
|
|
79 |
if(obj instanceof TaxonNodeDto) {
|
|
80 |
oldTaxonNodes.add((TaxonNodeDto)obj);
|
|
81 |
nextClassification = CdmStore.getService(IClassificationService.class).find(((TaxonNodeDto)obj).getClassificationUUID());
|
|
80 | 82 |
if (classification == null){ |
81 | 83 |
classification = nextClassification; |
82 | 84 |
}else if (!classification.equals(nextClassification)){ |
... | ... | |
95 | 97 |
TaxonNavigatorLabels.SELECTED_OBJECT_NOT_TREE_NODE_MESSAGE); |
96 | 98 |
} |
97 | 99 |
// check that the source taxon node does not have children |
98 |
if(((TaxonNode)obj).getCountChildren() > 0) {
|
|
100 |
if(((TaxonNodeDto)obj).getTaxonomicChildrenCount() > 0) {
|
|
99 | 101 |
return new Status(IStatus.ERROR, |
100 | 102 |
"unknown", //$NON-NLS-1$ |
101 | 103 |
TaxonNavigatorLabels.SOURCE_TAXON_HAS_CHILDREN_MESSAGE); |
102 |
|
|
104 |
|
|
103 | 105 |
} |
104 |
|
|
106 |
|
|
105 | 107 |
// check if corresponding name editor is closed |
106 |
EditorUtil.closeObsoleteEditor((TaxonNode)obj, partService); |
|
108 |
EditorUtil.closeObsoleteEditor((TaxonNodeDto)obj, partService);
|
|
107 | 109 |
} |
108 | 110 |
return Status.OK_STATUS; |
109 | 111 |
} |
... | ... | |
114 | 116 |
MPart activePart, |
115 | 117 |
MHandledMenuItem menuItem) { |
116 | 118 |
List<UUID> excludeTaxa = new ArrayList<UUID>(); |
117 |
for (TaxonNode oldNode:oldTaxonNodes){ |
|
118 |
excludeTaxa.add(oldNode.getTaxon().getUuid());
|
|
119 |
for (TaxonNodeDto oldNode:oldTaxonNodes){
|
|
120 |
excludeTaxa.add(oldNode.getTaxonUuid()); |
|
119 | 121 |
} |
120 | 122 |
TaxonNode newAcceptedTaxonNode = TaxonNodeSelectionDialog.select(shell, |
121 | 123 |
// new ConversationHolderMock(), |
122 | 124 |
Messages.RemotingChangeAcceptedTaxonToSynonymHandler_CHOOSE_TAXON, |
123 | 125 |
excludeTaxa, |
124 | 126 |
null, |
125 |
classification); |
|
127 |
classification.getUuid());
|
|
126 | 128 |
|
127 | 129 |
if (newAcceptedTaxonNode == null) { |
128 | 130 |
return null; |
129 | 131 |
} |
130 | 132 |
Set<UUID> nodeUuids = new HashSet(); |
131 |
for (TaxonNode node: oldTaxonNodes){ |
|
133 |
for (TaxonNodeDto node: oldTaxonNodes){
|
|
132 | 134 |
nodeUuids.add(node.getUuid()); |
133 | 135 |
} |
134 | 136 |
RemotingChangeAcceptedTaxonToSynonymOperation rcattso = |
... | ... | |
143 | 145 |
@CanExecute |
144 | 146 |
private boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)TreeSelection selection, MHandledMenuItem menuItem){ |
145 | 147 |
boolean canExecute = false; |
146 |
canExecute = selection.getFirstElement() instanceof TaxonNode |
|
147 |
&& ((TaxonNode) selection.getFirstElement()).getTaxon()!=null; |
|
148 |
canExecute = selection.getFirstElement() instanceof TaxonNodeDto; |
|
148 | 149 |
menuItem.setVisible(canExecute); |
149 | 150 |
return canExecute; |
150 | 151 |
} |
Also available in: Unified diff
ref #2380: implement usage of Dto for taxon navigator