import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
import eu.etaxonomy.cdm.model.description.Feature;
import eu.etaxonomy.cdm.model.description.TaxonDescription;
+import eu.etaxonomy.cdm.model.name.TaxonName;
import eu.etaxonomy.cdm.model.taxon.Taxon;
import eu.etaxonomy.taxeditor.editor.EditorUtil;
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonEditor;
description = TaxonDescription.NewInstance(taxon);
description.setDefault(true);
}
- }
+ }
else {
MessagingUtils.error(getClass(), new IllegalArgumentException("Could not determine the taxon description")); //$NON-NLS-1$
return;
Object o = activePart.getObject();
if (o instanceof FactualDataPartE4) {
FactualDataPartE4 part = (FactualDataPartE4)o;
- MPart selectionProvidingPart = part.getSelectionProvidingPart();
- if (selectionProvidingPart.getObject() instanceof TaxonEditor) {
- TaxonEditor editor = (TaxonEditor)selectionProvidingPart.getObject();
- object = editor.getTaxon();
- }
+ object = part.getViewer().getInput();
}else if (o instanceof TaxonEditor) {
TaxonEditor editor = (TaxonEditor)AbstractUtility.getActiveEditor();
object = editor.getTaxon();
description = HibernateProxyHelper.deproxy(object, DescriptionBase.class);
}else if (object instanceof Taxon){
Taxon taxon = (Taxon) object;
- description =taxon.getDefaultDescription();
-
+ description =taxon.getDefaultDescription();
}
if (description != null &&((description.isComputed() || description.isCloneForSource())&& PreferencesUtil.isComputedDesciptionHandlingDisabled())){
|| selection.getFirstElement() instanceof DescriptionElementBase
|| selection.getFirstElement() instanceof FeatureNodeContainer
|| object instanceof Taxon))
- || (selection.size() == 0 && object instanceof Taxon);
+ || (selection.size() == 0 && object instanceof Taxon)
+ || (selection.size() == 0 && object instanceof TaxonName);
}
menuItem.setVisible(canExecute);
return canExecute;
import javax.inject.Named;
+import org.eclipse.e4.core.di.annotations.Optional;
import org.eclipse.e4.ui.di.AboutToShow;
import org.eclipse.e4.ui.model.application.commands.MCommand;
import org.eclipse.e4.ui.model.application.commands.MCommandsFactory;
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
import eu.etaxonomy.cdm.model.description.Feature;
import eu.etaxonomy.cdm.model.description.TaxonNameDescription;
+import eu.etaxonomy.cdm.model.name.TaxonName;
import eu.etaxonomy.cdm.model.taxon.Taxon;
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
import eu.etaxonomy.cdm.model.term.TermNode;
* @date 15.08.2017
*/
public class DynamicFeatureMenuE4 {
+ Object selectedElement = null;
@AboutToShow
- public void aboutToShow(List<MMenuElement> items, @Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection) {
+ public void aboutToShow(List<MMenuElement> items, @Optional@Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection) {
Language globalLanguage = PreferencesUtil.getGlobalLanguage();
MMenu menu = MMenuFactory.INSTANCE.createMenu();
menu.setLabel(Messages.DynamicFeatureMenuE4_new);
items.add(menu);
List<MMenuElement> menuItems = new ArrayList<>();
- Object selectedElement = selection.getFirstElement();
- if (selectedElement == null) {
+ if (selection != null) {
+ selectedElement = selection.getFirstElement();
+ }
+ if (selectedElement == null || !(selectedElement instanceof DescriptionBase<?> || selectedElement instanceof DescriptionElementBase || selectedElement instanceof FeatureNodeContainer )) {
MPart activePart = EventUtility.getActivePart();
Object o = activePart.getObject();
if (o instanceof FactualDataPartE4) {
FactualDataPartE4 part = (FactualDataPartE4)o;
- MPart selectionProvidingPart = part.getSelectionProvidingPart();
- if (selectionProvidingPart.getObject() instanceof TaxonEditor) {
- TaxonEditor editor = (TaxonEditor)selectionProvidingPart.getObject();
- selectedElement = editor.getTaxon();
- }
+ selectedElement = part.getViewer().getInput();
+
}else if (o instanceof TaxonEditor) {
TaxonEditor editor = (TaxonEditor)AbstractUtility.getActiveEditor();
selectedElement = editor.getTaxon();
}
}
- DescriptionBase<?> description;
+ DescriptionBase<?> description = null;
if (selectedElement instanceof DescriptionBase<?>) {
description = (DescriptionBase<?>) selectedElement;
} else if (selectedElement instanceof FeatureNodeContainer){
} else if (selectedElement instanceof Taxon){
Taxon taxon = (Taxon) selectedElement;
description = taxon.getDefaultDescription();
+ } else if (selectedElement instanceof TaxonName){
+ TaxonName taxonName = (TaxonName) selectedElement;
+ if (taxonName.getDescriptions() != null && taxonName.getDescriptions().size()>1) {
+ description = taxonName.getDescriptions().iterator().next();
+ }
} else {
//TODO or should we throw exception instead?
return;
//compute menu to show
List<Feature> featureList = new ArrayList<>();
- if (selectedElement instanceof DescriptionBase<?> || selectedElement instanceof Taxon) {
+ if (selectedElement instanceof DescriptionBase<?> || selectedElement instanceof Taxon || selectedElement instanceof TaxonName) {
TermTree<Feature> featureTree = (TermTree)getFeatureTree(description);
for (TermNode<Feature> childNode : featureTree.getRootChildren()) {
Feature feature = childNode.getTerm();
}
protected Map<UUID, Integer> getElementCounts(DescriptionBase<?> selectedElement) {
+
if (selectedElement == null) {
return null;
}
featureTree = TermEditorInput.getPreferredTaxonFeatureTree(false);
}
}else {
- featureTree = TermEditorInput.getPreferredTaxonFeatureTree(false);
+ if (selectedElement instanceof TaxonName) {
+ featureTree = TermEditorInput.getPreferredNameFeatureTree(false);
+ }else {
+ featureTree = TermEditorInput.getPreferredTaxonFeatureTree(false);
+ }
}
return featureTree;