示例#1
0
 @Override
 protected void onUnload() {
   super.onUnload();
   RootPanel.get().remove(goTop);
 }
示例#2
0
  /*
   * Purpose - When adding a food to a meal plan, default the quantity to the food serving size
   */
  private void updateQuantityWithServingSize(LookupFieldView lookupFieldView) {
    // Determine food ID
    int intFoodID = lookupFieldView.getInt();

    // Get the serving size of the food
    double doubleFoodServingQuantity = 0;

    // Create a CalculatedModel for this purpose
    CalculatedModel calculatedModel = new CalculatedModel();
    calculatedModel.setConnection(applicationController.getConnection());

    try {
      doubleFoodServingQuantity = calculatedModel.getFoodServingQuantity(intFoodID);
    } catch (SQLException e) {
      // Just default to zero quantity on any database error
      return;
    }

    // Set the value in the quantity widget to the serving size
    IWidgetView widgetViewParent = lookupFieldView.getParentWidgetView();
    CompositeView compositeView = null;

    // Parent widget should be a CompositeView (part of SubObjectView)
    if (widgetViewParent instanceof CompositeView) {
      compositeView = (CompositeView) widgetViewParent;
    } else {
      assert (false);
      return;
    }

    // Find the Quantity field
    Map<IWidgetUI, IWidgetView> mapWidget = compositeView.getWidgetMap();
    for (Map.Entry<IWidgetUI, IWidgetView> entry : mapWidget.entrySet()) {
      IWidgetUI widgetUI = entry.getKey();
      IWidgetView widgetView = entry.getValue();

      switch (widgetUI.getWidgetType()) {
        case OBJECT:
        case GROUP:
        case LIST:
          break;
        case FIELD:
          IFieldUI iFieldUI = (IFieldUI) widgetUI;
          String stringName = iFieldUI.getName();

          if (stringName != null && stringName.equals("Quantity")) {
            // Found quantity widget
            // Set the serving size as the value
            assert (widgetView.getWidgetType() == IWidgetView.TYPE.FIELD);
            FieldView fieldView = (FieldView) widgetView;

            assert (fieldView instanceof DecimalFieldView);
            DecimalFieldView decimalFieldView = (DecimalFieldView) fieldView;

            decimalFieldView.setDouble(doubleFoodServingQuantity);
            return;
          }

          break;
      }
    }
  }
示例#3
0
 @Override
 protected void onAttach() {
   super.onAttach();
   RootPanel.get().add(goTop);
 }