Sample Java Projects

Our Finsemble Java Repository contains four example Java applications:

  • The JavaFX Example contains a Finsemble-aware JavaFX application that has the linker and grouping controls, accepts drag and drop from Finsemble, and communicates over linker channels.
  • The Java Swing Example contains a Finsemble-aware Java Swing application that has a linker control, accepts drag and drop from Finsemble, and communicates over linker channels.
  • The Authentication Example contains an example of authenticating with a Java application.
  • The Java Headless Example contains an example of how to work with a Java application without a window: for example, to allow it to function as a service within Finsemble, which can communicate over the Router.

Here is a sample configuration to use the Java Example project with the Finsemble seed project:

		"Java Example (local)": {
			"window": {
				"id": "JavaExample",
				"windowType": "native",
				"path": "Path to FinsembleJavaFXExample.jar",
				"url": "",
				"arguments": "",
				"defaultHeight": 600,
				"autoShow": true,
				"alwaysOnTop": false,
				"resizable": true,
				"showTaskbarIcon": false,
				"contextMenu": true,
				"addToWorkspace": true
			},
			"component": {
				"spawnOnStartup": false
			},
			"foreign": {
				"services": {
					"workspaceService": {
						"isArrangable": true
					}
				},
				"components": {
					"App Launcher": {
						"launchableByUser": true
					},
					"Window Manager": {
						"persistWindowState": false,
						"FSBLHeader": true
					},
					"Toolbar": {
						"iconURL": "$applicationRoot/assets/img/example.png"
					}
				}
			}
		},

Window title bar functionality in Java

The Finsemble window title bar has not been implemented in Java, but examples have been provided for implementing the linker and grouping functionality in Java. Java windows can participate in snapping and docking, linking and drag and drop data sharing.

Scrim

When data to be shared in Finsemble is dragged, a scrim should displayed on top of all components denoting whether or not the component can receive that data. You must create a control that occupies the entire space of the component, sits on top of all other controls, and is hidden. This is the control that will accept the dragged data from other components. In order to keep the implementation UI agnostic, the addWindowHighlight and removeWindowHighlight callbacks are provided to trigger when the scrim should be shown. Here is how to provide this control to Finsemble:

private void addWindowHighlight(JSONObject err, JSONObject res) {
	Platform.runLater(() -> {
		fxScrim = new HBox();
		fxScrim.setId("scrim");
		fxScrim.setMinWidth(window.getWidth());
		fxScrim.setMinHeight(window.getHeight());

		boolean canReceiveData = res.getBoolean("canReceiveData");
		if (canReceiveData) {
			fxScrim.setBackground(new Background(new BackgroundFill(Color.rgb(0, 0, 99, 0.5), CornerRadii.EMPTY, Insets.EMPTY)));
			fxScrim.setOnDragOver((DragEvent dragEvent) -> {
				dragEvent.acceptTransferModes(TransferMode.COPY_OR_MOVE);
			});
			fxScrim.setOnDragDropped((DragEvent dragEvent) -> {
				final Dragboard db = dragEvent.getDragboard();
				final String dragDataStr = db.getString();
				final JSONObject dragDataJson = new JSONObject(dragDataStr);
				fsbl.getClients().getDragAndDropClient().drop(dragDataJson);
			});
		} else
			fxScrim.setBackground(new Background(new BackgroundFill(Color.rgb(99, 0, 0, 0.5), CornerRadii.EMPTY, Insets.EMPTY)));

		((Pane) window.getScene().getRoot()).getChildren().add(fxScrim);
	});
}


private void removeWindowHighlight(JSONObject err, JSONObject res) {
	Platform.runLater(() -> {
		((Pane) window.getScene().getRoot()).getChildren().remove(fxScrim);
	});
}

Authenticating with a Java application

The main window of the Authentication Example application needs to be initialized. Once the user is authenticated, you need to call publishAuthorization:

fsbl.getClients().getAuthenticationClient().publishAuthorization(userName, credentials);

If your application requires credentials from Finsemble, you can call getCurrentCredentials:

fsbl.getClients().getAuthenticationClient().getCurrentCredentials((err, res) -> {});

Using a Java application as a service

You can also have Java applications that do not display a window to interoperate with other components via the Router. This allows for the integration of a Java application as a service within Finsemble. An example of such an integration is provided in the Headless Java Example.

Desktop services created from Java applications currently need to be added to the Finsemble component configuration and will always be started after all other services have been initialized. To add a Java service (i.e., windowless component) to Finsemble, add it to the components.json file as normal and ensure that you set:

  • window.windowType to "native"
  • window.name field to help you identify the component in the Central Logger
  • window.autoShow to false as no window should be displayed
  • window.addToWorkspace to false to disable any state capture and lifecycle events
  • component.spawnOnStartup to true to ensure that the component is auto-started
  • foreign.components["App Launcher"].launchableByUser to false to stop the component appearing in the launcher menu

The component may be launched using a path or alias and can be passed arguments in the same way as any other native component.

For example:

"JavaHeadlessExample": {
    "window": {
        "id": "Windowless",
        "name": "winlessSeed",
        "windowType": "native",
        "alias": "javaHeadlessExample",
        "arguments": "arg1 arg2 arg3",
        "autoShow": false,
        "addToWorkspace": false
    },
    "component": {
        "spawnOnStartup": true
    },
    "foreign": {
        "components": {
            "App Launcher": {
                "launchableByUser": false
            }
        }
    }
}

check   The Finsemble Java Example Repository contains several ways to integrate a Java app with Finsemble.
 

Further reading

The basics of integrating native components is covered in this tutorial.

For information about authentication, check out the Authentication tutorial.

Understanding how the Linker Client and Drag and Drop Client work is important for understanding this tutorial.