Project

General

Profile

Download (2.79 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
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
/**
24
 * @author cmathew
25
 * @date 8 Apr 2015
26
 *
27
 */
28
@StyleSheet({"css/d3.ctree.css"})
29
@JavaScript({"extlib/d3.min.js", "lib/d3ctree_connector.js"})
30
public class D3CTree extends AbstractJavaScriptComponent {
31

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

    
34
    public D3CTree() {
35
        addFunction("test", new JavaScriptFunction() {
36

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

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

    
47

    
48
            JSONArray tfChildren = new JSONArray();
49
            taxonFrom.put("children", tfChildren);
50

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

    
54
            JSONArray cr1Children = new JSONArray();
55
            conceptRelationship1.put("children", cr1Children);
56

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

    
60
            JSONArray cr2Children = new JSONArray();
61
            conceptRelationship2.put("children", cr2Children);
62

    
63
            tfChildren.put(0, conceptRelationship1);
64
            tfChildren.put(1, conceptRelationship2);
65

    
66
            JSONObject taxonTo = new JSONObject();
67
            taxonTo.put("name", "taxon to");
68

    
69
            cr1Children.put(0, taxonTo);
70
            cr2Children.put(0, taxonTo);
71
            String conceptRelationshipTree = taxonFrom.toString();
72

    
73
            logger.warn("conceptRelationshipTree : " + conceptRelationshipTree);
74

    
75
            setConceptRelationshipTree(conceptRelationshipTree);
76
        } catch (JSONException e) {
77
            // TODO Auto-generated catch block
78
            e.printStackTrace();
79
        }
80

    
81
    }
82

    
83
    public void setConceptRelationshipTree(String conceptRelationshipTree) {
84
        getState().setConceptRelationshipTree(conceptRelationshipTree);;
85
    }
86

    
87
    @Override
88
    public D3CTreeState getState() {
89
        return (D3CTreeState) super.getState();
90
    }
91

    
92
}
(1-1/2)