/*
* 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.handlers.playlists;
import java.util.Iterator;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IHandler;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PlatformUI;
import org.jampa.controllers.Controller;
import org.jampa.gui.views.PlaylistView;
import org.jampa.logging.Log;
import org.jampa.model.playlists.AudioItem;
import org.jampa.utils.Constants;
public class RemoveFromPlaylistHandler extends AbstractHandler implements
IHandler {
@SuppressWarnings("unchecked")
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
String playlistName;
IViewPart playlistView;
playlistName = page.getActivePart().getTitle();
if (page.findViewReference(PlaylistView.ID, playlistName) == null) {
playlistName = Constants.DEFAULT_PLAYLIST_ID;
}
playlistView = page.findViewReference(PlaylistView.ID, playlistName).getView(false);
ISelection selection = ((PlaylistView) playlistView).getViewer().getSelection();
Iterator iter = ((IStructuredSelection)selection).iterator();
while (iter.hasNext()) {
Object obj = iter.next();
Controller.getInstance().getPlaylistController().removeFromPlaylist(playlistName, (AudioItem) obj);
Log.getInstance(RemoveFromPlaylistHandler.class).debug("Removing file " + ((AudioItem ) obj).getFileName() + " from playlist " + playlistName + "."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
return null;
}
}