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

TableHelper

public final class TableHelper extends Object
Utility class to help using Table objects.

Fields Summary
Constructors Summary
Methods Summary
public static org.eclipse.swt.widgets.TableColumncreateTableColumn(org.eclipse.swt.widgets.Table parent, java.lang.String header, int style, java.lang.String sample_text, java.lang.String pref_name, org.eclipse.jface.preference.IPreferenceStore prefs)
Create a TableColumn with the specified parameters. If a PreferenceStore object and a preference entry name String object are provided then the column will listen to change in its width and update the preference store accordingly.

param
parent The Table parent object
param
header The header string
param
style The column style
param
sample_text A sample text to figure out column width if preference value is missing
param
pref_name The preference entry name for column width
param
prefs The preference store
return
The TableColumn object that was created


        // create the column
        TableColumn col = new TableColumn(parent, style);

        // if there is no pref store or the entry is missing, we use the sample
        // text and pack the column.
        // Otherwise we just read the width from the prefs and apply it.
        if (prefs == null || prefs.contains(pref_name) == false) {
            col.setText(sample_text);
            col.pack();

            // init the prefs store with the current value
            if (prefs != null) {
                prefs.setValue(pref_name, col.getWidth());
            }
        } else {
            col.setWidth(prefs.getInt(pref_name));
        }

        // set the header
        col.setText(header);

        // if there is a pref store and a pref entry name, then we setup a
        // listener to catch column resize to put store the new width value.
        if (prefs != null && pref_name != null) {
            col.addControlListener(new ControlListener() {
                public void controlMoved(ControlEvent e) {
                }

                public void controlResized(ControlEvent e) {
                    // get the new width
                    int w = ((TableColumn)e.widget).getWidth();

                    // store in pref store
                    prefs.setValue(pref_name, w);
                }
            });
        }

        return col;
    
public static voidcreateTreeColumn(org.eclipse.swt.widgets.Tree parent, java.lang.String header, int style, java.lang.String sample_text, java.lang.String pref_name, org.eclipse.jface.preference.IPreferenceStore prefs)
Create a TreeColumn with the specified parameters. If a PreferenceStore object and a preference entry name String object are provided then the column will listen to change in its width and update the preference store accordingly.

param
parent The Table parent object
param
header The header string
param
style The column style
param
sample_text A sample text to figure out column width if preference value is missing
param
pref_name The preference entry name for column width
param
prefs The preference store


        // create the column
        TreeColumn col = new TreeColumn(parent, style);

        // if there is no pref store or the entry is missing, we use the sample
        // text and pack the column.
        // Otherwise we just read the width from the prefs and apply it.
        if (prefs == null || prefs.contains(pref_name) == false) {
            col.setText(sample_text);
            col.pack();

            // init the prefs store with the current value
            if (prefs != null) {
                prefs.setValue(pref_name, col.getWidth());
            }
        } else {
            col.setWidth(prefs.getInt(pref_name));
        }

        // set the header
        col.setText(header);

        // if there is a pref store and a pref entry name, then we setup a
        // listener to catch column resize to put store the new width value.
        if (prefs != null && pref_name != null) {
            col.addControlListener(new ControlListener() {
                public void controlMoved(ControlEvent e) {
                }

                public void controlResized(ControlEvent e) {
                    // get the new width
                    int w = ((TreeColumn)e.widget).getWidth();

                    // store in pref store
                    prefs.setValue(pref_name, w);
                }
            });
        }