Search in sources :

Example 1 with KeySerializer

use of com.revolsys.ui.html.serializer.key.KeySerializer in project com.revolsys.open by revolsys.

the class KeySerializerTableSerializer method serializeBodyCell.

@Override
public void serializeBodyCell(final XmlWriter out, final int row, final int col) {
    if (col < this.colCount) {
        final Object object = this.rows.get(row);
        final KeySerializer serializer = getSerializer(col);
        serializer.serialize(out, object);
    } else {
        out.entityRef("nbsp");
    }
}
Also used : KeySerializer(com.revolsys.ui.html.serializer.key.KeySerializer)

Example 2 with KeySerializer

use of com.revolsys.ui.html.serializer.key.KeySerializer in project com.revolsys.open by revolsys.

the class FilterableTableView method initialize.

@Override
public void initialize(final HttpServletRequest request) {
    if (this.searchFields != null) {
        final ElementContainer searchContainer = new ElementContainer(new TableBodyLayout("search", this.model.getColumnCount()));
        add(searchContainer);
        for (final KeySerializer serializer : this.model.getSerializers()) {
            final String name = serializer.getName();
            Element element = this.searchFields.get(name);
            if (element == null) {
                element = NbspElement.INSTANCE;
            } else {
                element = element.clone();
                if (element instanceof Field) {
                    final Field field = (Field) element;
                    field.setRequired(false);
                }
                if (element instanceof TextField) {
                    final TextField textField = (TextField) element;
                    textField.setSize(1);
                }
                if (element instanceof TextAreaField) {
                    final TextAreaField textField = (TextAreaField) element;
                    textField.setRows(1);
                    textField.setCols(1);
                }
            }
            searchContainer.add(element);
        }
    }
    super.initialize(request);
}
Also used : Field(com.revolsys.ui.html.fields.Field) TextField(com.revolsys.ui.html.fields.TextField) TextAreaField(com.revolsys.ui.html.fields.TextAreaField) TableBodyLayout(com.revolsys.ui.html.layout.TableBodyLayout) TextField(com.revolsys.ui.html.fields.TextField) TextAreaField(com.revolsys.ui.html.fields.TextAreaField) KeySerializer(com.revolsys.ui.html.serializer.key.KeySerializer)

Example 3 with KeySerializer

use of com.revolsys.ui.html.serializer.key.KeySerializer in project com.revolsys.open by revolsys.

the class HtmlUiBuilder method addObjectViewPage.

public void addObjectViewPage(final TabElementContainer tabs, final Object object, final String prefix) {
    final HttpServletRequest request = getRequest();
    if (object == null) {
        throw new PageNotFoundException();
    } else {
        final String pageName = getName(prefix, "view");
        final Page page = getPage(pageName);
        if (page == null) {
            throw new PageNotFoundException("Page not found " + pageName);
        } else {
            final List<KeySerializer> serializers = getSerializers(pageName, "view");
            final Element detailView = newDetailView(object, serializers);
            setPageTitle(request, pageName);
            final Menu actionMenu = new Menu();
            final Menu editMenu = addMenuItem(actionMenu, prefix, "edit", "Edit", "_top");
            if (editMenu != null) {
                editMenu.addProperty("buttonClass", "btn-primary");
            }
            final ElementContainer view = new ElementContainer(detailView);
            addMenuElement(view, actionMenu);
            final String tabId = getTypeName() + "_" + pageName;
            final String title = getPageTitle(pageName);
            tabs.add(tabId, title, view);
        }
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) PageNotFoundException(com.revolsys.ui.web.exception.PageNotFoundException) ElementContainer(com.revolsys.ui.html.view.ElementContainer) TabElementContainer(com.revolsys.ui.html.view.TabElementContainer) ButtonsToolbarElement(com.revolsys.ui.html.view.ButtonsToolbarElement) Element(com.revolsys.ui.html.view.Element) Page(com.revolsys.ui.web.config.Page) Menu(com.revolsys.ui.model.Menu) KeySerializer(com.revolsys.ui.html.serializer.key.KeySerializer)

Example 4 with KeySerializer

use of com.revolsys.ui.html.serializer.key.KeySerializer in project com.revolsys.open by revolsys.

the class HtmlUiBuilder method newDataTable.

public ElementContainer newDataTable(final HttpServletRequest request, final String pageName, Map<String, ? extends Object> parameters, final Collection<? extends Object> rows) {
    parameters = new HashMap<>(parameters);
    final List<KeySerializer> serializers = getSerializers(pageName, "list");
    final RowsTableSerializer model = new KeySerializerTableSerializer(serializers, rows);
    final String typeName = getTypeName();
    final TableView tableView = new TableView(model, typeName + " dataTable no-footer");
    tableView.setWidth("100%");
    final String tableId = typeName + "_" + pageName + "_table";
    tableView.setId(tableId);
    tableView.setNoRecordsMessgae(null);
    final Map<String, Object> tableParams = new LinkedHashMap<>();
    tableParams.put("stateSave", true);
    tableParams.put("autoWidth", true);
    tableParams.put("dom", Maps.getString(parameters, "dom", "frtiS"));
    final Boolean ordering = Maps.getBoolean(parameters, "ordering");
    if (ordering != null) {
        tableParams.put("ordering", ordering);
    }
    final String scrollY = (String) parameters.get("scrollY");
    if (scrollY == null) {
        tableParams.put("scrollY", "300px");
    } else {
        tableParams.put("scrollY", scrollY);
    }
    final String scrollX = (String) parameters.get("scrollX");
    if (scrollX == null) {
        tableParams.put("scrollX", "true");
    } else {
        tableParams.put("scrollX", scrollX);
    }
    tableParams.put("order", getListSortOrder(pageName));
    Boolean serverSide = (Boolean) parameters.get("serverSide");
    final String ajaxSource = (String) parameters.get("ajaxSource");
    if (Property.hasValue(ajaxSource)) {
        if (serverSide == null) {
            serverSide = true;
        }
        tableParams.put("serverSide", serverSide);
        tableParams.put("ajax", ajaxSource);
    } else if (serverSide == null) {
        serverSide = false;
    }
    tableParams.put("scroller", Collections.singletonMap("loadingIndicator", true));
    final List<Map<String, Object>> columnDefs = new ArrayList<>();
    int i = 0;
    for (final KeySerializer serializer : serializers) {
        final Map<String, Object> columnDef = new LinkedHashMap<>();
        columnDef.put("targets", Arrays.asList(i));
        columnDef.put("name", serializer.getKey());
        columnDef.put("className", serializer.getKey().replaceAll("[^A-Za-z0-9]", "_"));
        columnDef.put("title", serializer.getLabel());
        final Boolean sortable = serializer.getProperty("sortable");
        if (sortable != null) {
            columnDef.put("orderable", sortable);
        }
        final Boolean searchable = serializer.getProperty("searchable");
        if (searchable != null) {
            columnDef.put("searchable", searchable);
        }
        final Boolean visible = serializer.getProperty("visible");
        if (visible != null) {
            columnDef.put("visible", visible);
        }
        final String width = serializer.getWidth();
        if (width != null) {
            columnDef.put("width", width);
        }
        columnDefs.add(columnDef);
        i++;
    }
    if (!columnDefs.isEmpty()) {
        tableParams.put("columnDefs", columnDefs);
    }
    Number scrollYPercent = (Number) parameters.get("scrollYPercent");
    if (scrollYPercent == null) {
        if (scrollY == null) {
            scrollYPercent = 0;
        } else {
            scrollYPercent = 0.98;
        }
    }
    final Script script = new Script();
    String jsonMap = Json.toString(tableParams);
    jsonMap = jsonMap.substring(0, jsonMap.length() - 1) + ",\"createdRow\": function( row, data, dataIndex ) {refreshButtons(row);}" + ",\"initComplete\": function() {$(this).DataTable().columns.adjust();}";
    jsonMap += "}";
    final StringBuffer scriptBody = new StringBuffer();
    scriptBody.append("$(document).ready(function() {\n");
    scriptBody.append("  var tableDiv = $('#");
    scriptBody.append(tableId);
    scriptBody.append(" table');\n");
    scriptBody.append("  var table = tableDiv.dataTable(");
    scriptBody.append(jsonMap);
    scriptBody.append("\n );\n");
    scriptBody.append("  tableShowEvents(table,");
    scriptBody.append(scrollYPercent);
    scriptBody.append(");\n");
    scriptBody.append("$(window).bind('resize', function () {$(table).DataTable().columns.adjust();} );");
    scriptBody.append("});");
    script.setContent(scriptBody.toString());
    final ElementContainer container = new ElementContainer(tableView, script);
    final String prefix = pageName.replaceAll("[lL]ist$", "");
    final Menu actionMenu = new Menu();
    final Menu addMenuItem = addMenuItem(actionMenu, prefix, "add", "Add", "_top");
    if (addMenuItem != null) {
        addMenuItem.addProperty("buttonClass", "btn-primary");
    }
    addListMenuItems(actionMenu, prefix);
    addMenuElement(container, actionMenu);
    return container;
}
Also used : KeySerializerTableSerializer(com.revolsys.ui.html.serializer.KeySerializerTableSerializer) Script(com.revolsys.ui.html.view.Script) ElementContainer(com.revolsys.ui.html.view.ElementContainer) TabElementContainer(com.revolsys.ui.html.view.TabElementContainer) ArrayList(java.util.ArrayList) KeySerializer(com.revolsys.ui.html.serializer.key.KeySerializer) LinkedHashMap(java.util.LinkedHashMap) Menu(com.revolsys.ui.model.Menu) RowsTableSerializer(com.revolsys.ui.html.serializer.RowsTableSerializer) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TableView(com.revolsys.ui.html.view.TableView)

Example 5 with KeySerializer

use of com.revolsys.ui.html.serializer.key.KeySerializer in project com.revolsys.open by revolsys.

the class HtmlUiBuilder method newDataTableMap.

public Map<String, Object> newDataTableMap(final HttpServletRequest request, final Collection<? extends Object> records, final String pageName) {
    final List<KeySerializer> serializers = getSerializers(pageName, "list");
    final List<List<String>> rows = new ArrayList<>();
    for (final Object object : records) {
        final List<String> row = new ArrayList<>();
        for (final KeySerializer serializer : serializers) {
            final String html = serializer.toString(object);
            row.add(html);
        }
        rows.add(row);
    }
    final Map<String, Object> response = new LinkedHashMap<>();
    final int recordCount = rows.size();
    response.put("draw", HttpServletUtils.getIntegerParameter(request, "draw"));
    response.put("recordsTotal", recordCount);
    response.put("recordsFiltered", recordCount);
    response.put("data", rows);
    return response;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) KeySerializer(com.revolsys.ui.html.serializer.key.KeySerializer) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

KeySerializer (com.revolsys.ui.html.serializer.key.KeySerializer)13 ArrayList (java.util.ArrayList)5 LinkedHashMap (java.util.LinkedHashMap)3 ElementContainer (com.revolsys.ui.html.view.ElementContainer)2 TabElementContainer (com.revolsys.ui.html.view.TabElementContainer)2 Menu (com.revolsys.ui.model.Menu)2 List (java.util.List)2 Record (com.revolsys.record.Record)1 Or (com.revolsys.record.query.Or)1 RecordStore (com.revolsys.record.schema.RecordStore)1 Field (com.revolsys.ui.html.fields.Field)1 TextAreaField (com.revolsys.ui.html.fields.TextAreaField)1 TextField (com.revolsys.ui.html.fields.TextField)1 TableBodyLayout (com.revolsys.ui.html.layout.TableBodyLayout)1 BuilderSerializer (com.revolsys.ui.html.serializer.BuilderSerializer)1 KeySerializerTableSerializer (com.revolsys.ui.html.serializer.KeySerializerTableSerializer)1 RowsTableSerializer (com.revolsys.ui.html.serializer.RowsTableSerializer)1 TypeSerializer (com.revolsys.ui.html.serializer.type.TypeSerializer)1 ButtonsToolbarElement (com.revolsys.ui.html.view.ButtonsToolbarElement)1 Element (com.revolsys.ui.html.view.Element)1