From: a.theys Date: Wed, 27 Jun 2012 11:30:05 +0000 (+0000) Subject: AT: committing changes to the TaxEditor for ethnic group testing and remove the featu... X-Git-Tag: 3.6.0~1055 X-Git-Url: https://dev.e-taxonomy.eu/gitweb/taxeditor.git/commitdiff_plain/403d38f842eaded6e44225d56ab679fa9c914013 AT: committing changes to the TaxEditor for ethnic group testing and remove the featureNodes from the contextual menu --- diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/handler/DynamicFeatureMenu.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/handler/DynamicFeatureMenu.java index f1194d785..d51bbfe14 100644 --- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/handler/DynamicFeatureMenu.java +++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/handler/DynamicFeatureMenu.java @@ -1,12 +1,12 @@ // $Id$ /** -* Copyright (C) 2007 EDIT -* European Distributed Institute of Taxonomy -* http://www.e-taxonomy.eu -* -* The contents of this file are subject to the Mozilla Public License Version 1.1 -* See LICENSE.TXT at the top of this package for the full license terms. -*/ + * Copyright (C) 2007 EDIT + * European Distributed Institute of Taxonomy + * http://www.e-taxonomy.eu + * + * The contents of this file are subject to the Mozilla Public License Version 1.1 + * See LICENSE.TXT at the top of this package for the full license terms. + */ package eu.etaxonomy.taxeditor.editor.view.descriptive.handler; @@ -31,6 +31,7 @@ import eu.etaxonomy.cdm.model.description.FeatureNode; import eu.etaxonomy.cdm.model.description.FeatureTree; import eu.etaxonomy.cdm.model.description.TaxonDescription; import eu.etaxonomy.taxeditor.editor.EditorUtil; +import eu.etaxonomy.taxeditor.editor.UsageTermCollection; import eu.etaxonomy.taxeditor.editor.view.descriptive.DescriptiveViewPart; import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.CreateDescriptionElementOperation; import eu.etaxonomy.taxeditor.model.FeatureNodeContainer; @@ -38,105 +39,128 @@ import eu.etaxonomy.taxeditor.preference.PreferencesUtil; import eu.etaxonomy.taxeditor.store.CdmStore; /** - *

DynamicFeatureMenu class.

- * + *

+ * DynamicFeatureMenu class. + *

+ * * @author n.hoffmann * @created 17.04.2009 * @version 1.0 */ public class DynamicFeatureMenu extends CompoundContributionItem { - - private ISelectionService selectionService = EditorUtil.getActivePart().getSite().getWorkbenchWindow().getSelectionService(); - private IHandlerService handlerService = (IHandlerService) EditorUtil.getService(IHandlerService.class); - - /* (non-Javadoc) - * @see org.eclipse.ui.actions.CompoundContributionItem#getContributionItems() + + private ISelectionService selectionService = EditorUtil.getActivePart() + .getSite().getWorkbenchWindow().getSelectionService(); + private IHandlerService handlerService = (IHandlerService) EditorUtil + .getService(IHandlerService.class); + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.ui.actions.CompoundContributionItem#getContributionItems() */ /** {@inheritDoc} */ @Override protected IContributionItem[] getContributionItems() { - - return new IContributionItem[] { - new ContributionItem() { - public void fill(Menu menu, int index){ - - ISelection selection = selectionService.getSelection(DescriptiveViewPart.ID); - - if(selection instanceof IStructuredSelection){ - IStructuredSelection structuredSelection = (IStructuredSelection) selection; - Object selectedElement = structuredSelection.getFirstElement(); - - if(selectedElement instanceof TaxonDescription){ - FeatureTree featureTree = getFeatureTree((TaxonDescription) selectedElement); - - for(FeatureNode childNode : featureTree.getRootChildren()){ - createMenuItem(menu, childNode.getFeature()); - } - } - else if(selectedElement instanceof FeatureNodeContainer){ - FeatureNode featureNode = ((FeatureNodeContainer) selectedElement).getFeatureNode(); - - // add the feature to the menu - createMenuItem(menu, featureNode.getFeature()); - - // add possible children to the menu - for(FeatureNode childNode : featureNode.getChildren()){ - createMenuItem(menu, childNode.getFeature()); - } - } - else if(selectedElement instanceof DescriptionElementBase){ - Feature feature = ((DescriptionElementBase) selectedElement).getFeature(); - createMenuItem(menu, feature); + + return new IContributionItem[] { new ContributionItem() { + public void fill(Menu menu, int index) { + + ISelection selection = selectionService + .getSelection(DescriptiveViewPart.ID); + + if (selection instanceof IStructuredSelection) { + IStructuredSelection structuredSelection = (IStructuredSelection) selection; + Object selectedElement = structuredSelection + .getFirstElement(); + + if (selectedElement instanceof TaxonDescription) { + FeatureTree featureTree = getFeatureTree((TaxonDescription) selectedElement); + + for (FeatureNode childNode : featureTree + .getRootChildren()) { + if (!(childNode.getFeature().getUuid() + .equals(UsageTermCollection.uuidUseRecordFeature)) + && !(childNode.getFeature().getUuid() + .equals(UsageTermCollection.uuidUseSummaryFeature))) { + createMenuItem(menu, childNode.getFeature()); } - } + } + } else if (selectedElement instanceof FeatureNodeContainer) { + FeatureNode featureNode = ((FeatureNodeContainer) selectedElement) + .getFeatureNode(); + + // add the feature to the menu + createMenuItem(menu, featureNode.getFeature()); + + // add possible children to the menu + for (FeatureNode childNode : featureNode.getChildren()) { + createMenuItem(menu, childNode.getFeature()); + } + } else if (selectedElement instanceof DescriptionElementBase) { + Feature feature = ((DescriptionElementBase) selectedElement) + .getFeature(); + createMenuItem(menu, feature); } } - }; - } - + } + } }; + } + private void createMenuItem(Menu menu, final Feature feature) { MenuItem menuItem = new MenuItem(menu, -1); - final Feature deproxiedFeature = (Feature) HibernateProxyHelper.deproxy(feature); - menuItem.setText(deproxiedFeature.getLabel()); - menuItem.addSelectionListener(new SelectionListener(){ - - public void widgetDefaultSelected(SelectionEvent e) {} - - public void widgetSelected(SelectionEvent ev) { - Event event = new Event(); - event.data = deproxiedFeature; - try { - handlerService.executeCommand(CreateDescriptionElementOperation.ID, event); - } catch (Exception e) { - EditorUtil.error(getClass(), e); + final Feature deproxiedFeature = (Feature) HibernateProxyHelper + .deproxy(feature); + + + menuItem.setText(deproxiedFeature.getLabel()); + menuItem.addSelectionListener(new SelectionListener() { + + public void widgetDefaultSelected(SelectionEvent e) { } - } - }); + + public void widgetSelected(SelectionEvent ev) { + Event event = new Event(); + event.data = deproxiedFeature; + try { + handlerService.executeCommand( + CreateDescriptionElementOperation.ID, event); + } catch (Exception e) { + EditorUtil.error(getClass(), e); + } + } + }); + } - + /** * Retrieves the feature tree associated with the given description * - * TODO as of now this is always the same thing because feature trees may not be associated - * to descriptions yet. + * TODO as of now this is always the same thing because feature trees may + * not be associated to descriptions yet. * * @param description * @return */ - private FeatureTree getFeatureTree(DescriptionBase description){ + private FeatureTree getFeatureTree(DescriptionBase description) { FeatureTree featureTree = null; - - // TODO change this to the feature tree associated with this taxon description - if (description.hasStructuredData()){ - featureTree = PreferencesUtil.getDefaultFeatureTreeForStructuredDescription(); - }else{ - featureTree = PreferencesUtil.getDefaultFeatureTreeForTextualDescription(); + + // TODO change this to the feature tree associated with this taxon + // description + if (description.hasStructuredData()) { + featureTree = PreferencesUtil + .getDefaultFeatureTreeForStructuredDescription(); + } else { + featureTree = PreferencesUtil + .getDefaultFeatureTreeForTextualDescription(); } - - if(featureTree == null){ - featureTree = FeatureTree.NewInstance(CdmStore.getTermManager().getPreferredTerms(Feature.class)); + + if (featureTree == null) { + featureTree = FeatureTree.NewInstance(CdmStore.getTermManager() + .getPreferredTerms(Feature.class)); } - + return featureTree; } } diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/uses/UsesLabelProvider.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/uses/UsesLabelProvider.java index dc96f4da4..1858c850a 100644 --- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/uses/UsesLabelProvider.java +++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/uses/UsesLabelProvider.java @@ -171,7 +171,7 @@ public class UsesLabelProvider extends ColumnLabelProvider implements else if ((term.getVocabulary() != null) && (term.getPartOf() == null) && (term.getVocabulary().getTitleCache().equals(vocabularyExpected))) { return true; } - else if ((vocabularyExpected.equals(UsageTermCollection.ethnicGroupLabel)) && (term.getVocabulary() != null) && ((term.getPartOf() != null))) { + else if ((vocabularyExpected.equals(UsageTermCollection.ethnicGroupLabel)) && ((term.getPartOf() != null))) { return true; } return false; diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/userecords/UseRecordDetailElement.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/userecords/UseRecordDetailElement.java index e10fe7dae..32d02813f 100644 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/userecords/UseRecordDetailElement.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/userecords/UseRecordDetailElement.java @@ -543,7 +543,7 @@ public class UseRecordDetailElement extends else if ((term.getVocabulary() != null) && (term.getPartOf()==null) && (term.getVocabulary().getTitleCache().equals(vocabularyExpected))) { return true; } - else if ((vocabularyExpected.equals(UsageTermCollection.ethnicGroupLabel)) && (term.getVocabulary() != null) && ((term.getPartOf() != null))) { + else if ((vocabularyExpected.equals(UsageTermCollection.ethnicGroupLabel)) && ((term.getPartOf() != null))) { return true; } return false;