mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
- Incorporated new sidebar which contains the shelf and navigator (tree) components
- Changed version number to 2.0.0 (dev) git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@4538 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -90,6 +90,7 @@ public final class Utils
|
||||
private static final String DEFAULT_FILE_IMAGE32 = IMAGE_PREFIX32 + "_default" + IMAGE_POSTFIX;
|
||||
|
||||
private static final String AJAX_SCRIPTS_WRITTEN = "_alfAjaxScriptsWritten";
|
||||
private static final String YAHOO_SCRIPTS_WRITTEN = "_alfYahooScriptsWritten";
|
||||
|
||||
private static final Map<String, String> s_fileExtensionMap = new HashMap<String, String>(89, 1.0f);
|
||||
|
||||
@@ -412,7 +413,7 @@ public final class Utils
|
||||
*/
|
||||
public static String generateFormSubmit(FacesContext context, UIComponent component, String fieldId, String fieldValue)
|
||||
{
|
||||
return generateFormSubmit(context, component, fieldId, fieldValue, null);
|
||||
return generateFormSubmit(context, component, fieldId, fieldValue, false, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -429,7 +430,31 @@ public final class Utils
|
||||
*
|
||||
* @return JavaScript event code
|
||||
*/
|
||||
public static String generateFormSubmit(FacesContext context, UIComponent component, String fieldId, String fieldValue, Map<String, String> params)
|
||||
public static String generateFormSubmit(FacesContext context, UIComponent component, String fieldId,
|
||||
String fieldValue, Map<String, String> params)
|
||||
{
|
||||
return generateFormSubmit(context, component, fieldId, fieldValue, false, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the JavaScript to submit set the specified hidden Form field to the
|
||||
* supplied value and submit the parent Form.
|
||||
*
|
||||
* NOTE: the supplied hidden field name is added to the Form Renderer map for output.
|
||||
*
|
||||
* @param context FacesContext
|
||||
* @param component UIComponent to generate JavaScript for
|
||||
* @param fieldId Hidden field id to set value for
|
||||
* @param fieldValue Hidden field value to set hidden field too on submit
|
||||
* @param valueIsParam Determines whether the fieldValue parameter should be treated
|
||||
* as a parameter in the generated JavaScript, false will treat
|
||||
* the value i.e. surround it with single quotes
|
||||
* @param params Optional map of param name/values to output
|
||||
*
|
||||
* @return JavaScript event code
|
||||
*/
|
||||
public static String generateFormSubmit(FacesContext context, UIComponent component, String fieldId,
|
||||
String fieldValue, boolean valueIsParam, Map<String, String> params)
|
||||
{
|
||||
UIForm form = Utils.getParentForm(context, component);
|
||||
if (form == null)
|
||||
@@ -446,9 +471,17 @@ public final class Utils
|
||||
buf.append("'");
|
||||
buf.append("]['");
|
||||
buf.append(fieldId);
|
||||
buf.append("'].value='");
|
||||
buf.append("'].value=");
|
||||
if (valueIsParam == false)
|
||||
{
|
||||
buf.append("'");
|
||||
}
|
||||
buf.append(fieldValue);
|
||||
buf.append("';");
|
||||
if (valueIsParam == false)
|
||||
{
|
||||
buf.append("'");
|
||||
}
|
||||
buf.append(";");
|
||||
|
||||
if (params != null)
|
||||
{
|
||||
@@ -474,9 +507,12 @@ public final class Utils
|
||||
buf.append("'");
|
||||
buf.append(formClientId);
|
||||
buf.append("'");
|
||||
buf.append("].submit()");
|
||||
buf.append("].submit();");
|
||||
|
||||
buf.append(";return false;");
|
||||
if (valueIsParam == false)
|
||||
{
|
||||
buf.append("return false;");
|
||||
}
|
||||
|
||||
// weak, but this seems to be the way Sun RI do it...
|
||||
//FormRenderer.addNeededHiddenField(context, fieldId);
|
||||
@@ -1244,14 +1280,14 @@ public final class Utils
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the script tags for including AJAX support, ensuring they
|
||||
* Writes the script tags for including dojo support, ensuring they
|
||||
* only get written once per page render.
|
||||
*
|
||||
* @param context Faces context
|
||||
* @param out The response writer
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static void writeAjaxScripts(FacesContext context, ResponseWriter out)
|
||||
public static void writeDojoScripts(FacesContext context, ResponseWriter out)
|
||||
throws IOException
|
||||
{
|
||||
Object present = context.getExternalContext().getRequestMap().get(AJAX_SCRIPTS_WRITTEN);
|
||||
@@ -1259,6 +1295,10 @@ public final class Utils
|
||||
if (present == null)
|
||||
{
|
||||
// write out the scripts
|
||||
// out.write("<script type=\"text/javascript\">");
|
||||
// out.write("var djConfig = {isDebug: true, debugAtAllCosts: true };");
|
||||
// out.write("</script>\n");
|
||||
|
||||
out.write("\n<script type=\"text/javascript\" src=\"");
|
||||
out.write(context.getExternalContext().getRequestContextPath());
|
||||
out.write("/scripts/ajax/dojo/dojo.js\"> </script>\n");
|
||||
@@ -1275,4 +1315,57 @@ public final class Utils
|
||||
context.getExternalContext().getRequestMap().put(AJAX_SCRIPTS_WRITTEN, Boolean.TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the scripts tags for using the Yahoo UI toolkit, ensuring they
|
||||
* only get written once per page render.
|
||||
* <p>
|
||||
* A comma separated list of scripts can also be passed to determine
|
||||
* which components are to be used, again these are only written once per page.
|
||||
*
|
||||
* @param context Faces context
|
||||
* @param out The response writer
|
||||
* @param scripts Comma separated list of scripts to include, if null the
|
||||
* base yahoo.js script only is included.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static void writeYahooScripts(FacesContext context, ResponseWriter out,
|
||||
String scripts) throws IOException
|
||||
{
|
||||
Object present = context.getExternalContext().getRequestMap().get(YAHOO_SCRIPTS_WRITTEN);
|
||||
|
||||
if (present == null)
|
||||
{
|
||||
// TODO: use the scripts parameter to determine which scripts to output
|
||||
// also add an ajax debug flag to the config and output relevant file
|
||||
|
||||
// base yahoo file
|
||||
out.write("\n<script type=\"text/javascript\" src=\"");
|
||||
out.write(context.getExternalContext().getRequestContextPath());
|
||||
out.write("/scripts/ajax/yahoo/yahoo/yahoo-min.js\"> </script>\n");
|
||||
|
||||
// io handling (AJAX)
|
||||
out.write("\n<script type=\"text/javascript\" src=\"");
|
||||
out.write(context.getExternalContext().getRequestContextPath());
|
||||
out.write("/scripts/ajax/yahoo/connection/connection-min.js\"> </script>\n");
|
||||
|
||||
// event handling
|
||||
out.write("\n<script type=\"text/javascript\" src=\"");
|
||||
out.write(context.getExternalContext().getRequestContextPath());
|
||||
out.write("/scripts/ajax/yahoo/event/event-min.js\"> </script>\n");
|
||||
|
||||
// common alfresco util methods
|
||||
out.write("<script type=\"text/javascript\" src=\"");
|
||||
out.write(context.getExternalContext().getRequestContextPath());
|
||||
out.write("/scripts/ajax/common.js\"> </script>\n");
|
||||
|
||||
// write out a global variable to hold the webapp context path
|
||||
out.write("<script type=\"text/javascript\">var WEBAPP_CONTEXT = '");
|
||||
out.write(context.getExternalContext().getRequestContextPath());
|
||||
out.write("';</script>\n");
|
||||
|
||||
// add marker to request
|
||||
context.getExternalContext().getRequestMap().put(YAHOO_SCRIPTS_WRITTEN, Boolean.TRUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -156,7 +156,28 @@ public class ModeListRenderer extends BaseRenderer
|
||||
for (Iterator i=list.getChildren().iterator(); i.hasNext(); /**/)
|
||||
{
|
||||
UIComponent child = (UIComponent)i.next();
|
||||
if (child instanceof UIListItem && child.isRendered() == true)
|
||||
if (child instanceof UIListItems)
|
||||
{
|
||||
// get the value of the list items component and iterate
|
||||
// through it's collection
|
||||
Object listItems = ((UIListItems)child).getValue();
|
||||
if (listItems instanceof Collection)
|
||||
{
|
||||
Iterator iter = ((Collection)listItems).iterator();
|
||||
while (iter.hasNext())
|
||||
{
|
||||
UIListItem item = (UIListItem)iter.next();
|
||||
|
||||
// if selected render as the label
|
||||
if (item.getValue().equals(list.getValue()) == true)
|
||||
{
|
||||
label = item.getLabel();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (child instanceof UIListItem && child.isRendered() == true)
|
||||
{
|
||||
// found a valid UIListItem child to render
|
||||
UIListItem item = (UIListItem)child;
|
||||
@@ -179,7 +200,7 @@ public class ModeListRenderer extends BaseRenderer
|
||||
outputAttribute(out, attrs.get("labelStyleClass"), "class");
|
||||
out.write('>');
|
||||
out.write(Utils.encode(label));
|
||||
out.write("</span>");
|
||||
out.write("</span> ");
|
||||
}
|
||||
|
||||
// output image
|
||||
|
387
source/java/org/alfresco/web/ui/repo/component/UINavigator.java
Normal file
387
source/java/org/alfresco/web/ui/repo/component/UINavigator.java
Normal file
@@ -0,0 +1,387 @@
|
||||
package org.alfresco.web.ui.repo.component;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.faces.component.UIComponent;
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.faces.context.ResponseWriter;
|
||||
import javax.faces.el.ValueBinding;
|
||||
import javax.faces.event.AbortProcessingException;
|
||||
import javax.faces.event.ActionEvent;
|
||||
import javax.faces.event.FacesEvent;
|
||||
|
||||
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.web.app.Application;
|
||||
import org.alfresco.web.app.servlet.FacesHelper;
|
||||
import org.alfresco.web.bean.BrowseBean;
|
||||
import org.alfresco.web.bean.NavigationBean;
|
||||
import org.alfresco.web.bean.ajax.NavigatorPluginBean;
|
||||
import org.alfresco.web.bean.repository.Repository;
|
||||
import org.alfresco.web.ui.common.Utils;
|
||||
import org.alfresco.web.ui.common.component.SelfRenderingComponent;
|
||||
import org.alfresco.web.ui.repo.component.UITree.TreeNode;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
/**
|
||||
* Navigator component that consists of 4 panels representing
|
||||
* the main areas of the repository i.e. company home, my home,
|
||||
* guest home and my alfresco.
|
||||
* <p>
|
||||
* Each panel (apart from my alfresco) uses the tree component
|
||||
* to allow navigation around that area of the repository.
|
||||
* </p>
|
||||
*
|
||||
* @author gavinc
|
||||
*/
|
||||
public class UINavigator extends SelfRenderingComponent
|
||||
{
|
||||
public static final String COMPONENT_TYPE = "org.alfresco.faces.Navigator";
|
||||
|
||||
protected String activeArea;
|
||||
|
||||
private static final Log logger = LogFactory.getLog(UINavigator.class);
|
||||
private static final String NAVIGATION_BEAN = "NavigationBean";
|
||||
private static final String BROWSE_BEAN = "BrowseBean";
|
||||
private static final String AJAX_URL_START = "/ajax/invoke/" + NavigatorPluginBean.BEAN_NAME;
|
||||
private static final String PANEL_ACTION = "panel:";
|
||||
private static final int PANEL_SELECTED = 1;
|
||||
private static final int NODE_SELECTED = 2;
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
// Component Impl
|
||||
|
||||
@Override
|
||||
public String getFamily()
|
||||
{
|
||||
return COMPONENT_TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void restoreState(FacesContext context, Object state)
|
||||
{
|
||||
Object values[] = (Object[])state;
|
||||
// standard component attributes are restored by the super class
|
||||
super.restoreState(context, values[0]);
|
||||
this.activeArea = (String)values[1];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object saveState(FacesContext context)
|
||||
{
|
||||
Object values[] = new Object[2];
|
||||
// standard component attributes are saved by the super class
|
||||
values[0] = super.saveState(context);
|
||||
values[1] = this.activeArea;
|
||||
return values;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.faces.component.UIComponentBase#decode(javax.faces.context.FacesContext)
|
||||
*/
|
||||
public void decode(FacesContext context)
|
||||
{
|
||||
Map requestMap = context.getExternalContext().getRequestParameterMap();
|
||||
String fieldId = getClientId(context);
|
||||
String value = (String)requestMap.get(fieldId);
|
||||
|
||||
if (value != null && value.length() != 0)
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Received post back: " + value);
|
||||
|
||||
// work out whether a panel or a node was selected
|
||||
int mode = NODE_SELECTED;
|
||||
String item = value;
|
||||
if (value.startsWith(PANEL_ACTION))
|
||||
{
|
||||
mode = PANEL_SELECTED;
|
||||
item = value.substring(PANEL_ACTION.length());
|
||||
}
|
||||
|
||||
// queue an event to be handled later
|
||||
NavigatorEvent event = new NavigatorEvent(this, mode, item);
|
||||
this.queueEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.faces.component.UIInput#broadcast(javax.faces.event.FacesEvent)
|
||||
*/
|
||||
public void broadcast(FacesEvent event) throws AbortProcessingException
|
||||
{
|
||||
if (event instanceof NavigatorEvent)
|
||||
{
|
||||
FacesContext context = FacesContext.getCurrentInstance();
|
||||
NavigatorEvent navEvent = (NavigatorEvent)event;
|
||||
|
||||
// node or panel selected?
|
||||
switch (navEvent.getMode())
|
||||
{
|
||||
case PANEL_SELECTED:
|
||||
{
|
||||
String panelSelected = navEvent.getItem();
|
||||
|
||||
// a panel was selected, setup the context to make the panel
|
||||
// the focus
|
||||
NavigationBean nb = (NavigationBean)FacesHelper.getManagedBean(
|
||||
context, NAVIGATION_BEAN);
|
||||
if (nb != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Selecting panel: " + panelSelected);
|
||||
|
||||
nb.processToolbarLocation(panelSelected, true);
|
||||
}
|
||||
catch (InvalidNodeRefException refErr)
|
||||
{
|
||||
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(
|
||||
FacesContext.getCurrentInstance(), Repository.ERROR_NOHOME),
|
||||
Application.getCurrentUser(context).getHomeSpaceId()), refErr );
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(
|
||||
FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC),
|
||||
err.getMessage()), err);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case NODE_SELECTED:
|
||||
{
|
||||
// a node was clicked in the tree
|
||||
NodeRef nodeClicked = new NodeRef(navEvent.getItem());
|
||||
|
||||
// setup the context to make the node the current node
|
||||
BrowseBean bb = (BrowseBean)FacesHelper.getManagedBean(
|
||||
context, BROWSE_BEAN);
|
||||
if (bb != null)
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Selected node: " + nodeClicked);
|
||||
|
||||
bb.clickSpace(nodeClicked);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
super.broadcast(event);
|
||||
}
|
||||
}
|
||||
|
||||
@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, NAVIGATION_BEAN);
|
||||
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, "company_home");
|
||||
}
|
||||
else if (NavigationBean.LOCATION_HOME.equals(area))
|
||||
{
|
||||
rootNodesForArea = navPluginBean.getMyHomeRootNodes();
|
||||
areaTitle = Application.getMessage(context, "my_home");
|
||||
}
|
||||
else if (NavigationBean.LOCATION_GUEST.equals(area))
|
||||
{
|
||||
rootNodesForArea = navPluginBean.getGuestHomeRootNodes();
|
||||
areaTitle = Application.getMessage(context, "guest_home");
|
||||
}
|
||||
else
|
||||
{
|
||||
treePanel = false;
|
||||
areaTitle = Application.getMessage(context, "my_alfresco");
|
||||
}
|
||||
|
||||
// generate the active panel title
|
||||
out.write("<div id=\"navigator\">");
|
||||
out.write("<div class=\"navigatorPanelTitleSelected\">");
|
||||
out.write(areaTitle);
|
||||
out.write("</div>");
|
||||
|
||||
// generate the javascript method to capture the tree node click events
|
||||
if (treePanel)
|
||||
{
|
||||
out.write("\n<script type=\"text/javascript\">\n");
|
||||
out.write("function treeNodeSelected(nodeRef) {\n");
|
||||
out.write(Utils.generateFormSubmit(context, this, getClientId(context),
|
||||
"nodeRef", true, null));
|
||||
out.write("\n}\n");
|
||||
out.write("</script>\n");
|
||||
|
||||
// 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
|
||||
if (NavigationBean.LOCATION_COMPANY.equals(area) == false &&
|
||||
navBean.getCompanyHomeVisible())
|
||||
{
|
||||
out.write("<div class=\"navigatorPanelTitle\">");
|
||||
out.write("<a onclick=\"");
|
||||
out.write(Utils.generateFormSubmit(context, this, getClientId(context),
|
||||
PANEL_ACTION + NavigationBean.LOCATION_COMPANY));
|
||||
out.write("\" href=\"#\">");
|
||||
out.write(Application.getMessage(context, "company_home"));
|
||||
out.write("</a></div>");
|
||||
}
|
||||
|
||||
if (NavigationBean.LOCATION_HOME.equals(area) == false)
|
||||
{
|
||||
out.write("<div class=\"navigatorPanelTitle\">");
|
||||
out.write("<a onclick=\"");
|
||||
out.write(Utils.generateFormSubmit(context, this, getClientId(context),
|
||||
PANEL_ACTION + NavigationBean.LOCATION_HOME));
|
||||
out.write("\" href=\"#\">");
|
||||
out.write(Application.getMessage(context, "my_home"));
|
||||
out.write("</a></div>");
|
||||
}
|
||||
|
||||
if (NavigationBean.LOCATION_GUEST.equals(area) == false &&
|
||||
navBean.getIsGuest() == false && navBean.getGuestHomeVisible())
|
||||
{
|
||||
out.write("<div class=\"navigatorPanelTitle\">");
|
||||
out.write("<a onclick=\"");
|
||||
out.write(Utils.generateFormSubmit(context, this, getClientId(context),
|
||||
PANEL_ACTION + NavigationBean.LOCATION_GUEST));
|
||||
out.write("\" href=\"#\">");
|
||||
out.write(Application.getMessage(context, "guest_home"));
|
||||
out.write("</a></div>");
|
||||
}
|
||||
|
||||
if (NavigationBean.LOCATION_MYALFRESCO.equals(area) == false)
|
||||
{
|
||||
out.write("<div class=\"navigatorPanelTitle\">");
|
||||
out.write("<a onclick=\"");
|
||||
out.write(Utils.generateFormSubmit(context, this, getClientId(context),
|
||||
PANEL_ACTION + NavigationBean.LOCATION_MYALFRESCO));
|
||||
out.write("\" href=\"#\">");
|
||||
out.write(Application.getMessage(context, "my_alfresco"));
|
||||
out.write("</a></div>");
|
||||
}
|
||||
|
||||
out.write("</div>");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encodeChildren(FacesContext context) throws IOException
|
||||
{
|
||||
if (!isRendered()) return;
|
||||
|
||||
for (Iterator i=this.getChildren().iterator(); i.hasNext(); /**/)
|
||||
{
|
||||
UIComponent child = (UIComponent)i.next();
|
||||
Utils.encodeRecursive(context, child);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getRendersChildren()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
// Strongly typed component property accessors
|
||||
|
||||
/**
|
||||
* Returns the active area the navigator component is showing
|
||||
*
|
||||
* @return The active area
|
||||
*/
|
||||
public String getActiveArea()
|
||||
{
|
||||
ValueBinding vb = getValueBinding("activeArea");
|
||||
if (vb != null)
|
||||
{
|
||||
this.activeArea = (String)vb.getValue(getFacesContext());
|
||||
}
|
||||
|
||||
if (this.activeArea == null)
|
||||
{
|
||||
this.activeArea = NavigationBean.LOCATION_HOME;
|
||||
}
|
||||
|
||||
return this.activeArea;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the active area for the navigator panel
|
||||
*
|
||||
* @param activeArea
|
||||
*/
|
||||
public void setActiveArea(String activeArea)
|
||||
{
|
||||
this.activeArea = activeArea;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
// Helper methods
|
||||
|
||||
/**
|
||||
* Class representing the clicking of a tree node.
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public static class NavigatorEvent extends ActionEvent
|
||||
{
|
||||
private int mode;
|
||||
private String item;
|
||||
|
||||
public NavigatorEvent(UIComponent component, int mode, String item)
|
||||
{
|
||||
super(component);
|
||||
|
||||
this.mode = mode;
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
public String getItem()
|
||||
{
|
||||
return item;
|
||||
}
|
||||
|
||||
public int getMode()
|
||||
{
|
||||
return mode;
|
||||
}
|
||||
}
|
||||
}
|
@@ -65,7 +65,7 @@ public class UINodeInfo extends SelfRenderingComponent
|
||||
|
||||
// output the scripts required by the component (checks are
|
||||
// made to make sure the scripts are only written once)
|
||||
Utils.writeAjaxScripts(context, out);
|
||||
Utils.writeDojoScripts(context, out);
|
||||
|
||||
// write out the JavaScript specific to the NodeInfo component,
|
||||
// again, make sure it's only done once
|
||||
|
223
source/java/org/alfresco/web/ui/repo/component/UISidebar.java
Normal file
223
source/java/org/alfresco/web/ui/repo/component/UISidebar.java
Normal file
@@ -0,0 +1,223 @@
|
||||
package org.alfresco.web.ui.repo.component;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.faces.component.UIComponent;
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.faces.context.ResponseWriter;
|
||||
import javax.faces.el.MethodBinding;
|
||||
import javax.faces.el.ValueBinding;
|
||||
import javax.faces.event.ActionEvent;
|
||||
|
||||
import org.alfresco.web.bean.SidebarBean;
|
||||
import org.alfresco.web.config.SidebarConfigElement;
|
||||
import org.alfresco.web.config.SidebarConfigElement.SidebarPluginConfig;
|
||||
import org.alfresco.web.ui.common.PanelGenerator;
|
||||
import org.alfresco.web.ui.common.Utils;
|
||||
import org.alfresco.web.ui.common.component.SelfRenderingComponent;
|
||||
import org.alfresco.web.ui.common.component.UIListItems;
|
||||
import org.alfresco.web.ui.common.component.UIModeList;
|
||||
|
||||
/**
|
||||
* Component that represents the sidebar.
|
||||
* <p>
|
||||
* A sidebar consists of multiple plugins, of which only
|
||||
* one is active at one time. All registered plugins are
|
||||
* displayed in a drop down allowing the user to
|
||||
* change the active plugin. An action group can also be
|
||||
* associated with a plugin, which get rendered in the
|
||||
* sidebar header.
|
||||
* </p>
|
||||
*
|
||||
* @author gavinc
|
||||
*/
|
||||
public class UISidebar extends SelfRenderingComponent
|
||||
{
|
||||
public static final String COMPONENT_TYPE = "org.alfresco.faces.Sidebar";
|
||||
|
||||
protected String activePlugin;
|
||||
|
||||
@Override
|
||||
public String getFamily()
|
||||
{
|
||||
return COMPONENT_TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void restoreState(FacesContext context, Object state)
|
||||
{
|
||||
Object values[] = (Object[])state;
|
||||
// standard component attributes are restored by the super class
|
||||
super.restoreState(context, values[0]);
|
||||
this.activePlugin = (String)values[1];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object saveState(FacesContext context)
|
||||
{
|
||||
Object values[] = new Object[8];
|
||||
// standard component attributes are saved by the super class
|
||||
values[0] = super.saveState(context);
|
||||
values[1] = this.activePlugin;
|
||||
return values;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void encodeBegin(FacesContext context) throws IOException
|
||||
{
|
||||
if (!isRendered()) return;
|
||||
|
||||
ResponseWriter out = context.getResponseWriter();
|
||||
|
||||
out.write("<div id=\"sidebar\">");
|
||||
|
||||
// render the start of the header panel
|
||||
PanelGenerator.generatePanelStart(out,
|
||||
context.getExternalContext().getRequestContextPath(),
|
||||
"blue", "#D3E6FE");
|
||||
|
||||
// generate the required child components if not present
|
||||
if (this.getChildCount() == 1)
|
||||
{
|
||||
// create the mode list component
|
||||
UIModeList modeList = (UIModeList)context.getApplication().
|
||||
createComponent("org.alfresco.faces.ModeList");
|
||||
modeList.setId("sidebarPluginList");
|
||||
modeList.setValue(this.getActivePlugin());
|
||||
modeList.setIconColumnWidth(2);
|
||||
modeList.setMenu(true);
|
||||
modeList.setMenuImage("/images/icons/menu.gif");
|
||||
modeList.getAttributes().put("itemSpacing", 4);
|
||||
modeList.getAttributes().put("styleClass", "moreActionsMenu");
|
||||
modeList.getAttributes().put("selectedStyleClass", "statusListHighlight");
|
||||
MethodBinding listener = context.getApplication().createMethodBinding(
|
||||
"#{SidebarBean.pluginChanged}", new Class[] {ActionEvent.class});
|
||||
modeList.setActionListener(listener);
|
||||
|
||||
// create the child list items component
|
||||
UIListItems items = (UIListItems)context.getApplication().
|
||||
createComponent("org.alfresco.faces.ListItems");
|
||||
ValueBinding binding = context.getApplication().createValueBinding(
|
||||
"#{SidebarBean.plugins}");
|
||||
items.setValueBinding("value", binding);
|
||||
|
||||
// add the list items to the mode list component
|
||||
modeList.getChildren().add(items);
|
||||
|
||||
// create the actions component
|
||||
UIActions actions = (UIActions)context.getApplication().
|
||||
createComponent("org.alfresco.faces.Actions");
|
||||
actions.setId("sidebarActions");
|
||||
actions.setShowLink(false);
|
||||
// TODO: we need to setup the context for the actions component
|
||||
// but when the app first starts there is no context yet,
|
||||
// also the tree will not update the context as it is
|
||||
// navigated so what do we use? we may have to only support
|
||||
// global non-context actions
|
||||
String actionsGroupId = null;
|
||||
SidebarConfigElement config = SidebarBean.getSidebarConfig(context);
|
||||
if (config != null)
|
||||
{
|
||||
SidebarPluginConfig plugin = config.getPlugin(getActivePlugin());
|
||||
if (plugin != null)
|
||||
{
|
||||
actionsGroupId = plugin.getActionsConfigId();
|
||||
}
|
||||
}
|
||||
actions.setValue(actionsGroupId);
|
||||
|
||||
// add components to the sidebar
|
||||
this.getChildren().add(0, modeList);
|
||||
this.getChildren().add(1, actions);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encodeChildren(FacesContext context) throws IOException
|
||||
{
|
||||
if (!isRendered()) return;
|
||||
|
||||
// there should be 3 children, the modelist, the actions
|
||||
// and the plugin, get them individually and render
|
||||
|
||||
if (getChildren().size() == 3)
|
||||
{
|
||||
ResponseWriter out = context.getResponseWriter();
|
||||
|
||||
out.write("<table border='0' cellpadding='0' cellspacing='0' width='100%'><tr><td>");
|
||||
|
||||
// render the list
|
||||
UIModeList modeList = (UIModeList)getChildren().get(0);
|
||||
Utils.encodeRecursive(context, modeList);
|
||||
|
||||
out.write("</td><td align='right'>");
|
||||
|
||||
// render the actions
|
||||
UIActions actions = (UIActions)getChildren().get(1);
|
||||
Utils.encodeRecursive(context, actions);
|
||||
|
||||
out.write("</td></tr></table>");
|
||||
|
||||
// render the end of the header panel
|
||||
PanelGenerator.generateTitledPanelMiddle(out,
|
||||
context.getExternalContext().getRequestContextPath(),
|
||||
"blue", "white", "white");
|
||||
|
||||
// render the plugin
|
||||
UIComponent plugin = (UIComponent)getChildren().get(2);
|
||||
Utils.encodeRecursive(context, plugin);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encodeEnd(FacesContext context) throws IOException
|
||||
{
|
||||
if (!isRendered()) return;
|
||||
|
||||
// render the end of the panel
|
||||
ResponseWriter out = context.getResponseWriter();
|
||||
PanelGenerator.generatePanelEnd(out,
|
||||
context.getExternalContext().getRequestContextPath(),
|
||||
"white");
|
||||
out.write("</div>");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getRendersChildren()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
// Strongly typed component property accessors
|
||||
|
||||
/**
|
||||
* Returns the id of the plugin that is currently active
|
||||
*
|
||||
* @return The currently active plugin
|
||||
*/
|
||||
public String getActivePlugin()
|
||||
{
|
||||
ValueBinding vb = getValueBinding("activePlugin");
|
||||
if (vb != null)
|
||||
{
|
||||
this.activePlugin = (String)vb.getValue(getFacesContext());
|
||||
}
|
||||
|
||||
return this.activePlugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the active plugin the sidebar should show
|
||||
*
|
||||
* @param activePlugin Id of the plugin to make active
|
||||
*/
|
||||
public void setActivePlugin(String activePlugin)
|
||||
{
|
||||
this.activePlugin = activePlugin;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
384
source/java/org/alfresco/web/ui/repo/component/UITree.java
Normal file
384
source/java/org/alfresco/web/ui/repo/component/UITree.java
Normal file
@@ -0,0 +1,384 @@
|
||||
package org.alfresco.web.ui.repo.component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import javax.faces.component.UIComponentBase;
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.faces.el.ValueBinding;
|
||||
|
||||
/**
|
||||
* JSF component that renders an AJAX based tree for browsing the
|
||||
* repository.
|
||||
*
|
||||
* @author gavinc
|
||||
*/
|
||||
public class UITree extends UIComponentBase
|
||||
{
|
||||
public static final String COMPONENT_TYPE = "org.alfresco.faces.Tree";
|
||||
public static final String DEFAULT_RENDERER = "org.alfresco.faces.Yahoo";
|
||||
|
||||
protected List<TreeNode> rootNodes = null;
|
||||
protected String retrieveChildrenUrl;
|
||||
protected String nodeCollapsedUrl;
|
||||
protected String nodeExpandedCallback;
|
||||
protected String nodeCollapsedCallback;
|
||||
protected String nodeSelectedCallback;
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
// Component Impl
|
||||
|
||||
public UITree()
|
||||
{
|
||||
setRendererType(DEFAULT_RENDERER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFamily()
|
||||
{
|
||||
return COMPONENT_TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void restoreState(FacesContext context, Object state)
|
||||
{
|
||||
Object values[] = (Object[])state;
|
||||
// standard component attributes are restored by the super class
|
||||
super.restoreState(context, values[0]);
|
||||
this.rootNodes = (List<TreeNode>)values[1];
|
||||
this.retrieveChildrenUrl = (String)values[2];
|
||||
this.nodeCollapsedUrl = (String)values[3];
|
||||
this.nodeExpandedCallback = (String)values[4];
|
||||
this.nodeCollapsedCallback = (String)values[5];
|
||||
this.nodeSelectedCallback = (String)values[6];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object saveState(FacesContext context)
|
||||
{
|
||||
Object values[] = new Object[7];
|
||||
// standard component attributes are saved by the super class
|
||||
values[0] = super.saveState(context);
|
||||
values[1] = this.rootNodes;
|
||||
values[2] = this.retrieveChildrenUrl;
|
||||
values[3] = this.nodeCollapsedUrl;
|
||||
values[4] = this.nodeExpandedCallback;
|
||||
values[5] = this.nodeCollapsedCallback;
|
||||
values[6] = this.nodeSelectedCallback;
|
||||
return values;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
// Strongly typed component property accessors
|
||||
|
||||
/**
|
||||
* Get the root nodes for the tree
|
||||
*
|
||||
* @return the list of nodes representing the root nodes of the tree
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<TreeNode> getRootNodes()
|
||||
{
|
||||
ValueBinding vb = getValueBinding("rootNodes");
|
||||
if (vb != null)
|
||||
{
|
||||
this.rootNodes = (List<TreeNode>)vb.getValue(getFacesContext());
|
||||
}
|
||||
|
||||
return this.rootNodes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the root nodes for the tree to show
|
||||
*
|
||||
* @param rootNodes The list of node for the tree
|
||||
*/
|
||||
public void setRootNodes(List<TreeNode> rootNodes)
|
||||
{
|
||||
this.rootNodes = rootNodes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Javascript function name to be used for node collapsed event
|
||||
*
|
||||
* @return Javascript function name to be used for node collapsed event
|
||||
*/
|
||||
public String getNodeCollapsedCallback()
|
||||
{
|
||||
ValueBinding vb = getValueBinding("nodeCollapsedCallback");
|
||||
if (vb != null)
|
||||
{
|
||||
this.nodeCollapsedCallback = (String)vb.getValue(getFacesContext());
|
||||
}
|
||||
|
||||
return this.nodeCollapsedCallback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the name of the Javascript function to use for the node collapsed event
|
||||
*
|
||||
* @param nodeCollapsedCallback The Javascript function to use for the node collapsed event
|
||||
*/
|
||||
public void setNodeCollapsedCallback(String nodeCollapsedCallback)
|
||||
{
|
||||
this.nodeCollapsedCallback = nodeCollapsedCallback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Javascript function name to be used for node expanded event
|
||||
*
|
||||
* @return Javascript function name to be used for node expanded event
|
||||
*/
|
||||
public String getNodeExpandedCallback()
|
||||
{
|
||||
ValueBinding vb = getValueBinding("nodeExpandedCallback");
|
||||
if (vb != null)
|
||||
{
|
||||
this.nodeExpandedCallback = (String)vb.getValue(getFacesContext());
|
||||
}
|
||||
|
||||
return this.nodeExpandedCallback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the name of the Javascript function to use for the expanded event
|
||||
*
|
||||
* @param nodeCollapsedCallback The Javascript function to use for the expanded event
|
||||
*/
|
||||
public void setNodeExpandedCallback(String nodeExpandedCallback)
|
||||
{
|
||||
this.nodeExpandedCallback = nodeExpandedCallback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Javascript function name to be used for node selected event
|
||||
*
|
||||
* @return Javascript function name to be used for node selected event
|
||||
*/
|
||||
public String getNodeSelectedCallback()
|
||||
{
|
||||
ValueBinding vb = getValueBinding("nodeSelectedCallback");
|
||||
if (vb != null)
|
||||
{
|
||||
this.nodeSelectedCallback = (String)vb.getValue(getFacesContext());
|
||||
}
|
||||
|
||||
return this.nodeSelectedCallback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the name of the Javascript function to use for the node selected event
|
||||
*
|
||||
* @param nodeCollapsedCallback The Javascript function to use for the node selected event
|
||||
*/
|
||||
public void setNodeSelectedCallback(String nodeSelectedCallback)
|
||||
{
|
||||
this.nodeSelectedCallback = nodeSelectedCallback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the URL to use for the AJAX call to retrieve the child nodea
|
||||
*
|
||||
* @return AJAX URL to get children
|
||||
*/
|
||||
public String getRetrieveChildrenUrl()
|
||||
{
|
||||
ValueBinding vb = getValueBinding("retrieveChildrenUrl");
|
||||
if (vb != null)
|
||||
{
|
||||
this.retrieveChildrenUrl = (String)vb.getValue(getFacesContext());
|
||||
}
|
||||
|
||||
return this.retrieveChildrenUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the AJAX URL to use to retrive child nodes
|
||||
*
|
||||
* @param retrieveChildrenUrl The AJAX URL to use
|
||||
*/
|
||||
public void setRetrieveChildrenUrl(String retrieveChildrenUrl)
|
||||
{
|
||||
this.retrieveChildrenUrl = retrieveChildrenUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the URL to use for the AJAX call to inform the server
|
||||
* that a node has been collapsed
|
||||
*
|
||||
* @return AJAX URL to inform of node collapse
|
||||
*/
|
||||
public String getNodeCollapsedUrl()
|
||||
{
|
||||
ValueBinding vb = getValueBinding("nodeCollapsedUrl");
|
||||
if (vb != null)
|
||||
{
|
||||
this.nodeCollapsedUrl = (String)vb.getValue(getFacesContext());
|
||||
}
|
||||
|
||||
return this.nodeCollapsedUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the AJAX URL to use to inform the server that a node
|
||||
* has been collapsed
|
||||
*
|
||||
* @param nodeCollapsedUrl The AJAX URL to use
|
||||
*/
|
||||
public void setNodeCollapsedUrl(String nodeCollapsedUrl)
|
||||
{
|
||||
this.nodeCollapsedUrl = nodeCollapsedUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inner class representing a node in the tree
|
||||
*
|
||||
* @author gavinc
|
||||
*/
|
||||
public static class TreeNode
|
||||
{
|
||||
private String nodeRef;
|
||||
private String name;
|
||||
private String icon;
|
||||
private boolean leafNode = false;
|
||||
private boolean expanded = false;
|
||||
private boolean selected = false;
|
||||
private TreeNode parent;
|
||||
private List<TreeNode> children = new ArrayList<TreeNode>();
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*
|
||||
* @param nodeRef The NodeRef of the item the node is representing
|
||||
* @param name The name for the tree label
|
||||
* @param icon The icon for the node
|
||||
*/
|
||||
public TreeNode(String nodeRef, String name, String icon)
|
||||
{
|
||||
this.nodeRef = nodeRef;
|
||||
this.name = name;
|
||||
this.icon = icon;
|
||||
}
|
||||
|
||||
public String getIcon()
|
||||
{
|
||||
return this.icon;
|
||||
}
|
||||
|
||||
public void setIcon(String icon)
|
||||
{
|
||||
this.icon = icon;
|
||||
}
|
||||
|
||||
public boolean isLeafNode()
|
||||
{
|
||||
return this.leafNode;
|
||||
}
|
||||
|
||||
public void setLeafNode(boolean leafNode)
|
||||
{
|
||||
this.leafNode = leafNode;
|
||||
}
|
||||
|
||||
public boolean isExpanded()
|
||||
{
|
||||
return this.expanded;
|
||||
}
|
||||
|
||||
public void setExpanded(boolean expanded)
|
||||
{
|
||||
this.expanded = expanded;
|
||||
}
|
||||
|
||||
public boolean isSelected()
|
||||
{
|
||||
return this.selected;
|
||||
}
|
||||
|
||||
public void setSelected(boolean selected)
|
||||
{
|
||||
this.selected = selected;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getNodeRef()
|
||||
{
|
||||
return this.nodeRef;
|
||||
}
|
||||
|
||||
public void setNodeRef(String nodeRef)
|
||||
{
|
||||
this.nodeRef = nodeRef;
|
||||
}
|
||||
|
||||
public TreeNode getParent()
|
||||
{
|
||||
return this.parent;
|
||||
}
|
||||
|
||||
public void setParent(TreeNode parent)
|
||||
{
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public List<TreeNode> getChildren()
|
||||
{
|
||||
return this.children;
|
||||
}
|
||||
|
||||
public void addChild(TreeNode child)
|
||||
{
|
||||
child.setParent(this);
|
||||
this.children.add(child);
|
||||
}
|
||||
|
||||
public void removeChildren()
|
||||
{
|
||||
this.children = new ArrayList<TreeNode>();
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
StringBuilder buffer = new StringBuilder(super.toString());
|
||||
buffer.append(" (nodeRef=").append(this.nodeRef);
|
||||
buffer.append(", name=").append(this.name);
|
||||
buffer.append(", icon=").append(this.icon);
|
||||
buffer.append(", expanded=").append(this.expanded);
|
||||
buffer.append(", selected=").append(this.selected);
|
||||
if (this.parent != null)
|
||||
{
|
||||
buffer.append(", parent=").append(this.parent.getNodeRef());
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer.append(", parent=null");
|
||||
}
|
||||
buffer.append(", leafNode=").append(this.leafNode).append(")");
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
public String toXML()
|
||||
{
|
||||
StringBuilder xml = new StringBuilder();
|
||||
xml.append("<node ref=\"");
|
||||
xml.append(this.nodeRef);
|
||||
xml.append("\" name=\"");
|
||||
xml.append(this.name);
|
||||
xml.append("\" icon=\"");
|
||||
xml.append(this.icon);
|
||||
xml.append("\"/>");
|
||||
return xml.toString();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,188 @@
|
||||
package org.alfresco.web.ui.repo.renderer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import javax.faces.component.UIComponent;
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.faces.context.ResponseWriter;
|
||||
|
||||
import org.alfresco.web.ui.common.Utils;
|
||||
import org.alfresco.web.ui.common.renderer.BaseRenderer;
|
||||
import org.alfresco.web.ui.repo.component.UITree;
|
||||
import org.alfresco.web.ui.repo.component.UITree.TreeNode;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
/**
|
||||
* Renderer for the UITree component that outputs the necessary
|
||||
* JavaScript to use the Yahoo UI toolkit tree control.
|
||||
*
|
||||
* @author gavinc
|
||||
*/
|
||||
public class YahooTreeRenderer extends BaseRenderer
|
||||
{
|
||||
protected int nodeCounter;
|
||||
|
||||
protected final static String TREE_SCRIPTS_WRITTEN = "_alfTreeScripts";
|
||||
|
||||
private static final Log logger = LogFactory.getLog(YahooTreeRenderer.class);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void encodeBegin(FacesContext context, UIComponent component) throws IOException
|
||||
{
|
||||
// get the root nodes
|
||||
UITree tree = (UITree)component;
|
||||
List<TreeNode> rootNodes = tree.getRootNodes();
|
||||
|
||||
if (rootNodes != null && rootNodes.size() > 0)
|
||||
{
|
||||
ResponseWriter out = context.getResponseWriter();
|
||||
String treeContainerId = component.getClientId(context) + "Container";
|
||||
|
||||
// output the scripts required by the component (checks are
|
||||
// made to make sure the scripts are only written once)
|
||||
Utils.writeYahooScripts(context, out, null);
|
||||
|
||||
// write out the JavaScript specific to the Tree component,
|
||||
// again, make sure it's only done once
|
||||
Object present = context.getExternalContext().getRequestMap().
|
||||
get(TREE_SCRIPTS_WRITTEN);
|
||||
if (present == null)
|
||||
{
|
||||
out.write("<link rel=\"stylesheet\" href=\"");
|
||||
out.write(context.getExternalContext().getRequestContextPath());
|
||||
out.write("/css/yahoo-tree.css\" type=\"text/css\" />");
|
||||
|
||||
out.write("<script type=\"text/javascript\" src=\"");
|
||||
out.write(context.getExternalContext().getRequestContextPath());
|
||||
out.write("/scripts/ajax/yahoo/treeview/treeview-min.js\"> </script>\n");
|
||||
|
||||
out.write("<script type=\"text/javascript\" src=\"");
|
||||
out.write(context.getExternalContext().getRequestContextPath());
|
||||
out.write("/scripts/ajax/yahoo-tree.js\"> </script>\n");
|
||||
|
||||
context.getExternalContext().getRequestMap().put(
|
||||
TREE_SCRIPTS_WRITTEN, Boolean.TRUE);
|
||||
}
|
||||
|
||||
// output the div container for the tree
|
||||
out.write("<div id=\"");
|
||||
out.write(treeContainerId);
|
||||
out.write("\"></div>\n");
|
||||
|
||||
// generate the startup
|
||||
out.write("<script type=\"text/javascript\">\n");
|
||||
out.write("var tree;\n");
|
||||
if (tree.getRetrieveChildrenUrl() != null)
|
||||
{
|
||||
out.write("setLoadDataUrl('");
|
||||
out.write(tree.getRetrieveChildrenUrl());
|
||||
out.write("');\n");
|
||||
}
|
||||
if (tree.getNodeCollapsedUrl() != null)
|
||||
{
|
||||
out.write("setCollapseUrl('");
|
||||
out.write(tree.getNodeCollapsedUrl());
|
||||
out.write("');\n");
|
||||
}
|
||||
if (tree.getNodeSelectedCallback() != null)
|
||||
{
|
||||
out.write("setNodeSelectedHandler('");
|
||||
out.write(tree.getNodeSelectedCallback());
|
||||
out.write("');\n");
|
||||
}
|
||||
out.write("function initTree() {\n");
|
||||
out.write(" tree = new YAHOO.widget.TreeView(\"");
|
||||
out.write(treeContainerId);
|
||||
out.write("\");\n");
|
||||
out.write(" var root = tree.getRoot();\n");
|
||||
|
||||
if (tree.getNodeExpandedCallback() != null)
|
||||
{
|
||||
out.write(" tree.subscribe('expand', ");
|
||||
out.write(tree.getNodeExpandedCallback());
|
||||
out.write(");\n");
|
||||
}
|
||||
if (tree.getNodeCollapsedCallback() != null)
|
||||
{
|
||||
out.write(" tree.subscribe('collapse', ");
|
||||
out.write(tree.getNodeCollapsedCallback());
|
||||
out.write(");\n");
|
||||
}
|
||||
|
||||
// generate script for each root node
|
||||
this.nodeCounter = 0;
|
||||
for (TreeNode node : rootNodes)
|
||||
{
|
||||
generateNode(node, out, null);
|
||||
}
|
||||
|
||||
out.write(" tree.draw();\n");
|
||||
out.write(" tree.setDynamicLoad(loadDataForNode);\n}\n");
|
||||
out.write("YAHOO.util.Event.on(window, \"load\", window.initTree);");
|
||||
out.write("</script>\n");
|
||||
}
|
||||
else if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("There weren't any nodes to render");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the JavaScript required to create the branch of a tree from
|
||||
* the given node.
|
||||
*
|
||||
* @param node The node to generate
|
||||
* @param out Response writer
|
||||
* @param parentVarName Name of the parent variable, null if the node has no parent
|
||||
*/
|
||||
protected void generateNode(TreeNode node, ResponseWriter out, String parentVarName)
|
||||
throws IOException
|
||||
{
|
||||
String currentVarName = getNextVarName();
|
||||
|
||||
// generate the Javascript to create the given node using the
|
||||
// appropriate parent variable
|
||||
out.write(" var ");
|
||||
out.write(currentVarName);
|
||||
out.write(" = createYahooTreeNode(");
|
||||
|
||||
if (node.getParent() == null)
|
||||
{
|
||||
out.write("root");
|
||||
}
|
||||
else
|
||||
{
|
||||
out.write(parentVarName);
|
||||
}
|
||||
|
||||
out.write(", \"");
|
||||
out.write(node.getNodeRef());
|
||||
out.write("\", \"");
|
||||
out.write(node.getName());
|
||||
out.write("\", \"");
|
||||
out.write(node.getIcon());
|
||||
out.write("\", ");
|
||||
out.write(Boolean.toString(node.isExpanded()));
|
||||
out.write(", ");
|
||||
out.write(Boolean.toString(node.isSelected()));
|
||||
out.write(");\n");
|
||||
|
||||
// iterate through the child nodes and generate them
|
||||
if (node.isExpanded() && node.getChildren().size() > 0)
|
||||
{
|
||||
for (TreeNode child : node.getChildren())
|
||||
{
|
||||
generateNode(child, out, currentVarName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected String getNextVarName()
|
||||
{
|
||||
this.nodeCounter++;
|
||||
return "n" + Integer.toString(this.nodeCounter);
|
||||
}
|
||||
}
|
77
source/java/org/alfresco/web/ui/repo/tag/NavigatorTag.java
Normal file
77
source/java/org/alfresco/web/ui/repo/tag/NavigatorTag.java
Normal file
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.web.ui.repo.tag;
|
||||
|
||||
import javax.faces.component.UIComponent;
|
||||
|
||||
import org.alfresco.web.ui.common.tag.HtmlComponentTag;
|
||||
|
||||
/**
|
||||
* Tag class for using the navigator component on a JSP page.
|
||||
*
|
||||
* @author gavinc
|
||||
*/
|
||||
public class NavigatorTag extends HtmlComponentTag
|
||||
{
|
||||
private String activeArea;
|
||||
|
||||
/**
|
||||
* @see javax.faces.webapp.UIComponentTag#getComponentType()
|
||||
*/
|
||||
public String getComponentType()
|
||||
{
|
||||
return "org.alfresco.faces.Navigator";
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.faces.webapp.UIComponentTag#getRendererType()
|
||||
*/
|
||||
public String getRendererType()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.faces.webapp.UIComponentTag#setProperties(javax.faces.component.UIComponent)
|
||||
*/
|
||||
protected void setProperties(UIComponent component)
|
||||
{
|
||||
super.setProperties(component);
|
||||
|
||||
setStringBindingProperty(component, "activeArea", this.activeArea);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.web.ui.common.tag.HtmlComponentTag#release()
|
||||
*/
|
||||
public void release()
|
||||
{
|
||||
super.release();
|
||||
|
||||
this.activeArea = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the active area of the navigator
|
||||
*
|
||||
* @param activeArea The active area
|
||||
*/
|
||||
public void setActiveArea(String activeArea)
|
||||
{
|
||||
this.activeArea = activeArea;
|
||||
}
|
||||
}
|
78
source/java/org/alfresco/web/ui/repo/tag/SidebarTag.java
Normal file
78
source/java/org/alfresco/web/ui/repo/tag/SidebarTag.java
Normal file
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.web.ui.repo.tag;
|
||||
|
||||
import javax.faces.component.UIComponent;
|
||||
|
||||
import org.alfresco.web.ui.common.tag.HtmlComponentTag;
|
||||
import org.alfresco.web.ui.repo.component.UISidebar;
|
||||
|
||||
/**
|
||||
* Tag class for using the sidebar component on a JSP page.
|
||||
*
|
||||
* @author gavinc
|
||||
*/
|
||||
public class SidebarTag extends HtmlComponentTag
|
||||
{
|
||||
private String activePlugin;
|
||||
|
||||
/**
|
||||
* @see javax.faces.webapp.UIComponentTag#getComponentType()
|
||||
*/
|
||||
public String getComponentType()
|
||||
{
|
||||
return UISidebar.COMPONENT_TYPE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.faces.webapp.UIComponentTag#getRendererType()
|
||||
*/
|
||||
public String getRendererType()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.faces.webapp.UIComponentTag#setProperties(javax.faces.component.UIComponent)
|
||||
*/
|
||||
protected void setProperties(UIComponent component)
|
||||
{
|
||||
super.setProperties(component);
|
||||
|
||||
setStringBindingProperty(component, "activePlugin", this.activePlugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.web.ui.common.tag.HtmlComponentTag#release()
|
||||
*/
|
||||
public void release()
|
||||
{
|
||||
super.release();
|
||||
|
||||
this.activePlugin = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the activePlugin attribute
|
||||
*
|
||||
* @param activePlugin
|
||||
*/
|
||||
public void setActivePlugin(String activePlugin)
|
||||
{
|
||||
this.activePlugin = activePlugin;
|
||||
}
|
||||
}
|
142
source/java/org/alfresco/web/ui/repo/tag/YahooTreeTag.java
Normal file
142
source/java/org/alfresco/web/ui/repo/tag/YahooTreeTag.java
Normal file
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.web.ui.repo.tag;
|
||||
|
||||
import javax.faces.component.UIComponent;
|
||||
|
||||
import org.alfresco.web.ui.common.tag.HtmlComponentTag;
|
||||
|
||||
/**
|
||||
* Tag class for using the Yahoo tree component on a JSP page.
|
||||
*
|
||||
* @author gavinc
|
||||
*/
|
||||
public class YahooTreeTag extends HtmlComponentTag
|
||||
{
|
||||
private String rootNodes;
|
||||
private String retrieveChildrenUrl;
|
||||
private String nodeCollapsedUrl;
|
||||
private String nodeExpandedCallback;
|
||||
private String nodeCollapsedCallback;
|
||||
private String nodeSelectedCallback;
|
||||
|
||||
/**
|
||||
* @see javax.faces.webapp.UIComponentTag#getComponentType()
|
||||
*/
|
||||
public String getComponentType()
|
||||
{
|
||||
return "org.alfresco.faces.Tree";
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.faces.webapp.UIComponentTag#getRendererType()
|
||||
*/
|
||||
public String getRendererType()
|
||||
{
|
||||
return "org.alfresco.faces.Yahoo";
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.faces.webapp.UIComponentTag#setProperties(javax.faces.component.UIComponent)
|
||||
*/
|
||||
protected void setProperties(UIComponent component)
|
||||
{
|
||||
super.setProperties(component);
|
||||
|
||||
setStringBindingProperty(component, "rootNodes", this.rootNodes);
|
||||
setStringBindingProperty(component, "retrieveChildrenUrl", this.retrieveChildrenUrl);
|
||||
setStringBindingProperty(component, "nodeCollapsedUrl", this.nodeCollapsedUrl);
|
||||
setStringBindingProperty(component, "nodeExpandedCallback", this.nodeExpandedCallback);
|
||||
setStringBindingProperty(component, "nodeCollapsedCallback", this.nodeCollapsedCallback);
|
||||
setStringBindingProperty(component, "nodeSelectedCallback", this.nodeSelectedCallback);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.web.ui.common.tag.HtmlComponentTag#release()
|
||||
*/
|
||||
public void release()
|
||||
{
|
||||
super.release();
|
||||
|
||||
this.rootNodes = null;
|
||||
this.retrieveChildrenUrl = null;
|
||||
this.nodeCollapsedUrl = null;
|
||||
this.nodeExpandedCallback = null;
|
||||
this.nodeCollapsedCallback = null;
|
||||
this.nodeSelectedCallback = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the root nodes for the tree
|
||||
*
|
||||
* @param rootNodes
|
||||
*/
|
||||
public void setRootNodes(String rootNodes)
|
||||
{
|
||||
this.rootNodes = rootNodes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the name of the Javascript function to handle the node collapsed event
|
||||
*
|
||||
* @param nodeCollapsedCallback
|
||||
*/
|
||||
public void setNodeCollapsedCallback(String nodeCollapsedCallback)
|
||||
{
|
||||
this.nodeCollapsedCallback = nodeCollapsedCallback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the name of the Javascript function to handle the node expanded event
|
||||
*
|
||||
* @param nodeExpandedCallback
|
||||
*/
|
||||
public void setNodeExpandedCallback(String nodeExpandedCallback)
|
||||
{
|
||||
this.nodeExpandedCallback = nodeExpandedCallback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the name of the Javascript function to handle the node selected event
|
||||
*
|
||||
* @param nodeSelectedCallback
|
||||
*/
|
||||
public void setNodeSelectedCallback(String nodeSelectedCallback)
|
||||
{
|
||||
this.nodeSelectedCallback = nodeSelectedCallback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the URL to use to retrieve child nodes
|
||||
*
|
||||
* @param retrieveChildrenUrl
|
||||
*/
|
||||
public void setRetrieveChildrenUrl(String retrieveChildrenUrl)
|
||||
{
|
||||
this.retrieveChildrenUrl = retrieveChildrenUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the URL to use to inform the server that a node has been collapsed
|
||||
*
|
||||
* @param nodeCollapsedUrl
|
||||
*/
|
||||
public void setNodeCollapsedUrl(String nodeCollapsedUrl)
|
||||
{
|
||||
this.nodeCollapsedUrl = nodeCollapsedUrl;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user