///
/// Copyright © 2003-2008 JetBrains s.r.o.
/// You may distribute under the terms of the GNU General Public License, as published by the Free Software Foundation, version 2 (see License.txt in the repository root folder).
///
using System;
using System.Collections;
using JetBrains.DataStructures;
using JetBrains.Omea.OpenAPI;
namespace JetBrains.Omea
{
///
/// Stores the information about columns hidden from ResourceBrowser because of
/// ShowIfNotEmpty and ShowIfDistinct flags.
///
internal class HiddenColumnState
{
private ArrayList _mayBeEmptyColumns;
private ArrayList _mayBeEmptyPropIds;
private ArrayList _distinctColumns;
private ArrayList _distinctPropIds;
private IntHashTable _distinctValueMap;
public int HiddenColumnCount
{
get { return _mayBeEmptyColumns.Count; }
}
///
/// If the array of column descriptors has any "show if not empty" or "show if distinct" columns,
/// removes the columns which are empty or non-distinct from the column array.
///
/// The array of columns to filter.
/// The resource list by which the filtering is performed.
/// Filtered array of columns.
internal ColumnDescriptor[] HideEmptyColumns( ColumnDescriptor[] columns, IResourceList resList )
{
_mayBeEmptyColumns = new ArrayList();
_mayBeEmptyPropIds = new ArrayList();
_distinctColumns = new ArrayList();
_distinctPropIds = new ArrayList();
_distinctValueMap = new IntHashTable();
foreach( ColumnDescriptor colDesc in columns )
{
if ( (colDesc.Flags & ColumnDescriptorFlags.ShowIfNotEmpty ) != 0 )
{
_mayBeEmptyColumns.Add( colDesc );
_mayBeEmptyPropIds.Add( ((DisplayColumnManager) Core.DisplayColumnManager).PropNamesToIDs( colDesc.PropNames, true ) );
}
else if ((colDesc.Flags & ColumnDescriptorFlags.ShowIfDistinct) != 0 )
{
_distinctColumns.Add( colDesc );
_distinctPropIds.Add( ((DisplayColumnManager) Core.DisplayColumnManager).PropNamesToIDs( colDesc.PropNames, true ) );
}
}
if ( _mayBeEmptyColumns.Count == 0 && _distinctColumns.Count == 0 )
{
return columns;
}
lock( resList )
{
foreach( IResource res in resList.ValidResources )
{
for( int i=_mayBeEmptyColumns.Count-1; i >= 0; i-- )
{
if ( !IsColumnEmpty( resList, res, i ) )
{
_mayBeEmptyPropIds.RemoveAt( i );
_mayBeEmptyColumns.RemoveAt( i );
}
}
for( int i=_distinctColumns.Count-1; i >= 0; i-- )
{
if ( !ValueMatchesDistinctColumn( res, i ) )
{
_distinctPropIds.RemoveAt( i );
_distinctColumns.RemoveAt( i );
}
}
if ( _mayBeEmptyColumns.Count == 0 && _distinctColumns.Count == 0 )
{
return columns;
}
}
}
ColumnDescriptor[] result = new ColumnDescriptor[ columns.Length - _mayBeEmptyColumns.Count - _distinctColumns.Count ];
int destIndex=0;
for( int i=0; i