/**
   * Adds and asset to the asset table and sets up all the click handlers for the given links.
   *
   * @param assetText
   * @param assetLink
   */
  private void addAssetToTable(final ScrollBarTextBox assetText, SquareHyperlink assetLink) {

    // add the click handler for removing the link from the textbox.
    assetLink.addClickHandler(
        new ClickHandler() {
          boolean commitChanges = false;

          public void onClick(ClickEvent event) {
            if (assetText.getText().toString().length() != 0) {
              boolean isAssetToBeDeleted = Window.confirm(messages.confirmAssetDelete());
              if (isAssetToBeDeleted) {
                commitChanges = true;
              }
            } else {
              commitChanges = true;
            }
            if (commitChanges) {
              // this should also delete the asset from the DB.
              Cell cellForEvent = assetsTable.getCellForEvent(event);
              int row = cellForEvent.getRowIndex();
              removeRowInAssetsTable(assetsTable, row, assetText.getKey(), assetText);
            }
          }
        });

    assetText.addClickHandler(
        new ClickHandler() {

          public void onClick(ClickEvent event) {
            Cell cellForEvent = assetsTable.getCellForEvent((ClickEvent) event);
            int row = cellForEvent.getRowIndex();
            assetText.setName(row + "");
          }
        });

    // Add the blur handler to save the information from the textbox to the
    // DB
    assetText.addBlurHandler(
        new BlurHandler() {
          public void onBlur(BlurEvent event) {
            // don't save anything if the textbox is empty
            if (assetText.getText().equals("")) {
              return;
            }

            int index = Integer.parseInt(assetText.getName());

            GwtAsset newAsset = new GwtAsset();
            newAsset.setDescription(assetText.getText());

            if (assetText.getKey() == null) {
              addAssetToDatabase(newAsset, index, assetText);
            } else {
              newAsset.setId(Integer.parseInt(assetText.getKey()));
              updateAssetInDatabase(
                  newAsset, index, Integer.parseInt(assetText.getKey()), assetText);
            }
          }
        });
  }
  /**
   * Adds and goal to the sub goals table and sets up all the click handlers for the given links.
   *
   * @param assetText
   * @param assetLink
   */
  private void addGoalToTable(final ScrollBarTextBox userInput, SquareHyperlink subGoalLink) {
    // add the click handler for removing the link from the textbox.
    subGoalLink.addClickHandler(
        new ClickHandler() {
          boolean commitChanges = false;

          public void onClick(ClickEvent event) {
            if (userInput.getText().toString().length() != 0) {
              boolean isSubGoalToBeDeleted = Window.confirm(messages.confirmSubGoalDelete());
              if (isSubGoalToBeDeleted) {
                commitChanges = true;
              }
            } else {
              commitChanges = true;
            }
            if (commitChanges) {
              Cell cellForEvent = subGoalsTable.getCellForEvent(event);
              int row = cellForEvent.getRowIndex();
              removeRowInSubGoalsTable(subGoalsTable, row, userInput.getKey(), userInput);
            }
          }
        });

    userInput.addClickHandler(
        new ClickHandler() {
          public void onClick(ClickEvent event) {
            Cell cellForEvent = subGoalsTable.getCellForEvent((ClickEvent) event);
            int row = cellForEvent.getRowIndex();
            userInput.setName(row + "");
          }
        });

    // Add the blur handler to save the information from the textbox to the DB
    userInput.addBlurHandler(
        new BlurHandler() {
          public void onBlur(BlurEvent event) {
            // don't save anything if the textbox is empty
            if (userInput.getText().equals("")) {
              return;
            }

            int index = Integer.parseInt(userInput.getName());

            GwtSubGoal newSubGoal = new GwtSubGoal();
            newSubGoal.setDescription(userInput.getText());

            if (userInput.getKey() == null) {
              newSubGoal.setPriority(new Integer(-1));
              addSubGoalToDatabase(newSubGoal, index, userInput);
            } else {
              newSubGoal.setId(Integer.parseInt(userInput.getKey()));
              newSubGoal.setPriority(userInput.getPriority());
              updateSubGoalInDatabase(
                  newSubGoal, index, Integer.parseInt(userInput.getKey()), userInput);
            }
          }
        });
  }