Subversion Repository Public Repository

litesoft

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package com.temp.client.foundation.widget.table.column;

import com.temp.client.foundation.widget.table.DataRow;
import com.temp.client.foundation.widget.table.cell.CellDecorator;
import com.temp.client.foundation.widget.table.cell.CellDecoratorAccessor;
import com.temp.client.foundation.widget.table.cell.TextDataCell;
import com.temp.shared.utils.ObjectUtils;

import com.google.gwt.cell.client.Cell.Context;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.user.cellview.client.Column;

public class TextDataColumn<R extends DataRow<F>, F> extends Column<R, String> implements DataColumn {

    private F field;
    private CellDecorator<R> cellDecorator;

    public TextDataColumn(F field) {
        this(field, false, false);
    }

    public TextDataColumn(F field, boolean isSortable) {
        this(field, isSortable, false);
    }

    public TextDataColumn(F field, boolean isSortable, boolean isNumeric) {
        //super(new TextCell());
        super(new TextDataCell<String>());
        this.field = field;
        setSortable(isSortable);
        if (isNumeric) {
            setHorizontalAlignment(ALIGN_RIGHT);
        }
        if (field instanceof CellDecorator) {
            cellDecorator = ObjectUtils.cast(field);
        }
        if (field instanceof CellDecoratorAccessor) {
            CellDecoratorAccessor<R> accessor = ObjectUtils.cast(field);
            cellDecorator = accessor.getCellDecorator();
        }
    }

    @Override
    public String getFieldString() {
        return field.toString();
    }

    @Override
    public String getValue(R rowData) {
        return rowData.getNonNullValueString(field);
    }

    public void render(Context context, R object, SafeHtmlBuilder sb) {
        if (cellDecorator == null) {
            super.render(context, object, sb);
        } else {
            cellDecorator.prepend(context, object, sb);
            super.render(context, object, sb);
            cellDecorator.append(context, object, sb);
        }
    }
}

Commits for litesoft/trunk/GWT_Sandbox/FormEngine/src/com/temp/client/foundation/widget/table/column/TextDataColumn.java

Diff revisions: vs.
Revision Author Commited Message
626 GeorgeS picture GeorgeS Wed 11 Apr, 2012 19:39:41 +0000