public UIDashboardContainer setColumns(final int num) throws Exception {
if (num < 1 || num > MAX_COLUMN) {
return null;
}
UIContainer uiRoot = findFirstComponentOfType(UIContainer.class);
List<UIContainer> columns = getColumns();
int colSize = columns.size();
if (num < colSize) {
for (int i = num; i < colSize; i++) {
UIContainer tempCol = columns.get(i);
List<UIComponent> components = new ArrayList<UIComponent>();
for (UIComponent component : tempCol.getChildren()) {
columns.get(num - 1).addChild(component);
components.add(component);
}
uiRoot.removeChildById(tempCol.getId());
for (UIComponent component : components) {
component.setParent(columns.get(num - 1));
}
}
} else {
if (num > colSize) {
do {
UIContainer uiContainer = createUIComponent(UIContainer.class, null, null);
PortalDataMapper.toUIContainer(uiContainer, createContainer(ROW_CONTAINER, "UIColumn-" + colSize));
uiRoot.addChild(uiContainer);
colSize++;
} while (num > colSize);
}