FileDocCategorySizeDatePackage
TableRowImpl.javaAPI DocAzureus 3.0.3.412874Sat Aug 04 15:48:10 BST 2007org.gudy.azureus2.ui.swt.views.table.impl

TableRowImpl

public class TableRowImpl extends org.gudy.azureus2.ui.swt.components.BufferedTableRow implements org.gudy.azureus2.ui.swt.views.table.TableRowSWT
Represents an entire row in a table. Stores each cell belonging to the row and handles refreshing them.
see
TableCellImpl
author
TuxPaper 2005/Oct/07: Moved TableItem.SetData("TableRow", ..) to BufferedTableRow 2005/Oct/07: Removed all calls to BufferedTableRoe.getItem()

Fields Summary
private Map
mTableCells
List of cells in this column. They are not stored in display order
private String
sTableID
private Object
coreDataSource
private Object
pluginDataSource
private boolean
bDisposed
private boolean
bSetNotUpToDateLastRefresh
private com.aelitis.azureus.ui.common.table.TableView
tableView
private static org.gudy.azureus2.core3.util.AEMonitor
this_mon
private ArrayList
mouseListeners
Constructors Summary
public TableRowImpl(com.aelitis.azureus.ui.common.table.TableView tv, org.eclipse.swt.widgets.Table table, String sTableID, com.aelitis.azureus.ui.common.table.TableColumnCore[] columnsSorted, Object dataSource, boolean bSkipFirstColumn)
Default constructor

param
table
param
sTableID
param
columnsSorted
param
dataSource
param
bSkipFirstColumn


  // XXX add rowVisuallyupdated bool like in ListRow

                  
        
			   
			  
		super(table);
		this.tableView = tv;
    this.sTableID = sTableID;
    coreDataSource = dataSource;
    mTableCells = new HashMap();
    bDisposed = false;

    // create all the cells for the column
    for (int i = 0; i < columnsSorted.length; i++) {
    	if (columnsSorted[i] == null)
    		continue;
      //System.out.println(dataSource + ": " + tableColumns[i].getName() + ": " + tableColumns[i].getPosition());
    	TableCellImpl cell = new TableCellImpl(TableRowImpl.this, columnsSorted[i], 
          bSkipFirstColumn ? i+1 : i);
      mTableCells.put(columnsSorted[i].getName(), cell);
      //if (i == 10) cell.bDebug = true;
    }
  
Methods Summary
public voidaddMouseListener(TableRowMouseListener listener)

		try {
			this_mon.enter();

			if (mouseListeners == null)
				mouseListeners = new ArrayList(1);

			mouseListeners.add(listener);

		} finally {
			this_mon.exit();
		}
	
public voiddelete()

		this_mon.enter();

		try {
			if (bDisposed)
				return;

			if (TableViewSWT.DEBUGADDREMOVE)
				System.out.println((table.isDisposed() ? "" : table.getData("Name"))
						+ " row delete; index=" + getIndex());

			Iterator iter = mTableCells.values().iterator();
			while (iter.hasNext()) {
				TableCellSWT item = (TableCellSWT) iter.next();
				item.dispose();
			}

			bDisposed = true;
		} finally {
			this_mon.exit();
		}
	
public voiddoPaint(org.eclipse.swt.graphics.GC gc)

  	doPaint(gc, isVisible());
  
public voiddoPaint(org.eclipse.swt.graphics.GC gc, boolean bVisible)

    if (bDisposed || !bVisible)
      return;

    Iterator iter = mTableCells.values().iterator();
    while(iter.hasNext()) {
    	TableCellSWT cell = (TableCellSWT) iter.next();
    	if (cell == null) {
    		continue;
    	}
//    	if (bOnlyIfChanged && !cell.getVisuallyChangedSinceRefresh()) {
//    		continue;
//    	}
  		if (cell.needsPainting()) {
  			cell.doPaint(gc);
  		}
    }
  
public java.lang.ObjectgetDataSource(boolean bCoreObject)

  	if (bDisposed)
  		return null;

    if (bCoreObject)
      return coreDataSource;
      
    if (pluginDataSource != null)
      return pluginDataSource;

    if (sTableID.equals(TableManager.TABLE_MYTORRENTS_COMPLETE) ||
        sTableID.equals(TableManager.TABLE_MYTORRENTS_INCOMPLETE)) {
      DownloadManager dm = (DownloadManager)coreDataSource;
      if (dm != null) {
        try {
          pluginDataSource = DownloadManagerImpl.getDownloadStatic(dm);
        } catch (DownloadException e) { /* Ignore */ }
      }
    }
    if (sTableID.equals(TableManager.TABLE_TORRENT_PEERS)) {
      PEPeer peer = (PEPeer)coreDataSource;
      if (peer != null)
        pluginDataSource = PeerManagerImpl.getPeerForPEPeer( peer );
    }

    if (sTableID.equals(TableManager.TABLE_TORRENT_PIECES)) {
      // XXX There is no Piece object for plugins yet
      PEPiece piece = (PEPiece)coreDataSource;
      if (piece != null)
        pluginDataSource = null;
    }

    if (sTableID.equals(TableManager.TABLE_TORRENT_FILES)) {
      DiskManagerFileInfo fileInfo = (DiskManagerFileInfo)coreDataSource;
      if (fileInfo != null){
    	  try {
    		  pluginDataSource = 
    			  new DiskManagerFileInfoImpl(
    					  DownloadManagerImpl.getDownloadStatic(fileInfo.getDownloadManager()),
    					  fileInfo);
          } catch (DownloadException e) { /* Ignore */ }
      }
    }

    if (sTableID.equals(TableManager.TABLE_MYSHARES)) {
      pluginDataSource = coreDataSource;
    }

    if (sTableID.equals(TableManager.TABLE_MYTRACKER)) {
      TRHostTorrent item = (TRHostTorrent)coreDataSource;
      if (item != null)
        pluginDataSource = new TrackerTorrentImpl(item);
    }
    
    return pluginDataSource;
  
public java.lang.ObjectgetDataSource()
TableRow Implementation which returns the associated plugin object for the row. Core Column Object who wish to get core data source must re-class TableRow as TableRowCore and use getDataSource(boolean)

see
TableRowCore.getDataSource()

    return getDataSource(false);
  
public intgetIndex()

		if (bDisposed)
			return -1;

		return ((TableViewSWTImpl)tableView).indexOf(this);

		//return super.getIndex();
	
public intgetRealIndex()

		return super.getIndex();
	
public TableCellgetTableCell(java.lang.String field)

  	if (bDisposed)
  		return null;
    return (TableCell)mTableCells.get(field);
  
public com.aelitis.azureus.ui.common.table.TableCellCoregetTableCellCore(java.lang.String field)

  	if (bDisposed)
  		return null;

    return (TableCellCore)mTableCells.get(field);
  
public org.gudy.azureus2.ui.swt.views.table.TableCellSWTgetTableCellSWT(java.lang.String name)

param
name
return

  	if (bDisposed)
  		return null;

    return (TableCellSWT)mTableCells.get(name);
	
public java.lang.StringgetTableID()

    return sTableID;
  
public com.aelitis.azureus.ui.common.table.TableViewgetView()

		return tableView;
	
public voidinvalidate()

		super.invalidate();
		
  	if (bDisposed)
  		return;

    Iterator iter = mTableCells.values().iterator();
    while (iter.hasNext()) {
    	TableCellSWT cell = (TableCellSWT)iter.next();
      if (cell != null)
        cell.invalidate(true);
    }
	
public voidinvokeMouseListeners(TableRowMouseEvent event)

		ArrayList listeners = mouseListeners;
		if (listeners == null)
			return;
		
		for (int i = 0; i < listeners.size(); i++) {
			try {
				TableRowMouseListener l = (TableRowMouseListener) (listeners.get(i));

				l.rowMouseTrigger(event);

			} catch (Throwable e) {
				Debug.printStackTrace(e);
			}
		}
	
public booleanisRowDisposed()

		return bDisposed;
	
public booleanisValid()

  	if (bDisposed)
  		return true;

    boolean valid = true;
    Iterator iter = mTableCells.values().iterator();
    while (iter.hasNext()) {
    	TableCellSWT cell = (TableCellSWT)iter.next();
      if (cell != null)
        valid &= cell.isValid();
    }
    return valid;
  
public voidlocationChanged(int iStartColumn)

    if (bDisposed || !isVisible())
      return;

  	Iterator iter = mTableCells.values().iterator();
  	while(iter.hasNext()) {
  		TableCellSWT item = (TableCellSWT)iter.next();
  		if (item.getTableColumn().getPosition() > iStartColumn)
  		  item.locationChanged();
  	}
  
public voidredraw()

		refresh(true);
	
public java.util.Listrefresh(boolean bDoGraphics)

    if (bDisposed) {
      return new ArrayList(0);
    }
    
    boolean bVisible = isVisible();

    return refresh(bDoGraphics, bVisible);
  
public java.util.Listrefresh(boolean bDoGraphics, boolean bVisible)

    // If this were called from a plugin, we'd have to refresh the sorted column
    // even if we weren't visible
    ArrayList list = new ArrayList();

  	if (bDisposed) {
  		return list;
  	}

    if (!bVisible) {
    	if (!bSetNotUpToDateLastRefresh) {
    		setUpToDate(false);
    		bSetNotUpToDateLastRefresh = true;
    	}
  		return list;
  	}
    
		bSetNotUpToDateLastRefresh = false;
		
		//System.out.println(SystemTime.getCurrentTime() + "refresh " + getIndex());

    Iterator iter = mTableCells.values().iterator();
    while(iter.hasNext()) {
    	TableCellSWT item = (TableCellSWT)iter.next();
      boolean changed = item.refresh(bDoGraphics, bVisible);
      if (changed) {
      	list.add(item);
      }
    }
    return list;
  
public voidremoveMouseListener(TableRowMouseListener listener)

		try {
			this_mon.enter();

			if (mouseListeners == null)
				return;

			mouseListeners.remove(listener);

		} finally {
			this_mon.exit();
		}
	
public voidsetAlternatingBGColor(boolean bEvenIfNotVisible)

  	super.setAlternatingBGColor(bEvenIfNotVisible);
  
public voidsetForeground(org.eclipse.swt.graphics.Color c)

  	// Don't need to set when not visible
  	if (!isVisible())
  		return;
  	
  	super.setForeground(c);
	
public booleansetTableItem(int newIndex)

		if (bDisposed) {
			System.out.println("XXX setTI: bDisposed from " + Debug.getCompressedStackTrace());
			return false;
		}

		//if (getRealIndex() != newIndex) {
		//	((TableViewSWTImpl)tableView).debug("sTI " + newIndex + "; via " + Debug.getCompressedStackTrace(4));
		//}
		return setTableItem(newIndex, false);
	
public voidsetUpToDate(boolean upToDate)

  	if (bDisposed)
  		return;

    Iterator iter = mTableCells.values().iterator();
    while (iter.hasNext()) {
    	TableCellSWT cell = (TableCellSWT)iter.next();
      if (cell != null)
        cell.setUpToDate(upToDate);
    }
	
public java.lang.StringtoString()

		String result = "TableRowImpl@" + Integer.toHexString(hashCode());
		
		// In the rare case that we are calling this outside of a SWT thread, this
		// may break, so we will just ignore those exceptions.
		String index = null;
		try {index = String.valueOf(getIndex());}
		catch (SWTException se) {/* do nothing */}
		
		return result + ((index == null) ? "" : ("/#" + index));