3 * Copyright (C) 2017 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.navigation
.navigator
.e4
.handler
;
12 import javax
.inject
.Named
;
14 import org
.eclipse
.core
.commands
.operations
.AbstractOperation
;
15 import org
.eclipse
.core
.runtime
.IStatus
;
16 import org
.eclipse
.core
.runtime
.Status
;
17 import org
.eclipse
.e4
.core
.di
.annotations
.CanExecute
;
18 import org
.eclipse
.e4
.ui
.model
.application
.ui
.basic
.MPart
;
19 import org
.eclipse
.e4
.ui
.model
.application
.ui
.menu
.MHandledMenuItem
;
20 import org
.eclipse
.e4
.ui
.services
.IServiceConstants
;
21 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
22 import org
.eclipse
.jface
.viewers
.TreeSelection
;
23 import org
.eclipse
.jface
.window
.Window
;
24 import org
.eclipse
.jface
.wizard
.WizardDialog
;
25 import org
.eclipse
.swt
.widgets
.Shell
;
27 import eu
.etaxonomy
.cdm
.api
.service
.config
.PublishForSubtreeConfigurator
;
28 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
29 import eu
.etaxonomy
.cdm
.persistence
.dto
.TaxonNodeDto
;
30 import eu
.etaxonomy
.taxeditor
.navigation
.navigator
.TaxonNavigatorLabels
;
31 import eu
.etaxonomy
.taxeditor
.navigation
.navigator
.operation
.SetPublishForSubtreeOperation
;
32 import eu
.etaxonomy
.taxeditor
.operation
.e4
.RemotingCdmHandlerE4
;
33 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.configurator
.SetPublishForSubtreeWizard
;
40 public class SetPublishFlagForSubtreeHandlerE4
extends RemotingCdmHandlerE4
{
45 public SetPublishFlagForSubtreeHandlerE4() {
46 //FIXME add missing l10n property
47 // super(TaxonNavigatorLabels.CHANGE_PUBLISH_FOR_SUBTREE);
52 private TaxonNodeDto taxonNode
;
53 private PublishForSubtreeConfigurator configurator
;
57 public IStatus
allowOperations(IStructuredSelection selection
, Shell shell
, MPart activePart
,
58 MHandledMenuItem menuItem
) {
59 // check that only a single taxon tree node has been selected
60 if(selection
.size() > 1) { }
62 // check for no taxon tree node selected
63 if(selection
.size() == 0) {
64 return new Status(IStatus
.ERROR
,
65 "unknown", //$NON-NLS-1$
66 TaxonNavigatorLabels
.NO_TAXON_SELECTION_MESSAGE
);
69 // check that selected object is a taxon node
70 Object obj
= selection
.iterator().next();
71 if(obj
instanceof TaxonNodeDto
) {
72 taxonNode
= (TaxonNodeDto
)obj
;
73 } else if(obj
instanceof Classification
){
74 taxonNode
= new TaxonNodeDto(((Classification
)obj
).getRootNode());
76 return new Status(IStatus
.ERROR
,
77 "unknown", //$NON-NLS-1$
78 TaxonNavigatorLabels
.SELECTED_OBJECT_NOT_TREE_NODE_MESSAGE
);
80 configurator
= new PublishForSubtreeConfigurator(taxonNode
.getUuid());
81 SetPublishForSubtreeWizard wizard
= new SetPublishForSubtreeWizard(configurator
);
83 WizardDialog dialog
= new WizardDialog(shell
, wizard
);
85 if (dialog
.open() == Window
.OK
) {
86 return Status
.OK_STATUS
;
88 return Status
.CANCEL_STATUS
;
93 private boolean canExecute(@Named(IServiceConstants
.ACTIVE_SELECTION
)TreeSelection selection
, MHandledMenuItem menuItem
){
94 boolean canExecute
= false;
95 canExecute
= selection
.size()==1
96 && selection
.getFirstElement() instanceof TaxonNodeDto
;
97 menuItem
.setVisible(canExecute
);
103 public AbstractOperation
prepareOperation(IStructuredSelection selection
, Shell shell
, MPart activePart
,
104 MHandledMenuItem menuItem
) {
105 SetPublishForSubtreeOperation operation
=
106 new SetPublishForSubtreeOperation(getTrigger(),
120 public void onComplete() {
126 protected Object
getTrigger() {