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

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);
  }
}

4 thoughts on “Lightweight Dialogs in e4 & JavaFX

    • Tom Schindl June 24, 2015 / 8:11 am

      Great any slides, … available?

  1. Konstantin August 12, 2015 / 11:55 am

    “This is done through an OSGi-Service of type LightweightDialogTransitionService”
    that means you need to have your own implementation of LightweightDialogTransitionService as an OSGi-Service, where you can also adjust transition (easy out/in, duration, etc)

    P.S. It wasn’t clear for me for a while, could be a bit difficult for somebody else.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s