4 package eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.e4
.handler
;
6 import java
.util
.ArrayList
;
7 import java
.util
.HashSet
;
10 import java
.util
.UUID
;
12 import javax
.inject
.Named
;
14 import org
.eclipse
.e4
.core
.di
.annotations
.CanExecute
;
15 import org
.eclipse
.e4
.core
.di
.annotations
.Execute
;
16 import org
.eclipse
.e4
.core
.di
.annotations
.Optional
;
17 import org
.eclipse
.e4
.ui
.di
.UISynchronize
;
18 import org
.eclipse
.e4
.ui
.model
.application
.MApplication
;
19 import org
.eclipse
.e4
.ui
.model
.application
.ui
.basic
.MPart
;
20 import org
.eclipse
.e4
.ui
.model
.application
.ui
.menu
.MHandledMenuItem
;
21 import org
.eclipse
.e4
.ui
.model
.application
.ui
.menu
.MMenuItem
;
22 import org
.eclipse
.e4
.ui
.services
.IServiceConstants
;
23 import org
.eclipse
.e4
.ui
.workbench
.modeling
.EModelService
;
24 import org
.eclipse
.e4
.ui
.workbench
.modeling
.EPartService
;
25 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
26 import org
.eclipse
.jface
.viewers
.ISelection
;
27 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
28 import org
.eclipse
.swt
.widgets
.Display
;
29 import org
.eclipse
.swt
.widgets
.Shell
;
31 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
32 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionBase
;
33 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
34 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
35 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
36 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
37 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
38 import eu
.etaxonomy
.taxeditor
.editor
.l10n
.Messages
;
39 import eu
.etaxonomy
.taxeditor
.editor
.name
.e4
.TaxonNameEditorE4
;
40 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.e4
.FactualDataPartE4
;
41 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.operation
.MoveDescriptionToOtherTaxonOperation
;
42 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
43 import eu
.etaxonomy
.taxeditor
.model
.FeatureNodeContainer
;
44 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
45 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
46 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
.TaxonNodeSelectionDialog
;
47 import eu
.etaxonomy
.taxeditor
.workbench
.WorkbenchUtility
;
55 public class MoveDescriptionToOtherTaxonHandlerE4
implements IPostOperationEnabled
{
57 private MoveDescriptionToOtherTaxonOperation operation
;
59 private UUID newAcceptedTaxonNodeUuid
;
60 private TaxonNameEditorE4 editor
;
61 private MApplication application
;
62 private EModelService modelService
;
63 private EPartService partService
;
66 public void execute(@Named(IServiceConstants
.ACTIVE_PART
) MPart activePart
,
67 @Optional @Named(IServiceConstants
.ACTIVE_SELECTION
) IStructuredSelection selection
,
68 @Named(IServiceConstants
.ACTIVE_SHELL
) Shell shell
, MMenuItem menuItem
, EPartService partService
,
69 EModelService modelService
, MApplication application
, UISynchronize sync
) {
71 this.modelService
= modelService
;
72 this.application
= application
;
73 this.partService
= partService
;
75 FactualDataPartE4 factualDataPart
= (FactualDataPartE4
) activePart
.getObject();
76 Object e4WrappedPart
= WorkbenchUtility
.getE4WrappedPart(factualDataPart
.getSelectionProvidingPart());
77 if(e4WrappedPart
instanceof TaxonNameEditorE4
){
78 editor
= (TaxonNameEditorE4
) e4WrappedPart
;
79 if (this.editor
.isDirty()){
80 boolean proceed
= MessageDialog
.openQuestion(null,
81 Messages
.MoveDescriptionToOtherTaxonHandler_SAVE_CHANGES
, Messages
.MoveDescriptionToOtherTaxonHandler_SAVE_CHANGES_MESSAGE
);
83 editor
.save(AbstractUtility
.getMonitor());
91 List
<TaxonDescription
> descriptions
= new ArrayList
<TaxonDescription
>();
92 TaxonDescription description
= null;
93 Object selectedElement
= selection
.getFirstElement();
94 if (selectedElement
instanceof FeatureNodeContainer
){
95 FeatureNodeContainer container
= (FeatureNodeContainer
)selectedElement
;
96 description
= (TaxonDescription
) container
.getDescription();
97 }else if (selectedElement
instanceof TaxonDescription
){
98 description
= (TaxonDescription
)selectedElement
;
100 descriptions
.add(description
);
102 // Choose the target taxon
103 Set
<UUID
> excludeTaxa
= new HashSet
<>();
105 excludeTaxa
.add(descriptions
.get(0).getTaxon().getUuid());
107 //get current taxon node
108 TaxonNode node
= null;
109 Classification classification
= null;
111 node
= editor
.getEditorInput().getTaxonNode();
112 classification
= node
.getClassification();
114 TaxonNode newAcceptedTaxonNode
= TaxonNodeSelectionDialog
.select(shell
,
115 // editor.getConversationHolder(),
116 Messages
.MoveDescriptionToOtherTaxonHandler_CHOOSE_ACC_TAXON
,
119 classification
.getUuid());
121 if (newAcceptedTaxonNode
== null) {
125 newAcceptedTaxonNodeUuid
= newAcceptedTaxonNode
.getUuid();
127 for(TaxonDescription taxonDescription
: descriptions
){
128 operation
= new MoveDescriptionToOtherTaxonOperation(menuItem
.getLocalizedLabel(),
129 editor
.getUndoContext(),
131 newAcceptedTaxonNode
,
134 editor
.getEditorInput());
135 AbstractUtility
.executeOperation(operation
, sync
);
143 public boolean postOperation(CdmBase objectAffectedByOperation
) {
144 Display
.getDefault().asyncExec(new Runnable(){
149 // AbstractUtility.close(editor);
152 // MultiPageTaxonEditor possibleOpenEditor = (MultiPageTaxonEditor) EditorUtil.findEditorByTaxonNodeUuid(newAcceptedTaxonNodeUuid);
153 // if(possibleOpenEditor != null){
154 // AbstractUtility.close(possibleOpenEditor);
156 EditorUtil
.openTaxonNodeE4(newAcceptedTaxonNodeUuid
, modelService
, partService
, application
);
157 // } catch (PartInitException e) {
158 // MessagingUtils.error(this.getClass(), e);
159 // throw new RuntimeException(e);
160 } catch (Exception e
) {
161 MessagingUtils
.warningDialog(Messages
.MoveDescriptionToOtherTaxonHandler_CREATE_FAILED
, this, e
.getMessage());
172 public boolean onComplete() {
177 public boolean canExecute(@Optional @Named(IServiceConstants
.ACTIVE_PART
) MPart activePart
,
178 MHandledMenuItem menuItem
){
179 boolean canExecute
= false;
180 FactualDataPartE4 factualDataPart
= (FactualDataPartE4
) activePart
.getObject();
182 Object e4WrappedPart
= WorkbenchUtility
.getE4WrappedPart(factualDataPart
.getSelectionProvidingPart());
183 if(e4WrappedPart
instanceof TaxonNameEditorE4
){
184 ISelection selection
= factualDataPart
.getViewer().getSelection();
185 if(selection
instanceof IStructuredSelection
){
186 Object firstElement
= ((IStructuredSelection
) selection
).getFirstElement();
187 canExecute
= ((IStructuredSelection
) selection
).size()==1
189 (firstElement
instanceof FeatureNodeContainer
190 || firstElement
instanceof DescriptionElementBase
191 || firstElement
instanceof DescriptionBase
);
192 menuItem
.setVisible(canExecute
);