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.service.ITermService;
|
27
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
28
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
29
|
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
|
30
|
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
|
31
|
import eu.etaxonomy.taxeditor.editor.view.concept.e4.ConceptViewPartE4;
|
32
|
import eu.etaxonomy.taxeditor.editor.view.concept.operation.CreateConceptRelationOperation;
|
33
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
34
|
import eu.etaxonomy.taxeditor.model.TaxonRelationshipTypeInverseContainer;
|
35
|
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
|
36
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
37
|
import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonSelectionDialog;
|
38
|
import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
|
39
|
|
40
|
/**
|
41
|
*
|
42
|
* @author pplitzner
|
43
|
* @date 21.08.2017
|
44
|
*
|
45
|
*/
|
46
|
public class CreateConceptRelationHandlerE4 {
|
47
|
|
48
|
@Execute
|
49
|
public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart,
|
50
|
@Optional@Named(IServiceConstants.ACTIVE_SHELL) Shell shell,
|
51
|
MHandledMenuItem menuItem,
|
52
|
UISynchronize sync) {
|
53
|
|
54
|
String commandId = menuItem.getCommand().getElementId();
|
55
|
UUID uuid = (UUID) menuItem.getTransientData().get(commandId+".taxonRelationshipType.uuid");
|
56
|
TaxonRelationshipType taxonRelationshipType = HibernateProxyHelper.deproxy(CdmStore.getService(ITermService.class).load(uuid), TaxonRelationshipType.class);
|
57
|
|
58
|
TaxonNameEditorE4 editor = null;
|
59
|
|
60
|
ConceptViewPartE4 conceptView = (ConceptViewPartE4) activePart.getObject();
|
61
|
|
62
|
Object e4WrappedPart = WorkbenchUtility.getE4WrappedPart(conceptView.getSelectionProvidingPart());
|
63
|
if(e4WrappedPart instanceof TaxonNameEditorE4){
|
64
|
editor = (TaxonNameEditorE4) e4WrappedPart;
|
65
|
|
66
|
IUndoContext undoContext = null;
|
67
|
|
68
|
Taxon taxon = null;
|
69
|
taxon = editor.getTaxon();
|
70
|
|
71
|
undoContext = editor.getUndoContext();
|
72
|
|
73
|
//FIXME should this also be enabled for bulk editor
|
74
|
// else if(activeEditor instanceof BulkEditor){
|
75
|
// BulkEditor bulkEditor = (BulkEditor)activeEditor;
|
76
|
// ISelection selection = bulkEditor.getSelectionProvider().getSelection();
|
77
|
// taxon = (Taxon) ((IStructuredSelection)selection).getFirstElement();
|
78
|
// undoContext = bulkEditor.getUndoContext();
|
79
|
// }
|
80
|
|
81
|
Taxon relatedConcept = TaxonSelectionDialog.selectTaxon(shell, taxon);
|
82
|
|
83
|
if(relatedConcept == null){
|
84
|
return;
|
85
|
}
|
86
|
boolean isInverse = taxonRelationshipType.getInverseLabel().isEmpty()?false:true;
|
87
|
TaxonRelationshipTypeInverseContainer typeInverseContainer = new TaxonRelationshipTypeInverseContainer(taxonRelationshipType, isInverse) ;
|
88
|
|
89
|
AbstractPostOperation<?> operation = new CreateConceptRelationOperation(menuItem.getLocalizedLabel(),
|
90
|
undoContext, taxon, relatedConcept, typeInverseContainer, conceptView);
|
91
|
AbstractUtility.executeOperation(operation, sync);
|
92
|
}
|
93
|
}
|
94
|
|
95
|
@CanExecute
|
96
|
public boolean canExecute(@Optional @Named(IServiceConstants.ACTIVE_PART) MPart activePart,
|
97
|
MHandledMenuItem menuItem){
|
98
|
boolean canExecute = false;
|
99
|
ConceptViewPartE4 conceptView = (ConceptViewPartE4) activePart.getObject();
|
100
|
|
101
|
Object e4WrappedPart = WorkbenchUtility.getE4WrappedPart(conceptView.getSelectionProvidingPart());
|
102
|
canExecute = e4WrappedPart instanceof TaxonNameEditorE4;
|
103
|
menuItem.setVisible(canExecute);
|
104
|
return canExecute;
|
105
|
}
|
106
|
}
|