use of org.alfresco.web.ui.repo.component.UITree.TreeNode in project acs-community-packaging by Alfresco.
the class CategoryBrowserPluginBean method retrieveChildren.
/**
* Retrieves the child folders for the noderef given in the 'noderef' parameter and caches the nodes against the area
* in the 'area' parameter.
*/
public void retrieveChildren() throws IOException {
FacesContext context = FacesContext.getCurrentInstance();
ResponseWriter out = context.getResponseWriter();
UserTransaction tx = null;
try {
tx = Repository.getUserTransaction(context, true);
tx.begin();
Map params = context.getExternalContext().getRequestParameterMap();
String nodeRefStr = (String) params.get("nodeRef");
// work out which list to cache the nodes in
Map<String, TreeNode> currentNodes = getNodesMap();
if (nodeRefStr != null && currentNodes != null) {
// get the given node's details
NodeRef parentNodeRef = new NodeRef(nodeRefStr);
TreeNode parentNode = currentNodes.get(parentNodeRef.toString());
parentNode.setExpanded(true);
if (logger.isDebugEnabled())
logger.debug("retrieving children for noderef: " + parentNodeRef);
// remove any existing children as the latest ones will be added
// below
parentNode.removeChildren();
// get all the child folder objects for the parent
List<ChildAssociationRef> childRefs = this.getNodeService().getChildAssocs(parentNodeRef, ContentModel.ASSOC_SUBCATEGORIES, RegexQNamePattern.MATCH_ALL);
List<TreeNode> sortedNodes = new ArrayList<TreeNode>();
for (ChildAssociationRef ref : childRefs) {
NodeRef nodeRef = ref.getChildRef();
logger.debug("retrieving child : " + nodeRef);
// build the XML representation of the child node
TreeNode childNode = createTreeNode(nodeRef);
parentNode.addChild(childNode);
currentNodes.put(childNode.getNodeRef(), childNode);
sortedNodes.add(childNode);
}
// order the tree nodes by the tree label
if (sortedNodes.size() > 1) {
QuickSort sorter = new QuickSort(sortedNodes, "name", true, IDataContainer.SORT_CASEINSENSITIVE);
sorter.sort();
}
// generate the XML representation
StringBuilder xml = new StringBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?><nodes>");
for (TreeNode childNode : sortedNodes) {
xml.append(childNode.toXML());
}
xml.append("</nodes>");
// send the generated XML back to the tree
out.write(xml.toString());
if (logger.isDebugEnabled())
logger.debug("returning XML: " + xml.toString());
}
// commit the transaction
tx.commit();
} catch (Throwable err) {
try {
if (tx != null) {
tx.rollback();
}
} catch (Exception tex) {
}
}
}
use of org.alfresco.web.ui.repo.component.UITree.TreeNode in project acs-community-packaging by Alfresco.
the class CategoryBrowserPluginBean method getCategoryRootNodes.
public List<TreeNode> getCategoryRootNodes() {
if (this.categoryRootNodes == null) {
this.categoryRootNodes = new ArrayList<TreeNode>();
this.categoryNodes = new HashMap<String, TreeNode>();
UserTransaction tx = null;
try {
tx = Repository.getUserTransaction(FacesContext.getCurrentInstance(), true);
tx.begin();
Collection<ChildAssociationRef> childRefs = this.getCategoryService().getRootCategories(Repository.getStoreRef(), ContentModel.ASPECT_GEN_CLASSIFIABLE);
for (ChildAssociationRef ref : childRefs) {
NodeRef child = ref.getChildRef();
TreeNode node = createTreeNode(child);
this.categoryRootNodes.add(node);
this.categoryNodes.put(node.getNodeRef(), node);
}
tx.commit();
} catch (Throwable err) {
Utils.addErrorMessage("NavigatorPluginBean exception in getCompanyHomeRootNodes()", err);
try {
if (tx != null) {
tx.rollback();
}
} catch (Exception tex) {
}
}
}
return this.categoryRootNodes;
}
use of org.alfresco.web.ui.repo.component.UITree.TreeNode in project acs-community-packaging by Alfresco.
the class NavigatorPluginBean method getMyHomeRootNodes.
/**
* Returns the root nodes for the my home panel.
* <p>
* As the user expands and collapses nodes in the client this
* cache will be updated with the appropriate nodes and states.
* </p>
*
* @return List of root nodes for the my home panel
*/
public List<TreeNode> getMyHomeRootNodes() {
if (this.myHomeRootNodes == null) {
this.myHomeRootNodes = new ArrayList<TreeNode>();
this.myHomeNodes = new HashMap<String, TreeNode>();
UserTransaction tx = null;
try {
tx = Repository.getUserTransaction(FacesContext.getCurrentInstance(), true);
tx.begin();
// query for the child nodes of the user's home
NodeRef root = new NodeRef(Repository.getStoreRef(), Application.getCurrentUser(FacesContext.getCurrentInstance()).getHomeSpaceId());
List<ChildAssociationRef> childRefs = this.getNodeService().getChildAssocs(root, ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL);
for (ChildAssociationRef ref : childRefs) {
NodeRef child = ref.getChildRef();
if (isAddableChild(child)) {
TreeNode node = createTreeNode(child);
this.myHomeRootNodes.add(node);
this.myHomeNodes.put(node.getNodeRef(), node);
}
}
tx.commit();
} catch (Throwable err) {
Utils.addErrorMessage("NavigatorPluginBean exception in getMyHomeRootNodes()", err);
try {
if (tx != null) {
tx.rollback();
}
} catch (Exception tex) {
}
}
}
return this.myHomeRootNodes;
}
use of org.alfresco.web.ui.repo.component.UITree.TreeNode in project acs-community-packaging by Alfresco.
the class NavigatorPluginBean method nodeCollapsed.
/**
* Sets the state of the node given in the 'nodeRef' parameter to collapsed
*/
public void nodeCollapsed() throws IOException {
FacesContext context = FacesContext.getCurrentInstance();
ResponseWriter out = context.getResponseWriter();
Map params = context.getExternalContext().getRequestParameterMap();
String nodeRefStr = (String) params.get("nodeRef");
String area = (String) params.get("area");
if (logger.isDebugEnabled())
logger.debug("nodeCollapsed: area = " + area + ", nodeRef = " + nodeRefStr);
// work out which list to cache the nodes in
Map<String, TreeNode> currentNodes = getNodesMapForArea(area);
if (nodeRefStr != null && currentNodes != null) {
TreeNode treeNode = currentNodes.get(nodeRefStr);
if (treeNode != null) {
treeNode.setExpanded(false);
// we need to return something for the client to be happy!
out.write("<ok/>");
if (logger.isDebugEnabled())
logger.debug("Set node " + treeNode + " to collapsed state");
}
}
}
use of org.alfresco.web.ui.repo.component.UITree.TreeNode in project acs-community-packaging by Alfresco.
the class UINavigator method encodeBegin.
@Override
@SuppressWarnings("unchecked")
public void encodeBegin(FacesContext context) throws IOException {
if (!isRendered())
return;
// TODO: pull width and height from user preferences and/or the main config,
// if present override below using the style attribute
ResponseWriter out = context.getResponseWriter();
NavigationBean navBean = (NavigationBean) FacesHelper.getManagedBean(context, NavigationBean.BEAN_NAME);
NavigatorPluginBean navPluginBean = (NavigatorPluginBean) FacesHelper.getManagedBean(context, NavigatorPluginBean.BEAN_NAME);
List<TreeNode> rootNodesForArea = null;
String area = this.getActiveArea();
String areaTitle = null;
boolean treePanel = true;
if (NavigationBean.LOCATION_COMPANY.equals(area)) {
rootNodesForArea = navPluginBean.getCompanyHomeRootNodes();
areaTitle = Application.getMessage(context, NavigationBean.MSG_COMPANYHOME);
} else if (NavigationBean.LOCATION_HOME.equals(area)) {
rootNodesForArea = navPluginBean.getMyHomeRootNodes();
areaTitle = Application.getMessage(context, NavigationBean.MSG_MYHOME);
} else if (NavigationBean.LOCATION_GUEST.equals(area)) {
rootNodesForArea = navPluginBean.getGuestHomeRootNodes();
areaTitle = Application.getMessage(context, NavigationBean.MSG_GUESTHOME);
} else {
treePanel = false;
areaTitle = Application.getMessage(context, NavigationBean.MSG_MYALFRESCO);
}
// order the root nodes by the tree label
if (rootNodesForArea != null && rootNodesForArea.size() > 1) {
QuickSort sorter = new QuickSort(rootNodesForArea, "name", true, IDataContainer.SORT_CASEINSENSITIVE);
sorter.sort();
}
// main container div
out.write("<div id=\"navigator\" class=\"navigator\">");
// generate the active panel title
String cxPath = context.getExternalContext().getRequestContextPath();
out.write("<div class=\"sidebarButtonSelected\" style=\"background-image: url(" + cxPath + "/images/parts/navigator_blue_gradient_bg.gif)\">");
out.write("<a class='sidebarButtonSelectedLink' onclick=\"");
out.write(Utils.generateFormSubmit(context, this, getClientId(context), PANEL_ACTION + area));
out.write("\" href=\"#\">");
out.write(Utils.encode(areaTitle));
out.write("</a></div>");
// generate the javascript method to capture the tree node click events
if (treePanel) {
out.write("<script type=\"text/javascript\">");
out.write("function treeNodeSelected(nodeRef) {");
out.write(Utils.generateFormSubmit(context, this, getClientId(context), "nodeRef", true, null));
out.write("}</script>");
// generate the active panel containing the tree
out.write("<div class=\"navigatorPanelBody\">");
UITree tree = (UITree) context.getApplication().createComponent(UITree.COMPONENT_TYPE);
tree.setId("tree");
tree.setRootNodes(rootNodesForArea);
tree.setRetrieveChildrenUrl(AJAX_URL_START + ".retrieveChildren?area=" + area);
tree.setNodeCollapsedUrl(AJAX_URL_START + ".nodeCollapsed?area=" + area);
tree.setNodeSelectedCallback("treeNodeSelected");
tree.setNodeCollapsedCallback("informOfCollapse");
Utils.encodeRecursive(context, tree);
out.write("</div>");
}
// generate the closed panel title areas
String sideBarStyle = "style=\"background-image: url(" + cxPath + "/images/parts/navigator_grey_gradient_bg.gif)\"";
if (NavigationBean.LOCATION_COMPANY.equals(area) == false && navBean.getCompanyHomeVisible()) {
encodeSidebarButton(context, out, sideBarStyle, NavigationBean.LOCATION_COMPANY, NavigationBean.MSG_COMPANYHOME);
}
if (NavigationBean.LOCATION_HOME.equals(area) == false) {
encodeSidebarButton(context, out, sideBarStyle, NavigationBean.LOCATION_HOME, NavigationBean.MSG_MYHOME);
}
if (NavigationBean.LOCATION_GUEST.equals(area) == false && navBean.getIsGuest() == false && navBean.getGuestHomeVisible()) {
encodeSidebarButton(context, out, sideBarStyle, NavigationBean.LOCATION_GUEST, NavigationBean.MSG_GUESTHOME);
}
if (NavigationBean.LOCATION_MYALFRESCO.equals(area) == false) {
encodeSidebarButton(context, out, sideBarStyle, NavigationBean.LOCATION_MYALFRESCO, NavigationBean.MSG_MYALFRESCO);
}
out.write("</div>");
}
Aggregations