예제 #1
0
  private List<ViewComponentState> getViewPointData(User user, View view, boolean edit) {
    WebContext webContext = WebContextFactory.get();
    HttpServletRequest request = webContext.getHttpServletRequest();
    List<ViewComponentState> states = new ArrayList<ViewComponentState>();
    Map<String, Object> model = new HashMap<String, Object>();
    RuntimeManager rtm = Common.ctx.getRuntimeManager();

    for (ViewComponent viewComponent : view.getViewComponents()) {
      if (viewComponent.isCompoundComponent() && (edit || viewComponent.isVisible())) {
        CompoundComponent compoundComponent = (CompoundComponent) viewComponent;

        boolean imageChart = compoundComponent instanceof ImageChartComponent;

        // Add states for each of the children
        for (CompoundChild child : compoundComponent.getChildComponents())
          addPointComponentState(
              child.getViewComponent(), rtm, model, request, view, user, states, edit, !imageChart);

        // Add a state for the compound component.
        ViewComponentState state = new ViewComponentState();
        state.setId(compoundComponent.getId());

        model.clear();
        model.put("compoundComponent", compoundComponent);

        List<Map<String, Object>> childData = new ArrayList<Map<String, Object>>();
        for (CompoundChild child : compoundComponent.getChildComponents()) {
          if (child.getViewComponent().isPointComponent()) {
            DataPointVO point = ((PointComponent) child.getViewComponent()).tgetDataPoint();
            if (point != null) {
              Map<String, Object> map = new HashMap<String, Object>();
              if (imageChart) map.put("name", point.getName());
              else map.put("name", getMessage(child.getDescription()));
              map.put("point", point);
              map.put("pointValue", point.lastValue());
              childData.add(map);
            }
          }
        }
        model.put("childData", childData);

        if (compoundComponent.hasInfo())
          state.setInfo(generateContent(request, "compoundInfoContent.jsp", model));

        if (imageChart)
          state.setContent(
              ((ImageChartComponent) compoundComponent).getImageChartData(getResourceBundle()));
        else if (!edit) state.setChart(compoundComponent.getImageChartData(getResourceBundle()));

        states.add(state);
      } else
        addPointComponentState(viewComponent, rtm, model, request, view, user, states, edit, true);
    }

    return states;
  }
예제 #2
0
  /** Shared convenience method for creating a populated view component state. */
  private ViewComponentState preparePointComponentState(
      PointComponent pointComponent,
      User user,
      DataPointRT point,
      Map<String, Object> model,
      HttpServletRequest request) {
    ViewComponentState state = new ViewComponentState();
    state.setId(pointComponent.getId());

    PointValueTime pointValue =
        prepareBasePointState(
            pointComponent.getId(), state, pointComponent.tgetDataPoint(), point, model);

    model.put("pointComponent", pointComponent);
    if (pointComponent.isValid()) setEvents(pointComponent.tgetDataPoint(), user, model);

    pointComponent.addDataToModel(model, pointValue);

    if (!pointComponent.isValid()) model.put("invalid", "true");
    else {
      // Add the rendered text as a convenience to the snippets.
      model.put(
          "text",
          pointComponent
              .tgetDataPoint()
              .getTextRenderer()
              .getText(pointValue, TextRenderer.HINT_FULL));

      state.setContent(generateContent(request, pointComponent.snippetName() + ".jsp", model));
      pointComponent.tgetDataPoint().updateLastValue(pointValue);
    }

    state.setInfo(generateContent(request, "infoContent.jsp", model));
    setMessages(state, request, "warningContent", model);

    return state;
  }