Exemplo n.º 1
0
  /** Reads view contents from the underlying model. */
  @Override
  protected void updateView() {
    final String currentCoverUrl;
    Track track = getTrack();
    titleField.setText(track.getName());
    trackNumber.setText(track.getTrackNumber());
    comment.setText(track.getComment());
    location.setText(track.getTrackUrl());
    location.setToolTipText(track.getTrackUrl());
    createdDateLabel.setText(DATE_FORMAT.format(track.getCreatedDate()));
    createdByLabel.setText(track.getCreatedUser());
    modifiedDateLabel.setText(DATE_FORMAT.format(track.getModifiedDate()));
    modifiedByLabel.setText(track.getModifiedUser());
    albumImage.setDisc(track.getDisc());
    if (this.getSettings().isCopyImagesToDirectory()) {
      currentCoverUrl =
          ImageFactory.standardImageFileName(
              track.getDisc().getArtist().getName(),
              track.getDisc().getName(),
              track.getDisc().getYear());
    } else {
      currentCoverUrl = track.getDisc().getCoverUrl();
    }
    if (StringUtils.isNotBlank(currentCoverUrl)) {
      int dimension = this.getSettings().getCoverSizeSmall();
      albumImage.setImage(
          ImageFactory.getScaledImage(currentCoverUrl, dimension, dimension).getImage());
    } else {
      albumImage.setImage(null);
    }

    // try and open the tag, but fail safely
    try {
      // AZ: verify if file is accessible
      final File file = new File(track.getTrackUrl());
      if (file.exists()) {
        musicTag = TagFactory.getTag(track.getTrackUrl());
        duration.setText(musicTag.getTrackLengthAsString());
        layer.setText(musicTag.getLayer());
        version.setText(musicTag.getVersion());
        bitRate.setText(musicTag.getBitRateAsString());
        frequency.setText(musicTag.getFrequency() + " Hz");
        mode.setText(musicTag.getMode());
        fileSize.setText(FileUtils.byteCountToDisplaySize(musicTag.getFile().length()));
        emphasis.setText(musicTag.getEmphasis());
        copyrighted.setText(musicTag.getCopyrighted());
      } else {
        LOG.debug("File: " + track.getTrackUrl() + " is not accessible");
        duration.setText("");
        layer.setText("");
        version.setText("");
        bitRate.setText("");
        frequency.setText("");
        mode.setText("");
        fileSize.setText("");
        emphasis.setText("");
        copyrighted.setText("");
        musicTag = null;
      }
    } catch (MusicTagException ex) {
      LOG.info(ex.getMessage(), ex);
      duration.setText("");
      layer.setText("");
      version.setText("");
      bitRate.setText("");
      frequency.setText("");
      mode.setText("");
      fileSize.setText("");
      emphasis.setText("");
      copyrighted.setText("");
      musicTag = null;
    }
  }
Exemplo n.º 2
0
  /*
   * (non-Javadoc)
   * @see com.melloware.jukes.gui.view.editor.AbstractEditor#delete()
   */
  @Override
  public void delete() {
    super.delete();
    final Track track = getTrack();
    final Disc disc = track.getDisc();
    try {
      if (!MessageUtil.confirmDelete(this)) {
        return;
      }
      // try to delete track from database
      setBusyCursor(true);
      HibernateUtil.beginTransaction();
      // AZ: no refreshing to speed-up processing
      // HibernateDao.refresh(disc);
      disc.getTracks().remove(track);
      // HibernateDao.refresh(track);
      HibernateDao.delete(track);
      HibernateUtil.commitTransaction();
      // reset dirty flag since we are deleting
      getValidationModel().setDirty(false);
      // tell the tree to select the parent node
      this.getMainModule().refreshSelection(disc, Resources.NODE_DELETED);
    } catch (Exception ex) {
      final String errorMessage = ResourceUtils.getString("messages.ErrorDeletingTrack");
      MessageUtil.showError(this, errorMessage); // AZ
      LOG.error(errorMessage, ex);
      HibernateUtil.rollbackTransaction();
    } finally {
      setBusyCursor(false);
    }
    // AZ Verify if disc has no more tracks and delete the disc
    if (disc.getTracks().isEmpty()) {
      try {
        // try to delete disc from database
        setBusyCursor(true);
        HibernateUtil.beginTransaction();
        final Artist artist = disc.getArtist();
        // AZ: no refreshing to speed-up processing
        // HibernateDao.refresh(artist);
        artist.getDiscs().remove(disc);
        // HibernateDao.refresh(disc);
        HibernateDao.delete(disc);
        HibernateUtil.commitTransaction();

        // AZ : If transaction is committed and copies of images are used
        // then delete the image copy
        if (this.getSettings().isCopyImagesToDirectory()) {
          final String oldImageName =
              ImageFactory.standardImageFileName(artist.getName(), disc.getName(), disc.getYear());
          File oldImageFile = new File(oldImageName);
          if (oldImageFile.exists()) {
            if (!oldImageFile.delete()) {
              LOG.debug("Error deleting file: " + oldImageFile.getAbsolutePath());
            }
          }
        }
        // reset dirty flag since we are deleting
        getValidationModel().setDirty(false);
      } catch (Exception ex) {
        final String errorMessage = ResourceUtils.getString("messages.ErrorDeletingDisc");
        MessageUtil.showError(this, errorMessage); // AZ
        LOG.error(errorMessage, ex);
        HibernateUtil.rollbackTransaction();
      } finally {
        setBusyCursor(false);
        // refresh main tree
        ActionManager.get(Actions.REFRESH_ID).actionPerformed(null);
      }
    }
  }