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

Source Code of org.rssowl.contrib.podcast.ui.media.MediaView

/*   **********************************************************************  **
**   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.viewers.StructuredSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.rssowl.contrib.podcast.model.IPersonalAttachment;
import org.rssowl.contrib.podcast.model.IPersonalBookMark;
import org.rssowl.contrib.podcast.model.IXFile;
import org.rssowl.contrib.podcast.util.Logger;

/**
* This class sets up the File View and interacts with the main application
*
* @author <a href="mailto:christophe@kualasoft.com">Christophe Bouhier</a>
* @author <a href="mailto:andreas.schaefer@madplanet.com">Andreas Schaefer </a>
* @version 1.1
*/

public class MediaView {

  private Logger mLog = new Logger(getClass().getName());

  /**
   * The Item and Media viewer is now created, but should be dynamic in the
   * future. Some listeners are set in the controller. Need to rethink on how
   * the selection listeners can access the controller actions when viewer is
   * loaded dynamicly.
   */
  protected MediaTreeView mItemViewer;

  protected MediaTableView mMediaViewer;

  /**
   * The selection can be an XItem or an XPersonalEnclosure depending on the
   * selected row.
   */
  protected Object mSelection;

  /**
   * The selection can be an XItem or an XPersonalEnclosure depending on the
   * selected row.
   */
  protected Object[] mSelectionArray;

  public static final int ITEM_VIEW = 401;

  public static final int MEDIA_VIEW = 402;

  protected int mCurrentView;

  protected Composite mParent;

  protected Composite mComposite;

  protected ModelPreparator mPreparator;

  public int getCurrentView() {
    return mCurrentView;
  }

  public Composite getView() {
    return mComposite;
  }

  public ModelPreparator getModelPreparator() {
    return mPreparator;
  }

  /**
   * Constructor. Defines the actions in this controller.
   */
  public MediaView(Composite pParent) {
    mLog.info("<init>");
    mParent = pParent;
  }

  public void setViewer(int pView) {
    if (mCurrentView == pView) {
      return;
    }

    if (mComposite != null) {
      mComposite.dispose();
    }
    mComposite = new Composite(mParent, SWT.NONE);
    GridLayout lGridLayout = new GridLayout();
    lGridLayout.marginLeft = 0;
    lGridLayout.marginRight = 0;
    lGridLayout.marginHeight = 0;
    lGridLayout.marginWidth = 0;
    mComposite.setLayout(lGridLayout);

    if (pView == ITEM_VIEW) {

      mItemViewer = createItemViewer(mComposite);
      mLog.info("setViewer() Changed view to Item view ");
    }
    if (pView == MEDIA_VIEW) {
      mMediaViewer = createMediaViewer(mComposite);
      mLog.info("setViewer() Changed view to Media view ");
    }
    mCurrentView = pView;
    mParent.layout();
  }

  public MediaTreeView getItemViewer() {
    return mItemViewer;
  }

  public MediaTableView getMediaViewer() {
    return mMediaViewer;
  }

  public MediaTreeView createItemViewer(Composite pParent) {

    SashForm lItemSash = new SashForm(pParent, SWT.VERTICAL);
    GridData lData = new GridData(GridData.FILL_BOTH);
    lItemSash.setLayoutData(lData);

    mItemViewer = new MediaTreeView(lItemSash);

// CB TODO move
// mItemInfoView = new MediaItemView(lItemSash);

// mItemViewer.mTree.addListener(SWT.Selection, new Listener() {
// public void handleEvent(Event arg0) {
// if (mSelection != null) {
// if (mSelection instanceof IXItem) {
// mItemInfoView.formatItem((IXItem) mSelection,
// HTMLLogic.STYLE_SHEET);
// }
// }
// }
// });

    return mItemViewer;
  }

  public MediaTableView createMediaViewer(Composite pParent) {
    MediaTableView lMediaViewer = new MediaTableView(pParent);
    return lMediaViewer;
  }

  /**
   * Asynchronously update the object in the current active view.
   *
   * @param pFile
   */
  // CB TODO Doesn't work on delete (of what?)!
  public void update(final IXFile pFile) {
    Display.getDefault().asyncExec(new Runnable() {
      public void run() {

        switch (mCurrentView) {
        case ITEM_VIEW: {
          if (mItemViewer.mTreeViewer.getTree().isDisposed()) {
            return;
          }
          mItemViewer.mTreeViewer.refresh(pFile);
        }
          break;
        case MEDIA_VIEW: {
          if (mMediaViewer.mTableViewer.getTable().isDisposed()) {
            return;
          }
          mMediaViewer.mTableViewer.refresh(pFile);
// mMediaViewer.mTableViewer.update(pFile, null);
        }
          break;
        }
      }
    });
  }

  public void updateDownload(final IXFile pFile) {

    Display.getDefault().asyncExec(new Runnable() {
      public void run() {

        switch (mCurrentView) {
        case ITEM_VIEW: {
          if (mItemViewer.mTreeViewer.getTree().isDisposed()) {
            return;
          }
          mItemViewer.mTreeViewer.update(pFile, null);
        }
          break;
        case MEDIA_VIEW: {
          if (mMediaViewer.mTableViewer.getTable().isDisposed()) {
            return;
          }
          if (pFile instanceof IPersonalAttachment) {
            // Only update the column representing the
            // file/enclosure size.
            String[] lProperties = new String[] { mMediaViewer.mColumnNames[3] };
            mMediaViewer.mTableViewer.update(
                (IPersonalAttachment) pFile, lProperties);
          } else {
            mMediaViewer.mTableViewer.update(pFile, null);
          }

        }
          break;
        }
      }
    });
  }

  /**
   * Asynchronously update the current active view.
   */
  public void update() {
    Display.getDefault().asyncExec(new Runnable() {
      public void run() {
        switch (mCurrentView) {
        case ITEM_VIEW: {
          if (mItemViewer.mTreeViewer.getTree().isDisposed()) {
            return;
          }
          mItemViewer.mTreeViewer.refresh();
        }
          break;
        case MEDIA_VIEW: {
          if (mMediaViewer.mTableViewer.getTable().isDisposed()) {
            return;
          }
          mMediaViewer.mTableViewer.refresh();
        }
          break;
        }
      }
    });
  }

  public void setInput(IPersonalBookMark pPBookMark) {

    if (mPreparator != null) {
      mPreparator.dispose();
    }
    mPreparator = new ModelPreparator(this, pPBookMark);
    switch (mCurrentView) {
    case ITEM_VIEW: {
      mItemViewer.mTreeViewer.setInput(mPreparator);
    }
      break;
    case MEDIA_VIEW: {
      MediaTableProvider lLabelProvider = new MediaTableProvider(
          mPreparator);
      mMediaViewer.mTableViewer.setLabelProvider(lLabelProvider);
      mMediaViewer.mTableViewer.setInput(mPreparator);
    }
      break;
    }
  }

  public void clean() {
    if (mPreparator != null) {
      mPreparator.dispose();
    }
    switch (mCurrentView) {
    case ITEM_VIEW: {
      mItemViewer.mTreeViewer.setInput(null);
    }
      break;
    case MEDIA_VIEW: {
      mMediaViewer.mTableViewer.setInput(null);
    }
      break;
    }
  }

  public void setSelected(IXFile pFile) {
    StructuredSelection lSelection = new StructuredSelection(pFile);
    switch (mCurrentView) {
    case ITEM_VIEW: {
      mItemViewer.mTreeViewer.setSelection(lSelection);
    }
      break;
    case MEDIA_VIEW: {
      mMediaViewer.mTableViewer.setSelection(lSelection);
    }
      break;
    }
  }
}
TOP

Related Classes of org.rssowl.contrib.podcast.ui.media.MediaView

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.