@Override protected void onUnload() { super.onUnload(); RootPanel.get().remove(goTop); }
/* * 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; } } }
@Override protected void onAttach() { super.onAttach(); RootPanel.get().add(goTop); }