2 * Copyright (C) 2018 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
.editor
.descriptiveDataSet
.matrix
.handler
;
11 import javax
.inject
.Named
;
13 import org
.eclipse
.e4
.ui
.model
.application
.ui
.basic
.MPart
;
14 import org
.eclipse
.e4
.ui
.model
.application
.ui
.menu
.MHandledMenuItem
;
15 import org
.eclipse
.e4
.ui
.services
.IServiceConstants
;
16 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
18 import eu
.etaxonomy
.cdm
.api
.service
.IDescriptiveDataSetService
;
19 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionType
;
20 import eu
.etaxonomy
.cdm
.model
.description
.DescriptiveDataSet
;
21 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
22 import eu
.etaxonomy
.cdm
.persistence
.dto
.TaxonNodeDto
;
23 import eu
.etaxonomy
.taxeditor
.editor
.descriptiveDataSet
.matrix
.CharacterMatrixPart
;
24 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
31 public class CreateDefaultTaxonDescriptionHandler
extends CreateTaxonDescriptionHandler
{
34 protected DescriptionType
getDescriptionType() {
35 return DescriptionType
.DEFAULT_VALUES_FOR_AGGREGATION
;
39 public boolean canExecute(@Named(IServiceConstants
.ACTIVE_PART
)MPart activePart
,
40 MHandledMenuItem menuItem
){
41 boolean canExecute
= super.canExecute(activePart
, menuItem
);
43 CharacterMatrixPart matrixPart
= (CharacterMatrixPart
) activePart
.getObject();
44 DescriptiveDataSet descriptiveDataSet
= matrixPart
.getDescriptiveDataSet();
45 IStructuredSelection selection
= ((CharacterMatrixPart
)activePart
.getObject()).getSelection();
46 TaxonNodeDto taxonNodeDto
= (TaxonNodeDto
) selection
.getFirstElement();
48 TaxonDescription defaultTaxonDescription
= CdmStore
.getService(IDescriptiveDataSetService
.class)
49 .findTaxonDescriptionByDescriptionType(descriptiveDataSet
.getUuid(), taxonNodeDto
.getUuid(), getDescriptionType());
50 canExecute
= defaultTaxonDescription
==null;
51 menuItem
.setVisible(canExecute
);