Package org.jampa.gui.handlers.playlists

Source Code of org.jampa.gui.handlers.playlists.CopyPlaylistHandler

/*
* 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 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.dialogs.InputDialog;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.handlers.HandlerUtil;
import org.jampa.controllers.Controller;
import org.jampa.gui.translations.Messages;
import org.jampa.gui.views.PlaylistView;
import org.jampa.logging.Log;
import org.jampa.model.validators.PlaylistNameValidator;
import org.jampa.utils.Constants;




public class CopyPlaylistHandler extends AbstractHandler implements IHandler {

  @Override
  public Object execute(ExecutionEvent event) throws ExecutionException {
    InputDialog dialog = new InputDialog(HandlerUtil.getActiveWorkbenchWindow(event).getShell(),
                      Messages.getString("CopyPlaylistHandler.Title"), Messages.getString("CopyPlaylistHandler.Question"), Messages.getString("CopyPlaylistHandler.DefaultValue"), new PlaylistNameValidator()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
   
    int result = dialog.open();
   
    if (result == InputDialog.OK) {
     
      String playlistName;
      IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();           
                 
      playlistName = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart().getTitle();
      if (page.findViewReference(PlaylistView.ID, playlistName) == null) {
        playlistName = Constants.DEFAULT_PLAYLIST_ID;
      }
     
      Controller.getInstance().getPlaylistController().duplicatePlaylist(dialog.getValue(), playlistName);                       

      try {
        page.showView(PlaylistView.ID, dialog.getValue(), IWorkbenchPage.VIEW_ACTIVATE);
      } catch (PartInitException e) {
        Log.getInstance(CopyPlaylistHandler.class).error(e.getMessage());
      }
    }

    return null;
  }

}
TOP

Related Classes of org.jampa.gui.handlers.playlists.CopyPlaylistHandler

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.