1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.rendering.internal.macro.dashboard; |
21 |
|
|
22 |
|
import java.util.ArrayList; |
23 |
|
import java.util.Collections; |
24 |
|
import java.util.Comparator; |
25 |
|
import java.util.List; |
26 |
|
|
27 |
|
import javax.inject.Inject; |
28 |
|
import javax.inject.Named; |
29 |
|
import javax.inject.Singleton; |
30 |
|
|
31 |
|
import org.xwiki.component.annotation.Component; |
32 |
|
import org.xwiki.component.manager.ComponentManager; |
33 |
|
import org.xwiki.rendering.block.Block; |
34 |
|
import org.xwiki.rendering.block.GroupBlock; |
35 |
|
import org.xwiki.rendering.macro.MacroExecutionException; |
36 |
|
import org.xwiki.rendering.macro.container.ContainerMacroParameters; |
37 |
|
import org.xwiki.rendering.macro.dashboard.DashboardRenderer; |
38 |
|
import org.xwiki.rendering.macro.dashboard.Gadget; |
39 |
|
import org.xwiki.rendering.macro.dashboard.GadgetRenderer; |
40 |
|
import org.xwiki.rendering.transformation.MacroTransformationContext; |
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
@version |
47 |
|
@since |
48 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 6 |
Complexity Density: 0.67 |
|
49 |
|
class ColumnGadget extends Gadget |
50 |
|
{ |
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
private Integer column; |
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
private Integer index; |
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
@param |
65 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
66 |
13 |
ColumnGadget(Gadget gadget)... |
67 |
|
{ |
68 |
13 |
super(gadget.getId(), gadget.getTitle(), gadget.getContent(), gadget.getPosition()); |
69 |
13 |
this.setTitleSource(gadget.getTitleSource()); |
70 |
|
} |
71 |
|
|
72 |
|
|
73 |
|
@return |
74 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
75 |
95 |
public Integer getColumn()... |
76 |
|
{ |
77 |
95 |
return this.column; |
78 |
|
} |
79 |
|
|
80 |
|
|
81 |
|
@return |
82 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
83 |
47 |
public Integer getIndex()... |
84 |
|
{ |
85 |
47 |
return this.index; |
86 |
|
} |
87 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 3 |
Complexity Density: 0.6 |
|
88 |
13 |
@Override... |
89 |
|
public void setPosition(String position) |
90 |
|
{ |
91 |
13 |
super.setPosition(position); |
92 |
|
|
93 |
|
|
94 |
|
|
95 |
|
|
96 |
13 |
String[] split = position.split(","); |
97 |
13 |
try { |
98 |
13 |
this.column = Integer.valueOf(split[0].trim()); |
99 |
13 |
this.index = Integer.valueOf(split[1].trim()); |
100 |
|
} catch (ArrayIndexOutOfBoundsException e) { |
101 |
|
|
102 |
|
} catch (NumberFormatException e) { |
103 |
|
|
104 |
|
} |
105 |
|
} |
106 |
|
} |
107 |
|
|
108 |
|
|
109 |
|
|
110 |
|
|
111 |
|
|
112 |
|
@version |
113 |
|
@since |
114 |
|
|
115 |
|
@Component |
116 |
|
@Named("columns") |
117 |
|
@Singleton |
|
|
| 92.9% |
Uncovered Elements: 3 (42) |
Complexity: 8 |
Complexity Density: 0.27 |
|
118 |
|
public class ColumnsDashboardRenderer implements DashboardRenderer |
119 |
|
{ |
120 |
|
|
121 |
|
|
122 |
|
|
123 |
|
protected static final String CLASS = "class"; |
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
|
128 |
|
protected static final String ID = "id"; |
129 |
|
|
130 |
|
|
131 |
|
@link |
132 |
|
|
133 |
|
@Inject |
134 |
|
private ComponentManager componentManager; |
135 |
|
|
|
|
| 91.9% |
Uncovered Elements: 3 (37) |
Complexity: 6 |
Complexity Density: 0.21 |
|
136 |
3 |
@Override... |
137 |
|
public List<Block> renderGadgets(List<Gadget> gadgets, GadgetRenderer gadgetsRenderer, |
138 |
|
MacroTransformationContext context) throws MacroExecutionException |
139 |
|
{ |
140 |
|
|
141 |
3 |
List<ColumnGadget> columnGadgets = new ArrayList<ColumnGadget>(); |
142 |
3 |
List<Gadget> invalidGadgets = new ArrayList<Gadget>(); |
143 |
3 |
for (Gadget gadget : gadgets) { |
144 |
13 |
ColumnGadget cGadget = new ColumnGadget(gadget); |
145 |
13 |
if (cGadget.getColumn() != null && cGadget.getIndex() != null) { |
146 |
13 |
columnGadgets.add(cGadget); |
147 |
|
} else { |
148 |
0 |
invalidGadgets.add(gadget); |
149 |
|
} |
150 |
|
} |
151 |
|
|
152 |
|
|
153 |
|
|
154 |
3 |
Collections.sort(columnGadgets, new Comparator<ColumnGadget>() |
155 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
156 |
25 |
public int compare(ColumnGadget g1, ColumnGadget g2)... |
157 |
|
{ |
158 |
25 |
return g1.getColumn().equals(g2.getColumn()) ? g1.getIndex() - g2.getIndex() : g1.getColumn() |
159 |
|
- g2.getColumn(); |
160 |
|
} |
161 |
|
}); |
162 |
|
|
163 |
|
|
164 |
|
|
165 |
|
|
166 |
3 |
int columns = 1; |
167 |
3 |
if (!columnGadgets.isEmpty()) { |
168 |
|
|
169 |
3 |
int lastGadgetsColumn = columnGadgets.get(columnGadgets.size() - 1).getColumn(); |
170 |
3 |
if (lastGadgetsColumn > 1) { |
171 |
1 |
columns = lastGadgetsColumn; |
172 |
|
} |
173 |
|
} |
174 |
|
|
175 |
|
|
176 |
3 |
List<Block> gadgetContainers = new ArrayList<Block>(); |
177 |
7 |
for (int i = 0; i < columns; i++) { |
178 |
4 |
GroupBlock gContainer = new GroupBlock(); |
179 |
4 |
gContainer.setParameter(CLASS, DashboardMacro.GADGET_CONTAINER); |
180 |
|
|
181 |
4 |
gContainer.setParameter(ID, DashboardMacro.GADGET_CONTAINER_PREFIX + (i + 1)); |
182 |
4 |
gadgetContainers.add(gContainer); |
183 |
|
} |
184 |
|
|
185 |
|
|
186 |
3 |
ContainerMacroParameters containerParams = new ContainerMacroParameters(); |
187 |
3 |
containerParams.setLayoutStyle("columns"); |
188 |
3 |
BlocksContainerMacro containerMacro = new BlocksContainerMacro(); |
189 |
3 |
containerMacro.setComponentManager(this.componentManager); |
190 |
3 |
containerMacro.setContent(gadgetContainers); |
191 |
3 |
List<Block> layoutedResult = containerMacro.execute(containerParams, null, context); |
192 |
|
|
193 |
3 |
for (ColumnGadget gadget : columnGadgets) { |
194 |
13 |
int columnIndex = gadget.getColumn() - 1; |
195 |
13 |
gadgetContainers.get(columnIndex).addChildren(gadgetsRenderer.decorateGadget(gadget)); |
196 |
|
} |
197 |
|
|
198 |
|
|
199 |
3 |
return layoutedResult; |
200 |
|
} |
201 |
|
} |