Search in sources :

Example 1 with ClipboardItem

use of org.alfresco.web.bean.clipboard.ClipboardItem in project acs-community-packaging by Alfresco.

the class UIClipboardShelfItem method encodeBegin.

/**
 * @see javax.faces.component.UIComponentBase#encodeBegin(javax.faces.context.FacesContext)
 */
public void encodeBegin(FacesContext context) throws IOException {
    if (isRendered() == false) {
        return;
    }
    ResponseWriter out = context.getResponseWriter();
    List<ClipboardItem> items = getCollections();
    out.write(SHELF_START);
    if (items.size() != 0) {
        DictionaryService dd = Repository.getServiceRegistry(context).getDictionaryService();
        NodeService nodeService = Repository.getServiceRegistry(context).getNodeService();
        ResourceBundle bundle = Application.getBundle(context);
        for (int i = 0; i < items.size(); i++) {
            ClipboardItem item = items.get(i);
            // check that the item has not been deleted since added to the clipboard
            if (nodeService.exists(item.getNodeRef()) == false) {
                // remove from clipboard
                items.remove(i--);
                continue;
            }
            // start row with cut/copy state icon
            out.write("<tr><td width=16>");
            if (item.getMode() == ClipboardStatus.COPY) {
                out.write(Utils.buildImageTag(context, WebResources.IMAGE_COPY, 14, 16, bundle.getString(MSG_COPY), null, "absmiddle"));
            } else {
                out.write(Utils.buildImageTag(context, WebResources.IMAGE_CUT, 13, 16, bundle.getString(MSG_CUT), null, "absmiddle"));
            }
            out.write("</td><td width=16>");
            boolean isFolder = (dd.isSubClass(item.getType(), ContentModel.TYPE_FOLDER));
            if (isFolder) {
                // start row with correct node icon
                String icon = (String) item.getIcon();
                if (icon != null) {
                    icon = "/images/icons/" + icon + "-16.gif";
                } else {
                    icon = WebResources.IMAGE_SPACE;
                }
                out.write(Utils.buildImageTag(context, icon, 16, 16, null, null, "absmiddle"));
            } else {
                String image = FileTypeImageUtils.getFileTypeImage(item.getName(), true);
                out.write(Utils.buildImageTag(context, image, null, "absmiddle"));
            }
            // output cropped item label - we also output with no breaks, this is ok
            // as the copped label will ensure a sensible maximum width
            out.write("</td><td width=100%><nobr>&nbsp;");
            if (isFolder) {
                out.write(Utils.cropEncode(item.getName()));
            } else {
                // output as a content download link
                out.write("<a href='");
                out.write(context.getExternalContext().getRequestContextPath());
                out.write(generateBrowserURL(dd, nodeService, item));
                out.write("' target='new'>");
                out.write(Utils.cropEncode(item.getName()));
                out.write("</a>");
            }
            // output actions
            out.write("</nobr></td><td align=right><nobr>");
            out.write(buildActionLink(ACTION_REMOVE_ITEM, i, bundle.getString(MSG_REMOVE_ITEM), WebResources.IMAGE_REMOVE));
            out.write("&nbsp;");
            out.write(buildActionLink(ACTION_PASTE_ITEM, i, bundle.getString(MSG_PASTE_ITEM), WebResources.IMAGE_PASTE));
            if (item.supportsLink() && item.getMode() == ClipboardStatus.COPY && dd.isSubClass(item.getType(), ContentModel.TYPE_LINK) == false) {
                out.write("&nbsp;");
                out.write(buildActionLink(ACTION_PASTE_LINK, i, bundle.getString(MSG_PASTE_LINK), WebResources.IMAGE_PASTE_LINK));
            }
            // end actions cell and end row
            out.write("</nobr></td></tr>");
        }
        // output general actions if any clipboard items are present
        out.write("<tr><td colspan=4 style='padding-top:3px' align='center'><nobr>");
        out.write(buildActionLink(ACTION_PASTE_ALL, -1, bundle.getString(MSG_PASTE_ALL), null));
        out.write("&nbsp;|&nbsp;");
        out.write(buildActionLink(ACTION_REMOVE_ALL, -1, bundle.getString(MSG_REMOVE_ALL), null));
        out.write("</nobr></td><td></td></tr>");
    }
    out.write(SHELF_END);
}
Also used : ClipboardItem(org.alfresco.web.bean.clipboard.ClipboardItem) DictionaryService(org.alfresco.service.cmr.dictionary.DictionaryService) ResponseWriter(javax.faces.context.ResponseWriter) NodeService(org.alfresco.service.cmr.repository.NodeService) ResourceBundle(java.util.ResourceBundle)

Aggregations

ResourceBundle (java.util.ResourceBundle)1 ResponseWriter (javax.faces.context.ResponseWriter)1 DictionaryService (org.alfresco.service.cmr.dictionary.DictionaryService)1 NodeService (org.alfresco.service.cmr.repository.NodeService)1 ClipboardItem (org.alfresco.web.bean.clipboard.ClipboardItem)1