/*
* 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.controllers.ui;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.commands.ActionHandler;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IPerspectiveDescriptor;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.WorkbenchException;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.dialogs.ElementListSelectionDialog;
import org.eclipse.ui.handlers.IHandlerService;
import org.jampa.Activator;
import org.jampa.controllers.Controller;
import org.jampa.controllers.events.EventConstants;
import org.jampa.gui.actions.PauseAction;
import org.jampa.gui.actions.PlayNextAction;
import org.jampa.gui.actions.PlayPreviousAction;
import org.jampa.gui.actions.SetVolumeAction;
import org.jampa.gui.actions.StopAction;
import org.jampa.gui.actions.VolumeMuteAction;
import org.jampa.gui.actions.playlist.NewPlaylistAction;
import org.jampa.gui.actions.playlist.OpenPlaylistAction;
import org.jampa.gui.dialogs.CheckPlaylistsDialog;
import org.jampa.gui.dialogs.RemovableStorageDialog;
import org.jampa.gui.perspectives.MainPerspective;
import org.jampa.gui.translations.Messages;
import org.jampa.gui.views.DebugView;
import org.jampa.gui.views.DiskView;
import org.jampa.gui.views.EqualizerView;
import org.jampa.gui.views.HelpView;
import org.jampa.gui.views.LibraryView;
import org.jampa.gui.views.PlayerView;
import org.jampa.gui.views.PlaylistOverview;
import org.jampa.gui.views.PlaylistView;
import org.jampa.gui.views.PodcastListView;
import org.jampa.gui.views.PropertyView;
import org.jampa.gui.views.RadioView;
import org.jampa.gui.views.SearchView;
import org.jampa.gui.views.StatisticView;
import org.jampa.gui.wizard.playlistexport.PlaylistExportWizard;
import org.jampa.gui.wizard.playlistimport.PlaylistImportWizard;
import org.jampa.gui.wizard.playlistsgenerator.PlaylistGeneratorWizard;
import org.jampa.logging.Log;
import org.jampa.model.IAudioItem;
import org.jampa.net.version.VersionCheckerJobLauncher;
import org.jampa.preferences.PreferenceConstants;
import org.jampa.utils.ApplicationUtils;
import org.jampa.utils.Constants;
public class MenuController implements PropertyChangeListener {
/**
* Playlists menu.
*/
private IAction newPlaylistAction;
private IAction playlistGeneratorAction;
private IAction importPlaylistAction;
private IAction exportPlaylistAction;
private IAction checkPlaylistsAction;
private IAction exitAction;
/**
* Actions menu.
*/
private IAction volumeDownAction;
private IAction volumeUpAction;
private IAction volumeMuteAction;
private IAction volume100Action;
private IAction volume75Action;
private IAction volume50Action;
private IAction volume25Action;
private IAction previousAction;
private IAction stopAction;
private IAction pauseAction;
private IAction nextAction;
private IAction manageExternalDevices;
private IAction updateLibrary;
private IAction scanLibrary;
/**
* Tools menu.
*/
/**
* Views menu.
*/
private IAction showDiskViewAction;
private IAction showLibraryViewAction;
private IAction showPlaylistsViewAction;
private IAction showDefaultPlaylistViewAction;
private IAction showPodcastViewAction;
private IAction showRadioViewAction;
private IAction showPropertyViewAction;
private IAction showControlsViewAction;
private IAction showEqualizerViewAction;
private IAction showStatisticsViewAction;
private IAction showSearchViewAction;
private IAction resetUIAction;
private IAction showPreferencesWindowAction;
private IAction savePerspectiveAction;
private IAction removePerspectiveAction;
/**
* Help menu.
*/
private IAction showHelpViewAction;
private IAction checkUpdateAction;
private IAction showDebugViewAction;
private IAction showAboutAction;
private IWorkbenchWindow _window = null;
public MenuController() {
Controller.getInstance().getEventController().addAudioItemChangeListener(this);
}
private void buildHelpAction(final IWorkbenchWindow window, IHandlerService handlerService) {
showHelpViewAction = new Action(Messages.getString("Menu.Help.ShowHelpView"), SWT.NONE) {
public void run() {
ApplicationUtils.showViewByID(HelpView.ID);
}
};
showHelpViewAction.setImageDescriptor(Activator.getImageDescriptor("/icons/help_16.png"));
showHelpViewAction.setActionDefinitionId("Jampa.showHelpView");
handlerService.activateHandler("Jampa.showHelpView", new ActionHandler(showHelpViewAction));
checkUpdateAction = new Action(Messages.getString("Menu.Help.CheckUpdate"), SWT.NONE) {
public void run() {
new VersionCheckerJobLauncher(false, true).start();
}
};
checkUpdateAction.setActionDefinitionId("Jampa.menuCheckVersion");
handlerService.activateHandler("Jampa.menuCheckVersion", new ActionHandler(checkUpdateAction));
showDebugViewAction = new Action(Messages.getString("Menu.Help.ShowDebugView"), SWT.NONE) {
public void run() {
ApplicationUtils.showViewByID(DebugView.ID);
}
};
showDebugViewAction.setImageDescriptor(Activator.getImageDescriptor("/icons/debug.png"));
showDebugViewAction.setActionDefinitionId("Jampa.showConsoleView");
handlerService.activateHandler("Jampa.showConsoleView", new ActionHandler(showDebugViewAction));
resetUIAction = new Action(Messages.getString("Menu.Help.ResetUI"), SWT.NONE) {
public void run() {
try {
PlatformUI.getWorkbench().showPerspective(MainPerspective.ID, window);
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().resetPerspective();
} catch (WorkbenchException e) {
Log.getInstance(MenuController.class).warn("Unable to reset UI: " + e.getMessage());
}
}
};
resetUIAction.setActionDefinitionId("Jampa.resetViews");
handlerService.activateHandler("Jampa.resetViews", new ActionHandler(resetUIAction));
showAboutAction = ActionFactory.ABOUT.create(window);
}
private void fillHelpMenu(IMenuManager menuBar) {
MenuManager helpMenu = new MenuManager(Messages.getString("Menu.Help"));
menuBar.add(helpMenu);
helpMenu.add(showHelpViewAction);
helpMenu.add(checkUpdateAction);
helpMenu.add(new Separator());
helpMenu.add(showDebugViewAction);
helpMenu.add(resetUIAction);
helpMenu.add(new Separator());
helpMenu.add(showAboutAction);
}
private void buildViewsAction(final IWorkbenchWindow window, final IHandlerService handlerService) {
_window = window;
showDiskViewAction = new Action(Messages.getString("Menu.Views.ShowDiskView"), SWT.NONE) {
public void run() {
ApplicationUtils.showViewByID(DiskView.ID);
}
};
showDiskViewAction.setImageDescriptor(Activator.getImageDescriptor("/icons/folderview_16.png"));
showDiskViewAction.setActionDefinitionId("Jampa.showDiskView");
handlerService.activateHandler("Jampa.showDiskView", new ActionHandler(showDiskViewAction));
showLibraryViewAction = new Action(Messages.getString("Menu.Views.ShowLibraryView"), SWT.NONE) {
public void run() {
ApplicationUtils.showViewByID(LibraryView.ID);
}
};
showLibraryViewAction.setImageDescriptor(Activator.getImageDescriptor("/icons/libraryview_16.png"));
showLibraryViewAction.setActionDefinitionId("Jampa.showLibraryView");
handlerService.activateHandler("Jampa.showLibraryView", new ActionHandler(showLibraryViewAction));
showPlaylistsViewAction = new Action(Messages.getString("Menu.Views.ShowPlaylistsView"), SWT.NONE) {
public void run() {
ApplicationUtils.showViewByID(PlaylistOverview.ID);
}
};
showPlaylistsViewAction.setImageDescriptor(Activator.getImageDescriptor("/icons/playlistoverview_16.png"));
showPlaylistsViewAction.setActionDefinitionId("Jampa.showPlaylistOverview");
handlerService.activateHandler("Jampa.showPlaylistOverview", new ActionHandler(showPlaylistsViewAction));
showDefaultPlaylistViewAction = new Action(Messages.getString("Menu.Views.ShowDefaultPlaylistView"), SWT.NONE) {
public void run() {
ApplicationUtils.showViewByID(PlaylistView.ID, Constants.DEFAULT_PLAYLIST_ID);
}
};
showDefaultPlaylistViewAction.setImageDescriptor(Activator.getImageDescriptor("/icons/playlist_16.png"));
showDefaultPlaylistViewAction.setActionDefinitionId("Jampa.showDefaultPlaylist");
handlerService.activateHandler("Jampa.showDefaultPlaylist", new ActionHandler(showDefaultPlaylistViewAction));
showPodcastViewAction = new Action(Messages.getString("Menu.Views.ShowPodcastView"), SWT.NONE) {
public void run() {
ApplicationUtils.showViewByID(PodcastListView.ID);
}
};
showPodcastViewAction.setImageDescriptor(Activator.getImageDescriptor("/icons/rss_list_16.png"));
showPodcastViewAction.setActionDefinitionId("Jampa.showPodcastListView");
handlerService.activateHandler("Jampa.showPodcastListView", new ActionHandler(showPodcastViewAction));
showRadioViewAction = new Action(Messages.getString("Menu.Views.ShowRadioView"), SWT.NONE) {
public void run() {
ApplicationUtils.showViewByID(RadioView.ID);
}
};
showRadioViewAction.setImageDescriptor(Activator.getImageDescriptor("/icons/radio_16.png"));
showRadioViewAction.setActionDefinitionId("Jampa.showRadioView");
handlerService.activateHandler("Jampa.showRadioView", new ActionHandler(showRadioViewAction));
showPropertyViewAction = new Action(Messages.getString("Menu.Views.ShowPropertyView"), SWT.NONE) {
public void run() {
ApplicationUtils.showViewByID(PropertyView.ID);
}
};
showPropertyViewAction.setImageDescriptor(Activator.getImageDescriptor("/icons/property_16.png"));
showPropertyViewAction.setActionDefinitionId("Jampa.showPropertyView");
handlerService.activateHandler("Jampa.showPropertyView", new ActionHandler(showPropertyViewAction));
showControlsViewAction = new Action(Messages.getString("Menu.Views.ShowControlsView"), SWT.NONE) {
public void run() {
ApplicationUtils.showViewByID(PlayerView.ID);
}
};
showControlsViewAction.setImageDescriptor(Activator.getImageDescriptor("/icons/playerview_16.png"));
showControlsViewAction.setActionDefinitionId("Jampa.showPlayerView");
handlerService.activateHandler("Jampa.showPlayerView", new ActionHandler(showControlsViewAction));
showEqualizerViewAction = new Action(Messages.getString("Menu.Views.ShowEqualizerView"), SWT.NONE) {
public void run() {
ApplicationUtils.showViewByID(EqualizerView.ID);
}
};
showEqualizerViewAction.setImageDescriptor(Activator.getImageDescriptor("/icons/equalizer_16.png"));
showEqualizerViewAction.setActionDefinitionId("Jampa.showEqualizerView");
handlerService.activateHandler("Jampa.showEqualizerView", new ActionHandler(showEqualizerViewAction));
showStatisticsViewAction = new Action(Messages.getString("Menu.Views.ShowStatisticsView"), SWT.NONE) {
public void run() {
ApplicationUtils.showViewByID(StatisticView.ID);
}
};
showStatisticsViewAction.setImageDescriptor(Activator.getImageDescriptor("/icons/stats_16.png"));
showStatisticsViewAction.setActionDefinitionId("Jampa.showStatisticView");
handlerService.activateHandler("Jampa.showStatisticView", new ActionHandler(showStatisticsViewAction));
showPreferencesWindowAction = ActionFactory.PREFERENCES.create(window);
showPreferencesWindowAction.setImageDescriptor(Activator.getImageDescriptor("/icons/preferences_16.png"));
showPreferencesWindowAction.setActionDefinitionId("org.eclipse.ui.window.preferences");
handlerService.activateHandler("org.eclipse.ui.window.preferences", new ActionHandler(showPreferencesWindowAction));
savePerspectiveAction = ActionFactory.SAVE_PERSPECTIVE.create(window);
savePerspectiveAction.setText(Messages.getString("Menu.Views.SavePerspective"));
removePerspectiveAction = new Action(Messages.getString("Menu.Views.RemovePerspective"), SWT.NONE) {
public void run() {
String perspectiveName = getPerspectiveId(window,
Messages.getString("Menu.Views.RemovePerspectiveTitle"),
Messages.getString("Menu.Views.RemovePerspectiveMessage"));
if ((perspectiveName != null) &&
(!perspectiveName.isEmpty())) {
PlatformUI.getWorkbench().getPerspectiveRegistry().deletePerspective(
PlatformUI.getWorkbench().getPerspectiveRegistry().findPerspectiveWithLabel(perspectiveName));
}
}
};
}
private void fillViewsMenu(IMenuManager menuBar) {
MenuManager viewsMenu = new MenuManager(Messages.getString("Menu.Views"));
menuBar.add(viewsMenu);
viewsMenu.add(showDiskViewAction);
viewsMenu.add(showLibraryViewAction);
viewsMenu.add(showPlaylistsViewAction);
viewsMenu.add(showDefaultPlaylistViewAction);
if (ApplicationUtils.doesEngineSupportPodcasts()) {
viewsMenu.add(showPodcastViewAction);
}
if (ApplicationUtils.doesEngineSupportRadio()) {
viewsMenu.add(showRadioViewAction);
}
viewsMenu.add(new Separator());
viewsMenu.add(showPropertyViewAction);
if (ApplicationUtils.doesEngineSupportEqualizer()) {
viewsMenu.add(showEqualizerViewAction);
}
viewsMenu.add(showStatisticsViewAction);
if (!Controller.getInstance().getPreferenceStore().getBoolean(PreferenceConstants.PLAYERVIEW_SHOW_IN_TOOLBAR)) {
viewsMenu.add(showControlsViewAction);
}
viewsMenu.add(new Separator());
MenuManager perspectiveMenu = new MenuManager(Messages.getString("Menu.Views.Perspectives"));
perspectiveMenu.addMenuListener(new IMenuListener() {
@Override
public void menuAboutToShow(IMenuManager manager) {
manager.removeAll();
manager.add(savePerspectiveAction);
manager.add(removePerspectiveAction);
manager.add(new Separator());
IAction perspectiveAction;
final IPerspectiveDescriptor[] perspectiveArray = PlatformUI.getWorkbench().getPerspectiveRegistry().getPerspectives();
for (int i = 0; i < perspectiveArray.length; i++) {
final IPerspectiveDescriptor perspectiveDesc = perspectiveArray[i];
perspectiveAction = new Action(perspectiveDesc.getLabel()) {
public void run() {
try {
PlatformUI.getWorkbench().showPerspective(perspectiveDesc.getId(), _window);
} catch (WorkbenchException e) {
Log.getInstance(MenuController.class).warn("Error while load perspective: " + e.getMessage());
}
}
};
if (perspectiveAction.getText().equals(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getPerspective().getLabel())) {
perspectiveAction.setChecked(true);
}
manager.add(perspectiveAction);
}
}
});
viewsMenu.add(perspectiveMenu);
perspectiveMenu.add(savePerspectiveAction);
perspectiveMenu.add(removePerspectiveAction);
perspectiveMenu.add(new Separator());
viewsMenu.add(new Separator());
viewsMenu.add(showPreferencesWindowAction);
}
/**
* Tools menu.
*/
private void buildToolsAction(final IWorkbenchWindow window, final IHandlerService handlerService) {
showSearchViewAction = new Action(Messages.getString("Menu.Views.ShowSearchView"), SWT.NONE) {
public void run() {
ApplicationUtils.showViewByID(SearchView.ID);
}
};
showSearchViewAction.setImageDescriptor(Activator.getImageDescriptor("/icons/search_16.png"));
showSearchViewAction.setActionDefinitionId("Jampa.showSearchView");
handlerService.activateHandler("Jampa.showSearchView", new ActionHandler(showSearchViewAction));
manageExternalDevices = new Action(Messages.getString("Menu.Actions.ManageExternalDevices"), SWT.NONE) {
public void run() {
RemovableStorageDialog dialog = new RemovableStorageDialog(Display.getCurrent().getActiveShell());
dialog.open();
}
};
manageExternalDevices.setImageDescriptor(Activator.getImageDescriptor("/icons/folder_removable_16.png"));
manageExternalDevices.setActionDefinitionId("Jampa.menuManageRemovableStorage");
handlerService.activateHandler("Jampa.menuManageRemovableStorage", new ActionHandler(manageExternalDevices));
updateLibrary = new Action(Messages.getString("Menu.Actions.UpdateLibrary"), SWT.NONE) {
public void run() {
Controller.getInstance().doUpdateLibrary();
}
};
updateLibrary.setImageDescriptor(Activator.getImageDescriptor("/icons/scanplaylist_16.png"));
updateLibrary.setActionDefinitionId("Jampa.updateLibrary");
handlerService.activateHandler("Jampa.updateLibrary", new ActionHandler(updateLibrary));
scanLibrary = new Action(Messages.getString("Menu.Actions.ScanLibrary"), SWT.NONE) {
public void run() {
Controller.getInstance().doScanLibrary();
}
};
scanLibrary.setActionDefinitionId("Jampa.scanLibrary");
handlerService.activateHandler("Jampa.scanLibrary", new ActionHandler(scanLibrary));
}
private void fillToolsMenu(IMenuManager menuBar) {
MenuManager toolsMenu = new MenuManager(Messages.getString("Menu.Tools"));
toolsMenu.add(showSearchViewAction);
toolsMenu.add(new Separator());
toolsMenu.add(manageExternalDevices);
toolsMenu.add(new Separator());
toolsMenu.add(updateLibrary);
toolsMenu.add(scanLibrary);
menuBar.add(toolsMenu);
}
/**
* Actions menu
*/
private void buildActionsAction(final IWorkbenchWindow window, IHandlerService handlerService) {
volumeDownAction = new Action(Messages.getString("Menu.Actions.VolumeDown"), SWT.NONE) {
public void run() {
new SetVolumeAction(Controller.getInstance().getPreferenceStore().getInt(PreferenceConstants.PLAYBACK_VOLUME) - 10).run();
}
};
volumeDownAction.setImageDescriptor(Activator.getImageDescriptor("/icons/volumedown_16.png"));
volumeDownAction.setActionDefinitionId("Jampa.menuVolumeDown");
handlerService.activateHandler("Jampa.menuVolumeDown", new ActionHandler(volumeDownAction));
volumeUpAction = new Action(Messages.getString("Menu.Actions.VolumeUp"), SWT.NONE) {
public void run() {
new SetVolumeAction(Controller.getInstance().getPreferenceStore().getInt(PreferenceConstants.PLAYBACK_VOLUME) + 10).run();
}
};
volumeUpAction.setImageDescriptor(Activator.getImageDescriptor("/icons/volumeup_16.png"));
volumeUpAction.setActionDefinitionId("Jampa.menuVolumeUp");
handlerService.activateHandler("Jampa.menuVolumeUp", new ActionHandler(volumeUpAction));
volumeMuteAction = new Action(Messages.getString("Menu.Actions.VolumeMute"), SWT.NONE) {
public void run() {
new VolumeMuteAction().run();
}
};
volumeMuteAction.setImageDescriptor(Activator.getImageDescriptor("/icons/volumemute_16.png"));
volumeMuteAction.setActionDefinitionId("Jampa.menuVolumeMute");
handlerService.activateHandler("Jampa.menuVolumeMute", new ActionHandler(volumeMuteAction));
volumeMuteAction.setEnabled(false);
volume100Action = new Action(Messages.getString("Menu.Actions.Volume100"), SWT.NONE) {
public void run() {
new SetVolumeAction(100).run();
}
};
volume100Action.setActionDefinitionId("Jampa.menuVolume100");
handlerService.activateHandler("Jampa.menuVolume100", new ActionHandler(volume100Action));
volume75Action = new Action(Messages.getString("Menu.Actions.Volume75"), SWT.NONE) {
public void run() {
new SetVolumeAction(75).run();
}
};
volume75Action.setActionDefinitionId("Jampa.menuVolume75");
handlerService.activateHandler("Jampa.menuVolume75", new ActionHandler(volume75Action));
volume50Action = new Action(Messages.getString("Menu.Actions.Volume50"), SWT.NONE) {
public void run() {
new SetVolumeAction(50).run();
}
};
volume50Action.setActionDefinitionId("Jampa.menuVolume50");
handlerService.activateHandler("Jampa.menuVolume50", new ActionHandler(volume50Action));
volume25Action = new Action(Messages.getString("Menu.Actions.Volume25"), SWT.NONE) {
public void run() {
new SetVolumeAction(25).run();
}
};
volume25Action.setActionDefinitionId("Jampa.menuVolume25");
handlerService.activateHandler("Jampa.menuVolume25", new ActionHandler(volume25Action));
previousAction = new Action(Messages.getString("Menu.Actions.Previous"), SWT.NONE) {
public void run() {
new PlayPreviousAction().run();
}
};
previousAction.setImageDescriptor(Activator.getImageDescriptor("/icons/previous_16.png"));
previousAction.setActionDefinitionId("Jampa.menuPrevious");
handlerService.activateHandler("Jampa.menuPrevious", new ActionHandler(previousAction));
previousAction.setEnabled(false);
stopAction = new Action(Messages.getString("Menu.Actions.Stop"), SWT.NONE) {
public void run() {
new StopAction().run();
}
};
stopAction.setImageDescriptor(Activator.getImageDescriptor("/icons/stop_16.png"));
stopAction.setActionDefinitionId("Jampa.menuStop");
handlerService.activateHandler("Jampa.menuStop", new ActionHandler(stopAction));
stopAction.setEnabled(false);
pauseAction = new Action(Messages.getString("Menu.Actions.Pause"), SWT.NONE) {
public void run() {
new PauseAction().run();
}
};
pauseAction.setImageDescriptor(Activator.getImageDescriptor("/icons/pause_16.png"));
pauseAction.setActionDefinitionId("Jampa.menuPause");
handlerService.activateHandler("Jampa.menuPause", new ActionHandler(pauseAction));
pauseAction.setEnabled(false);
nextAction = new Action(Messages.getString("Menu.Actions.Next"), SWT.NONE) {
public void run() {
new PlayNextAction().run();
}
};
nextAction.setImageDescriptor(Activator.getImageDescriptor("/icons/next_16.png"));
nextAction.setActionDefinitionId("Jampa.menuNext");
handlerService.activateHandler("Jampa.menuNext", new ActionHandler(nextAction));
nextAction.setEnabled(false);
}
private void fillActionsMenu(IMenuManager menuBar) {
MenuManager actionsMenu = new MenuManager(Messages.getString("Menu.Actions"));
MenuManager predefinedVolume = new MenuManager(Messages.getString("Menu.Actions.PredefinedVolumes"));
actionsMenu.add(volumeDownAction);
actionsMenu.add(volumeUpAction);
actionsMenu.add(volumeMuteAction);
actionsMenu.add(predefinedVolume);
predefinedVolume.add(volume100Action);
predefinedVolume.add(volume75Action);
predefinedVolume.add(volume50Action);
predefinedVolume.add(volume25Action);
actionsMenu.add(new Separator());
actionsMenu.add(previousAction);
actionsMenu.add(stopAction);
actionsMenu.add(pauseAction);
actionsMenu.add(nextAction);
menuBar.add(actionsMenu);
}
private void buildPlaylistsActions(final IWorkbenchWindow window, IHandlerService handlerService) {
newPlaylistAction = new Action(Messages.getString("Menu.Playlists.NewPlaylist"), SWT.NONE) {
public void run() {
new NewPlaylistAction(Display.getCurrent().getActiveShell()).run();
}
};
newPlaylistAction.setImageDescriptor(Activator.getImageDescriptor("/icons/newplaylist_16.png"));
newPlaylistAction.setActionDefinitionId("Jampa.newPlaylist");
handlerService.activateHandler("Jampa.newPlaylist", new ActionHandler(newPlaylistAction));
playlistGeneratorAction = new Action(Messages.getString("Menu.Playlists.PlaylistGenerator"), SWT.NONE) {
public void run() {
System.out.println("test2");
PlaylistGeneratorWizard wizard = new PlaylistGeneratorWizard();
WizardDialog wizardDialog = new WizardDialog(Display.getCurrent().getActiveShell(), wizard);
wizardDialog.setPageSize(500, 200);
if (wizardDialog.open() == Dialog.OK) {
Controller.getInstance().getPlaylistController().addEmptyPlaylist(wizard.getPlaylistName());
Controller.getInstance().getPlaylistController().addItemToPlaylist(wizard.getPlaylistName(), wizard.getGenerator().getResults(), wizard.getPlay());
new OpenPlaylistAction(wizard.getPlaylistName()).run();
}
}
};
playlistGeneratorAction.setActionDefinitionId("Jampa.playlistGeneratorWizard");
handlerService.activateHandler("Jampa.playlistGeneratorWizard", new ActionHandler(playlistGeneratorAction));
importPlaylistAction = new Action(Messages.getString("Menu.Playlists.ImportPlaylist"), SWT.NONE) {
public void run() {
PlaylistImportWizard wizard = new PlaylistImportWizard();
WizardDialog wizardDialog = new WizardDialog(Display.getCurrent().getActiveShell(), wizard);
wizardDialog.setPageSize(500, 100);
if (wizardDialog.open() == Dialog.OK) {
Log.getInstance(MenuController.class).debug("Importing file " + wizard.getFileName() + " to playlist: " + wizard.getPlaylistName()); //$NON-NLS-1$ //$NON-NLS-2$
Controller.getInstance().getPlaylistController().importPlaylist(wizard.getPlaylistName(), wizard.getFileName());
}
}
};
importPlaylistAction.setActionDefinitionId("Jampa.playlistImportWizard");
handlerService.activateHandler("Jampa.playlistImportWizard", new ActionHandler(importPlaylistAction));
exportPlaylistAction = new Action(Messages.getString("Menu.Playlists.ExportPlaylist"), SWT.NONE) {
public void run() {
PlaylistExportWizard wizard = new PlaylistExportWizard();
WizardDialog wizardDialog = new WizardDialog(Display.getCurrent().getActiveShell(), wizard);
wizardDialog.setPageSize(500, 225);
wizardDialog.open();
}
};
exportPlaylistAction.setActionDefinitionId("Jampa.playlistExportWizard");
handlerService.activateHandler("Jampa.playlistExportWizard", new ActionHandler(exportPlaylistAction));
checkPlaylistsAction = new Action(Messages.getString("Menu.Playlists.CheckPlaylist"), SWT.NONE) {
public void run() {
CheckPlaylistsDialog dialog = new CheckPlaylistsDialog(Display.getCurrent().getActiveShell());
dialog.open();
}
};
checkPlaylistsAction.setImageDescriptor(Activator.getImageDescriptor("/icons/checkplaylists_16.png"));
checkPlaylistsAction.setActionDefinitionId("Jampa.checkPlaylists");
handlerService.activateHandler("Jampa.checkPlaylists", new ActionHandler(checkPlaylistsAction));
exitAction = new Action(Messages.getString("Menu.Playlists.Exit"), SWT.NONE) {
public void run() {
window.close();
}
};
exitAction.setActionDefinitionId("Jampa.exit");
handlerService.activateHandler("Jampa.exit", new ActionHandler(exitAction));
}
private void fillPlaylistsMenu(IMenuManager menuBar) {
MenuManager playlistMenu = new MenuManager(Messages.getString("Menu.Playlists"));
menuBar.add(playlistMenu);
playlistMenu.add(newPlaylistAction);
playlistMenu.add(playlistGeneratorAction);
playlistMenu.add(new Separator());
playlistMenu.add(importPlaylistAction);
playlistMenu.add(exportPlaylistAction);
playlistMenu.add(new Separator());
playlistMenu.add(checkPlaylistsAction);
playlistMenu.add(new Separator());
playlistMenu.add(exitAction);
}
public void buildActions(final IWorkbenchWindow window) {
IHandlerService handlerService = (IHandlerService) window.getService(IHandlerService.class);
buildPlaylistsActions(window, handlerService);
buildActionsAction(window, handlerService);
buildViewsAction(window, handlerService);
buildToolsAction(window, handlerService);
buildHelpAction(window, handlerService);
}
public void fillMenuBar(IMenuManager menuBar) {
fillPlaylistsMenu(menuBar);
fillActionsMenu(menuBar);
fillViewsMenu(menuBar);
fillToolsMenu(menuBar);
fillHelpMenu(menuBar);
}
private String getPerspectiveId(final IWorkbenchWindow window, String title, String message) {
ElementListSelectionDialog dialog = new ElementListSelectionDialog(window.getShell(), new LabelProvider());
dialog.setTitle(title);
dialog.setMessage(message); //$NON-NLS-1$
dialog.setMultipleSelection(false);
List<String> perspectiveList = new ArrayList<String>();
IPerspectiveDescriptor[] perspectiveArray = PlatformUI.getWorkbench().getPerspectiveRegistry().getPerspectives();
for (int i = 0; i < perspectiveArray.length; i++) {
perspectiveList.add(perspectiveArray[i].getLabel());
}
dialog.setElements(perspectiveList.toArray());
int result = dialog.open();
if (result == Dialog.OK) {
return (String) dialog.getFirstResult();
} else {
return null;
}
}
private void enableControlActions(boolean newState) {
volumeMuteAction.setEnabled(newState);
stopAction.setEnabled(newState);
pauseAction.setEnabled(newState);
previousAction.setEnabled(newState);
nextAction.setEnabled(newState);
}
private void onVolumeChange() {
//volumeMuteAction.setChecked(Controller.getInstance().getEngine().isMuted());
}
private void onPlayNewItem(IAudioItem item) {
enableControlActions(true);
}
private void onStopPlayback() {
enableControlActions(false);
}
@Override
public void propertyChange(PropertyChangeEvent arg0) {
if (arg0.getPropertyName().equals(EventConstants.EVT_PLAY_NEW_AUDIO_ITEM)) {
class onPlayNewItem implements Runnable {
IAudioItem _newItem;
public onPlayNewItem(IAudioItem newItem) {
_newItem = newItem;
}
public void run() {
onPlayNewItem(_newItem);
}
}
Display.getDefault().asyncExec(new onPlayNewItem((IAudioItem) arg0.getNewValue()));
}
if (arg0.getPropertyName().equals(EventConstants.EVT_STOP_PLAYBACK)) {
class onStopPlayback implements Runnable {
public void run() {
onStopPlayback();
}
}
Display.getDefault().asyncExec(new onStopPlayback());
}
if (arg0.getPropertyName().equals(EventConstants.EVT_VOLUME_CHANGE)) {
class onVolumeChange implements Runnable {
public void run() {
onVolumeChange();
}
}
Display.getDefault().asyncExec(new onVolumeChange());
}
}
public void dispose() {
Controller.getInstance().getEventController().removeAudioItemChangeListener(this);
}
}