// $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;
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;
import eu.etaxonomy.taxeditor.store.CdmStore;
/**
- * <p>DynamicFeatureMenu class.</p>
- *
+ * <p>
+ * DynamicFeatureMenu class.
+ * </p>
+ *
* @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;
}
}