private void submitMatch() {
    Match m =
        new Match(
            league.getId(),
            new Date(),
            league.getSports().get(sportBox.getSelectedIndex()),
            league.getPlayers().get(player1Box.getSelectedIndex() - 1),
            league.getPlayers().get(player2Box.getSelectedIndex() - 1));
    for (int i = 0; i < player1Score.size(); i++) {
      try {
        if (!player1Score.get(i).getText().equals("")
            && !player2Score.get(i).getText().equals("")) {
          m.addSet(
              new Set(
                  m.getSport(),
                  Integer.parseInt(player1Score.get(i).getText()),
                  Integer.parseInt(player2Score.get(i).getText())));
        }
      } catch (NumberFormatException e) {
        Window.alert("Failed to parse number: " + e.getMessage());
      }
    }
    AsyncCallback<Void> callback =
        new AsyncCallback<Void>() {
          public void onFailure(Throwable caught) {
            Window.alert("Failed to save match.");
          }

          public void onSuccess(Void arg) {
            Spelstegen.showMessage("Match sparad.", false);
            resetPanel();
          }
        };
    ServiceManager.getInstance().saveMatch(m, loggedInPlayer, league, callback);
  }
 private void populatePlayerBox(ListBox playerBox) {
   playerBox.clear();
   playerBox.addItem("Välj en spelare");
   for (Player player : league.getPlayers()) {
     playerBox.addItem(player.getPlayerName());
   }
 }
 private void updatePanel() {
   if ((loggedInPlayer == null)
       || (league == null)
       || (!league.getPlayers().contains(loggedInPlayer))) {
     mainPanel.clear();
     panelIsVisible = false;
     return;
   } else if (!panelIsVisible) {
     populatePanel();
     panelIsVisible = true;
   }
   populatePlayerBox(player1Box);
   populatePlayerBox(player2Box);
 }
  private void populatePanel() {
    player1Box = new ListBox(false);
    populatePlayerBox(player1Box);
    Label vsLabel = new Label(" spelade mot ");
    player2Box = new ListBox(false);
    populatePlayerBox(player2Box);
    HorizontalPanel playerPanel = Spelstegen.createStandardHorizontalPanel();
    playerPanel.add(player1Box);
    playerPanel.add(vsLabel);
    playerPanel.add(player2Box);

    sportBox = new ListBox(false);
    if (league.getSports().size() > 1) {
      sportBox.addItem("Välj sport");
      for (Sport sport : league.getSports()) {
        sportBox.addItem(sport.getName());
      }
    } else {
      sportBox.addItem(league.getSports().get(0).getName());
      sportBox.setEnabled(false);
    }

    HorizontalPanel sportPanel = Spelstegen.createStandardHorizontalPanel();
    sportPanel.add(new Label("i:"));
    sportPanel.add(sportBox);

    Label setLabel = new Label("Spel om bäst av");
    oneSet = new RadioButton("setSelection", "1");
    threeSet = new RadioButton("setSelection", "3");
    fiveSet = new RadioButton("setSelection", "5");
    oneSet.setValue(true);
    SetClickHandler setClickHandler = new SetClickHandler();
    oneSet.addClickHandler(setClickHandler);
    threeSet.addClickHandler(setClickHandler);
    fiveSet.addClickHandler(setClickHandler);
    Label setLabel2 = new Label(" set");
    HorizontalPanel setPanel = Spelstegen.createStandardHorizontalPanel();
    setPanel.add(setLabel);
    setPanel.add(oneSet);
    setPanel.add(threeSet);
    setPanel.add(fiveSet);
    setPanel.add(setLabel2);

    player1Score = new ArrayList<TextBox>(5);
    player2Score = new ArrayList<TextBox>(5);
    scorePanel = new VerticalPanel();
    scorePanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    setScoreBoxes(1);

    saveButton = new PushButton("Spara");
    if (loggedInPlayer != null) {
      saveButton.setEnabled(loggedInPlayer.isLeagueAdmin(league.getId()));
    }
    saveButton.addClickHandler(
        new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
            submitMatch();
          }
        });

    HorizontalPanel buttonPanel = Spelstegen.createStandardHorizontalPanel();
    buttonPanel.add(saveButton);
    mainPanel.add(playerPanel);
    mainPanel.add(sportPanel);
    mainPanel.add(setPanel);
    mainPanel.add(scorePanel);
    mainPanel.add(buttonPanel);
  }