示例#1
0
 /**
  * Set the tables parameters
  *
  * @param formWidget the widget
  * @param evaluatedExpressions the map of evaluated expressions
  * @param context the context including the URL parameters
  * @throws FormNotFoundException
  * @throws FormServiceProviderNotFoundException
  */
 @SuppressWarnings("unchecked")
 public void setTablesParams(
     final FormWidget formWidget,
     final Map<String, Serializable> evaluatedExpressions,
     final Map<String, Object> context)
     throws FormNotFoundException, FormServiceProviderNotFoundException {
   final String widgetId = formWidget.getId();
   if (WidgetType.TABLE.equals(formWidget.getType())
       || WidgetType.EDITABLE_GRID.equals(formWidget.getType())) {
     final Object valueColumnIndex =
         evaluatedExpressions.get(widgetId + EXPRESSION_KEY_SEPARATOR + WIDGET_VALUE_COLUMN_INDEX);
     if (valueColumnIndex != null) {
       try {
         formWidget.setValueColumnIndex((Integer) valueColumnIndex);
       } catch (final Exception e) {
         if (LOGGER.isLoggable(Level.WARNING)) {
           LOGGER.log(
               Level.WARNING,
               "The max number of columns has to be set with an integer or a groovy expression returning an integer.");
         }
         formWidget.setValueColumnIndex(0);
       }
     }
     final Object maxColumns =
         evaluatedExpressions.get(widgetId + EXPRESSION_KEY_SEPARATOR + WIDGET_MAX_COLUMNS);
     if (maxColumns != null) {
       try {
         formWidget.setMaxColumns((Integer) maxColumns);
       } catch (final Exception e) {
         if (LOGGER.isLoggable(Level.WARNING)) {
           LOGGER.log(
               Level.WARNING,
               "The max number of columns has to be set with an integer or a groovy expression returning an integer.");
         }
         formWidget.setMaxColumns(-1);
       }
     } else {
       formWidget.setMaxColumns(-1);
     }
     final Object minColumns =
         evaluatedExpressions.get(widgetId + EXPRESSION_KEY_SEPARATOR + WIDGET_MIN_COLUMNS);
     if (minColumns != null) {
       try {
         formWidget.setMinColumns((Integer) minColumns);
       } catch (final Exception e) {
         if (LOGGER.isLoggable(Level.WARNING)) {
           LOGGER.log(
               Level.WARNING,
               "The min number of columns has to be set with an integer or a groovy expression returning an integer.");
         }
         formWidget.setMinColumns(-1);
       }
     } else {
       formWidget.setMinColumns(-1);
     }
     final Object maxRows =
         evaluatedExpressions.get(widgetId + EXPRESSION_KEY_SEPARATOR + WIDGET_MAX_ROWS);
     if (maxRows != null) {
       try {
         formWidget.setMaxRows((Integer) maxRows);
       } catch (final Exception e) {
         if (LOGGER.isLoggable(Level.WARNING)) {
           LOGGER.log(
               Level.WARNING,
               "The max number of rows has to be set with an integer or a groovy expression returning an integer.");
         }
         formWidget.setMaxRows(-1);
       }
     } else {
       formWidget.setMaxRows(-1);
     }
     final Object minRows =
         evaluatedExpressions.get(widgetId + EXPRESSION_KEY_SEPARATOR + WIDGET_MIN_ROWS);
     if (minRows != null) {
       try {
         formWidget.setMinRows((Integer) minRows);
       } catch (final Exception e) {
         if (LOGGER.isLoggable(Level.WARNING)) {
           LOGGER.log(
               Level.WARNING,
               "The max number of rows has to be set with an integer or a groovy expression returning an integer.");
         }
         formWidget.setMinRows(-1);
       }
     } else {
       formWidget.setMinRows(-1);
     }
     final Object verticalHeader =
         evaluatedExpressions.get(widgetId + EXPRESSION_KEY_SEPARATOR + WIDGET_VERTICAL_HEADER);
     List<String> verticalHeaderList = null;
     if (verticalHeader != null) {
       try {
         verticalHeaderList = new ArrayList<String>((Collection<String>) verticalHeader);
       } catch (final ClassCastException e) {
         if (LOGGER.isLoggable(Level.SEVERE)) {
           LOGGER.log(
               Level.SEVERE,
               "The vertical header expression for widget "
                   + formWidget.getId()
                   + " should return a Collection.",
               e);
         }
       }
     } else if (evaluatedExpressions.containsKey(
         widgetId + EXPRESSION_KEY_SEPARATOR + WIDGET_VERTICAL_HEADER + 0)) {
       verticalHeaderList = new ArrayList<String>();
       int verticalHeaderIndex = 0;
       do {
         final Object verticalHeaderCell =
             evaluatedExpressions.get(
                 widgetId
                     + EXPRESSION_KEY_SEPARATOR
                     + WIDGET_VERTICAL_HEADER
                     + verticalHeaderIndex);
         try {
           verticalHeaderList.add((String) verticalHeaderCell);
         } catch (final ClassCastException e) {
           if (LOGGER.isLoggable(Level.SEVERE)) {
             LOGGER.log(
                 Level.SEVERE,
                 "All the vertical header expressions for widget "
                     + formWidget.getId()
                     + " should return a String.",
                 e);
           }
         }
         verticalHeaderIndex++;
       } while (evaluatedExpressions.containsKey(
           widgetId + EXPRESSION_KEY_SEPARATOR + WIDGET_VERTICAL_HEADER + verticalHeaderIndex));
     }
     formWidget.setVerticalHeader(verticalHeaderList);
     final Object horizontalHeader =
         evaluatedExpressions.get(widgetId + EXPRESSION_KEY_SEPARATOR + WIDGET_HORIZONTAL_HEADER);
     List<String> horizontalHeaderList = null;
     if (horizontalHeader != null) {
       try {
         horizontalHeaderList = new ArrayList<String>((Collection<String>) horizontalHeader);
       } catch (final ClassCastException e) {
         if (LOGGER.isLoggable(Level.SEVERE)) {
           LOGGER.log(
               Level.SEVERE,
               "The horizontal header expression for widget "
                   + formWidget.getId()
                   + " should return a Collection.",
               e);
         }
       }
     } else if (evaluatedExpressions.containsKey(
         widgetId + EXPRESSION_KEY_SEPARATOR + WIDGET_HORIZONTAL_HEADER + 0)) {
       horizontalHeaderList = new ArrayList<String>();
       int horizontalHeaderIndex = 0;
       do {
         final Object horizontalHeaderCell =
             evaluatedExpressions.get(
                 widgetId
                     + EXPRESSION_KEY_SEPARATOR
                     + WIDGET_HORIZONTAL_HEADER
                     + horizontalHeaderIndex);
         try {
           horizontalHeaderList.add((String) horizontalHeaderCell);
         } catch (final ClassCastException e) {
           if (LOGGER.isLoggable(Level.SEVERE)) {
             LOGGER.log(
                 Level.SEVERE,
                 "All the horizontal header expressions for widget "
                     + formWidget.getId()
                     + " should return a String.",
                 e);
           }
         }
         horizontalHeaderIndex++;
       } while (evaluatedExpressions.containsKey(
           widgetId
               + EXPRESSION_KEY_SEPARATOR
               + WIDGET_HORIZONTAL_HEADER
               + horizontalHeaderIndex));
     }
     formWidget.setHorizontalHeader(horizontalHeaderList);
   }
 }
示例#2
0
 /** @param formWidget */
 protected void addFormWidgetAvailableValuesExpressions(
     final FormWidget formWidget, final List<Expression> expressionsToEvaluate) {
   final String widgetId = formWidget.getId();
   if (formWidget.getAvailableValuesExpression() != null
       && !WidgetType.SUGGESTBOX_ASYNC.equals(formWidget.getType())) {
     final Expression availableValuesExpression = formWidget.getAvailableValuesExpression();
     availableValuesExpression.setName(
         widgetId + EXPRESSION_KEY_SEPARATOR + WIDGET_AVAILABLE_VALUES);
     expressionsToEvaluate.add(availableValuesExpression);
   } else {
     if (WidgetType.TABLE.equals(formWidget.getType())) {
       final List<List<FormFieldAvailableValue>> tableAvailableValues =
           formWidget.getTableAvailableValues();
       if (tableAvailableValues != null && !tableAvailableValues.isEmpty()) {
         int availableValueRowIndex = 0;
         for (final List<FormFieldAvailableValue> formFieldAvailableValuesRow :
             tableAvailableValues) {
           int availableValueIndex = 0;
           for (final FormFieldAvailableValue formFieldAvailableValue :
               formFieldAvailableValuesRow) {
             final Expression availableValueLabelExpression =
                 formFieldAvailableValue.getLabelExpression();
             availableValueLabelExpression.setName(
                 widgetId
                     + EXPRESSION_KEY_SEPARATOR
                     + WIDGET_AVAILABLE_VALUE_LABEL
                     + availableValueRowIndex
                     + INDEX_SEPARATOR
                     + availableValueIndex);
             expressionsToEvaluate.add(availableValueLabelExpression);
             final Expression availableValueValueExpression =
                 formFieldAvailableValue.getValueExpression();
             availableValueValueExpression.setName(
                 widgetId
                     + EXPRESSION_KEY_SEPARATOR
                     + WIDGET_AVAILABLE_VALUE_VALUE
                     + availableValueRowIndex
                     + INDEX_SEPARATOR
                     + availableValueIndex);
             expressionsToEvaluate.add(availableValueValueExpression);
             availableValueIndex++;
           }
           availableValueRowIndex++;
         }
       }
     } else {
       final List<FormFieldAvailableValue> availableValues = formWidget.getAvailableValues();
       if (availableValues != null && !availableValues.isEmpty()) {
         int availableValueIndex = 0;
         for (final FormFieldAvailableValue formFieldAvailableValue : availableValues) {
           final Expression availableValueLabelExpression =
               formFieldAvailableValue.getLabelExpression();
           availableValueLabelExpression.setName(
               widgetId
                   + EXPRESSION_KEY_SEPARATOR
                   + WIDGET_AVAILABLE_VALUE_LABEL
                   + availableValueIndex);
           expressionsToEvaluate.add(availableValueLabelExpression);
           final Expression availableValueValueExpression =
               formFieldAvailableValue.getValueExpression();
           availableValueValueExpression.setName(
               widgetId
                   + EXPRESSION_KEY_SEPARATOR
                   + WIDGET_AVAILABLE_VALUE_VALUE
                   + availableValueIndex);
           expressionsToEvaluate.add(availableValueValueExpression);
           availableValueIndex++;
         }
       }
     }
   }
 }
示例#3
0
 /**
  * @param formWidget
  * @param evaluatedExpressions
  */
 protected void setAvailableValuesListsAndArrays(
     final FormWidget formWidget, final Map<String, Serializable> evaluatedExpressions) {
   final String widgetId = formWidget.getId();
   if (WidgetType.TABLE.equals(formWidget.getType())) {
     if (evaluatedExpressions.containsKey(
         widgetId
             + EXPRESSION_KEY_SEPARATOR
             + WIDGET_AVAILABLE_VALUE_VALUE
             + 0
             + INDEX_SEPARATOR
             + 0)) {
       int availableValueRowIndex = 0;
       do {
         int availableValueColumnIndex = 0;
         do {
           final Object availableValuelabel =
               evaluatedExpressions.get(
                   widgetId
                       + EXPRESSION_KEY_SEPARATOR
                       + WIDGET_AVAILABLE_VALUE_LABEL
                       + availableValueRowIndex
                       + INDEX_SEPARATOR
                       + availableValueColumnIndex);
           final Object availableValueValue =
               evaluatedExpressions.get(
                   widgetId
                       + EXPRESSION_KEY_SEPARATOR
                       + WIDGET_AVAILABLE_VALUE_VALUE
                       + availableValueRowIndex
                       + INDEX_SEPARATOR
                       + availableValueColumnIndex);
           final FormFieldAvailableValue availableValue =
               formWidget
                   .getTableAvailableValues()
                   .get(availableValueRowIndex)
                   .get(availableValueColumnIndex);
           availableValue.setLabel(getStringValue(availableValuelabel));
           availableValue.setValue(getStringValue(availableValueValue));
           availableValueColumnIndex++;
         } while (evaluatedExpressions.containsKey(
             widgetId
                 + EXPRESSION_KEY_SEPARATOR
                 + WIDGET_AVAILABLE_VALUE_VALUE
                 + availableValueRowIndex
                 + INDEX_SEPARATOR
                 + availableValueColumnIndex));
         availableValueRowIndex++;
       } while (evaluatedExpressions.containsKey(
           widgetId
               + EXPRESSION_KEY_SEPARATOR
               + WIDGET_AVAILABLE_VALUE_VALUE
               + availableValueRowIndex
               + INDEX_SEPARATOR
               + 0));
     }
   } else {
     if (evaluatedExpressions.containsKey(
         widgetId + EXPRESSION_KEY_SEPARATOR + WIDGET_AVAILABLE_VALUE_VALUE + 0)) {
       int availableValueIndex = 0;
       do {
         final Object availableValuelabel =
             evaluatedExpressions.get(
                 widgetId
                     + EXPRESSION_KEY_SEPARATOR
                     + WIDGET_AVAILABLE_VALUE_LABEL
                     + availableValueIndex);
         final Object availableValueValue =
             evaluatedExpressions.get(
                 widgetId
                     + EXPRESSION_KEY_SEPARATOR
                     + WIDGET_AVAILABLE_VALUE_VALUE
                     + availableValueIndex);
         final FormFieldAvailableValue availableValue =
             formWidget.getAvailableValues().get(availableValueIndex);
         availableValue.setLabel(getStringValue(availableValuelabel));
         availableValue.setValue(getStringValue(availableValueValue));
         availableValueIndex++;
       } while (evaluatedExpressions.containsKey(
           widgetId
               + EXPRESSION_KEY_SEPARATOR
               + WIDGET_AVAILABLE_VALUE_VALUE
               + availableValueIndex));
     }
   }
 }
示例#4
0
  /**
   * Generate the Map of groovy expressions to evaluate for a widget
   *
   * @param formWidget the widget
   * @param context the context including the URL parameters
   * @return the Map of expressions to evaluate
   */
  protected List<Expression> getWidgetExpressions(
      final FormWidget formWidget, final Map<String, Object> context) {
    final String widgetId = formWidget.getId();
    final List<Expression> expressionsToEvaluate = new ArrayList<Expression>();
    if (formWidget.getLabelExpression() != null) {
      final Expression labelExpression = formWidget.getLabelExpression();
      labelExpression.setName(widgetId + EXPRESSION_KEY_SEPARATOR + WIDGET_LABEL);
      expressionsToEvaluate.add(labelExpression);
    }
    if (formWidget.getTitleExpression() != null) {
      final Expression titleExpression = formWidget.getTitleExpression();
      titleExpression.setName(widgetId + EXPRESSION_KEY_SEPARATOR + WIDGET_TITLE);
      expressionsToEvaluate.add(titleExpression);
    }
    if (formWidget.getSubtitle() != null) {
      final Expression subtitleLabelExpression = formWidget.getSubtitle().getLabelExpression();
      if (subtitleLabelExpression != null) {
        subtitleLabelExpression.setName(widgetId + EXPRESSION_KEY_SEPARATOR + WIDGET_SUBTITLE);
        expressionsToEvaluate.add(subtitleLabelExpression);
      }
    }
    if (formWidget.getPopupTooltipExpression() != null) {
      final Expression popupToolTipExpression = formWidget.getPopupTooltipExpression();
      popupToolTipExpression.setName(widgetId + EXPRESSION_KEY_SEPARATOR + WIDGET_TOOLTIP);
      expressionsToEvaluate.add(popupToolTipExpression);
    }
    addFormWidgetValueExpressionToEvaluate(formWidget, expressionsToEvaluate, context);
    addFormWidgetAvailableValuesExpressions(formWidget, expressionsToEvaluate);

    if (WidgetType.TABLE.equals(formWidget.getType())
        || WidgetType.EDITABLE_GRID.equals(formWidget.getType())) {
      if (formWidget.getValueColumnIndexExpression() != null) {
        final Expression valueColumnIndexExpression = formWidget.getValueColumnIndexExpression();
        valueColumnIndexExpression.setName(
            widgetId + EXPRESSION_KEY_SEPARATOR + WIDGET_VALUE_COLUMN_INDEX);
        expressionsToEvaluate.add(valueColumnIndexExpression);
      }
      if (formWidget.getMaxColumnsExpression() != null) {
        final Expression valueColumnIndexExpression = formWidget.getMaxColumnsExpression();
        valueColumnIndexExpression.setName(
            widgetId + EXPRESSION_KEY_SEPARATOR + WIDGET_MAX_COLUMNS);
        expressionsToEvaluate.add(valueColumnIndexExpression);
      }
      if (formWidget.getMinColumnsExpression() != null) {
        final Expression minColumnsExpression = formWidget.getMinColumnsExpression();
        minColumnsExpression.setName(widgetId + EXPRESSION_KEY_SEPARATOR + WIDGET_MIN_COLUMNS);
        expressionsToEvaluate.add(minColumnsExpression);
      }
      if (formWidget.getMaxRowsExpression() != null) {
        final Expression maxRowsExpression = formWidget.getMaxRowsExpression();
        maxRowsExpression.setName(widgetId + EXPRESSION_KEY_SEPARATOR + WIDGET_MAX_ROWS);
        expressionsToEvaluate.add(maxRowsExpression);
      }
      if (formWidget.getMinRowsExpression() != null) {
        final Expression minRowsExpression = formWidget.getMinRowsExpression();
        minRowsExpression.setName(widgetId + EXPRESSION_KEY_SEPARATOR + WIDGET_MIN_ROWS);
        expressionsToEvaluate.add(minRowsExpression);
      }
      if (formWidget.getVerticalHeaderExpression() != null) {
        final Expression verticalHeaderExpression = formWidget.getVerticalHeaderExpression();
        verticalHeaderExpression.setName(
            widgetId + EXPRESSION_KEY_SEPARATOR + WIDGET_VERTICAL_HEADER);
        expressionsToEvaluate.add(verticalHeaderExpression);
      } else if (formWidget.getVerticalHeaderExpressionList() != null) {
        final List<Expression> verticalHeaderExpressionList =
            formWidget.getVerticalHeaderExpressionList();
        if (!verticalHeaderExpressionList.isEmpty()) {
          int verticalHeaderExpressionListIndex = 0;
          for (final Expression expression : verticalHeaderExpressionList) {
            expression.setName(
                widgetId
                    + EXPRESSION_KEY_SEPARATOR
                    + WIDGET_VERTICAL_HEADER
                    + verticalHeaderExpressionListIndex);
            expressionsToEvaluate.add(expression);
            verticalHeaderExpressionListIndex++;
          }
        }
      }
      if (formWidget.getHorizontalHeaderExpression() != null) {
        final Expression horizontalHeaderExpression = formWidget.getHorizontalHeaderExpression();
        horizontalHeaderExpression.setName(
            widgetId + EXPRESSION_KEY_SEPARATOR + WIDGET_HORIZONTAL_HEADER);
        expressionsToEvaluate.add(horizontalHeaderExpression);
      } else if (formWidget.getHorizontalHeaderExpressionList() != null) {
        final List<Expression> horizontalHeaderExpressionList =
            formWidget.getHorizontalHeaderExpressionList();
        if (!horizontalHeaderExpressionList.isEmpty()) {
          int horizontalHeaderExpressionListIndex = 0;
          for (final Expression expression : horizontalHeaderExpressionList) {
            expression.setName(
                widgetId
                    + EXPRESSION_KEY_SEPARATOR
                    + WIDGET_HORIZONTAL_HEADER
                    + horizontalHeaderExpressionListIndex);
            expressionsToEvaluate.add(expression);
            horizontalHeaderExpressionListIndex++;
          }
        }
      }
    }
    return expressionsToEvaluate;
  }