All Downloads are FREE. Search and download functionalities are using the official Maven repository.

xapi.ui.autoui.X_AutoUi Maven / Gradle / Ivy

There is a newer version: 0.5
Show newest version
package xapi.ui.autoui;

import xapi.inject.X_Inject;
import xapi.ui.autoui.api.UserInterface;
import xapi.ui.autoui.api.UserInterfaceFactory;

public class X_AutoUi {

  private X_AutoUi(){}
  
  @SuppressWarnings("unchecked")
  public static > U makeUi(T model, Class uiOptions, Class uiType) {
    if (uiOptions == null) {
      assert model != null : "You must provide either a model object, or a model class";
      uiOptions = (Class) model.getClass();
    }
    U ui = instantiate(uiOptions, uiType);
    try {
      return ui;
    } finally {
      if (model != null) {
        ui.renderUi(model);
      }
    }
  }

  public static > U instantiate(Class cls, Class uiType) {
      return X_Inject
          .instance(UserInterfaceFactory.class)
          .createUi(cls, uiType);
  }
  
}