【问题标题】:Add Icon in a Column of CellTable in GWT在 GWT 的 CellTable 列中添加图标
【发布时间】:2012-05-03 17:21:50
【问题描述】:

文本列中的所有值。

我想添加图片单元格。

我不想使用 Gwt-Ext 或 Smart 客户端。

我的代码

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.

我想添加到图像单元格。怎么做。


已编辑

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);
            }

        };

在 FDocument 类中

public String getImageUrl(FilenetDocument 对象){

            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)";
                    }

                }

            }
        }
    }

【问题讨论】:

    标签: gwt gwt2 uibinder


    【解决方案1】:

    重写render 方法,该方法可用于将任何类型的HTML 内容添加为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>"); 
    
            }
           }    
        };  
    

    【讨论】:

    • 有很多像pdf doc这样的文件。他们各自的图标保存在war文件夹中。我能够显示除图标之外的所有文档值。我知道每个文档的 MIME 类型。请检查代码的编辑部分。
    • 我不知道渲染如何帮助我制作图标。并且返回是“”;以及何时调用渲染。
    【解决方案2】:

    在您的函数getImageUrl() 中,返回的是css 样式,而不是图像的路径...

    所以要么实现一个新的 Cell 以您提供的样式呈现,或者使用 ImageResourceCell 与您的静态图标,或者尝试 Hardik Mishra 提供的呈现方法,但更新 getImageUrl() 以返回图像的路径.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-19
      • 2012-02-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-05
      • 2023-03-23
      • 1970-01-01
      相关资源
      最近更新 更多