TableHelperpublic final class TableHelper extends Object Utility class to help using Table objects. |
Methods Summary |
---|
public static org.eclipse.swt.widgets.TableColumn | createTableColumn(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.
// 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 void | createTreeColumn(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.
// 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);
}
});
}
|
|