Revision 84a43ef0
Added by U-BGBM\k.luther over 8 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/handler/MoveDescriptionElementsHandler.java | ||
---|---|---|
1 | 1 |
// $Id$ |
2 | 2 |
/** |
3 | 3 |
* Copyright (C) 2007 EDIT |
4 |
* European Distributed Institute of Taxonomy
|
|
4 |
* European Distributed Institute of Taxonomy |
|
5 | 5 |
* http://www.e-taxonomy.eu |
6 |
*
|
|
6 |
* |
|
7 | 7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
8 | 8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
9 | 9 |
*/ |
... | ... | |
25 | 25 |
import org.eclipse.ui.handlers.HandlerUtil; |
26 | 26 |
|
27 | 27 |
import eu.etaxonomy.cdm.api.service.IDescriptionService; |
28 |
import eu.etaxonomy.cdm.api.service.ITaxonService; |
|
29 | 28 |
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper; |
30 | 29 |
import eu.etaxonomy.cdm.model.common.Annotation; |
31 | 30 |
import eu.etaxonomy.cdm.model.common.AnnotationType; |
... | ... | |
34 | 33 |
import eu.etaxonomy.cdm.model.description.DescriptionBase; |
35 | 34 |
import eu.etaxonomy.cdm.model.description.DescriptionElementBase; |
36 | 35 |
import eu.etaxonomy.cdm.model.description.TaxonDescription; |
36 |
import eu.etaxonomy.cdm.model.taxon.Classification; |
|
37 | 37 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
38 | 38 |
import eu.etaxonomy.cdm.model.taxon.TaxonNode; |
39 | 39 |
import eu.etaxonomy.taxeditor.editor.EditorUtil; |
40 | 40 |
import eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor; |
41 | 41 |
import eu.etaxonomy.taxeditor.editor.Page; |
42 | 42 |
import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor; |
43 |
import eu.etaxonomy.taxeditor.editor.view.descriptive.DescriptiveViewPart; |
|
44 | 43 |
import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.MoveDescriptionElementsOperation; |
45 | 44 |
import eu.etaxonomy.taxeditor.model.AbstractUtility; |
46 | 45 |
import eu.etaxonomy.taxeditor.model.FeatureNodeContainer; |
... | ... | |
48 | 47 |
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation; |
49 | 48 |
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled; |
50 | 49 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
51 |
import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonBaseSelectionDialog; |
|
52 | 50 |
import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonNodeSelectionDialog; |
53 | 51 |
|
54 | 52 |
|
... | ... | |
65 | 63 |
*/ |
66 | 64 |
@Override |
67 | 65 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
68 |
|
|
66 |
|
|
69 | 67 |
// ConversationHolder conversation = CdmStore.createConversation(); |
70 | 68 |
editor = (TaxonNameEditor) EditorUtil.getActiveEditorPage(Page.NAME); |
71 | 69 |
ISelection selection = HandlerUtil.getCurrentSelection(event); |
72 |
|
|
70 |
Taxon actualTaxon= null; |
|
73 | 71 |
if(selection instanceof IStructuredSelection){ |
74 | 72 |
|
75 | 73 |
IStructuredSelection structuredSelection = (IStructuredSelection) selection; |
76 |
|
|
74 |
|
|
77 | 75 |
List<DescriptionElementBase> elements = new ArrayList<DescriptionElementBase>(); |
78 |
|
|
76 |
|
|
79 | 77 |
for(Object element : structuredSelection.toArray()){ |
80 | 78 |
if(element instanceof DescriptionElementBase){ |
81 | 79 |
UUID uuid = ((DescriptionElementBase) element).getUuid(); |
82 |
|
|
80 |
|
|
83 | 81 |
elements.add(CdmStore.getService(IDescriptionService.class).loadDescriptionElement(uuid, null)); |
84 | 82 |
} else if(element instanceof FeatureNodeContainer){ |
85 | 83 |
for(DescriptionElementBase de : ((FeatureNodeContainer)element).getDescriptionElements()){ |
86 | 84 |
elements.add( |
87 |
(DescriptionElementBase)CdmStore.getService(IDescriptionService.class).loadDescriptionElement(de.getUuid(), null)
|
|
85 |
CdmStore.getService(IDescriptionService.class).loadDescriptionElement(de.getUuid(), null) |
|
88 | 86 |
); |
89 | 87 |
} |
90 | 88 |
} |
91 | 89 |
} |
92 |
|
|
90 |
|
|
93 | 91 |
if(elements.size() == 0){ |
94 | 92 |
return null; |
95 | 93 |
} |
... | ... | |
97 | 95 |
List<UUID> excludeTaxa = new ArrayList<UUID>(); |
98 | 96 |
if (description.isInstanceOf(TaxonDescription.class)){ |
99 | 97 |
TaxonDescription taxonDescription = HibernateProxyHelper.deproxy(description, TaxonDescription.class); |
100 |
Taxon actualTaxon = taxonDescription.getTaxon();
|
|
98 |
actualTaxon = taxonDescription.getTaxon(); |
|
101 | 99 |
excludeTaxa.add(actualTaxon.getUuid()); |
102 | 100 |
} |
103 |
|
|
104 |
|
|
101 |
Classification classification = null; |
|
102 |
if (actualTaxon != null){ |
|
103 |
if (!actualTaxon.getTaxonNodes().isEmpty() && actualTaxon.getTaxonNodes().size() ==1){ |
|
104 |
classification = actualTaxon.getTaxonNodes().iterator().next().getClassification(); |
|
105 |
} |
|
106 |
} |
|
105 | 107 |
TaxonNode newAcceptedTaxonNode = TaxonNodeSelectionDialog.select(HandlerUtil.getActiveShell(event), |
106 | 108 |
editor.getConversationHolder(), |
107 | 109 |
"Choose the accepted taxon", |
108 | 110 |
excludeTaxa, |
109 |
null, |
|
110 |
null); |
|
111 |
Taxon targetTaxon = newAcceptedTaxonNode.getTaxon(); |
|
112 |
|
|
113 |
if(targetTaxon == null){ |
|
114 |
// canceled |
|
115 |
return null; |
|
116 |
} |
|
117 |
newAcceptedTaxonNodeUuid = newAcceptedTaxonNode.getUuid(); |
|
118 |
TaxonDescription targetDescription = TaxonDescription.NewInstance(targetTaxon); |
|
119 |
String moveMessage = String.format("Elements moved from %s", EditorUtil.getActiveMultiPageTaxonEditor().getTaxon()); |
|
120 |
targetDescription.setTitleCache(moveMessage, true); |
|
121 |
Annotation annotation = Annotation.NewInstance(moveMessage, Language.getDefaultLanguage()); |
|
122 |
annotation.setAnnotationType(AnnotationType.TECHNICAL()); |
|
123 |
targetDescription.addAnnotation(annotation); |
|
124 |
|
|
125 |
try { |
|
126 |
AbstractPostOperation operation = new MoveDescriptionElementsOperation( |
|
127 |
event.getCommand().getName(), EditorUtil.getUndoContext(), |
|
128 |
targetDescription, elements, false, this); |
|
129 |
|
|
130 |
EditorUtil.executeOperation(operation); |
|
131 |
|
|
132 |
//CdmStore.getService(ITaxonService.class).saveOrUpdate(targetTaxon); |
|
133 |
|
|
134 |
} catch (NotDefinedException e) { |
|
135 |
MessagingUtils.error(getClass(), e); |
|
111 |
null,classification |
|
112 |
); |
|
113 |
if (newAcceptedTaxonNode != null){ |
|
114 |
Taxon targetTaxon = newAcceptedTaxonNode.getTaxon(); |
|
115 |
|
|
116 |
if(targetTaxon == null){ |
|
117 |
// canceled |
|
118 |
return null; |
|
119 |
} |
|
120 |
newAcceptedTaxonNodeUuid = newAcceptedTaxonNode.getUuid(); |
|
121 |
TaxonDescription targetDescription = TaxonDescription.NewInstance(targetTaxon); |
|
122 |
String moveMessage = String.format("Elements moved from %s", EditorUtil.getActiveMultiPageTaxonEditor().getTaxon()); |
|
123 |
targetDescription.setTitleCache(moveMessage, true); |
|
124 |
Annotation annotation = Annotation.NewInstance(moveMessage, Language.getDefaultLanguage()); |
|
125 |
annotation.setAnnotationType(AnnotationType.TECHNICAL()); |
|
126 |
targetDescription.addAnnotation(annotation); |
|
127 |
|
|
128 |
try { |
|
129 |
AbstractPostOperation operation = new MoveDescriptionElementsOperation( |
|
130 |
event.getCommand().getName(), EditorUtil.getUndoContext(), |
|
131 |
targetDescription, elements, false, this); |
|
132 |
|
|
133 |
EditorUtil.executeOperation(operation); |
|
134 |
|
|
135 |
//CdmStore.getService(ITaxonService.class).saveOrUpdate(targetTaxon); |
|
136 |
|
|
137 |
} catch (NotDefinedException e) { |
|
138 |
MessagingUtils.error(getClass(), e); |
|
139 |
} |
|
136 | 140 |
} |
137 | 141 |
} |
138 |
|
|
142 |
|
|
139 | 143 |
return null; |
140 | 144 |
} |
141 | 145 |
|
... | ... | |
145 | 149 |
/** {@inheritDoc} */ |
146 | 150 |
@Override |
147 | 151 |
public boolean postOperation(CdmBase objectAffectedByOperation) { |
148 |
|
|
152 |
|
|
149 | 153 |
editor.getConversationHolder().bind(); |
150 | 154 |
editor.getConversationHolder().commit(true); |
151 | 155 |
Display.getDefault().asyncExec(new Runnable(){ |
152 |
|
|
156 |
|
|
157 |
@Override |
|
153 | 158 |
public void run() { |
154 | 159 |
//AbstractUtility.close(editor.getMultiPageTaxonEditor()); |
155 | 160 |
|
... | ... | |
178 | 183 |
// TODO Auto-generated method stub |
179 | 184 |
return false; |
180 | 185 |
} |
181 |
|
|
186 |
|
|
182 | 187 |
} |
Also available in: Unified diff
fixing #5150