1
|
package eu.etaxonomy.taxeditor.navigation.navigator.e4.handler;
|
2
|
|
3
|
import java.util.ArrayList;
|
4
|
import java.util.List;
|
5
|
import java.util.UUID;
|
6
|
|
7
|
import javax.inject.Named;
|
8
|
|
9
|
import org.eclipse.e4.core.di.annotations.CanExecute;
|
10
|
import org.eclipse.e4.core.di.annotations.Execute;
|
11
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
12
|
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
|
13
|
import org.eclipse.e4.ui.services.IServiceConstants;
|
14
|
import org.eclipse.jface.dialogs.MessageDialog;
|
15
|
import org.eclipse.jface.viewers.TreeSelection;
|
16
|
import org.eclipse.swt.widgets.Display;
|
17
|
import org.eclipse.swt.widgets.Shell;
|
18
|
|
19
|
import eu.etaxonomy.cdm.api.service.IDescriptionService;
|
20
|
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
|
21
|
import eu.etaxonomy.cdm.api.service.ITaxonService;
|
22
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
23
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
24
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
25
|
import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
|
26
|
import eu.etaxonomy.taxeditor.navigation.l10n.Messages;
|
27
|
import eu.etaxonomy.taxeditor.navigation.navigator.e4.TaxonNavigatorE4;
|
28
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
29
|
import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonNodeSelectionDialog;
|
30
|
|
31
|
public class MoveFactualDataHandlerE4 {
|
32
|
|
33
|
@Execute
|
34
|
public void execute(@Named(IServiceConstants.ACTIVE_SELECTION)TreeSelection selection,
|
35
|
@Named(IServiceConstants.ACTIVE_SHELL)Shell shell,
|
36
|
@Named(IServiceConstants.ACTIVE_PART)MPart activePart) {
|
37
|
|
38
|
TaxonNavigatorE4 taxonNavigator = (TaxonNavigatorE4) activePart.getObject();
|
39
|
|
40
|
if(taxonNavigator!=null){
|
41
|
Object object = selection.getFirstElement();
|
42
|
if(object instanceof TaxonNode){
|
43
|
TaxonNode taxonNode = HibernateProxyHelper.deproxy(object, TaxonNode.class);
|
44
|
final TaxonNode sourceTaxonNode = CdmStore.getService(ITaxonNodeService.class).load(taxonNode.getUuid());
|
45
|
if(NavigationUtil.isDirty(sourceTaxonNode)){
|
46
|
MessageDialog.openWarning(shell, Messages.MoveFactualDataHandler_UNSAVED_SOURCE, Messages.MoveFactualDataHandler_UNSAVED_SOURCE_MESSAGE);
|
47
|
return;
|
48
|
}
|
49
|
//reload to avoid session conflicts
|
50
|
Taxon taxon = HibernateProxyHelper.deproxy(CdmStore.getService(ITaxonService.class).load(sourceTaxonNode.getTaxon().getUuid()), Taxon.class);
|
51
|
if(taxon!=null){
|
52
|
// Choose the target taxon
|
53
|
List<UUID> excludeTaxa = new ArrayList<UUID>();
|
54
|
excludeTaxa.add(taxon.getUuid());
|
55
|
TaxonNode dialogTaxonNode = TaxonNodeSelectionDialog.select(shell,
|
56
|
taxonNavigator.getConversationHolder(),
|
57
|
Messages.MoveFactualDataHandler_CHOOSE_TAXON,
|
58
|
excludeTaxa,
|
59
|
sourceTaxonNode,
|
60
|
sourceTaxonNode.getClassification());
|
61
|
if (dialogTaxonNode == null) {
|
62
|
return;
|
63
|
}
|
64
|
//reload to avoid session conflicts
|
65
|
final TaxonNode targetTaxonNode = CdmStore.getService(ITaxonNodeService.class).load(dialogTaxonNode.getUuid());
|
66
|
if(NavigationUtil.isDirty(targetTaxonNode)){
|
67
|
MessageDialog.openWarning(shell, Messages.MoveFactualDataHandler_UNSAVED_TARGET, Messages.MoveFactualDataHandler_UNSAVED_TARGET_MESSAGE);
|
68
|
return;
|
69
|
}
|
70
|
CdmStore.getService(IDescriptionService.class).moveTaxonDescriptions(taxon.getUuid(),targetTaxonNode.getTaxon().getUuid());
|
71
|
|
72
|
taxonNavigator.getConversationHolder().bind();
|
73
|
taxonNavigator.getConversationHolder().commit();
|
74
|
|
75
|
Display.getDefault().asyncExec(new Runnable(){
|
76
|
|
77
|
@Override
|
78
|
public void run() {
|
79
|
//FIXME E4 refresh factual view via events or similar
|
80
|
// try {
|
81
|
// //close and re-open to refresh factual data view
|
82
|
// MultiPageTaxonEditor sourceEditor = (MultiPageTaxonEditor) EditorUtil.findEditorByTaxonNodeUuid(sourceTaxonNode.getUuid());
|
83
|
// MultiPageTaxonEditor targetEditor = (MultiPageTaxonEditor) EditorUtil.findEditorByTaxonNodeUuid(targetTaxonNode.getUuid());
|
84
|
// if(targetEditor != null){
|
85
|
// AbstractUtility.close(sourceEditor);
|
86
|
// AbstractUtility.close(targetEditor);
|
87
|
// }
|
88
|
// EditorUtil.openTaxonNodeE4(sourceTaxonNode.getUuid());
|
89
|
// EditorUtil.openTaxonNodeE4(targetTaxonNode.getUuid());
|
90
|
// } catch (PartInitException e) {
|
91
|
// MessagingUtils.error(this.getClass(), e);
|
92
|
// throw new RuntimeException(e);
|
93
|
// } catch (Exception e) {
|
94
|
// MessagingUtils.warningDialog(Messages.MoveFactualDataHandler_CREATE_FAILED, this, e.getMessage());
|
95
|
// }
|
96
|
}
|
97
|
|
98
|
});
|
99
|
}
|
100
|
}
|
101
|
}
|
102
|
}
|
103
|
|
104
|
@CanExecute
|
105
|
private boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)TreeSelection selection, MHandledMenuItem menuItem){
|
106
|
boolean canExecute = false;
|
107
|
canExecute = selection.getFirstElement() instanceof TaxonNode;
|
108
|
menuItem.setVisible(canExecute);
|
109
|
return canExecute;
|
110
|
}
|
111
|
|
112
|
}
|