1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package info.magnolia.ui.vaadin.layout;
35
36 import info.magnolia.ui.vaadin.gwt.client.layout.lazylayout.rpc.LazyLayoutClientRpc;
37 import info.magnolia.ui.vaadin.gwt.client.layout.lazylayout.rpc.LazyLayoutServerRpc;
38 import info.magnolia.ui.vaadin.gwt.shared.Range;
39 import info.magnolia.ui.vaadin.layout.LazyLayout.DataProviderKeyMapper;
40
41
42
43
44
45 public class LazyLayoutServerRpcImpl implements LazyLayoutServerRpc {
46
47 private DataProviderKeyMapper mapper;
48 private LazyLayoutClientRpc clientRpc;
49 private LazyLayout lazyLayout;
50
51 public LazyLayoutServerRpcImpl(DataProviderKeyMapper mapper, LazyLayoutClientRpc clientRpc, LazyLayout lazyLayout) {
52 this.mapper = mapper;
53 this.clientRpc = clientRpc;
54 this.lazyLayout = lazyLayout;
55 }
56
57 public void loadElements(int startFrom, int length, int cachedFirst, int cachedLast) {
58 final Range rangeToLoad = Range.withLength(startFrom, length);
59 final Range cachedRange = Range.between(cachedFirst, cachedLast);
60 final Range activeRange = cachedRange.isEmpty() ? rangeToLoad : rangeToLoad.combineWith(cachedRange);
61
62 mapper.setActiveRange(activeRange);
63 clientRpc.addElements(lazyLayout.fetchElements(rangeToLoad), rangeToLoad.getStart());
64 lazyLayout.updateSelectionIndices();
65 }
66
67 public void onElementsSelected(int index, boolean isMetaKeyPressed, boolean isShiftKeyPressed) {
68 lazyLayout.handleSelectionAtIndex(index, isMetaKeyPressed || isShiftKeyPressed);
69 lazyLayout.fireSelectionChange();
70 }
71
72 public void onElementDoubleClicked(int index) {
73 final Object item = mapper.itemAtIndex(index);
74 if (item != null) {
75 lazyLayout.onElementDoubleClicked(item);
76 }
77 }
78
79 public void onElementRightClicked(int index, int clickX, int clickY) {
80 final Object item = mapper.itemAtIndex(index);
81 if (item != null) {
82 lazyLayout.onElementRightClicked(item, clickX, clickY);
83 }
84 }
85
86 public void updateOffset(int currentElementOffset) {
87 lazyLayout.getState(false).offset = currentElementOffset;
88 }
89
90 public void setScaleRatio(float ratio) {
91 lazyLayout.getState(false).scaleRatio = ratio;
92 }
93 }