Search in sources :

Example 6 with DashletDefinition

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;
}
Also used : FacesContext(javax.faces.context.FacesContext) SelectItem(javax.faces.model.SelectItem) ArrayList(java.util.ArrayList) DashletDefinition(org.alfresco.web.config.DashboardsConfigElement.DashletDefinition) LayoutDefinition(org.alfresco.web.config.DashboardsConfigElement.LayoutDefinition)

Example 7 with DashletDefinition

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);
    }
}
Also used : StringWriter(java.io.StringWriter) Element(org.dom4j.Element) DashboardsConfigElement(org.alfresco.web.config.DashboardsConfigElement) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) DashletDefinition(org.alfresco.web.config.DashboardsConfigElement.DashletDefinition) Document(org.dom4j.Document) XMLWriter(org.dom4j.io.XMLWriter)

Example 8 with DashletDefinition

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;
}
Also used : ConfigException(org.springframework.extensions.config.ConfigException) DashletDefinition(org.alfresco.web.config.DashboardsConfigElement.DashletDefinition)

Example 9 with DashletDefinition

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;
}
Also used : DashletDefinition(org.alfresco.web.config.DashboardsConfigElement.DashletDefinition)

Example 10 with DashletDefinition

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
    }
}
Also used : SAXReader(org.dom4j.io.SAXReader) Element(org.dom4j.Element) DashboardsConfigElement(org.alfresco.web.config.DashboardsConfigElement) DocumentException(org.dom4j.DocumentException) StringReader(java.io.StringReader) Iterator(java.util.Iterator) DashletDefinition(org.alfresco.web.config.DashboardsConfigElement.DashletDefinition) Document(org.dom4j.Document) LayoutDefinition(org.alfresco.web.config.DashboardsConfigElement.LayoutDefinition)

Aggregations

DashletDefinition (org.alfresco.web.config.DashboardsConfigElement.DashletDefinition)11 LayoutDefinition (org.alfresco.web.config.DashboardsConfigElement.LayoutDefinition)5 DashboardsConfigElement (org.alfresco.web.config.DashboardsConfigElement)4 Element (org.dom4j.Element)3 ArrayList (java.util.ArrayList)2 UISelectOne (javax.faces.component.UISelectOne)2 FacesContext (javax.faces.context.FacesContext)2 SelectItem (javax.faces.model.SelectItem)2 Document (org.dom4j.Document)2 ConfigException (org.springframework.extensions.config.ConfigException)2 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 Iterator (java.util.Iterator)1 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)1 DocumentException (org.dom4j.DocumentException)1 SAXReader (org.dom4j.io.SAXReader)1 XMLWriter (org.dom4j.io.XMLWriter)1 ConfigElement (org.springframework.extensions.config.ConfigElement)1