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
46
47
48
49
50
51 public class LazyLayoutServerRpcImpl implements LazyLayoutServerRpc {
52
53 private DataProviderKeyMapper mapper;
54 private LazyLayoutClientRpc clientRpc;
55 private LazyLayout lazyLayout;
56
57 public LazyLayoutServerRpcImpl(DataProviderKeyMapper mapper, LazyLayoutClientRpc clientRpc, LazyLayout lazyLayout) {
58 this.mapper = mapper;
59 this.clientRpc = clientRpc;
60 this.lazyLayout = lazyLayout;
61 }
62
63 public void loadElements(int startFrom, int length, int cachedFirst, int cachedLast) {
64 final Range rangeToLoad = Range.withLength(startFrom, length);
65 final Range cachedRange = Range.between(cachedFirst, cachedLast);
66 final Range activeRange = cachedRange.isEmpty() ? rangeToLoad : rangeToLoad.combineWith(cachedRange);
67
68 mapper.setActiveRange(activeRange);
69 clientRpc.addElements(lazyLayout.fetchElements(rangeToLoad, mapper), rangeToLoad.getStart());
70 }
71
72 public void onElementsSelected(int index, boolean isMetaKeyPressed, boolean isShiftKeyPressed) {
73 lazyLayout.handleSelectionAtIndex(index, isMetaKeyPressed || isShiftKeyPressed);
74 lazyLayout.fireSelectionChange();
75 }
76
77 public void onElementDoubleClicked(int index) {
78 final Object itemId = mapper.itemIdAtIndex(index);
79 if (itemId != null) {
80 lazyLayout.onElementDoubleClicked(itemId);
81 }
82 }
83
84 public void onElementRightClicked(int index, int clickX, int clickY) {
85 final Object itemId = mapper.itemIdAtIndex(index);
86 if (itemId != null) {
87 lazyLayout.onElementRightClicked(itemId, clickX, clickY);
88 }
89 }
90
91 public void updateOffset(int currentElementOffset) {
92 lazyLayout.getState(false).offset = currentElementOffset;
93 }
94
95 public void setScaleRatio(float ratio) {
96 lazyLayout.getState(false).scaleRatio = ratio;
97 }
98 }