mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Merge from HEAD into WCM-DEV2. Also fixes build breakage in
jndi-client and catalina-virtual that I introduced earlier. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3393 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -0,0 +1,404 @@
|
||||
/*
|
||||
* 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.bean.dashboard;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
|
||||
import javax.faces.context.FacesContext;
|
||||
|
||||
import org.alfresco.config.ConfigService;
|
||||
import org.alfresco.web.app.Application;
|
||||
import org.alfresco.web.bean.repository.PreferencesService;
|
||||
import org.alfresco.web.config.DashboardsConfigElement;
|
||||
import org.alfresco.web.config.DashboardsConfigElement.DashletDefinition;
|
||||
import org.alfresco.web.config.DashboardsConfigElement.LayoutDefinition;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
/**
|
||||
* Bean that manages the Dashboard framework.
|
||||
*
|
||||
* @author Kevin Roast
|
||||
*/
|
||||
public class DashboardManager
|
||||
{
|
||||
private static Log logger = LogFactory.getLog(DashboardManager.class);
|
||||
|
||||
private static final String PREF_DASHBOARD = "dashboard";
|
||||
static final String LAYOUT_DEFAULT = "default";
|
||||
static final String DASHLET_DEFAULT = "getting-started";
|
||||
|
||||
private static final String JSP_DUMMY = "/jsp/dashboards/dummy.jsp";
|
||||
|
||||
private PageConfig pageConfig = null;
|
||||
private DashletRenderingList renderingList = null;
|
||||
private DashletTitleList titleList = null;
|
||||
|
||||
/**
|
||||
* @return The layout JSP page for the current My Alfresco dashboard page
|
||||
*/
|
||||
public String getLayoutPage()
|
||||
{
|
||||
String layout = null;
|
||||
Page page = getPageConfig().getCurrentPage();
|
||||
if (page != null)
|
||||
{
|
||||
layout = page.getLayoutDefinition().JSPPage;
|
||||
}
|
||||
return layout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to init the dashboard for display
|
||||
*/
|
||||
public void initDashboard()
|
||||
{
|
||||
this.renderingList = null;
|
||||
this.titleList = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return JSF List getter to return which dashlets are available for rendering
|
||||
*/
|
||||
public List getDashletAvailable()
|
||||
{
|
||||
if (this.renderingList == null)
|
||||
{
|
||||
this.renderingList = new DashletRenderingList(getPageConfig());
|
||||
}
|
||||
return this.renderingList;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return JSF List getter to return dashlet title strings
|
||||
*/
|
||||
public List getDashletTitle()
|
||||
{
|
||||
if (this.titleList == null)
|
||||
{
|
||||
this.titleList = new DashletTitleList(getPageConfig());
|
||||
}
|
||||
return this.titleList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the JSP for the specified dashlet index
|
||||
*
|
||||
* @param index Zero based index from the left most column working top-bottom then left-right
|
||||
*
|
||||
* @return JSP page for the dashlet or a blank dummy page if not found
|
||||
*/
|
||||
public String getDashletPage(int index)
|
||||
{
|
||||
String page = JSP_DUMMY;
|
||||
DashletDefinition def = getDashletDefinitionByIndex(getPageConfig(), index);
|
||||
if (def != null)
|
||||
{
|
||||
page = def.JSPPage;
|
||||
}
|
||||
return page;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the PageConfig for the current My Alfresco dashboard page
|
||||
*/
|
||||
public PageConfig getPageConfig()
|
||||
{
|
||||
if (this.pageConfig == null)
|
||||
{
|
||||
PageConfig pageConfig;
|
||||
|
||||
DashboardsConfigElement config = getDashboardConfig();
|
||||
|
||||
// read the config for this user from the Preferences
|
||||
String xml = (String)PreferencesService.getPreferences().getValue(PREF_DASHBOARD);
|
||||
if (xml != null && xml.length() != 0)
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("PageConfig found: " + xml);
|
||||
|
||||
// process the XML config and convert into a PageConfig object
|
||||
pageConfig = new PageConfig();
|
||||
pageConfig.fromXML(config, xml);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("No PageConfig found, creating default instance.");
|
||||
|
||||
// create default config for the first access for a user
|
||||
pageConfig = new PageConfig();
|
||||
LayoutDefinition layout = config.getLayoutDefinition(LAYOUT_DEFAULT);
|
||||
if (layout != null)
|
||||
{
|
||||
Page page = new Page("default", layout);
|
||||
Column defaultColumn = new Column();
|
||||
DashletDefinition dashlet = config.getDashletDefinition(DASHLET_DEFAULT);
|
||||
if (dashlet != null)
|
||||
{
|
||||
defaultColumn.addDashlet(dashlet);
|
||||
page.addColumn(defaultColumn);
|
||||
pageConfig.addPage(page);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.pageConfig = pageConfig;
|
||||
}
|
||||
|
||||
return this.pageConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Persist the supplied PageConfig for the current user
|
||||
*/
|
||||
public void savePageConfig(PageConfig config)
|
||||
{
|
||||
this.pageConfig = config;
|
||||
|
||||
// reset cached values
|
||||
initDashboard();
|
||||
|
||||
// persist the changes
|
||||
PreferencesService.getPreferences().setValue(PREF_DASHBOARD, this.pageConfig.toXML());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The externally configured WebClient config element for the Dashboards
|
||||
*/
|
||||
public static DashboardsConfigElement getDashboardConfig()
|
||||
{
|
||||
ConfigService service = Application.getConfigService(FacesContext.getCurrentInstance());
|
||||
DashboardsConfigElement config = (DashboardsConfigElement)service.getConfig("Dashboards").getConfigElement(
|
||||
DashboardsConfigElement.CONFIG_ELEMENT_ID);
|
||||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to get the DashDefinition as the zero based index, working from the left most column
|
||||
* top-bottom then working left-right.
|
||||
*
|
||||
* @param index Zero based index from the left most column working top-bottom then left-right
|
||||
*
|
||||
* @return DashletDefinition if found or null if no dashlet at the specified index
|
||||
*/
|
||||
private static DashletDefinition getDashletDefinitionByIndex(PageConfig config, int index)
|
||||
{
|
||||
DashletDefinition def = null;
|
||||
|
||||
LayoutDefinition layoutDef = config.getCurrentPage().getLayoutDefinition();
|
||||
List<Column> columns = config.getCurrentPage().getColumns();
|
||||
int columnCount = columns.size();
|
||||
int selectedColumn = index / layoutDef.ColumnLength;
|
||||
if (selectedColumn < columnCount)
|
||||
{
|
||||
List<DashletDefinition> dashlets = columns.get(selectedColumn).getDashlets();
|
||||
if (index % layoutDef.ColumnLength < dashlets.size())
|
||||
{
|
||||
def = dashlets.get(index % layoutDef.ColumnLength);
|
||||
}
|
||||
}
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Searching for dashlet at index: " + index +
|
||||
" and found " + (def != null ? def.JSPPage : null));
|
||||
|
||||
return def;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Dashlet rendering list.
|
||||
*
|
||||
* Returns true from the get() method if the specified dashlet is available for rendering.
|
||||
*/
|
||||
private static class DashletRenderingList extends JSFHelperList
|
||||
{
|
||||
PageConfig config;
|
||||
|
||||
public DashletRenderingList(PageConfig config)
|
||||
{
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.util.List#get(int)
|
||||
*/
|
||||
public Object get(int index)
|
||||
{
|
||||
return getDashletDefinitionByIndex(config, index) != null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Dashlet title list.
|
||||
*
|
||||
* Returns the title string from the get() method if the specified dashlet is available.
|
||||
*/
|
||||
private static class DashletTitleList extends JSFHelperList
|
||||
{
|
||||
PageConfig config;
|
||||
|
||||
public DashletTitleList(PageConfig config)
|
||||
{
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.util.List#get(int)
|
||||
*/
|
||||
public Object get(int index)
|
||||
{
|
||||
String result = "";
|
||||
|
||||
DashletDefinition def = getDashletDefinitionByIndex(config, index);
|
||||
if (def != null)
|
||||
{
|
||||
if (def.LabelId != null)
|
||||
{
|
||||
result = Application.getMessage(FacesContext.getCurrentInstance(), def.LabelId);
|
||||
}
|
||||
else if (def.Label != null)
|
||||
{
|
||||
result = def.Label;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper class that implements a dummy List contract for use by JSF List getter methods
|
||||
*/
|
||||
private static abstract class JSFHelperList implements List
|
||||
{
|
||||
//
|
||||
// Satisfy List interface contract
|
||||
//
|
||||
|
||||
public void add(int arg0, Object arg1)
|
||||
{
|
||||
}
|
||||
|
||||
public boolean add(Object arg0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean addAll(Collection arg0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean addAll(int arg0, Collection arg1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public void clear()
|
||||
{
|
||||
}
|
||||
|
||||
public boolean contains(Object arg0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean containsAll(Collection arg0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public int indexOf(Object arg0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public Iterator iterator()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public int lastIndexOf(Object arg0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public ListIterator listIterator()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public ListIterator listIterator(int arg0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public Object remove(int arg0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean remove(Object arg0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean removeAll(Collection arg0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean retainAll(Collection arg0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public Object set(int arg0, Object arg1)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public int size()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public List subList(int arg0, int arg1)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public Object[] toArray()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public Object[] toArray(Object[] arg0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
467
source/java/org/alfresco/web/bean/dashboard/DashboardWizard.java
Normal file
467
source/java/org/alfresco/web/bean/dashboard/DashboardWizard.java
Normal file
@@ -0,0 +1,467 @@
|
||||
/*
|
||||
* 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.bean.dashboard;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.faces.component.UISelectMany;
|
||||
import javax.faces.component.UISelectOne;
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.faces.event.ActionEvent;
|
||||
import javax.faces.model.SelectItem;
|
||||
|
||||
import org.alfresco.web.app.Application;
|
||||
import org.alfresco.web.bean.wizard.BaseWizardBean;
|
||||
import org.alfresco.web.config.DashboardsConfigElement;
|
||||
import org.alfresco.web.config.DashboardsConfigElement.DashletDefinition;
|
||||
import org.alfresco.web.config.DashboardsConfigElement.LayoutDefinition;
|
||||
import org.alfresco.web.ui.common.component.UIListItem;
|
||||
import org.alfresco.web.ui.common.component.description.UIDescription;
|
||||
|
||||
/**
|
||||
* @author Kevin Roast
|
||||
*/
|
||||
public class DashboardWizard extends BaseWizardBean
|
||||
{
|
||||
private static final String COMPONENT_COLUMNDASHLETS = "column-dashlets";
|
||||
|
||||
private static final String COMPONENT_ALLDASHLETS = "all-dashlets";
|
||||
|
||||
private static final String MSG_COLUMN = "dashboard_column";
|
||||
|
||||
/** List of icons items to display as selectable Layout definitions */
|
||||
private List<UIListItem> layoutIcons = null;
|
||||
|
||||
/** List of descriptions of the layouts */
|
||||
private List<UIDescription> layoutDescriptions = null;
|
||||
|
||||
/** List of SelectItem objects representing the available dashlets */
|
||||
private List<SelectItem> dashlets = null;
|
||||
|
||||
/** Currently selected layout */
|
||||
private String layout;
|
||||
|
||||
/** Currently selected column to edit */
|
||||
private int column;
|
||||
|
||||
/** The PageConfig holding the columns/dashlets during editing */
|
||||
private PageConfig editConfig;
|
||||
|
||||
/** The DashboardManager instance */
|
||||
private DashboardManager dashboardManager;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
// Bean setters
|
||||
|
||||
/**
|
||||
* @param dashboardManager The dashboardManager to set.
|
||||
*/
|
||||
public void setDashboardManager(DashboardManager dashboardManager)
|
||||
{
|
||||
this.dashboardManager = dashboardManager;
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
// Wizard implementation
|
||||
|
||||
/**
|
||||
* @see org.alfresco.web.bean.dialog.BaseDialogBean#init(java.util.Map)
|
||||
*/
|
||||
public void init(Map<String, String> parameters)
|
||||
{
|
||||
super.init(parameters);
|
||||
|
||||
this.editConfig = new PageConfig(this.dashboardManager.getPageConfig());
|
||||
this.layout = this.editConfig.getCurrentPage().getLayoutDefinition().Id;
|
||||
this.column = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.web.bean.dialog.BaseDialogBean#finishImpl(javax.faces.context.FacesContext, java.lang.String)
|
||||
*/
|
||||
protected String finishImpl(FacesContext context, String outcome) throws Exception
|
||||
{
|
||||
this.dashboardManager.savePageConfig(this.editConfig);
|
||||
return outcome;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the summary data for the wizard.
|
||||
*/
|
||||
public String getSummary()
|
||||
{
|
||||
LayoutDefinition def = DashboardManager.getDashboardConfig().getLayoutDefinition(this.layout);
|
||||
String label = def.Label;
|
||||
if (label == null)
|
||||
{
|
||||
label = Application.getMessage(FacesContext.getCurrentInstance(), def.LabelId);
|
||||
}
|
||||
return buildSummary(
|
||||
new String[]{"Layout"},
|
||||
new String[]{label});
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
// Dashboard Wizard bean getters
|
||||
|
||||
/**
|
||||
* @return The currently selected layout ID - used by the Dynamic Description component
|
||||
*/
|
||||
public String getLayout()
|
||||
{
|
||||
return this.layout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the currently selected layout ID
|
||||
*/
|
||||
public void setLayout(String layout)
|
||||
{
|
||||
this.layout = layout;
|
||||
LayoutDefinition def = DashboardManager.getDashboardConfig().getLayoutDefinition(layout);
|
||||
this.editConfig.getCurrentPage().setLayoutDefinition(def);
|
||||
if (this.column >= def.Columns)
|
||||
{
|
||||
this.column = def.Columns - 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the number of columns in the selected page layout
|
||||
*/
|
||||
public int getColumnCount()
|
||||
{
|
||||
return DashboardManager.getDashboardConfig().getLayoutDefinition(getLayout()).Columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the number of components per column supported in the selected page layout
|
||||
*/
|
||||
public int getColumnMax()
|
||||
{
|
||||
return DashboardManager.getDashboardConfig().getLayoutDefinition(getLayout()).ColumnLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the array of UI select items representing the columns that can be configured
|
||||
*/
|
||||
public SelectItem[] getColumns()
|
||||
{
|
||||
FacesContext fc = FacesContext.getCurrentInstance();
|
||||
LayoutDefinition layoutDef = DashboardManager.getDashboardConfig().getLayoutDefinition(getLayout());
|
||||
SelectItem[] columns = new SelectItem[layoutDef.Columns];
|
||||
for (int i=0; i<layoutDef.Columns; i++)
|
||||
{
|
||||
String label = Application.getMessage(fc, MSG_COLUMN) + " " + Integer.toString(i + 1);
|
||||
columns[i] = new SelectItem(i, label);
|
||||
}
|
||||
return columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the index of the column being edited in the columns wizard page
|
||||
*/
|
||||
public int getColumn()
|
||||
{
|
||||
return this.column;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the index of the column being edited in the columns wizard page. This value is
|
||||
* set when the Columns drop-down value is changed by the user.
|
||||
*
|
||||
* @param column Column index
|
||||
*/
|
||||
public void setColumn(int column)
|
||||
{
|
||||
if (column != this.column)
|
||||
{
|
||||
// setting this value will cause various List getters to return
|
||||
// different values on the next page refresh
|
||||
this.column = column;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The SelectItem List of all available dashlets
|
||||
*/
|
||||
public List<SelectItem> getAllDashlets()
|
||||
{
|
||||
if (this.dashlets == null)
|
||||
{
|
||||
FacesContext fc = FacesContext.getCurrentInstance();
|
||||
DashboardsConfigElement config = DashboardManager.getDashboardConfig();
|
||||
Collection<DashletDefinition> dashletDefs = config.getDashlets();
|
||||
List<SelectItem> dashlets = new ArrayList<SelectItem>(dashletDefs.size());
|
||||
for (DashletDefinition dashletDef : dashletDefs)
|
||||
{
|
||||
String label = dashletDef.Label;
|
||||
if (label == null)
|
||||
{
|
||||
label = Application.getMessage(fc, dashletDef.LabelId);
|
||||
}
|
||||
String description = dashletDef.Description;
|
||||
if (description == null)
|
||||
{
|
||||
description = Application.getMessage(fc, dashletDef.DescriptionId);
|
||||
}
|
||||
if (description != null)
|
||||
{
|
||||
// append description of the dashlet if set
|
||||
label = label + " (" + description + ')';
|
||||
}
|
||||
SelectItem item = new SelectItem(dashletDef.Id, label);
|
||||
dashlets.add(item);
|
||||
}
|
||||
this.dashlets = dashlets;
|
||||
}
|
||||
return this.dashlets;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the List of SelectItem objects representing the dashlets displayed in the
|
||||
* currently selected column.
|
||||
*/
|
||||
public List<SelectItem> getColumnDashlets()
|
||||
{
|
||||
FacesContext fc = FacesContext.getCurrentInstance();
|
||||
|
||||
Column column = this.editConfig.getCurrentPage().getColumns().get(this.column);
|
||||
List<SelectItem> dashlets = new ArrayList<SelectItem>(column.getDashlets().size());
|
||||
for (DashletDefinition dashletDef : column.getDashlets())
|
||||
{
|
||||
String label = dashletDef.Label;
|
||||
if (label == null)
|
||||
{
|
||||
label = Application.getMessage(fc, dashletDef.LabelId);
|
||||
}
|
||||
dashlets.add(new SelectItem(dashletDef.Id, label));
|
||||
}
|
||||
return dashlets;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return List of UIDescription objects for the available layouts
|
||||
*/
|
||||
public List<UIDescription> getLayoutDescriptions()
|
||||
{
|
||||
if (this.layoutDescriptions == null)
|
||||
{
|
||||
buildLayoutValueLists();
|
||||
}
|
||||
return this.layoutDescriptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the List of UIListItem objects representing the Layout icons
|
||||
*/
|
||||
public List<UIListItem> getLayoutIcons()
|
||||
{
|
||||
if (this.layoutIcons == null)
|
||||
{
|
||||
buildLayoutValueLists();
|
||||
}
|
||||
return this.layoutIcons;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the cached list of values for the layout page. The lists are used by the
|
||||
* image radio picker and dynamic description components.
|
||||
*/
|
||||
private void buildLayoutValueLists()
|
||||
{
|
||||
List<UIListItem> icons = new ArrayList<UIListItem>(4);
|
||||
List<UIDescription> descriptions = new ArrayList<UIDescription>(4);
|
||||
|
||||
FacesContext context = FacesContext.getCurrentInstance();
|
||||
|
||||
DashboardsConfigElement config = DashboardManager.getDashboardConfig();
|
||||
Iterator<LayoutDefinition> layoutItr = config.getLayouts().iterator();
|
||||
while (layoutItr.hasNext())
|
||||
{
|
||||
LayoutDefinition layoutDef = layoutItr.next();
|
||||
|
||||
// build UIListItem to represent the layout image
|
||||
String label = layoutDef.Label;
|
||||
if (label == null)
|
||||
{
|
||||
label = Application.getMessage(context, layoutDef.LabelId);
|
||||
}
|
||||
String desc = layoutDef.Description;
|
||||
if (desc == null)
|
||||
{
|
||||
desc = Application.getMessage(context, layoutDef.DescriptionId);
|
||||
}
|
||||
UIListItem item = new UIListItem();
|
||||
item.setLabel(label);
|
||||
item.setTooltip(desc);
|
||||
item.setValue(layoutDef.Id);
|
||||
// set the special attribute used by the imageRadioPicker component
|
||||
item.getAttributes().put("image", layoutDef.Image);
|
||||
icons.add(item);
|
||||
|
||||
// build UIDescription to represent the layout description text
|
||||
UIDescription description = new UIDescription();
|
||||
description.setControlValue(layoutDef.Id);
|
||||
description.setText(desc);
|
||||
descriptions.add(description);
|
||||
}
|
||||
|
||||
this.layoutIcons = icons;
|
||||
this.layoutDescriptions = descriptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Action event handler called to Add dashlets to the selection for a column
|
||||
*/
|
||||
public void addDashlets(ActionEvent event)
|
||||
{
|
||||
UISelectMany dashletPicker = (UISelectMany)event.getComponent().findComponent(COMPONENT_ALLDASHLETS);
|
||||
UISelectOne dashletColumn = (UISelectOne)event.getComponent().findComponent(COMPONENT_COLUMNDASHLETS);
|
||||
|
||||
// get the IDs of the selected Dashlet definitions
|
||||
Object[] selected = dashletPicker.getSelectedValues();
|
||||
|
||||
if (selected.length != 0)
|
||||
{
|
||||
// get the column to add the dashlets too
|
||||
DashboardsConfigElement config = DashboardManager.getDashboardConfig();
|
||||
LayoutDefinition layoutDef = this.editConfig.getCurrentPage().getLayoutDefinition();
|
||||
Column column = this.editConfig.getCurrentPage().getColumns().get(this.column);
|
||||
|
||||
// add each selected dashlet to the column
|
||||
for (int i=0; i<selected.length && column.getDashlets().size() < layoutDef.ColumnLength; i++)
|
||||
{
|
||||
String dashletId = (String)selected[i];
|
||||
|
||||
// don't add if already present in the list
|
||||
boolean found = false;
|
||||
for (int x=0; x<column.getDashlets().size(); x++)
|
||||
{
|
||||
if (column.getDashlets().get(x).Id.equals(dashletId))
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found == false)
|
||||
{
|
||||
column.addDashlet(config.getDashletDefinition(dashletId));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Action handler called to Remove a dashlet from the selection for a column
|
||||
*/
|
||||
public void removeDashlet(ActionEvent event)
|
||||
{
|
||||
UISelectOne dashletColumn = (UISelectOne)event.getComponent().findComponent(COMPONENT_COLUMNDASHLETS);
|
||||
|
||||
// get the ID of the selected Dashlet definition
|
||||
String dashletId = (String)dashletColumn.getValue();
|
||||
if (dashletId != null)
|
||||
{
|
||||
Column column = this.editConfig.getCurrentPage().getColumns().get(this.column);
|
||||
|
||||
// remove the selected dashlet from the column
|
||||
for (int i=0; i<column.getDashlets().size(); i++)
|
||||
{
|
||||
if (column.getDashlets().get(i).Id.equals(dashletId))
|
||||
{
|
||||
column.getDashlets().remove(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Action event called to move a dashlet up the column list
|
||||
*/
|
||||
public void dashletUp(ActionEvent event)
|
||||
{
|
||||
UISelectOne dashletColumn = (UISelectOne)event.getComponent().findComponent(COMPONENT_COLUMNDASHLETS);
|
||||
|
||||
// get the ID of the selected Dashlet definition
|
||||
String dashletId = (String)dashletColumn.getValue();
|
||||
if (dashletId != null)
|
||||
{
|
||||
Column column = this.editConfig.getCurrentPage().getColumns().get(this.column);
|
||||
|
||||
// find the dashlet in the list
|
||||
for (int i=0; i<column.getDashlets().size(); i++)
|
||||
{
|
||||
if (column.getDashlets().get(i).Id.equals(dashletId))
|
||||
{
|
||||
if (i != 0)
|
||||
{
|
||||
DashletDefinition dashletDef = column.getDashlets().get(i);
|
||||
column.getDashlets().remove(i);
|
||||
column.getDashlets().add(i - 1, dashletDef);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Action event called to move a dashlet down the column list
|
||||
*/
|
||||
public void dashletDown(ActionEvent event)
|
||||
{
|
||||
UISelectOne dashletColumn = (UISelectOne)event.getComponent().findComponent(COMPONENT_COLUMNDASHLETS);
|
||||
|
||||
// get the ID of the selected Dashlet definition
|
||||
String dashletId = (String)dashletColumn.getValue();
|
||||
if (dashletId != null)
|
||||
{
|
||||
Column column = this.editConfig.getCurrentPage().getColumns().get(this.column);
|
||||
|
||||
// find the dashlet in the list
|
||||
for (int i=0; i<column.getDashlets().size(); i++)
|
||||
{
|
||||
if (column.getDashlets().get(i).Id.equals(dashletId))
|
||||
{
|
||||
if (i != column.getDashlets().size() - 1)
|
||||
{
|
||||
DashletDefinition dashletDef = column.getDashlets().get(i);
|
||||
column.getDashlets().remove(i);
|
||||
if (i + 1 < column.getDashlets().size())
|
||||
{
|
||||
column.getDashlets().add(i + 1, dashletDef);
|
||||
}
|
||||
else
|
||||
{
|
||||
column.getDashlets().add(dashletDef);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
381
source/java/org/alfresco/web/bean/dashboard/PageConfig.java
Normal file
381
source/java/org/alfresco/web/bean/dashboard/PageConfig.java
Normal file
@@ -0,0 +1,381 @@
|
||||
/*
|
||||
* 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.bean.dashboard;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.web.config.DashboardsConfigElement;
|
||||
import org.alfresco.web.config.DashboardsConfigElement.DashletDefinition;
|
||||
import org.alfresco.web.config.DashboardsConfigElement.LayoutDefinition;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.DocumentException;
|
||||
import org.dom4j.DocumentHelper;
|
||||
import org.dom4j.Element;
|
||||
import org.dom4j.io.OutputFormat;
|
||||
import org.dom4j.io.SAXReader;
|
||||
import org.dom4j.io.XMLWriter;
|
||||
|
||||
/**
|
||||
* Describes the config for the Pages in a user Dashboard.
|
||||
* Multiple Pages are supported.
|
||||
*
|
||||
* @author Kevin Roast
|
||||
*/
|
||||
final class PageConfig
|
||||
{
|
||||
private static Log logger = LogFactory.getLog(DashboardManager.class);
|
||||
|
||||
private static final String ELEMENT_DASHBOARD = "dashboard";
|
||||
private static final String ELEMENT_PAGE = "page";
|
||||
private static final String ELEMENT_COLUMN = "column";
|
||||
private static final String ELEMENT_DASHLET = "dashlet";
|
||||
private static final String ATTR_ID = "id";
|
||||
private static final String ATTR_LAYOUTID = "layout-id";
|
||||
private static final String ATTR_REFID = "idref";
|
||||
|
||||
private List<Page> pages = new ArrayList<Page>(4);
|
||||
private int currentPageIndex = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
public PageConfig()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy constructor
|
||||
*
|
||||
* @param copy PageConfig to copy
|
||||
*/
|
||||
public PageConfig(PageConfig copy)
|
||||
{
|
||||
this.pages = new ArrayList<Page>(copy.pages.size());
|
||||
for (Page page : copy.pages)
|
||||
{
|
||||
// invoke the copy constructor on each Page
|
||||
// which in turn calls the copy constructor of child classes
|
||||
this.pages.add(new Page(page));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The current page in the config
|
||||
*/
|
||||
public Page getCurrentPage()
|
||||
{
|
||||
if (currentPageIndex < pages.size())
|
||||
{
|
||||
return pages.get(currentPageIndex);
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new Page to the list
|
||||
*
|
||||
* @param page Page to add
|
||||
*/
|
||||
public void addPage(Page page)
|
||||
{
|
||||
pages.add(page);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a Page with the specified page Id
|
||||
*
|
||||
* @param pageId Of the page to return
|
||||
*
|
||||
* @return Page or null if not found
|
||||
*/
|
||||
public Page getPage(String pageId)
|
||||
{
|
||||
Page foundPage = null;
|
||||
for (Page page : pages)
|
||||
{
|
||||
if (page.getId().equals(pageId))
|
||||
{
|
||||
foundPage = page;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return foundPage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert this config to an XML definition which can be serialized.
|
||||
* Example:
|
||||
* <code>
|
||||
* <?xml version="1.0"?>
|
||||
* <dashboard>
|
||||
* <page id="main" layout-id="narrow-left-2column">
|
||||
* <column>
|
||||
* <dashlet idref="clock" />
|
||||
* <dashlet idref="random-joke" />
|
||||
* </column>
|
||||
* <column>
|
||||
* <dashlet idref="getting-started" />
|
||||
* <dashlet idref="task-list" />
|
||||
* <dashlet idref="my-checkedout-docs" />
|
||||
* <dashlet idref="my-documents" />
|
||||
* </column>
|
||||
* </page>
|
||||
* </dashboard>
|
||||
* </code>
|
||||
*
|
||||
* @return XML for this config
|
||||
*/
|
||||
public String toXML()
|
||||
{
|
||||
try
|
||||
{
|
||||
Document doc = DocumentHelper.createDocument();
|
||||
|
||||
Element root = doc.addElement(ELEMENT_DASHBOARD);
|
||||
for (Page page : pages)
|
||||
{
|
||||
Element pageElement = root.addElement(ELEMENT_PAGE);
|
||||
pageElement.addAttribute(ATTR_ID, page.getId());
|
||||
pageElement.addAttribute(ATTR_LAYOUTID, page.getLayoutDefinition().Id);
|
||||
for (Column column : page.getColumns())
|
||||
{
|
||||
Element columnElement = pageElement.addElement(ELEMENT_COLUMN);
|
||||
for (DashletDefinition dashletDef : column.getDashlets())
|
||||
{
|
||||
columnElement.addElement(ELEMENT_DASHLET).addAttribute(ATTR_REFID, dashletDef.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
StringWriter out = new StringWriter(512);
|
||||
XMLWriter writer = new XMLWriter(OutputFormat.createPrettyPrint());
|
||||
writer.setWriter(out);
|
||||
writer.write(doc);
|
||||
|
||||
return out.toString();
|
||||
}
|
||||
catch (Throwable err)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Unable to serialize Dashboard PageConfig to XML: " + err.getMessage(), err);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return toXML();
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserialise this PageConfig instance from the specified XML stream.
|
||||
*
|
||||
* @param xml
|
||||
*/
|
||||
public void fromXML(DashboardsConfigElement config, String xml)
|
||||
{
|
||||
try
|
||||
{
|
||||
SAXReader reader = new SAXReader();
|
||||
Document document = reader.read(new StringReader(xml));
|
||||
Element rootElement = document.getRootElement();
|
||||
|
||||
// walk the pages found in xml
|
||||
Iterator itrPages = rootElement.elementIterator(ELEMENT_PAGE);
|
||||
while (itrPages.hasNext())
|
||||
{
|
||||
Element pageElement = (Element)itrPages.next();
|
||||
String layoutId = pageElement.attributeValue(ATTR_LAYOUTID);
|
||||
LayoutDefinition layoutDef = config.getLayoutDefinition(layoutId);
|
||||
if (layoutDef != null)
|
||||
{
|
||||
// found the layout now build the page and read the columns
|
||||
Page page = new Page(pageElement.attributeValue(ATTR_ID), layoutDef);
|
||||
Iterator itrColumns = pageElement.elementIterator(ELEMENT_COLUMN);
|
||||
while (itrColumns.hasNext())
|
||||
{
|
||||
Column column = new Column();
|
||||
|
||||
// read and resolve the dashlet definitions for this column
|
||||
Element columnElement = (Element)itrColumns.next();
|
||||
Iterator itrDashlets = columnElement.elementIterator(ELEMENT_DASHLET);
|
||||
while (itrDashlets.hasNext())
|
||||
{
|
||||
String dashletId = ((Element)itrDashlets.next()).attributeValue(ATTR_REFID);
|
||||
DashletDefinition dashletDef = config.getDashletDefinition(dashletId);
|
||||
if (dashletDef != null)
|
||||
{
|
||||
column.addDashlet(dashletDef);
|
||||
}
|
||||
else if (logger.isWarnEnabled())
|
||||
{
|
||||
logger.warn("Failed to resolve Dashboard Dashlet Definition ID: " + dashletId);
|
||||
}
|
||||
}
|
||||
|
||||
// add the column of dashlets to the page
|
||||
page.addColumn(column);
|
||||
}
|
||||
|
||||
// add the page to this config instance
|
||||
this.addPage(page);
|
||||
}
|
||||
else if (logger.isWarnEnabled())
|
||||
{
|
||||
logger.warn("Failed to resolve Dashboard Layout Definition ID: " + layoutId);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (DocumentException docErr)
|
||||
{
|
||||
// if we cannot parse, then we simply revert to default
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple class to represent a Page in a Dashboard.
|
||||
* Each Page has a Layout associated with it, and a number of Column definitions.
|
||||
*/
|
||||
final class Page
|
||||
{
|
||||
private String id;
|
||||
private LayoutDefinition layoutDef;
|
||||
private List<Column> columns = new ArrayList<Column>(4);
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param id
|
||||
* @param layout
|
||||
*/
|
||||
public Page(String id, LayoutDefinition layout)
|
||||
{
|
||||
if (id == null || id.length() == 0)
|
||||
{
|
||||
throw new IllegalArgumentException("ID for a Dashboard Page is mandatory.");
|
||||
}
|
||||
if (layout == null)
|
||||
{
|
||||
throw new IllegalArgumentException("Layout for a Dashboard Page is mandatory.");
|
||||
}
|
||||
this.id = id;
|
||||
this.layoutDef = layout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy Constructor
|
||||
*
|
||||
* @param copy Page to build a copy from
|
||||
*/
|
||||
public Page(Page copy)
|
||||
{
|
||||
this.id = copy.id;
|
||||
this.layoutDef = copy.layoutDef;
|
||||
for (Column column : copy.columns)
|
||||
{
|
||||
Column cloneColumn = new Column(column);
|
||||
addColumn(cloneColumn);
|
||||
}
|
||||
}
|
||||
|
||||
public String getId()
|
||||
{
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public LayoutDefinition getLayoutDefinition()
|
||||
{
|
||||
return this.layoutDef;
|
||||
}
|
||||
|
||||
public void setLayoutDefinition(LayoutDefinition layout)
|
||||
{
|
||||
if (layout == null)
|
||||
{
|
||||
throw new IllegalArgumentException("Layout for a Dashboard Page is mandatory.");
|
||||
}
|
||||
|
||||
// correct column collection based on new layout definition
|
||||
while (this.columns.size() < layout.Columns)
|
||||
{
|
||||
addColumn(new Column());
|
||||
}
|
||||
if (this.columns.size() > layout.Columns)
|
||||
{
|
||||
this.columns = this.columns.subList(0, layout.Columns);
|
||||
}
|
||||
|
||||
this.layoutDef = layout;
|
||||
}
|
||||
|
||||
public void addColumn(Column column)
|
||||
{
|
||||
this.columns.add(column);
|
||||
}
|
||||
|
||||
public List<Column> getColumns()
|
||||
{
|
||||
return this.columns;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple class representing a single Column in a dashboard Page.
|
||||
* Each column contains a list of Dashlet definitions.
|
||||
*/
|
||||
final class Column
|
||||
{
|
||||
private List<DashletDefinition> dashlets = new ArrayList<DashletDefinition>(4);
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
public Column()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy constructor
|
||||
*
|
||||
* @param copy Column to copy
|
||||
*/
|
||||
public Column(Column copy)
|
||||
{
|
||||
this.dashlets = (List<DashletDefinition>)((ArrayList<DashletDefinition>)copy.dashlets).clone();
|
||||
}
|
||||
|
||||
public void addDashlet(DashletDefinition dashlet)
|
||||
{
|
||||
dashlets.add(dashlet);
|
||||
}
|
||||
|
||||
public List<DashletDefinition> getDashlets()
|
||||
{
|
||||
return this.dashlets;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user