Project

General

Profile

Download (3.92 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
 * Copyright (C) 2015 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
 */
9
package eu.etaxonomy.cdm.vaadin.jscomponent;
10

    
11
import org.apache.logging.log4j.LogManager;
12
import org.apache.logging.log4j.Logger;
13
import org.json.JSONArray;
14
import org.json.JSONException;
15
import org.json.JSONObject;
16

    
17
import com.vaadin.annotations.JavaScript;
18
import com.vaadin.annotations.StyleSheet;
19
import com.vaadin.ui.AbstractJavaScriptComponent;
20
import com.vaadin.ui.JavaScriptFunction;
21
import com.vaadin.ui.Notification;
22

    
23
import elemental.json.JsonArray;
24

    
25
/**
26
 * @author cmathew
27
 * @since 8 Apr 2015
28
 *
29
 */
30
@StyleSheet({"css/d3.ctree.css"})
31
@JavaScript({"extlib/d3.min.js", "lib/d3ctree_connector.js"})
32
public class D3CTree extends AbstractJavaScriptComponent {
33

    
34
    private static final long serialVersionUID = 910149189854426279L;
35
    private static final Logger logger = LogManager.getLogger();
36

    
37
    public D3CTree() {
38
        addFunction("select", new JavaScriptFunction() {
39
            private static final long serialVersionUID = 3021677255132798998L;
40
            @Override
41
			public void call(JsonArray arguments) {
42
				Notification.show("JS Rpc call : click on " + arguments.getString(0));
43
			}
44
        });
45

    
46
        try {
47
            JSONObject taxonFrom = new JSONObject();
48
            taxonFrom.put("name", "taxon from");
49

    
50

    
51
            JSONArray tfChildren = new JSONArray();
52
            taxonFrom.put("children", tfChildren);
53

    
54
            JSONObject conceptRelationship1 = new JSONObject();
55
            conceptRelationship1.put("name", "concept relationship 1");
56

    
57
            JSONArray cr1Children = new JSONArray();
58
            conceptRelationship1.put("children", cr1Children);
59

    
60
            JSONObject conceptRelationship2 = new JSONObject();
61
            conceptRelationship2.put("name", "concept relationship 2");
62

    
63
            JSONArray cr2Children = new JSONArray();
64
            conceptRelationship2.put("children", cr2Children);
65

    
66
            tfChildren.put(0, conceptRelationship1);
67
            tfChildren.put(1, conceptRelationship2);
68

    
69
            JSONObject taxonTo = new JSONObject();
70
            taxonTo.put("name", "taxon to");
71

    
72
            cr1Children.put(0, taxonTo);
73
            cr2Children.put(0, taxonTo);
74
            //String conceptRelationshipTree = taxonFrom.toString();
75
            String conceptRelationshipTree = "{\"direction\":\"right-left\",\"name\":\"Taxon d\",\"children\":[{\"name\":\"Congruent to\",\"children\":[{\"name\":\"Taxon e\",\"uuid\":\"84e99e24-f50a-4726-92d0-6088430c492a\",\"type\":\"taxon\"}],\"uuid\":\"511f504b-ae3b-4f04-b7b9-35c222f06e10\",\"type\":\"conceptr\"},{\"name\":\"Includes\",\"children\":[{\"name\":\"Taxon a\",\"uuid\":\"eaac797e-cac7-4649-97cf-c7b580076895\",\"type\":\"taxon\"}],\"uuid\":\"0e8b7922-974d-4389-b71e-af6fc9f98c56\",\"type\":\"conceptr\"},{\"name\":\"Includes\",\"children\":[{\"name\":\"Taxon b\",\"uuid\":\"5004a8e7-b907-4744-b67e-44ccb057ab3b\",\"type\":\"taxon\"}],\"uuid\":\"6fd9947e-21c3-4190-8748-57d9661e8659\",\"type\":\"conceptr\"},{\"name\":\"Excludes\",\"children\":[{\"name\":\"Taxon c\",\"uuid\":\"3d71c8b8-3bec-4f5f-ba23-6f9d55ef84e9\",\"type\":\"taxon\"}],\"uuid\":\"cc761030-38d2-4b5d-954d-32329c0ea106\",\"type\":\"conceptr\"}],\"uuid\":\"5f713f69-e03e-4a11-8a55-700fbbf44805\",\"type\":\"taxon\"}";
76
            logger.warn("conceptRelationshipTree : " + conceptRelationshipTree);
77

    
78
            setConceptRelationshipTree(conceptRelationshipTree);
79
        } catch (JSONException e) {
80
            // TODO Auto-generated catch block
81
            e.printStackTrace();
82
        }
83
    }
84

    
85
    public void setConceptRelationshipTree(String conceptRelationshipTree) {
86
        getState().setConceptRelationshipTree(conceptRelationshipTree);
87
    }
88

    
89
    @Override
90
    public D3CTreeState getState() {
91
        return (D3CTreeState) super.getState();
92
    }
93
}
(1-1/2)