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

The following examples show how to use com.google.gwt.dom.client.Element#getAttribute() . 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: JsFacade.java    From actor-platform with GNU Affero General Public License v3.0 6 votes vote down vote up
@UsedByApp
public void handleLinkClick(Event event) {
    Element target = Element.as(event.getEventTarget());
    String href = target.getAttribute("href");
    if (href.startsWith("send:")) {
        String msg = href.substring("send:".length());
        msg = URL.decode(msg);
        if (lastVisiblePeer != null) {
            messenger.sendMessage(lastVisiblePeer, msg);
            event.preventDefault();
        }
    } else {
        if (JsElectronApp.isElectron()) {
            JsElectronApp.openUrlExternal(href);
            event.preventDefault();
        }
    }
}
 
Example 2
Source File: BlipMetaDomImpl.java    From incubator-retired-wave with Apache License 2.0 6 votes vote down vote up
public StringSequence getInlineLocators() {
  if (inlineLocators == null) {
    Element content = getContentContainer().getFirstChildElement();
    if (content != null) {
      inlineLocators = (StringSequence) content.getPropertyObject(INLINE_LOCATOR_PROPERTY);
      if (inlineLocators == null) {
        // Note: getAttribute() of a missing attribute does not return null on
        // all browsers.
        if (content.hasAttribute(INLINE_LOCATOR_ATTRIBUTE)) {
          String serial = content.getAttribute(INLINE_LOCATOR_ATTRIBUTE);
          inlineLocators = StringSequence.create(serial);
        } else {
          inlineLocators = StringSequence.create();
        }
        content.setPropertyObject(INLINE_LOCATOR_PROPERTY, inlineLocators);
      }
    } else {
      // Leave inlineLocators as null, since the document is not here yet.
    }
  }
  return inlineLocators;
}
 
Example 3
Source File: BlipMetaDomImpl.java    From swellrt with Apache License 2.0 6 votes vote down vote up
public StringSequence getInlineLocators() {
  if (inlineLocators == null) {
    Element content = getContentContainer().getFirstChildElement();
    if (content != null) {
      inlineLocators = (StringSequence) content.getPropertyObject(INLINE_LOCATOR_PROPERTY);
      if (inlineLocators == null) {
        // Note: getAttribute() of a missing attribute does not return null on
        // all browsers.
        if (content.hasAttribute(INLINE_LOCATOR_ATTRIBUTE)) {
          String serial = content.getAttribute(INLINE_LOCATOR_ATTRIBUTE);
          inlineLocators = StringSequence.create(serial);
        } else {
          inlineLocators = StringSequence.create();
        }
        content.setPropertyObject(INLINE_LOCATOR_PROPERTY, inlineLocators);
      }
    } else {
      // Leave inlineLocators as null, since the document is not here yet.
    }
  }
  return inlineLocators;
}
 
Example 4
Source File: FinderColumn.java    From core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private ButtonRef resolveActionAttribute(Element element) {
    if(!element.hasAttribute("action"))
    {
        if(element.hasParentElement())
            return resolveActionAttribute(element.getParentElement());
        else
            new ButtonRef("unresolved", element);
    }
    return new ButtonRef(element.getAttribute("action"), element);
}
 
Example 5
Source File: ClientUtils.java    From proarc with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Dumps Element content and traverse its children.
 * <p/><b>WARNING:</b> it is com.google.gwt.dom.client.Element not com.google.gwt.xml.client.Element!!!
 * 
 * @param elm an element to dump
 * @param indent row indentation for current level
 * @param indentIncrement increment for next level
 * @param sb dumped content
 * @return dumped content
 */
public static StringBuilder dump(Element elm, String indent, String indentIncrement, StringBuilder sb) {
    int childCount = elm.getChildCount();
    String innerText = elm.getInnerText();
    String lang = elm.getLang();
    String nodeName = elm.getNodeName();
    short nodeType = elm.getNodeType();
    String getString = elm.getString();
    String tagNameWithNS = elm.getTagName();
    String xmlLang = elm.getAttribute("xml:lang");

    sb.append(ClientUtils.format("%sElement {nodeName: %s, nodeType: %s, tagNameWithNS: %s, lang: %s,"
            + " childCount: %s, getString: %s, xmlLang: %s}\n",
            indent, nodeName, nodeType, tagNameWithNS, lang, childCount, getString, xmlLang));
    NodeList<Node> childNodes = elm.getChildNodes();
    indent += indentIncrement;
    for (int i = 0; i < childNodes.getLength(); i++) {
        Node child = childNodes.getItem(i);
        if (Element.is(child)) {
            dump(Element.as(child), indent, indentIncrement, sb);
        } else {
            sb.append(ClientUtils.format("%sNode: nodeType: %s, nodeName: %s, childCount: %s, nodeValue: %s\n",
                    indent, child.getNodeType(), child.getNodeName(), child.getChildCount(), child.getNodeValue()));
        }
    }
    return sb;
}
 
Example 6
Source File: FullStructure.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
/** @return the view type of an element. */
private Type typeOf(Element e) {
  Type type = e.hasAttribute(KIND_ATTRIBUTE) ? type(e.getAttribute(KIND_ATTRIBUTE)) : null;
  if (type == null) {
    throw new RuntimeException("element has no known kind: " + e.getAttribute(KIND_ATTRIBUTE));
  } else {
    return type;
  }
}
 
Example 7
Source File: DebugClassHelper.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
/**
 * Get a set of debug classes present in an element.
 * @param elem from which debug classes will be read from
 * @return the set of debug classes
 */
private static final Set<String> getDebugClasses(Element elem) {
  Set<String> result = new HashSet<String>();
  String debugClasses = elem.getAttribute(DEBUG_CLASS_ATTRIBUTE);
  result.addAll(Arrays.asList(debugClasses.split(" ")));
  return result;
}
 
Example 8
Source File: StructureView.java    From openchemlib-js with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void draw() {
    Element el = canvas.getCanvasElement();
    String idcode = el.getAttribute("data-idcode");
    String text = el.getAttribute("data-text");
    String[] at = text != null ? text.split(",") : null;
    Context2d ctx = canvas.getContext2d();
    drawMolecule(ctx, idcode, canvas.getCoordinateSpaceWidth(), canvas.getCoordinateSpaceHeight(), 0, at);
}
 
Example 9
Source File: StructureView.java    From openchemlib-js with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static String getIDCode(String id) {
    Element el = Document.get().getElementById(id);
    if (el instanceof CanvasElement) {
        return el.getAttribute("data-idcode");
    }
    return null;
}
 
Example 10
Source File: SvgArrowWidget.java    From gantt with Apache License 2.0 5 votes vote down vote up
protected void addStyleName(Element element, String style) {
    String curStyles = element.getAttribute("class");
    if (curStyles == null) {
        curStyles = "";
    }
    if (!curStyles.contains(style)) {
        curStyles += " " + style;
        element.setAttribute("class", curStyles);
    }
}
 
Example 11
Source File: InputDatePicker.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onBrowserEvent(Event event) {
	int type = event.getTypeInt();
	Element target = event.getCurrentTarget();
	if (type == Event.ONCLICK) {
		String dataDate = target.getAttribute(InputDatePicker.ATTRIBUTE_DATA_DATE);
		String dataCursor = target.getAttribute(InputDatePicker.ATTRIBUTE_DATA_CURSOR);
		String dataYear = target.getAttribute(InputDatePicker.ATTRIBUTE_DATA_YEAR);
		if (dataDate != null && dataDate.length() > 0) {
			this.mode = Mode.CALENDAR;
			this.setValue(InputDatePicker.ATTRIBUTE_DATE_FORMAT.parse(dataDate), true);
		} else if (dataCursor != null && dataCursor.length() > 0) {
			this.mode = Mode.CALENDAR;
			this.cursor = InputDatePicker.ATTRIBUTE_DATE_FORMAT.parse(dataCursor);
			this.redraw();
		} else if (dataYear != null && dataYear.length() > 0) {
			this.openMonthOfYear(Integer.valueOf(dataYear));
		} else if (target == this.monthPickerButton) {
			if (this.mode != Mode.MONTH) {
				this.mode = Mode.MONTH;
			} else {
				this.mode = Mode.CALENDAR;
			}
			this.redraw();
		}
		event.stopPropagation();
		event.preventDefault();
	} else if (type == Event.ONKEYDOWN) {
		this.handleKeyPress(event.getKeyCode());
		event.stopPropagation();
		event.preventDefault();
	} else {
		super.onBrowserEvent(event);
	}
}
 
Example 12
Source File: FullStructure.java    From swellrt with Apache License 2.0 5 votes vote down vote up
/** @return the view type of an element. */
private Type typeOf(Element e) {
  Type type = e.hasAttribute(KIND_ATTRIBUTE) ? type(e.getAttribute(KIND_ATTRIBUTE)) : null;
  if (type == null) {
    throw new RuntimeException("element has no known kind: " + e.getAttribute(KIND_ATTRIBUTE));
  } else {
    return type;
  }
}
 
Example 13
Source File: DebugClassHelper.java    From swellrt with Apache License 2.0 5 votes vote down vote up
/**
 * Get a set of debug classes present in an element.
 * @param elem from which debug classes will be read from
 * @return the set of debug classes
 */
private static final Set<String> getDebugClasses(Element elem) {
  Set<String> result = new HashSet<String>();
  String debugClasses = elem.getAttribute(DEBUG_CLASS_ATTRIBUTE);
  result.addAll(Arrays.asList(debugClasses.split(" ")));
  return result;
}
 
Example 14
Source File: WidgetDoodad.java    From swellrt with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to get a native view of widget based on its DOM element or descendant.
 * 
 * @param doc the mutable document
 * @param domElement the widget element or a descendant
 */
public static JsoWidget getWidget(CMutableDocument doc, Element domElement) {

 Element widgetDomElement = getWidgetElementUp(domElement);
 if (widgetDomElement == null)
  return null;

 String widgetId = widgetDomElement.getAttribute(ATTR_ID);
 ContentElement widgetElement = DocHelper.findElementById(doc, doc.getDocumentElement(), widgetId);

 if (widgetElement == null) 
  return null;
 		  
 return JsoWidget.create(widgetElement.getImplNodelet(), widgetElement);
}
 
Example 15
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 16
Source File: HtmlViewImpl.java    From swellrt with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
public String getAttribute(Element element, String name) {
  return name.equals("class") ? element.getClassName() : element.getAttribute(name);
}
 
Example 17
Source File: HtmlViewImpl.java    From incubator-retired-wave with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
public String getAttribute(Element element, String name) {
  return name.equals("class") ? element.getClassName() : element.getAttribute(name);
}