/**
   * 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);
  }
Beispiel #2
0
  /**
   * Add Application to UiPage
   *
   * @param event
   * @throws Exception
   */
  private static void addApplicationToPage(Event<UIAddNewApplication> event, boolean atStartup)
      throws Exception {
    UIPortalApplication uiPortalApp = Util.getUIPortalApplication();
    UIPortal uiPortal = uiPortalApp.getShowedUIPortal();
    PortalRequestContext pcontext = Util.getPortalRequestContext();

    UIDesktopPage uiDesktopPage = uiPortal.findFirstComponentOfType(UIDesktopPage.class);
    if (uiDesktopPage == null) {
      pcontext.addUIComponentToUpdateByAjax(
          uiPortalApp.getChildById(UIPortalApplication.UI_WORKING_WS_ID));
      UIMaskWorkspace maskWorkspace = uiPortalApp.getChildById(UIPortalApplication.UI_MASK_WS_ID);
      maskWorkspace.createEvent("Close", Event.Phase.DECODE, event.getRequestContext()).broadcast();
      pcontext.setFullRender(true);
      return;
    }

    String applicationId = event.getRequestContext().getRequestParameter(UIComponent.OBJECTID);

    Application application = event.getSource().getApplication(applicationId);
    ApplicationType appType = application.getType();

    UIPortlet uiPortlet = uiDesktopPage.createUIComponent(UIPortlet.class, null, null);
    ApplicationState appState;

    // TODO: Check if there 's already a portlet window of this portlet. A CloneApplicationState
    // should be created in such case
    appState = new TransientApplicationState<Object>(application.getContentId());

    uiPortlet.setState(new PortletState(appState, appType));
    uiPortlet.setPortletInPortal(false);

    if (atStartup) {
      uiPortlet.getProperties().setProperty("appStatus", "HIDE");
    }

    String portletName = application.getApplicationName();
    String displayName = application.getDisplayName();
    if (displayName != null) {
      uiPortlet.setTitle(displayName);
    } else if (portletName != null) {
      uiPortlet.setTitle(portletName);
    }
    uiPortlet.setDescription(application.getDescription());
    List<String> accessPers = application.getAccessPermissions();
    String[] accessPermissions = accessPers.toArray(new String[accessPers.size()]);
    uiPortlet.setAccessPermissions(accessPermissions);

    // Add portlet to page
    uiDesktopPage.addChild(uiPortlet);

    if (uiDesktopPage.isModifiable()) {
      Page page = (Page) PortalDataMapper.buildModelObject(uiDesktopPage);
      if (page.getChildren() == null) {
        page.setChildren(new ArrayList<ModelObject>());
      }
      DataStorage dataService = uiPortalApp.getApplicationComponent(DataStorage.class);
      dataService.save(page);

      // Rebuild the uiPage to synchronize (storageId, storageName) mapping
      page = dataService.getPage(page.getPageId());
      page.setModifiable(true);
      uiDesktopPage.getChildren().clear();
      PortalDataMapper.toUIPage(uiDesktopPage, page);
    }

    UIWorkingWorkspace uiWorkingWS = uiPortalApp.getChildById(UIPortalApplication.UI_WORKING_WS_ID);
    pcontext.setFullRender(true);
    pcontext.addUIComponentToUpdateByAjax(uiWorkingWS);
  }