/* ********************************************************************** **
** Copyright notice **
** **
** (c) 2005-2006 RSSOwl Development Team **
** http://www.rssowl.org/ **
** **
** All rights reserved **
** **
** This program and the accompanying materials are made available under **
** the terms of the Eclipse Public License v1.0 which accompanies this **
** distribution, and is available at: **
** http://www.rssowl.org/legal/epl-v10.html **
** **
** A copy is found in the file epl-v10.html and important notices to the **
** license from the team is found in the textfile LICENSE.txt distributed **
** in this package. **
** **
** This copyright notice MUST APPEAR in all copies of the file! **
** **
** Contributors: **
** Christophe Bouhier - podcast plugin **
** **
** ********************************************************************** */
package org.rssowl.contrib.podcast.ui.media;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.ISelectionListener;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.part.ViewPart;
import org.rssowl.contrib.podcast.core.process.InstructionService;
import org.rssowl.contrib.podcast.model.IPersonalBookMark;
import org.rssowl.contrib.podcast.model.PersonalCache;
import org.rssowl.contrib.podcast.ui.media.action.MediaOpenAction;
import org.rssowl.contrib.podcast.ui.media.action.SyncPlayAction;
import org.rssowl.core.persist.IBookMark;
/**
* A Media View with several views, showing podcast items in a tree or table
* format.
*/
public class MediaViewPart extends ViewPart {
private MediaController mMediaController;
private MediaView mMediaView;
private ISelectionListener listener;
/*
* The content provider class is responsible for providing objects to the
* view. It can wrap existing objects in adapters or simply return objects
* as-is. These objects may be sensitive to the current input of the view,
* or ignore it and always show the same content (like Task List, for
* example).
*/
/**
* The constructor.
*/
public MediaViewPart() {
listener = new ISelectionListener() {
public void selectionChanged(IWorkbenchPart part, ISelection sel) {
if (!(sel instanceof IStructuredSelection))
return;
IStructuredSelection ss = (IStructuredSelection) sel;
Object o = ss.getFirstElement();
// ********************* CB TODO
// We force an inspection on the bookmark first.
if (o instanceof IBookMark) {
IBookMark lBookMark = (IBookMark) o;
IPersonalBookMark lPBookMark = PersonalCache.getInstance()
.getPersonalBookMark(lBookMark);
mMediaController.setMediaView(lPBookMark);
// Invoke a codelet sequence for inspection.
InstructionService.getInstance().inspectInstruction(this, lPBookMark);
}
}
};
}
/**
* This is a callback that will allow us to create the viewer and initialize
* it.
*/
public void createPartControl(Composite parent) {
getSite().getPage().addSelectionListener(listener);
mMediaView = new MediaView(parent);
mMediaController = new MediaController();
mMediaController.setView(mMediaView);
hookContextMenu();
// hookDoubleClickAction();
// contributeToActionBars();
}
private void hookContextMenu() {
final MenuManager menuMgr = new MenuManager("#PopupMenu");
menuMgr.setRemoveAllWhenShown(true);
Control lControl = null;
ISelectionProvider lProvider = null;
if (mMediaView.getCurrentView() == MediaView.MEDIA_VIEW) {
lControl = mMediaView.getMediaViewer().mTableViewer.getControl();
lProvider = mMediaView.getMediaViewer().mTableViewer;
} else {
lControl = mMediaView.getItemViewer().mTreeViewer.getControl();
lProvider = mMediaView.getItemViewer().mTreeViewer;
}
final IStructuredSelection selection = (IStructuredSelection) lProvider
.getSelection();
if (selection.isEmpty()) {
// CB TODO decide what to do on an empty selection.
}
menuMgr.addMenuListener(new IMenuListener() {
public void menuAboutToShow(IMenuManager manager) {
manager.add(new Separator("control"));
menuMgr
.appendToGroup("control",
new MediaOpenAction(selection));
menuMgr.appendToGroup("control", new SyncPlayAction(selection));
MediaViewPart.this.fillContextMenu(manager);
}
});
if (lControl != null && lProvider != null) {
Menu menu = menuMgr.createContextMenu(lControl);
lControl.setMenu(menu);
// Register to the workbench.
getSite().registerContextMenu(menuMgr, lProvider);
}
}
private void contributeToActionBars() {
IActionBars bars = getViewSite().getActionBars();
fillLocalPullDown(bars.getMenuManager());
fillLocalToolBar(bars.getToolBarManager());
}
private void fillLocalPullDown(IMenuManager manager) {
// manager.add(action1);
// manager.add(new Separator());
// manager.add(action2);
}
private void fillContextMenu(IMenuManager manager) {
// Workbench marker for extensions.
manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
manager.add(new Separator("control"));
// CB only add to menu based on selection, somethign with a selection
// IStructuredSelection selection = (IStructuredSelection) fViewer
// .getSelection();
// if (selection.isEmpty()) {
// return;
// }
}
private void fillLocalToolBar(IToolBarManager manager) {
// manager.add(action1);
// manager.add(action2);
}
private void hookDoubleClickAction() {
// viewer.addDoubleClickListener(new IDoubleClickListener() {
// public void doubleClick(DoubleClickEvent event) {
// doubleClickAction.run();
// }
// });
}
private void showMessage(String message) {
// MessageDialog.openInformation(
// viewer.getControl().getShell(),
// "Sample View",
// message);
}
/**
* Passing the focus request to the viewer's control.
*/
public void setFocus() {
// viewer.getControl().setFocus();
}
/**
*
*/
public void dispose() {
// We shall start or stop services related to this view.
}
}