Search in sources :

Example 1 with DashletDefinition

use of org.alfresco.web.config.DashboardsConfigElement.DashletDefinition in project acs-community-packaging by Alfresco.

the class DashboardManager method getDashletDefinitionByIndex.

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

Example 2 with DashletDefinition

use of org.alfresco.web.config.DashboardsConfigElement.DashletDefinition in project acs-community-packaging by Alfresco.

the class DashboardManager method getPageConfig.

/**
 * @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();
                // add the default dashlet(s) to the column as specified in the config
                if (config.getDefaultDashlets() != null) {
                    for (String id : config.getDefaultDashlets()) {
                        DashletDefinition dashlet = config.getDashletDefinition(id);
                        if (dashlet != null) {
                            defaultColumn.addDashlet(dashlet);
                        }
                    }
                }
                // add the column to the page and we are done
                page.addColumn(defaultColumn);
                pageConfig.addPage(page);
            }
        }
        this.pageConfig = pageConfig;
    }
    return this.pageConfig;
}
Also used : DashboardsConfigElement(org.alfresco.web.config.DashboardsConfigElement) DashletDefinition(org.alfresco.web.config.DashboardsConfigElement.DashletDefinition) LayoutDefinition(org.alfresco.web.config.DashboardsConfigElement.LayoutDefinition)

Example 3 with DashletDefinition

use of org.alfresco.web.config.DashboardsConfigElement.DashletDefinition in project acs-community-packaging by Alfresco.

the class DashboardWizard method getAllDashlets.

/**
 * @return The SelectItem List of all available dashlets
 */
public List<SelectItem> getAllDashlets() {
    if ((this.dashlets == null) || (Application.isDynamicConfig(FacesContext.getCurrentInstance()))) {
        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;
}
Also used : FacesContext(javax.faces.context.FacesContext) SelectItem(javax.faces.model.SelectItem) ArrayList(java.util.ArrayList) DashboardsConfigElement(org.alfresco.web.config.DashboardsConfigElement) DashletDefinition(org.alfresco.web.config.DashboardsConfigElement.DashletDefinition)

Example 4 with DashletDefinition

use of org.alfresco.web.config.DashboardsConfigElement.DashletDefinition in project acs-community-packaging by Alfresco.

the class DashboardWizard method dashletDown.

/**
 * 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;
            }
        }
    }
}
Also used : DashletDefinition(org.alfresco.web.config.DashboardsConfigElement.DashletDefinition) UISelectOne(javax.faces.component.UISelectOne)

Example 5 with DashletDefinition

use of org.alfresco.web.config.DashboardsConfigElement.DashletDefinition in project acs-community-packaging by Alfresco.

the class DashboardWizard method dashletUp.

/**
 * 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;
            }
        }
    }
}
Also used : DashletDefinition(org.alfresco.web.config.DashboardsConfigElement.DashletDefinition) UISelectOne(javax.faces.component.UISelectOne)

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