diff --git a/plugins/org.eclipse.reddeer.jface/src/org/eclipse/reddeer/jface/dialogs/InputDialog.java b/plugins/org.eclipse.reddeer.jface/src/org/eclipse/reddeer/jface/dialogs/InputDialog.java new file mode 100644 index 0000000000..9c09bf3ee5 --- /dev/null +++ b/plugins/org.eclipse.reddeer.jface/src/org/eclipse/reddeer/jface/dialogs/InputDialog.java @@ -0,0 +1,84 @@ +/******************************************************************************* + * Copyright (c) 2020 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v2.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v20.html + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.eclipse.reddeer.jface.dialogs; + +import org.eclipse.reddeer.common.util.Display; +import org.eclipse.reddeer.swt.impl.button.CancelButton; +import org.eclipse.reddeer.swt.impl.button.OkButton; +import org.eclipse.reddeer.swt.impl.shell.DefaultShell; +import org.eclipse.reddeer.swt.impl.text.DefaultText; + +/** + * {@link org.eclipse.jface.dialogs.InputDialog} + * + * @author Radoslav Rabara, jkopriva@redhat.com + * + */ +public class InputDialog extends DefaultShell { + + /** + * Represents the InputDialog. + */ + public InputDialog() { + super(); + } + + /** + * Represents InputDialog with the specified title. + * + * @param title InputDialog title + */ + public InputDialog(String title) { + super(title); + } + + /** + * Click on the OK button. + */ + public void ok() { + new OkButton().click(); + } + + /** + * Click on the cancel button. + */ + public void cancel() { + new CancelButton().click(); + } + + /** + * Returns text from input text field. + * + * @return input text + */ + public String getInputText() { + return new DefaultText().getText(); + } + + /** + * Returns text from input text field. + * + * @return input text + */ + public String getTitleText() { + return Display.syncExec(() -> this.getText()); + } + + /** + * Sets the specified text into input text field. + * + * @param text text to be set + */ + public void setInputText(String text) { + new DefaultText().setText(text); + } + +} diff --git a/tests/org.eclipse.reddeer.jface.test/src/org/eclipse/reddeer/jface/test/dialogs/InputDialogTest.java b/tests/org.eclipse.reddeer.jface.test/src/org/eclipse/reddeer/jface/test/dialogs/InputDialogTest.java new file mode 100644 index 0000000000..f77a5ace4f --- /dev/null +++ b/tests/org.eclipse.reddeer.jface.test/src/org/eclipse/reddeer/jface/test/dialogs/InputDialogTest.java @@ -0,0 +1,93 @@ +/******************************************************************************* + * Copyright (c) 2020 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v2.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v20.html + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.eclipse.reddeer.jface.test.dialogs; + +import static org.junit.Assert.assertEquals; + +import org.eclipse.reddeer.common.util.Display; +import org.eclipse.reddeer.jface.dialogs.InputDialog; +import org.eclipse.reddeer.jface.test.dialogs.impl.TestingInputDialog; +import org.eclipse.swt.widgets.Shell; +import org.junit.After; +import org.junit.Test; + +/** + * + * @author jkopriva@redhat.com + * + */ +public class InputDialogTest { + + private static TestingInputDialog inputDialog; + private Shell s; + + @Test + public void inputDialogMessagesTest() { + openInputDialog(); + InputDialog dialog = new InputDialog(TestingInputDialog.TITLE); + assertEquals(TestingInputDialog.TITLE, dialog.getTitleText()); + assertEquals(TestingInputDialog.INITIAL_TEXT, dialog.getInputText()); + } + + @Test + public void inputDialogCancelTest() { + openInputDialog(); + InputDialog dialog = new InputDialog(TestingInputDialog.TITLE); + dialog.cancel(); + } + + @Test + public void inputDialogOkTest() { + openInputDialog(); + InputDialog dialog = new InputDialog(TestingInputDialog.TITLE); + dialog.ok(); + } + + @Test + public void inputDialogSetTextGetTextTest() { + openInputDialog(); + InputDialog dialog = new InputDialog(TestingInputDialog.TITLE); + dialog.setInputText("something"); + assertEquals("something", dialog.getInputText()); + dialog.cancel(); + } + + public void openInputDialog() { + Display.asyncExec(new Runnable() { + + @Override + public void run() { + inputDialog = new TestingInputDialog(); + inputDialog.create(); + inputDialog.open(); + + } + }); + + } + + @After + public void closeShell() { + Display.syncExec(new Runnable() { + + @Override + public void run() { + if (s != null) { + s.dispose(); + } + if (inputDialog != null) { + inputDialog.close(); + } + } + }); + } + +} diff --git a/tests/org.eclipse.reddeer.jface.test/src/org/eclipse/reddeer/jface/test/dialogs/TitleAreaDialogTest.java b/tests/org.eclipse.reddeer.jface.test/src/org/eclipse/reddeer/jface/test/dialogs/TitleAreaDialogTest.java index f3341b9be1..7d12b2ffc8 100644 --- a/tests/org.eclipse.reddeer.jface.test/src/org/eclipse/reddeer/jface/test/dialogs/TitleAreaDialogTest.java +++ b/tests/org.eclipse.reddeer.jface.test/src/org/eclipse/reddeer/jface/test/dialogs/TitleAreaDialogTest.java @@ -11,11 +11,11 @@ *******************************************************************************/ package org.eclipse.reddeer.jface.test.dialogs; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.resource.JFaceResources; -import org.eclipse.swt.widgets.Shell; import org.eclipse.reddeer.common.util.Display; import org.eclipse.reddeer.core.exception.CoreLayerException; import org.eclipse.reddeer.eclipse.selectionwizard.NewMenuWizard; @@ -25,6 +25,7 @@ import org.eclipse.reddeer.jface.test.dialogs.impl.TestingNewWizard; import org.eclipse.reddeer.jface.test.dialogs.impl.TestingTitleAreaDialog; import org.eclipse.reddeer.swt.impl.button.PushButton; +import org.eclipse.swt.widgets.Shell; import org.junit.After; import org.junit.Test; diff --git a/tests/org.eclipse.reddeer.jface.test/src/org/eclipse/reddeer/jface/test/dialogs/impl/TestingInputDialog.java b/tests/org.eclipse.reddeer.jface.test/src/org/eclipse/reddeer/jface/test/dialogs/impl/TestingInputDialog.java new file mode 100644 index 0000000000..90bee2a401 --- /dev/null +++ b/tests/org.eclipse.reddeer.jface.test/src/org/eclipse/reddeer/jface/test/dialogs/impl/TestingInputDialog.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2020 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v2.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v20.html + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.eclipse.reddeer.jface.test.dialogs.impl; + +import org.eclipse.jface.dialogs.InputDialog; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; + +/** + * + * @author jkopriva@redhat.com + * + */ +public class TestingInputDialog extends InputDialog { + + public static final String TEXT = "InputDialog info message"; + public static final String INITIAL_TEXT = "InputDialog initial text"; + public static final String TITLE = "InputDialog title"; + + public TestingInputDialog() { + super(null, TITLE, TEXT, INITIAL_TEXT, null); + } + + @Override + public void create() { + super.create(); + getShell().setText(TITLE); + } + + @Override + protected Control createDialogArea(Composite parent) { + Composite area = (Composite) super.createDialogArea(parent); + Composite container = new Composite(area, SWT.NONE); + container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + GridLayout layout = new GridLayout(2, false); + container.setLayout(layout); + + return area; + } + +}