Revision 6e249736
Added by Patrick Plitzner almost 7 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/FeatureTreeBuilderViewPart.java | ||
---|---|---|
9 | 9 |
*/ |
10 | 10 |
package eu.etaxonomy.taxeditor.editor.workingSet; |
11 | 11 |
|
12 |
import java.math.BigInteger; |
|
13 |
import java.util.ArrayList; |
|
14 |
import java.util.HashMap; |
|
15 |
import java.util.List; |
|
16 |
import java.util.Map; |
|
17 | 12 |
import java.util.UUID; |
18 | 13 |
|
19 | 14 |
import javax.annotation.PostConstruct; |
20 | 15 |
import javax.annotation.PreDestroy; |
21 | 16 |
|
22 |
import org.bgbm.prometheus.xml.NEWQUALITATIVEPROPERTY; |
|
23 |
import org.bgbm.prometheus.xml.ONTOLOGYDETAILS; |
|
24 |
import org.bgbm.prometheus.xml.STRUCTURETERM; |
|
25 |
import org.bgbm.prometheus.xml.Structure; |
|
26 |
import org.bgbm.prometheus.xml.TYPETERM; |
|
27 | 17 |
import org.eclipse.e4.ui.di.Focus; |
28 | 18 |
import org.eclipse.jface.viewers.TreeViewer; |
29 | 19 |
import org.eclipse.swt.SWT; |
30 | 20 |
import org.eclipse.swt.layout.FillLayout; |
31 | 21 |
import org.eclipse.swt.widgets.Composite; |
32 |
import org.eclipse.swt.widgets.Tree; |
|
33 | 22 |
|
34 | 23 |
import eu.etaxonomy.cdm.api.service.IVocabularyService; |
35 | 24 |
import eu.etaxonomy.cdm.model.common.TermVocabulary; |
... | ... | |
42 | 31 |
*/ |
43 | 32 |
public class FeatureTreeBuilderViewPart { |
44 | 33 |
|
45 |
private Tree treeStructures; |
|
46 |
private Tree treeProperties; |
|
47 |
private Tree treeCharacters; |
|
48 | 34 |
private TreeViewer treeViewerCharacters; |
49 | 35 |
private TreeViewer treeViewerProperties; |
50 | 36 |
private TreeViewer treeViewerStructures; |
51 | 37 |
|
52 | 38 |
public FeatureTreeBuilderViewPart() { |
53 |
ontology = PrometheusOntology.createOntology(); |
|
54 |
createIndex(ontology); |
|
55 | 39 |
} |
56 | 40 |
|
57 | 41 |
/** |
... | ... | |
63 | 47 |
|
64 | 48 |
treeViewerStructures = new TreeViewer(parent, SWT.BORDER); |
65 | 49 |
treeViewerStructures.setColumnProperties(new String[] {}); |
66 |
treeStructures = treeViewerStructures.getTree(); |
|
67 | 50 |
|
68 | 51 |
treeViewerProperties = new TreeViewer(parent, SWT.BORDER); |
69 |
treeProperties = treeViewerProperties.getTree(); |
|
70 | 52 |
|
71 | 53 |
treeViewerCharacters = new TreeViewer(parent, SWT.BORDER); |
72 |
treeCharacters = treeViewerCharacters.getTree(); |
|
73 | 54 |
|
74 | 55 |
init(); |
75 | 56 |
} |
76 | 57 |
|
77 | 58 |
private void init(){ |
78 |
TermVocabulary vocabulary = CdmStore.getService(IVocabularyService.class).load(UUID.fromString("b94244a5-5040-4c00-be34-12137c4b192f"));
|
|
79 |
treeViewerStructures.setContentProvider(new StructureContentProvider(vocabulary));
|
|
59 |
TermVocabulary structureVoc = CdmStore.getService(IVocabularyService.class).load(UUID.fromString("51f3a28e-6c1a-40bf-b504-012a12d69112"));
|
|
60 |
treeViewerStructures.setContentProvider(new StructureContentProvider()); |
|
80 | 61 |
treeViewerStructures.setLabelProvider(new StructureLabelProvider()); |
81 |
treeViewerStructures.setInput(""); |
|
62 |
treeViewerStructures.setInput(structureVoc); |
|
63 |
|
|
64 |
TermVocabulary propertiesVoc = CdmStore.getService(IVocabularyService.class).load(UUID.fromString("c5ff574b-40a5-4046-b2a0-59bfbe6b6616")); |
|
65 |
treeViewerProperties.setContentProvider(new StructureContentProvider()); |
|
66 |
treeViewerProperties.setLabelProvider(new StructureLabelProvider()); |
|
67 |
treeViewerProperties.setInput(propertiesVoc); |
|
82 | 68 |
} |
83 | 69 |
|
84 | 70 |
@PreDestroy |
... | ... | |
87 | 73 |
|
88 | 74 |
@Focus |
89 | 75 |
public void setFocus() { |
90 |
// TODO Set the focus to control |
|
91 | 76 |
} |
92 | 77 |
|
93 | 78 |
public TreeViewer getTreeViewerCharacters() { |
... | ... | |
100 | 85 |
return treeViewerStructures; |
101 | 86 |
} |
102 | 87 |
|
103 |
|
|
104 |
private final Map<String, List<String>> taxonToCharacterListMap = new HashMap<>(); |
|
105 |
|
|
106 |
private final Map<BigInteger, STRUCTURETERM> structureTermMap = new HashMap<>(); |
|
107 |
private final Map<BigInteger, TYPETERM> typeTermMap = new HashMap<>(); |
|
108 |
private final Map<BigInteger, NEWQUALITATIVEPROPERTY> qualPropertyTermMap = new HashMap<>(); |
|
109 |
private final Map<BigInteger, List<BigInteger>> structureTermToQualPropertyMap = new HashMap<>(); |
|
110 |
private ONTOLOGYDETAILS ontology; |
|
111 |
|
|
112 |
|
|
113 |
private void createIndex(ONTOLOGYDETAILS ontology){ |
|
114 |
//structures |
|
115 |
List<STRUCTURETERM> terms = ontology.getONTOLOGYDETAILSBody().getTERMS().getSTRUCTURETERMS().getSTRUCTURETERM(); |
|
116 |
terms.forEach((STRUCTURETERM structureTerm) -> structureTermMap.put(structureTerm.getGLOBALID(), structureTerm)); |
|
117 |
//type terms |
|
118 |
List<TYPETERM> typeTerms = ontology.getONTOLOGYDETAILSBody().getTERMS().getTYPEOFSTRUCTURETERMS().getTYPETERM(); |
|
119 |
typeTerms.forEach((TYPETERM typeterm) -> typeTermMap.put(typeterm.getGLOBALID(), typeterm)); |
|
120 |
//properties |
|
121 |
List<NEWQUALITATIVEPROPERTY> qualProperties = ontology.getONTOLOGYDETAILSBody().getNewQualitativeProperties().getNEWQUALITATIVEPROPERTY(); |
|
122 |
qualProperties.forEach((NEWQUALITATIVEPROPERTY newqualitativeproperty) -> |
|
123 |
{ |
|
124 |
BigInteger id = newqualitativeproperty.getIDSEQ(); |
|
125 |
qualPropertyTermMap.put(id, newqualitativeproperty); |
|
126 |
|
|
127 |
List<Structure> structures = newqualitativeproperty.getStructuresLinkedToProperty().getStructure(); |
|
128 |
structures.forEach((Structure structure) -> |
|
129 |
{ |
|
130 |
List<BigInteger> properties = structureTermToQualPropertyMap.get(structure.getRefID()); |
|
131 |
if(properties==null){ |
|
132 |
properties = new ArrayList<>(); |
|
133 |
} |
|
134 |
properties.add(id); |
|
135 |
structureTermToQualPropertyMap.put(structure.getRefID(), properties); |
|
136 |
}); |
|
137 |
}); |
|
138 |
} |
|
139 |
|
|
140 |
/** |
|
141 |
* @return the ontology |
|
142 |
*/ |
|
143 |
public ONTOLOGYDETAILS getOntology() { |
|
144 |
return ontology; |
|
145 |
} |
|
146 |
|
|
147 |
public Map<BigInteger, STRUCTURETERM> getStructureTermMap() { |
|
148 |
return structureTermMap; |
|
149 |
} |
|
150 | 88 |
} |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/PrometheusOntology.java | ||
---|---|---|
1 |
package eu.etaxonomy.taxeditor.editor.workingSet; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.io.IOException; |
|
5 |
import java.net.URISyntaxException; |
|
6 |
import java.net.URL; |
|
7 |
|
|
8 |
import javax.xml.bind.JAXBContext; |
|
9 |
import javax.xml.bind.JAXBException; |
|
10 |
import javax.xml.bind.Unmarshaller; |
|
11 |
|
|
12 |
import org.bgbm.prometheus.xml.ONTOLOGYDETAILS; |
|
13 |
import org.bgbm.prometheus.xml.TreeNode; |
|
14 |
import org.eclipse.core.runtime.FileLocator; |
|
15 |
import org.eclipse.core.runtime.Path; |
|
16 |
import org.eclipse.core.runtime.Platform; |
|
17 |
|
|
18 |
public class PrometheusOntology { |
|
19 |
|
|
20 |
public static ONTOLOGYDETAILS createOntology() { |
|
21 |
try { |
|
22 |
|
|
23 |
URL url = null; |
|
24 |
URL iconUrl = FileLocator.find(Platform.getBundle("eu.etaxonomy.taxeditor.editor"), new Path("icons/Ontology.xml"), null); |
|
25 |
// URL url = PrometheusOntology.class.getResource("Ontology.xml"); |
|
26 |
File file = null; |
|
27 |
try { |
|
28 |
file = new File(FileLocator.resolve(iconUrl).toURI()); |
|
29 |
} catch (URISyntaxException | IOException e) { |
|
30 |
// TODO Auto-generated catch block |
|
31 |
e.printStackTrace(); |
|
32 |
} |
|
33 |
JAXBContext jaxbContext = JAXBContext.newInstance(ONTOLOGYDETAILS.class, TreeNode.class); |
|
34 |
|
|
35 |
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); |
|
36 |
ONTOLOGYDETAILS unmarshal = (ONTOLOGYDETAILS) jaxbUnmarshaller.unmarshal(file); |
|
37 |
return unmarshal; |
|
38 |
|
|
39 |
} catch (JAXBException e) { |
|
40 |
e.printStackTrace(); |
|
41 |
} |
|
42 |
return null; |
|
43 |
} |
|
44 |
|
|
45 |
public static void main(String[] args) { |
|
46 |
createOntology(); |
|
47 |
} |
|
48 |
} |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/StructureContentProvider.java | ||
---|---|---|
9 | 9 |
*/ |
10 | 10 |
package eu.etaxonomy.taxeditor.editor.workingSet; |
11 | 11 |
|
12 |
import java.util.HashSet; |
|
13 |
import java.util.Set; |
|
14 |
import java.util.SortedSet; |
|
15 |
|
|
12 | 16 |
import org.eclipse.jface.viewers.ITreeContentProvider; |
13 | 17 |
|
18 |
import eu.etaxonomy.cdm.model.common.DefinedTermBase; |
|
14 | 19 |
import eu.etaxonomy.cdm.model.common.TermVocabulary; |
15 | 20 |
import eu.etaxonomy.cdm.model.description.Feature; |
21 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
|
16 | 22 |
|
17 | 23 |
/** |
18 | 24 |
* @author pplitzner |
... | ... | |
21 | 27 |
*/ |
22 | 28 |
public class StructureContentProvider implements ITreeContentProvider { |
23 | 29 |
|
24 |
private TermVocabulary<Feature> root; |
|
25 |
|
|
26 |
public StructureContentProvider(TermVocabulary<Feature> root) { |
|
27 |
this.root = root; |
|
30 |
public StructureContentProvider() { |
|
28 | 31 |
} |
29 | 32 |
|
30 | 33 |
/** |
... | ... | |
32 | 35 |
*/ |
33 | 36 |
@Override |
34 | 37 |
public Object[] getElements(Object inputElement) { |
35 |
return root.getTerms().toArray();
|
|
38 |
return getTopLevelElements((TermVocabulary<Feature>) inputElement);
|
|
36 | 39 |
} |
37 | 40 |
|
38 | 41 |
/** |
... | ... | |
59 | 62 |
return !((Feature)element).getIncludes().isEmpty(); |
60 | 63 |
} |
61 | 64 |
|
65 |
/** |
|
66 |
* |
|
67 |
* @param vocabulary |
|
68 |
* @return An array of DefinedTermBase objects that do not have parents |
|
69 |
* |
|
70 |
* TODO: Needs to be implemented in cdmlib |
|
71 |
*/ |
|
72 |
private Object[] getTopLevelElements(TermVocabulary vocabulary) { |
|
73 |
|
|
74 |
SortedSet<DefinedTermBase> terms = vocabulary.getTermsOrderedByLabels(CdmStore.getDefaultLanguage()); |
|
75 |
Set<DefinedTermBase> topLevelTerms = new HashSet<DefinedTermBase>(); |
|
76 |
|
|
77 |
for (DefinedTermBase term : terms){ |
|
78 |
if (term.getPartOf() == null){ |
|
79 |
topLevelTerms.add(term); |
|
80 |
} |
|
81 |
} |
|
82 |
return topLevelTerms.toArray(); |
|
83 |
} |
|
84 |
|
|
62 | 85 |
} |
eu.etaxonomy.taxeditor.editor/src/main/java/org/bgbm/prometheus/.gitignore | ||
---|---|---|
1 |
/xml/ |
Also available in: Unified diff
Show properties in property tree