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 AppD configuration to use the Java Example project with the Finsemble seed project:
{
...
"apps": [
...
{
"appId": "JavaExample",
"name": "JavaExample",
"type": "native",
"details": {
"path": "C:/some/path/to/FinsembleJavaFXExample.jar",
},
"hostManifests" : {
"Finsemble": {
"window": {
"autoShow": true,
"addToWorkspace": true
},
"foreign": {
"services": {
"workspaceService": {
"isArrangable": true
}
},
"components": {
"App Launcher": {
"launchableByUser": true
}
}
}
}
}
}
]
}
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, grouping, and linking.
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. After 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 an App service
You can also have Java applications that do not display a window to interoperate with other components via the Router or FDC3. 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.
App services created from Java applications should be added to the Finsemble apps configuration. To add a Java app service to Finsemble, add it to the public/configs/application/apps.json file as normal and ensure that you set:
hostManifests.Finsemble.appService
totrue
- a
hostManifests.Finsemble.window.name
field to help you identify the component in the Central Logger
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:
{
...
"apps": [
...
{
"appId": "JavaHeadlessExample",
"name": "JavaHeadlessExample",
"type": "native",
"details": {
"path": "C:/some/path/to/WPFExample.exe",
},
"hostManifests" : {
"Finsemble": {
"appService": true,
"window": {
"name": "javaHeadlessExample",
"windowType": "native",
"alias": "javaHeadlessExample",
"arguments": "arg1 arg2 arg3"
}
}
}
}
]
}
For more details see App services.
See also
The basics of integrating native components is covered in Integrating native apps.
For information about authentication, see the Authentication tutorial.