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