I can\'t search for | in Google. If you had found it in a software source code that you are trying to interpret, you didn\'t know what it does and you couldn\'t ask other pe
The pipe operator in this case means "use both SWT.APPLICATION_MODAL and SWT.OK as options/flags for my popup box." It's a very commonly used idiom with bitfield configuration identifiers, esp. in windowing systems like SWT or Win32.
How it works
The pipe (|) operator is the bitwise OR operator, that is, it computes an OR operation of the two binary integer values. If you check out where APPLICATION_MODAL and OK are defined, you'll find they are something like this:
...
SWT.OK = 1, // 00000001 in binary
SWT.ABORT_RETRY_IGNORE = 2, // 00000010 in binary
SWT.OK_CANCEL = 4; // 00000100 in binary
...
SWT.APPLICATION_MODAL = 32; // 00100000 in binary
... (and so on...)
When you bitwise OR two (or more) of these numbers together, individual bits will be set for each of the options:
int style = SWT.OK | SWT.APPLICATION_MODAL = 00000001 | 00100000 = 00100001
The windowing toolkit that goes to interpret style will be able to tell exactly what you wanted (a popup box that is Modal and has an OK button) by doing a bitwise AND like this:
...
if(style & SWT.OK)
{
// we want an OK box
}
if(style & SWT.ABORT_RETRY_IGNORE)
{
// we want an Abort/Retry/Ignore box
}
if(style & SWT.OK_CANCEL)
{
// we want an OK/Cancel box
}
...
if(style & SWT.APPLICATION_MODAL)
{
// We want a modal box
}
...
Kinda clever, in my humble opinion. It allows you to select/represent multiple configuration options in a single variable. The trick is in the integer definitions of the options, and ensuring that they are only powers of 2.