FileDocCategorySizeDatePackage
TablePanel.javaAPI DocAndroid 1.5 API4335Wed May 06 22:41:08 BST 2009com.android.ddmuilib

TablePanel

public abstract class TablePanel extends ClientDisplayPanel
Base class for panel containing Table that need to support copy-paste-selectAll

Fields Summary
private ITableFocusListener
mGlobalListener
Constructors Summary
Methods Summary
protected final voidaddTableToFocusListener(org.eclipse.swt.widgets.Table table, int colStart, int colEnd)
Sets up a Table object to notify the global Table Focus listener when it gets or loses the focus.

param
table the Table object.
param
colStart
param
colEnd

        // create the activator for this table
        final IFocusedTableActivator activator = new IFocusedTableActivator() {
            public void copy(Clipboard clipboard) {
                int[] selection = table.getSelectionIndices();

                // we need to sort the items to be sure.
                Arrays.sort(selection);

                // all lines must be concatenated.
                StringBuilder sb = new StringBuilder();

                // loop on the selection and output the file.
                for (int i : selection) {
                    TableItem item = table.getItem(i);
                    for (int c = colStart ; c <= colEnd ; c++) {
                        sb.append(item.getText(c));
                        sb.append('\t");
                    }
                    sb.append('\n");
                }

                // now add that to the clipboard if the string has content
                String data = sb.toString();
                if (data != null || data.length() > 0) {
                    clipboard.setContents(
                            new Object[] { data },
                            new Transfer[] { TextTransfer.getInstance() });
                }
            }

            public void selectAll() {
                table.selectAll();
            }
        };

        // add the focus listener on the table to notify the global listener
        table.addFocusListener(new FocusListener() {
            public void focusGained(FocusEvent e) {
                mGlobalListener.focusGained(activator);
            }

            public void focusLost(FocusEvent e) {
                mGlobalListener.focusLost(activator);
            }
        });
    
protected final voidaddTableToFocusListener(org.eclipse.swt.widgets.Table table)
Sets up a Table object to notify the global Table Focus listener when it gets or loses the focus.
When the copy method is invoked, all columns are put in the clipboard, separated by tabs

param
table the Table object.

        addTableToFocusListener(table, 0, table.getColumnCount()-1);
    
public final voidsetTableFocusListener(ITableFocusListener listener)
Sets a TableFocusListener which will be notified when one of the tables gets or loses focus.

param
listener

        // record the global listener, to make sure table created after
        // this call will still be setup.
        mGlobalListener = listener;

        setTableFocusListener();
    
protected voidsetTableFocusListener()
Sets up the Table of object of the panel to work with the global listener.
Default implementation does nothing.