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 UUID oldAcceptedTaxonNodeUuid
;
61 private UUID newAcceptedTaxonUuid
;
62 private UUID oldAcceptedTaxonUuid
;
63 private TaxonNameEditorE4 editor
;
64 private MApplication application
;
65 private EModelService modelService
;
66 private EPartService partService
;
69 public void execute(@Named(IServiceConstants
.ACTIVE_PART
) MPart activePart
,
70 @Optional @Named(IServiceConstants
.ACTIVE_SELECTION
) IStructuredSelection selection
,
71 @Named(IServiceConstants
.ACTIVE_SHELL
) Shell shell
, MMenuItem menuItem
, EPartService partService
,
72 EModelService modelService
, MApplication application
, UISynchronize sync
) {
74 this.modelService
= modelService
;
75 this.application
= application
;
76 this.partService
= partService
;
78 FactualDataPartE4 factualDataPart
= (FactualDataPartE4
) activePart
.getObject();
79 Object e4WrappedPart
= WorkbenchUtility
.getE4WrappedPart(factualDataPart
.getSelectionProvidingPart());
80 if(e4WrappedPart
instanceof TaxonNameEditorE4
){
81 editor
= (TaxonNameEditorE4
) e4WrappedPart
;
82 if (this.editor
.isDirty()){
83 boolean proceed
= MessageDialog
.openQuestion(null,
84 Messages
.MoveDescriptionToOtherTaxonHandler_SAVE_CHANGES
, Messages
.MoveDescriptionToOtherTaxonHandler_SAVE_CHANGES_MESSAGE
);
86 editor
.save(AbstractUtility
.getMonitor());
94 List
<TaxonDescription
> descriptions
= new ArrayList
<TaxonDescription
>();
95 TaxonDescription description
= null;
96 Object selectedElement
= selection
.getFirstElement();
97 if (selectedElement
instanceof FeatureNodeContainer
){
98 FeatureNodeContainer container
= (FeatureNodeContainer
)selectedElement
;
99 description
= (TaxonDescription
) container
.getDescription();
100 }else if (selectedElement
instanceof TaxonDescription
){
101 description
= (TaxonDescription
)selectedElement
;
103 descriptions
.add(description
);
105 // Choose the target taxon
108 //get current taxon node
109 TaxonNode node
= null;
110 Classification classification
= null;
112 node
= editor
.getEditorInput().getTaxonNode();
113 oldAcceptedTaxonUuid
= editor
.getTaxon().getUuid();
114 oldAcceptedTaxonNodeUuid
= node
.getUuid();
115 classification
= node
.getClassification();
118 Set
<UUID
> excludeTaxa
= new HashSet
<>();
119 excludeTaxa
.add(oldAcceptedTaxonNodeUuid
);
120 TaxonNode newAcceptedTaxonNode
= TaxonNodeSelectionDialog
.select(shell
,
121 // editor.getConversationHolder(),
122 Messages
.MoveDescriptionToOtherTaxonHandler_CHOOSE_ACC_TAXON
,
125 classification
.getUuid());
127 if (newAcceptedTaxonNode
== null) {
131 newAcceptedTaxonNodeUuid
= newAcceptedTaxonNode
.getUuid();
132 newAcceptedTaxonUuid
= newAcceptedTaxonNode
.getTaxon().getUuid();
133 for(TaxonDescription taxonDescription
: descriptions
){
134 operation
= new MoveDescriptionToOtherTaxonOperation(menuItem
.getLocalizedLabel(),
135 editor
.getUndoContext(),
137 newAcceptedTaxonNode
,
140 editor
.getEditorInput());
141 AbstractUtility
.executeOperation(operation
, sync
);
149 public boolean postOperation(CdmBase objectAffectedByOperation
) {
150 Display
.getDefault().asyncExec(new Runnable(){
155 // AbstractUtility.close(editor);
158 // MultiPageTaxonEditor possibleOpenEditor = (MultiPageTaxonEditor) EditorUtil.findEditorByTaxonNodeUuid(newAcceptedTaxonNodeUuid);
159 // if(possibleOpenEditor != null){
160 // AbstractUtility.close(possibleOpenEditor);
162 // EventUtility.postEvent(WorkbenchEventConstants.REFRESH_NAME_EDITOR, oldAcceptedTaxonNodeUuid);
163 // EventUtility.postEvent(WorkbenchEventConstants.REFRESH_NAME_EDITOR, newAcceptedTaxonNodeUuid);
164 EditorUtil
.openTaxonNodeE4(newAcceptedTaxonNodeUuid
, modelService
, partService
, application
);
165 EditorUtil
.openTaxonNodeE4(oldAcceptedTaxonNodeUuid
, modelService
, partService
, application
);
166 // } catch (PartInitException e) {
167 // MessagingUtils.error(this.getClass(), e);
168 // throw new RuntimeException(e);
169 } catch (Exception e
) {
170 MessagingUtils
.warningDialog(Messages
.MoveDescriptionToOtherTaxonHandler_CREATE_FAILED
, this, e
.getMessage());
181 public boolean onComplete() {
186 public boolean canExecute(@Optional @Named(IServiceConstants
.ACTIVE_PART
) MPart activePart
,
187 MHandledMenuItem menuItem
){
188 boolean canExecute
= false;
189 FactualDataPartE4 factualDataPart
= (FactualDataPartE4
) activePart
.getObject();
191 Object e4WrappedPart
= WorkbenchUtility
.getE4WrappedPart(factualDataPart
.getSelectionProvidingPart());
192 if(e4WrappedPart
instanceof TaxonNameEditorE4
){
193 ISelection selection
= factualDataPart
.getViewer().getSelection();
194 if(selection
instanceof IStructuredSelection
){
195 Object firstElement
= ((IStructuredSelection
) selection
).getFirstElement();
196 canExecute
= ((IStructuredSelection
) selection
).size()==1
198 (firstElement
instanceof FeatureNodeContainer
199 || firstElement
instanceof DescriptionElementBase
200 || firstElement
instanceof DescriptionBase
);
201 menuItem
.setVisible(canExecute
);