Java Code Examples for com.google.gwt.dom.client.Element#setAttribute()

The following examples show how to use com.google.gwt.dom.client.Element#setAttribute() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CubaSourceCodeEditorWidget.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Override
public void setEnabled(boolean enabled) {
    super.setEnabled(enabled);

    super.setReadOnly(!enabled || readOnly);

    if (editor != null) {
        Element textAreaElement = getTextAreaElement();

        if (enabled) {
            textAreaElement.removeAttribute("disabled");
        } else {
            textAreaElement.setAttribute("disabled", "disabled");
        }

        updateTabIndex();
    }
}
 
Example 2
Source File: DomHelper.java    From incubator-retired-wave with Apache License 2.0 6 votes vote down vote up
/**
 * Make an element editable or not
 *
 * @param element
 * @param whiteSpacePreWrap Whether to additionally turn on the white space
 *   pre wrap property. If in doubt, set to true. This is what we use for
 *   the editor. So for any concurrently editable areas and such, we must
 *   use true. If false, does nothing (it does not clear the property).
 * @param isEditable
 * @return the same element for convenience
 */
public static Element setContentEditable(Element element, boolean isEditable,
    boolean whiteSpacePreWrap) {
  if (UserAgent.isSafari()) {
    // We MUST use the "plaintext-only" variant to prevent nasty things like
    // Apple+B munging our dom without giving us a key event.

    // Assertion in GWT stuffs this up... fix GWT, in the meantime use a string map
    //      element.getStyle().setProperty("-webkit-user-modify",
    //          isEditable ? "read-write-plaintext-only" : "read-only");

    JsoView.as(element.getStyle()).setString("-webkit-user-modify",
        isEditable ? "read-write-plaintext-only" : "read-only");
  } else {
    element.setAttribute("contentEditable", isEditable ? "true" : "false");
  }

  if (whiteSpacePreWrap) {
    // More GWT assertion fun!
    JsoView.as(element.getStyle()).setString("white-space", "pre-wrap");
  }

  return element;
}
 
Example 3
Source File: MaterialCheckBox.java    From gwt-material with Apache License 2.0 6 votes vote down vote up
/**
 * Setting the type of Checkbox.
 */
public void setType(CheckBoxType type) {
    this.type = type;
    switch (type) {
        case FILLED:
            Element input = DOM.getChild(getElement(), 0);
            input.setAttribute("class", CssName.FILLED_IN);
            break;
        case INTERMEDIATE:
            addStyleName(type.getCssName() + "-checkbox");
            break;
        default:
            addStyleName(type.getCssName());
            break;
    }
}
 
Example 4
Source File: MultiValueTagsInput.java    From gwtbootstrap3-extras with Apache License 2.0 5 votes vote down vote up
public MultiValueTagsInput(Element e, final Collection<? extends Dataset<T>> datasets) {
    e.setAttribute("data-role", "tagsinput");

    setElement(e);
    
    // Wrapped elements are already attached to the DOM and the onAttach method will not be called automatically,
    // so it is called manually to correctly set attached state.
    onAttach();
    
    setDatasets(datasets);
}
 
Example 5
Source File: AnnotationSpreadRenderer.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
private static Element createHtml(boolean isAnchor) {
  Element e = isAnchor
      ? Document.get().createAnchorElement()
      : Document.get().createSpanElement();

  // Prevents some browsers (to my knowledge, currently just Webkit)
  // from removing empty elements from the dom too much
  if (UserAgent.isWebkit()) {
    e.setAttribute("x", "y");
  }

  return e;
}
 
Example 6
Source File: DebugClassHelper.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
/**
 * Replaces a debug class name from an Element with another one.
 *
 * @param elem the object to modify
 * @param oldClassName previous class name to be removed
 * @param newClassName new class name to be added
 */
public static final void replaceDebugClass(
    Element elem, String oldClassName, String newClassName) {
  Preconditions.checkNotNull(elem, "replaceDebugClass: Element must not be null");
  if (debugClassEnabled) {
    Set<String> debugClasses = getDebugClasses(elem);
    boolean removed = debugClasses.remove(oldClassName);
    // if no change happened in the debugClasses, do nothing
    if (debugClasses.add(newClassName) || removed) {
      elem.setAttribute(DEBUG_CLASS_ATTRIBUTE, joinDebugClasses(debugClasses));
    }
  }
}
 
Example 7
Source File: DomHelper.java    From swellrt with Apache License 2.0 5 votes vote down vote up
/**
 * Makes an element, and all its descendant elements, unselectable.
 */
public static void makeUnselectable(Element e) {
  if (UserAgent.isIE()) {
    e.setAttribute("unselectable", "on");
    e = e.getFirstChildElement();
    while (e != null) {
      makeUnselectable(e);
      e = e.getNextSiblingElement();
    }
  }
}
 
Example 8
Source File: SingleValueTagsInput.java    From gwtbootstrap3-extras with Apache License 2.0 5 votes vote down vote up
public SingleValueTagsInput(final Element e, final Collection<? extends Dataset<T>> datasets) {
    e.setAttribute("data-role", "tagsinput");

    setElement(e);
    
    // Wrapped elements are already attached to the DOM and the onAttach method will not be called automatically,
    // so it is called manually to correctly set attached state.
    onAttach();
    
    setDatasets(datasets);
}
 
Example 9
Source File: DebugClassHelper.java    From swellrt with Apache License 2.0 5 votes vote down vote up
/**
 * Remove a debug class from an Element.
 *
 * @param elem the object to modify
 * @param debugClass to be removed
 */
public static final void removeDebugClass(Element elem, String debugClass) {
  if (debugClassEnabled && null != elem) {
    Set<String> debugClasses = getDebugClasses(elem);
    if (debugClasses.remove(debugClass)) {
      elem.setAttribute(DEBUG_CLASS_ATTRIBUTE, joinDebugClasses(debugClasses));
    }
  }
}
 
Example 10
Source File: DebugClassHelper.java    From swellrt with Apache License 2.0 5 votes vote down vote up
/**
 * Replaces a debug class name from an Element with another one.
 *
 * @param elem the object to modify
 * @param oldClassName previous class name to be removed
 * @param newClassName new class name to be added
 */
public static final void replaceDebugClass(
    Element elem, String oldClassName, String newClassName) {
  Preconditions.checkNotNull(elem, "replaceDebugClass: Element must not be null");
  if (debugClassEnabled) {
    Set<String> debugClasses = getDebugClasses(elem);
    boolean removed = debugClasses.remove(oldClassName);
    // if no change happened in the debugClasses, do nothing
    if (debugClasses.add(newClassName) || removed) {
      elem.setAttribute(DEBUG_CLASS_ATTRIBUTE, joinDebugClasses(debugClasses));
    }
  }
}
 
Example 11
Source File: DebugClassHelper.java    From swellrt with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a debug class to an Element.
 *
 * @param elem the object to modify
 * @param debugClass to be added
 */
public static final void addDebugClass(Element elem, String debugClass) {
  Preconditions.checkNotNull(elem, "addDebugClass: Element must not be null");
  if (debugClassEnabled) {
    Set<String> debugClasses = getDebugClasses(elem);
    if (debugClasses.add(debugClass)) {
      elem.setAttribute(DEBUG_CLASS_ATTRIBUTE, joinDebugClasses(debugClasses));
    }
  }
}
 
Example 12
Source File: DiffDeleteRenderer.java    From swellrt with Apache License 2.0 5 votes vote down vote up
@Override
public Element createDomImpl(Renderable element) {
  Element nodelet = Document.get().createSpanElement();
  DomHelper.makeUnselectable(nodelet);
  DomHelper.setContentEditable(nodelet, false, true);
  nodelet.setAttribute("class", DIFF_DELETE_CSS_CLASS);
  return element.setAutoAppendContainer(nodelet);
}
 
Example 13
Source File: DefaultDragMoveEventListener.java    From gwt-material-addins with Apache License 2.0 5 votes vote down vote up
@Override
public void register(InteractDragEvent event) {
    Element target = event.target;

    String dataX = target.getAttribute("data-x");
    String dataY = target.getAttribute("data-y");

    float dx = parseAttributeToFloat(dataX, event.dx);
    float dy = parseAttributeToFloat(dataY, event.dy);

    target.getStyle().setProperty("transform", "translate(" + dx + "px, " + dy + "px)");
    target.setAttribute("data-x", String.valueOf(dx));
    target.setAttribute("data-y", String.valueOf(dy));
}
 
Example 14
Source File: DomHelper.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
/**
 * Makes an element, and all its descendant elements, unselectable.
 */
public static void makeUnselectable(Element e) {
  if (UserAgent.isIE()) {
    e.setAttribute("unselectable", "on");
    e = e.getFirstChildElement();
    while (e != null) {
      makeUnselectable(e);
      e = e.getNextSiblingElement();
    }
  }
}
 
Example 15
Source File: Header.java    From core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void highlight(String name)
{
    toggleSubnavigation(name);

    com.google.gwt.user.client.Element target = linksPane.getElementById("header-links-ref");
    if(target!=null) // TODO: i think this cannot happen, does it?
    {
        NodeList<Node> childNodes = target.getChildNodes();
        for(int i=0; i<childNodes.getLength(); i++)
        {
            Node n = childNodes.getItem(i);
            if(Node.ELEMENT_NODE == n.getNodeType())
            {
                Element element = (Element) n;
                if(element.getId().equals("header-"+name))
                {
                    element.addClassName("header-link-selected");
                    element.setAttribute("aria-selected", "true");
                }
                else {
                    element.removeClassName("header-link-selected");
                    element.setAttribute("aria-selected", "false");
                }
            }
        }
    }
}
 
Example 16
Source File: DebugClassHelper.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a debug class to an Element.
 *
 * @param elem the object to modify
 * @param debugClass to be added
 */
public static final void addDebugClass(Element elem, String debugClass) {
  Preconditions.checkNotNull(elem, "addDebugClass: Element must not be null");
  if (debugClassEnabled) {
    Set<String> debugClasses = getDebugClasses(elem);
    if (debugClasses.add(debugClass)) {
      elem.setAttribute(DEBUG_CLASS_ATTRIBUTE, joinDebugClasses(debugClasses));
    }
  }
}
 
Example 17
Source File: MaterialDropDown.java    From gwt-material with Apache License 2.0 4 votes vote down vote up
public MaterialDropDown(Element activatorElement) {
    this();
    activatorElement.setAttribute("data-activates", getId());
    this.activatorElement = activatorElement;
}
 
Example 18
Source File: CubaLinkWidget.java    From cuba with Apache License 2.0 4 votes vote down vote up
public void setRel(String rel) {
    Element element = getElement().getFirstChildElement();
    element.setAttribute("rel", rel);
}
 
Example 19
Source File: DomHelper.java    From swellrt with Apache License 2.0 2 votes vote down vote up
/**
 * Sets the spell check attribute on the element.
 * @param enabled  true to enable spell check, false to disable.
 */
public static void setNativeSpellCheck(Element element, boolean enabled) {
  element.setAttribute("spellcheck", enabled ? "true" : "false");
}
 
Example 20
Source File: DomHelper.java    From incubator-retired-wave with Apache License 2.0 2 votes vote down vote up
/**
 * Sets the spell check attribute on the element.
 * @param enabled  true to enable spell check, false to disable.
 */
public static void setNativeSpellCheck(Element element, boolean enabled) {
  element.setAttribute("spellcheck", enabled ? "true" : "false");
}