Project

General

Profile

Download (5.36 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2017 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
package eu.etaxonomy.taxeditor.editor.workingSet;
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

    
18
import javax.annotation.PostConstruct;
19
import javax.annotation.PreDestroy;
20

    
21
import org.bgbm.prometheus.xml.NEWQUALITATIVEPROPERTY;
22
import org.bgbm.prometheus.xml.ONTOLOGYDETAILS;
23
import org.bgbm.prometheus.xml.STRUCTURETERM;
24
import org.bgbm.prometheus.xml.Structure;
25
import org.bgbm.prometheus.xml.TYPETERM;
26
import org.eclipse.e4.ui.di.Focus;
27
import org.eclipse.jface.viewers.TreeViewer;
28
import org.eclipse.swt.SWT;
29
import org.eclipse.swt.widgets.Composite;
30
import org.eclipse.swt.widgets.Tree;
31
import org.eclipse.ui.forms.widgets.TableWrapData;
32
import org.eclipse.ui.forms.widgets.TableWrapLayout;
33

    
34
/**
35
 * @author pplitzner
36
 * @date 24.05.2017
37
 *
38
 */
39
public class FeatureTreeBuilderViewPart {
40

    
41
    private Tree treeStructures;
42
    private Tree treeProperties;
43
    private Tree treeCharacters;
44
    private TreeViewer treeViewerCharacters;
45
    private TreeViewer treeViewerProperties;
46
    private TreeViewer treeViewerStructures;
47

    
48
    public FeatureTreeBuilderViewPart() {
49
        ontology = PrometheusOntology.createOntology();
50
        createIndex(ontology);
51
    }
52

    
53
    /**
54
     * Create contents of the view part.
55
     */
56
    @PostConstruct
57
    public void createControls(Composite parent) {
58
        {
59
            TableWrapLayout twl_parent = new TableWrapLayout();
60
            twl_parent.numColumns = 3;
61
            parent.setLayout(twl_parent);
62
        }
63

    
64
        treeViewerStructures = new TreeViewer(parent, SWT.BORDER);
65
        treeViewerStructures.setColumnProperties(new String[] {});
66
        treeStructures = treeViewerStructures.getTree();
67
        treeStructures.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.FILL_GRAB, 1, 1));
68

    
69
        treeViewerProperties = new TreeViewer(parent, SWT.BORDER);
70
        treeProperties = treeViewerProperties.getTree();
71
        treeProperties.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.FILL_GRAB, 1, 1));
72

    
73
        treeViewerCharacters = new TreeViewer(parent, SWT.BORDER);
74
        treeCharacters = treeViewerCharacters.getTree();
75
        treeCharacters.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.FILL_GRAB, 1, 1));
76

    
77
        init();
78
    }
79

    
80
    private void init(){
81
        treeViewerStructures.setContentProvider(new StructureContenProvider(this));
82
        treeViewerStructures.setLabelProvider(new StructureLabelProvider(this));
83
        treeViewerStructures.setInput("");
84
    }
85

    
86
    @PreDestroy
87
    public void dispose() {
88
    }
89

    
90
    @Focus
91
    public void setFocus() {
92
        // TODO	Set the focus to control
93
    }
94

    
95
    public TreeViewer getTreeViewerCharacters() {
96
        return treeViewerCharacters;
97
    }
98
    public TreeViewer getTreeViewerProperties() {
99
        return treeViewerProperties;
100
    }
101
    public TreeViewer getTreeViewerStructures() {
102
        return treeViewerStructures;
103
    }
104

    
105

    
106
    private final Map<String, List<String>> taxonToCharacterListMap = new HashMap<>();
107

    
108
    private final Map<BigInteger, STRUCTURETERM> structureTermMap = new HashMap<>();
109
    private final Map<BigInteger, TYPETERM> typeTermMap = new HashMap<>();
110
    private final Map<BigInteger, NEWQUALITATIVEPROPERTY> qualPropertyTermMap = new HashMap<>();
111
    private final Map<BigInteger, List<BigInteger>> structureTermToQualPropertyMap = new HashMap<>();
112
    private ONTOLOGYDETAILS ontology;
113

    
114

    
115
    private void createIndex(ONTOLOGYDETAILS ontology){
116
        //structures
117
        List<STRUCTURETERM> terms = ontology.getONTOLOGYDETAILSBody().getTERMS().getSTRUCTURETERMS().getSTRUCTURETERM();
118
        terms.forEach((STRUCTURETERM structureTerm) -> structureTermMap.put(structureTerm.getGLOBALID(), structureTerm));
119
        //type terms
120
        List<TYPETERM> typeTerms = ontology.getONTOLOGYDETAILSBody().getTERMS().getTYPEOFSTRUCTURETERMS().getTYPETERM();
121
        typeTerms.forEach((TYPETERM typeterm) -> typeTermMap.put(typeterm.getGLOBALID(), typeterm));
122
        //properties
123
        List<NEWQUALITATIVEPROPERTY> qualProperties = ontology.getONTOLOGYDETAILSBody().getNewQualitativeProperties().getNEWQUALITATIVEPROPERTY();
124
        qualProperties.forEach((NEWQUALITATIVEPROPERTY newqualitativeproperty) ->
125
        {
126
            BigInteger id = newqualitativeproperty.getIDSEQ();
127
            qualPropertyTermMap.put(id, newqualitativeproperty);
128

    
129
            List<Structure> structures = newqualitativeproperty.getStructuresLinkedToProperty().getStructure();
130
            structures.forEach((Structure structure) ->
131
            {
132
                List<BigInteger> properties = structureTermToQualPropertyMap.get(structure.getRefID());
133
                if(properties==null){
134
                    properties = new ArrayList<>();
135
                }
136
                properties.add(id);
137
                structureTermToQualPropertyMap.put(structure.getRefID(), properties);
138
            });
139
        });
140
    }
141

    
142
    /**
143
     * @return the ontology
144
     */
145
    public ONTOLOGYDETAILS getOntology() {
146
        return ontology;
147
    }
148

    
149
    public Map<BigInteger, STRUCTURETERM> getStructureTermMap() {
150
        return structureTermMap;
151
    }
152
}
(1-1/4)