Package org.rssowl.contrib.podcast.ui.download

Source Code of org.rssowl.contrib.podcast.ui.download.DownloadViewPart

/*   **********************************************************************  **
**   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.download;

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.IStructuredSelection;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.part.ViewPart;
import org.rssowl.contrib.podcast.ui.download.actions.CleanAction;
import org.rssowl.contrib.podcast.ui.download.actions.PauzeAction;

public class DownloadViewPart extends ViewPart {

  private DownloadController mDownloadController;
  private DownloadTableViewer mDownloadViewer;

  /*
   * 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 DownloadViewPart() {
  }

  /**
   * This is a callback that will allow us to create the viewer and initialize
   * it.
   */
  public void createPartControl(Composite parent) {

    mDownloadViewer = new DownloadTableViewer(parent);
    this.mDownloadController = new DownloadController();
    mDownloadController.setView(mDownloadViewer);

    hookContextMenu();
    // hookDoubleClickAction();
    // contributeToActionBars();
  }

  private void hookContextMenu() {
    final MenuManager menuMgr = new MenuManager("#PopupMenu");
    menuMgr.setRemoveAllWhenShown(true);
   
    final IStructuredSelection selection = (IStructuredSelection) mDownloadViewer.getTableViewer().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 PauzeAction(selection));
            menuMgr.appendToGroup("control", new CleanAction(selection));
        DownloadViewPart.this.fillContextMenu(manager);
      }
    });
   
   
    Menu menu = menuMgr.createContextMenu(mDownloadViewer.mTableViewer.getControl());
    mDownloadViewer.mTableViewer.getControl().setMenu(menu);
    // Register to the workbench.
    getSite().registerContextMenu(menuMgr, mDownloadViewer.mTableViewer);
  }

  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.

  }
}
TOP

Related Classes of org.rssowl.contrib.podcast.ui.download.DownloadViewPart

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.