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:
169
source/java/org/alfresco/web/bean/SidebarBean.java
Normal file
169
source/java/org/alfresco/web/bean/SidebarBean.java
Normal file
@@ -0,0 +1,169 @@
|
||||
package org.alfresco.web.bean;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.faces.event.ActionEvent;
|
||||
|
||||
import org.alfresco.config.Config;
|
||||
import org.alfresco.web.app.Application;
|
||||
import org.alfresco.web.config.SidebarConfigElement;
|
||||
import org.alfresco.web.config.SidebarConfigElement.SidebarPluginConfig;
|
||||
import org.alfresco.web.ui.common.component.UIListItem;
|
||||
import org.alfresco.web.ui.common.component.UIModeList;
|
||||
|
||||
/**
|
||||
* Managed bean used by the sidebar component to manage it's state.
|
||||
*
|
||||
* @author gavinc
|
||||
*/
|
||||
public class SidebarBean
|
||||
{
|
||||
protected String activePlugin;
|
||||
protected List<UIListItem> plugins;
|
||||
protected SidebarConfigElement sidebarConfig;
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
public SidebarBean()
|
||||
{
|
||||
// get the sidebar config object
|
||||
this.sidebarConfig = getSidebarConfig(FacesContext.getCurrentInstance());
|
||||
|
||||
// make sure we found the config
|
||||
if (this.sidebarConfig == null)
|
||||
{
|
||||
throw new IllegalStateException("Failed to find configuration for the sidebar");
|
||||
}
|
||||
|
||||
// build the list of plugins available and check we have at least one
|
||||
List<UIListItem> items = this.getPlugins();
|
||||
if (items.size() == 0)
|
||||
{
|
||||
throw new IllegalStateException("Failed to find configuration for any sidebar plugins, at least one must be defined!");
|
||||
}
|
||||
|
||||
// determine the default plugin
|
||||
this.activePlugin = this.sidebarConfig.getDefaultPlugin();
|
||||
if (this.activePlugin == null)
|
||||
{
|
||||
this.activePlugin = (String)items.get(0).getValue();
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
// Event handlers
|
||||
|
||||
public void pluginChanged(ActionEvent event)
|
||||
{
|
||||
UIModeList pluginList = (UIModeList)event.getComponent();
|
||||
|
||||
// get the selected plugin
|
||||
this.activePlugin = pluginList.getValue().toString();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
// Bean Getters and Setters
|
||||
|
||||
/**
|
||||
* Returns a list of configured plugins
|
||||
*
|
||||
* @return List of UIListItem's representing the plugins available
|
||||
*/
|
||||
public List<UIListItem> getPlugins()
|
||||
{
|
||||
if (this.plugins == null)
|
||||
{
|
||||
FacesContext context = FacesContext.getCurrentInstance();
|
||||
this.plugins = new ArrayList<UIListItem>();
|
||||
|
||||
// create a list entry for each configured plugin
|
||||
for (String pluginId : this.sidebarConfig.getPlugins().keySet())
|
||||
{
|
||||
SidebarPluginConfig plugin = this.sidebarConfig.getPlugin(pluginId);
|
||||
|
||||
// resolve the label for the plugin
|
||||
String label = plugin.getlabelId();
|
||||
if (label != null)
|
||||
{
|
||||
label = Application.getMessage(context, label);
|
||||
}
|
||||
if (label == null)
|
||||
{
|
||||
label = plugin.getlabel();
|
||||
}
|
||||
if (label == null)
|
||||
{
|
||||
label = plugin.getId();
|
||||
}
|
||||
|
||||
// resolve the description (tooltip for the plugin)
|
||||
String tooltip = plugin.getDescriptionId();
|
||||
if (tooltip != null)
|
||||
{
|
||||
tooltip = Application.getMessage(context, tooltip);
|
||||
}
|
||||
if (tooltip == null)
|
||||
{
|
||||
tooltip = plugin.getDescription();
|
||||
}
|
||||
|
||||
UIListItem item = new UIListItem();
|
||||
item.setValue(plugin.getId());
|
||||
item.setLabel(label);
|
||||
if (tooltip != null)
|
||||
{
|
||||
item.setTooltip(tooltip);
|
||||
}
|
||||
|
||||
this.plugins.add(item);
|
||||
}
|
||||
}
|
||||
|
||||
return this.plugins;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the id of the currently active plugin
|
||||
*
|
||||
* @return Id of the current plugin
|
||||
*/
|
||||
public String getActivePlugin()
|
||||
{
|
||||
return activePlugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the path of the JSP to use for the current plugin
|
||||
*
|
||||
* @return JSP to use for the current plugin
|
||||
*/
|
||||
public String getActivePluginPage()
|
||||
{
|
||||
return this.sidebarConfig.getPlugin(this.activePlugin).getPage();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
// Helper methods
|
||||
|
||||
/**
|
||||
* Returns the SidebarConfigElement for the application
|
||||
*
|
||||
* @param context Faces context
|
||||
* @return The SidebarConfigElement object or null if it's not found
|
||||
*/
|
||||
public static SidebarConfigElement getSidebarConfig(FacesContext context)
|
||||
{
|
||||
SidebarConfigElement config = null;
|
||||
|
||||
Config cfg = Application.getConfigService(context).getConfig("Sidebar");
|
||||
if (cfg != null)
|
||||
{
|
||||
config = (SidebarConfigElement)cfg.getConfigElement(SidebarConfigElement.CONFIG_ELEMENT_ID);
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user