Project

General

Profile

Download (3.75 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.log4j.Logger;
12
import org.json.JSONArray;
13
import org.json.JSONException;
14
import org.json.JSONObject;
15

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

    
22
import elemental.json.JsonArray;
23

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

    
33
    private static final Logger logger = Logger.getLogger(D3CTree.class);
34

    
35
    public D3CTree() {
36
        addFunction("select", new JavaScriptFunction() {
37

    
38
            @Override
39
			public void call(JsonArray arguments) {
40
				Notification.show("JS Rpc call : click on " + arguments.getString(0));
41
				
42
			}
43
        });
44

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

    
49

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

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

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

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

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

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

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

    
71
            cr1Children.put(0, taxonTo);
72
            cr2Children.put(0, taxonTo);
73
            //String conceptRelationshipTree = taxonFrom.toString();
74
            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\"}";
75
            logger.warn("conceptRelationshipTree : " + conceptRelationshipTree);
76

    
77
            setConceptRelationshipTree(conceptRelationshipTree);
78
        } catch (JSONException e) {
79
            // TODO Auto-generated catch block
80
            e.printStackTrace();
81
        }
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

    
94
}
(1-1/2)