JIDE 3.5.15

com.jidesoft.grid
Class TableColumnChooserPopupMenuCustomizer

java.lang.Object
  extended by com.jidesoft.grid.TableColumnChooserPopupMenuCustomizer
All Implemented Interfaces:
TableHeaderPopupMenuCustomizer
Direct Known Subclasses:
AggregateTableColumnChooserPopupMenuCustomizer

public class TableColumnChooserPopupMenuCustomizer
extends Object
implements TableHeaderPopupMenuCustomizer

A TableHeaderPopupMenuCustomizer to add menu items related to show or hide the columns to a popup menu. To use it, you can use the code like this. Please be noted that if you are going to install these menu items for AggregateTable, please use AggregateTableColumnChooserPopupMenuCustomizer instead.

 TableHeaderPopupMenuInstaller installer = new TableHeaderPopupMenuInstaller(aggregateTable)
 installer.addTableHeaderPopupMenuCustomizer(new TableColumnChooserPopupMenuCustomizer());
 


Field Summary
protected  Locale _locale
           
static String CLIENT_PROPERTY_CLICK_COLUMN_INDEX
          client property used to pass clicking column index to ActionListener
static String CONTEXT_MENU_HIDE
          CONTEXT_MENU_...
static String CONTEXT_MENU_MORE
           
static String CONTEXT_MENU_OTHER_COLUMNS
           
static String CONTEXT_MENU_RESET_COLUMNS
           
static String CONTEXT_MENU_SHOW_ALL
           
 
Constructor Summary
TableColumnChooserPopupMenuCustomizer()
           
 
Method Summary
protected  TableColumnChooserDialog createTableColumnChooserDialog(Window owner, String title, JTable table)
          Create TableColumnChooserDialog instance while you choose "More..." option.
 void customizePopupMenu(JTableHeader header, JPopupMenu popup, int clickingColumn)
          The method generates the context menu items by clickingColumn.
protected  int getColumnCount(JTable table)
           
protected  String getDisplayColumnName(JTable table, int columnIndex)
          Gets the display column name to be displayed on the popup menu.
 String[] getDisplayColumnNames()
          Gets the display column names set by setDisplayColumnNames(String[]).
 int[] getFavoriteColumns()
          Gets the favorite columns.
 int[] getFixedColumns()
          Gets the fixed columns.
 int[] getHiddenColumns()
          Gets the hidden columns.
protected  Object getIdentifier(JTable table, int columnIndex)
          Gets the identifier of the column.
protected  String getResourceString(String key)
          Gets the localized string from resource bundle.
protected  void hideColumn(JTable table, int columnIndex)
          Calls to TableColumnChooser.hideColumn to hide the column.
 void setDisplayColumnNames(String[] displayColumnNames)
          This method can be used to specify what column names to display on the popup menu.
 void setFavoriteColumns(int[] favoriteColumns)
          Sets the favorite columns.
 void setFixedColumns(int[] fixedColumns)
          Sets the fixed columns.
 void setHiddenColumns(int[] hiddenColumns)
          Sets the hidden columns.
protected  void showAllColumns(JTable table)
           
protected  void showColumn(JTable table, int columnIndex)
          Deprecated. replaced by showColumn(javax.swing.JTable, int, Object)
protected  void showColumn(JTable table, int columnIndex, Object columnIdentifier)
          Calls to TableColumnChooser.showColumn to show the column.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLIENT_PROPERTY_CLICK_COLUMN_INDEX

public static final String CLIENT_PROPERTY_CLICK_COLUMN_INDEX
client property used to pass clicking column index to ActionListener

See Also:
Constant Field Values

CONTEXT_MENU_HIDE

public static final String CONTEXT_MENU_HIDE
CONTEXT_MENU_... are the possible menu names displayed in the menu. You can use these string as name to locate the existing menu items.

See Also:
customizePopupMenu(javax.swing.table.JTableHeader, javax.swing.JPopupMenu, int), Constant Field Values

CONTEXT_MENU_SHOW_ALL

public static final String CONTEXT_MENU_SHOW_ALL
See Also:
Constant Field Values

CONTEXT_MENU_OTHER_COLUMNS

public static final String CONTEXT_MENU_OTHER_COLUMNS
See Also:
Constant Field Values

CONTEXT_MENU_RESET_COLUMNS

public static final String CONTEXT_MENU_RESET_COLUMNS
See Also:
Constant Field Values

CONTEXT_MENU_MORE

public static final String CONTEXT_MENU_MORE
See Also:
Constant Field Values

_locale

protected Locale _locale
Constructor Detail

TableColumnChooserPopupMenuCustomizer

public TableColumnChooserPopupMenuCustomizer()
Method Detail

getDisplayColumnNames

public String[] getDisplayColumnNames()
Gets the display column names set by setDisplayColumnNames(String[]).

Returns:
the column names displayed on the popup menu. Or null if the setter is never called. In this case, TableModel#getColumnName will be used to get the name and display on the popup menu.

setDisplayColumnNames

public void setDisplayColumnNames(String[] displayColumnNames)
This method can be used to specify what column names to display on the popup menu. The value for it is of type String[]. The length of the array should be the same as the table model's column count. Each item in the array represents one column as in the order of the table model. If you didn't call this method, TableModel#getColumnName will be used to get the name and display on the popup menu.

Parameters:
displayColumnNames - the display column names on the table model.

getHiddenColumns

public int[] getHiddenColumns()
Gets the hidden columns. The hidden columns will not appear in the popup so that user can not show or hide those columns. Please note, it doesn't mean the columns should be hidden on the table.

Returns:
the hidden columns.

setHiddenColumns

public void setHiddenColumns(int[] hiddenColumns)
Sets the hidden columns. The hidden columns will not appear in the popup so that user can not show or hide those columns. Please note, it doesn't mean the columns should be hidden on the table. It is an int array. Each int is a column index as in the table model.

Parameters:
hiddenColumns - the hidden column indices.

getFixedColumns

public int[] getFixedColumns()
Gets the fixed columns. The fixed columns will appear on the popup but as a disabled menu item so that user can not show or hide those columns.

Returns:
the fixed columns.

setFixedColumns

public void setFixedColumns(int[] fixedColumns)
Sets the fixed columns. The fixed columns will appear on the popup but as a disabled menu item so that user can not show or hide those columns. It is an int array. Each int is a column index as in the table model.

Parameters:
fixedColumns - the hidden column indices.

getFavoriteColumns

public int[] getFavoriteColumns()
Gets the favorite columns. The favorite columns will appear directly on the popup. And all non-favorite columns will appear as a sub-menu so that the main popup is not so crowded with too many menu items.

Returns:
the favorite columns.

setFavoriteColumns

public void setFavoriteColumns(int[] favoriteColumns)
Sets the favorite columns. The favorite columns will appear directly on the popup. And all non-favorite columns will appear as a sub-menu so that the main popup is not so crowded with too many menu items. If you don't call this method, all columns will be treated as favorite columns which means they will be shown directly on the popup.

Parameters:
favoriteColumns - the hidden column indices.

getResourceString

protected String getResourceString(String key)
Gets the localized string from resource bundle. Subclass can override it to provide its own string. Available keys are defined in grid.properties that begin with "TableColumnChooser.".

Parameters:
key - the resource string key
Returns:
the localized string.

getDisplayColumnName

protected String getDisplayColumnName(JTable table,
                                      int columnIndex)
Gets the display column name to be displayed on the popup menu.

Parameters:
table - the table
columnIndex - the column index as in table model.
Returns:
the display name for the column at the specified column index.

getIdentifier

protected Object getIdentifier(JTable table,
                               int columnIndex)
Gets the identifier of the column.

Parameters:
table - the table
columnIndex - the column index as in table model.
Returns:
the identifier at the specified column index.

customizePopupMenu

public void customizePopupMenu(JTableHeader header,
                               JPopupMenu popup,
                               int clickingColumn)
The method generates the context menu items by clickingColumn. After the process, the popup will contain all the generated menu items. You can override the method to add some new menu items or delete some existing menu items as you wish. You can use CONTEXT_MENU_... as the name to find the existing menu items.
      for (int i = 0; i < popup.getComponentCount(); i++) {
          if (CONTEXT_MENU_HIDE.equals(popup.getComponent(i).getName())) {
              popup.remove(popup.getComponent(i));
          }
      }
 

Specified by:
customizePopupMenu in interface TableHeaderPopupMenuCustomizer
Parameters:
header - the table header
popup - the popup menu to be displayed
clickingColumn - the column index clicked

createTableColumnChooserDialog

protected TableColumnChooserDialog createTableColumnChooserDialog(Window owner,
                                                                  String title,
                                                                  JTable table)
Create TableColumnChooserDialog instance while you choose "More..." option. By default, the dialog shows a CheckBoxList of current column name for you to choose. You can override this method to change the layout of the dialog.

Parameters:
owner - the owner of the dialog
title - the title of the dialog
table - the JTable related to the dialog
Returns:
a TableColumnChooserDialog instance.

getColumnCount

protected int getColumnCount(JTable table)

showAllColumns

protected void showAllColumns(JTable table)

hideColumn

protected void hideColumn(JTable table,
                          int columnIndex)
Calls to TableColumnChooser.hideColumn to hide the column.

Parameters:
table - the table
columnIndex - the model column index.

showColumn

@Deprecated
protected void showColumn(JTable table,
                                     int columnIndex)
Deprecated. replaced by showColumn(javax.swing.JTable, int, Object)

Calls to TableColumnChooser.showColumn to show the column.

Parameters:
table - the table
columnIndex - the model column index.

showColumn

protected void showColumn(JTable table,
                          int columnIndex,
                          Object columnIdentifier)
Calls to TableColumnChooser.showColumn to show the column.

Parameters:
table - the table
columnIndex - the model column index.
columnIdentifier - the column identifier
Since:
3.2.2

JIDE 3.5.15