001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.tests.internal.util;
011:
012: import org.eclipse.jface.dialogs.Dialog;
013: import org.eclipse.jface.dialogs.IDialogConstants;
014: import org.eclipse.jface.resource.JFaceResources;
015: import org.eclipse.swt.SWT;
016: import org.eclipse.swt.layout.GridData;
017: import org.eclipse.swt.widgets.Composite;
018: import org.eclipse.swt.widgets.Control;
019: import org.eclipse.swt.widgets.Label;
020: import org.eclipse.swt.widgets.Shell;
021: import org.eclipse.swt.widgets.Text;
022:
023: /*
024: * A dialog for collecting notes from the tester regarding
025: * the failure of a test.
026: */
027: public class FailureDialog extends Dialog {
028: private Text _text;
029:
030: private String _log;
031:
032: private int SIZING_TEXT_WIDTH = 400;
033:
034: private int SIZING_TEXT_HEIGHT = 200;
035:
036: /**
037: * Constructor for FailureDialog
038: */
039: public FailureDialog(Shell parentShell) {
040: super (parentShell);
041: }
042:
043: /* (non-Javadoc)
044: * Method declared on Window.
045: */
046: protected void configureShell(Shell newShell) {
047: super .configureShell(newShell);
048: newShell.setText("Dialog Test Failed");
049: }
050:
051: /* (non-Javadoc)
052: * Method declared on Dialog.
053: */
054: protected void createButtonsForButtonBar(Composite parent) {
055: createButton(parent, IDialogConstants.OK_ID, "&OK", true);
056: createButton(parent, IDialogConstants.CANCEL_ID,
057: IDialogConstants.CANCEL_LABEL, false);
058: }
059:
060: /* (non-Javadoc)
061: * Method declared on Dialog.
062: */
063: protected Control createDialogArea(Composite parent) {
064: // page group
065: Composite composite = (Composite) super
066: .createDialogArea(parent);
067: composite.setSize(composite.computeSize(SWT.DEFAULT,
068: SWT.DEFAULT));
069:
070: Label label = new Label(composite, SWT.WRAP);
071: label.setText("&Enter a note regarding the failure:");
072:
073: _text = new Text(composite, SWT.MULTI | SWT.BORDER
074: | SWT.H_SCROLL | SWT.V_SCROLL);
075: _text.setFont(JFaceResources.getFontRegistry().get(
076: JFaceResources.TEXT_FONT));
077: GridData data = new GridData(GridData.FILL_BOTH);
078: data.widthHint = SIZING_TEXT_WIDTH;
079: data.heightHint = SIZING_TEXT_HEIGHT;
080: _text.setLayoutData(data);
081:
082: return composite;
083: }
084:
085: /* (non-Javadoc)
086: * Method declared on Dialog.
087: */
088: protected void okPressed() {
089: _log = _text.getText();
090: super .okPressed();
091: }
092:
093: /*
094: * @return String the text contained in the input area of
095: * the dialog.
096: */
097: String getText() {
098: if (_log == null) {
099: return "Empty entry.";
100: } else {
101: return _log;
102: }
103: }
104:
105: /*
106: * Sets the text of the input area. This should only be
107: * called to set the initial text so only call before invoking
108: * open().
109: */
110: void setText(String text) {
111: _text.setText(text);
112: }
113:
114: /*
115: * Returns a string representation of this class which
116: * the text contained in the input area of the dialog.
117: */
118: public String toString() {
119: return getText();
120: }
121: }
|