use of org.alfresco.web.config.DashboardsConfigElement.DashletDefinition in project acs-community-packaging by Alfresco.
the class DashboardWizard method getColumnDashlets.
/**
* @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);
// trim the max number of dashlets for this column
LayoutDefinition layoutDef = this.editConfig.getCurrentPage().getLayoutDefinition();
column.trimDashlets(layoutDef.ColumnLength);
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;
}
use of org.alfresco.web.config.DashboardsConfigElement.DashletDefinition in project acs-community-packaging by Alfresco.
the class Column method toXML.
/**
* 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);
}
}
use of org.alfresco.web.config.DashboardsConfigElement.DashletDefinition in project acs-community-packaging by Alfresco.
the class DashboardsElementReader method parseDashletDefinition.
/**
* Parse a single Dashlet definition from config.
*
* @param config Element
*
* @return DashletDefinition for the specified config element.
*/
private static DashletDefinition parseDashletDefinition(Element config) {
String id = getMandatoryDashletAttributeValue(config, ATTR_ID);
DashletDefinition def = new DashletDefinition(id);
String allowNarrow = config.attributeValue(ATTR_ALLOWNARROW);
if (allowNarrow != null && allowNarrow.length() != 0) {
def.AllowNarrow = Boolean.parseBoolean(allowNarrow);
}
def.JSPPage = getMandatoryDashletAttributeValue(config, ATTR_JSP);
def.ConfigJSPPage = config.attributeValue(ATTR_CONFIGJSP);
String label = config.attributeValue(ATTR_LABEL);
String labelId = config.attributeValue(ATTR_LABELID);
if ((label == null || label.length() == 0) && (labelId == null || labelId.length() == 0)) {
throw new ConfigException("Either 'label' or 'label-id' attribute must be specified for Dashboard 'dashlet' configuration element.");
}
def.Label = label;
def.LabelId = labelId;
String description = config.attributeValue(ATTR_DESCRIPTION);
String descriptionId = config.attributeValue(ATTR_DESCRIPTIONID);
if ((description == null || description.length() == 0) && (descriptionId == null || descriptionId.length() == 0)) {
throw new ConfigException("Either 'description' or 'description-id' attribute must be specified for Dashboard 'dashlet' configuration element.");
}
def.Description = description;
def.DescriptionId = descriptionId;
return def;
}
use of org.alfresco.web.config.DashboardsConfigElement.DashletDefinition in project acs-community-packaging by Alfresco.
the class DashboardManager method getDashletPage.
/**
* 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;
}
use of org.alfresco.web.config.DashboardsConfigElement.DashletDefinition in project acs-community-packaging by Alfresco.
the class Column method fromXML.
/**
* 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
}
}
Aggregations