1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
|
10
|
package eu.etaxonomy.taxeditor.editor.view.concept.e4.handler;
|
11
|
|
12
|
import java.util.UUID;
|
13
|
|
14
|
import javax.inject.Named;
|
15
|
|
16
|
import org.eclipse.core.commands.operations.IUndoContext;
|
17
|
import org.eclipse.e4.core.di.annotations.CanExecute;
|
18
|
import org.eclipse.e4.core.di.annotations.Execute;
|
19
|
import org.eclipse.e4.core.di.annotations.Optional;
|
20
|
import org.eclipse.e4.ui.di.UISynchronize;
|
21
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
22
|
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
|
23
|
import org.eclipse.e4.ui.services.IServiceConstants;
|
24
|
import org.eclipse.swt.widgets.Shell;
|
25
|
|
26
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
27
|
import eu.etaxonomy.cdm.api.service.ITermService;
|
28
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
29
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
30
|
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
|
31
|
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
|
32
|
import eu.etaxonomy.taxeditor.editor.view.concept.e4.ConceptViewPartE4;
|
33
|
import eu.etaxonomy.taxeditor.editor.view.concept.operation.CreateConceptRelationOperation;
|
34
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
35
|
import eu.etaxonomy.taxeditor.model.TaxonRelationshipTypeInverseContainer;
|
36
|
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
|
37
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
38
|
import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonBaseSelectionDialog;
|
39
|
import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
|
40
|
|
41
|
/**
|
42
|
*
|
43
|
* @author pplitzner
|
44
|
* @date 21.08.2017
|
45
|
*
|
46
|
*/
|
47
|
public class CreateConceptRelationHandlerE4 {
|
48
|
|
49
|
@Execute
|
50
|
public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart,
|
51
|
@Optional@Named(IServiceConstants.ACTIVE_SHELL) Shell shell,
|
52
|
MHandledMenuItem menuItem,
|
53
|
UISynchronize sync) {
|
54
|
|
55
|
String commandId = menuItem.getCommand().getElementId();
|
56
|
UUID uuid = (UUID) menuItem.getTransientData().get(commandId+".taxonRelationshipType.uuid");
|
57
|
TaxonRelationshipType taxonRelationshipType = HibernateProxyHelper.deproxy(CdmStore.getService(ITermService.class).load(uuid), TaxonRelationshipType.class);
|
58
|
|
59
|
TaxonNameEditorE4 editor = null;
|
60
|
|
61
|
ConceptViewPartE4 conceptView = (ConceptViewPartE4) activePart.getObject();
|
62
|
|
63
|
Object e4WrappedPart = WorkbenchUtility.getE4WrappedPart(conceptView.getSelectionProvidingPart());
|
64
|
if(e4WrappedPart instanceof TaxonNameEditorE4){
|
65
|
editor = (TaxonNameEditorE4) e4WrappedPart;
|
66
|
|
67
|
IUndoContext undoContext = null;
|
68
|
ConversationHolder conversationHolder = null;
|
69
|
Taxon taxon = null;
|
70
|
taxon = editor.getTaxon();
|
71
|
conversationHolder = editor.getConversationHolder();
|
72
|
undoContext = editor.getUndoContext();
|
73
|
|
74
|
//FIXME should this also be enabled for bulk editor
|
75
|
// else if(activeEditor instanceof BulkEditor){
|
76
|
// BulkEditor bulkEditor = (BulkEditor)activeEditor;
|
77
|
// ISelection selection = bulkEditor.getSelectionProvider().getSelection();
|
78
|
// taxon = (Taxon) ((IStructuredSelection)selection).getFirstElement();
|
79
|
// conversationHolder = bulkEditor.getConversationHolder();
|
80
|
// undoContext = bulkEditor.getUndoContext();
|
81
|
// }
|
82
|
|
83
|
Taxon relatedConcept = TaxonBaseSelectionDialog.selectTaxon(shell, //conversationHolder,
|
84
|
taxon);
|
85
|
|
86
|
|
87
|
if(relatedConcept == null){
|
88
|
return;
|
89
|
}
|
90
|
boolean isInverse = taxonRelationshipType.getInverseLabel().isEmpty()?false:true;
|
91
|
TaxonRelationshipTypeInverseContainer typeInverseContainer =new TaxonRelationshipTypeInverseContainer(taxonRelationshipType, isInverse) ;
|
92
|
|
93
|
|
94
|
AbstractPostOperation operation = new CreateConceptRelationOperation(menuItem.getLocalizedLabel(),
|
95
|
undoContext, taxon, relatedConcept, typeInverseContainer, conceptView);
|
96
|
AbstractUtility.executeOperation(operation, sync);
|
97
|
}
|
98
|
}
|
99
|
|
100
|
@CanExecute
|
101
|
public boolean canExecute(@Optional @Named(IServiceConstants.ACTIVE_PART) MPart activePart,
|
102
|
MHandledMenuItem menuItem){
|
103
|
boolean canExecute = false;
|
104
|
ConceptViewPartE4 conceptView = (ConceptViewPartE4) activePart.getObject();
|
105
|
|
106
|
Object e4WrappedPart = WorkbenchUtility.getE4WrappedPart(conceptView.getSelectionProvidingPart());
|
107
|
canExecute = e4WrappedPart instanceof TaxonNameEditorE4;
|
108
|
menuItem.setVisible(canExecute);
|
109
|
return canExecute;
|
110
|
}
|
111
|
}
|