/**
   * Fill the UI component with both information from the persistent model and some coming from the
   * portlet.xml defined by the JSR 286 specification
   */
  private static <S> void toUIPortlet(UIPortlet<S, ?> uiPortlet, Application<S> model) {

    //
    PortletState<S> portletState = new PortletState<S>(model.getState(), model.getType());

    /*
     * Fill UI component object with info from the XML file that persist portlet information
     */
    uiPortlet.setWidth(model.getWidth());
    uiPortlet.setHeight(model.getHeight());
    uiPortlet.setState(portletState);
    uiPortlet.setTitle(model.getTitle());
    uiPortlet.setIcon(model.getIcon());
    uiPortlet.setDescription(model.getDescription());
    uiPortlet.setShowInfoBar(model.getShowInfoBar());
    uiPortlet.setShowWindowState(model.getShowApplicationState());
    uiPortlet.setShowPortletMode(model.getShowApplicationMode());
    uiPortlet.setProperties(model.getProperties());
    uiPortlet.setTheme(model.getTheme());
    if (model.getAccessPermissions() != null)
      uiPortlet.setAccessPermissions(model.getAccessPermissions());
    uiPortlet.setModifiable(model.isModifiable());

    Portlet portlet = uiPortlet.getProducedOfferedPortlet();
    if (portlet == null || portlet.getInfo() == null) return;

    PortletInfo portletInfo = portlet.getInfo();

    /*
     * Define which portlet modes the portlet supports and hence should be shown in the portlet info bar
     */
    Set<ModeInfo> modes = portletInfo.getCapabilities().getModes(MediaType.create("text/html"));
    List<String> supportModes = new ArrayList<String>();
    for (ModeInfo modeInfo : modes) {
      String modeName = modeInfo.getModeName().toLowerCase();
      if ("config".equals(modeInfo.getModeName())) {
        supportModes.add(modeName);
      } else {
        supportModes.add(modeName);
      }
    }

    if (supportModes.size() > 1) supportModes.remove("view");
    uiPortlet.setSupportModes(supportModes);
  }
 public static void toUIGadget(UIGadget uiGadget, Application<Gadget> model) {
   uiGadget.setProperties(model.getProperties());
   uiGadget.setState(model.getState());
 }