elemental.dom.Element Java Examples
The following examples show how to use
elemental.dom.Element.
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: ResourceLoader.java From flow with Apache License 2.0 | 6 votes |
/** * Adds an onload listener to the given element, which should be a link or a * script tag. The listener is called whenever loading is complete or an * error occurred. * * @param element * the element to attach a listener to * @param listener * the listener to call * @param event * the event passed to the listener */ public static native void addOnloadHandler(Element element, ResourceLoadListener listener, ResourceLoadEvent event) /*-{ element.onload = $entry(function() { element.onload = null; element.onerror = null; element.onreadystatechange = null; [email protected]::onLoad(Lcom/vaadin/client/ResourceLoader$ResourceLoadEvent;)(event); }); element.onerror = $entry(function() { element.onload = null; element.onerror = null; element.onreadystatechange = null; [email protected]::onError(Lcom/vaadin/client/ResourceLoader$ResourceLoadEvent;)(event); }); element.onreadystatechange = function() { if ("loaded" === element.readyState || "complete" === element.readyState ) { element.onload(arguments[0]); } }; }-*/;
Example #2
Source File: SimpleElementBindingStrategy.java From flow with Apache License 2.0 | 6 votes |
private native void bindPolymerModelProperties(StateNode node, Element element) /*-{ if ( @com.vaadin.client.PolymerUtils::isPolymerElement(*)(element) ) { this.@SimpleElementBindingStrategy::hookUpPolymerElement(*)(node, element); } else if ( @com.vaadin.client.PolymerUtils::mayBePolymerElement(*)(element) ) { var self = this; try { $wnd.customElements.whenDefined(element.localName).then( function () { if ( @com.vaadin.client.PolymerUtils::isPolymerElement(*)(element) ) { self.@SimpleElementBindingStrategy::hookUpPolymerElement(*)(node, element); } }); } catch (e) { // ignore the exception: the element cannot be a custom element } } }-*/;
Example #3
Source File: SystemErrorHandler.java From flow with Apache License 2.0 | 6 votes |
/** * Shows an error notification for an error which is unrecoverable, using * the given parameters. * * @param caption * the caption of the message * @param message * the message body * @param details * message details or {@code null} if there are no details * @param url * a URL to redirect to when the user clicks the message or * {@code null} to refresh on click * @param querySelector * query selector to find the element under which the error will * be added . If element is not found or the selector is * {@code null}, body will be used */ public void handleUnrecoverableError(String caption, String message, String details, String url, String querySelector) { if (caption == null && message == null && details == null) { if (!isWebComponentMode()) { WidgetUtil.redirect(url); } return; } Element systemErrorContainer = handleError(caption, message, details, querySelector); if (!isWebComponentMode()) { systemErrorContainer.addEventListener("click", e -> WidgetUtil.redirect(url), false); Browser.getDocument().addEventListener(Event.KEYDOWN, e -> { int keyCode = ((KeyboardEvent) e).getKeyCode(); if (keyCode == KeyCode.ESC) { e.preventDefault(); WidgetUtil.redirect(url); } }, false); } }
Example #4
Source File: GwtBasicElementBinderTest.java From flow with Apache License 2.0 | 6 votes |
public void testVirtualChild() { Binder.bind(node, element); StateNode childNode = createChildNode("child"); NodeMap elementData = childNode.getMap(NodeFeatures.ELEMENT_DATA); JsonObject object = Json.createObject(); object.put(NodeProperties.TYPE, NodeProperties.IN_MEMORY_CHILD); elementData.getProperty(NodeProperties.PAYLOAD).setValue(object); NodeList virtialChildren = node.getList(NodeFeatures.VIRTUAL_CHILDREN); virtialChildren.add(0, childNode); Reactive.flush(); assertEquals(element.getChildElementCount(), 0); Element childElement = (Element) childNode.getDomNode(); assertEquals("SPAN", childElement.getTagName()); assertEquals("child", childElement.getId()); }
Example #5
Source File: GwtPolymerModelTest.java From flow with Apache License 2.0 | 6 votes |
private native void setupSetMethod(Element element) /*-{ element.set = function(path, newValue) { var split = path.split("."); var prop = element; for (var i = 0; i < split.length - 1; i++) { if (!prop) { break; } prop = prop[split[i]]; } if (prop) { prop[split[split.length - 1]] = newValue; } } }-*/;
Example #6
Source File: ElementUtil.java From flow with Apache License 2.0 | 6 votes |
/** * Searches the shadow root of the given context element for the given id or * searches the light DOM if the element has no shadow root. * * @param context * the container element to search through * @param id * the identifier of the element to search for * @return the element with the given {@code id} if found, otherwise * <code>null</code> */ public static native Element getElementById(Node context, String id) /*-{ if (document.body.$ && document.body.$[id]) { // Exported WCs add their id to body.$ and cannot be found using a real id attribute return document.body.$[id]; } else if (context.shadowRoot) { return context.shadowRoot.getElementById(id); } else if (context.getElementById) { return context.getElementById(id); } else if (id && id.match("^[a-zA-Z0-9-_]*$")) { // No funky characters in id so querySelector can be used directly return context.querySelector("#" + id); } else { // Find all elements with an id attribute and filter out the correct one return Array.from(context.querySelectorAll('[id]')).find(function(e) {return e.id == id}); } }-*/;
Example #7
Source File: FeatureHandler.java From ThinkMap with Apache License 2.0 | 6 votes |
private boolean handleMissing() { if (hasFailed) { DivElement el = Browser.getDocument().createDivElement(); el.getClassList().add("fade-background"); Browser.getDocument().getBody().appendChild(el); DivElement message = Browser.getDocument().createDivElement(); message.getClassList().add("center-message"); Element title = Browser.getDocument().createElement("h1"); title.setInnerHTML("Failed to start ThinkMap"); message.appendChild(title); for (String feature : missingFeatures) { Element header = Browser.getDocument().createElement("h2"); header.setInnerHTML(featureTitles.get(feature)); message.appendChild(header); ParagraphElement body = Browser.getDocument().createParagraphElement(); body.setInnerHTML(featureErrors.get(feature)); message.appendChild(body); } Browser.getDocument().getBody().appendChild(message); } return !hasFailed; }
Example #8
Source File: GwtMultipleBindingTest.java From flow with Apache License 2.0 | 6 votes |
private native void initPolymer(Element element) /*-{ $wnd.Polymer = function() {}; $wnd.Polymer.dom = function(node){ return node; }; $wnd.Polymer.Element = {}; element.__proto__ = $wnd.Polymer.Element; if( !element.removeAttribute ) { element.removeAttribute = function(attribute){ element[attribute] = null; }; } if ( !element.getAttribute ){ element.getAttribute = function( attribute ){ return element[attribute]; }; } if ( !element.setAttribute ){ element.setAttribute = function( attribute , value){ element[attribute] = value; }; } }-*/;
Example #9
Source File: GwtMultipleBindingTest.java From flow with Apache License 2.0 | 6 votes |
public void testBindModelPropertiesDoubleBind() { String name = "custom-div"; Element element = Browser.getDocument().createElement(name); WidgetUtil.setJsProperty(element, "localName", name); initPolymer(element); NativeFunction function = NativeFunction.create(""); WidgetUtil.setJsProperty(element, "set", function); Binder.bind(node, element); node.getMap(NodeFeatures.ELEMENT_PROPERTIES).getProperty("foo") .setValue("bar"); Reactive.flush(); node.setBound(); Binder.bind(node, element); }
Example #10
Source File: SimpleElementBindingStrategy.java From flow with Apache License 2.0 | 6 votes |
private void updateProperty(MapProperty mapProperty, Element element) { String name = mapProperty.getName(); if (mapProperty.hasValue()) { Object treeValue = mapProperty.getValue(); Object domValue = WidgetUtil.getJsProperty(element, name); // We compare with the current property to avoid setting properties // which are updated on the client side, e.g. when synchronizing // properties to the server (won't work for readonly properties). if (WidgetUtil.isUndefined(domValue) || !Objects.equals(domValue, treeValue)) { Reactive.runWithComputation(null, () -> WidgetUtil.setJsProperty(element, name, PolymerUtils.createModelTree(treeValue))); } } else if (WidgetUtil.hasOwnJsProperty(element, name)) { WidgetUtil.deleteJsProperty(element, name); } else { // Can't delete inherited property, so instead just clear // the value WidgetUtil.setJsProperty(element, name, null); } }
Example #11
Source File: AnotherTest.java From vertxui with GNU General Public License v3.0 | 6 votes |
private void printStructure(Element element) { console.log("<" + element.getNodeName()); NamedNodeMap attributes = element.getAttributes(); if (attributes != null) { for (int x = 0; x < attributes.length(); x++) { Node attr = attributes.item(x); console.log(" " + attr.getNodeName() + "=" + attr.getNodeValue()); } } console.log(">"); if (element.getTextContent() != null) { console.log(element.getTextContent()); } NodeList children = element.getChildNodes(); for (int x = 0; x < children.getLength(); x++) { printStructure((Element) children.at(x)); } console.log("</" + element.getNodeName() + ">"); }
Example #12
Source File: DomApiAbstractionUsageTest.java From flow with Apache License 2.0 | 6 votes |
private static void verifyMethod(String callingMethod, String targetClassName, String targetMethod) { // Won't care about overhead of loading all // classes since this is just a test Class<?> targetClass = getClass(targetClassName); if (!Node.class.isAssignableFrom(targetClass)) { return; } if (ignoredElementalClasses.contains(targetClass)) { return; } if ((Element.class == targetClass || Node.class == targetClass) && ignoredElementMethods.contains(targetMethod)) { return; } Assert.fail(callingMethod + " calls " + targetClass.getName() + "." + targetMethod); }
Example #13
Source File: GwtBasicElementBinderTest.java From flow with Apache License 2.0 | 6 votes |
private void assertDeferredPolymerElement_originalReadyIsCalled( Element element) { initPolymer(element); mockWhenDefined(element); NativeFunction function = NativeFunction.create("this['foo']='bar';"); WidgetUtil.setJsProperty(element, "ready", function); Binder.bind(node, element); runWhenDefined(element); NativeFunction readyCall = new NativeFunction("this.ready();"); readyCall.call(element); assertEquals("bar", WidgetUtil.getJsProperty(element, "foo")); }
Example #14
Source File: GwtRouterLinkHandlerTest.java From flow with Apache License 2.0 | 5 votes |
public void testRouterLink_altClick_eventNotIntercepted() { currentEvent = null; assertInvocations(0); Element target = createTarget("a", "foobar", true); boundElement.appendChild(target); fireClickEvent(target, true, false, false, false); assertInvocations(0); assertEventDefaultNotPrevented(); }
Example #15
Source File: ExecuteJavaScriptElementUtils.java From flow with Apache License 2.0 | 5 votes |
private static Integer getExistingIdOrUpdate(StateNode parent, int serverSideId, Element existingElement, Integer existingId) { if (existingId == null) { ExistingElementMap map = parent.getTree().getRegistry() .getExistingElementMap(); Integer fromMap = map.getId(existingElement); if (fromMap == null) { map.add(serverSideId, existingElement); return serverSideId; } return fromMap; } return existingId; }
Example #16
Source File: Elements.java From core with GNU Lesser General Public License v2.1 | 5 votes |
/** * Returns the element which was stored using {@link #rememberAs(String)}. * * @throws NoSuchElementException if no element was stored under that id. */ @SuppressWarnings("unchecked") public <T extends Element> T referenceFor(String id) { if (!references.containsKey(id)) { throw new NoSuchElementException("No element reference found for '" + id + "'"); } return (T) references.get(id); }
Example #17
Source File: Elements.java From core with GNU Lesser General Public License v2.1 | 5 votes |
/** * Adds the given event listener to the the last added element. */ public Builder on(EventType type, EventListener listener) { assertCurrent(); Element element = elements.peek().element; type.register(element, listener); return this; }
Example #18
Source File: GwtBasicElementBinderTest.java From flow with Apache License 2.0 | 5 votes |
private native void mockWhenDefined(Element element) /*-{ $wnd.OldPolymer = $wnd.Polymer; $wnd.Polymer = null; $wnd.customElements = { whenDefined: function() { return { then: function (callback) { element.callback = callback; } } } }; }-*/;
Example #19
Source File: Elements.java From core with GNU Lesser General Public License v2.1 | 5 votes |
/** * Removes all child elements from {@code element} */ public static void removeChildrenFrom(final Element element) { if (element != null) { while (element.getFirstChild() != null) { element.removeChild(element.getFirstChild()); } } }
Example #20
Source File: GwtPolymerModelTest.java From flow with Apache License 2.0 | 5 votes |
private native void addMockMethods(Element element) /*-{ element.propertiesChangedCallCount = 0; element._propertiesChanged = function() { element.propertiesChangedCallCount += 1; }; element.callbackCallCount = 0; $wnd.customElements = { whenDefined: function() { return { then: function (callback) { $wnd.Polymer = $wnd.OldPolymer; element.callbackCallCount += 1; callback(); } } } }; if( !element.removeAttribute ) { element.removeAttribute = function(attribute){ element[attribute] = null; }; } if ( !element.getAttribute ){ element.getAttribute = function( attribute ){ return element[attribute]; }; } if ( !element.setAttribute ){ element.setAttribute = function( attribute, value ){ element[attribute] = value; }; } }-*/;
Example #21
Source File: DefaultReconnectDialog.java From flow with Apache License 2.0 | 5 votes |
/** * Creates a new instance. */ public DefaultReconnectDialog() { root = Browser.getDocument().createElement("div"); root.setClassName("v-reconnect-dialog"); Element spinner = Browser.getDocument().createElement("div"); spinner.setClassName("spinner"); label = Browser.getDocument().createElement("span"); label.setClassName("text"); root.appendChild(spinner); root.appendChild(label); }
Example #22
Source File: GwtStateTreeTest.java From flow with Apache License 2.0 | 5 votes |
private static native boolean createMockPromise(Element element) /*-{ var eventObject = element.$server["}p"]; eventObject.promiseResult = null; eventObject.promises[0] = [function() { eventObject.promiseResult = true; },function() { eventObject.promiseResult = false; }]; }-*/;
Example #23
Source File: GwtBasicElementBinderTest.java From flow with Apache License 2.0 | 5 votes |
public void testVirtualBindChild_noCorrespondingElementInShadowRoot_searchById() { Element shadowRootElement = addShadowRootElement(element); String childId = "childElement"; String tag = "a"; StateNode child = createChildNode(childId, tag); addVirtualChild(node, child, NodeProperties.INJECT_BY_ID, Json.create(childId)); Element elementWithDifferentId = createAndAppendElementToShadowRoot( shadowRootElement, "otherId", tag); assertNotSame( "Element added to shadow root should not have same id as virtual child node", childId, elementWithDifferentId.getId()); Binder.bind(node, element); Reactive.flush(); assertEquals( "Unexpected 'sendExistingElementWithIdAttachToServer' method call number", 4, tree.existingElementRpcArgs.size()); assertEquals( "Unexpected requested node id value argument in the 'sendExistingElementWithIdAttachToServer' method call", node, tree.existingElementRpcArgs.get(0)); assertEquals( "Unexpected requested node id value argument in the 'sendExistingElementWithIdAttachToServer' method call", child.getId(), tree.existingElementRpcArgs.get(1)); assertEquals( "Unexpected attached node id value argument in the 'sendExistingElementWithIdAttachToServer' method call", -1, tree.existingElementRpcArgs.get(2)); assertEquals( "Unexpected identifier value argument in the 'sendExistingElementWithIdAttachToServer' method call", childId, tree.existingElementRpcArgs.get(3)); }
Example #24
Source File: PolymerUtils.java From flow with Apache License 2.0 | 5 votes |
/** * Fires the ready event for the {@code polymerElement}. * * @param polymerElement * the custom (polymer) element whose state is "ready" */ public static void fireReadyEvent(Element polymerElement) { if (readyListeners == null) { return; } JsSet<Runnable> listeners = readyListeners.get(polymerElement); if (listeners != null) { readyListeners.delete(polymerElement); listeners.forEach(Runnable::run); } }
Example #25
Source File: ChildrenIterator.java From core with GNU Lesser General Public License v2.1 | 5 votes |
@Override public Element next() { if (!hasNext()) { throw new NoSuchElementException(); } Element child = (Element) children.item(index); index++; return child; }
Example #26
Source File: GwtEventHandlerTest.java From flow with Apache License 2.0 | 5 votes |
/** * Add a function to the element prototype ("default" function) for * {@code methodName} that adds the second argument to the event (first * argument) as a result * * @param element * Element to add "default" method to * @param methodName * Name of event to add method to */ private native void setPrototypeEventHandler(Element element, String methodName) /*-{ Object.getPrototypeOf(element)[methodName] = function(event) { if(this !== element) { throw "This and target element didn't match"; }; event.result = arguments[1]; } }-*/;
Example #27
Source File: GwtBasicElementBinderTest.java From flow with Apache License 2.0 | 5 votes |
public void testVirtualBindChild_wrongTag_searchById() { Element shadowRootElement = addShadowRootElement(element); String childId = "childElement"; StateNode child = createChildNode(childId, "a"); addVirtualChild(node, child, NodeProperties.INJECT_BY_ID, Json.create(childId)); Element elementWithDifferentId = createAndAppendElementToShadowRoot( shadowRootElement, "otherId", "div"); assertNotSame( "Element added to shadow root should not have same id as virtual child node", childId, elementWithDifferentId.getId()); Binder.bind(node, element); Reactive.flush(); assertEquals( "Unexpected 'sendExistingElementWithIdAttachToServer' method call number", 4, tree.existingElementRpcArgs.size()); assertEquals( "Unexpected node argument in the 'sendExistingElementWithIdAttachToServer' method call", node, tree.existingElementRpcArgs.get(0)); assertEquals( "Unexpected requested node id value argument in the 'sendExistingElementWithIdAttachToServer' method call", child.getId(), tree.existingElementRpcArgs.get(1)); assertEquals( "Unexpected attached node id value argument in the 'sendExistingElementWithIdAttachToServer' method call", -1, tree.existingElementRpcArgs.get(2)); assertEquals( "Unexpected identifier value argument in the 'sendExistingElementWithIdAttachToServer' method call", childId, tree.existingElementRpcArgs.get(3)); }
Example #28
Source File: GwtRouterLinkHandlerTest.java From flow with Apache License 2.0 | 5 votes |
public void testRouterLink_anchorWithRouterLink_ui_stopped() { currentEvent = null; assertInvocations(0); registry.getUILifecycle().setState(UIState.TERMINATED); Element target = createTarget("a", "foobar", true); boundElement.appendChild(target); fireClickEvent(target); assertInvocations(0); assertEventDefaultNotPrevented(); }
Example #29
Source File: GwtPolymerModelTest.java From flow with Apache License 2.0 | 5 votes |
private native void emulatePolymerPropertyChange(Element element, String propertyName, String newPropertyValue) /*-{ var changedProperties = {}; changedProperties[propertyName] = newPropertyValue; element._propertiesChanged({}, changedProperties, {}); }-*/;
Example #30
Source File: GwtEventHandlerTest.java From flow with Apache License 2.0 | 5 votes |
private JsArray<String> getPublishedServerMethods(Element element) { ServerEventObject serverEventObject = WidgetUtil .crazyJsoCast(WidgetUtil.getJsProperty(element, "$server")); if (serverEventObject == null) { return JsCollections.array(); } else { return serverEventObject.getMethods(); } }