Package org.jampa.gui.dialogs

Source Code of org.jampa.gui.dialogs.CheckPlaylistsDialog

/*
* Jampa
* Copyright (C) 2008-2009 J. Devauchelle and contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 3 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*/

package org.jampa.gui.dialogs;

import java.util.HashMap;
import java.util.Iterator;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.IMessageProvider;
import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.jface.util.Util;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.jampa.controllers.Controller;
import org.jampa.gui.translations.Messages;
import org.jampa.model.playlists.AudioItem;

public class CheckPlaylistsDialog extends TitleAreaDialog {

  private Table viewer;
  private TableColumn _playlistCol;
  private TableColumn _fileCol;
  private Label _laResult;
  private Button _correctBtn;
 
  private HashMap<AudioItem, String> _correctList = null;
 
  public CheckPlaylistsDialog(Shell parentShell) {
    super(parentShell);     
  }
 
  protected Control createContents(Composite parent) {
    Control contents = super.createContents(parent);
   
    // Set the title
    setTitle(Messages.getString("CheckPlaylistsDialog.Title")); //$NON-NLS-1$
    // Set the message
    setMessage(Messages.getString("CheckPlaylistsDialog.TitleArea"), IMessageProvider.INFORMATION); //$NON-NLS-1$
    return contents;
  }
 
  protected Control createDialogArea(Composite parent) {
    Composite composite = (Composite) super.createDialogArea(parent);
   
      // Create a table
      viewer = new Table(composite, SWT.FULL_SELECTION | SWT.BORDER);
      viewer.setLayoutData(new GridData(GridData.FILL_BOTH));

      // Create two columns and show
      _playlistCol = new TableColumn(viewer, SWT.LEFT);
      _playlistCol.setText(Messages.getString("CheckPlaylistsDialog.ColHeaderPlaylist")); //$NON-NLS-1$

      _fileCol = new TableColumn(viewer, SWT.LEFT);
      _fileCol.setText(Messages.getString("CheckPlaylistsDialog.ColHeaderFile")); //$NON-NLS-1$
   
    // Lines visible is ugly under Windows.
    if (!Util.isWindows()) {
      viewer.setLinesVisible(true);
    }
    viewer.setHeaderVisible(true);   
     
    _playlistCol.pack();
    _fileCol.pack();
   
    _laResult = new Label(composite, SWT.NONE);
    _laResult.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));
    //_laResult.setText(Messages.getString("CheckPlaylistsDialog.Results")); //$NON-NLS-1$
    _laResult.setText(""); //$NON-NLS-1$
   
    return parent;
  }
 
  protected void createButtonsForButtonBar(Composite parent) {
    _correctBtn = createButton(parent, -1, Messages.getString("CheckPlaylistsDialog.BtnCorrect"), false); //$NON-NLS-1$
    Button doCheckBtn = createButton(parent, -1, Messages.getString("CheckPlaylistsDialog.BtnCheck"), false); //$NON-NLS-1$
    Button closeBtn = createButton(parent, IDialogConstants.CLOSE_ID, Messages.getString("CheckPlaylistsDialog.BtnClose"), true); //$NON-NLS-1$     
   
    _correctBtn.setEnabled(false);
    _correctBtn.addSelectionListener(new SelectionAdapter() {
      public void widgetSelected(SelectionEvent e) {
        correctList(_correctList);
      }
    });
   
    doCheckBtn.addSelectionListener(new SelectionAdapter() {
      public void widgetSelected(SelectionEvent e) {
        _correctList = Controller.getInstance().getPlaylistController().doCheckPlaylists();
        updateList(_correctList);     
      }
    });
   
    closeBtn.addSelectionListener(new SelectionAdapter() {
      public void widgetSelected(SelectionEvent e) {       
        close();       
      }
    });
  }
 
  private void correctList(HashMap<AudioItem, String> values) {
    if (values.size() > 0) {
      AudioItem audioItem;
      String playList;
      Iterator<AudioItem> iter = values.keySet().iterator();
      while (iter.hasNext()) {
        audioItem = iter.next();
        playList = values.get(audioItem);
        Controller.getInstance().getPlaylistController().removeFromPlaylist(playList, audioItem);
      }
    }
    _correctBtn.setEnabled(false);
    _correctList = Controller.getInstance().getPlaylistController().doCheckPlaylists();
    updateList(_correctList);
  }
 
  private void updateList(HashMap<AudioItem, String> values) {
    TableItem item;
    String message = Messages.getString("CheckPlaylistsDialog.Results") + " " + //$NON-NLS-1$ //$NON-NLS-2$
              values.size() + " " + Messages.getString("CheckPlaylistsDialog.NbFileResult"); //$NON-NLS-1$ //$NON-NLS-2$   
   
    viewer.removeAll();
    if (values.size() > 0) {
      AudioItem audioItem;
      String playList;
      Iterator<AudioItem> iter = values.keySet().iterator();
      while (iter.hasNext()) {
        audioItem = iter.next();
        playList = values.get(audioItem);
        item = new TableItem(viewer, SWT.NONE);
        item.setText(0, playList);
        item.setText(1, audioItem.getFileName());
      }
      _correctBtn.setEnabled(true);
     
      message = message + " " + Messages.getString("CheckPlaylistsDialog.MsgEntryNeedCorrection"); //$NON-NLS-1$ //$NON-NLS-2$
    }
   
    _laResult.setText(message);
   
    _playlistCol.pack();
    _fileCol.pack();
  }
 
  protected Point getInitialSize() {
    return new Point(600, 300);
  }
}
TOP

Related Classes of org.jampa.gui.dialogs.CheckPlaylistsDialog

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.