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

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

The 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", "rawtypes" })
  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 = (U) instantiate((Class)uiOptions, (Class)uiType);
    try {
      return ui;
    } finally {
      if (model != null) {
        ui.renderUi(model);
      }
    }
  }

  @SuppressWarnings({ "unchecked", "rawtypes" })
  private static > U instantiate(Class cls, Class uiType) {
      return (U) X_Inject
          .instance(UserInterfaceFactory.class)
          .createUi((Class)cls, (Class)uiType);
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy