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
|
|
54
|
private final IConceptRelationshipComponentListener listener;
|
55
|
|
56
|
private UUID currentFromTaxonUuid;
|
57
|
|
58
|
/**
|
59
|
* The constructor should first build the main layout, set the
|
60
|
* composition root and then do any custom initialization.
|
61
|
*
|
62
|
* The constructor will not be automatically regenerated by the
|
63
|
* visual editor.
|
64
|
*/
|
65
|
public ConceptRelationshipComposite() {
|
66
|
buildMainLayout();
|
67
|
setCompositionRoot(mainLayout);
|
68
|
|
69
|
CdmVaadinSessionUtilities.getCurrentSelectionService().register(this);
|
70
|
listener = new ConceptRelationshipPresenter(d3ConceptRelationShipTree);
|
71
|
d3ConceptRelationShipTree.setImmediate(true);
|
72
|
|
73
|
}
|
74
|
|
75
|
/* (non-Javadoc)
|
76
|
* @see eu.etaxonomy.cdm.vaadin.session.ISelectionListener#onSelect(eu.etaxonomy.cdm.vaadin.session.SelectionEvent)
|
77
|
*/
|
78
|
@Override
|
79
|
public void onSelect(SelectionEvent event) {
|
80
|
if(event.getSourceType().equals(StatusComposite.class)) {
|
81
|
currentFromTaxonUuid = (UUID)event.getSelectedObjects().get(0);
|
82
|
try {
|
83
|
listener.refreshRelationshipView(currentFromTaxonUuid);
|
84
|
} catch (JSONException e) {
|
85
|
Notification.show("Error generating concept relation JSON", e.getMessage(), Type.WARNING_MESSAGE);
|
86
|
}
|
87
|
}
|
88
|
|
89
|
}
|
90
|
|
91
|
@AutoGenerated
|
92
|
private VerticalLayout buildMainLayout() {
|
93
|
// common part: create layout
|
94
|
mainLayout = new VerticalLayout();
|
95
|
mainLayout.setImmediate(false);
|
96
|
mainLayout.setWidth("100%");
|
97
|
mainLayout.setHeight("100%");
|
98
|
mainLayout.setMargin(true);
|
99
|
mainLayout.setSpacing(true);
|
100
|
|
101
|
// top-level component properties
|
102
|
setWidth("100.0%");
|
103
|
setHeight("100.0%");
|
104
|
|
105
|
// updateHorizontalLayout
|
106
|
updateHorizontalLayout = buildUpdateHorizontalLayout();
|
107
|
mainLayout.addComponent(updateHorizontalLayout);
|
108
|
mainLayout.setComponentAlignment(updateHorizontalLayout, new Alignment(20));
|
109
|
|
110
|
// d3ConceptRelationShipTree
|
111
|
d3ConceptRelationShipTree = new D3ConceptRelationshipTree();
|
112
|
d3ConceptRelationShipTree.setImmediate(false);
|
113
|
d3ConceptRelationShipTree.setWidth("-1px");
|
114
|
d3ConceptRelationShipTree.setHeight("-1px");
|
115
|
mainLayout.addComponent(d3ConceptRelationShipTree);
|
116
|
mainLayout.setExpandRatio(d3ConceptRelationShipTree, 1.0f);
|
117
|
mainLayout.setComponentAlignment(d3ConceptRelationShipTree, new Alignment(20));
|
118
|
|
119
|
return mainLayout;
|
120
|
}
|
121
|
|
122
|
@AutoGenerated
|
123
|
private HorizontalLayout buildUpdateHorizontalLayout() {
|
124
|
// common part: create layout
|
125
|
updateHorizontalLayout = new HorizontalLayout();
|
126
|
updateHorizontalLayout.setImmediate(false);
|
127
|
updateHorizontalLayout.setWidth("-1px");
|
128
|
updateHorizontalLayout.setHeight("-1px");
|
129
|
updateHorizontalLayout.setMargin(true);
|
130
|
updateHorizontalLayout.setSpacing(true);
|
131
|
|
132
|
// newButton
|
133
|
newButton = new Button();
|
134
|
newButton.setCaption("new");
|
135
|
newButton.setImmediate(true);
|
136
|
newButton.setWidth("-1px");
|
137
|
newButton.setHeight("-1px");
|
138
|
updateHorizontalLayout.addComponent(newButton);
|
139
|
|
140
|
// editButton
|
141
|
editButton = new Button();
|
142
|
editButton.setCaption("edit");
|
143
|
editButton.setImmediate(true);
|
144
|
editButton.setWidth("-1px");
|
145
|
editButton.setHeight("-1px");
|
146
|
updateHorizontalLayout.addComponent(editButton);
|
147
|
|
148
|
// deleteButton
|
149
|
deleteButton = new Button();
|
150
|
deleteButton.setCaption("delete");
|
151
|
deleteButton.setImmediate(true);
|
152
|
deleteButton.setWidth("-1px");
|
153
|
deleteButton.setHeight("-1px");
|
154
|
updateHorizontalLayout.addComponent(deleteButton);
|
155
|
|
156
|
return updateHorizontalLayout;
|
157
|
}
|
158
|
|
159
|
}
|