Add Icon in a Column of CellTable in GWT

别来无恙 提交于 2020-01-01 19:19:47

问题


With all the values in textcoloumn.

I want to add image cell.

I don't want use Gwt-Ext or Smart client.

My code

private CellTable<FDocument> getDocumentTable() {
        if (documentTable == null) {
            documentTable = new CellTable<FDocument>();
            documentTable.setSize("600px", "300px");
            documentTable.addColumn(nameColumnD, "NAME");
            documentTable.addColumn(sizeColumnD, "SIZE");
            documentTable.addColumn(modified_by_ColumnD, "MODIFIED BY");
            documentTable.addColumn(dateColumnD, "MODIFIED ON");
            documentTable.addColumn(majorVersion, "Major Version");


        }
        return documentTable;
    }

TextColumn<FDocument> nameColumnD = new TextColumn<FDocument>() {
            @Override
            public String getValue(FDocument object) {
                return object.getName();
            }
        };          
        TextColumn<FDocument> sizeColumnD = new TextColumn<FDocument>() {
            @Override
            public String getValue(FDocument object) {
                return object.getSize();                            
            }
        };

..// similarly all the coloumn.

I want to add to image Cell. How to do it.


edited

ImageCell imageCell=new ImageCell();
        Column<FDocument,String> iconColumn = new Column<FDocument, String>(imageCell){

            @Override
            public String getValue(FDocument object) {
                // TODO Auto-generated method stub
                return object.getImageUrl(object);
            }

        };

in FDocument Class

public String getImageUrl(FilenetDocument object){

            if(object.getMimeType().equals("text/plain")){
        return "url(Txt16.gif)";
    }else{
        if(object.getMimeType()=="application/x-filenet-publishtemplate"){
            return "url(PublishTemplate16.gif)";
        }else{
            if(object.getMimeType()=="application/x-filenet-filetype-msg"){
                return "url(Msg16.gif)";
            }else{
                if(object.getMimeType()=="application/x-filenet-workflowdefinition"){
                    return "url(WorkflowDefinition16.gif)";
                }else{
                    if(object.getMimeType()=="application/msword"){
                        return "url(Doc16.gif)";
                    }else{
                        return "url(Txt16.gif)";
                    }

                }

            }
        }
    }

回答1:


Override render method which can be used to add any type of HTML content as Column in CellTable

TextColumn<FDocument> iconColumn = new TextColumn<FDocument>() {
        @Override
        public String getValue(FDocument object) {
            return "";                          
        }

    @Override
        protected void render(Context context, SafeHtml value, SafeHtmlBuilder sb) {
        if (value != null) {
          sb.appendHtmlConstant("<p style=\"textalign:center;\"><img src=\"icon.gif\"\></p>"); 

        }
       }    
    };  



回答2:


In your function getImageUrl(), the return is a css style, not path to an image...

So either implement a new Cell which render with the style you provide, or use a ImageResourceCell with your static icons, or try the render method provided by Hardik Mishra but update getImageUrl() to return a PATH to an image.



来源:https://stackoverflow.com/questions/10415205/add-icon-in-a-column-of-celltable-in-gwt

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!