FileDocCategorySizeDatePackage
TableColumnManager.javaAPI DocAzureus 3.0.3.410122Wed Aug 01 10:19:56 BST 2007org.gudy.azureus2.ui.swt.views.table.utils

TableColumnManager

public class TableColumnManager extends Object
Holds a list of column definitions (TableColumnCore) for all the tables in Azureus. Colum definitions are added via PluginInterface.addColumn(TableColumn) See Use javadoc section for more uses.
author
Oliver (Original Code)
author
TuxPaper (Modifications to make generic & comments)

Fields Summary
private static TableColumnManager
instance
private static org.gudy.azureus2.core3.util.AEMonitor
class_mon
private Map
items
private org.gudy.azureus2.core3.util.AEMonitor
items_mon
private Map
autoHideOrder
Holds the order in which the columns are auto-hidden key = TABLE_* type value = List of TableColumn, indexed in the order they should be removed
Constructors Summary
private TableColumnManager()


  
    
   items = new HashMap();
  
Methods Summary
public voidaddColumn(com.aelitis.azureus.ui.common.table.TableColumnCore item)
Adds a column definition to the list

param
item The column definition object

    try {
      String name = item.getName();
      String sTableID = item.getTableID();
     try{
     	items_mon.enter();
        Map mTypes = (Map)items.get(sTableID);
        if (mTypes == null) {
          // LinkedHashMap to preserve order
          mTypes = new LinkedHashMap();
          items.put(sTableID, mTypes);
        }
        if (!mTypes.containsKey(name)) {
          mTypes.put(name, item);
          ((TableColumnCore)item).loadSettings();
        }
      }finally{
      	items_mon.exit();
      }
      if (!item.getColumnAdded()) {
        item.setColumnAdded(true);
      }
    } catch (Exception e) {
      System.out.println("Error while adding Table Column Extension");
      Debug.printStackTrace( e );
    }
  
public voidaddExtension(java.lang.String name, org.gudy.azureus2.plugins.ui.tables.mytorrents.PluginMyTorrentsItemFactory item)
Add an extension from the deprecated PluginMyTorrentsItemFactory

deprecated

    String sAlign = item.getOrientation();
    int iAlign;
    if (sAlign.equals(PluginMyTorrentsItemFactory.ORIENT_RIGHT))
      iAlign = TableColumnCore.ALIGN_TRAIL;
    else
      iAlign = TableColumnCore.ALIGN_LEAD;

    int iVisibleIn = item.getTablesVisibleIn();
    if ((iVisibleIn & PluginMyTorrentsItemFactory.TABLE_COMPLETE) != 0) {
      TableColumnCore tci = 
        new OldMyTorrentsPluginItem(TableManager.TABLE_MYTORRENTS_COMPLETE, 
                                    name, item);
      tci.initialize(iAlign, item.getDefaultPosition(), item.getDefaultSize());
      addColumn(tci);
    }
    if ((iVisibleIn & PluginMyTorrentsItemFactory.TABLE_INCOMPLETE) != 0) {
      TableColumnCore tci = 
        new OldMyTorrentsPluginItem(TableManager.TABLE_MYTORRENTS_INCOMPLETE, 
                                    name, item);
      tci.initialize(iAlign, item.getDefaultPosition(), item.getDefaultSize());
      addColumn(tci);
    }
  
public voidaddExtension(java.lang.String name, org.gudy.azureus2.plugins.ui.tables.peers.PluginPeerItemFactory item)
Add an extension from the deprecated PluginPeerItemFactory

deprecated

    TableColumnCore tci = new OldPeerPluginItem(TableManager.TABLE_TORRENT_PEERS,
                                            name, item);
    tci.initialize(TableColumnCore.ALIGN_LEAD, 
                   TableColumnCore.POSITION_INVISIBLE, item.getDefaultSize());
    addColumn(tci);
  
public voidensureIntegrety(java.lang.String sTableID)

    Map mTypes = (Map)items.get(sTableID);
    if (mTypes == null)
      return;

    TableColumnCore[] tableColumns = 
      (TableColumnCore[])mTypes.values().toArray(new TableColumnCore[mTypes.values().size()]);

    Arrays.sort(tableColumns, new Comparator () {
      public final int compare (Object a, Object b) {
        int iPositionA = ((TableColumnCore)a).getPosition();
        if (iPositionA == TableColumnCore.POSITION_LAST)
          iPositionA = 0xFFFF;
        int iPositionB = ((TableColumnCore)b).getPosition();
        if (iPositionB == TableColumnCore.POSITION_LAST)
          iPositionB = 0xFFFF;

        return iPositionA - iPositionB;
      }
    });
    int iPos = 0;
    for (int i = 0; i < tableColumns.length; i++) {
      int iCurPos = tableColumns[i].getPosition();
      if (iCurPos >= 0 || iCurPos == TableColumnCore.POSITION_LAST) {
        tableColumns[i].setPositionNoShift(iPos++);
      }
    }
  
public voidgenerateDiagnostics(org.gudy.azureus2.core3.util.IndentWriter writer)

param
writer

    try{
     	items_mon.enter();
     	
     	writer.println("TableColumns");

     	for (Iterator iter = items.keySet().iterator(); iter.hasNext();) {
     		String sTableID = (String)iter.next();
        Map mTypes = (Map)items.get(sTableID);

        writer.indent();
     		writer.println(sTableID + ": " + mTypes.size() + " columns:");
     		
     		writer.indent();
       	for (Iterator iter2 = mTypes.values().iterator(); iter2.hasNext();) {
       		TableColumnCore tc = (TableColumnCore)iter2.next();
       		tc.generateDiagnostics(writer);
       	}
        writer.exdent();

        writer.exdent();
			}
    } catch (Exception e) {
    	e.printStackTrace();
    } finally {
    	items_mon.exit();
    }
	
public com.aelitis.azureus.ui.common.table.TableColumnCore[]getAllTableColumnCoreAsArray(java.lang.String sTableID)

    Map mTypes = (Map)items.get(sTableID);
    if (mTypes != null) {
      return (TableColumnCore[])mTypes.values().toArray(new TableColumnCore[mTypes.values().size()]);
    }
    return new TableColumnCore[0];
  
public java.util.ListgetAutoHideOrder(java.lang.String sTableID)

  	List list = (List)autoHideOrder.get(sTableID);
  	if (list == null) {
  		return new ArrayList();
  	}
  	return list;
  
public static org.gudy.azureus2.ui.swt.views.table.utils.TableColumnManagergetInstance()
Retrieve the static TableColumnManager instance

return
the static TableColumnManager instance

  	try{
  		class_mon.enter();
  	
  		if(instance == null)
  			instance = new TableColumnManager();
  		return instance;
  	}finally{
  		
  		class_mon.exit();
  	}
  
public com.aelitis.azureus.ui.common.table.TableColumnCoregetTableColumnCore(java.lang.String sTableID, java.lang.String sColumnName)

    Map mTypes = (Map)items.get(sTableID);
    if (mTypes == null)
      return null;
    return (TableColumnCore)mTypes.get(sColumnName);
  
public intgetTableColumnCount(java.lang.String sTableID)

    Map mTypes = (Map)items.get(sTableID);
    if (mTypes == null) {
    	return 0;
    }
    return mTypes.size();
  
public java.util.MapgetTableColumnsAsMap(java.lang.String sTableID)
Retrieves TableColumnCore objects of a particular type.

param
sTableID TABLE_* constant. See {@link TableColumn} for list of constants
return
Map of column definition objects matching the supplied criteria. key = name value = TableColumnCore object

    //System.out.println("getTableColumnsAsMap(" + sTableID + ")");
    try{
    	items_mon.enter();
      Map mReturn = new LinkedHashMap();
      Map mTypes = (Map)items.get(sTableID);
      if (mTypes != null) {
        mReturn.putAll(mTypes);
      }
      //System.out.println("getTableColumnsAsMap(" + sTableID + ") returnsize: " + mReturn.size());
      return mReturn;
    }finally{
    	
    	items_mon.exit();
    }
  
public voidsaveTableColumns(java.lang.String sTableID)
Saves all the user configurable Table Column settings at once, complete with a COConfigurationManager.save().

param
sTableID Table to save settings for

  	try {
      TableColumnCore[] tcs = getAllTableColumnCoreAsArray(sTableID);
      for (int i = 0; i < tcs.length; i++) {
        if (tcs[i] != null)
          tcs[i].saveSettings();
      }
      COConfigurationManager.save();
  	} catch (Exception e) {
  		Debug.out(e);
  	}
  
public voidsetAutoHideOrder(java.lang.String sTableID, java.lang.String[] autoHideOrderColumnIDs)

  	ArrayList autoHideOrderList = new ArrayList(autoHideOrderColumnIDs.length);
  	for (int i = 0; i < autoHideOrderColumnIDs.length; i++) {
			String sColumnID = autoHideOrderColumnIDs[i];
			TableColumnCore column = getTableColumnCore(sTableID, sColumnID);
			if (column != null) {
				autoHideOrderList.add(column);
			}
		}
  	
  	autoHideOrder.put(sTableID, autoHideOrderList);