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.view;
|
11
|
|
12
|
import java.util.Arrays;
|
13
|
import java.util.UUID;
|
14
|
|
15
|
import com.vaadin.annotations.AutoGenerated;
|
16
|
import com.vaadin.data.Container;
|
17
|
import com.vaadin.event.Transferable;
|
18
|
import com.vaadin.event.dd.DragAndDropEvent;
|
19
|
import com.vaadin.event.dd.DropHandler;
|
20
|
import com.vaadin.event.dd.DropTarget;
|
21
|
import com.vaadin.event.dd.acceptcriteria.AcceptAll;
|
22
|
import com.vaadin.event.dd.acceptcriteria.AcceptCriterion;
|
23
|
import com.vaadin.navigator.View;
|
24
|
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
|
25
|
import com.vaadin.ui.AbstractSelect.AbstractSelectTargetDetails;
|
26
|
import com.vaadin.ui.Alignment;
|
27
|
import com.vaadin.ui.Component;
|
28
|
import com.vaadin.ui.CustomComponent;
|
29
|
import com.vaadin.ui.HorizontalLayout;
|
30
|
import com.vaadin.ui.TreeTable;
|
31
|
|
32
|
import eu.etaxonomy.cdm.vaadin.component.ConceptRelationshipComposite;
|
33
|
import eu.etaxonomy.cdm.vaadin.component.EditConceptRelationshipComposite;
|
34
|
import eu.etaxonomy.cdm.vaadin.component.StatusComposite;
|
35
|
import eu.etaxonomy.cdm.vaadin.container.IdUuidName;
|
36
|
import eu.etaxonomy.cdm.vaadin.container.LeafNodeTaxonContainer;
|
37
|
import eu.etaxonomy.cdm.vaadin.jscomponent.D3ConceptRelationshipTree.Direction;
|
38
|
import eu.etaxonomy.cdm.vaadin.session.BasicEvent;
|
39
|
import eu.etaxonomy.cdm.vaadin.session.CdmChangeEvent;
|
40
|
import eu.etaxonomy.cdm.vaadin.session.IBasicEventListener;
|
41
|
import eu.etaxonomy.cdm.vaadin.session.SelectionEvent;
|
42
|
import eu.etaxonomy.cdm.vaadin.util.CdmVaadinSessionUtilities;
|
43
|
|
44
|
/**
|
45
|
* @author cmathew
|
46
|
* @date 9 Apr 2015
|
47
|
*
|
48
|
*/
|
49
|
public class ConceptRelationshipView extends CustomComponent implements View, IBasicEventListener {
|
50
|
|
51
|
/*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */
|
52
|
|
53
|
@AutoGenerated
|
54
|
private HorizontalLayout mainLayout;
|
55
|
@AutoGenerated
|
56
|
private StatusComposite statusCompositeRight;
|
57
|
@AutoGenerated
|
58
|
private ConceptRelationshipComposite conceptRelationshipComposite;
|
59
|
@AutoGenerated
|
60
|
private StatusComposite statusCompositeLeft;
|
61
|
|
62
|
private StatusComposite primaryStatusComposite, secondaryStatusComposite;
|
63
|
|
64
|
private Direction direction;
|
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 ConceptRelationshipView() {
|
73
|
|
74
|
buildMainLayout();
|
75
|
setCompositionRoot(mainLayout);
|
76
|
|
77
|
conceptRelationshipComposite.setView(this);
|
78
|
conceptRelationshipComposite.setSizeFull();
|
79
|
|
80
|
setPrimaryStatusCompositeUuid(statusCompositeLeft.getSelectedClassificationUuid());
|
81
|
direction = Direction.LEFT_RIGHT;
|
82
|
CdmVaadinSessionUtilities.getCurrentBasicEventService().register(this);
|
83
|
|
84
|
initDropHandlers();
|
85
|
}
|
86
|
|
87
|
/* (non-Javadoc)
|
88
|
* @see com.vaadin.navigator.View#enter(com.vaadin.navigator.ViewChangeListener.ViewChangeEvent)
|
89
|
*/
|
90
|
@Override
|
91
|
public void enter(ViewChangeEvent event) {
|
92
|
// TODO Auto-generated method stub
|
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(UUID scUuid) {
|
106
|
if(scUuid != null) {
|
107
|
if(scUuid.equals(statusCompositeLeft.getSelectedClassificationUuid())) {
|
108
|
primaryStatusComposite = statusCompositeLeft;
|
109
|
secondaryStatusComposite = statusCompositeRight;
|
110
|
direction = Direction.LEFT_RIGHT;
|
111
|
}
|
112
|
if(scUuid.equals(statusCompositeRight.getSelectedClassificationUuid())) {
|
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(event.getEventId().equals(ConceptRelationshipComposite.UPDATE_START_ID)) {
|
127
|
primaryStatusComposite.setTaxaTableEnabled(false);
|
128
|
secondaryStatusComposite.setTaxaTableSelectable(false);
|
129
|
}
|
130
|
if(event.getEventId().equals(ConceptRelationshipComposite.UPDATE_END_ID)) {
|
131
|
primaryStatusComposite.setTaxaTableEnabled(true);
|
132
|
secondaryStatusComposite.setTaxaTableSelectable(true);
|
133
|
}
|
134
|
}
|
135
|
|
136
|
@AutoGenerated
|
137
|
private HorizontalLayout buildMainLayout() {
|
138
|
// common part: create layout
|
139
|
mainLayout = new HorizontalLayout();
|
140
|
mainLayout.setImmediate(false);
|
141
|
mainLayout.setWidth("100%");
|
142
|
mainLayout.setHeight("100%");
|
143
|
mainLayout.setMargin(true);
|
144
|
|
145
|
// top-level component properties
|
146
|
setWidth("100.0%");
|
147
|
setHeight("100.0%");
|
148
|
|
149
|
// statusCompositeLeft
|
150
|
statusCompositeLeft = new StatusComposite();
|
151
|
statusCompositeLeft.setImmediate(false);
|
152
|
statusCompositeLeft.setWidth("-1px");
|
153
|
statusCompositeLeft.setHeight("-1px");
|
154
|
mainLayout.addComponent(statusCompositeLeft);
|
155
|
|
156
|
// conceptRelationshipComposite
|
157
|
conceptRelationshipComposite = new ConceptRelationshipComposite();
|
158
|
conceptRelationshipComposite.setImmediate(false);
|
159
|
conceptRelationshipComposite.setWidth("-1px");
|
160
|
conceptRelationshipComposite.setHeight("-1px");
|
161
|
mainLayout.addComponent(conceptRelationshipComposite);
|
162
|
mainLayout.setExpandRatio(conceptRelationshipComposite, 1.0f);
|
163
|
mainLayout.setComponentAlignment(conceptRelationshipComposite, new Alignment(20));
|
164
|
|
165
|
// statusCompositeRight
|
166
|
statusCompositeRight = new StatusComposite();
|
167
|
statusCompositeRight.setImmediate(false);
|
168
|
statusCompositeRight.setWidth("-1px");
|
169
|
statusCompositeRight.setHeight("-1px");
|
170
|
mainLayout.addComponent(statusCompositeRight);
|
171
|
|
172
|
return mainLayout;
|
173
|
}
|
174
|
|
175
|
private class ConceptRelationshipDropHandler implements DropHandler {
|
176
|
|
177
|
private StatusComposite sourceSc;
|
178
|
|
179
|
|
180
|
public ConceptRelationshipDropHandler(StatusComposite sourceSc) {
|
181
|
this.sourceSc = sourceSc;
|
182
|
}
|
183
|
|
184
|
@Override
|
185
|
public AcceptCriterion getAcceptCriterion() {
|
186
|
return AcceptAll.get();
|
187
|
}
|
188
|
|
189
|
@Override
|
190
|
public void drop(DragAndDropEvent event) {
|
191
|
// Wrapper for the object that is dragged
|
192
|
Transferable t = event.getTransferable();
|
193
|
Component source = t.getSourceComponent();
|
194
|
|
195
|
// This is the case where the source of the dd is another
|
196
|
// taxon table not the one in this object
|
197
|
if (source instanceof TreeTable && source == sourceSc.getTaxaTreeTable()) {
|
198
|
TreeTable sourceTable = (TreeTable)t.getSourceComponent();
|
199
|
LeafNodeTaxonContainer sourceContainer = (LeafNodeTaxonContainer)sourceTable.getContainerDataSource();
|
200
|
|
201
|
IdUuidName fromTaxonIun, toTaxonIun;
|
202
|
|
203
|
Object sourceItemId = t.getData("itemId");
|
204
|
String fromName = (String)sourceContainer.getProperty(sourceItemId, LeafNodeTaxonContainer.NAME_ID).getValue();
|
205
|
|
206
|
AbstractSelectTargetDetails dropData = ((AbstractSelectTargetDetails) event.getTargetDetails());
|
207
|
DropTarget target = dropData.getTarget();
|
208
|
if(target instanceof TreeTable) {
|
209
|
TreeTable targetTable = (TreeTable)target;
|
210
|
Container container = targetTable.getContainerDataSource();
|
211
|
if(container instanceof LeafNodeTaxonContainer) {
|
212
|
LeafNodeTaxonContainer targetContainer = (LeafNodeTaxonContainer)container;
|
213
|
Object targetItemId = dropData.getItemIdOver();
|
214
|
String toName = (String)targetContainer.getProperty(targetItemId, LeafNodeTaxonContainer.NAME_ID).getValue();
|
215
|
|
216
|
fromTaxonIun = new IdUuidName(sourceItemId,
|
217
|
sourceContainer.getUuid(sourceItemId),
|
218
|
fromName);
|
219
|
toTaxonIun = new IdUuidName(targetItemId,
|
220
|
targetContainer.getUuid(targetItemId),
|
221
|
toName);
|
222
|
CdmVaadinSessionUtilities.getCurrentSelectionService()
|
223
|
.fireSelectionEvent(new SelectionEvent(Arrays.asList(fromTaxonIun, sourceSc.getSelectedClassificationUuid()), StatusComposite.class), false);
|
224
|
EditConceptRelationshipComposite.showInDialog(ConceptRelationshipComposite.CREATE_NEW_CR_TITLE,
|
225
|
fromTaxonIun,
|
226
|
null,
|
227
|
toTaxonIun,
|
228
|
CdmChangeEvent.Action.Create,
|
229
|
direction);
|
230
|
}
|
231
|
}
|
232
|
|
233
|
}
|
234
|
|
235
|
}
|
236
|
|
237
|
}
|
238
|
}
|