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

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

Introduction

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

Prototype

public void setEnabled(boolean enabled) 

Source Link

Document

Enables the receiver if the argument is true, and disables it otherwise.

Usage

From source file:org.eclipse.swt.snippets.Snippet363.java

public static void main(String[] args) {
    Display display = new Display();
    errorIcon = display.getSystemImage(SWT.ICON_ERROR);
    Shell shell = new Shell(display);
    shell.setText("Snippet 363");
    shell.setLayout(new GridLayout(2, false));
    shell.setText("LiveRegion Test");

    icon = new Label(shell, SWT.NONE);
    icon.setLayoutData(new GridData(32, 32));

    liveLabel = new Text(shell, SWT.READ_ONLY);
    GC gc = new GC(liveLabel);
    Point pt = gc.textExtent(errorMessage);
    GridData data = new GridData(SWT.FILL, SWT.CENTER, true, false);
    data.minimumWidth = (int) (pt.x + gc.getFontMetrics().getAverageCharacterWidth() * 2);
    gc.dispose();//from  ww  w  . j ava 2 s . c om
    liveLabel.setLayoutData(data);
    liveLabel.setText("");
    liveLabel.getAccessible().addAccessibleAttributeListener(new AccessibleAttributeAdapter() {
        @Override
        public void getAttributes(AccessibleAttributeEvent e) {
            e.attributes = new String[] { "container-live", "polite", "live", "polite", "container-live-role",
                    "status", };
        }
    });

    final Label textFieldLabel = new Label(shell, SWT.NONE);
    textFieldLabel.setText("Type a number:");
    textFieldLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));

    final Text textField = new Text(shell, SWT.SINGLE | SWT.BORDER);
    textField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));

    final Button okButton = new Button(shell, SWT.PUSH);
    okButton.setText("OK");
    okButton.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false, 2, 1));
    okButton.setEnabled(false);

    textField.addModifyListener(e -> {
        boolean isNumber = false;
        String textValue = textField.getText();
        try {
            Integer.parseInt(textValue);
            isNumber = true;
            setMessageText(false, "Thank-you");
        } catch (NumberFormatException ex) {
            if (textValue.isEmpty()) {
                setMessageText(false, "");
            } else {
                setMessageText(true, "Error: Number expected.");
            }
        }
        okButton.setEnabled(isNumber);
    });

    textField.setFocus();
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:org.eclipse.swt.snippets.Snippet326.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 326");
    shell.setLayout(new GridLayout());

    final Browser browser;
    try {/*from w  ww  . ja va  2  s. com*/
        browser = new Browser(shell, SWT.NONE);
    } catch (SWTError e) {
        System.out.println("Could not instantiate Browser: " + e.getMessage());
        display.dispose();
        return;
    }
    browser.setLayoutData(new GridData(400, 400));
    browser.setText(HTML);

    final Button button = new Button(shell, SWT.PUSH);
    button.setText("Invoke Browser.close()");
    button.addListener(SWT.Selection, event -> {
        boolean result = browser.close();
        System.out.println("was Browser disposed: " + result);
        if (result) {
            button.setEnabled(false);
        }
    });
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:MailDialog.java

/**
 * @see org.eclipse.jface.dialogs.Dialog#
 *      createButtonsForButtonBar(org.eclipse.swt.widgets.Composite) We
 *      replace the OK and Cancel buttons by our own creations We use the
 *      method createButton() (from Dialog), to create the new buttons
 *//*  ww w.  j  a  va2s . co  m*/
protected void createButtonsForButtonBar(Composite parent) {
    // Create Open button
    Button openButton = createButton(parent, OPEN, "Open", true);
    // Initially deactivate it
    openButton.setEnabled(false);
    // Add a SelectionListener
    openButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            // Retrieve selected entries from list
            itemsToOpen = list.getSelection();
            // Set return code
            setReturnCode(OPEN);
            // Close dialog
            close();
        }
    });
    // Create Delete button
    Button deleteButton = createButton(parent, DELETE, "Delete", false);
    deleteButton.setEnabled(false);
    // Add a SelectionListener
    deleteButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            // Get the indices of the selected entries
            int selectedItems[] = list.getSelectionIndices();
            // Remove all these entries
            list.remove(selectedItems);
            // Now re-validate the list because it has changed
            validate();
        }
    });
    // Create Cancel button
    Button cancelButton = createButton(parent, CANCEL, "Cancel", false);
    // Add a SelectionListener
    cancelButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            setReturnCode(CANCEL);
            close();
        }
    });
}

From source file:eu.stratosphere.addons.visualization.swt.SWTInstanceToolTip.java

public SWTInstanceToolTip(Shell parent, final SWTToolTipCommandReceiver commandReceiver,
        NetworkNode networkNode, int x, int y) {
    super(parent, x, y);

    this.networkNode = networkNode;

    final Color backgroundColor = getShell().getBackground();
    final Color foregroundColor = getShell().getForeground();

    boolean isProfilingEnabled = false;
    final InstanceVisualizationData instanceVisualizationData = (InstanceVisualizationData) networkNode
            .getAttachment();/* ww  w  .  j  a v  a2s .  c o m*/
    if (instanceVisualizationData != null) {
        isProfilingEnabled = instanceVisualizationData.isProfilingEnabledForJob();
    }

    int height;

    // Set the title
    setTitle(networkNode.getName());

    // Only create chart if profiling is enabled
    if (isProfilingEnabled) {
        this.cpuChart = createCPUChart(instanceVisualizationData, backgroundColor);
        this.cpuChart.setLayoutData(new GridData(GridData.FILL_BOTH));
        this.memoryChart = createMemoryChart(instanceVisualizationData, backgroundColor);
        this.memoryChart.setLayoutData(new GridData(GridData.FILL_BOTH));
        this.networkChart = createNetworkChart(instanceVisualizationData, backgroundColor);
        this.networkChart.setLayoutData(new GridData(GridData.FILL_BOTH));
        height = 460;
    } else {
        this.cpuChart = null;
        this.memoryChart = null;
        this.networkChart = null;
        height = 75;
    }

    // Available instance actions
    final Composite instanceActionComposite = new Composite(getShell(), SWT.NONE);
    instanceActionComposite.setLayout(new RowLayout(SWT.HORIZONTAL));
    instanceActionComposite.setBackground(backgroundColor);
    instanceActionComposite.setForeground(foregroundColor);

    final Button killInstanceButton = new Button(instanceActionComposite, SWT.PUSH);
    final String instanceName = this.networkNode.getName();
    killInstanceButton.setText("Kill instance...");
    killInstanceButton.setEnabled(this.networkNode.isLeafNode());
    killInstanceButton.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event arg0) {
            commandReceiver.killInstance(instanceName);
        }

    });

    getShell().setSize(WIDTH, height);

    finishInstantiation(x, y, WIDTH, false);
}

From source file:eu.stratosphere.addons.visualization.swt.SWTVertexToolTip.java

public SWTVertexToolTip(Shell parent, final SWTToolTipCommandReceiver commandReceiver,
        ManagementVertex managementVertex, int x, int y) {
    super(parent, x, y);

    this.managementVertex = managementVertex;

    final VertexVisualizationData vertexVisualizationData = (VertexVisualizationData) managementVertex
            .getAttachment();//from  w  w  w .  java2  s .c o m

    int height;

    final Color backgroundColor = getShell().getBackground();
    final Color foregroundColor = getShell().getForeground();

    // Set the title
    final String taskName = managementVertex.getName() + " (" + (managementVertex.getIndexInGroup() + 1)
            + " of " + managementVertex.getNumberOfVerticesInGroup() + ")";
    setTitle(taskName);

    // Only create chart if profiling is enabled
    if (vertexVisualizationData.isProfilingEnabledForJob()) {
        this.threadChart = createThreadChart(vertexVisualizationData, backgroundColor);
        this.threadChart.setLayoutData(new GridData(GridData.FILL_BOTH));
        height = 240; // should be 265 when cancel button is enabled
    } else {
        this.threadChart = null;
        height = 125;
    }

    final Composite tableComposite = new Composite(getShell(), SWT.NONE);
    tableComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    tableComposite.setBackground(backgroundColor);
    tableComposite.setForeground(foregroundColor);
    final GridLayout tableGridLayout = new GridLayout(3, false);
    tableGridLayout.marginHeight = 0;
    tableGridLayout.marginLeft = 0;
    tableComposite.setLayout(tableGridLayout);

    final GridData gridData1 = new GridData();
    gridData1.horizontalSpan = 2;
    gridData1.grabExcessHorizontalSpace = true;
    gridData1.widthHint = 200;

    final GridData gridData2 = new GridData();
    gridData2.grabExcessHorizontalSpace = true;

    // Instance type
    final Label instanceTypeTextLabel = new Label(tableComposite, SWT.NONE);
    instanceTypeTextLabel.setBackground(backgroundColor);
    instanceTypeTextLabel.setForeground(foregroundColor);
    instanceTypeTextLabel.setText("Instance type:");

    this.instanceTypeLabel = new Label(tableComposite, SWT.NONE);
    this.instanceTypeLabel.setBackground(backgroundColor);
    this.instanceTypeLabel.setForeground(foregroundColor);
    this.instanceTypeLabel.setText(this.managementVertex.getInstanceType());
    this.instanceTypeLabel.setLayoutData(gridData1);

    // Instance ID
    final Label instanceIDTextLabel = new Label(tableComposite, SWT.NONE);
    instanceIDTextLabel.setBackground(backgroundColor);
    instanceIDTextLabel.setForeground(foregroundColor);
    instanceIDTextLabel.setText("Instance ID:");

    this.instanceIDLabel = new Label(tableComposite, SWT.NONE);
    this.instanceIDLabel.setBackground(backgroundColor);
    this.instanceIDLabel.setForeground(foregroundColor);
    this.instanceIDLabel.setText(this.managementVertex.getInstanceName());
    this.instanceIDLabel.setLayoutData(gridData2);

    final Button switchToInstanceButton = new Button(tableComposite, SWT.PUSH);
    switchToInstanceButton.setText("Switch to instance...");
    switchToInstanceButton.setEnabled(vertexVisualizationData.isProfilingEnabledForJob());
    switchToInstanceButton.setVisible(false);

    /*
     * final String instanceName = this.managementVertex.getInstanceName();
     * switchToInstanceButton.addListener(SWT.Selection, new Listener() {
     * @Override
     * public void handleEvent(Event arg0) {
     * commandReceiver.switchToInstance(instanceName);
     * }
     * });
     */

    // Execution state
    final Label executionStateTextLabel = new Label(tableComposite, SWT.NONE);
    executionStateTextLabel.setBackground(backgroundColor);
    executionStateTextLabel.setForeground(foregroundColor);
    executionStateTextLabel.setText("Execution state:");

    this.executionStateLabel = new Label(tableComposite, SWT.NONE);
    this.executionStateLabel.setBackground(backgroundColor);
    this.executionStateLabel.setForeground(foregroundColor);
    this.executionStateLabel.setText(this.managementVertex.getExecutionState().toString());
    this.executionStateLabel.setLayoutData(gridData1);

    final ManagementGroupVertex groupVertex = this.managementVertex.getGroupVertex();
    final GroupVertexVisualizationData groupVertexVisualizationData = (GroupVertexVisualizationData) groupVertex
            .getAttachment();
    if (groupVertexVisualizationData.isCPUBottleneck()) {
        this.warningComposite = createWarningComposite(WARNINGTEXT, SWT.ICON_WARNING);
        height += ICONSIZE;
    } else {
        this.warningComposite = null;
    }

    // Available task actions
    final Composite taskActionComposite = new Composite(getShell(), SWT.NONE);
    taskActionComposite.setLayout(new RowLayout(SWT.HORIZONTAL));
    taskActionComposite.setBackground(backgroundColor);
    taskActionComposite.setForeground(foregroundColor);

    /*
     * final Button cancelTaskButton = new Button(taskActionComposite, SWT.PUSH);
     * final ManagementVertexID vertexID = this.managementVertex.getID();
     * cancelTaskButton.setText("Cancel task");
     * cancelTaskButton.setEnabled(this.managementVertex.getExecutionState() == ExecutionState.RUNNING);
     * cancelTaskButton.addListener(SWT.Selection, new Listener() {
     * @Override
     * public void handleEvent(Event arg0) {
     * commandReceiver.cancelTask(vertexID, taskName);
     * }
     * });
     */

    getShell().setSize(WIDTH, height);

    finishInstantiation(x, y, WIDTH, false);
}

From source file:eu.stratosphere.nephele.visualization.swt.SWTVertexToolTip.java

public SWTVertexToolTip(Shell parent, final SWTToolTipCommandReceiver commandReceiver,
        ManagementVertex managementVertex, int x, int y) {
    super(parent, x, y);

    this.managementVertex = managementVertex;

    final VertexVisualizationData vertexVisualizationData = (VertexVisualizationData) managementVertex
            .getAttachment();// w  ww  .j a  va 2 s .  co  m

    int height;

    final Color backgroundColor = getShell().getBackground();
    final Color foregroundColor = getShell().getForeground();

    // Set the title
    final String taskName = managementVertex.getName() + " (" + (managementVertex.getIndexInGroup() + 1)
            + " of " + managementVertex.getNumberOfVerticesInGroup() + ")";
    setTitle(taskName);

    // Only create chart if profiling is enabled
    if (vertexVisualizationData.isProfilingEnabledForJob()) {
        this.threadChart = createThreadChart(vertexVisualizationData, backgroundColor);
        this.threadChart.setLayoutData(new GridData(GridData.FILL_BOTH));
        height = 240; // should be 265 when cancel button is enabled
    } else {
        this.threadChart = null;
        height = 125;
    }

    final Composite tableComposite = new Composite(getShell(), SWT.NONE);
    tableComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    tableComposite.setBackground(backgroundColor);
    tableComposite.setForeground(foregroundColor);
    final GridLayout tableGridLayout = new GridLayout(3, false);
    tableGridLayout.marginHeight = 0;
    tableGridLayout.marginLeft = 0;
    tableComposite.setLayout(tableGridLayout);

    final GridData gridData1 = new GridData();
    gridData1.horizontalSpan = 2;
    gridData1.grabExcessHorizontalSpace = true;
    gridData1.widthHint = 200;

    final GridData gridData2 = new GridData();
    gridData2.grabExcessHorizontalSpace = true;

    // Instance type
    final Label instanceTypeTextLabel = new Label(tableComposite, SWT.NONE);
    instanceTypeTextLabel.setBackground(backgroundColor);
    instanceTypeTextLabel.setForeground(foregroundColor);
    instanceTypeTextLabel.setText("Instance type:");

    this.instanceTypeLabel = new Label(tableComposite, SWT.NONE);
    this.instanceTypeLabel.setBackground(backgroundColor);
    this.instanceTypeLabel.setForeground(foregroundColor);
    this.instanceTypeLabel.setText(this.managementVertex.getInstanceType());
    this.instanceTypeLabel.setLayoutData(gridData1);

    // Instance ID
    final Label instanceIDTextLabel = new Label(tableComposite, SWT.NONE);
    instanceIDTextLabel.setBackground(backgroundColor);
    instanceIDTextLabel.setForeground(foregroundColor);
    instanceIDTextLabel.setText("Instance ID:");

    this.instanceIDLabel = new Label(tableComposite, SWT.NONE);
    this.instanceIDLabel.setBackground(backgroundColor);
    this.instanceIDLabel.setForeground(foregroundColor);
    this.instanceIDLabel.setText(this.managementVertex.getInstanceName());
    this.instanceIDLabel.setLayoutData(gridData2);

    final Button switchToInstanceButton = new Button(tableComposite, SWT.PUSH);
    switchToInstanceButton.setText("Switch to instance...");
    switchToInstanceButton.setEnabled(vertexVisualizationData.isProfilingEnabledForJob());
    switchToInstanceButton.setVisible(false);

    /*
     * final String instanceName = this.managementVertex.getInstanceName();
     * switchToInstanceButton.addListener(SWT.Selection, new Listener() {
     * @Override
     * public void handleEvent(Event arg0) {
     * commandReceiver.switchToInstance(instanceName);
     * }
     * });
     */

    // Execution state
    final Label executionStateTextLabel = new Label(tableComposite, SWT.NONE);
    executionStateTextLabel.setBackground(backgroundColor);
    executionStateTextLabel.setForeground(foregroundColor);
    executionStateTextLabel.setText("Execution state:");

    this.executionStateLabel = new Label(tableComposite, SWT.NONE);
    this.executionStateLabel.setBackground(backgroundColor);
    this.executionStateLabel.setForeground(foregroundColor);
    this.executionStateLabel.setText(this.managementVertex.getExecutionState().toString());
    this.executionStateLabel.setLayoutData(gridData1);

    // Checkpoint state
    final Label checkpointStateTextLabel = new Label(tableComposite, SWT.NONE);
    checkpointStateTextLabel.setBackground(backgroundColor);
    checkpointStateTextLabel.setForeground(foregroundColor);
    checkpointStateTextLabel.setText("Checkpoint state:");

    this.checkpointStateLabel = new Label(tableComposite, SWT.NONE);
    this.checkpointStateLabel.setBackground(backgroundColor);
    this.checkpointStateLabel.setForeground(foregroundColor);
    this.checkpointStateLabel.setText(this.managementVertex.getCheckpointState().toString());
    this.checkpointStateLabel.setLayoutData(gridData1);

    final ManagementGroupVertex groupVertex = this.managementVertex.getGroupVertex();
    final GroupVertexVisualizationData groupVertexVisualizationData = (GroupVertexVisualizationData) groupVertex
            .getAttachment();
    if (groupVertexVisualizationData.isCPUBottleneck()) {
        this.warningComposite = createWarningComposite(WARNINGTEXT, SWT.ICON_WARNING);
        height += ICONSIZE;
    } else {
        this.warningComposite = null;
    }

    // Available task actions
    final Composite taskActionComposite = new Composite(getShell(), SWT.NONE);
    taskActionComposite.setLayout(new RowLayout(SWT.HORIZONTAL));
    taskActionComposite.setBackground(backgroundColor);
    taskActionComposite.setForeground(foregroundColor);

    /*
     * final Button cancelTaskButton = new Button(taskActionComposite, SWT.PUSH);
     * final ManagementVertexID vertexID = this.managementVertex.getID();
     * cancelTaskButton.setText("Cancel task");
     * cancelTaskButton.setEnabled(this.managementVertex.getExecutionState() == ExecutionState.RUNNING);
     * cancelTaskButton.addListener(SWT.Selection, new Listener() {
     * @Override
     * public void handleEvent(Event arg0) {
     * commandReceiver.cancelTask(vertexID, taskName);
     * }
     * });
     */

    getShell().setSize(WIDTH, height);

    finishInstantiation(x, y, WIDTH, false);
}

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

/**
 * Creates and opens the "Listener selection" dialog.
 *//*from  ww w  .j  a v a  2 s .  c  o m*/
void createListenerSelectionDialog() {
    final Shell dialog = new Shell(shell, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.APPLICATION_MODAL);
    dialog.setText(ControlExample.getResourceString("Select_Listeners"));
    dialog.setLayout(new GridLayout(2, false));
    final Table table = new Table(dialog, SWT.BORDER | SWT.V_SCROLL | SWT.CHECK);
    GridData data = new GridData(GridData.FILL_BOTH);
    data.verticalSpan = 3;
    table.setLayoutData(data);
    for (int i = 0; i < EVENT_INFO.length; i++) {
        TableItem item = new TableItem(table, SWT.NONE);
        item.setText(EVENT_INFO[i].name);
        item.setChecked(eventsFilter[i]);
    }
    final String[] customNames = getCustomEventNames();
    for (int i = 0; i < customNames.length; i++) {
        TableItem item = new TableItem(table, SWT.NONE);
        item.setText(customNames[i]);
        item.setChecked(eventsFilter[EVENT_INFO.length + i]);
    }
    Button selectAll = new Button(dialog, SWT.PUSH);
    selectAll.setText(ControlExample.getResourceString("Select_All"));
    selectAll.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
    selectAll.addSelectionListener(widgetSelectedAdapter(e -> {
        TableItem[] items = table.getItems();
        for (int i = 0; i < EVENT_INFO.length; i++) {
            items[i].setChecked(true);
        }
        for (int i = 0; i < customNames.length; i++) {
            items[EVENT_INFO.length + i].setChecked(true);
        }
    }));
    Button deselectAll = new Button(dialog, SWT.PUSH);
    deselectAll.setText(ControlExample.getResourceString("Deselect_All"));
    deselectAll.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
    deselectAll.addSelectionListener(widgetSelectedAdapter(e -> {
        TableItem[] items = table.getItems();
        for (int i = 0; i < EVENT_INFO.length; i++) {
            items[i].setChecked(false);
        }
        for (int i = 0; i < customNames.length; i++) {
            items[EVENT_INFO.length + i].setChecked(false);
        }
    }));
    final Button editEvent = new Button(dialog, SWT.PUSH);
    editEvent.setText(ControlExample.getResourceString("Edit_Event"));
    editEvent.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING));
    editEvent.addSelectionListener(widgetSelectedAdapter(e -> {
        Point pt = editEvent.getLocation();
        pt = e.display.map(editEvent, null, pt);
        int index = table.getSelectionIndex();
        if (getExampleWidgets().length > 0 && index != -1) {
            createEditEventDialog(dialog, pt.x, pt.y, index);
        }
    }));
    editEvent.setEnabled(false);
    table.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            int fields = 0;
            int index = table.getSelectionIndex();
            if (index != -1 && index < EVENT_INFO.length) { // TODO: Allow custom widgets to specify event info
                fields = (EVENT_INFO[index].settableFields);
            }
            editEvent.setEnabled(fields != 0);
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            if (editEvent.getEnabled()) {
                Point pt = editEvent.getLocation();
                pt = e.display.map(editEvent, null, pt);
                int index = table.getSelectionIndex();
                if (getExampleWidgets().length > 0 && index != -1 && index < EVENT_INFO.length) {
                    createEditEventDialog(dialog, pt.x, pt.y, index);
                }
            }
        }
    });

    new Label(dialog, SWT.NONE); /* Filler */
    Button ok = new Button(dialog, SWT.PUSH);
    ok.setText(ControlExample.getResourceString("OK"));
    dialog.setDefaultButton(ok);
    ok.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
    ok.addSelectionListener(widgetSelectedAdapter(e -> {
        TableItem[] items = table.getItems();
        for (int i = 0; i < EVENT_INFO.length; i++) {
            eventsFilter[i] = items[i].getChecked();
        }
        for (int i = 0; i < customNames.length; i++) {
            eventsFilter[EVENT_INFO.length + i] = items[EVENT_INFO.length + i].getChecked();
        }
        dialog.dispose();
    }));
    dialog.pack();
    /*
     * If the preferred size of the dialog is too tall for the display,
     * then reduce the height, so that the vertical scrollbar will appear.
     */
    Rectangle bounds = dialog.getBounds();
    Rectangle trim = dialog.computeTrim(0, 0, 0, 0);
    Rectangle clientArea = display.getClientArea();
    if (bounds.height > clientArea.height) {
        dialog.setSize(bounds.width, clientArea.height - trim.height);
    }
    dialog.setLocation(bounds.x, clientArea.y);
    dialog.open();
    while (!dialog.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
}