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

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

Introduction

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

Prototype

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

Source Link

Usage

From source file:com.bedatadriven.renjin.appengine.client.CommandPrompt.java

License:Apache License

private int measureTextWidthInPixels(String text) {
    SpanElement span = Document.get().createSpanElement();
    RootPanel.get().getElement().appendChild(span);
    span.setAttribute("position", "absolute");
    span.setInnerText(text);/*from w  ww  . j  av  a2 s . c o  m*/
    int width = span.getOffsetWidth();
    RootPanel.get().getElement().removeChild(span);
    return width;
}

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  a2  s.  c  o  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:org.drools.workbench.screens.scenariosimulation.client.collectioneditor.CollectionEditorUtils.java

License:Apache License

public static void setSpanAttributeAttributes(String dataI18nKey, String innerText, String dataField,
        SpanElement spanElement) {
    spanElement.setInnerText(innerText);
    spanElement.setAttribute("data-i18n-key", dataI18nKey);
    spanElement.setAttribute("data-field", dataField);
}

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   www.  ja  v  a 2s  .c  o m
 */
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;
}

From source file:org.waveprotocol.wave.client.clipboard.Clipboard.java

License:Apache License

/**
 * Hijacks the paste fragment by hiding a span with metadata at the end of the
 * fragment.//from   w w w. j ava  2  s  .  co  m
 *
 * @param xmlInRange The xml string to pass into the magic span element
 * @param annotations The annotation string to pass into the magic span
 *        element
 * @param origRange the current range. The span element will be inserted
 *        before the start
 *
 * @return The new adjusted selection. The end will be adjusted such that it
 *         encloses the original selection and the span with metadata
 */
private PointRange<Node> hijackFragment(String xmlInRange, String annotations, PointRange<Node> origRange) {
    Point<Node> origStart = origRange.getFirst();
    Point<Node> origEnd = origRange.getSecond();
    SpanElement spanForXml = Document.get().createSpanElement();
    spanForXml.setAttribute(WAVE_XML_ATTRIBUTE, xmlInRange);
    spanForXml.setAttribute(WAVE_ANNOTATIONS_ATTRIBUTE, annotations);
    spanForXml.setClassName(MAGIC_CLASSNAME);

    LOG.trace().log("original point: " + origStart);

    // NOTE(user): An extra span is required at the end for Safari, otherwise
    // the span with the metadata may get discarded.
    SpanElement trailingSpan = Document.get().createSpanElement();
    trailingSpan.setInnerHTML("&nbsp;");

    if (origEnd.isInTextNode()) {
        Text t = (Text) origEnd.getContainer();
        t.setData(t.getData().substring(0, origEnd.getTextOffset()));
        origEnd.getContainer().getParentElement().insertAfter(spanForXml, t);
        origEnd.getContainer().getParentElement().insertAfter(trailingSpan, spanForXml);
    } else {
        origEnd.getContainer().insertAfter(spanForXml, origEnd.getNodeAfter());
        origEnd.getContainer().insertAfter(trailingSpan, spanForXml);
    }

    Point<Node> newEnd = Point.<Node>inElement(spanForXml.getParentElement(), trailingSpan.getNextSibling());
    LOG.trace().log("new point: " + newEnd);
    LOG.trace().logPlainText("parent: " + spanForXml.getParentElement().getInnerHTML());
    assert newEnd.getNodeAfter() == null
            || newEnd.getNodeAfter().getParentElement() == newEnd.getContainer() : "inconsistent point";
    return new PointRange<Node>(origStart, newEnd);
}

From source file:org.xwiki.gwt.wysiwyg.client.plugin.sync.SyncPlugin.java

License:Open Source License

private void insertCursor(Document doc) {
    try {// w w  w .ja va2 s.  c o m
        int color = id - 10 * (int) Math.floor(id / 10);
        // insertCursor(element, id, color);
        SpanElement cursorNode = doc.createSpanElement();
        cursorNode.setId("cursor-" + id);
        cursorNode.setClassName("cursor cursor-" + color);
        cursorNode.setAttribute("style", "background-color: #" + color + ";");
        Range range = doc.getSelection().getRangeAt(0);
        try {
            if (range != null) {
                if (range.getStartContainer().equals(doc) && range.getEndContainer().equals(doc)
                        && range.getStartOffset() == 0 && range.getEndOffset() == 0) {
                    debugMessage("Cursor at start.. let's not handle it");
                } else {
                    debugMessage("Start container: " + range.getStartContainer());
                    debugMessage("Start offset: " + range.getStartOffset());
                    debugMessage("End container: " + range.getEndContainer());
                    debugMessage("End offset: " + range.getEndOffset());
                    range.surroundContents(cursorNode);
                    debugMessage("surrounding range ok");
                }
            }
        } catch (Exception e) {
            try {
                debugMessage("error surrounding range");
                debugMessage("Exception: " + e.getMessage());
                e.printStackTrace();
                debugMessage(e.toString());
                if (range != null) {
                    debugMessage("Start container: " + range.getStartContainer());
                    debugMessage("Start offset: " + range.getStartOffset());
                    debugMessage("End container: " + range.getEndContainer());
                    debugMessage("End offset: " + range.getEndOffset());
                    try {
                        debugMessage("Range content: " + range.cloneContents().getInnerHTML());
                    } catch (Exception e3) {
                    }
                }
                Selection selection = doc.getSelection();
                if (selection != null) {
                    debugMessage("Selection range count: " + selection.getRangeCount());
                }
            } catch (Exception e2) {
                debugMessage("Exception: " + e2.getMessage());
            }
        }

    } catch (Exception e) {
        debugMessage("Uncaught exception in insertCursor: " + e.getMessage());
    }

}