List of usage examples for com.google.gwt.dom.client Document createImageElement
public ImageElement createImageElement()
From source file:com.smartgwt.mobile.client.widgets.tableview.TableView.java
License:Open Source License
private LIElement showGroup(List<Record> recordsToShow, UListElement ul) { final Document document = Document.get(); final String primaryKeyField = getPrimaryKeyFieldName(), iconField = getIconField(), titleField = getTitleField(), infoField = getInfoField(), descriptionField = getDescriptionField(); LIElement lastLI = null;/*www. j ava2 s . c o m*/ for (final Record record : recordsToShow) { final Canvas recordComponent; if (getShowRecordComponents()) { recordComponent = createRecordComponent(record); if (recordComponent == null) { continue; } else recordComponents.add(recordComponent); } else recordComponent = null; final LIElement li = document.createLIElement(); li.addClassName(ROW_CLASS_NAME); com.google.gwt.user.client.Element element = li.cast(); final Object recordID = record.getAttributeAsObject(primaryKeyField); elementMap.put(recordID, element); final Integer recordIndex = record.getAttributeAsInt(recordIndexProperty); li.setAttribute(RECORD_INDEX_ATTRIBUTE_NAME, recordIndex.toString()); if (lastLI == null) { li.addClassName(_CSS.firstTableViewRowClass()); } if (showSelectedIcon && selectedIcon == null && getSelectionType() == SelectionStyle.MULTIPLE) { DivElement selectionDisclosure = document.createDivElement(); selectionDisclosure.setClassName(_CSS.recordSelectionDisclosureClass()); if (!_canSelectRecord(record)) { selectionDisclosure.addClassName(_CSS.nonselectableSelectionDisclosureClass()); } SpanElement span = document.createSpanElement(); selectionDisclosure.appendChild(span); li.appendChild(selectionDisclosure); } if (canRemoveRecords) { Boolean deletable = record.getAttributeAsBoolean(canRemoveProperty); if (deletable == null || (deletable != null && deletable.booleanValue())) { DivElement div = document.createDivElement(); div.addClassName(_CSS.recordDeleteDisclosureClass()); SpanElement span = document.createSpanElement(); div.appendChild(span); li.appendChild(div); if (markedForRemoval != null && markedForRemoval.contains(record)) { _markRecordRemoved(record, div, true); } } } if (canReorderRecords) { MoveIndicator draggableRow = new MoveIndicator(element); add(draggableRow, element); } if (!getShowRecordComponents()) { if (recordFormatter != null) { DivElement div = document.createDivElement(); div.setClassName("content"); div.setInnerHTML(recordFormatter.format(record)); li.appendChild(div); } else { if (getShowNavigation(record)) { final ImageResource navIcon = getNavigationIcon(record); if (navigationMode == NavigationMode.NAVICON_ONLY) { Boolean navigate = record.getAttributeAsBoolean(getRecordNavigationProperty()); if (navigate == null || (navigate != null && navigate.booleanValue())) { final DetailsRow detailsRow = new DetailsRow(navIcon); add(detailsRow, element); } } else if (navIcon != null) { final Image image = new Image(navIcon); image.getElement().addClassName(TableView._CSS.recordDetailDisclosureNavIconClass()); add(image, element); } else { li.addClassName(_CSS.tableViewRowHasNavigationDisclosureClass()); } } if (showIcons) { Object icon = record.get(iconField); if (!(icon instanceof ImageResource) && !(icon instanceof Image)) { icon = formatCellValue(record, recordIndex.intValue(), iconField); } if (icon != null) { SpanElement span = document.createSpanElement(); span.addClassName(RECORD_ICON_CLASS_NAME); li.appendChild(span); li.addClassName(_CSS.tableViewRowHasIconClass()); ImageElement img = document.createImageElement(); if (icon instanceof ImageResource) { img.setSrc(((ImageResource) icon).getSafeUri().asString()); } else if (icon instanceof Image) { img.setSrc(((Image) icon).getUrl()); } else { img.setSrc(icon.toString()); } span.appendChild(img); } } if (showDetailCount) { String count = formatCellValue(record, recordIndex.intValue(), detailCountProperty); if (count != null) { SpanElement span = document.createSpanElement(); span.addClassName(RECORD_COUNTER_CLASS_NAME); span.setInnerHTML(count); li.appendChild(span); } } String title = formatCellValue(record, recordIndex.intValue(), titleField); if (title != null) { SpanElement span = document.createSpanElement(); final String baseStyle = getBaseStyle(record, recordIndex.intValue(), getFieldNum(titleField)); if (baseStyle != null) span.setClassName(baseStyle); span.addClassName(RECORD_TITLE_CLASS_NAME); span.setInnerHTML(title); li.appendChild(span); } if (recordLayout == RecordLayout.AUTOMATIC || recordLayout == RecordLayout.SUMMARY_FULL || recordLayout == RecordLayout.SUMMARY_INFO) { String info = formatCellValue(record, recordIndex.intValue(), infoField); if (info != null) { ul.addClassName(_CSS.stackedTableViewClass()); li.addClassName(_CSS.tableViewRowHasRecordInfoClass()); SpanElement span = document.createSpanElement(); final String baseStyle = getBaseStyle(record, recordIndex.intValue(), getFieldNum(infoField)); if (baseStyle != null) span.setClassName(baseStyle); span.addClassName(RECORD_INFO_CLASS_NAME); span.appendChild(document.createTextNode(info)); li.appendChild(span); } } if (recordLayout == RecordLayout.AUTOMATIC || recordLayout == RecordLayout.TITLE_DESCRIPTION || recordLayout == RecordLayout.SUMMARY_DATA || recordLayout == RecordLayout.SUMMARY_FULL || recordLayout == RecordLayout.SUMMARY_INFO) { String description = formatCellValue(record, recordIndex.intValue(), descriptionField); if (description != null) { SpanElement span = document.createSpanElement(); final String baseStyle = getBaseStyle(record, recordIndex.intValue(), getFieldNum(descriptionField)); if (baseStyle != null) span.setClassName(baseStyle); span.addClassName(RECORD_DESCRIPTION_CLASS_NAME); span.appendChild(document.createTextNode(description)); li.appendChild(span); } } } } else { assert recordComponent != null; recordComponent.getElement().addClassName(RECORD_COMPONENT_CLASS_NAME); add(recordComponent, element); } ul.appendChild(li); lastLI = li; } return lastLI; }