Class | Line # | Actions | |||||
---|---|---|---|---|---|---|---|
BlocksContainerMacro | 44 | 6 | 0% | 6 | 2 |
1 | /* | |
2 | * See the NOTICE file distributed with this work for additional | |
3 | * information regarding copyright ownership. | |
4 | * | |
5 | * This is free software; you can redistribute it and/or modify it | |
6 | * under the terms of the GNU Lesser General Public License as | |
7 | * published by the Free Software Foundation; either version 2.1 of | |
8 | * the License, or (at your option) any later version. | |
9 | * | |
10 | * This software is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | * Lesser General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU Lesser General Public | |
16 | * License along with this software; if not, write to the Free | |
17 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | |
18 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org. | |
19 | */ | |
20 | package org.xwiki.rendering.internal.macro.dashboard; | |
21 | ||
22 | import java.util.ArrayList; | |
23 | import java.util.List; | |
24 | ||
25 | import org.xwiki.component.manager.ComponentManager; | |
26 | import org.xwiki.rendering.block.Block; | |
27 | import org.xwiki.rendering.macro.MacroExecutionException; | |
28 | import org.xwiki.rendering.macro.container.AbstractContainerMacro; | |
29 | import org.xwiki.rendering.macro.container.ContainerMacroParameters; | |
30 | import org.xwiki.rendering.transformation.MacroTransformationContext; | |
31 | ||
32 | /** | |
33 | * Version of the container macro that takes a list of blocks as content and renders them according to the parameters in | |
34 | * {@link ContainerMacroParameters}. Also, it can be instantiated and used as a POJO, not only injected by the component | |
35 | * manager, as long as an instance of the component manager is being passed with | |
36 | * {@link #setComponentManager(ComponentManager)}. <br> | |
37 | * TODO: this macro should be defined in the container macro package, since it's generic enough. Unfortunately, this | |
38 | * macro cannot be made public, since ftm there is no mechanism to hide macros from user (in the wysiwyg list, for | |
39 | * example), which forces us to keep it here with package visibility, so it can be used in the gadgets implementation. | |
40 | * | |
41 | * @version $Id: 9a7438f50551f22bf20e1fb0e3bd34775f508466 $ | |
42 | * @since 3.0M3 | |
43 | */ | |
44 | class BlocksContainerMacro extends AbstractContainerMacro<ContainerMacroParameters> | |
45 | { | |
46 | /** | |
47 | * The component manager, injected to this macro by the caller, since this macro cannot be exposed to the cm because | |
48 | * we don't want it available in the macros list. <br> | |
49 | * FIXME: when we will be able to hide macros from the user, this should be implemented properly as a component. | |
50 | */ | |
51 | private ComponentManager componentManager; | |
52 | ||
53 | /** | |
54 | * The macro block of the gadget macro inside the dashboard, will be used as the content of this box. | |
55 | */ | |
56 | private List<Block> content = new ArrayList<Block>(); | |
57 | ||
58 | /** | |
59 | * Default constructor, building a blocks macro with the default name and description. | |
60 | */ | |
61 | 3 | BlocksContainerMacro() |
62 | { | |
63 | 3 | super("Container", "Lays out the blocks passed as content according to the passed parameters.", |
64 | null, ContainerMacroParameters.class); | |
65 | } | |
66 | ||
67 | 3 | @Override |
68 | protected List<Block> getContent(ContainerMacroParameters parameters, String content, | |
69 | MacroTransformationContext context) throws MacroExecutionException | |
70 | { | |
71 | 3 | return this.content; |
72 | } | |
73 | ||
74 | /** | |
75 | * @return the componentManager used by this macro to find components. | |
76 | */ | |
77 | 3 | @Override |
78 | public ComponentManager getComponentManager() | |
79 | { | |
80 | 3 | return componentManager; |
81 | } | |
82 | ||
83 | /** | |
84 | * Sets the component manager of this container macro. | |
85 | * | |
86 | * @param componentManager the {@link ComponentManager} to set | |
87 | */ | |
88 | 3 | public void setComponentManager(ComponentManager componentManager) |
89 | { | |
90 | 3 | this.componentManager = componentManager; |
91 | } | |
92 | ||
93 | /** | |
94 | * @return the content of this container | |
95 | */ | |
96 | 0 | public List<Block> getContent() |
97 | { | |
98 | 0 | return content; |
99 | } | |
100 | ||
101 | /** | |
102 | * Sets the content of this container, as a list of blocks. | |
103 | * | |
104 | * @param content the content to set to this container | |
105 | */ | |
106 | 3 | public void setContent(List<Block> content) |
107 | { | |
108 | 3 | this.content = content; |
109 | } | |
110 | } |