/* ********************************************************************** **
** 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.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.OwnerDrawLabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.rssowl.contrib.i18n.Messages;
/**
* @author <a href="mailto:christophe@kualasoft.com">Christophe Bouhier </a>
* @version 1.1
*/
public class DownloadTableViewer implements IStructuredContentProvider {
protected static String[] COLUMN_TOOLTIPS;
protected static String[] COLUMN_NAMES;
// private static String[] STATUS_NAMES;
// private static int MIN_ROWS = 50;
private Table mTable;
protected TableViewer mTableViewer;
private static int[] mColumnWidths;
int[] mColumnAlignments = { SWT.NONE, SWT.LEFT, SWT.LEFT, SWT.LEFT,
SWT.CENTER, SWT.LEFT, SWT.CENTER, SWT.CENTER };
public TableViewer getTableViewer(){
return mTableViewer;
}
public DownloadTableViewer(Composite pParent) {
mColumnWidths = new int[] { 40, 100, 120, 300, 60, 60, 100, 100};
COLUMN_TOOLTIPS = new String[] {
}; // TODO, Add Tooltips.
COLUMN_NAMES = new String[] { Messages.getString("downloadtable.item"),
Messages.getString("downloadtable.filename"),
Messages.getString("downloadtable.feed"),
Messages.getString("downloadtable.progress"),
Messages.getString("downloadtable.speed"),
Messages.getString("downloadtable.time"),
Messages.getString("downloadtable.status"),
Messages.getString("downloadtable.downloaded") };
// STATUS_NAMES = new String[] {
// Messages.getString("downloadtable.status.connecting"),
// Messages.getString("downloadtable.status.downloading"),
// Messages.getString("downloadtable.status.retrying"),
// Messages.getString("downloadtable.status.error"),
// Messages.getString("downloadtable.status.cancelled"),
// Messages.getString("downloadtable.status.completed"),
// Messages.getString("downloadtable.status.queued"),
// "", // IDLE status
// Messages.getString("downloadtable.status.pauzed"),
// Messages.getString("downloadtable.status.release") };
mTable = new Table(pParent, SWT.BORDER | SWT.FULL_SELECTION
| SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI);
mTable.setHeaderVisible(true);
GridData lData = new GridData(GridData.FILL_BOTH);
mTable.setLayoutData(lData);
buildColumns();
mTableViewer = new TableViewer(mTable);
mTableViewer.setUseHashlookup(true);
mTableViewer.setContentProvider(this);
mTableViewer.setLabelProvider(new DownloadLabelProvider(this));
mTableViewer.setColumnProperties(COLUMN_NAMES);
OwnerDrawLabelProvider.setUpOwnerDraw(mTableViewer);
}
/**
* Generate the table columns. The column text is aligened in the center.
*/
public void buildColumns() {
for (int i = 0; i < COLUMN_NAMES.length; i++) {
TableColumn lColumn = new TableColumn(mTable, mColumnAlignments[i]);
lColumn.setText(COLUMN_NAMES[i]);
lColumn.setWidth(mColumnWidths[i]);
}
}
/**
* Call when calling setInput();
*
*/
public Object[] getElements(Object inputElement) {
return (Object[]) inputElement;
// if(inputElement instanceof List){
// mDownloadList = (List<IDownload>)inputElement;
// List<IDownload> list = ((List<IDownload>)inputElement);
// return list.toArray();
// }
// return null;
}
public void dispose() {
}
public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
// Could be used to register a listener on the model.
}
}