forked from eclipse-archived/reddeer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add InputDialog and tests for it (fixes eclipse-archived#2084)
Signed-off-by: Josef Kopriva <jkopriva@redhat.com>
- Loading branch information
Showing
4 changed files
with
232 additions
and
2 deletions.
There are no files selected for viewing
84 changes: 84 additions & 0 deletions
84
plugins/org.eclipse.reddeer.jface/src/org/eclipse/reddeer/jface/dialogs/InputDialog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <var>title</var>. | ||
* | ||
* @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 <var>text</var> into input text field. | ||
* | ||
* @param text text to be set | ||
*/ | ||
public void setInputText(String text) { | ||
new DefaultText().setText(text); | ||
} | ||
|
||
} |
93 changes: 93 additions & 0 deletions
93
...clipse.reddeer.jface.test/src/org/eclipse/reddeer/jface/test/dialogs/InputDialogTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...eddeer.jface.test/src/org/eclipse/reddeer/jface/test/dialogs/impl/TestingInputDialog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} |