Exemplo n.º 1
0
  /** Move items from components to others. */
  public static void moveAllItems(
      UISelectItems sourceItems,
      UISelectItems targetItems,
      UIEditableList hiddenTargetList,
      boolean setTargetIds) {
    SelectItem[] all = (SelectItem[]) sourceItems.getValue();
    List<SelectItem> toMove = new ArrayList<SelectItem>();
    List<SelectItem> toKeep = new ArrayList<SelectItem>();
    List<String> hiddenIds = new ArrayList<String>();
    if (all != null) {
      for (SelectItem item : all) {
        if (!item.isDisabled()) {
          toMove.add(item);
        } else {
          toKeep.add(item);
        }
      }
    }
    // reset left values
    sourceItems.setValue(toKeep.toArray(new SelectItem[] {}));

    // change right values
    List<SelectItem> newSelectItems = new ArrayList<SelectItem>();
    SelectItem[] oldSelectItems = (SelectItem[]) targetItems.getValue();
    if (oldSelectItems == null) {
      newSelectItems.addAll(toMove);
    } else {
      newSelectItems.addAll(Arrays.asList(oldSelectItems));
      List<String> oldIds = new ArrayList<String>();
      for (SelectItem oldItem : oldSelectItems) {
        String id = oldItem.getValue().toString();
        oldIds.add(id);
      }
      if (setTargetIds) {
        hiddenIds.addAll(0, oldIds);
      }
      for (SelectItem toMoveItem : toMove) {
        String id = toMoveItem.getValue().toString();
        if (!oldIds.contains(id)) {
          newSelectItems.add(toMoveItem);
          if (setTargetIds) {
            hiddenIds.add(id);
          }
        }
      }
    }
    targetItems.setValue(newSelectItems.toArray(new SelectItem[] {}));

    // update hidden values
    int numValues = hiddenTargetList.getRowCount();
    if (numValues > 0) {
      for (int i = numValues - 1; i > -1; i--) {
        hiddenTargetList.removeValue(i);
      }
    }
    for (String newHiddenValue : hiddenIds) {
      hiddenTargetList.addValue(newHiddenValue);
    }
  }
Exemplo n.º 2
0
 public static void shiftItemsLast(
     UISelectMany targetSelect, UISelectItems targetItems, UIEditableList hiddenTargetList) {
   String[] selected = (String[]) targetSelect.getSelectedValues();
   SelectItem[] all = (SelectItem[]) targetItems.getValue();
   if (selected == null) {
     // nothing to do
     return;
   }
   all = shiftLast(selected, all);
   targetItems.setValue(all);
   clearTargetList(hiddenTargetList);
   addToTargetList(hiddenTargetList, all);
 }
Exemplo n.º 3
0
 public static UISelectItems getPseudoSelectItems(SelectItemsInterface selectItemsInterface) {
   UISelectItems selectItems = null;
   if (selectItemsInterface.getVar() != null && selectItemsInterface.getItemValues() != null) {
     selectItems = new UISelectItems();
     selectItems.setValue(selectItemsInterface.getItemValues());
     selectItems.getAttributes().put("var", selectItemsInterface.getVar());
     if (selectItemsInterface.getItemValue() != null) {
       selectItems.getAttributes().put("itemValue", selectItemsInterface.getItemValue());
     }
     if (selectItemsInterface.getItemLabel() != null) {
       selectItems.getAttributes().put("itemLabel", selectItemsInterface.getItemLabel());
     }
   }
   return selectItems;
 }
Exemplo n.º 4
0
  /**
   * populate the argument component with values, being sensitive to the possible multi-nature of
   * the values, and to the type of the values.
   *
   * @param context the <code>FacesContext</code> for the current request
   * @param component the <code>UIComponent</code> to populate
   * @param componentType the component type
   * @param value the value
   * @param valueType the value type
   */
  private void populateComponentWithValue(
      FacesContext context,
      UIComponent component,
      String componentType,
      String value,
      String valueType) {
    Application application = context.getApplication();
    Converter converter = null;

    // if we need a converter, and can have a converter
    if (!"java.lang.String".equals(valueType) && component instanceof ValueHolder) {
      // if so create it,
      try {
        converter = application.createConverter(CarStore.loadClass(valueType, this));
        // add it to our component,
        ((ValueHolder) component).setConverter(converter);
      } catch (ClassNotFoundException cne) {
        FacesMessage errMsg = MessageFactory.getMessage(CONVERTER_ERROR_MESSAGE_ID, valueType);
        throw new IllegalStateException(errMsg.getSummary());
      }
    }

    // if this component is a SelectOne or SelectMany, take special action
    if (isMultiValue(componentType)) {
      // create a UISelectItems instance
      UISelectItems items = new UISelectItems();
      items.setValue(parseStringIntoArrayList(value, converter));
      // add it to the component
      component.getChildren().add(items);
    } else {
      // we have a single value
      if (null != converter) {
        component.getAttributes().put("value", converter.getAsObject(context, component, value));
      } else {
        component.getAttributes().put("value", value);
      }
    }
  }
  /**
   * Takes a parent UIComponent and adds all UIComponents which are required for configuring a
   * metric. i.e. metric name, math expression, value, etc.
   *
   * @param metric
   * @param parent
   */
  private void helperCreateUICompsForMetricConfig(MetricBean metric, UIComponent parent) {

    // 1)remove all existing child elements that may have been created previously from ALL
    // pConfigVeryGood, pConfigGood, etc.
    removeAllInputHelpersForMetricConfig();

    // 2) now build the gui elements for building a metric configuration
    // 2a) Add an output text with the metric's name
    HtmlOutputText mnameText = new HtmlOutputText();
    mnameText.setId("metricName" + metric.getInternalID());
    mnameText.setValue(metric.getName());
    // add on parent
    parent.getChildren().add(mnameText);

    // 2b) Select a math expression
    HtmlSelectOneMenu select2 = new HtmlSelectOneMenu();
    select2.setId("mathSelect" + metric.getInternalID());
    UISelectItems items2 = new UISelectItems();
    items2.setId("mathvals" + metric.getInternalID());
    items2.setValue(metric.getAllAvailableTypes());
    Class[] parms2 = new Class[] {ValueChangeEvent.class};
    ExpressionFactory ef =
        FacesContext.getCurrentInstance().getApplication().getExpressionFactory();
    MethodExpression mb =
        ef.createMethodExpression(
            FacesContext.getCurrentInstance().getELContext(),
            "#{AutoEvalSerUserConfigBean.processMathExprChange}",
            null,
            parms2);
    MethodExpressionValueChangeListener vcl = new MethodExpressionValueChangeListener(mb);
    select2.addValueChangeListener(vcl);
    select2.getChildren().add(items2);
    select2.setImmediate(true);

    // place an ajax support on the selectonemenu field
    HtmlAjaxSupport ajaxSupport2 = new HtmlAjaxSupport();
    // Class[] parms = new Class[]{ActionEvent.class};
    // ajaxSupport.setAction(FacesContext.getCurrentInstance().getApplication().createMethodBinding("#{AutoEvalSerUserConfigBean.sliderValue}", parms));
    ajaxSupport2.setEvent("onchange");
    // to add multiple ids for rerendering, separate them with a ","
    ajaxSupport2.setReRender(select2.getId());
    ajaxSupport2.setEventsQueue("foo");
    select2.getFacets().put("a4jsupport2", ajaxSupport2);

    // add to parent
    parent.getChildren().add(select2);

    // 2c) For all input types except boolean values:
    if (metric.isHtmlInputTextUsed()) {
      // enter a boundary value for a specific added metric
      HtmlInputText inputText = new HtmlInputText();
      inputText.setId("metricBoundary" + metric.getInternalID());
      inputText.setValue(metric.getEvalBoundary());
      inputText.setSize(10);
      Class[] parms = new Class[] {ValueChangeEvent.class};
      MethodExpression mb2 =
          ef.createMethodExpression(
              FacesContext.getCurrentInstance().getELContext(),
              "#{AutoEvalSerUserConfigBean.processMetricBoundaryValueChange}",
              null,
              parms);
      MethodExpressionValueChangeListener vcl2 = new MethodExpressionValueChangeListener(mb2);
      inputText.addValueChangeListener(vcl2);
      inputText.setImmediate(true);

      // place an ajax support on the InputText field
      HtmlAjaxSupport ajaxSupport = new HtmlAjaxSupport();
      // Class[] parms = new Class[]{ActionEvent.class};
      // ajaxSupport.setAction(FacesContext.getCurrentInstance().getApplication().createMethodBinding("#{AutoEvalSerUserConfigBean.sliderValue}", parms));
      ajaxSupport.setEvent("onchange");
      // to add multiple ids for rerendering, separate them with a ","
      ajaxSupport.setReRender(inputText.getId());
      ajaxSupport.setEventsQueue("foo");
      inputText.getFacets().put("a4jsupport", ajaxSupport);

      // add to parent
      parent.getChildren().add(inputText);
    } else {
      // add a drop-down box for boolean values
      HtmlSelectOneMenu select = new HtmlSelectOneMenu();
      select.setId("booleanSelect" + metric.getInternalID());
      UISelectItems items = new UISelectItems();
      items.setId("vals" + metric.getInternalID());
      List<SelectItem> l = new ArrayList<SelectItem>();
      l.add(new SelectItem("true"));
      l.add(new SelectItem("false"));
      items.setValue(l);
      Class[] parms = new Class[] {ValueChangeEvent.class};
      MethodExpression mb3 =
          ef.createMethodExpression(
              FacesContext.getCurrentInstance().getELContext(),
              "#{AutoEvalSerUserConfigBean.processMetricBoundaryValueChange}",
              null,
              parms);
      MethodExpressionValueChangeListener vcl3 = new MethodExpressionValueChangeListener(mb3);
      select.addValueChangeListener(vcl3);
      select.getChildren().add(items);
      select.setImmediate(true);

      // place an ajax support on the selectonemenu field
      HtmlAjaxSupport ajaxSupport = new HtmlAjaxSupport();
      // Class[] parms = new Class[]{ActionEvent.class};
      // ajaxSupport.setAction(FacesContext.getCurrentInstance().getApplication().createMethodBinding("#{AutoEvalSerUserConfigBean.sliderValue}", parms));
      ajaxSupport.setEvent("onchange");
      // to add multiple ids for rerendering, separate them with a ","
      ajaxSupport.setReRender(select.getId());
      ajaxSupport.setEventsQueue("foo");
      select.getFacets().put("a4jsupport", ajaxSupport);

      // add to parent
      parent.getChildren().add(select);
    }

    // 2d) finally the submit button for saving the configuration
    HtmlCommandButton button_save = new HtmlCommandButton();
    button_save.setId("buttonSave" + metric.getInternalID());
    button_save.setValue("add config");
    Class[] parms3 = new Class[] {ActionEvent.class};
    MethodExpression mb4 =
        ef.createMethodExpression(
            FacesContext.getCurrentInstance().getELContext(),
            "#{AutoEvalSerUserConfigBean.command_saveMetricConfiguration}",
            null,
            parms3);
    MethodExpressionActionListener vcl4 = new MethodExpressionActionListener(mb4);
    button_save.addActionListener(vcl4);
    UIParameter p = new UIParameter();
    p.setId("param_save_button" + metric.getInternalID());
    p.setName("pConfigPanel");
    p.setValue(parent.getId());
    button_save.getChildren().add(p);

    parent.getChildren().add(button_save);

    HtmlOutputText message = new HtmlOutputText();
    message.setId("message" + metric.getInternalID());
    message.setStyle("color:red;");
    parent.getChildren().add(message);
  }