1 /*
2  * aTunes
3  * Copyright (C) Alex Aranda, Sylvain Gaudard and contributors
4  *
5  * See http://www.atunes.org/wiki/index.php?title=Contributing for information about contributors
6  *
7  * http://www.atunes.org
8  * http://sourceforge.net/projects/atunes
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  */
20 
21 package net.sourceforge.atunes.kernel.modules.context.similar;
22 
23 import net.sourceforge.atunes.kernel.modules.context.ContextTableAction;
24 import net.sourceforge.atunes.model.IAlbum;
25 import net.sourceforge.atunes.model.IArtist;
26 import net.sourceforge.atunes.model.IArtistAlbumSelectorDialog;
27 import net.sourceforge.atunes.model.IArtistInfo;
28 import net.sourceforge.atunes.model.IDialogFactory;
29 import net.sourceforge.atunes.model.IPlayListHandler;
30 import net.sourceforge.atunes.model.IRepositoryHandler;
31 import net.sourceforge.atunes.utils.I18nUtils;
32 
33 /**
34  * Adds an album of select artist to play list
35  *
36  * @author alex
37  *
38  */
39 public final class AddAlbumArtistToPlayListContextTableAction extends
40 		ContextTableAction<IArtistInfo> {
41 
42 	private static final long serialVersionUID = -3920095074089169426L;
43 
44 	private IRepositoryHandler repositoryHandler;
45 
46 	private IDialogFactory dialogFactory;
47 
48 	private IPlayListHandler playListHandler;
49 
50 	/**
51 	 * @param playListHandler
52 	 */
setPlayListHandler(final IPlayListHandler playListHandler)53 	public void setPlayListHandler(final IPlayListHandler playListHandler) {
54 		this.playListHandler = playListHandler;
55 	}
56 
57 	/**
58 	 * @param dialogFactory
59 	 */
setDialogFactory(final IDialogFactory dialogFactory)60 	public void setDialogFactory(final IDialogFactory dialogFactory) {
61 		this.dialogFactory = dialogFactory;
62 	}
63 
64 	/**
65 	 * @param repositoryHandler
66 	 */
setRepositoryHandler(final IRepositoryHandler repositoryHandler)67 	public void setRepositoryHandler(final IRepositoryHandler repositoryHandler) {
68 		this.repositoryHandler = repositoryHandler;
69 	}
70 
71 	/**
72      *
73      */
AddAlbumArtistToPlayListContextTableAction()74 	AddAlbumArtistToPlayListContextTableAction() {
75 		super(I18nUtils.getString("ADD_ALBUM_ARTIST_TO_PLAYLIST"));
76 	}
77 
78 	@Override
execute(final IArtistInfo object)79 	protected void execute(final IArtistInfo object) {
80 		showAddArtistDragDialog(this.repositoryHandler.getArtist(object
81 				.getName()));
82 	}
83 
84 	@Override
getSelectedObject(final int row)85 	protected IArtistInfo getSelectedObject(final int row) {
86 		return ((SimilarArtistsTableModel) getTable().getModel())
87 				.getArtist(row);
88 	}
89 
90 	@Override
isEnabledForObject(final Object object)91 	protected boolean isEnabledForObject(final Object object) {
92 		return this.repositoryHandler.getArtist(((IArtistInfo) object)
93 				.getName()) != null;
94 	}
95 
showAddArtistDragDialog(final IArtist currentArtist)96 	private void showAddArtistDragDialog(final IArtist currentArtist) {
97 		IArtistAlbumSelectorDialog dialog = this.dialogFactory
98 				.newDialog(IArtistAlbumSelectorDialog.class);
99 		dialog.setArtist(currentArtist);
100 		dialog.showDialog();
101 		IAlbum album = dialog.getAlbum();
102 		if (album != null) {
103 			this.playListHandler.addToVisiblePlayList(album.getAudioObjects());
104 		}
105 	}
106 }