Search in sources :

Example 1 with IField

use of cn.cerc.jpage.core.IField in project summer-mis by cn-cerc.

the class DataGrid method outputGrid.

@Override
public void outputGrid(HtmlWriter html) {
    DataSet dataSet = this.getDataSet();
    MutiPage pages = this.getPages();
    double sumFieldWidth = 0;
    for (RowCell cell : this.getMasterLine().getOutputCells()) sumFieldWidth += cell.getFields().get(0).getWidth();
    if (sumFieldWidth < 0)
        throw new RuntimeException("总列宽不允许小于1");
    if (sumFieldWidth > MaxWidth)
        throw new RuntimeException("总列宽不允许大于600");
    html.print("<table class=\"%s\"", this.getCSSClass());
    if (this.getCSSStyle() != null)
        html.print(" style=\"%s\"", this.getCSSStyle());
    html.println(">");
    html.println("<tr>");
    for (RowCell cell : this.getMasterLine().getOutputCells()) {
        IField field = cell.getFields().get(0);
        html.print("<th");
        if (field.getWidth() == 0)
            html.print(" style=\"display:none\"");
        else {
            double val = roundTo(field.getWidth() / sumFieldWidth * 100, -2);
            html.print(" width=\"%f%%\"", val);
        }
        html.print("onclick=\"gridSort(this,'%s')\"", field.getField());
        html.print(">");
        html.print(field.getTitle());
        html.println("</th>");
    }
    html.println("</tr>");
    if (dataSet.size() > 0) {
        int i = pages.getBegin();
        while (i <= pages.getEnd()) {
            dataSet.setRecNo(i + 1);
            for (int lineNo = 0; lineNo < this.getLines().size(); lineNo++) {
                AbstractGridLine line = this.getLine(lineNo);
                if (line instanceof ExpenderGridLine)
                    line.getCell(0).setColSpan(this.getMasterLine().getFields().size());
                if (line instanceof ChildGridLine && this.beforeOutput != null)
                    beforeOutput.process(line);
                line.output(html, lineNo);
            }
            // 下一行
            i++;
        }
    }
    html.println("</table>");
    return;
}
Also used : ChildGridLine(cn.cerc.jpage.grid.lines.ChildGridLine) DataSet(cn.cerc.jdb.core.DataSet) ExpenderGridLine(cn.cerc.jpage.grid.lines.ExpenderGridLine) IField(cn.cerc.jpage.core.IField) AbstractGridLine(cn.cerc.jpage.grid.lines.AbstractGridLine)

Example 2 with IField

use of cn.cerc.jpage.core.IField in project summer-mis by cn-cerc.

the class ExpenderGridLine method output.

@Override
public void output(HtmlWriter html, int lineNo) {
    DataSet dataSet = dataSource.getDataSet();
    html.print("<tr");
    html.print(" id='%s_%s'", "tr" + dataSet.getRecNo(), lineNo);
    html.print(" role=\"%s\"", dataSet.getRecNo());
    if (!this.isVisible())
        html.print(" style=\"display:none\"");
    html.println(">");
    for (RowCell item : this.getCells()) {
        IField objField = item.getFields().get(0);
        html.print("<td");
        if (item.getColSpan() > 1)
            html.print(" colspan=\"%d\"", item.getColSpan());
        if (item.getStyle() != null)
            html.print(" style=\"%s\"", item.getStyle());
        if (item.getAlign() != null)
            html.print(" align=\"%s\"", item.getAlign());
        else if (objField.getAlign() != null)
            html.print(" align=\"%s\"", objField.getAlign());
        if (item.getRole() != null)
            html.print(" role=\"%s\"", item.getRole());
        html.print(">");
        for (IField obj : item.getFields()) {
            if (obj instanceof AbstractField) {
                AbstractField field = (AbstractField) obj;
                html.print("<span>");
                if (!"".equals(field.getName())) {
                    html.print(field.getName());
                    html.print(": ");
                }
                if (field instanceof IColumn)
                    html.print(((IColumn) field).format(dataSource.getDataSet().getCurrent()));
                else if (field instanceof AbstractField)
                    outputField(html, field);
                else
                    throw new RuntimeException("暂不支持的数据类型:" + field.getClass().getName());
                html.println("</span>");
            }
        }
        html.println("</td>");
    }
    html.println("</tr>");
}
Also used : AbstractField(cn.cerc.jpage.fields.AbstractField) DataSet(cn.cerc.jdb.core.DataSet) IColumn(cn.cerc.jpage.core.IColumn) RowCell(cn.cerc.jpage.grid.RowCell) IField(cn.cerc.jpage.core.IField)

Example 3 with IField

use of cn.cerc.jpage.core.IField in project summer-mis by cn-cerc.

the class ColumnEditor method format.

public String format(Record ds) {
    String data = ds.getString(owner.getField());
    if (owner.getBuildText() != null) {
        HtmlWriter html = new HtmlWriter();
        owner.getBuildText().outputText(ds, html);
        data = html.toString();
    } else if (ds.getField(owner.getField()) instanceof Double) {
        DecimalFormat df = new DecimalFormat("0.####");
        data = df.format(ds.getDouble(owner.getField()));
    }
    if (!this.init) {
        dataSet = gridLine.getDataSet();
        columns = new ArrayList<>();
        for (IField field : gridLine.getFields()) {
            if (field instanceof IColumn) {
                if (((AbstractField) field).isReadonly())
                    continue;
                if (field.getWidth() == 0)
                    continue;
                columns.add(field);
            }
        }
        if (gridLine.getOwner() instanceof DataGrid) {
            DataGrid grid = (DataGrid) gridLine.getOwner();
            if (columns.size() > 0 && grid.getPrimaryKey() == null)
                throw new RuntimeException("BaseGrid.primaryKey is null");
        }
        this.init = true;
    }
    HtmlWriter html = new HtmlWriter();
    String inputStyle = "";
    html.print("<input");
    if (gridLine instanceof MasterGridLine)
        html.print(" id='%s'", this.getDataId());
    else {
        if (owner.getId() != null)
            html.print(" id='%s'", owner.getId());
        inputStyle = "width:80%;";
    }
    inputStyle += "border: 1px solid #dcdcdc;";
    html.print(" type='text'");
    html.print(" name='%s'", owner.getField());
    html.print(" value='%s'", data);
    html.print(" autocomplete='off'");
    html.print(" data-%s='[%s]'", owner.getField(), data);
    if (gridLine instanceof MasterGridLine) {
        html.print(" data-focus='[%s]'", this.getDataFocus());
        if (owner.getAlign() != null)
            inputStyle += String.format("text-align:%s;", owner.getAlign());
        if (owner.getOnclick() != null) {
            html.print(" onclick=\"%s\"", owner.getOnclick());
        } else
            html.print(" onclick='this.select()'");
    }
    if (!"".equals(inputStyle))
        html.print(" style='%s'", inputStyle);
    html.print(" onkeydown='return tableDirection(event,this)'");
    if (dataField.size() > 0) {
        for (String field : dataField) {
            html.print(" data-%s='%s'", field, ds.getString(field));
        }
    }
    if (onUpdate != null)
        html.print(" oninput=\"tableOnChanged(this,'%s')\"", onUpdate);
    else
        html.print(" oninput='tableOnChanged(this)'");
    html.println("/>");
    return html.toString();
}
Also used : AbstractField(cn.cerc.jpage.fields.AbstractField) MasterGridLine(cn.cerc.jpage.grid.lines.MasterGridLine) IColumn(cn.cerc.jpage.core.IColumn) HtmlWriter(cn.cerc.jpage.core.HtmlWriter) DecimalFormat(java.text.DecimalFormat) DataGrid(cn.cerc.jpage.grid.DataGrid) IField(cn.cerc.jpage.core.IField)

Example 4 with IField

use of cn.cerc.jpage.core.IField in project summer-mis by cn-cerc.

the class ChildGridLine method output.

@Override
public void output(HtmlWriter html, int lineNo) {
    html.print("<tr");
    html.print(" id='%s_%s'", "tr" + dataSource.getDataSet().getRecNo(), lineNo);
    if (!this.isVisible())
        html.print(" style=\"display:none\"");
    html.println(">");
    for (RowCell item : this.getCells()) {
        IField objField = item.getFields().get(0);
        html.print("<td");
        if (item.getColSpan() > 1)
            html.print(" colspan=\"%d\"", item.getColSpan());
        if (item.getStyle() != null)
            html.print(" style=\"%s\"", item.getStyle());
        if (item.getAlign() != null)
            html.print(" align=\"%s\"", item.getAlign());
        else if (objField.getAlign() != null)
            html.print(" align=\"%s\"", objField.getAlign());
        if (item.getRole() != null)
            html.print(" role=\"%s\"", item.getRole());
        else if (item.getFields().get(0).getField() != null)
            html.print(" role=\"%s\"", item.getFields().get(0).getField());
        html.print(">");
        for (IField obj : item.getFields()) {
            if (obj instanceof AbstractField) {
                AbstractField field = (AbstractField) obj;
                if (field instanceof IColumn)
                    html.print(((IColumn) field).format(dataSource.getDataSet().getCurrent()));
                else if (field instanceof AbstractField)
                    outputField(html, field);
                else
                    throw new RuntimeException("暂不支持的数据类型:" + field.getClass().getName());
                if (field.getTitle() != null && !"".equals(field.getTitle()))
                    html.print("<span style='float: left;'>%s:</span> ", field.getTitle());
            }
        }
        html.println("</td>");
    }
    html.println("</tr>");
}
Also used : AbstractField(cn.cerc.jpage.fields.AbstractField) IColumn(cn.cerc.jpage.core.IColumn) RowCell(cn.cerc.jpage.grid.RowCell) IField(cn.cerc.jpage.core.IField)

Example 5 with IField

use of cn.cerc.jpage.core.IField in project summer-mis by cn-cerc.

the class UIFormHorizontal method readAll.

public ButtonField readAll() {
    if (readAll) {
        return submit;
    }
    if (buttons == null) {
        return submit;
    }
    submit = null;
    // 取 form submit 按钮
    for (AbstractField field : buttons.getFields()) {
        if (field instanceof ButtonField) {
            ButtonField button = (ButtonField) field;
            String key = button.getField();
            String val = request.getParameter(key);
            if (val != null && val.equals(button.getData())) {
                submit = button;
                break;
            }
        }
    }
    // 将用户值或缓存值存入到dataSet中
    for (AbstractField field : this.fields) field.updateField();
    // 将可折叠字段的值存入到dataSet中
    for (IField field : this.getExpender().getFields()) ((AbstractField) field).updateField();
    readAll = true;
    return submit;
}
Also used : AbstractField(cn.cerc.jpage.fields.AbstractField) IField(cn.cerc.jpage.core.IField) ButtonField(cn.cerc.jpage.fields.ButtonField)

Aggregations

IField (cn.cerc.jpage.core.IField)6 AbstractField (cn.cerc.jpage.fields.AbstractField)5 IColumn (cn.cerc.jpage.core.IColumn)4 DataSet (cn.cerc.jdb.core.DataSet)3 RowCell (cn.cerc.jpage.grid.RowCell)3 HtmlWriter (cn.cerc.jpage.core.HtmlWriter)1 ButtonField (cn.cerc.jpage.fields.ButtonField)1 DataGrid (cn.cerc.jpage.grid.DataGrid)1 AbstractGridLine (cn.cerc.jpage.grid.lines.AbstractGridLine)1 ChildGridLine (cn.cerc.jpage.grid.lines.ChildGridLine)1 ExpenderGridLine (cn.cerc.jpage.grid.lines.ExpenderGridLine)1 MasterGridLine (cn.cerc.jpage.grid.lines.MasterGridLine)1 DecimalFormat (java.text.DecimalFormat)1