2 * Copyright (C) 2017 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.navigation
.navigator
.e4
.handler
;
11 import java
.util
.Collection
;
12 import java
.util
.Iterator
;
14 import javax
.inject
.Named
;
16 import org
.eclipse
.core
.commands
.operations
.AbstractOperation
;
17 import org
.eclipse
.core
.runtime
.IStatus
;
18 import org
.eclipse
.core
.runtime
.NullProgressMonitor
;
19 import org
.eclipse
.core
.runtime
.Status
;
20 import org
.eclipse
.e4
.core
.di
.annotations
.CanExecute
;
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
.jface
.dialogs
.MessageDialog
;
25 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
26 import org
.eclipse
.jface
.viewers
.TreeSelection
;
27 import org
.eclipse
.jface
.window
.Window
;
28 import org
.eclipse
.jface
.wizard
.WizardDialog
;
29 import org
.eclipse
.swt
.widgets
.Shell
;
31 import eu
.etaxonomy
.cdm
.api
.service
.config
.SecundumForSubtreeConfigurator
;
32 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
33 import eu
.etaxonomy
.cdm
.persistence
.dto
.TaxonNodeDto
;
34 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
35 import eu
.etaxonomy
.taxeditor
.navigation
.l10n
.Messages
;
36 import eu
.etaxonomy
.taxeditor
.navigation
.navigator
.TaxonNavigatorLabels
;
37 import eu
.etaxonomy
.taxeditor
.navigation
.navigator
.operation
.SetSecundumForSubtreeOperation
;
38 import eu
.etaxonomy
.taxeditor
.operation
.e4
.CdmHandlerE4
;
39 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.configurator
.SetSecundumForSubtreeConfigurationWizard
;
40 import eu
.etaxonomy
.taxeditor
.workbench
.part
.IE4SavablePart
;
48 public class SetSecReferenceForSubtreeHandlerE4
extends CdmHandlerE4
{
50 private TaxonNodeDto taxonNode
;
51 private SecundumForSubtreeConfigurator configurator
;
53 public SetSecReferenceForSubtreeHandlerE4() {
54 super(TaxonNavigatorLabels
.CHANGE_SECUNDUM_FOR_SUBTREE
);
58 public IStatus
allowOperations(IStructuredSelection selection
,
61 MHandledMenuItem menuItem
) {
62 // check that only a single taxon tree node has been selected
63 if(selection
.size() > 1) { }
65 // check for no taxon tree node selected
66 if(selection
.size() == 0) {
67 return new Status(IStatus
.ERROR
,
68 "unknown", //$NON-NLS-1$
69 TaxonNavigatorLabels
.NO_TAXON_SELECTION_MESSAGE
);
72 // check that selected object is a taxon node
73 Object obj
= selection
.iterator().next();
74 if(obj
instanceof TaxonNodeDto
) {
75 if(obj
instanceof Classification
){
76 taxonNode
= new TaxonNodeDto(((Classification
)obj
).getRootNode());
78 taxonNode
= (TaxonNodeDto
)obj
;
81 return new Status(IStatus
.ERROR
,
82 "unknown", //$NON-NLS-1$
83 TaxonNavigatorLabels
.SELECTED_OBJECT_NOT_TREE_NODE_MESSAGE
);
85 Collection
<IE4SavablePart
> dirtyParts
= EditorUtil
.checkForTaxonChanges(null, partService
);
87 if (dirtyParts
!= null && !dirtyParts
.isEmpty()){
88 String
[] buttonLables
= {Messages
.YES
, Messages
.NO
,Messages
.TreeNodeDropAdapter_CANCEL
};
89 MessageDialog dialog
= new MessageDialog(null, Messages
.SetPublishFlagForSubtreeHandlerE4_UnsavedChanges
, null, Messages
.SetPublishFlagForSubtreeHandlerE4_UnsavedChangesQuestion
, MessageDialog
.QUESTION_WITH_CANCEL
, buttonLables
, 0);
91 int returnCode
= dialog
.getReturnCode();
92 boolean proceed
= false;
95 }else if (returnCode
== 2){
96 return Status
.CANCEL_STATUS
;
99 Iterator
<IE4SavablePart
> partIterator
= dirtyParts
.iterator();
100 while( partIterator
.hasNext() ){
101 IE4SavablePart part
= partIterator
.next();
104 part
.save(new NullProgressMonitor());
110 configurator
= new SecundumForSubtreeConfigurator(taxonNode
.getUuid(), null, null, false);
111 SetSecundumForSubtreeConfigurationWizard wizard
= new SetSecundumForSubtreeConfigurationWizard(configurator
);
113 WizardDialog dialog
= new WizardDialog(shell
, wizard
);
115 if (dialog
.open() == Window
.OK
) {
116 return Status
.OK_STATUS
;
118 return Status
.CANCEL_STATUS
;
123 private boolean canExecute(@Named(IServiceConstants
.ACTIVE_SELECTION
)TreeSelection selection
, MHandledMenuItem menuItem
){
124 boolean canExecute
= false;
125 canExecute
= selection
.size()==1
126 && selection
.getFirstElement() instanceof TaxonNodeDto
;
127 menuItem
.setEnabled(canExecute
);
132 public AbstractOperation
prepareOperation(IStructuredSelection selection
,
135 MHandledMenuItem menuItem
) {
136 SetSecundumForSubtreeOperation operation
=
137 new SetSecundumForSubtreeOperation(getTrigger(),
140 partService
, activePart
, application
, modelService
,
147 public void onComplete() {
154 protected Object
getTrigger() {