Directory

← Back

webswing-vaadin

Integration of Webswing application with Vaadin application.

Author

Rating

Popularity

<100

This component allows you to run a Webswing application in a Vaadin component.

Sample code

package org.webswing.demo.vaadin;

import java.nio.charset.StandardCharsets;
import java.util.Base64;

import org.vaadin.addons.webswing.Webswing;
import org.vaadin.addons.webswing.WebswingListener;

import com.vaadin.flow.component.Unit;
import com.vaadin.flow.component.dependency.CssImport;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.router.Route;

import elemental.json.Json;
import elemental.json.JsonObject;

@Route("")
@CssImport("./src/style.css")
public class MainView extends Div {

	private static final long serialVersionUID = 2863699250925129379L;

	private Webswing webswing;
	
	public MainView() {
		setSizeFull();
		addClassNames("p-4 flex flex-row h-full overflow-y-auto");
    	
    	JsonObject options = Json.createObject();
    	
		JsonObject pingParams = Json.createObject();
		pingParams.put("count", 6);
		pingParams.put("interval", 1);
		pingParams.put("maxLatency", 1000);
		pingParams.put("notifyIf", 3);
		
		options.put("autoReconnect", 5000);
        options.put("syncClipboard", true);
        options.put("pingParams", pingParams);
        
        String webswingUrl = System.getProperty("vaadin.webswingAppUrl");
        if (webswingUrl == null) {
        	throw new RuntimeException("Cannot start Webswing Vaadin integration app, please provide 'vaadin.webswingAppUrl' system property!");
        }
        
        webswing = new Webswing(webswingUrl, options);
        webswing.setSizeFull();
        
        webswing.addWebswingListener(new WebswingListener() {
			@Override
			public void webswingStarted() {
				String binaryBase64Data = new String(Base64.getEncoder().encode(new String("testBinaryData").getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8);
				webswing.getElement().callJsFunction("performAction", "vaadin_test", "testData", binaryBase64Data);
			}
			
			@Override
			public void webswingInitialized() {
				webswing.getElement().executeJs("this.injector.services.taskbar.config.enabled = true;");
	        	webswing.getElement().callJsFunction("startInstance");
			}
			
			@Override
			public void handleActionEvent(String actionName, String data, String binaryDataBase64) {
				String decoded = null;
				if (binaryDataBase64 != null) {
					decoded = new String(Base64.getDecoder().decode(binaryDataBase64.getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8);
				}
				System.out.println(actionName + " " + data + " " + binaryDataBase64 + " " + decoded);
			}
		});
        webswing.setMinWidth(50, Unit.PERCENTAGE);
        
        Div wsWrapper = new Div(webswing);
        wsWrapper.addClassNames("ws-height");
        
        add(wsWrapper);
    }
	
}

Compatibility

(Loading compatibility data...)

Was this helpful? Need more help?
Leave a comment or a question below. You can also join the chat on Discord or ask questions on StackOverflow.

Version

First release of Webswing add-on for Vaadin.

Released
2023-10-12
Maturity
STABLE
License
Apache License 2.0

Compatibility

Framework
Vaadin 23+
Browser
Firefox
Opera
Safari
Google Chrome
iOS Browser
Android Browser
Windows Phone
Microsoft Edge

webswing-vaadin - Vaadin Add-on Directory

Integration of Webswing application with Vaadin application. webswing-vaadin - Vaadin Add-on Directory
This component allows you to run a Webswing application in a Vaadin component.
Online Demo
Author Homepage

webswing-vaadin version 23.2.1
First release of Webswing add-on for Vaadin.

Online