1 package eu
.etaxonomy
.taxeditor
.navigation
.navigator
.handler
;
3 import java
.util
.ArrayList
;
7 import org
.apache
.log4j
.Logger
;
8 import org
.eclipse
.core
.commands
.AbstractHandler
;
9 import org
.eclipse
.core
.commands
.ExecutionEvent
;
10 import org
.eclipse
.core
.commands
.ExecutionException
;
11 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
12 import org
.eclipse
.jface
.viewers
.ISelection
;
13 import org
.eclipse
.jface
.viewers
.TreeSelection
;
14 import org
.eclipse
.swt
.widgets
.Display
;
15 import org
.eclipse
.ui
.IWorkbenchPart
;
16 import org
.eclipse
.ui
.PartInitException
;
17 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
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
.editor
.EditorUtil
;
26 import eu
.etaxonomy
.taxeditor
.editor
.MultiPageTaxonEditor
;
27 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
28 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
29 import eu
.etaxonomy
.taxeditor
.navigation
.NavigationUtil
;
30 import eu
.etaxonomy
.taxeditor
.navigation
.l10n
.Messages
;
31 import eu
.etaxonomy
.taxeditor
.navigation
.navigator
.TaxonNavigator
;
32 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
33 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
.TaxonNodeSelectionDialog
;
35 public class MoveFactualDataHandler
extends AbstractHandler
{
37 @SuppressWarnings("unused")
38 private static final Logger logger
= Logger
.getLogger(MoveFactualDataHandler
.class);
41 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
42 ISelection currentSelection
= HandlerUtil
.getCurrentSelection(event
);
43 IWorkbenchPart activePart
= AbstractUtility
.getActivePart();
44 TaxonNavigator navigator
= null;
45 if(activePart
instanceof TaxonNavigator
){
46 navigator
= (TaxonNavigator
)activePart
;
48 if(navigator
!=null && currentSelection
instanceof TreeSelection
){
49 Object object
= ((TreeSelection
) currentSelection
).getFirstElement();
50 if(object
instanceof TaxonNode
){
51 TaxonNode taxonNode
= HibernateProxyHelper
.deproxy(object
, TaxonNode
.class);
52 final TaxonNode sourceTaxonNode
= CdmStore
.getService(ITaxonNodeService
.class).load(taxonNode
.getUuid());
53 if(NavigationUtil
.isDirty(sourceTaxonNode
)){
54 MessageDialog
.openWarning(HandlerUtil
.getActiveShell(event
), Messages
.MoveFactualDataHandler_UNSAVED_SOURCE
, Messages
.MoveFactualDataHandler_UNSAVED_SOURCE_MESSAGE
);
57 //reload to avoid session conflicts
58 Taxon taxon
= HibernateProxyHelper
.deproxy(CdmStore
.getService(ITaxonService
.class).load(sourceTaxonNode
.getTaxon().getUuid()), Taxon
.class);
60 // Choose the target taxon
61 List
<UUID
> excludeTaxa
= new ArrayList
<UUID
>();
62 excludeTaxa
.add(taxon
.getUuid());
63 TaxonNode dialogTaxonNode
= TaxonNodeSelectionDialog
.select(HandlerUtil
.getActiveShell(event
),
64 navigator
.getConversationHolder(),
65 Messages
.MoveFactualDataHandler_CHOOSE_TAXON
,
68 sourceTaxonNode
.getClassification());
69 if (dialogTaxonNode
== null) {
72 //reload to avoid session conflicts
73 final TaxonNode targetTaxonNode
= CdmStore
.getService(ITaxonNodeService
.class).load(dialogTaxonNode
.getUuid());
74 if(NavigationUtil
.isDirty(targetTaxonNode
)){
75 MessageDialog
.openWarning(HandlerUtil
.getActiveShell(event
), Messages
.MoveFactualDataHandler_UNSAVED_TARGET
, Messages
.MoveFactualDataHandler_UNSAVED_TARGET_MESSAGE
);
78 CdmStore
.getService(IDescriptionService
.class).moveTaxonDescriptions(taxon
.getUuid(),targetTaxonNode
.getTaxon().getUuid());
80 navigator
.getConversationHolder().bind();
81 navigator
.getConversationHolder().commit();
83 Display
.getDefault().asyncExec(new Runnable(){
88 //close and re-open to refresh factual data view
89 MultiPageTaxonEditor sourceEditor
= (MultiPageTaxonEditor
) EditorUtil
.findEditorByTaxonNodeUuid(sourceTaxonNode
.getUuid());
90 MultiPageTaxonEditor targetEditor
= (MultiPageTaxonEditor
) EditorUtil
.findEditorByTaxonNodeUuid(targetTaxonNode
.getUuid());
91 if(targetEditor
!= null){
92 AbstractUtility
.close(sourceEditor
);
93 AbstractUtility
.close(targetEditor
);
95 EditorUtil
.openTaxonNode(sourceTaxonNode
.getUuid());
96 EditorUtil
.openTaxonNode(targetTaxonNode
.getUuid());
97 } catch (PartInitException e
) {
98 MessagingUtils
.error(this.getClass(), e
);
99 throw new RuntimeException(e
);
100 } catch (Exception e
) {
101 MessagingUtils
.warningDialog(Messages
.MoveFactualDataHandler_CREATE_FAILED
, this, e
.getMessage());