1 |
513ad98e
|
Cherian Mathew
|
/**
|
2 |
6f501be5
|
Cherian Mathew
|
* 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 |
513ad98e
|
Cherian Mathew
|
package eu.etaxonomy.cdm.vaadin.view;
|
10 |
|
|
|
11 |
6f501be5
|
Cherian Mathew
|
import java.util.Arrays;
|
12 |
08af4f8a
|
Cherian Mathew
|
|
13 |
513ad98e
|
Cherian Mathew
|
import com.vaadin.annotations.AutoGenerated;
|
14 |
6f501be5
|
Cherian Mathew
|
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 |
513ad98e
|
Cherian Mathew
|
import com.vaadin.navigator.View;
|
22 |
|
|
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
|
23 |
6f501be5
|
Cherian Mathew
|
import com.vaadin.ui.AbstractSelect.AbstractSelectTargetDetails;
|
24 |
513ad98e
|
Cherian Mathew
|
import com.vaadin.ui.Alignment;
|
25 |
6f501be5
|
Cherian Mathew
|
import com.vaadin.ui.Component;
|
26 |
513ad98e
|
Cherian Mathew
|
import com.vaadin.ui.CustomComponent;
|
27 |
|
|
import com.vaadin.ui.HorizontalLayout;
|
28 |
6f501be5
|
Cherian Mathew
|
import com.vaadin.ui.TreeTable;
|
29 |
513ad98e
|
Cherian Mathew
|
|
30 |
29078af6
|
Andreas Kohlbecker
|
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 |
6f501be5
|
Cherian Mathew
|
import eu.etaxonomy.cdm.vaadin.container.IdUuidName;
|
34 |
|
|
import eu.etaxonomy.cdm.vaadin.container.LeafNodeTaxonContainer;
|
35 |
6809e6bd
|
Cherian Mathew
|
import eu.etaxonomy.cdm.vaadin.jscomponent.D3ConceptRelationshipTree.Direction;
|
36 |
08af4f8a
|
Cherian Mathew
|
import eu.etaxonomy.cdm.vaadin.session.BasicEvent;
|
37 |
6f501be5
|
Cherian Mathew
|
import eu.etaxonomy.cdm.vaadin.session.CdmChangeEvent;
|
38 |
08af4f8a
|
Cherian Mathew
|
import eu.etaxonomy.cdm.vaadin.session.IBasicEventListener;
|
39 |
6f501be5
|
Cherian Mathew
|
import eu.etaxonomy.cdm.vaadin.session.SelectionEvent;
|
40 |
08af4f8a
|
Cherian Mathew
|
import eu.etaxonomy.cdm.vaadin.util.CdmVaadinSessionUtilities;
|
41 |
21a1bf2d
|
Cherian Mathew
|
import eu.etaxonomy.cdm.vaadin.util.CdmVaadinUtilities;
|
42 |
513ad98e
|
Cherian Mathew
|
|
43 |
|
|
/**
|
44 |
|
|
* @author cmathew
|
45 |
539794c5
|
Andreas Müller
|
* @since 9 Apr 2015
|
46 |
513ad98e
|
Cherian Mathew
|
*
|
47 |
|
|
*/
|
48 |
08af4f8a
|
Cherian Mathew
|
public class ConceptRelationshipView extends CustomComponent implements View, IBasicEventListener {
|
49 |
513ad98e
|
Cherian Mathew
|
|
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 |
08af4f8a
|
Cherian Mathew
|
private StatusComposite primaryStatusComposite, secondaryStatusComposite;
|
61 |
6809e6bd
|
Cherian Mathew
|
|
62 |
|
|
private Direction direction;
|
63 |
513ad98e
|
Cherian Mathew
|
/**
|
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 |
aee16929
|
Cherian Mathew
|
public ConceptRelationshipView(String oc, String cc) {
|
71 |
513ad98e
|
Cherian Mathew
|
|
72 |
|
|
buildMainLayout();
|
73 |
|
|
setCompositionRoot(mainLayout);
|
74 |
|
|
|
75 |
f1a1f6de
|
Cherian Mathew
|
|
76 |
08af4f8a
|
Cherian Mathew
|
conceptRelationshipComposite.setView(this);
|
77 |
|
|
|
78 |
f1a1f6de
|
Cherian Mathew
|
setPrimaryStatusCompositeUuid(statusCompositeLeft);
|
79 |
6809e6bd
|
Cherian Mathew
|
direction = Direction.LEFT_RIGHT;
|
80 |
08af4f8a
|
Cherian Mathew
|
CdmVaadinSessionUtilities.getCurrentBasicEventService().register(this);
|
81 |
6f501be5
|
Cherian Mathew
|
|
82 |
aee16929
|
Cherian Mathew
|
statusCompositeLeft.setClassification(oc);
|
83 |
|
|
statusCompositeRight.setClassification(cc);
|
84 |
|
|
|
85 |
6f501be5
|
Cherian Mathew
|
initDropHandlers();
|
86 |
513ad98e
|
Cherian Mathew
|
}
|
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 |
6809e6bd
|
Cherian Mathew
|
public Direction getDirection() {
|
97 |
|
|
return direction;
|
98 |
|
|
}
|
99 |
|
|
|
100 |
6f501be5
|
Cherian Mathew
|
public void initDropHandlers() {
|
101 |
|
|
statusCompositeLeft.getTaxaTreeTable().setDropHandler(new ConceptRelationshipDropHandler(statusCompositeRight));
|
102 |
|
|
statusCompositeRight.getTaxaTreeTable().setDropHandler(new ConceptRelationshipDropHandler(statusCompositeLeft));
|
103 |
|
|
}
|
104 |
|
|
|
105 |
f1a1f6de
|
Cherian Mathew
|
public void setPrimaryStatusCompositeUuid(StatusComposite sc) {
|
106 |
|
|
if(sc != null) {
|
107 |
|
|
if(sc == statusCompositeLeft) {
|
108 |
08af4f8a
|
Cherian Mathew
|
primaryStatusComposite = statusCompositeLeft;
|
109 |
|
|
secondaryStatusComposite = statusCompositeRight;
|
110 |
6809e6bd
|
Cherian Mathew
|
direction = Direction.LEFT_RIGHT;
|
111 |
|
|
}
|
112 |
f1a1f6de
|
Cherian Mathew
|
if(sc == statusCompositeRight) {
|
113 |
08af4f8a
|
Cherian Mathew
|
secondaryStatusComposite = statusCompositeLeft;
|
114 |
|
|
primaryStatusComposite = statusCompositeRight;
|
115 |
6809e6bd
|
Cherian Mathew
|
direction = Direction.RIGHT_LEFT;
|
116 |
08af4f8a
|
Cherian Mathew
|
}
|
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 |
7207e4a0
|
Cherian Mathew
|
if(ConceptRelationshipComposite.UPDATE_START_ID.equals(event.getEventId())) {
|
127 |
aee16929
|
Cherian Mathew
|
primaryStatusComposite.getTaxaTreeTable().setEnabled(false);
|
128 |
|
|
secondaryStatusComposite.getTaxaTreeTable().setSelectable(false);
|
129 |
6f501be5
|
Cherian Mathew
|
}
|
130 |
7207e4a0
|
Cherian Mathew
|
if(ConceptRelationshipComposite.UPDATE_END_ID.equals(event.getEventId())) {
|
131 |
aee16929
|
Cherian Mathew
|
primaryStatusComposite.getTaxaTreeTable().setEnabled(true);
|
132 |
|
|
secondaryStatusComposite.getTaxaTreeTable().setSelectable(true);
|
133 |
6f501be5
|
Cherian Mathew
|
}
|
134 |
08af4f8a
|
Cherian Mathew
|
}
|
135 |
|
|
|
136 |
6f501be5
|
Cherian Mathew
|
private class ConceptRelationshipDropHandler implements DropHandler {
|
137 |
|
|
|
138 |
|
|
private StatusComposite sourceSc;
|
139 |
08af4f8a
|
Cherian Mathew
|
|
140 |
6f501be5
|
Cherian Mathew
|
|
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 |
21a1bf2d
|
Cherian Mathew
|
if(!CdmVaadinUtilities.isSelected(sourceTable, sourceItemId)) {
|
184 |
|
|
CdmVaadinSessionUtilities.getCurrentSelectionService()
|
185 |
6f501be5
|
Cherian Mathew
|
.fireSelectionEvent(new SelectionEvent(Arrays.asList(fromTaxonIun, sourceSc.getSelectedClassificationUuid()), StatusComposite.class), false);
|
186 |
21a1bf2d
|
Cherian Mathew
|
}
|
187 |
|
|
sourceTable.setValue(Arrays.asList(sourceItemId));
|
188 |
6f501be5
|
Cherian Mathew
|
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 |
aee16929
|
Cherian Mathew
|
|
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 |
90cf504a
|
Cherian Mathew
|
statusCompositeLeft.setHeight("100.0%");
|
218 |
aee16929
|
Cherian Mathew
|
mainLayout.addComponent(statusCompositeLeft);
|
219 |
90cf504a
|
Cherian Mathew
|
mainLayout.setExpandRatio(statusCompositeLeft, 1.0f);
|
220 |
f1a1f6de
|
Cherian Mathew
|
mainLayout.setComponentAlignment(statusCompositeLeft, new Alignment(20));
|
221 |
aee16929
|
Cherian Mathew
|
|
222 |
|
|
// conceptRelationshipComposite
|
223 |
|
|
conceptRelationshipComposite = new ConceptRelationshipComposite();
|
224 |
|
|
conceptRelationshipComposite.setImmediate(false);
|
225 |
f1a1f6de
|
Cherian Mathew
|
conceptRelationshipComposite.setWidth("100.0%");
|
226 |
90cf504a
|
Cherian Mathew
|
conceptRelationshipComposite.setHeight("100.0%");
|
227 |
aee16929
|
Cherian Mathew
|
mainLayout.addComponent(conceptRelationshipComposite);
|
228 |
f1a1f6de
|
Cherian Mathew
|
mainLayout.setExpandRatio(conceptRelationshipComposite, 2.3f);
|
229 |
aee16929
|
Cherian Mathew
|
mainLayout.setComponentAlignment(conceptRelationshipComposite, new Alignment(20));
|
230 |
|
|
|
231 |
|
|
// statusCompositeRight
|
232 |
|
|
statusCompositeRight = new StatusComposite();
|
233 |
|
|
statusCompositeRight.setImmediate(false);
|
234 |
|
|
statusCompositeRight.setWidth("-1px");
|
235 |
90cf504a
|
Cherian Mathew
|
statusCompositeRight.setHeight("100.0%");
|
236 |
aee16929
|
Cherian Mathew
|
mainLayout.addComponent(statusCompositeRight);
|
237 |
90cf504a
|
Cherian Mathew
|
mainLayout.setExpandRatio(statusCompositeRight, 1.0f);
|
238 |
f1a1f6de
|
Cherian Mathew
|
mainLayout.setComponentAlignment(statusCompositeRight, new Alignment(20));
|
239 |
aee16929
|
Cherian Mathew
|
|
240 |
|
|
return mainLayout;
|
241 |
|
|
}
|
242 |
513ad98e
|
Cherian Mathew
|
}
|