Project

General

Profile

« Previous | Next » 

Revision 403d38f8

Added by Alex Theys almost 12 years ago

AT: committing changes to the TaxEditor for ethnic group testing and remove the featureNodes from the contextual menu

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/handler/DynamicFeatureMenu.java
1 1
// $Id$
2 2
/**
3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy 
5
* http://www.e-taxonomy.eu
6
* 
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.
9
*/
3
 * Copyright (C) 2007 EDIT
4
 * European Distributed Institute of Taxonomy 
5
 * http://www.e-taxonomy.eu
6
 * 
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.
9
 */
10 10

  
11 11
package eu.etaxonomy.taxeditor.editor.view.descriptive.handler;
12 12

  
......
31 31
import eu.etaxonomy.cdm.model.description.FeatureTree;
32 32
import eu.etaxonomy.cdm.model.description.TaxonDescription;
33 33
import eu.etaxonomy.taxeditor.editor.EditorUtil;
34
import eu.etaxonomy.taxeditor.editor.UsageTermCollection;
34 35
import eu.etaxonomy.taxeditor.editor.view.descriptive.DescriptiveViewPart;
35 36
import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.CreateDescriptionElementOperation;
36 37
import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
......
38 39
import eu.etaxonomy.taxeditor.store.CdmStore;
39 40

  
40 41
/**
41
 * <p>DynamicFeatureMenu class.</p>
42
 *
42
 * <p>
43
 * DynamicFeatureMenu class.
44
 * </p>
45
 * 
43 46
 * @author n.hoffmann
44 47
 * @created 17.04.2009
45 48
 * @version 1.0
46 49
 */
47 50
public class DynamicFeatureMenu extends CompoundContributionItem {
48
	
49
	private ISelectionService selectionService = EditorUtil.getActivePart().getSite().getWorkbenchWindow().getSelectionService();
50
	private IHandlerService handlerService = (IHandlerService) EditorUtil.getService(IHandlerService.class);
51
	
52
	/* (non-Javadoc)
53
	 * @see org.eclipse.ui.actions.CompoundContributionItem#getContributionItems()
51

  
52
	private ISelectionService selectionService = EditorUtil.getActivePart()
53
			.getSite().getWorkbenchWindow().getSelectionService();
54
	private IHandlerService handlerService = (IHandlerService) EditorUtil
55
			.getService(IHandlerService.class);
56

  
57
	/*
58
	 * (non-Javadoc)
59
	 * 
60
	 * @see
61
	 * org.eclipse.ui.actions.CompoundContributionItem#getContributionItems()
54 62
	 */
55 63
	/** {@inheritDoc} */
56 64
	@Override
57 65
	protected IContributionItem[] getContributionItems() {
58
		
59
		return new IContributionItem[] {
60
				new ContributionItem() {
61
					public void fill(Menu menu, int index){
62
								
63
						ISelection selection = selectionService.getSelection(DescriptiveViewPart.ID);
64
						
65
						if(selection instanceof IStructuredSelection){
66
							IStructuredSelection structuredSelection = (IStructuredSelection) selection;
67
							Object selectedElement = structuredSelection.getFirstElement();
68
							
69
							if(selectedElement instanceof TaxonDescription){
70
								FeatureTree featureTree = getFeatureTree((TaxonDescription) selectedElement);
71
								
72
								for(FeatureNode childNode : featureTree.getRootChildren()){
73
									createMenuItem(menu, childNode.getFeature());
74
								}
75
							}
76
							else if(selectedElement instanceof FeatureNodeContainer){
77
								FeatureNode featureNode = ((FeatureNodeContainer) selectedElement).getFeatureNode();
78
								
79
								// add the feature to the menu
80
								createMenuItem(menu, featureNode.getFeature());
81
								
82
								// add possible children to the menu
83
								for(FeatureNode childNode : featureNode.getChildren()){
84
									createMenuItem(menu, childNode.getFeature());
85
								}
86
							}
87
							else if(selectedElement instanceof DescriptionElementBase){
88
								Feature feature = ((DescriptionElementBase) selectedElement).getFeature();
89
								createMenuItem(menu, feature);
66

  
67
		return new IContributionItem[] { new ContributionItem() {
68
			public void fill(Menu menu, int index) {
69

  
70
				ISelection selection = selectionService
71
						.getSelection(DescriptiveViewPart.ID);
72

  
73
				if (selection instanceof IStructuredSelection) {
74
					IStructuredSelection structuredSelection = (IStructuredSelection) selection;
75
					Object selectedElement = structuredSelection
76
							.getFirstElement();
77

  
78
					if (selectedElement instanceof TaxonDescription) {
79
						FeatureTree featureTree = getFeatureTree((TaxonDescription) selectedElement);
80

  
81
						for (FeatureNode childNode : featureTree
82
								.getRootChildren()) {
83
							if (!(childNode.getFeature().getUuid()
84
									.equals(UsageTermCollection.uuidUseRecordFeature))
85
									&& !(childNode.getFeature().getUuid()
86
											.equals(UsageTermCollection.uuidUseSummaryFeature))) {
87
								createMenuItem(menu, childNode.getFeature());
90 88
							}
91
						}	
89
						}
90
					} else if (selectedElement instanceof FeatureNodeContainer) {
91
						FeatureNode featureNode = ((FeatureNodeContainer) selectedElement)
92
								.getFeatureNode();
93

  
94
						// add the feature to the menu
95
						createMenuItem(menu, featureNode.getFeature());
96

  
97
						// add possible children to the menu
98
						for (FeatureNode childNode : featureNode.getChildren()) {
99
							createMenuItem(menu, childNode.getFeature());
100
						}
101
					} else if (selectedElement instanceof DescriptionElementBase) {
102
						Feature feature = ((DescriptionElementBase) selectedElement)
103
								.getFeature();
104
						createMenuItem(menu, feature);
92 105
					}
93 106
				}
94
		};
95
	}	
96
	
107
			}
108
		} };
109
	}
110

  
97 111
	private void createMenuItem(Menu menu, final Feature feature) {
98 112
		MenuItem menuItem = new MenuItem(menu, -1);
99
		final Feature deproxiedFeature = (Feature) HibernateProxyHelper.deproxy(feature);
100
		menuItem.setText(deproxiedFeature.getLabel());
101
		menuItem.addSelectionListener(new SelectionListener(){
102

  
103
			public void widgetDefaultSelected(SelectionEvent e) {}
104

  
105
			public void widgetSelected(SelectionEvent ev) {
106
				Event event = new Event();
107
				event.data = deproxiedFeature;
108
				try {
109
					handlerService.executeCommand(CreateDescriptionElementOperation.ID, event);
110
				} catch (Exception e) {
111
					EditorUtil.error(getClass(), e);
113
		final Feature deproxiedFeature = (Feature) HibernateProxyHelper
114
				.deproxy(feature);
115
		
116

  
117
			menuItem.setText(deproxiedFeature.getLabel());
118
			menuItem.addSelectionListener(new SelectionListener() {
119

  
120
				public void widgetDefaultSelected(SelectionEvent e) {
112 121
				}
113
			}				
114
		});
122

  
123
				public void widgetSelected(SelectionEvent ev) {
124
					Event event = new Event();
125
					event.data = deproxiedFeature;
126
					try {
127
						handlerService.executeCommand(
128
								CreateDescriptionElementOperation.ID, event);
129
					} catch (Exception e) {
130
						EditorUtil.error(getClass(), e);
131
					}
132
				}
133
			});
134
		
115 135
	}
116
	
136

  
117 137
	/**
118 138
	 * Retrieves the feature tree associated with the given description
119 139
	 * 
120
	 * TODO as of now this is always the same thing because feature trees may not be associated 
121
	 * to descriptions yet.
140
	 * TODO as of now this is always the same thing because feature trees may
141
	 * not be associated to descriptions yet.
122 142
	 * 
123 143
	 * @param description
124 144
	 * @return
125 145
	 */
126
	private FeatureTree getFeatureTree(DescriptionBase description){
146
	private FeatureTree getFeatureTree(DescriptionBase description) {
127 147
		FeatureTree featureTree = null;
128
		
129
		// TODO change this to the feature tree associated with this taxon description
130
		if (description.hasStructuredData()){					
131
			featureTree = PreferencesUtil.getDefaultFeatureTreeForStructuredDescription();
132
		}else{
133
			featureTree = PreferencesUtil.getDefaultFeatureTreeForTextualDescription();
148

  
149
		// TODO change this to the feature tree associated with this taxon
150
		// description
151
		if (description.hasStructuredData()) {
152
			featureTree = PreferencesUtil
153
					.getDefaultFeatureTreeForStructuredDescription();
154
		} else {
155
			featureTree = PreferencesUtil
156
					.getDefaultFeatureTreeForTextualDescription();
134 157
		}
135
		
136
		if(featureTree == null){
137
			featureTree = FeatureTree.NewInstance(CdmStore.getTermManager().getPreferredTerms(Feature.class));
158

  
159
		if (featureTree == null) {
160
			featureTree = FeatureTree.NewInstance(CdmStore.getTermManager()
161
					.getPreferredTerms(Feature.class));
138 162
		}
139
		
163

  
140 164
		return featureTree;
141 165
	}
142 166
}

Also available in: Unified diff