Example usage for org.eclipse.swt.widgets Button setSelection

List of usage examples for org.eclipse.swt.widgets Button setSelection

Introduction

In this page you can find the example usage for org.eclipse.swt.widgets Button setSelection.

Prototype

public void setSelection(boolean selected) 

Source Link

Document

Sets the selection state of the receiver, if it is of type CHECK, RADIO, or TOGGLE.

Usage

From source file:DNDExample.java

private void createDragOperations(Composite parent) {
    parent.setLayout(new RowLayout(SWT.VERTICAL));
    final Button moveButton = new Button(parent, SWT.CHECK);
    moveButton.setText("DND.DROP_MOVE");
    moveButton.setSelection(true);
    dragOperation = DND.DROP_MOVE;/*from ww  w  . java 2 s.c  om*/
    moveButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            Button b = (Button) e.widget;
            if (b.getSelection()) {
                dragOperation |= DND.DROP_MOVE;
            } else {
                dragOperation = dragOperation & ~DND.DROP_MOVE;
                if (dragOperation == 0) {
                    dragOperation = DND.DROP_MOVE;
                    moveButton.setSelection(true);
                }
            }
            if (dragEnabled) {
                createDragSource();
            }
        }
    });

    Button b = new Button(parent, SWT.CHECK);
    b.setText("DND.DROP_COPY");
    b.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            Button b = (Button) e.widget;
            if (b.getSelection()) {
                dragOperation |= DND.DROP_COPY;
            } else {
                dragOperation = dragOperation & ~DND.DROP_COPY;
                if (dragOperation == 0) {
                    dragOperation = DND.DROP_MOVE;
                    moveButton.setSelection(true);
                }
            }
            if (dragEnabled) {
                createDragSource();
            }
        }
    });

    b = new Button(parent, SWT.CHECK);
    b.setText("DND.DROP_LINK");
    b.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            Button b = (Button) e.widget;
            if (b.getSelection()) {
                dragOperation |= DND.DROP_LINK;
            } else {
                dragOperation = dragOperation & ~DND.DROP_LINK;
                if (dragOperation == 0) {
                    dragOperation = DND.DROP_MOVE;
                    moveButton.setSelection(true);
                }
            }
            if (dragEnabled) {
                createDragSource();
            }
        }
    });
}

From source file:DNDExample.java

private void createDropOperations(Composite parent) {
    parent.setLayout(new RowLayout(SWT.VERTICAL));
    final Button moveButton = new Button(parent, SWT.CHECK);
    moveButton.setText("DND.DROP_MOVE");
    moveButton.setSelection(true);
    dropOperation = DND.DROP_MOVE;/*  ww w . j a v  a  2s.c o  m*/
    moveButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            Button b = (Button) e.widget;
            if (b.getSelection()) {
                dropOperation |= DND.DROP_MOVE;
            } else {
                dropOperation = dropOperation & ~DND.DROP_MOVE;
                if (dropOperation == 0 || (dropDefaultOperation & DND.DROP_MOVE) != 0) {
                    dropOperation |= DND.DROP_MOVE;
                    moveButton.setSelection(true);
                }
            }
            if (dropEnabled) {
                createDropTarget();
            }
        }
    });

    final Button copyButton = new Button(parent, SWT.CHECK);
    copyButton.setText("DND.DROP_COPY");
    copyButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            Button b = (Button) e.widget;
            if (b.getSelection()) {
                dropOperation |= DND.DROP_COPY;
            } else {
                dropOperation = dropOperation & ~DND.DROP_COPY;
                if (dropOperation == 0 || (dropDefaultOperation & DND.DROP_COPY) != 0) {
                    dropOperation = DND.DROP_COPY;
                    copyButton.setSelection(true);
                }
            }
            if (dropEnabled) {
                createDropTarget();
            }
        }
    });

    final Button linkButton = new Button(parent, SWT.CHECK);
    linkButton.setText("DND.DROP_LINK");
    linkButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            Button b = (Button) e.widget;
            if (b.getSelection()) {
                dropOperation |= DND.DROP_LINK;
            } else {
                dropOperation = dropOperation & ~DND.DROP_LINK;
                if (dropOperation == 0 || (dropDefaultOperation & DND.DROP_LINK) != 0) {
                    dropOperation = DND.DROP_LINK;
                    linkButton.setSelection(true);
                }
            }
            if (dropEnabled) {
                createDropTarget();
            }
        }
    });

    Button b = new Button(parent, SWT.CHECK);
    b.setText("DND.DROP_DEFAULT");
    defaultParent = new Composite(parent, SWT.NONE);
    b.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            Button b = (Button) e.widget;
            if (b.getSelection()) {
                dropOperation |= DND.DROP_DEFAULT;
                defaultParent.setVisible(true);
            } else {
                dropOperation = dropOperation & ~DND.DROP_DEFAULT;
                defaultParent.setVisible(false);
            }
            if (dropEnabled) {
                createDropTarget();
            }
        }
    });

    defaultParent.setVisible(false);
    GridLayout layout = new GridLayout();
    layout.marginWidth = 20;
    defaultParent.setLayout(layout);
    Label label = new Label(defaultParent, SWT.NONE);
    label.setText("Value for default operation is:");
    b = new Button(defaultParent, SWT.RADIO);
    b.setText("DND.DROP_MOVE");
    b.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            Button b = (Button) e.widget;
            if (b.getSelection()) {
                dropDefaultOperation = DND.DROP_MOVE;
                dropOperation |= DND.DROP_MOVE;
                moveButton.setSelection(true);
                if (dropEnabled) {
                    createDropTarget();
                }
            }
        }
    });

    b = new Button(defaultParent, SWT.RADIO);
    b.setText("DND.DROP_COPY");
    b.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            Button b = (Button) e.widget;
            if (b.getSelection()) {
                dropDefaultOperation = DND.DROP_COPY;
                dropOperation |= DND.DROP_COPY;
                copyButton.setSelection(true);
                if (dropEnabled) {
                    createDropTarget();
                }
            }
        }
    });

    b = new Button(defaultParent, SWT.RADIO);
    b.setText("DND.DROP_LINK");
    b.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            Button b = (Button) e.widget;
            if (b.getSelection()) {
                dropDefaultOperation = DND.DROP_LINK;
                dropOperation |= DND.DROP_LINK;
                linkButton.setSelection(true);
                if (dropEnabled) {
                    createDropTarget();
                }
            }
        }
    });

    b = new Button(defaultParent, SWT.RADIO);
    b.setText("DND.DROP_NONE");
    b.setSelection(true);
    b.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            Button b = (Button) e.widget;
            if (b.getSelection()) {
                dropDefaultOperation = DND.DROP_NONE;
                dropOperation &= ~DND.DROP_DEFAULT;
                if (dropEnabled) {
                    createDropTarget();
                }
            }
        }
    });
}

From source file:org.eclipse.swt.examples.dnd.DNDExample.java

private void createDragWidget(Composite parent) {
    parent.setLayout(new FormLayout());
    Combo combo = new Combo(parent, SWT.READ_ONLY);
    combo.setItems("Toggle Button", "Radio Button", "Checkbox", "Canvas", "Label", "List", "Table", "Tree",
            "Text", "StyledText", "Combo");
    combo.select(LABEL);/*  w  w  w .  ja v a 2 s  .c  o m*/
    dragControlType = combo.getSelectionIndex();
    dragControl = createWidget(dragControlType, parent, "Drag Source");

    combo.addSelectionListener(widgetSelectedAdapter(e -> {
        Object data = dragControl.getLayoutData();
        Composite dragParent = dragControl.getParent();
        dragControl.dispose();
        Combo c = (Combo) e.widget;
        dragControlType = c.getSelectionIndex();
        dragControl = createWidget(dragControlType, dragParent, "Drag Source");
        dragControl.setLayoutData(data);
        if (dragEnabled)
            createDragSource();
        dragParent.layout();
    }));

    Button b = new Button(parent, SWT.CHECK);
    b.setText("DragSource");
    b.addSelectionListener(widgetSelectedAdapter(e -> {
        Button b1 = (Button) e.widget;
        dragEnabled = b1.getSelection();
        if (dragEnabled) {
            createDragSource();
        } else {
            if (dragSource != null) {
                dragSource.dispose();
            }
            dragSource = null;
        }
    }));
    b.setSelection(true);
    dragEnabled = true;

    FormData data = new FormData();
    data.top = new FormAttachment(0, 10);
    data.bottom = new FormAttachment(combo, -10);
    data.left = new FormAttachment(0, 10);
    data.right = new FormAttachment(100, -10);
    dragControl.setLayoutData(data);

    data = new FormData();
    data.bottom = new FormAttachment(100, -10);
    data.left = new FormAttachment(0, 10);
    combo.setLayoutData(data);

    data = new FormData();
    data.bottom = new FormAttachment(100, -10);
    data.left = new FormAttachment(combo, 10);
    b.setLayoutData(data);
}

From source file:org.eclipse.swt.examples.dnd.DNDExample.java

private void createDragOperations(Composite parent) {
    parent.setLayout(new RowLayout(SWT.VERTICAL));
    final Button moveButton = new Button(parent, SWT.CHECK);
    moveButton.setText("DND.DROP_MOVE");
    moveButton.addSelectionListener(widgetSelectedAdapter(e -> {
        Button b = (Button) e.widget;
        if (b.getSelection()) {
            dragOperation |= DND.DROP_MOVE;
        } else {/*from w  ww . ja  va 2  s . co  m*/
            dragOperation = dragOperation & ~DND.DROP_MOVE;
            if (dragOperation == 0) {
                dragOperation = DND.DROP_MOVE;
                moveButton.setSelection(true);
            }
        }
        if (dragEnabled) {
            createDragSource();
        }
    }));

    Button copyButton = new Button(parent, SWT.CHECK);
    copyButton.setText("DND.DROP_COPY");
    copyButton.addSelectionListener(widgetSelectedAdapter(e -> {
        Button b = (Button) e.widget;
        if (b.getSelection()) {
            dragOperation |= DND.DROP_COPY;
        } else {
            dragOperation = dragOperation & ~DND.DROP_COPY;
            if (dragOperation == 0) {
                dragOperation = DND.DROP_MOVE;
                moveButton.setSelection(true);
            }
        }
        if (dragEnabled) {
            createDragSource();
        }
    }));

    Button linkButton = new Button(parent, SWT.CHECK);
    linkButton.setText("DND.DROP_LINK");
    linkButton.addSelectionListener(widgetSelectedAdapter(e -> {
        Button b = (Button) e.widget;
        if (b.getSelection()) {
            dragOperation |= DND.DROP_LINK;
        } else {
            dragOperation = dragOperation & ~DND.DROP_LINK;
            if (dragOperation == 0) {
                dragOperation = DND.DROP_MOVE;
                moveButton.setSelection(true);
            }
        }
        if (dragEnabled) {
            createDragSource();
        }
    }));

    //initialize state
    moveButton.setSelection(true);
    copyButton.setSelection(true);
    linkButton.setSelection(true);
    dragOperation |= DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK;
}

From source file:org.eclipse.swt.examples.dnd.DNDExample.java

private void createDropWidget(Composite parent) {
    parent.setLayout(new FormLayout());
    Combo combo = new Combo(parent, SWT.READ_ONLY);
    combo.setItems("Toggle Button", "Radio Button", "Checkbox", "Canvas", "Label", "List", "Table", "Tree",
            "Text", "StyledText", "Combo");
    combo.select(LABEL);//from   w  w w . j a  va2s.  co  m
    dropControlType = combo.getSelectionIndex();
    dropControl = createWidget(dropControlType, parent, "Drop Target");
    combo.addSelectionListener(widgetSelectedAdapter(e -> {
        Object data = dropControl.getLayoutData();
        Composite dropParent = dropControl.getParent();
        dropControl.dispose();
        Combo c = (Combo) e.widget;
        dropControlType = c.getSelectionIndex();
        dropControl = createWidget(dropControlType, dropParent, "Drop Target");
        dropControl.setLayoutData(data);
        if (dropEnabled)
            createDropTarget();
        dropParent.layout();
    }));

    Button b = new Button(parent, SWT.CHECK);
    b.setText("DropTarget");
    b.addSelectionListener(widgetSelectedAdapter(e -> {
        Button eb = (Button) e.widget;
        dropEnabled = eb.getSelection();
        if (dropEnabled) {
            createDropTarget();
        } else {
            if (dropTarget != null) {
                dropTarget.dispose();
            }
            dropTarget = null;
        }
    }));
    // initialize state
    b.setSelection(true);
    dropEnabled = true;

    FormData data = new FormData();
    data.top = new FormAttachment(0, 10);
    data.bottom = new FormAttachment(combo, -10);
    data.left = new FormAttachment(0, 10);
    data.right = new FormAttachment(100, -10);
    dropControl.setLayoutData(data);

    data = new FormData();
    data.bottom = new FormAttachment(100, -10);
    data.left = new FormAttachment(0, 10);
    combo.setLayoutData(data);

    data = new FormData();
    data.bottom = new FormAttachment(100, -10);
    data.left = new FormAttachment(combo, 10);
    b.setLayoutData(data);
}

From source file:org.eclipse.swt.examples.dnd.DNDExample.java

private void createDropOperations(Composite parent) {
    parent.setLayout(new RowLayout(SWT.VERTICAL));
    final Button moveButton = new Button(parent, SWT.CHECK);
    moveButton.setText("DND.DROP_MOVE");
    moveButton.addSelectionListener(widgetSelectedAdapter(e -> {
        Button b = (Button) e.widget;
        if (b.getSelection()) {
            dropOperation |= DND.DROP_MOVE;
        } else {/*from w  w w  .  j  a  va  2s.  c  om*/
            dropOperation = dropOperation & ~DND.DROP_MOVE;
            if (dropOperation == 0 || (dropDefaultOperation & DND.DROP_MOVE) != 0) {
                dropOperation |= DND.DROP_MOVE;
                moveButton.setSelection(true);
            }
        }
        if (dropEnabled) {
            createDropTarget();
        }
    }));

    final Button copyButton = new Button(parent, SWT.CHECK);
    copyButton.setText("DND.DROP_COPY");
    copyButton.addSelectionListener(widgetSelectedAdapter(e -> {
        Button b = (Button) e.widget;
        if (b.getSelection()) {
            dropOperation |= DND.DROP_COPY;
        } else {
            dropOperation = dropOperation & ~DND.DROP_COPY;
            if (dropOperation == 0 || (dropDefaultOperation & DND.DROP_COPY) != 0) {
                dropOperation = DND.DROP_COPY;
                copyButton.setSelection(true);
            }
        }
        if (dropEnabled) {
            createDropTarget();
        }
    }));

    final Button linkButton = new Button(parent, SWT.CHECK);
    linkButton.setText("DND.DROP_LINK");
    linkButton.addSelectionListener(widgetSelectedAdapter(e -> {
        Button eb = (Button) e.widget;
        if (eb.getSelection()) {
            dropOperation |= DND.DROP_LINK;
        } else {
            dropOperation = dropOperation & ~DND.DROP_LINK;
            if (dropOperation == 0 || (dropDefaultOperation & DND.DROP_LINK) != 0) {
                dropOperation = DND.DROP_LINK;
                linkButton.setSelection(true);
            }
        }
        if (dropEnabled) {
            createDropTarget();
        }
    }));

    Button b = new Button(parent, SWT.CHECK);
    b.setText("DND.DROP_DEFAULT");
    defaultParent = new Composite(parent, SWT.NONE);
    b.addSelectionListener(widgetSelectedAdapter(e -> {
        Button eb = (Button) e.widget;
        if (eb.getSelection()) {
            dropOperation |= DND.DROP_DEFAULT;
            defaultParent.setVisible(true);
        } else {
            dropOperation = dropOperation & ~DND.DROP_DEFAULT;
            defaultParent.setVisible(false);
        }
        if (dropEnabled) {
            createDropTarget();
        }
    }));

    defaultParent.setVisible(false);
    GridLayout layout = new GridLayout();
    layout.marginWidth = 20;
    defaultParent.setLayout(layout);
    Label label = new Label(defaultParent, SWT.NONE);
    label.setText("Value for default operation is:");
    b = new Button(defaultParent, SWT.RADIO);
    b.setText("DND.DROP_MOVE");
    b.addSelectionListener(widgetSelectedAdapter(e -> {
        Button eb = (Button) e.widget;
        if (eb.getSelection()) {
            dropDefaultOperation = DND.DROP_MOVE;
            dropOperation |= DND.DROP_MOVE;
            moveButton.setSelection(true);
            if (dropEnabled) {
                createDropTarget();
            }
        }
    }));

    b = new Button(defaultParent, SWT.RADIO);
    b.setText("DND.DROP_COPY");
    b.addSelectionListener(widgetSelectedAdapter(e -> {
        Button eb = (Button) e.widget;
        if (eb.getSelection()) {
            dropDefaultOperation = DND.DROP_COPY;
            dropOperation |= DND.DROP_COPY;
            copyButton.setSelection(true);
            if (dropEnabled) {
                createDropTarget();
            }
        }
    }));

    b = new Button(defaultParent, SWT.RADIO);
    b.setText("DND.DROP_LINK");
    b.addSelectionListener(widgetSelectedAdapter(e -> {
        Button eb = (Button) e.widget;
        if (eb.getSelection()) {
            dropDefaultOperation = DND.DROP_LINK;
            dropOperation |= DND.DROP_LINK;
            linkButton.setSelection(true);
            if (dropEnabled) {
                createDropTarget();
            }
        }
    }));

    b = new Button(defaultParent, SWT.RADIO);
    b.setText("DND.DROP_NONE");
    b.setSelection(true);
    b.addSelectionListener(widgetSelectedAdapter(e -> {
        Button eb = (Button) e.widget;
        if (eb.getSelection()) {
            dropDefaultOperation = DND.DROP_NONE;
            dropOperation &= ~DND.DROP_DEFAULT;
            if (dropEnabled) {
                createDropTarget();
            }
        }
    }));

    // initialize state
    moveButton.setSelection(true);
    copyButton.setSelection(true);
    linkButton.setSelection(true);
    dropOperation = DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK;
}

From source file:ImageAnalyzer.java

int showBMPDialog() {
    final int[] bmpType = new int[1];
    bmpType[0] = SWT.IMAGE_BMP;//  www  .  j av a  2 s. com
    SelectionListener radioSelected = new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            Button radio = (Button) event.widget;
            if (radio.getSelection())
                bmpType[0] = ((Integer) radio.getData()).intValue();
        }
    };
    // need to externalize strings
    final Shell dialog = new Shell(shell, SWT.DIALOG_TRIM);

    dialog.setText("Save_as");
    dialog.setLayout(new GridLayout());

    Label label = new Label(dialog, SWT.NONE);
    label.setText("Save_as");

    Button radio = new Button(dialog, SWT.RADIO);
    radio.setText("Save_as_type_no_compress");
    radio.setSelection(true);
    radio.setData(new Integer(SWT.IMAGE_BMP));
    radio.addSelectionListener(radioSelected);

    radio = new Button(dialog, SWT.RADIO);
    radio.setText("Save_as_type_rle_compress");
    radio.setData(new Integer(SWT.IMAGE_BMP_RLE));
    radio.addSelectionListener(radioSelected);

    radio = new Button(dialog, SWT.RADIO);
    radio.setText("Save_as_type_os2");
    radio.setData(new Integer(SWT.IMAGE_OS2_BMP));
    radio.addSelectionListener(radioSelected);

    label = new Label(dialog, SWT.SEPARATOR | SWT.HORIZONTAL);
    label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    Button ok = new Button(dialog, SWT.PUSH);
    ok.setText("OK");
    GridData data = new GridData();
    data.horizontalAlignment = SWT.CENTER;
    data.widthHint = 75;
    ok.setLayoutData(data);
    ok.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            dialog.close();
        }
    });

    dialog.pack();
    dialog.open();
    while (!dialog.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    return bmpType[0];
}

From source file:org.eclipse.swt.examples.imageanalyzer.ImageAnalyzer.java

int showBMPDialog() {
    final int[] bmpType = new int[1];
    bmpType[0] = SWT.IMAGE_BMP;/*from w  ww.j  a  v  a 2  s  . c  o m*/
    SelectionListener radioSelected = widgetSelectedAdapter(event -> {
        Button radio = (Button) event.widget;
        if (radio.getSelection())
            bmpType[0] = ((Integer) radio.getData()).intValue();
    });
    // need to externalize strings
    final Shell dialog = new Shell(shell, SWT.DIALOG_TRIM);

    dialog.setText(bundle.getString("Save_as_type"));
    dialog.setLayout(new GridLayout());

    Label label = new Label(dialog, SWT.NONE);
    label.setText(bundle.getString("Save_as_type_label"));

    Button radio = new Button(dialog, SWT.RADIO);
    radio.setText(bundle.getString("Save_as_type_no_compress"));
    radio.setSelection(true);
    radio.setData(Integer.valueOf(SWT.IMAGE_BMP));
    radio.addSelectionListener(radioSelected);

    radio = new Button(dialog, SWT.RADIO);
    radio.setText(bundle.getString("Save_as_type_rle_compress"));
    radio.setData(Integer.valueOf(SWT.IMAGE_BMP_RLE));
    radio.addSelectionListener(radioSelected);

    radio = new Button(dialog, SWT.RADIO);
    radio.setText(bundle.getString("Save_as_type_os2"));
    radio.setData(Integer.valueOf(SWT.IMAGE_OS2_BMP));
    radio.addSelectionListener(radioSelected);

    label = new Label(dialog, SWT.SEPARATOR | SWT.HORIZONTAL);
    label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    Button ok = new Button(dialog, SWT.PUSH);
    ok.setText(bundle.getString("OK"));
    GridData data = new GridData();
    data.horizontalAlignment = SWT.CENTER;
    data.widthHint = 75;
    ok.setLayoutData(data);
    ok.addSelectionListener(widgetSelectedAdapter(e -> dialog.close()));

    dialog.pack();
    dialog.open();
    while (!dialog.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    return bmpType[0];
}

From source file:org.eclipse.swt.examples.dnd.DNDExample.java

private void createDropTypes(Composite parent) {
    parent.setLayout(new RowLayout(SWT.VERTICAL));
    Button textButton = new Button(parent, SWT.CHECK);
    textButton.setText("Text Transfer");
    textButton.addSelectionListener(widgetSelectedAdapter(e -> {
        Button b = (Button) e.widget;
        if (b.getSelection()) {
            addDropTransfer(TextTransfer.getInstance());
        } else {// w w  w .jav a  2  s. c  o  m
            removeDropTransfer(TextTransfer.getInstance());
        }
    }));

    Button b = new Button(parent, SWT.CHECK);
    b.setText("RTF Transfer");
    b.addSelectionListener(widgetSelectedAdapter(e -> {
        Button eb = (Button) e.widget;
        if (eb.getSelection()) {
            addDropTransfer(RTFTransfer.getInstance());
        } else {
            removeDropTransfer(RTFTransfer.getInstance());
        }
    }));

    b = new Button(parent, SWT.CHECK);
    b.setText("HTML Transfer");
    b.addSelectionListener(widgetSelectedAdapter(e -> {
        Button eb = (Button) e.widget;
        if (eb.getSelection()) {
            addDropTransfer(HTMLTransfer.getInstance());
        } else {
            removeDropTransfer(HTMLTransfer.getInstance());
        }
    }));

    b = new Button(parent, SWT.CHECK);
    b.setText("URL Transfer");
    b.addSelectionListener(widgetSelectedAdapter(e -> {
        Button eb = (Button) e.widget;
        if (eb.getSelection()) {
            addDropTransfer(URLTransfer.getInstance());
        } else {
            removeDropTransfer(URLTransfer.getInstance());
        }
    }));

    b = new Button(parent, SWT.CHECK);
    b.setText("File Transfer");
    b.addSelectionListener(widgetSelectedAdapter(e -> {
        Button eb = (Button) e.widget;
        if (eb.getSelection()) {
            addDropTransfer(FileTransfer.getInstance());
        } else {
            removeDropTransfer(FileTransfer.getInstance());
        }
    }));

    // initialize state
    textButton.setSelection(true);
    addDropTransfer(TextTransfer.getInstance());
}

From source file:org.eclipse.swt.examples.dnd.DNDExample.java

private void createDragTypes(Composite parent) {
    parent.setLayout(new GridLayout());
    Button textButton = new Button(parent, SWT.CHECK);
    textButton.setText("Text Transfer");
    textButton.addSelectionListener(widgetSelectedAdapter(e -> {
        Button b = (Button) e.widget;
        if (b.getSelection()) {
            addDragTransfer(TextTransfer.getInstance());
        } else {/*from  ww  w .  jav a 2s .  c o  m*/
            removeDragTransfer(TextTransfer.getInstance());
        }
    }));

    Button b = new Button(parent, SWT.CHECK);
    b.setText("RTF Transfer");
    b.addSelectionListener(widgetSelectedAdapter(e -> {
        Button b1 = (Button) e.widget;
        if (b1.getSelection()) {
            addDragTransfer(RTFTransfer.getInstance());
        } else {
            removeDragTransfer(RTFTransfer.getInstance());
        }
    }));

    b = new Button(parent, SWT.CHECK);
    b.setText("HTML Transfer");
    b.addSelectionListener(widgetSelectedAdapter(e -> {
        Button b2 = (Button) e.widget;
        if (b2.getSelection()) {
            addDragTransfer(HTMLTransfer.getInstance());
        } else {
            removeDragTransfer(HTMLTransfer.getInstance());
        }
    }));

    b = new Button(parent, SWT.CHECK);
    b.setText("URL Transfer");
    b.addSelectionListener(widgetSelectedAdapter(e -> {
        Button b3 = (Button) e.widget;
        if (b3.getSelection()) {
            addDragTransfer(URLTransfer.getInstance());
        } else {
            removeDragTransfer(URLTransfer.getInstance());
        }
    }));

    b = new Button(parent, SWT.CHECK);
    b.setText("File Transfer");
    b.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
    b.addSelectionListener(widgetSelectedAdapter(e -> {
        Button b4 = (Button) e.widget;
        if (b4.getSelection()) {
            addDragTransfer(FileTransfer.getInstance());
        } else {
            removeDragTransfer(FileTransfer.getInstance());
        }
    }));
    b = new Button(parent, SWT.PUSH);
    b.setText("Select File(s)");
    b.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
    b.addSelectionListener(widgetSelectedAdapter(e -> {
        FileDialog dialog = new FileDialog(fileList.getShell(), SWT.OPEN | SWT.MULTI);
        String result = dialog.open();
        if (result != null && result.length() > 0) {
            fileList.removeAll();
            String path = dialog.getFilterPath();
            String[] names = dialog.getFileNames();
            for (String name : names) {
                fileList.add(path + File.separatorChar + name);
            }
        }
    }));
    fileList = new List(parent, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    GridData data = new GridData();
    data.grabExcessHorizontalSpace = true;
    data.horizontalAlignment = GridData.FILL;
    data.verticalAlignment = GridData.BEGINNING;
    fileList.setLayoutData(data);

    // initialize state
    textButton.setSelection(true);
    addDragTransfer(TextTransfer.getInstance());
}