TableViewer(Composite parent, int style)
. When you want to set style parameter, code completion does not help. So you have to read the (3.1) javadoc of TableViewer it says: @param style SWT style bits
. Great, but not very helpful. Ok if you are clever, you know that TableViewer passes the status
flags directly to the Table constructor. The documentatios there there indicates that the following flags can be used SWT.SINGLE, SWT.MULTI, SWT.CHECK, SWT.FULL_SELECTION, SWT.HIDE_SELECTION, SWT.VIRTUAL
Ok this gives you a hint, what to use. But if you follow the link to
SWT.MULTI
, you read: "Used by Text,List and FileDialog"... Hmm, no mentioning of Table....I don't want to blame the documentation. The problem comes from the design choice to use integer bits constants in the first place. If you look into the class SWT, you are simply overwhelmed by all the integer constants. I see two solutions (in Java 1.4): >
- eclipse supports structured comments for code completion, and the javadoc would reflect the flags correctly.
- Use some classes representing the flags:
Then the constructor of TableViewer and Table would take this class. You would have all the benefits of code completion and documentation. Internally, SWT could still use integer bit flags, but as a user I would have a fully typed constructor: Instead of
public static class Style {
int flags;
public Style(){}
protected Style(int flags) {
this.flags=flags;
}
public Style multi() {
return new Style(flags|SWT.MULTI);
}
public Style full_selection() {
return new Style(flags|SWT.FULL_SELECTION);
}
...
}
new TableViewer(parent,SWT.MULTI|SWT.FULL_SELECTION)
I would use the fully typed construct new TableViewer(parent,new Table.Style().multi().full_selection())
. Code completion would help me. No more wrong flags! I would love to see additional constructors(and methods) with typed versions....
I have always found the use of integer constants in SWT very frustrating. For the reasons you mention, it's slow to write SWT code ... as you cross-reference various SWT documents and simply try to find the right flags through trial and error. I also feel it would be helpful to provide constructors that pass a sane "default" set of flags.
ReplyDelete+1 Have you created a bug for this?
ReplyDeleteHow about writing a patch?
ReplyDeleteI'd suggest to replace "return new Style(flags|SWT.MULTI);" with "flags |= SWT.MULTI; return this;", though.