use of org.apereo.portal.layout.node.IUserLayoutFolderDescription in project uPortal by Jasig.
the class DistributedLayoutManager method updateNode.
/**
* Handles pushing changes made to the passed-in node into the user's layout. If the node is an
* ILF node then the change is recorded via directives in the PLF if such changes are allowed by
* the owning fragment. If the node is a user owned node then the changes are applied directly
* to the corresponding node in the PLF.
*/
public synchronized boolean updateNode(IUserLayoutNodeDescription node) throws PortalException {
if (canUpdateNode(node)) {
String nodeId = node.getId();
IUserLayoutNodeDescription oldNode = getNode(nodeId);
if (oldNode instanceof IUserLayoutChannelDescription) {
IUserLayoutChannelDescription oldChanDesc = (IUserLayoutChannelDescription) oldNode;
if (!(node instanceof IUserLayoutChannelDescription)) {
throw new PortalException("Change channel to folder is " + "not allowed by updateNode() method! Occurred " + "in layout for " + owner.getAttribute(IPerson.USERNAME) + ".");
}
IUserLayoutChannelDescription newChanDesc = (IUserLayoutChannelDescription) node;
updateChannelNode(nodeId, newChanDesc, oldChanDesc);
} else {
// must be a folder
IUserLayoutFolderDescription oldFolderDesc = (IUserLayoutFolderDescription) oldNode;
if (oldFolderDesc.getId().equals(getRootFolderId()))
throw new PortalException("Update of root node is not currently allowed!");
if (node instanceof IUserLayoutFolderDescription) {
IUserLayoutFolderDescription newFolderDesc = (IUserLayoutFolderDescription) node;
updateFolderNode(nodeId, newFolderDesc, oldFolderDesc);
}
}
this.updateCacheKey();
return true;
}
return false;
}
use of org.apereo.portal.layout.node.IUserLayoutFolderDescription in project uPortal by Jasig.
the class DistributedLayoutManager method getChildIds.
private Enumeration<String> getChildIds(String nodeId, boolean visibleOnly) throws PortalException {
Vector<String> v = new Vector<String>();
IUserLayoutNodeDescription node = getNode(nodeId);
if (node instanceof IUserLayoutFolderDescription) {
Document uld = this.getUserLayoutDOM();
Element felement = uld.getElementById(nodeId);
for (Node n = felement.getFirstChild(); n != null; n = n.getNextSibling()) {
if (n.getNodeType() == Node.ELEMENT_NODE && (visibleOnly == false || (visibleOnly == true && ((Element) n).getAttribute(Constants.ATT_HIDDEN).equals("false")))) {
Element e = (Element) n;
if (e.getAttribute("ID") != null) {
v.add(e.getAttribute("ID"));
}
}
}
}
return v.elements();
}
use of org.apereo.portal.layout.node.IUserLayoutFolderDescription in project uPortal by Jasig.
the class SimpleLayout method getChildIds.
@Override
public Enumeration getChildIds(String nodeId) throws PortalException {
Vector v = new Vector();
IUserLayoutNodeDescription node = getNodeDescription(nodeId);
if (node instanceof IUserLayoutFolderDescription) {
Element element = layout.getElementById(nodeId);
for (Node n = element.getFirstChild(); n != null; n = n.getNextSibling()) {
if (n.getNodeType() == Node.ELEMENT_NODE) {
Element e = (Element) n;
if (e.getAttribute("ID") != null) {
v.add(e.getAttribute("ID"));
}
}
}
}
return v.elements();
}
use of org.apereo.portal.layout.node.IUserLayoutFolderDescription in project uPortal by Jasig.
the class UpdatePreferencesServlet method changeColumns.
/**
* Change the number of columns on a specified tab. In the event that the user is decreasing the
* number of columns, extra columns will be stripped from the right-hand side. Any channels in
* these columns will be moved to the bottom of the last preserved column.
*
* @param widths array of column widths
* @param deleted array of deleted column IDs
* @param acceptor not sure what this is
* @param request HttpRequest
* @param response HttpResponse
* @throws IOException
* @throws PortalException
*/
@RequestMapping(method = RequestMethod.POST, params = "action=changeColumns")
public ModelAndView changeColumns(HttpServletRequest request, HttpServletResponse response, @RequestParam("tabId") String tabId, @RequestParam("widths[]") String[] widths, @RequestParam(value = "deleted[]", required = false) String[] deleted, @RequestParam(value = "acceptor", required = false) String acceptor) throws IOException, PortalException {
IUserInstance ui = userInstanceManager.getUserInstance(request);
IPerson per = getPerson(ui, response);
UserPreferencesManager upm = (UserPreferencesManager) ui.getPreferencesManager();
IUserLayoutManager ulm = upm.getUserLayoutManager();
int newColumnCount = widths.length;
// build a list of the current columns for this tab
Enumeration<String> columns = ulm.getChildIds(tabId);
List<String> columnList = new ArrayList<String>();
while (columns.hasMoreElements()) {
columnList.add(columns.nextElement());
}
int oldColumnCount = columnList.size();
Map<String, Object> model = new HashMap<String, Object>();
// if the new layout has more columns
if (newColumnCount > oldColumnCount) {
List<String> newColumnIds = new ArrayList<String>();
for (int i = columnList.size(); i < newColumnCount; i++) {
// create new column element
IUserLayoutFolderDescription newColumn = new UserLayoutFolderDescription();
newColumn.setName("Column");
newColumn.setId("tbd");
newColumn.setFolderType(IUserLayoutFolderDescription.REGULAR_TYPE);
newColumn.setHidden(false);
newColumn.setUnremovable(false);
newColumn.setImmutable(false);
// add the column to our layout
IUserLayoutNodeDescription node = ulm.addNode(newColumn, tabId, null);
newColumnIds.add(node.getId());
model.put("newColumnIds", newColumnIds);
columnList.add(node.getId());
}
} else // if the new layout has fewer columns
if (deleted != null && deleted.length > 0) {
if (columnList.size() != widths.length + deleted.length) {
// TODO: error?
}
for (String columnId : deleted) {
// move all channels in the current column to the last valid column
Enumeration channels = ulm.getChildIds(columnId);
while (channels.hasMoreElements()) {
ulm.addNode(ulm.getNode((String) channels.nextElement()), acceptor, null);
}
// delete the column from the user's layout
ulm.deleteNode(columnId);
columnList.remove(columnId);
}
}
int count = 0;
for (String columnId : columnList) {
this.stylesheetUserPreferencesService.setLayoutAttribute(request, PreferencesScope.STRUCTURE, columnId, "width", widths[count] + "%");
try {
// This sets the column attribute in memory but doesn't persist it. Comment says saves changes "prior to persisting"
Element folder = ulm.getUserLayoutDOM().getElementById(columnId);
UserPrefsHandler.setUserPreference(folder, "width", per);
} catch (Exception e) {
logger.error("Error saving new column widths", e);
}
count++;
}
try {
ulm.saveUserLayout();
} catch (PortalException e) {
logger.warn("Error saving layout", e);
}
return new ModelAndView("jsonView", model);
}
use of org.apereo.portal.layout.node.IUserLayoutFolderDescription in project uPortal by Jasig.
the class UpdatePreferencesServlet method getTabIdFromName.
protected String getTabIdFromName(IUserLayout userLayout, String tabName) {
@SuppressWarnings("unchecked") Enumeration<String> childrenOfRoot = userLayout.getChildIds(userLayout.getRootId());
while (childrenOfRoot.hasMoreElements()) {
//loop over folders that might be the favorites folder
String nodeId = childrenOfRoot.nextElement();
try {
IUserLayoutNodeDescription nodeDescription = userLayout.getNodeDescription(nodeId);
IUserLayoutNodeDescription.LayoutNodeType nodeType = nodeDescription.getType();
if (IUserLayoutNodeDescription.LayoutNodeType.FOLDER.equals(nodeType) && nodeDescription instanceof IUserLayoutFolderDescription) {
IUserLayoutFolderDescription folderDescription = (IUserLayoutFolderDescription) nodeDescription;
if (tabName.equalsIgnoreCase(folderDescription.getName())) {
return folderDescription.getId();
}
}
} catch (Exception e) {
logger.error("Error getting the nodeID of the tab name " + tabName, e);
}
}
logger.warn("Tab " + tabName + " was searched for but not found");
//didn't find tab
return null;
}
Aggregations