Package org.rssowl.contrib.podcast.ui.media.action

Source Code of org.rssowl.contrib.podcast.ui.media.action.MediaOpenAction

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

import java.util.Iterator;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
import org.rssowl.contrib.i18n.Messages;
import org.rssowl.contrib.podcast.content.ContentAssociation;
import org.rssowl.contrib.podcast.model.IXFile;
import org.rssowl.contrib.podcast.ui.IControllerAction;
import org.rssowl.contrib.podcast.ui.media.MediaController;
import org.rssowl.contrib.podcast.util.Util;

public class MediaOpenAction extends Action implements
    IControllerAction<MediaController>, IWorkbenchWindowActionDelegate {

  @SuppressWarnings("unused")
  private Shell fShell;
  private MediaController mController;
  @SuppressWarnings("unused")
  private IStructuredSelection mSelection;

  public MediaOpenAction(IStructuredSelection pSelection) {
    mSelection = pSelection;
  }

  public void dispose() {
  }

  public void init(IWorkbenchWindow window) {
    fShell = window.getShell();
  }

  public void run(IAction action) {
    run();
  }

  /**
   * parse the selection, check for the correct file type and open the
   * selection in the associated OS application.
   */
  public void run() {
    if (mSelection != null) {
      Iterator<?> lIter = mSelection.iterator();
      while (lIter.hasNext()) {
        Object lObject = lIter.next();
        if (conditionMet(lObject)) {
          IXFile lFile = (IXFile) lObject;
          if (lFile != null) {
            String lPath = lFile.getFile().getPath();
            String lExtension = Util.stripName(lFile.getFile()
                .getName());
            ContentAssociation.openProgram(lExtension, lPath);
          }
        }
      }
    }
  }

  public void selectionChanged(IAction action, ISelection selection) {
    if (selection instanceof IStructuredSelection) {
      mSelection = (IStructuredSelection) selection;
    }
  }

  public MediaController getController() {
    return mController;
  }

  public void setController(MediaController controller) {
    mController = controller;
  }

  @Override
  public String getText() {
    return Messages.getString(Messages.getString("general.open"));
  }

  public boolean conditionMet(Object pConditionObject) {
    if (pConditionObject instanceof IXFile) {
      IXFile lFile = (IXFile) pConditionObject;
      if (lFile.isLocal()) {
        return true;
      }
    }
    return false;
  }
}
TOP

Related Classes of org.rssowl.contrib.podcast.ui.media.action.MediaOpenAction

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.