Revision 6a45f6a2
Added by Alex Theys almost 12 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/uses/UsesContentProvider.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2007 EDIT |
|
3 |
* European Distributed Institute of Taxonomy |
|
4 |
* http://www.e-taxonomy.eu |
|
5 |
* |
|
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. |
|
8 |
*/ |
|
1 | 9 |
package eu.etaxonomy.taxeditor.editor.view.uses; |
2 | 10 |
|
3 | 11 |
import java.util.ArrayList; |
... | ... | |
5 | 13 |
import java.util.List; |
6 | 14 |
import java.util.Map; |
7 | 15 |
import java.util.Set; |
8 |
import java.util.UUID; |
|
9 | 16 |
|
10 | 17 |
import org.eclipse.jface.viewers.ITreeContentProvider; |
18 |
import org.eclipse.jface.viewers.Viewer; |
|
11 | 19 |
|
12 | 20 |
import eu.etaxonomy.cdm.api.service.ITermService; |
13 | 21 |
import eu.etaxonomy.cdm.model.common.Marker; |
... | ... | |
19 | 27 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
20 | 28 |
import eu.etaxonomy.taxeditor.editor.TaxonEditorInput; |
21 | 29 |
import eu.etaxonomy.taxeditor.editor.UsageTermCollection; |
22 |
import eu.etaxonomy.taxeditor.editor.view.descriptive.DescriptiveContentProvider;
|
|
30 |
import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
|
|
23 | 31 |
import eu.etaxonomy.taxeditor.model.FeatureNodeContainerTree; |
24 | 32 |
import eu.etaxonomy.taxeditor.preference.PreferencesUtil; |
25 | 33 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
26 | 34 |
import eu.etaxonomy.taxeditor.store.TermStore; |
27 | 35 |
|
28 | 36 |
/** |
29 |
* UsesContentProvider Class
|
|
37 |
* The class provides the required content to the Uses View
|
|
30 | 38 |
* @author a.theys |
31 | 39 |
* @created mar 13, 2012 |
32 | 40 |
* @version 1.0 |
33 | 41 |
*/ |
34 |
public class UsesContentProvider extends DescriptiveContentProvider implements ITreeContentProvider {
|
|
42 |
public class UsesContentProvider implements ITreeContentProvider { |
|
35 | 43 |
|
36 | 44 |
private static final Object[] NO_CHILDREN = new Object[0]; |
37 | 45 |
private Map<TaxonDescription, FeatureNodeContainerTree> featureNodeContainerCache; |
... | ... | |
43 | 51 |
* @param featureNodeContainerCache a {@link java.util.Map} object. |
44 | 52 |
*/ |
45 | 53 |
public UsesContentProvider(Map<TaxonDescription, FeatureNodeContainerTree> featureNodeContainerCache) { |
46 |
super(featureNodeContainerCache); |
|
47 | 54 |
this.featureNodeContainerCache = featureNodeContainerCache; |
48 | 55 |
} |
49 | 56 |
|
57 |
|
|
58 |
/* (non-Javadoc) |
|
59 |
* @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object) |
|
60 |
*/ |
|
61 |
/** {@inheritDoc} */ |
|
62 |
public Object[] getChildren(Object parentElement) { |
|
63 |
if (parentElement instanceof TaxonEditorInput) { |
|
64 |
return getDescriptions((TaxonEditorInput) parentElement).toArray(); |
|
65 |
} |
|
66 |
else if (parentElement instanceof TaxonDescription) { |
|
67 |
if ( ! ((TaxonDescription) parentElement).isImageGallery()) { |
|
68 |
TaxonDescription description = (TaxonDescription) parentElement; |
|
69 |
|
|
70 |
FeatureNodeContainerTree containerTree = getContainerTreeForDesription(description); |
|
71 |
|
|
72 |
return containerTree.getRoot().getChildren().toArray(); |
|
73 |
} |
|
74 |
} |
|
75 |
else if (parentElement instanceof FeatureNodeContainer){ |
|
76 |
FeatureNodeContainer container = (FeatureNodeContainer) parentElement; |
|
77 |
if(container.isLeaf()){ |
|
78 |
return container.getDescriptionElements().toArray(); |
|
79 |
}else{ |
|
80 |
return container.getChildren().toArray(); |
|
81 |
} |
|
82 |
} |
|
83 |
|
|
84 |
return NO_CHILDREN; |
|
85 |
} |
|
50 | 86 |
|
51 | 87 |
private FeatureNodeContainerTree getContainerTreeForDesription(TaxonDescription description){ |
52 | 88 |
if(! featureNodeContainerCache.containsKey(description)){ |
... | ... | |
56 | 92 |
return featureNodeContainerCache.get(description); |
57 | 93 |
} |
58 | 94 |
|
95 |
/** {@inheritDoc} */ |
|
96 |
@Override |
|
97 |
public boolean hasChildren(Object element) { |
|
98 |
if (element instanceof TaxonDescription){ |
|
99 |
TaxonDescription description = (TaxonDescription) element; |
|
100 |
FeatureNodeContainerTree containerTree = featureNodeContainerCache.get(description); |
|
101 |
if(containerTree != null && containerTree.getRoot() != null){ |
|
102 |
return containerTree.getRoot().getChildren().size() != 0; |
|
103 |
} |
|
104 |
} |
|
105 |
return getChildren(element).length != 0; |
|
106 |
} |
|
107 |
|
|
59 | 108 |
/** |
60 | 109 |
* Retrieves the feature tree associated with the given description |
61 | 110 |
* |
... | ... | |
96 | 145 |
|
97 | 146 |
for(DescriptionBase description : taxon.getDescriptions()){ |
98 | 147 |
if(! description.isImageGallery()){ |
99 |
MarkerType useMarkertype = (MarkerType) CdmStore.getService(ITermService.class).find(UsageTermCollection.uuidUseRecordFeature);
|
|
148 |
MarkerType useMarkertype = (MarkerType) CdmStore.getService(ITermService.class).find(UsageTermCollection.uuidUseMarkerType);
|
|
100 | 149 |
Set<Marker> descriptionMarkers = description.getMarkers(); |
101 | 150 |
if(descriptionMarkers != null) { |
102 | 151 |
for (Marker marker: descriptionMarkers) { |
103 |
//TODO Use the GetbyUUID method |
|
104 | 152 |
if(marker.getMarkerType().equals(useMarkertype)) { |
105 | 153 |
descriptions.add(description); |
106 | 154 |
} |
... | ... | |
111 | 159 |
return descriptions; |
112 | 160 |
} |
113 | 161 |
|
162 |
/* (non-Javadoc) |
|
163 |
* @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object) |
|
164 |
*/ |
|
165 |
/** {@inheritDoc} */ |
|
166 |
public Object getParent(Object element) { |
|
167 |
return null; |
|
168 |
} |
|
169 |
|
|
170 |
/* (non-Javadoc) |
|
171 |
* @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object) |
|
172 |
*/ |
|
173 |
/** {@inheritDoc} */ |
|
174 |
public Object[] getElements(Object inputElement) { |
|
175 |
return getChildren(inputElement); |
|
176 |
} |
|
177 |
|
|
178 |
/* (non-Javadoc) |
|
179 |
* @see org.eclipse.jface.viewers.IContentProvider#dispose() |
|
180 |
*/ |
|
181 |
/** |
|
182 |
* <p>dispose</p> |
|
183 |
*/ |
|
184 |
public void dispose() { |
|
185 |
featureNodeContainerCache.clear(); |
|
186 |
} |
|
187 |
|
|
188 |
/* (non-Javadoc) |
|
189 |
* @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object) |
|
190 |
*/ |
|
191 |
/** {@inheritDoc} */ |
|
192 |
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {} |
|
193 |
|
|
114 | 194 |
} |
Also available in: Unified diff
AT: committing changes to the TaxEditor Post second round of code review