Project

General

Profile

Download (5.34 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.component;
11

    
12
import java.util.UUID;
13

    
14
import org.json.JSONException;
15

    
16
import com.vaadin.annotations.AutoGenerated;
17
import com.vaadin.ui.Alignment;
18
import com.vaadin.ui.Button;
19
import com.vaadin.ui.CustomComponent;
20
import com.vaadin.ui.HorizontalLayout;
21
import com.vaadin.ui.Notification;
22
import com.vaadin.ui.Notification.Type;
23
import com.vaadin.ui.VerticalLayout;
24

    
25
import eu.etaxonomy.cdm.vaadin.jscomponent.D3ConceptRelationshipTree;
26
import eu.etaxonomy.cdm.vaadin.presenter.ConceptRelationshipPresenter;
27
import eu.etaxonomy.cdm.vaadin.session.ISelectionListener;
28
import eu.etaxonomy.cdm.vaadin.session.SelectionEvent;
29
import eu.etaxonomy.cdm.vaadin.util.CdmVaadinSessionUtilities;
30
import eu.etaxonomy.cdm.vaadin.view.IConceptRelationshipComponentListener;
31

    
32
/**
33
 * @author cmathew
34
 * @date 9 Apr 2015
35
 *
36
 */
37
public class ConceptRelationshipComposite extends CustomComponent implements ISelectionListener {
38

    
39
    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */
40

    
41
    @AutoGenerated
42
    private VerticalLayout mainLayout;
43
    @AutoGenerated
44
    private D3ConceptRelationshipTree d3ConceptRelationShipTree;
45
    @AutoGenerated
46
    private HorizontalLayout updateHorizontalLayout;
47
    @AutoGenerated
48
    private Button deleteButton;
49
    @AutoGenerated
50
    private Button editButton;
51
    @AutoGenerated
52
    private Button newButton;
53
    private final IConceptRelationshipComponentListener listener;
54
    /**
55
     * The constructor should first build the main layout, set the
56
     * composition root and then do any custom initialization.
57
     *
58
     * The constructor will not be automatically regenerated by the
59
     * visual editor.
60
     */
61
    public ConceptRelationshipComposite() {
62
        buildMainLayout();
63
        setCompositionRoot(mainLayout);
64

    
65
        CdmVaadinSessionUtilities.getCurrentSelectionService().register(this);
66
        listener = new ConceptRelationshipPresenter(d3ConceptRelationShipTree);
67
        d3ConceptRelationShipTree.setImmediate(true);
68

    
69
    }
70

    
71
    /* (non-Javadoc)
72
     * @see eu.etaxonomy.cdm.vaadin.session.ISelectionListener#onSelect(eu.etaxonomy.cdm.vaadin.session.SelectionEvent)
73
     */
74
    @Override
75
    public void onSelect(SelectionEvent event) {
76
        if(event.getSourceType().equals(StatusComposite.class)) {
77
            UUID taxonUuid = (UUID)event.getSelectedObjects().get(0);
78
            try {
79
                listener.updateConceptRelationship(taxonUuid);
80
            } catch (JSONException e) {
81
               Notification.show("Error generating concept relation JSON",  e.getMessage(), Type.WARNING_MESSAGE);
82
            }
83
        }
84

    
85
    }
86

    
87
    @AutoGenerated
88
    private VerticalLayout buildMainLayout() {
89
        // common part: create layout
90
        mainLayout = new VerticalLayout();
91
        mainLayout.setImmediate(false);
92
        mainLayout.setWidth("100%");
93
        mainLayout.setHeight("100%");
94
        mainLayout.setMargin(true);
95
        mainLayout.setSpacing(true);
96

    
97
        // top-level component properties
98
        setWidth("100.0%");
99
        setHeight("100.0%");
100

    
101
        // updateHorizontalLayout
102
        updateHorizontalLayout = buildUpdateHorizontalLayout();
103
        mainLayout.addComponent(updateHorizontalLayout);
104
        mainLayout.setComponentAlignment(updateHorizontalLayout, new Alignment(20));
105

    
106
        // d3ConceptRelationShipTree
107
        d3ConceptRelationShipTree = new D3ConceptRelationshipTree();
108
        d3ConceptRelationShipTree.setImmediate(false);
109
        d3ConceptRelationShipTree.setWidth("-1px");
110
        d3ConceptRelationShipTree.setHeight("-1px");
111
        mainLayout.addComponent(d3ConceptRelationShipTree);
112
        mainLayout.setExpandRatio(d3ConceptRelationShipTree, 1.0f);
113
        mainLayout.setComponentAlignment(d3ConceptRelationShipTree, new Alignment(20));
114

    
115
        return mainLayout;
116
    }
117

    
118
    @AutoGenerated
119
    private HorizontalLayout buildUpdateHorizontalLayout() {
120
        // common part: create layout
121
        updateHorizontalLayout = new HorizontalLayout();
122
        updateHorizontalLayout.setImmediate(false);
123
        updateHorizontalLayout.setWidth("-1px");
124
        updateHorizontalLayout.setHeight("-1px");
125
        updateHorizontalLayout.setMargin(true);
126
        updateHorizontalLayout.setSpacing(true);
127

    
128
        // newButton
129
        newButton = new Button();
130
        newButton.setCaption("new");
131
        newButton.setImmediate(true);
132
        newButton.setWidth("-1px");
133
        newButton.setHeight("-1px");
134
        updateHorizontalLayout.addComponent(newButton);
135

    
136
        // editButton
137
        editButton = new Button();
138
        editButton.setCaption("edit");
139
        editButton.setImmediate(true);
140
        editButton.setWidth("-1px");
141
        editButton.setHeight("-1px");
142
        updateHorizontalLayout.addComponent(editButton);
143

    
144
        // deleteButton
145
        deleteButton = new Button();
146
        deleteButton.setCaption("delete");
147
        deleteButton.setImmediate(true);
148
        deleteButton.setWidth("-1px");
149
        deleteButton.setHeight("-1px");
150
        updateHorizontalLayout.addComponent(deleteButton);
151

    
152
        return updateHorizontalLayout;
153
    }
154

    
155
}
(1-1/4)