Example usage for com.google.gwt.dom.client LIElement setAttribute

List of usage examples for com.google.gwt.dom.client LIElement setAttribute

Introduction

In this page you can find the example usage for com.google.gwt.dom.client LIElement setAttribute.

Prototype

@Override
    public void setAttribute(String name, String value) 

Source Link

Usage

From source file:com.horaz.client.widgets.ListView.java

License:Open Source License

/**
 * creates a new list item from a model//  w ww.  j av a  2s. c  o  m
 * notice: after that {@link #refresh()} has to be called.
 * @param model
 */
protected void createNewItem(T model) {
    String inner = generateItemInnerHTML(model);
    LIElement newItem = Document.get().createLIElement();
    newItem.setInnerHTML(inner);
    newItem.setAttribute("data-modelid", String.valueOf(model.getModelId()));
    // models cache for itemApply
    modelsCache.put(model.getModelId(), model);
    getElement().appendChild(newItem);
}

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()/*  w  w w.j a  v  a  2s  . co  m*/
 */
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.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;//from ww w  . j a  v  a  2s . 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;
}

From source file:fr.putnami.pwt.core.widget.client.InputDatePicker.java

License:Open Source License

private void openMonthOfYear(int year) {
    String yearString = String.valueOf(year);
    this.monthPickerUlMonthElement.removeFromParent();
    for (int i = 0; i < this.monthPickerInner.getChildCount(); i++) {
        Element child = (Element) this.monthPickerInner.getChild(i);
        if (yearString.equals(child.getAttribute(InputDatePicker.ATTRIBUTE_DATA_YEAR))) {
            this.monthPickerInner.insertAfter(this.monthPickerUlMonthElement, child);
            Date monthButtonDate = new Date(this.cursor.getTime());
            monthButtonDate.setYear(year - InputDatePicker.YEAR_OFFSET);
            if (this.monthPickerUlMonthElement.getChildCount() == 0) {
                for (int month = 0; month < 12; month++) {
                    LIElement monthElement = Document.get().createLIElement();
                    this.monthPickerUlMonthElement.appendChild(monthElement);
                    Event.sinkEvents(monthElement, Event.ONCLICK);
                    monthButtonDate.setMonth(month);
                    monthElement.setInnerText(InputDatePicker.MONTH_ABBR_FORMAT.format(monthButtonDate));
                }/* w  w w  . java  2  s.  co m*/
            }
            for (int month = 0; month < 12; month++) {
                LIElement monthElement = (LIElement) this.monthPickerUlMonthElement.getChild(month);
                monthButtonDate.setMonth(month);
                monthElement.setAttribute(InputDatePicker.ATTRIBUTE_DATA_CURSOR,
                        InputDatePicker.ATTRIBUTE_DATE_FORMAT.format(monthButtonDate));
            }
            this.monthPicker.setScrollTop(child.getOffsetTop());
            break;
        }
    }
}

From source file:org.drools.workbench.screens.scenariosimulation.client.collectioneditor.PropertyPresenter.java

License:Apache License

@Override
public LIElement getPropertyFields(String itemId, String propertyName, String propertyValue) {
    final PropertyView propertyEditorView = viewsProvider.getPropertyEditorView();
    String hashedPropertyName = "#" + propertyName;
    final SpanElement propertyNameSpan = propertyEditorView.getPropertyName();
    setSpanAttributeAttributes(propertyName, hashedPropertyName, "propertyName" + hashedPropertyName,
            propertyNameSpan);//from w w  w. j  a  v a  2 s .c  o  m
    final SpanElement propertyValueSpan = propertyEditorView.getPropertyValueSpan();
    setSpanAttributeAttributes(propertyName, propertyValue, "propertyValue" + hashedPropertyName,
            propertyValueSpan);
    propertySpanElementMap.put(propertyName, propertyValueSpan);
    final InputElement propertyValueInput = propertyEditorView.getPropertyValueInput();
    propertyValueInput.setAttribute("placeholder", hashedPropertyName);
    propertyValueInput.setAttribute("data-field", "propertyValue" + hashedPropertyName);
    propertyValueInput.setDisabled(true);
    propertyValueInput.getStyle().setDisplay(Style.Display.NONE);
    final LIElement propertyFields = propertyEditorView.getPropertyFields();
    propertyFields.setAttribute("data-field", "propertyFields" + hashedPropertyName);
    if (propertyViewMap.containsKey(itemId)) {
        propertyViewMap.get(itemId).add(propertyEditorView);
    } else {
        List<PropertyView> toPut = new ArrayList<>();
        toPut.add(propertyEditorView);
        propertyViewMap.put(itemId, toPut);
    }
    return propertyFields;
}

From source file:org.jboss.demo.widgets.client.local.PickListWidget.java

License:Open Source License

public void initCapitals(List<Capital> capitals, List<Capital> selectedCapitals) {
    this.capitals = capitals;
    clearChildren(sourceList);/*from   w w  w . j a v a2  s. co  m*/
    clearChildren(targetList);

    Document document = Document.get();
    for (Capital capital : capitals) {
        LIElement li = document.createLIElement();
        li.setInnerText(capital.getName());
        // "data-key" is used by the jQuery plugin to uniquely identify the list elements
        li.setAttribute("data-key", capital.getName());
        // use JSNI to store the item object in the "data-object" attribute of the list element
        setCapital(li, capital);
        if (selectedCapitals.contains(capital)) {
            targetList.appendChild(li);
        } else {
            sourceList.appendChild(li);
        }
    }
    // We don't initialize the jQuery plugin until the list elements are in place
    initPlugin();
}

From source file:org.overlord.rtgov.ui.client.local.pages.situations.CallTraceWidget.java

License:Apache License

/**
 * Creates a single tree node from the given trace node.
 * @param node/*from   w ww.j  a v a2s  .c om*/
 */
protected LIElement createTreeNode(TraceNodeBean node) {
    String nodeId = String.valueOf(nodeIdCounter++);
    nodeMap.put(nodeId, node);

    boolean isCall = "Call".equals(node.getType()); //$NON-NLS-1$
    boolean hasChildren = !node.getTasks().isEmpty();
    LIElement li = Document.get().createLIElement();
    li.setClassName(hasChildren ? "parent_li" : "leaf_li"); //$NON-NLS-1$ //$NON-NLS-2$
    if (hasChildren)
        li.setAttribute("role", "treeitem"); //$NON-NLS-1$ //$NON-NLS-2$
    SpanElement span = Document.get().createSpanElement();
    span.setAttribute("data-nodeid", nodeId); //$NON-NLS-1$
    Element icon = Document.get().createElement("i"); //$NON-NLS-1$
    span.appendChild(icon);
    span.appendChild(Document.get().createTextNode(" ")); //$NON-NLS-1$
    if (isCall) {
        span.setClassName(node.getStatus());
        icon.setClassName("icon-minus-sign"); //$NON-NLS-1$
        span.appendChild(Document.get().createTextNode(node.getOperation()));
        span.appendChild(Document.get().createTextNode(":")); //$NON-NLS-1$
        span.appendChild(Document.get().createTextNode(node.getComponent()));
    } else {
        span.appendChild(Document.get().createTextNode(node.getDescription()));
        span.setClassName("Info"); //$NON-NLS-1$
        icon.setClassName("icon-info-sign"); //$NON-NLS-1$
    }
    li.appendChild(span);
    if (node.getDuration() != -1) {
        li.appendChild(Document.get().createTextNode(" [")); //$NON-NLS-1$
        li.appendChild(Document.get().createTextNode(String.valueOf(node.getDuration())));
        li.appendChild(Document.get().createTextNode("ms]")); //$NON-NLS-1$
    }
    if (node.getPercentage() != -1) {
        li.appendChild(Document.get().createTextNode(" (")); //$NON-NLS-1$
        li.appendChild(Document.get().createTextNode(String.valueOf(node.getPercentage())));
        li.appendChild(Document.get().createTextNode("%)")); //$NON-NLS-1$
    }

    if (hasChildren) {
        UListElement ul = Document.get().createULElement();
        ul.setAttribute("role", "group"); //$NON-NLS-1$ //$NON-NLS-2$
        li.appendChild(ul);

        List<TraceNodeBean> tasks = node.getTasks();
        for (TraceNodeBean task : tasks) {
            LIElement tn = createTreeNode(task);
            ul.appendChild(tn);
        }
    }
    return li;
}