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 org.json.JSONException;
|
13
|
|
14
|
import com.vaadin.annotations.AutoGenerated;
|
15
|
import com.vaadin.ui.Alignment;
|
16
|
import com.vaadin.ui.Button;
|
17
|
import com.vaadin.ui.Button.ClickEvent;
|
18
|
import com.vaadin.ui.Button.ClickListener;
|
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.UI;
|
24
|
import com.vaadin.ui.VerticalLayout;
|
25
|
import com.vaadin.ui.Window;
|
26
|
|
27
|
import eu.etaxonomy.cdm.vaadin.container.IdUuidName;
|
28
|
import eu.etaxonomy.cdm.vaadin.jscomponent.D3ConceptRelationshipTree;
|
29
|
import eu.etaxonomy.cdm.vaadin.presenter.ConceptRelationshipPresenter;
|
30
|
import eu.etaxonomy.cdm.vaadin.session.CdmChangeEvent;
|
31
|
import eu.etaxonomy.cdm.vaadin.session.ICdmChangeListener;
|
32
|
import eu.etaxonomy.cdm.vaadin.session.ISelectionListener;
|
33
|
import eu.etaxonomy.cdm.vaadin.session.SelectionEvent;
|
34
|
import eu.etaxonomy.cdm.vaadin.util.CdmVaadinSessionUtilities;
|
35
|
import eu.etaxonomy.cdm.vaadin.view.IConceptRelationshipComponentListener;
|
36
|
|
37
|
/**
|
38
|
* @author cmathew
|
39
|
* @date 9 Apr 2015
|
40
|
*
|
41
|
*/
|
42
|
public class ConceptRelationshipComposite extends CustomComponent implements ISelectionListener, ICdmChangeListener {
|
43
|
|
44
|
/*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */
|
45
|
|
46
|
@AutoGenerated
|
47
|
private VerticalLayout mainLayout;
|
48
|
@AutoGenerated
|
49
|
private D3ConceptRelationshipTree d3ConceptRelationShipTree;
|
50
|
@AutoGenerated
|
51
|
private HorizontalLayout updateHorizontalLayout;
|
52
|
@AutoGenerated
|
53
|
private Button deleteButton;
|
54
|
@AutoGenerated
|
55
|
private Button editButton;
|
56
|
@AutoGenerated
|
57
|
private Button newButton;
|
58
|
|
59
|
private final IConceptRelationshipComponentListener listener;
|
60
|
|
61
|
private IdUuidName fromTaxonIun;
|
62
|
|
63
|
public static final String CREATE_NEW_CR_TITLE = "Create New Concept Relationship";
|
64
|
|
65
|
/**
|
66
|
* The constructor should first build the main layout, set the
|
67
|
* composition root and then do any custom initialization.
|
68
|
*
|
69
|
* The constructor will not be automatically regenerated by the
|
70
|
* visual editor.
|
71
|
*/
|
72
|
public ConceptRelationshipComposite() {
|
73
|
buildMainLayout();
|
74
|
setCompositionRoot(mainLayout);
|
75
|
|
76
|
CdmVaadinSessionUtilities.getCurrentSelectionService().register(this);
|
77
|
CdmVaadinSessionUtilities.getCurrentCdmDataChangeService().register(this);
|
78
|
listener = new ConceptRelationshipPresenter(d3ConceptRelationShipTree);
|
79
|
|
80
|
addUIListeners();
|
81
|
init();
|
82
|
|
83
|
}
|
84
|
|
85
|
|
86
|
private void init() {
|
87
|
initD3ConceptRelationShipTree();
|
88
|
}
|
89
|
|
90
|
private void initD3ConceptRelationShipTree() {
|
91
|
d3ConceptRelationShipTree.setImmediate(true);
|
92
|
}
|
93
|
|
94
|
private void addUIListeners() {
|
95
|
addNewButtonListener();
|
96
|
}
|
97
|
|
98
|
private void addNewButtonListener() {
|
99
|
newButton.addClickListener(new ClickListener() {
|
100
|
|
101
|
@Override
|
102
|
public void buttonClick(ClickEvent event) {
|
103
|
showEditConceptRelationshipWindow(CREATE_NEW_CR_TITLE, fromTaxonIun, null, null);
|
104
|
}
|
105
|
});
|
106
|
}
|
107
|
|
108
|
public static void showEditConceptRelationshipWindow(String windowTitle,
|
109
|
IdUuidName fromTaxonIun,
|
110
|
IdUuidName taxonRTypeIun,
|
111
|
IdUuidName toTaxonIun) {
|
112
|
Window dialog = new Window(windowTitle);
|
113
|
dialog.setModal(false);
|
114
|
dialog.setClosable(false);
|
115
|
dialog.setResizable(false);
|
116
|
UI.getCurrent().addWindow(dialog);
|
117
|
|
118
|
EditConceptRelationshipComposite ecrc = new EditConceptRelationshipComposite(dialog,fromTaxonIun, taxonRTypeIun, toTaxonIun);
|
119
|
dialog.setContent(ecrc);
|
120
|
}
|
121
|
|
122
|
private void refreshRelationshipView() {
|
123
|
if(fromTaxonIun != null) {
|
124
|
try {
|
125
|
listener.refreshRelationshipView(fromTaxonIun);
|
126
|
} catch (JSONException e) {
|
127
|
Notification.show("Error generating concept relation JSON", e.getMessage(), Type.WARNING_MESSAGE);
|
128
|
}
|
129
|
}
|
130
|
}
|
131
|
|
132
|
/* (non-Javadoc)
|
133
|
* @see eu.etaxonomy.cdm.vaadin.session.ISelectionListener#onSelect(eu.etaxonomy.cdm.vaadin.session.SelectionEvent)
|
134
|
*/
|
135
|
@Override
|
136
|
public void onSelect(SelectionEvent event) {
|
137
|
if(event.getSourceType().equals(StatusComposite.class)) {
|
138
|
fromTaxonIun = (IdUuidName)event.getSelectedObjects().get(0);
|
139
|
refreshRelationshipView();
|
140
|
}
|
141
|
|
142
|
}
|
143
|
|
144
|
|
145
|
|
146
|
/* (non-Javadoc)
|
147
|
* @see eu.etaxonomy.cdm.vaadin.session.ICdmChangeListener#onCreate(eu.etaxonomy.cdm.vaadin.session.CdmChangeEvent)
|
148
|
*/
|
149
|
@Override
|
150
|
public void onCreate(CdmChangeEvent event) {
|
151
|
if(event.getSourceType().equals(EditConceptRelationshipComposite.class)) {
|
152
|
refreshRelationshipView();
|
153
|
}
|
154
|
|
155
|
}
|
156
|
|
157
|
|
158
|
/* (non-Javadoc)
|
159
|
* @see eu.etaxonomy.cdm.vaadin.session.ICdmChangeListener#onUpdate(eu.etaxonomy.cdm.vaadin.session.CdmChangeEvent)
|
160
|
*/
|
161
|
@Override
|
162
|
public void onUpdate(CdmChangeEvent event) {
|
163
|
// TODO Auto-generated method stub
|
164
|
|
165
|
}
|
166
|
|
167
|
|
168
|
/* (non-Javadoc)
|
169
|
* @see eu.etaxonomy.cdm.vaadin.session.ICdmChangeListener#onDelete(eu.etaxonomy.cdm.vaadin.session.CdmChangeEvent)
|
170
|
*/
|
171
|
@Override
|
172
|
public void onDelete(CdmChangeEvent event) {
|
173
|
// TODO Auto-generated method stub
|
174
|
|
175
|
}
|
176
|
@AutoGenerated
|
177
|
private VerticalLayout buildMainLayout() {
|
178
|
// common part: create layout
|
179
|
mainLayout = new VerticalLayout();
|
180
|
mainLayout.setImmediate(false);
|
181
|
mainLayout.setWidth("100%");
|
182
|
mainLayout.setHeight("100%");
|
183
|
mainLayout.setMargin(true);
|
184
|
mainLayout.setSpacing(true);
|
185
|
|
186
|
// top-level component properties
|
187
|
setWidth("100.0%");
|
188
|
setHeight("100.0%");
|
189
|
|
190
|
// updateHorizontalLayout
|
191
|
updateHorizontalLayout = buildUpdateHorizontalLayout();
|
192
|
mainLayout.addComponent(updateHorizontalLayout);
|
193
|
mainLayout.setComponentAlignment(updateHorizontalLayout, new Alignment(20));
|
194
|
|
195
|
// d3ConceptRelationShipTree
|
196
|
d3ConceptRelationShipTree = new D3ConceptRelationshipTree();
|
197
|
d3ConceptRelationShipTree.setImmediate(false);
|
198
|
d3ConceptRelationShipTree.setWidth("-1px");
|
199
|
d3ConceptRelationShipTree.setHeight("-1px");
|
200
|
mainLayout.addComponent(d3ConceptRelationShipTree);
|
201
|
mainLayout.setExpandRatio(d3ConceptRelationShipTree, 1.0f);
|
202
|
mainLayout.setComponentAlignment(d3ConceptRelationShipTree, new Alignment(20));
|
203
|
|
204
|
return mainLayout;
|
205
|
}
|
206
|
|
207
|
@AutoGenerated
|
208
|
private HorizontalLayout buildUpdateHorizontalLayout() {
|
209
|
// common part: create layout
|
210
|
updateHorizontalLayout = new HorizontalLayout();
|
211
|
updateHorizontalLayout.setImmediate(false);
|
212
|
updateHorizontalLayout.setWidth("-1px");
|
213
|
updateHorizontalLayout.setHeight("-1px");
|
214
|
updateHorizontalLayout.setMargin(true);
|
215
|
updateHorizontalLayout.setSpacing(true);
|
216
|
|
217
|
// newButton
|
218
|
newButton = new Button();
|
219
|
newButton.setCaption("new");
|
220
|
newButton.setImmediate(true);
|
221
|
newButton.setWidth("-1px");
|
222
|
newButton.setHeight("-1px");
|
223
|
updateHorizontalLayout.addComponent(newButton);
|
224
|
|
225
|
// editButton
|
226
|
editButton = new Button();
|
227
|
editButton.setCaption("edit");
|
228
|
editButton.setImmediate(true);
|
229
|
editButton.setWidth("-1px");
|
230
|
editButton.setHeight("-1px");
|
231
|
updateHorizontalLayout.addComponent(editButton);
|
232
|
|
233
|
// deleteButton
|
234
|
deleteButton = new Button();
|
235
|
deleteButton.setCaption("delete");
|
236
|
deleteButton.setImmediate(true);
|
237
|
deleteButton.setWidth("-1px");
|
238
|
deleteButton.setHeight("-1px");
|
239
|
updateHorizontalLayout.addComponent(deleteButton);
|
240
|
|
241
|
return updateHorizontalLayout;
|
242
|
}
|
243
|
|
244
|
|
245
|
}
|