Project

General

Profile

Download (3.84 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
 * Copyright (C) 2015 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.cdm.vaadin.jscomponent;
11

    
12
import org.apache.log4j.Logger;
13

    
14
import com.google.gwt.json.client.JSONException;
15
import com.vaadin.annotations.JavaScript;
16
import com.vaadin.annotations.StyleSheet;
17
import com.vaadin.ui.AbstractJavaScriptComponent;
18
import com.vaadin.ui.JavaScriptFunction;
19
import com.vaadin.ui.Notification;
20

    
21
import elemental.json.Json;
22
import elemental.json.JsonArray;
23
import elemental.json.JsonObject;
24

    
25
/**
26
 * @author cmathew
27
 * @date 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 Logger logger = Logger.getLogger(D3CTree.class);
35

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

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

    
45
        try {
46
            JsonObject taxonFrom = Json.createObject();
47
            taxonFrom.put("name", "taxon from");
48

    
49

    
50
            JsonArray tfChildren = Json.createArray();
51
            taxonFrom.put("children", tfChildren);
52

    
53
            JsonObject conceptRelationship1 = Json.createObject();
54
            conceptRelationship1.put("name", "concept relationship 1");
55

    
56
            JsonArray cr1Children = Json.createArray();
57
            conceptRelationship1.put("children", cr1Children);
58

    
59
            JsonObject conceptRelationship2 = Json.createObject();
60
            conceptRelationship2.put("name", "concept relationship 2");
61

    
62
            JsonArray cr2Children = Json.createArray();
63
            conceptRelationship2.put("children", cr2Children);
64

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

    
68
            JsonObject taxonTo = Json.createObject();
69
            taxonTo.put("name", "taxon to");
70

    
71
            cr1Children.set(0, taxonTo);
72
            cr2Children.set(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)