Esempio n. 1
0
  public void setValues(final UIPortlet uiPortlet) throws Exception {
    uiPortlet_ = uiPortlet;
    invokeGetBindingBean(uiPortlet_);
    String icon = uiPortlet.getIcon();

    if (icon == null || icon.length() < 0) {
      icon = "PortletIcon";
    }
    getChild(UIFormInputIconSelector.class).setSelectedIcon(icon);
    getChild(UIFormInputThemeSelector.class)
        .getChild(UIItemThemeSelector.class)
        .setSelectedTheme(uiPortlet.getSuitedTheme(null));
    if (hasEditMode()) {
      uiPortlet.setCurrentPortletMode(PortletMode.EDIT);
    } else {
      Map<String, String> portletPreferenceMaps = new HashMap<String, String>();
      org.gatein.pc.api.Portlet portlet = uiPortlet.getProducedOfferedPortlet();
      Set<String> keySet = portlet.getInfo().getPreferences().getKeys();

      for (String key : keySet) {
        PreferenceInfo preferenceInfo = portlet.getInfo().getPreferences().getPreference(key);
        if (!preferenceInfo.isReadOnly()) {
          String ppValue =
              (preferenceInfo.getDefaultValue().size() > 0)
                  ? preferenceInfo.getDefaultValue().get(0)
                  : "";
          portletPreferenceMaps.put(key, ppValue);
        }
      }

      Portlet pp = uiPortlet.getPreferences();
      if (pp != null) {
        for (Preference pref : pp) {
          if (!pref.isReadOnly()) {
            portletPreferenceMaps.put(
                pref.getName(), (pref.getValues().size() > 0) ? pref.getValues().get(0) : "");
          }
        }
      }

      if (portletPreferenceMaps.size() > 0) {
        Set<String> ppKeySet = portletPreferenceMaps.keySet();
        UIFormInputSet uiPortletPrefSet = getChildById(FIELD_PORTLET_PREF);
        uiPortletPrefSet.getChildren().clear();
        for (String ppKey : ppKeySet) {
          String ppValue = portletPreferenceMaps.get(ppKey);
          UIFormStringInput preferenceStringInput = new UIFormStringInput(ppKey, null, ppValue);
          preferenceStringInput.setLabel(ppKey);
          preferenceStringInput.addValidator(MandatoryValidator.class);
          uiPortletPrefSet.addUIFormInput(preferenceStringInput);
        }

        uiPortletPrefSet.setRendered(true);
        setSelectedTab(FIELD_PORTLET_PREF);
        return;
      }

      setSelectedTab("PortletSetting");
    }
  }
Esempio n. 2
0
  @SuppressWarnings("unchecked")
  public UIPortletForm() throws Exception {
    super("UIPortletForm");
    UIFormInputSet uiPortletPrefSet = new UIFormInputSet(FIELD_PORTLET_PREF).setRendered(false);
    addUIFormInput(uiPortletPrefSet);
    UIFormInputSet uiSettingSet = new UIFormInputSet("PortletSetting");
    uiSettingSet
        .addUIFormInput(new UIFormInputInfo("displayName", "displayName", null))
        .addUIFormInput(
            new UIFormStringInput("title", "title", null)
                .addValidator(StringLengthValidator.class, 3, 60)
                .addValidator(NotHTMLTagValidator.class, "UIPortletForm.msg.InvalidPortletTitle"))
        .addUIFormInput(
            new UIFormStringInput("width", "width", null)
                .addValidator(
                    ExpressionValidator.class,
                    "(^([1-9]\\d*)px$)?",
                    "UIPortletForm.msg.InvalidWidthHeight"))
        .addUIFormInput(
            new UIFormStringInput("height", "height", null)
                .addValidator(
                    ExpressionValidator.class,
                    "(^([1-9]\\d*)px$)?",
                    "UIPortletForm.msg.InvalidWidthHeight"))
        .addUIFormInput(new UICheckBoxInput("showInfoBar", "showInfoBar", false))
        .addUIFormInput(new UICheckBoxInput("showPortletMode", "showPortletMode", false))
        .addUIFormInput(new UICheckBoxInput("showWindowState", "showWindowState", false))
        .addUIFormInput(
            new UIFormTextAreaInput("description", "description", null)
                .addValidator(
                    NotHTMLTagValidator.class, "UIPortletForm.msg.InvalidPortletDescription"));
    addUIFormInput(uiSettingSet);
    UIFormInputIconSelector uiIconSelector = new UIFormInputIconSelector("Icon", "icon");
    addUIFormInput(uiIconSelector);

    UIFormInputThemeSelector uiThemeSelector = new UIFormInputThemeSelector(FIELD_THEME, null);
    SkinService skinService = getApplicationComponent(SkinService.class);
    uiThemeSelector.getChild(UIItemThemeSelector.class).setValues(skinService.getPortletThemes());
    addUIFormInput(uiThemeSelector);

    UIListPermissionSelector uiListPermissionSelector =
        createUIComponent(UIListPermissionSelector.class, null, null);
    uiListPermissionSelector.configure("UIAccessPermission", "accessPermissions");
    uiListPermissionSelector.addValidator(EmptyIteratorValidator.class);
    UIFormInputSet uiPermissionSet =
        createUIComponent(UIFormInputSet.class, "PortletPermission", null);
    uiPermissionSet.addChild(uiListPermissionSelector);
    addUIFormInput(uiPermissionSet);
  }
Esempio n. 3
0
  private void savePreferences() throws Exception {
    UIFormInputSet uiPortletPrefSet = getChildById(FIELD_PORTLET_PREF);
    List<UIFormStringInput> uiFormInputs = new ArrayList<UIFormStringInput>(3);
    uiPortletPrefSet.findComponentOfType(uiFormInputs, UIFormStringInput.class);
    if (uiFormInputs.size() < 1) {
      return;
    }

    PropertyChange[] propertyChanges = new PropertyChange[uiFormInputs.size()];

    for (int i = 0; i < uiFormInputs.size(); i++) {
      String name = uiFormInputs.get(i).getName();
      String value = uiFormInputs.get(i).getValue();
      propertyChanges[i] = PropertyChange.newUpdate(name, value);
    }

    // Now save it
    uiPortlet_.update(propertyChanges);
  }