elemental2.dom.DomGlobal Java Examples

The following examples show how to use elemental2.dom.DomGlobal. 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: MapTest.java    From gwty-leaflet with Apache License 2.0 6 votes vote down vote up
public void testMapPan(){
	InjectedLeafletResources.whenReady((e) -> {
			 HTMLElement div = (HTMLElement) DomGlobal.document.createElement("div");
			    div.id = "test4";
			    DomGlobal.document.body.appendChild(div);
			      MapOptions options = new MapOptions.Builder(L.latLng(52.51, 13.40), 12.0, 7.0).maxZoom(20.0).build();
				Map map = L.map("test4", options);

				assertNotNull(map);
				map.panTo(L.latLng(51.51, 13.80), null);
				assertEquals(map.getCenter().lat, 51.51);
				assertEquals(map.getCenter().lng, 13.80);
				
				return null;
	});
}
 
Example #2
Source File: MapTest.java    From gwty-leaflet with Apache License 2.0 6 votes vote down vote up
public void testMapZoom(){
	InjectedLeafletResources.whenReady((e) -> {
			 HTMLElement div = (HTMLElement) DomGlobal.document.createElement("div");
			    div.id = "test3";
			    DomGlobal.document.body.appendChild(div);
			      MapOptions options = new MapOptions.Builder(L.latLng(52.51, 13.40), 12.0, 7.0).dragging(true).maxZoom(20.0).build();
				Map map = L.map("test3", options);
				
				assertNotNull(map);
				assertEquals(String.valueOf(map.getZoom()), "12");
			    assertEquals(String.valueOf(map.getMinZoom()), "7");
    				assertEquals(String.valueOf(map.getMaxZoom()), "20");
    				
    				//Zoom In method has weird behavior *** Fails
    				map.zoomOut(5.0, null);
    				assertEquals("7", map.getZoom().toString());
				
				return null;
	});
}
 
Example #3
Source File: NaluPluginElemento.java    From nalu with Apache License 2.0 6 votes vote down vote up
@Override
public boolean attach(String selector,
                      Object content) {
  Element selectorElement = DomGlobal.document.querySelector("#" + selector);
  if (selectorElement == null) {
    return false;
  } else {
    if (content instanceof Iterable) {
      Iterable<?> elements = (Iterable<?>) content;
      for (Object element : elements) {
        if (element instanceof IsElement) {
          selectorElement.appendChild(((IsElement<?>) element).element());
        } else if (element instanceof HTMLElement) {
          selectorElement.appendChild(((HTMLElement) element));
        }
      }
    } else if (content instanceof IsElement) {
      selectorElement.appendChild(((IsElement<?>) content).element());
    } else if (content instanceof HTMLElement) {
      selectorElement.appendChild(((HTMLElement) content));
    }
    return true;
  }
}
 
Example #4
Source File: MarkerTest.java    From gwty-leaflet with Apache License 2.0 6 votes vote down vote up
public void testMarkeradd(){
	InjectedLeafletResources.whenReady((e) -> {
			 HTMLElement div = (HTMLElement) DomGlobal.document.createElement("div");
			    div.id = "test6";
			    DomGlobal.document.body.appendChild(div);
			   
				Map map = L.map("test6", null);
				MarkerOptions mkOptions = new MarkerOptions.Builder().build();
                   Marker marker = L.marker(L.latLng(52.51, 13.40), mkOptions);
                   marker.addTo(map);
                   
				assertNotNull(map);
				assertNotNull(marker);
				
				assertEquals(marker.getLatLng().lat, 52.51);
				assertEquals(marker.getLatLng().lng, 13.40);
				
				return null;
	});
}
 
Example #5
Source File: NaluPluginElemento.java    From nalu with Apache License 2.0 6 votes vote down vote up
@Override
public void updateMetaNameContent(String name,
                                  String content) {
  NodeList<Element> metaTagList = DomGlobal.document.getElementsByTagName("meta");
  for (int i = 0; i < metaTagList.length; i++) {
    if (metaTagList.item(i) instanceof HTMLMetaElement) {
      HTMLMetaElement nodeListElement = (HTMLMetaElement) metaTagList.item(i);
      if (!Objects.isNull(nodeListElement.name)) {
        if (nodeListElement.name.equals(name)) {
          nodeListElement.remove();
          break;
        }
      }
    }
  }
  HTMLMetaElement metaTagElement = (HTMLMetaElement) DomGlobal.document.createElement("meta");
  metaTagElement.name = name;
  metaTagElement.content = content;
  DomGlobal.document.head.appendChild(metaTagElement);
}
 
Example #6
Source File: NaluPluginElemento.java    From nalu with Apache License 2.0 6 votes vote down vote up
@Override
public void updateMetaPropertyContent(String property,
                                      String content) {
  NodeList<Element> metaTagList = DomGlobal.document.getElementsByTagName("meta");
  for (int i = 0; i < metaTagList.length; i++) {
    if (metaTagList.item(i) instanceof HTMLMetaElement) {
      HTMLMetaElement nodeListElement = (HTMLMetaElement) metaTagList.item(i);
      if (!Objects.isNull(nodeListElement.getAttribute("property"))) {
        if (nodeListElement.getAttribute("property")
                           .equals(property)) {
          nodeListElement.remove();
          break;
        }
      }
    }
  }
  HTMLMetaElement metaElement = (HTMLMetaElement) DomGlobal.document.createElement("meta");
  metaElement.setAttribute("property",
                           property);
  metaElement.content = content;
  DomGlobal.document.head.appendChild(metaElement);
}
 
Example #7
Source File: LeafletResources.java    From gwty-leaflet with Apache License 2.0 6 votes vote down vote up
public static void whenReady(boolean debug, Element.OnloadFn function){
	HTMLScriptElement leafletScript = (HTMLScriptElement) DomGlobal.document.createElement("script");
	if (debug) {
		leafletScript.src = GWT.getModuleName() + "/leaflet/leaflet-src.js";
	} else {
		leafletScript.src = GWT.getModuleName() + "/leaflet/leaflet.js";
	}
	leafletScript.type="text/javascript";
	
	HTMLLinkElement leafletStyle = (HTMLLinkElement) DomGlobal.document.createElement("link");
	leafletStyle.href=GWT.getModuleName()+"/leaflet/leaflet.css";
	leafletStyle.rel="stylesheet";
	
	
	DomGlobal.document.head.appendChild(leafletScript);
	DomGlobal.document.head.appendChild(leafletStyle);
	
	leafletScript.onload = function;
}
 
Example #8
Source File: NaluPluginElemental2.java    From nalu with Apache License 2.0 6 votes vote down vote up
@Override
public void updateMetaPropertyContent(String property,
                                      String content) {
  NodeList<Element> metaTagList = DomGlobal.document.getElementsByTagName("meta");
  for (int i = 0; i < metaTagList.length; i++) {
    if (metaTagList.item(i) instanceof HTMLMetaElement) {
      HTMLMetaElement nodeListElement = (HTMLMetaElement) metaTagList.item(i);
      if (!Objects.isNull(nodeListElement.getAttribute("property"))) {
        if (nodeListElement.getAttribute("property")
                           .equals(property)) {
          nodeListElement.remove();
          break;
        }
      }
    }
  }
  HTMLMetaElement metaElement = (HTMLMetaElement) DomGlobal.document.createElement("meta");
  metaElement.setAttribute("property",
                           property);
  metaElement.content = content;
  DomGlobal.document.head.appendChild(metaElement);
}
 
Example #9
Source File: NaluPluginElemental2.java    From nalu with Apache License 2.0 6 votes vote down vote up
@Override
public void updateMetaNameContent(String name,
                                  String content) {
  NodeList<Element> metaTagList = DomGlobal.document.getElementsByTagName("meta");
  for (int i = 0; i < metaTagList.length; i++) {
    if (metaTagList.item(i) instanceof HTMLMetaElement) {
      HTMLMetaElement nodeListElement = (HTMLMetaElement) metaTagList.item(i);
      if (!Objects.isNull(nodeListElement.name)) {
        if (nodeListElement.name.equals(name)) {
          nodeListElement.remove();
          break;
        }
      }
    }
  }
  HTMLMetaElement metaTagElement = (HTMLMetaElement) DomGlobal.document.createElement("meta");
  metaTagElement.name = name;
  metaTagElement.content = content;
  DomGlobal.document.head.appendChild(metaTagElement);
}
 
Example #10
Source File: NaluPluginElemental2.java    From nalu with Apache License 2.0 5 votes vote down vote up
@Override
public void confirm(String message,
                    ConfirmHandler handler) {
  if (customConfirmPresenter == null) {
    if (DomGlobal.window.confirm(message)) {
      handler.onOk();
    } else {
      handler.onCancel();
    }
  } else {
    customConfirmPresenter.addConfirmHandler(handler);
    customConfirmPresenter.confirm(message);
  }
}
 
Example #11
Source File: MapTest.java    From gwty-leaflet with Apache License 2.0 5 votes vote down vote up
public void testMapView(){
	InjectedLeafletResources.whenReady((e) -> {
			     HTMLElement div = (HTMLElement) DomGlobal.document.createElement("div");
			    div.id = "test2";
			    DomGlobal.document.body.appendChild(div);
			    
				Map map = L.map("test2", null);
				map.setView(L.latLng(52.51, 13.40), 12.0, null);
				assertNotNull(map);
				assertEquals(map.getCenter().lat, 52.51);
				assertEquals(map.getCenter().lng, 13.40);
				
				return null;
	});
}
 
Example #12
Source File: MapTest.java    From gwty-leaflet with Apache License 2.0 5 votes vote down vote up
public void testMapRemove(){
	InjectedLeafletResources.whenReady((e) -> {
			 HTMLElement div = (HTMLElement) DomGlobal.document.createElement("div");
			    div.id = "test5";
			    DomGlobal.document.body.appendChild(div);
			      MapOptions options = new MapOptions.Builder(L.latLng(52.51, 13.40), 12.0, 7.0).maxZoom(20.0).build();
				Map map = L.map("test5", options);

				assertNotNull(map);
				map.remove();
			
				
				return null;
	});
}
 
Example #13
Source File: MapTest.java    From gwty-leaflet with Apache License 2.0 5 votes vote down vote up
public void testMapCreateWithHTMLElement(){
	InjectedLeafletResources.whenReady((e) -> {
			HTMLElement mapContainer = (HTMLElement) DomGlobal.document.createElement("div");
            Map map = L.map(mapContainer, null);
			assertNotNull(map);
			return null;
	});
}
 
Example #14
Source File: MapTest.java    From gwty-leaflet with Apache License 2.0 5 votes vote down vote up
public void testMapCreateWithId(){
	
	InjectedLeafletResources.whenReady((e) -> {
		    HTMLElement div = (HTMLElement) DomGlobal.document.createElement("div");
		    div.id = "test";
		    DomGlobal.document.body.appendChild(div);
		    
			Map map = L.map("test", null);
			assertNotNull(map);
			return null;
	});
}
 
Example #15
Source File: InjectedLeafletResources.java    From gwty-leaflet with Apache License 2.0 5 votes vote down vote up
public static void whenReady(Element.OnloadFn function){
	HTMLScriptElement leafletScript = (HTMLScriptElement) DomGlobal.document.createElement("script");
	leafletScript.src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0/leaflet.js";
	leafletScript.type="text/javascript";
	DomGlobal.document.head.appendChild(leafletScript);		
	leafletScript.onload = function;
}
 
Example #16
Source File: DefaultElemental2Logger.java    From nalu with Apache License 2.0 5 votes vote down vote up
@Override
public void log(String message,
                int depth) {
  if (NaluPluginCoreWeb.isSuperDevMode()) {
    DomGlobal.window.console.log(createLog(message,
                                           depth));
  }
}
 
Example #17
Source File: NaluPluginElemental2.java    From nalu with Apache License 2.0 5 votes vote down vote up
@Override
public void remove(String selector) {
  Element selectorElement = DomGlobal.document.querySelector("#" + selector);
  if (selectorElement != null) {
    if (selectorElement.childNodes.length > 0) {
      for (int i = selectorElement.childNodes.asList()
                                             .size() - 1; i > -1; i--) {
        selectorElement.removeChild(selectorElement.childNodes.asList()
                                                              .get(i));
      }
    }
  }
}
 
Example #18
Source File: NaluPluginElemental2.java    From nalu with Apache License 2.0 5 votes vote down vote up
@Override
public boolean attach(String selector,
                      Object asElement) {
  Element selectorElement = DomGlobal.document.querySelector("#" + selector);
  if (selectorElement == null) {
    return false;
  } else {
    selectorElement.appendChild((HTMLElement) asElement);
    return true;
  }
}
 
Example #19
Source File: NaluPluginElemental2.java    From nalu with Apache License 2.0 5 votes vote down vote up
@Override
public void alert(String message) {
  if (customAlertPresenter == null) {
    DomGlobal.window.alert(message);
  } else {
    this.customAlertPresenter.alert(message);
  }
}
 
Example #20
Source File: DefaultElementoLogger.java    From nalu with Apache License 2.0 5 votes vote down vote up
public void log(String message,
                int depth) {
  if (NaluPluginCoreWeb.isSuperDevMode()) {
    DomGlobal.window.console.log(createLog(message,
                                           depth));
  }
}
 
Example #21
Source File: NaluPluginElemento.java    From nalu with Apache License 2.0 5 votes vote down vote up
@Override
public void remove(String selector) {
  Element selectorElement = DomGlobal.document.querySelector("#" + selector);
  if (selectorElement != null) {
    if (selectorElement.childNodes.length > 0) {
      for (int i = selectorElement.childNodes.asList()
                                             .size() - 1; i > -1; i--) {
        selectorElement.removeChild(selectorElement.childNodes.asList()
                                                              .get(i));
      }
    }
  }
}
 
Example #22
Source File: NaluPluginElemento.java    From nalu with Apache License 2.0 5 votes vote down vote up
@Override
public void confirm(String message,
                    ConfirmHandler handler) {
  if (customConfirmPresenter == null) {
    if (DomGlobal.window.confirm(message)) {
      handler.onOk();
    } else {
      handler.onCancel();
    }
  } else {
    customConfirmPresenter.addConfirmHandler(handler);
    customConfirmPresenter.confirm(message);
  }
}
 
Example #23
Source File: NaluPluginElemento.java    From nalu with Apache License 2.0 5 votes vote down vote up
@Override
public void alert(String message) {
  if (customAlertPresenter == null) {
    DomGlobal.window.alert(message);
  } else {
    this.customAlertPresenter.alert(message);
  }
}
 
Example #24
Source File: NaluPluginCoreWeb.java    From nalu with Apache License 2.0 5 votes vote down vote up
public static void addOnHashChangeHandler(RouteChangeHandler handler) {
  DomGlobal.window.onhashchange = e -> {
    String newUrl;
    Location location = Js.uncheckedCast(DomGlobal.location);
    newUrl = location.getHash();
    NaluPluginCoreWeb.handleChange(handler,
                                   newUrl);
    return null;
  };
}
 
Example #25
Source File: NaluPluginCoreWeb.java    From nalu with Apache License 2.0 5 votes vote down vote up
public static void addPopStateHandler(RouteChangeHandler handler,
                                      String contextPath) {
  DomGlobal.window.onpopstate = e -> {
    String newUrl;
    if (PropertyFactory.get()
                       .isUsingHash()) {
      Location location = Js.uncheckedCast(DomGlobal.location);
      newUrl = location.getHash();
    } else {
      PopStateEvent event = (PopStateEvent) e;
      newUrl = (String) event.state;
      if (Objects.isNull(newUrl) ||
          newUrl.trim()
                .length() == 0) {
        newUrl = PropertyFactory.get()
                                .getStartRoute();
      }
    }
    // remove leading '/'
    if (newUrl.length() > 1) {
      if (newUrl.startsWith("/")) {
        newUrl = newUrl.substring(1);
      }
    }
    // remove contextPath
    if (!Objects.isNull(contextPath)) {
      if (newUrl.length() > contextPath.length()) {
        newUrl = newUrl.substring(contextPath.length());
      }
    }
    NaluPluginCoreWeb.handleChange(handler,
                                   newUrl);
    return null;
  };
}
 
Example #26
Source File: NaluPluginCoreWeb.java    From nalu with Apache License 2.0 5 votes vote down vote up
public static void route(String newRoute,
                         boolean replace,
                         RouteChangeHandler handler) {
  String newRouteToken;
  if (PropertyFactory.get()
                     .isUsingHash()) {
    newRouteToken = newRoute.startsWith("#") ? newRoute : "#" + newRoute;
  } else {
    newRouteToken = "/";
    if (PropertyFactory.get()
                       .getContextPath()
                       .length() > 0) {
      newRouteToken = newRouteToken +
          PropertyFactory.get()
                         .getContextPath() +
          "/";
    }
    newRouteToken = newRouteToken + newRoute;
  }
  if (PropertyFactory.get()
                     .hasHistory()) {
    if (replace) {
      DomGlobal.window.history.replaceState(newRouteToken,
                                            null,
                                            newRouteToken);
    } else {
      DomGlobal.window.history.pushState(newRouteToken,
                                         null,
                                         newRouteToken);
    }
  }
}
 
Example #27
Source File: EventTest.java    From gwty-leaflet with Apache License 2.0 4 votes vote down vote up
public void testMapLoadEvent() {
	InjectedLeafletResources.whenReady((e) -> {

			

			HTMLElement div = (HTMLElement) DomGlobal.document.createElement("div");
			div.id = "test9";
			DomGlobal.document.body.appendChild(div);
			
			 MapOptions options = new MapOptions.Builder(L.latLng(52.51, 13.40), 12.0, 7.0).maxZoom(20.0).build();
			Map map = L.map("test9", options);

			map.on(EventTypes.MapEvents.LOAD, (event) -> {


			});

			assertTrue(map.listens(EventTypes.MapEvents.LOAD));
			
			return null;

	});
}
 
Example #28
Source File: NaluPluginElemental2.java    From nalu with Apache License 2.0 4 votes vote down vote up
@Override
public void updateTitle(String title) {
  DomGlobal.document.title = title;
}
 
Example #29
Source File: App.java    From domino-jackson with Apache License 2.0 4 votes vote down vote up
public void onModuleLoad() {

        String input = "{" +
                "\"string\":\"toto\"," +
                "\"bytePrimitive\":34," +
                "\"byteBoxed\":87," +
                "\"shortPrimitive\":12," +
                "\"shortBoxed\":15," +
                "\"intPrimitive\":234," +
                "\"intBoxed\":456," +
                "\"longPrimitive\":-9223372036854775808," +
                "\"longBoxed\":\"9223372036854775807\"," +
                "\"doublePrimitive\":126.23," +
                "\"doubleBoxed\":1256.98," +
                "\"floatPrimitive\":12.89," +
                "\"floatBoxed\":67.3," +
                "\"booleanPrimitive\":true," +
                "\"booleanBoxed\":\"false\"," +
                "\"charPrimitive\":231," +
                "\"charBoxed\":232," +
                "\"bigInteger\":123456789098765432345678987654," +
                "\"bigDecimal\":\"12345678987654.456789\"," +
                "\"enumProperty\":\"B\"," +
                "\"date\":1345304756543," +
                "\"sqlDate\":\"2012-08-18\"," +
                "\"sqlTime\":\"15:45:56\"," +
                "\"sqlTimestamp\":1345304756546," +
                "\"stringArray\":[\"Hello\",null,\"World\",\"!\"]," +
                "\"enumArray\":[\"A\",null,\"C\",\"D\"]," +
                "\"booleanPrimitiveArray\":[true, null, false, 1, 0]," +
                "\"bytePrimitiveArray\":\"SGVsbG8=\"," +
                "\"characterPrimitiveArray\":\"çou\"," +
                "\"doublePrimitiveArray\":[45.789,null,5.1024]," +
                "\"floatPrimitiveArray\":[null]," +
                "\"integerPrimitiveArray\":[4,5,6,null,7,8]," +
                "\"longPrimitiveArray\":[9223372036854775807,null,-9223372036854775808]," +
                "\"shortPrimitiveArray\":[9,null,7,8,15]," +
                "\"stringArray2d\":[[\"Jean\",\"Dujardin\"],[\"Omar\",\"Sy\"],[\"toto\",null]]," +
                "\"enumArray2d\":[[\"A\",\"B\"],[\"C\",\"D\"],[\"B\",null]]," +
                "\"booleanPrimitiveArray2d\":[[true,false],[false,false]]," +
                "\"bytePrimitiveArray2d\":[\"SGVsbG8=\",\"V29ybGQ=\"]," +
                "\"characterPrimitiveArray2d\":[\"ço\",\"ab\"]," +
                "\"doublePrimitiveArray2d\":[[45.789,5.1024]]," +
                "\"floatPrimitiveArray2d\":[[]]," +
                "\"integerPrimitiveArray2d\":[[1,2,3],[4,5,6],[7,8,9]]," +
                "\"longPrimitiveArray2d\":[[9223372036854775807],[-9223372036854775808]]," +
                "\"shortPrimitiveArray2d\":[[9,7,8,15]]," +
                "\"voidProperty\":null" +
                "}";

        SimpleBean simpleBean = SampleMapper.INSTANCE.read(input);
        DomGlobal.console.log(simpleBean.toString());
        DomGlobal.console.log(SampleMapper.INSTANCE.write(simpleBean));

    }
 
Example #30
Source File: NaluPluginCoreWeb.java    From nalu with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("StringSplitter")
public static void getContextPath(ShellConfiguration shellConfiguration) {
  if (PropertyFactory.get()
                     .isUsingHash()) {
    return;
  }
  Location location = Js.uncheckedCast(DomGlobal.location);
  String pathName = location.getPathname();
  if (pathName.startsWith("/") && pathName.length() > 1) {
    pathName = pathName.substring(1);
  }
  if (pathName.contains(".")) {
    if (pathName.contains("/")) {
      pathName = pathName.substring(0,
                                    pathName.lastIndexOf("/"));
      StringBuilder context = new StringBuilder();
      for (String partOfContext : pathName.split("/")) {
        Optional<String> optional = shellConfiguration.getShells()
                                                      .stream()
                                                      .map(ShellConfig::getRoute)
                                                      .filter(f -> f.equals("/" + partOfContext))
                                                      .findAny();
        if (optional.isPresent()) {
          break;
        } else {
          if (context.length() > 0) {
            context.append("/");
          }
          context.append(partOfContext);
        }
      }
      PropertyFactory.get()
                     .setContextPath(context.toString());
    } else {
      PropertyFactory.get()
                     .setContextPath("");
    }
  }
  PropertyFactory.get()
                 .setContextPath("");
}