Exemplo n.º 1
0
 public void addPlayer(Player player) throws SQLException {
   PreparedStatement pstm =
       connection.prepareStatement(
           "INSERT INTO player(id_player,name,surname,countryfrom, id_club_fk, status, national, transfer_list, youth_team_id, height) VALUES (?, ?, ?, ?, ?, 0, ?, ?, ?, ?)");
   pstm.setInt(1, player.getId());
   pstm.setString(2, player.getName());
   pstm.setString(3, player.getSurname());
   pstm.setInt(4, player.getCountryfrom());
   pstm.setInt(5, player.getTeamId());
   pstm.setInt(6, player.getNational());
   pstm.setInt(7, player.getTransferList());
   pstm.setInt(8, player.getYouthTeamId());
   pstm.setInt(9, player.getHeight());
   pstm.executeUpdate();
   pstm.close();
 }
  public void fill(List<PlayerStats> alPlayerStats) {
    this.alPlayersStats = alPlayerStats;
    this.setRedraw(false);
    this.remove(0, this.getItemCount() - 1);
    if (alPlayerStats == null) {
      this.setRedraw(true);
      return;
    }
    for (PlayerStats playerStats : alPlayerStats) {
      TableItem item = new TableItem(this, SWT.NONE);
      if (playerStats.getFormation() == PlayerStats.GK) {
        item.setBackground(Colors.getPositionGK());
      } else if (playerStats.getFormation() == PlayerStats.DEF) {
        item.setBackground(Colors.getPositionDEF());
      } else if (playerStats.getFormation() == PlayerStats.MID) {
        item.setBackground(Colors.getPositionMID());
      } else if (playerStats.getFormation() == PlayerStats.ATT) {
        item.setBackground(Colors.getPositionATT());
      }
      int i = 0;
      if (playerStats.getTimeOut() > 0 && playerStats.getTimeIn() == 0) {
        item.setImage(i++, ImageResources.getImageResources("down_icon.png"));
      } else if (playerStats.getTimeIn() > 0 && playerStats.getTimeOut() == 0) {
        item.setImage(i++, ImageResources.getImageResources("up_icon.png"));
      } else if (playerStats.getTimeIn() > 0 && playerStats.getTimeOut() > 0) {
        item.setImage(i++, ImageResources.getImageResources("in_out.png"));
      } else {
        i++;
      }

      if (playerStats.getTimeIn() > 0) {
        item.setText(i++, "R" + playerStats.getNumber());
      } else if (playerStats.getTimePlayed() == 0) {
        item.setText(i++, "R");
      } else {
        item.setText(i++, String.valueOf(playerStats.getNumber()));
      }

      Player player = playerStats.getPlayer();
      if (player != null && player.getExistsInSokker() != Player.EXISTS_IN_SOKKER_UNCHECKED) {
        if (player.getExistsInSokker() == Player.EXISTS_IN_SOKKER_TRUE
            || player.getExistsInSokker() == Player.EXISTS_IN_SOKKER_COMPLETED) {
          item.setImage(i, FlagsResources.getFlag(player.getCountryfrom()));
          if (player.getName() == null
              || player.getSurname() == null
              || (player.getName().isEmpty() && player.getSurname().isEmpty())) {
            item.setText(i++, String.valueOf(playerStats.getPlayerId()));
          } else {
            if (player.getName().isEmpty()) {
              item.setText(i++, String.format("%s", player.getSurname()));
            } else {
              item.setText(
                  i++,
                  String.format("%s %s.", player.getSurname(), player.getName().substring(0, 1)));
            }
          }
        } else {
          item.setImage(i, FlagsResources.getFlag(FlagsResources.EMPTY_FLAG));
          item.setText(i++, String.valueOf(playerStats.getPlayerId() + " (n/a)"));
        }
      } else {
        item.setImage(i, FlagsResources.getFlag(FlagsResources.QUESTION_FLAG));
        item.setText(i++, String.valueOf(playerStats.getPlayerId() + " (n/d)"));
      }

      if (playerStats.getFormation() >= 0 && playerStats.getFormation() <= 4) {
        item.setText(i++, Messages.getString("formation." + playerStats.getFormation()));
      } else {
        item.setText(i++, "");
      }

      if (playerStats.getTimePlayed() == 0) {
        item.setForeground(ColorResources.getDarkGray());
        item.setBackground(ColorResources.getWhite());
      }
      item.setText(i++, playerStats.getTimePlayed() + "'");

      item.setText(i++, playerStats.getRating() + "%");
      item.setText(i++, String.valueOf(playerStats.getGoals()));
      item.setText(i++, String.valueOf(playerStats.getShoots()));
      item.setText(i++, String.valueOf(playerStats.getAssists()));
      item.setText(i++, String.valueOf(playerStats.getFouls()));

      item.setText(i, "");
      if (SettingsHandler.IS_WINDOWS) {
        item.setBackground(i, this.getBackground());
      }

      if (playerStats.getIsInjured() == PlayerStats.INJURED) {
        item.setImage(i++, ImageResources.getImageResources("injury.png"));
      } else {
        i++;
      }

      item.setText(i, "");
      if (SettingsHandler.IS_WINDOWS) {
        item.setBackground(i, this.getBackground());
      }
      if (playerStats.getYellowCards() < 2 && playerStats.getRedCards() > 0) {
        item.setImage(i++, ImageResources.getImageResources("red_card.png"));
      } else if (playerStats.getYellowCards() > 1 && playerStats.getRedCards() > 0) {
        item.setImage(i++, ImageResources.getImageResources("2_yellow_cards_1_red_card.png"));
      } else if (playerStats.getYellowCards() == 1 && playerStats.getRedCards() < 1) {
        item.setImage(i++, ImageResources.getImageResources("yellow_card.png"));
      } else if (playerStats.getYellowCards() > 1 && playerStats.getRedCards() < 1) {
        item.setImage(i++, ImageResources.getImageResources("2_yellow_cards.png"));
      } else {
        i++;
      }
      // item.setText(i++, String.valueOf(playerStats.getYellowCards() + "
      // " +
      // playerStats.getRedCards()));
    }
    for (int i = 0; i < this.getColumnCount() - 1; i++) {

      if (i == 0) {
        this.getColumn(i).setWidth(25);
      } else {
        this.getColumn(i).pack();
      }
      // else {
      // this.getColumn(i).setWidth(this.getColumn(i).getWidth() + 3);
      // }
    }

    // for (int i = 0; i < this.getItemCount(); i++) {
    // if ((i % 2) == 1) {
    // this.getItem(i).setBackground(this.getDisplay().getSystemColor(SWT.COLOR_GRAY));
    // }
    // }
    this.setRedraw(true);
    // table.pack();
    // table.computeSize(SWT.DEFAULT, SWT.DEFAULT);
  }