Skip to content

Commit

Permalink
Add method 'activate' for activating an active wizard
Browse files Browse the repository at this point in the history
Signed-off-by: Lukáš Valach <lvalach@redhat.com>
  • Loading branch information
luvalach authored and rawagner committed Feb 26, 2018
1 parent fe1c1fe commit 728a24b
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 3 deletions.
Expand Up @@ -10,9 +10,10 @@
*******************************************************************************/
package org.eclipse.reddeer.jface.window;

import org.hamcrest.Matcher;
import org.eclipse.reddeer.common.logging.Logger;
import org.eclipse.reddeer.common.matcher.MatcherBuilder;
import org.eclipse.reddeer.common.wait.TimePeriod;
import org.eclipse.reddeer.common.wait.WaitUntil;
import org.eclipse.reddeer.core.handler.WidgetHandler;
import org.eclipse.reddeer.core.lookup.ShellLookup;
import org.eclipse.reddeer.core.matcher.WithTextMatcher;
Expand All @@ -23,6 +24,7 @@
import org.eclipse.reddeer.swt.api.Shell;
import org.eclipse.reddeer.swt.impl.shell.DefaultShell;
import org.eclipse.swt.widgets.Control;
import org.hamcrest.Matcher;
/**
* Represends JFace Window
*
Expand Down Expand Up @@ -78,6 +80,37 @@ public AbstractWindow(Matcher<?>...matchers) {
this.windowMatchers = matchers;
this.shell = new DefaultShell(ShellLookup.getInstance().getShell(allMatchers));
}

/**
* Finds shell matching given matchers and set it as the shell of this window.
* The matchers given as constructor parameters will be applied. If they are
* not set, the matchers from OpenAction will be used.
*/
public void activate() {
activate(TimePeriod.DEFAULT);
}

/**
* Finds shell matching given matchers and set it as the shell of this window.
* The matchers given as constructor parameters will be applied. If they are
* not set, the matchers from OpenAction will be used.
*
* @param timeout
* period to wait for
*/
public void activate(TimePeriod timeout) {
WindowIsAvailable cond;
if(getWindowMatchers() != null){
cond = new WindowIsAvailable(getEclipseClass(), getWindowMatchers());
} else if(getOpenAction() != null){
cond = new WindowIsAvailable(getEclipseClass(), getOpenAction().getShellMatchers());
} else {
throw new JFaceLayerException("Unable to activate window. No matcher was set.");
}

new WaitUntil(cond,timeout);
setShell(new DefaultShell(cond.getResult()));
}

/**
* Gets the control.
Expand Down Expand Up @@ -111,7 +144,7 @@ public boolean isOpen(){
return false;
}

WindowIsAvailable cond = null;
WindowIsAvailable cond;
if(getWindowMatchers() != null){
cond = new WindowIsAvailable(getEclipseClass(), getWindowMatchers());
} else if(getOpenAction() != null){
Expand Down
Expand Up @@ -11,7 +11,11 @@
package org.eclipse.reddeer.jface.test.dialogs;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.*;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

import org.eclipse.reddeer.eclipse.selectionwizard.NewMenuWizard;
import org.eclipse.reddeer.jface.test.dialogs.impl.TestingNewWizard;
Expand All @@ -34,6 +38,29 @@ public void open() {
String wizardDialogText = new DefaultShell().getText();
assertThat(wizardDialogText, is(TestingNewWizard.NAME));
}

@Test
public void useExistingWizard() {
newWizardDialog.open();
NewWizardDialogImpl secondNewWizardDialog = new NewWizardDialogImpl();
assertNotNull(secondNewWizardDialog.getShell());
String wizardDialogText = new DefaultShell().getText();
assertThat(wizardDialogText, is(TestingNewWizard.NAME));;
}

@Test
public void activate() {
newWizardDialog.open();
NewWizardDialogImpl secondNewWizardDialog = new NewWizardDialogImpl();
newWizardDialog.cancel();
newWizardDialog.open();
assertTrue(secondNewWizardDialog.getShell().isDisposed());
secondNewWizardDialog.activate();
assertNotNull(secondNewWizardDialog.getShell());
assertFalse(secondNewWizardDialog.getShell().isDisposed());
String wizardDialogText = new DefaultShell().getText();
assertThat(wizardDialogText, is(TestingNewWizard.NAME));;
}

@After
public void tearDown(){
Expand Down

0 comments on commit 728a24b

Please sign in to comment.