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.container; |
21 |
|
|
22 |
|
import java.util.HashMap; |
23 |
|
import java.util.List; |
24 |
|
import java.util.Map; |
25 |
|
|
26 |
|
import javax.inject.Inject; |
27 |
|
import javax.inject.Named; |
28 |
|
import javax.inject.Singleton; |
29 |
|
|
30 |
|
import org.apache.commons.lang3.StringUtils; |
31 |
|
import org.xwiki.component.annotation.Component; |
32 |
|
import org.xwiki.rendering.block.Block; |
33 |
|
import org.xwiki.rendering.block.GroupBlock; |
34 |
|
import org.xwiki.rendering.block.match.ClassBlockMatcher; |
35 |
|
import org.xwiki.rendering.macro.container.LayoutManager; |
36 |
|
import org.xwiki.skinx.SkinExtension; |
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
@version |
42 |
|
@since |
43 |
|
|
44 |
|
@Component |
45 |
|
@Named("columns") |
46 |
|
@Singleton |
|
|
| 81.6% |
Uncovered Elements: 7 (38) |
Complexity: 9 |
Complexity Density: 0.39 |
|
47 |
|
public class ColumnsLayoutManager implements LayoutManager |
48 |
|
{ |
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
private static final String CLASS_ATTRIBUTE = "class"; |
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
@Inject |
58 |
|
@Named("ssfx") |
59 |
|
private SkinExtension ssfx; |
60 |
|
|
|
|
| 88.2% |
Uncovered Elements: 4 (34) |
Complexity: 7 |
Complexity Density: 0.32 |
|
61 |
3 |
@Override... |
62 |
|
public void layoutContainer(Block container) |
63 |
|
{ |
64 |
3 |
List<GroupBlock> innerGroups = |
65 |
|
container.getBlocks(new ClassBlockMatcher(GroupBlock.class), Block.Axes.CHILD); |
66 |
|
|
67 |
|
|
68 |
|
|
69 |
3 |
int count = innerGroups.size(); |
70 |
|
|
71 |
3 |
if (innerGroups.size() == 0) { |
72 |
|
|
73 |
0 |
return; |
74 |
|
} |
75 |
|
|
76 |
3 |
Map<String, Object> skinxParams = new HashMap<String, Object>(); |
77 |
3 |
skinxParams.put("forceSkinAction", true); |
78 |
|
|
79 |
3 |
ssfx.use("uicomponents/container/columns.css", skinxParams); |
80 |
|
|
81 |
|
|
82 |
7 |
for (int i = 0; i < count; i++) { |
83 |
4 |
GroupBlock column = innerGroups.get(i); |
84 |
4 |
String classValue = "column"; |
85 |
4 |
if (i == 0) { |
86 |
|
|
87 |
|
|
88 |
3 |
classValue = classValue + " first-column"; |
89 |
|
} |
90 |
4 |
if (i == count - 1) { |
91 |
|
|
92 |
3 |
classValue = classValue + " last-column"; |
93 |
|
} |
94 |
4 |
String oldClass = column.getParameter(CLASS_ATTRIBUTE); |
95 |
4 |
column.setParameter(CLASS_ATTRIBUTE, (StringUtils.isEmpty(oldClass) ? classValue : oldClass + " " |
96 |
|
+ classValue)); |
97 |
|
} |
98 |
|
|
99 |
|
|
100 |
3 |
Map<String, String> clearFloatsParams = new HashMap<String, String>(); |
101 |
3 |
clearFloatsParams.put(CLASS_ATTRIBUTE, "clearfloats"); |
102 |
3 |
String oldClass = container.getParameter(CLASS_ATTRIBUTE); |
103 |
3 |
String newClass = "container-columns container-columns-" + count; |
104 |
3 |
container.setParameter(CLASS_ATTRIBUTE, StringUtils.isEmpty(oldClass) ? newClass : oldClass + " " + newClass); |
105 |
3 |
container.addChild(new GroupBlock(clearFloatsParams)); |
106 |
|
} |
107 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
108 |
0 |
@Override... |
109 |
|
public Object getParameter(String parameterName) |
110 |
|
{ |
111 |
0 |
return null; |
112 |
|
} |
113 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
114 |
0 |
@Override... |
115 |
|
public void setParameter(String parameterName, Object parameterValue) |
116 |
|
{ |
117 |
|
} |
118 |
|
} |