List of usage examples for com.google.gwt.dom.client Document createULElement
public UListElement createULElement()
From source file:com.smartgwt.mobile.client.widgets.tableview.TableView.java
License:Open Source License
/** * Renders the records in <code>recordsToShow</code> on screen. * * @see #getShowRecordComponents()/*from w ww. j a v a2 s. com*/ */ public void loadRecords(List<Record> recordsToShow) { destroyRecordComponents(); final boolean hadShowDeletableRecordsClassName, hadShowMoveableRecordsClassName; if (_ul != null) { hadShowDeletableRecordsClassName = ElementUtil.hasClassName(_ul, _CSS.tableViewShowDeleteDisclosuresClass()); hadShowMoveableRecordsClassName = ElementUtil.hasClassName(_ul, _CSS.tableViewShowMoveIndicatorsClass()); if (_ul.hasParentElement()) { _ul.removeFromParent(); } } else { hadShowDeletableRecordsClassName = false; hadShowMoveableRecordsClassName = false; } final Document document = Document.get(); _ul = document.createULElement(); _ul.addClassName(COMPONENT_CLASS_NAME); if (parentNavStack != null) { _ul.addClassName(_CSS.tableViewHasParentNavStackClass()); } if (hadShowDeletableRecordsClassName) { _ul.addClassName(_CSS.tableViewShowDeleteDisclosuresClass()); } if (hadShowMoveableRecordsClassName) { _ul.addClassName(_CSS.tableViewShowMoveIndicatorsClass()); } if (this.tableMode == TableMode.GROUPED) { _ul.addClassName(_CSS.groupedTableViewClass()); } if (recordsToShow == null) recordsToShow = Collections.emptyList(); for (int i = 0; i < recordsToShow.size(); ++i) { final Record record = recordsToShow.get(i); if (record == null) throw new NullPointerException("The Record at index " + i + " is null."); record.setAttribute(recordIndexProperty, Integer.valueOf(i)); } ListGridField groupByField = null; GroupNode[] sortedGroupNodes = null; // Handle table grouping if (groupByFieldName != null) { final ListGridField[] fields = getFields(); if (fields != null) { for (ListGridField field : fields) { if (field != null && groupByFieldName.equals(field.getName())) { groupByField = field; break; } } } if (groupByField == null) { SC.logWarn("Could not find groupByField '" + groupByFieldName + "'"); } else if (groupByField.getGroupValueFunction() == null) { SC.logWarn("The groupByField '" + groupByFieldName + "' does not have a GroupByFunction."); } else { final GroupValueFunction groupByFunction = groupByField.getGroupValueFunction(); final Map<Object, GroupNode> groupNodes = new LinkedHashMap<Object, GroupNode>(); for (Record record : recordsToShow) { final Object groupValue = groupByFunction.getGroupValue( record.getAttributeAsObject(groupByFieldName), record, groupByField, groupByFieldName, this); GroupNode groupNode = groupNodes.get(groupValue); if (groupNode == null) { groupNode = new GroupNode(groupValue); groupNodes.put(groupValue, groupNode); } groupNode._add(record); } sortedGroupNodes = groupNodes.values().toArray(new GroupNode[groupNodes.size()]); Arrays.sort(sortedGroupNodes, GroupNode._COMPARATOR); } } elementMap = new HashMap<Object, Element>(); if (getShowRecordComponents()) recordComponents = new ArrayList<Canvas>(); if (recordsToShow.isEmpty()) { if (_getData() instanceof ResultSet && !((ResultSet) _getData()).lengthIsKnown()) { _ul.setInnerText(this.getLoadingMessage()); } else { if (emptyMessage != null) _ul.setInnerText(emptyMessage); } getElement().appendChild(_ul); } else { UListElement ul = _ul; LIElement lastLI; if (sortedGroupNodes == null) { lastLI = showGroup(recordsToShow, ul); } else { assert groupByField != null; assert sortedGroupNodes.length >= 1; final GroupTitleRenderer groupTitleRenderer = groupByField.getGroupTitleRenderer(); int i = 0; LIElement li; do { final GroupNode groupNode = sortedGroupNodes[i]; groupNode._setGroupTitle( groupTitleRenderer == null ? SafeHtmlUtils.htmlEscape(groupNode._getGroupValueString()) : groupTitleRenderer.getGroupTitle(groupNode.getGroupValue(), groupNode, groupByField, groupByFieldName, this)); li = document.createLIElement(); li.setAttribute(GROUP_VALUE_STRING_ATTRIBUTE_NAME, groupNode._getGroupValueString()); if (ul == null || _ul.equals(ul)) li.addClassName(_CSS.firstTableViewGroupClass()); final String groupTitle = groupNode.getGroupTitle(); if (groupTitle == null) { li.addClassName(_CSS.tableViewGroupWithoutGroupTitleClass()); } else { final DivElement labelDiv = document.createDivElement(); labelDiv.setClassName(Label.COMPONENT_CLASS_NAME); labelDiv.setInnerHTML(groupTitle); li.appendChild(labelDiv); } ul = document.createULElement(); ul.setClassName(COMPONENT_CLASS_NAME); ul.addClassName(TABLE_GROUP_CLASS_NAME); lastLI = showGroup(groupNode._getGroupMembersList(), ul); if (i != sortedGroupNodes.length - 1 && lastLI != null) { lastLI.addClassName(_CSS.lastTableViewRowClass()); } li.appendChild(ul); _ul.appendChild(li); } while (++i < sortedGroupNodes.length); assert li != null; li.addClassName(_CSS.lastTableViewGroupClass()); } if (_getData() instanceof ResultSet) { ResultSet rs = (ResultSet) _getData(); if (rs.getFetchMode() == FetchMode.PAGED && !rs.allRowsCached()) { LIElement li = document.createLIElement(); li.setClassName(ROW_CLASS_NAME); com.google.gwt.user.client.Element loadMoreRecordsElement = (com.google.gwt.user.client.Element) li .cast(); DOM.setEventListener(loadMoreRecordsElement, this); SpanElement span = document.createSpanElement(); span.addClassName(RECORD_TITLE_CLASS_NAME); span.setInnerText(SmartGwtMessages.INSTANCE.listGrid_loadMoreRecords()); span.setAttribute(IS_LOAD_MORE_RECORDS_ATTRIBUTE_NAME, "true"); li.setAttribute(IS_LOAD_MORE_RECORDS_ATTRIBUTE_NAME, "true"); li.appendChild(span); ul.appendChild(li); lastLI = li; } } if (lastLI != null) { lastLI.addClassName(_CSS.lastTableViewRowClass()); } getElement().appendChild(_ul); setSelecteds(); } if (isAttached()) { _fireContentChangedEvent(); // If this `TableView' is not currently attached, defer the firing of the content // changed event. } else { fireContentChangedOnLoad = true; } }
From source file:com.xemantic.tadedon.gwt.user.client.ui.ListPanel.java
License:Apache License
/** * Creates new list panel of specified root element {@code type}. * * @param type the list element type./*w w w .j av a 2 s.co m*/ */ public @UiConstructor ListPanel(Type type) { Document doc = Document.get(); switch (type) { case UL: m_listElement = doc.createULElement(); break; case OL: m_listElement = doc.createOLElement(); break; default: throw new AssertionError("Unknown list element type: " + type); } setElement(m_listElement); }