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

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

Introduction

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

Prototype

public boolean getSelection() 

Source Link

Document

Returns true if the receiver is selected, and false otherwise.

Usage

From source file:org.locationtech.udig.processingtoolbox.tools.HistogramDialog.java

private void createInputTab(final CTabFolder parentTabFolder) {
    inputTab = new CTabItem(parentTabFolder, SWT.NONE);
    inputTab.setText(Messages.ProcessExecutionDialog_tabparameters);

    ScrolledComposite scroller = new ScrolledComposite(parentTabFolder, SWT.NONE | SWT.V_SCROLL | SWT.H_SCROLL);
    scroller.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    Composite container = new Composite(scroller, SWT.NONE);
    container.setLayout(new GridLayout(2, false));
    container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    // local moran's i
    Image image = ToolboxPlugin.getImageDescriptor("icons/public_co.gif").createImage(); //$NON-NLS-1$
    uiBuilder.createLabel(container, Messages.HistogramDialog_InputLayer, EMPTY, image, 2);
    cboLayer = uiBuilder.createCombo(container, 2, true);
    fillLayers(map, cboLayer, VectorLayerType.ALL);

    uiBuilder.createLabel(container, Messages.HistogramDialog_InputField, EMPTY, image, 2);
    cboField = uiBuilder.createCombo(container, 2, true);

    uiBuilder.createLabel(container, Messages.HistogramDialog_BinCount, EMPTY, image, 2);
    spinner = uiBuilder.createSpinner(container, 10, 1, 50, 0, 1, 5, 2);

    // yXais Type
    uiBuilder.createLabel(container, Messages.HistogramDialog_YAxisType, EMPTY, image, 1);
    GridLayout layout = new GridLayout(2, false);
    layout.marginWidth = 0;/*from   w  ww.  j  a  v  a  2s. com*/

    Composite subCon = new Composite(container, SWT.NONE);
    subCon.setLayout(layout);
    subCon.setLayoutData(new GridData(SWT.LEFT_TO_RIGHT, SWT.CENTER, false, false, 1, 1));
    final Button chkRatio = uiBuilder.createRadioButton(subCon, Messages.HistogramDialog_Ratio, null, 1);
    final Button chkFrequency = uiBuilder.createRadioButton(subCon, Messages.HistogramDialog_Frequency, null,
            1);
    chkFrequency.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent event) {
            if (chkFrequency.getSelection()) {
                histogramType = HistogramType.FREQUENCY;
            }
        }
    });
    chkRatio.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent event) {
            if (chkRatio.getSelection()) {
                histogramType = HistogramType.RELATIVE_FREQUENCY;
            }
        }
    });
    chkRatio.setSelection(true);

    uiBuilder.createLabel(container, null, null, 2);
    chkStatistics = uiBuilder.createCheckbox(container, Messages.ScatterPlotDialog_BasicStatistics, null, 2);

    // register events
    cboLayer.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(ModifyEvent e) {
            inputLayer = MapUtils.getLayer(map, cboLayer.getText());
            if (inputLayer != null) {
                fillFields(cboField, inputLayer.getSchema(), FieldType.Number);
            }
        }
    });

    // finally
    scroller.setContent(container);
    inputTab.setControl(scroller);

    scroller.setMinSize(450, container.getSize().y - 2);
    scroller.setExpandVertical(true);
    scroller.setExpandHorizontal(true);

    scroller.pack();
    container.pack();
}

From source file:BugTracker.java

public BugTracker() {
    GridLayout gridLayout = new GridLayout();
    shell.setLayout(gridLayout);//  ww  w .ja va2  s .  c  om
    shell.setText("Bug Tracking System");

    // Action.
    Action actionAddNew = new Action("New bug") {
        public void run() {
            // Append.
            TableItem item = new TableItem(table, SWT.NULL);
            item.setImage(bugIcon);
            table.select(table.getItemCount() - 1);
        }
    };

    Action actionDelete = new Action("Delete selected") {
        public void run() {
            int index = table.getSelectionIndex();
            if (index < 0) {
                System.out.println("Please select an item first. ");
                return;
            }
            MessageBox messageBox = new MessageBox(shell, SWT.YES | SWT.NO);
            messageBox.setText("Confirmation");
            messageBox.setMessage("Are you sure to remove the bug with id #" + table.getItem(index).getText(0));
            if (messageBox.open() == SWT.YES) {
                table.remove(index);
            }
        }
    };

    Action actionSave = new Action("Save") {
        public void run() {
            saveBugs();
        }
    };

    ToolBar toolBar = new ToolBar(shell, SWT.RIGHT | SWT.FLAT);

    ToolBarManager manager = new ToolBarManager(toolBar);
    manager.add(actionAddNew);
    manager.add(actionDelete);
    manager.add(new Separator());
    manager.add(actionSave);
    manager.update(true);

    table = new Table(shell, SWT.BORDER | SWT.FULL_SELECTION);
    table.setLayoutData(new GridData(GridData.FILL_BOTH));

    table.setLinesVisible(true);
    table.setHeaderVisible(true);

    TableColumn tcID = new TableColumn(table, SWT.LEFT);
    tcID.setText("ID");

    TableColumn tcSummary = new TableColumn(table, SWT.NULL);
    tcSummary.setText("Summary");

    TableColumn tcAssignedTo = new TableColumn(table, SWT.NULL);
    tcAssignedTo.setText("Assigned to");

    TableColumn tcSolved = new TableColumn(table, SWT.NULL);
    tcSolved.setText("Solved");

    tcID.setWidth(60);
    tcSummary.setWidth(200);
    tcAssignedTo.setWidth(80);
    tcSolved.setWidth(50);

    table.pack();

    // Table editor.
    final TableEditor editor = new TableEditor(table);

    table.addListener(SWT.MouseDown, new Listener() {
        public void handleEvent(Event event) {
            // Locate the cell position.
            Point point = new Point(event.x, event.y);
            final TableItem item = table.getItem(point);
            if (item == null)
                return;
            int column = -1;
            for (int i = 0; i < table.getColumnCount(); i++) {
                Rectangle rect = item.getBounds(i);
                if (rect.contains(point))
                    column = i;
            }
            if (column != 3)
                return;

            // Cell position located, now open the table editor.

            final Button button = new Button(table, SWT.CHECK);
            button.setSelection(item.getText(column).equalsIgnoreCase("YES"));

            editor.horizontalAlignment = SWT.LEFT;
            editor.grabHorizontal = true;

            editor.setEditor(button, item, column);

            final int selectedColumn = column;
            Listener buttonListener = new Listener() {
                public void handleEvent(final Event e) {
                    switch (e.type) {
                    case SWT.FocusOut:
                        item.setText(selectedColumn, button.getSelection() ? "YES" : "NO");
                        button.dispose();
                        break;
                    case SWT.Traverse:
                        switch (e.detail) {
                        case SWT.TRAVERSE_RETURN:
                            item.setText(selectedColumn, button.getSelection() ? "YES" : "NO");
                            //FALL THROUGH
                        case SWT.TRAVERSE_ESCAPE:
                            button.dispose();
                            e.doit = false;
                        }
                        break;
                    }
                }
            };

            button.addListener(SWT.FocusOut, buttonListener);
            button.addListener(SWT.Traverse, buttonListener);

            button.setFocus();

        }
    });

    table.addListener(SWT.MouseDown, new Listener() {
        public void handleEvent(Event event) {
            // Locate the cell position.
            Point point = new Point(event.x, event.y);
            final TableItem item = table.getItem(point);
            if (item == null)
                return;
            int column = -1;
            for (int i = 0; i < table.getColumnCount(); i++) {
                Rectangle rect = item.getBounds(i);
                if (rect.contains(point))
                    column = i;
            }
            if (column < 0 || column >= 3)
                return;

            // Cell position located, now open the table editor.

            final Text text = new Text(table, SWT.NONE);
            text.setText(item.getText(column));

            editor.horizontalAlignment = SWT.LEFT;
            editor.grabHorizontal = true;

            editor.setEditor(text, item, column);

            final int selectedColumn = column;
            Listener textListener = new Listener() {
                public void handleEvent(final Event e) {
                    switch (e.type) {
                    case SWT.FocusOut:
                        item.setText(selectedColumn, text.getText());
                        text.dispose();
                        break;
                    case SWT.Traverse:
                        switch (e.detail) {
                        case SWT.TRAVERSE_RETURN:
                            item.setText(selectedColumn, text.getText());
                            //FALL THROUGH
                        case SWT.TRAVERSE_ESCAPE:
                            text.dispose();
                            e.doit = false;
                        }
                        break;
                    }
                }
            };

            text.addListener(SWT.FocusOut, textListener);
            text.addListener(SWT.Traverse, textListener);

            text.setFocus();
        }

    });

    loadBugs();

    table.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {
            System.out.println("Selected: " + table.getSelection()[0]);
        }
    });

    Listener sortListener = new Listener() {
        public void handleEvent(Event event) {
            if (!(event.widget instanceof TableColumn))
                return;
            TableColumn tc = (TableColumn) event.widget;
            sortTable(table, table.indexOf(tc));
            System.out.println("The table is sorted by column #" + table.indexOf(tc));
        }
    };

    for (int i = 0; i < table.getColumnCount(); i++)
        ((TableColumn) table.getColumn(i)).addListener(SWT.Selection, sortListener);

    shell.pack();
    shell.open();
    //textUser.forceFocus();

    // Set up the event loop.
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            // If no more entries in event queue
            display.sleep();
        }
    }

    display.dispose();
}

From source file:org.eclipse.swt.examples.layoutexample.Tab.java

/**
 * Creates the "control" group. This is the group on the
 * right half of each example tab. It contains controls
 * for adding new children to the layoutComposite, and
 * for modifying the children's layout data.
 *///from ww w  . ja v a  2s.c o  m
void createControlGroup() {
    controlGroup = new Group(sash, SWT.NONE);
    controlGroup.setText(LayoutExample.getResourceString("Parameters"));
    GridLayout layout = new GridLayout(2, true);
    layout.horizontalSpacing = 10;
    controlGroup.setLayout(layout);
    final Button preferredButton = new Button(controlGroup, SWT.CHECK);
    preferredButton.setText(LayoutExample.getResourceString("Preferred_Size"));
    preferredButton.setSelection(false);
    preferredButton.addSelectionListener(widgetSelectedAdapter(e -> {
        resetEditors();
        GridData data = (GridData) layoutComposite.getLayoutData();
        if (preferredButton.getSelection()) {
            data.heightHint = data.widthHint = SWT.DEFAULT;
            data.verticalAlignment = data.horizontalAlignment = 0;
            data.grabExcessVerticalSpace = data.grabExcessHorizontalSpace = false;
        } else {
            data.verticalAlignment = data.horizontalAlignment = SWT.FILL;
            data.grabExcessVerticalSpace = data.grabExcessHorizontalSpace = true;
        }
        layoutComposite.setLayoutData(data);
        layoutGroup.layout(true);
    }));
    preferredButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
    createControlWidgets();
}

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);//from   w w w. j  a  v  a 2 s .  co  m
    dragOperation = DND.DROP_MOVE;
    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:org.eclipse.swt.examples.dnd.DNDExample.java

private void createFeedbackTypes(Group parent) {
    parent.setLayout(new RowLayout(SWT.VERTICAL));
    Button b = new Button(parent, SWT.CHECK);
    b.setText("FEEDBACK_SELECT");
    b.addSelectionListener(widgetSelectedAdapter(e -> {
        Button eb = (Button) e.widget;
        if (eb.getSelection()) {
            dropFeedback |= DND.FEEDBACK_SELECT;
        } else {// w w w .  j a va 2  s .  c  o m
            dropFeedback &= ~DND.FEEDBACK_SELECT;
        }
    }));

    b = new Button(parent, SWT.CHECK);
    b.setText("FEEDBACK_SCROLL");
    b.addSelectionListener(widgetSelectedAdapter(e -> {
        Button eb = (Button) e.widget;
        if (eb.getSelection()) {
            dropFeedback |= DND.FEEDBACK_SCROLL;
        } else {
            dropFeedback &= ~DND.FEEDBACK_SCROLL;
        }
    }));

    b = new Button(parent, SWT.CHECK);
    b.setText("FEEDBACK_INSERT_BEFORE");
    b.addSelectionListener(widgetSelectedAdapter(e -> {
        Button eb = (Button) e.widget;
        if (eb.getSelection()) {
            dropFeedback |= DND.FEEDBACK_INSERT_BEFORE;
        } else {
            dropFeedback &= ~DND.FEEDBACK_INSERT_BEFORE;
        }
    }));

    b = new Button(parent, SWT.CHECK);
    b.setText("FEEDBACK_INSERT_AFTER");
    b.addSelectionListener(widgetSelectedAdapter(e -> {
        Button eb = (Button) e.widget;
        if (eb.getSelection()) {
            dropFeedback |= DND.FEEDBACK_INSERT_AFTER;
        } else {
            dropFeedback &= ~DND.FEEDBACK_INSERT_AFTER;
        }
    }));

    b = new Button(parent, SWT.CHECK);
    b.setText("FEEDBACK_EXPAND");
    b.addSelectionListener(widgetSelectedAdapter(e -> {
        Button eb = (Button) e.widget;
        if (eb.getSelection()) {
            dropFeedback |= DND.FEEDBACK_EXPAND;
        } else {
            dropFeedback &= ~DND.FEEDBACK_EXPAND;
        }
    }));
}

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.j  ava 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 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  .j  a  v a  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 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);//from   w w  w.  j a  va 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 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 www  .java2 s . 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 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  www  .ja v  a 2  s.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());
}