1
|
/**
|
2
|
* Copyright (C) 2015 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.vaadin.view;
|
10
|
|
11
|
import java.util.Arrays;
|
12
|
|
13
|
import com.vaadin.annotations.AutoGenerated;
|
14
|
import com.vaadin.data.Container;
|
15
|
import com.vaadin.event.Transferable;
|
16
|
import com.vaadin.event.dd.DragAndDropEvent;
|
17
|
import com.vaadin.event.dd.DropHandler;
|
18
|
import com.vaadin.event.dd.DropTarget;
|
19
|
import com.vaadin.event.dd.acceptcriteria.AcceptAll;
|
20
|
import com.vaadin.event.dd.acceptcriteria.AcceptCriterion;
|
21
|
import com.vaadin.navigator.View;
|
22
|
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
|
23
|
import com.vaadin.ui.AbstractSelect.AbstractSelectTargetDetails;
|
24
|
import com.vaadin.ui.Alignment;
|
25
|
import com.vaadin.ui.Component;
|
26
|
import com.vaadin.ui.CustomComponent;
|
27
|
import com.vaadin.ui.HorizontalLayout;
|
28
|
import com.vaadin.ui.TreeTable;
|
29
|
|
30
|
import eu.etaxonomy.cdm.vaadin.component.taxon.ConceptRelationshipComposite;
|
31
|
import eu.etaxonomy.cdm.vaadin.component.taxon.EditConceptRelationshipComposite;
|
32
|
import eu.etaxonomy.cdm.vaadin.component.taxon.StatusComposite;
|
33
|
import eu.etaxonomy.cdm.vaadin.container.IdUuidName;
|
34
|
import eu.etaxonomy.cdm.vaadin.container.LeafNodeTaxonContainer;
|
35
|
import eu.etaxonomy.cdm.vaadin.jscomponent.D3ConceptRelationshipTree.Direction;
|
36
|
import eu.etaxonomy.cdm.vaadin.session.BasicEvent;
|
37
|
import eu.etaxonomy.cdm.vaadin.session.CdmChangeEvent;
|
38
|
import eu.etaxonomy.cdm.vaadin.session.IBasicEventListener;
|
39
|
import eu.etaxonomy.cdm.vaadin.session.SelectionEvent;
|
40
|
import eu.etaxonomy.cdm.vaadin.util.CdmVaadinSessionUtilities;
|
41
|
import eu.etaxonomy.cdm.vaadin.util.CdmVaadinUtilities;
|
42
|
|
43
|
/**
|
44
|
* @author cmathew
|
45
|
* @date 9 Apr 2015
|
46
|
*
|
47
|
*/
|
48
|
public class ConceptRelationshipView extends CustomComponent implements View, IBasicEventListener {
|
49
|
|
50
|
/*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */
|
51
|
|
52
|
@AutoGenerated
|
53
|
private HorizontalLayout mainLayout;
|
54
|
@AutoGenerated
|
55
|
private StatusComposite statusCompositeRight;
|
56
|
@AutoGenerated
|
57
|
private ConceptRelationshipComposite conceptRelationshipComposite;
|
58
|
@AutoGenerated
|
59
|
private StatusComposite statusCompositeLeft;
|
60
|
private StatusComposite primaryStatusComposite, secondaryStatusComposite;
|
61
|
|
62
|
private Direction direction;
|
63
|
/**
|
64
|
* The constructor should first build the main layout, set the
|
65
|
* composition root and then do any custom initialization.
|
66
|
*
|
67
|
* The constructor will not be automatically regenerated by the
|
68
|
* visual editor.
|
69
|
*/
|
70
|
public ConceptRelationshipView(String oc, String cc) {
|
71
|
|
72
|
buildMainLayout();
|
73
|
setCompositionRoot(mainLayout);
|
74
|
|
75
|
|
76
|
conceptRelationshipComposite.setView(this);
|
77
|
|
78
|
setPrimaryStatusCompositeUuid(statusCompositeLeft);
|
79
|
direction = Direction.LEFT_RIGHT;
|
80
|
CdmVaadinSessionUtilities.getCurrentBasicEventService().register(this);
|
81
|
|
82
|
statusCompositeLeft.setClassification(oc);
|
83
|
statusCompositeRight.setClassification(cc);
|
84
|
|
85
|
initDropHandlers();
|
86
|
}
|
87
|
|
88
|
/* (non-Javadoc)
|
89
|
* @see com.vaadin.navigator.View#enter(com.vaadin.navigator.ViewChangeListener.ViewChangeEvent)
|
90
|
*/
|
91
|
@Override
|
92
|
public void enter(ViewChangeEvent event) {
|
93
|
|
94
|
}
|
95
|
|
96
|
public Direction getDirection() {
|
97
|
return direction;
|
98
|
}
|
99
|
|
100
|
public void initDropHandlers() {
|
101
|
statusCompositeLeft.getTaxaTreeTable().setDropHandler(new ConceptRelationshipDropHandler(statusCompositeRight));
|
102
|
statusCompositeRight.getTaxaTreeTable().setDropHandler(new ConceptRelationshipDropHandler(statusCompositeLeft));
|
103
|
}
|
104
|
|
105
|
public void setPrimaryStatusCompositeUuid(StatusComposite sc) {
|
106
|
if(sc != null) {
|
107
|
if(sc == statusCompositeLeft) {
|
108
|
primaryStatusComposite = statusCompositeLeft;
|
109
|
secondaryStatusComposite = statusCompositeRight;
|
110
|
direction = Direction.LEFT_RIGHT;
|
111
|
}
|
112
|
if(sc == statusCompositeRight) {
|
113
|
secondaryStatusComposite = statusCompositeLeft;
|
114
|
primaryStatusComposite = statusCompositeRight;
|
115
|
direction = Direction.RIGHT_LEFT;
|
116
|
}
|
117
|
secondaryStatusComposite.clearTaxaTableSelections();
|
118
|
}
|
119
|
}
|
120
|
|
121
|
/* (non-Javadoc)
|
122
|
* @see eu.etaxonomy.cdm.vaadin.session.IBasicEventListener#onAction(eu.etaxonomy.cdm.vaadin.session.BasicEvent)
|
123
|
*/
|
124
|
@Override
|
125
|
public void onAction(BasicEvent event) {
|
126
|
if(ConceptRelationshipComposite.UPDATE_START_ID.equals(event.getEventId())) {
|
127
|
primaryStatusComposite.getTaxaTreeTable().setEnabled(false);
|
128
|
secondaryStatusComposite.getTaxaTreeTable().setSelectable(false);
|
129
|
}
|
130
|
if(ConceptRelationshipComposite.UPDATE_END_ID.equals(event.getEventId())) {
|
131
|
primaryStatusComposite.getTaxaTreeTable().setEnabled(true);
|
132
|
secondaryStatusComposite.getTaxaTreeTable().setSelectable(true);
|
133
|
}
|
134
|
}
|
135
|
|
136
|
private class ConceptRelationshipDropHandler implements DropHandler {
|
137
|
|
138
|
private StatusComposite sourceSc;
|
139
|
|
140
|
|
141
|
public ConceptRelationshipDropHandler(StatusComposite sourceSc) {
|
142
|
this.sourceSc = sourceSc;
|
143
|
}
|
144
|
|
145
|
@Override
|
146
|
public AcceptCriterion getAcceptCriterion() {
|
147
|
return AcceptAll.get();
|
148
|
}
|
149
|
|
150
|
@Override
|
151
|
public void drop(DragAndDropEvent event) {
|
152
|
// Wrapper for the object that is dragged
|
153
|
Transferable t = event.getTransferable();
|
154
|
Component source = t.getSourceComponent();
|
155
|
|
156
|
// This is the case where the source of the dd is another
|
157
|
// taxon table not the one in this object
|
158
|
if (source instanceof TreeTable && source == sourceSc.getTaxaTreeTable()) {
|
159
|
TreeTable sourceTable = (TreeTable)t.getSourceComponent();
|
160
|
LeafNodeTaxonContainer sourceContainer = (LeafNodeTaxonContainer)sourceTable.getContainerDataSource();
|
161
|
|
162
|
IdUuidName fromTaxonIun, toTaxonIun;
|
163
|
|
164
|
Object sourceItemId = t.getData("itemId");
|
165
|
String fromName = (String)sourceContainer.getProperty(sourceItemId, LeafNodeTaxonContainer.NAME_ID).getValue();
|
166
|
|
167
|
AbstractSelectTargetDetails dropData = ((AbstractSelectTargetDetails) event.getTargetDetails());
|
168
|
DropTarget target = dropData.getTarget();
|
169
|
if(target instanceof TreeTable) {
|
170
|
TreeTable targetTable = (TreeTable)target;
|
171
|
Container container = targetTable.getContainerDataSource();
|
172
|
if(container instanceof LeafNodeTaxonContainer) {
|
173
|
LeafNodeTaxonContainer targetContainer = (LeafNodeTaxonContainer)container;
|
174
|
Object targetItemId = dropData.getItemIdOver();
|
175
|
String toName = (String)targetContainer.getProperty(targetItemId, LeafNodeTaxonContainer.NAME_ID).getValue();
|
176
|
|
177
|
fromTaxonIun = new IdUuidName(sourceItemId,
|
178
|
sourceContainer.getUuid(sourceItemId),
|
179
|
fromName);
|
180
|
toTaxonIun = new IdUuidName(targetItemId,
|
181
|
targetContainer.getUuid(targetItemId),
|
182
|
toName);
|
183
|
if(!CdmVaadinUtilities.isSelected(sourceTable, sourceItemId)) {
|
184
|
CdmVaadinSessionUtilities.getCurrentSelectionService()
|
185
|
.fireSelectionEvent(new SelectionEvent(Arrays.asList(fromTaxonIun, sourceSc.getSelectedClassificationUuid()), StatusComposite.class), false);
|
186
|
}
|
187
|
sourceTable.setValue(Arrays.asList(sourceItemId));
|
188
|
EditConceptRelationshipComposite.showInDialog(ConceptRelationshipComposite.CREATE_NEW_CR_TITLE,
|
189
|
fromTaxonIun,
|
190
|
null,
|
191
|
toTaxonIun,
|
192
|
CdmChangeEvent.Action.Create,
|
193
|
direction);
|
194
|
}
|
195
|
}
|
196
|
}
|
197
|
}
|
198
|
}
|
199
|
|
200
|
@AutoGenerated
|
201
|
private HorizontalLayout buildMainLayout() {
|
202
|
// common part: create layout
|
203
|
mainLayout = new HorizontalLayout();
|
204
|
mainLayout.setImmediate(false);
|
205
|
mainLayout.setWidth("100%");
|
206
|
mainLayout.setHeight("100%");
|
207
|
mainLayout.setMargin(true);
|
208
|
|
209
|
// top-level component properties
|
210
|
setWidth("100.0%");
|
211
|
setHeight("100.0%");
|
212
|
|
213
|
// statusCompositeLeft
|
214
|
statusCompositeLeft = new StatusComposite();
|
215
|
statusCompositeLeft.setImmediate(false);
|
216
|
statusCompositeLeft.setWidth("-1px");
|
217
|
statusCompositeLeft.setHeight("100.0%");
|
218
|
mainLayout.addComponent(statusCompositeLeft);
|
219
|
mainLayout.setExpandRatio(statusCompositeLeft, 1.0f);
|
220
|
mainLayout.setComponentAlignment(statusCompositeLeft, new Alignment(20));
|
221
|
|
222
|
// conceptRelationshipComposite
|
223
|
conceptRelationshipComposite = new ConceptRelationshipComposite();
|
224
|
conceptRelationshipComposite.setImmediate(false);
|
225
|
conceptRelationshipComposite.setWidth("100.0%");
|
226
|
conceptRelationshipComposite.setHeight("100.0%");
|
227
|
mainLayout.addComponent(conceptRelationshipComposite);
|
228
|
mainLayout.setExpandRatio(conceptRelationshipComposite, 2.3f);
|
229
|
mainLayout.setComponentAlignment(conceptRelationshipComposite, new Alignment(20));
|
230
|
|
231
|
// statusCompositeRight
|
232
|
statusCompositeRight = new StatusComposite();
|
233
|
statusCompositeRight.setImmediate(false);
|
234
|
statusCompositeRight.setWidth("-1px");
|
235
|
statusCompositeRight.setHeight("100.0%");
|
236
|
mainLayout.addComponent(statusCompositeRight);
|
237
|
mainLayout.setExpandRatio(statusCompositeRight, 1.0f);
|
238
|
mainLayout.setComponentAlignment(statusCompositeRight, new Alignment(20));
|
239
|
|
240
|
return mainLayout;
|
241
|
}
|
242
|
}
|