Blog
Lightweight Dialogs in e4 & JavaFX
I've just checked in the initial bits to use lightweight dialogs in your e4 + JavaFX applications. You can see it in action in the short video from below Watch on YouTube Useage is fairly simple. First you need to have dialog implementation like this:
static class OpenProjectDialogImpl extends TitleAreaDialog {
private ListView<Project> list;
private final CommandService cmdService;
@Inject
public OpenProjectDialogImpl(Workbench workbench,
CommandService cmdService, @Service List<ProjectService> projectServiceList) {
super("Open project",
"Open project", "Open an existing project");
this.cmdService = cmdService;
addDefaultButtons();
setMaxWidth(500);
setMaxHeight(500);
setId("open-project-dialog");
list = new ListView<>();
list.setMinWidth(600);
list.setCellFactory(v ->
new SimpleListCell<Project>(
p -> labelExtractor(p, projectServiceList),
p -> cssProvider(p,projectServiceList)));
list.setItems(FXCollections.observableArrayList(
workbench.getProjectList()));
setClientArea(list);
}
@Override
protected void handleOk() {
if( list.getSelectionModel().getSelectedItem() != null ) {
cmdService.execute("org.eclipse.fx.code.compensator.app.command.openproject", Collections.singletonMap("projectId", list.getSelectionModel().getSelectedItem().getProjectId()));
super.handleOk();
}
}
}
and displaying it is nothing more than:
public class OpenProjectDialog {
@Execute
public void open(LightWeightDialogService dialogService) {
dialogService.openDialog(OpenProjectDialogImpl.class, ModalityScope.WINDOW);
}
}
As you can see in the video you can choose how the dialog is opened & closed. This is done through an OSGi-Service of type LightweightDialogTransitionService:
@Component
public class FadeDialogTranstionServiceImpl extends FadeDialogTranstionService implements LightweightDialogTransitionService {
@Override
protected void configureFadeIn(FadeTransition transition) {
super.configureFadeIn(transition);
transition.setInterpolator(Interpolator.EASE_OUT);
}
@Override
protected void configureFadeOut(FadeTransition transition) {
super.configureFadeOut(transition);
transition.setInterpolator(Interpolator.EASE_OUT);
}
}