String sourceId = request.getParameter("channelID");
String method = request.getParameter("position");
IPortletDefinition definition = portletDefinitionRegistry.getPortletDefinition(sourceId);
IUserLayoutChannelDescription channel = new UserLayoutChannelDescription(definition);
IUserLayoutNodeDescription node = null;
if (isTab(ulm, destinationId)) {
node = addNodeToTab(ulm,channel, destinationId);
} else if (isColumn(ulm, destinationId)) {
// move the channel into the column
node = ulm.addNode(channel, destinationId, null);
} else {
// If we're moving this element before another one, we need
// to know what the target is. If there's no target, just
// assume we're moving it to the very end of the column.
String siblingId = null;
if (method.equals("insertBefore"))
siblingId = destinationId;
// move the node as requested and save the layout
node = ulm.addNode(channel, ulm.getParentId(destinationId),
siblingId);
}
final Locale locale = RequestContextUtils.getLocale(request);
if (node == null) {
return new ModelAndView("jsonView", Collections.singletonMap("error", getMessage("error.add.portlet.in.tab", "Can''t add a new channel", locale)));
}
String nodeId = node.getId();
try {
// save the user's layout
ulm.saveUserLayout();
if(addedWindowState!=null){
IPortletWindow portletWindow = this.portletWindowRegistry.getOrCreateDefaultPortletWindowByFname(request, channel.getFunctionalName());
portletWindow.setWindowState(addedWindowState);
this.portletWindowRegistry.storePortletWindow(request, portletWindow);
}
} catch (Exception e) {
log.warn("Error saving layout", e);