/*
* 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.IWorkbenchWindow;
import org.eclipse.ui.handlers.HandlerUtil;
import org.jampa.controllers.Controller;
import org.jampa.gui.actions.playlist.OpenPlaylistAction;
import org.jampa.logging.Log;
import org.jampa.model.IAudioItem;
import org.jampa.model.playlists.Playlist;
public class MenuOpenAndPlayPlaylistHandler extends AbstractHandler implements IHandler {
@SuppressWarnings("unchecked")
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
ISelection selection = window.getActivePage().getSelection();
Playlist item;
Playlist firstItem = null;
Iterator iter = ((IStructuredSelection)selection).iterator();
while (iter.hasNext()) {
item = (Playlist) iter.next();
if (firstItem == null) {
firstItem = item;
}
Log.getInstance(MenuOpenPlaylistHandler.class).debug("Openning playlist: " + item.getName()); //$NON-NLS-1$
new OpenPlaylistAction(item.getName()).run();
}
if (firstItem != null) {
IAudioItem firstAudioItem = firstItem.getAudioItemByIndex(0);
Controller.getInstance().getPlaylistController().playFile(firstItem, firstAudioItem);
}
return null;
}
}