Skip to content

Commit

Permalink
Close view using bot | create buttons and add them
Browse files Browse the repository at this point in the history
  • Loading branch information
JKutscha committed Aug 2, 2021
1 parent ca75d8f commit d3ee974
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,35 +46,32 @@ public synchronized void createPartControl(Composite parent) {
browser = new Browser(parent, SWT.NONE);
resetBrowser();
browser.addProgressListener(new PitUiUpdatePublisher(browser));
IActionBars actionBars = getViewSite().getActionBars();
IToolBarManager toolBar = actionBars.getToolBarManager();
// create back button
final Action backButtonAction = new Action(BACK_BUTTON_TEXT) {
toolBar.add(new Action(BACK_BUTTON_TEXT) {
@Override
public void run() {
browser.back();
}
};
});
// create home button for navigation
final Action homeButtonAction = new Action(HOME_BUTTON_TEXT) {
toolBar.add(new Action(HOME_BUTTON_TEXT) {
@Override
public void run() {
if (homeUrlString != null) {
// only set url, if an home is set otherwise NPE
browser.setUrl(homeUrlString);
}
}
};
});
// create forward button
final Action forwardButtonAction = new Action(FORWARD_BUTTON_TEXT) {
toolBar.add(new Action(FORWARD_BUTTON_TEXT) {
@Override
public void run() {
browser.forward();
}
};
IActionBars actionBars = getViewSite().getActionBars();
IToolBarManager toolBar = actionBars.getToolBarManager();
toolBar.add(backButtonAction);
toolBar.add(homeButtonAction);
toolBar.add(forwardButtonAction);
});
actionBars.updateActionBars();
} catch (SWTError e) {

This comment has been minimized.

Copy link
@LorenzoBettini

LorenzoBettini Aug 3, 2021

Collaborator

If you merge with master (maybe you'll get a conflict), you'll see that the error handling is now delegated to org.pitest.pitclipse.ui.utils.PitclipseUiUtils

MessageBox messageBox = new MessageBox(parent.getShell(), SWT.ICON_ERROR | SWT.OK);
Expand All @@ -96,7 +93,7 @@ private void resetBrowser() {

@Override
public void setFocus() {
if (browser != null && !browser.isDisposed()) {
if (!browser.isDisposed()) {

This comment has been minimized.

Copy link
@LorenzoBettini

LorenzoBettini Aug 3, 2021

Collaborator

If you merge with master (maybe you'll get a conflict), you can see that it is now implemented in terms of the new org.pitest.pitclipse.ui.utils.PitclipseUiUtils.setFocusSafely(Composite)

browser.setFocus();
}
}
Expand All @@ -110,12 +107,4 @@ public synchronized void update(File result) {
browser.setUrl(homeUrlString);
}
}

@Override
public void dispose() {

This comment has been minimized.

Copy link
@LorenzoBettini

LorenzoBettini Aug 3, 2021

Collaborator

So we don't need to dispose the browser?

if (browser != null && !browser.isDisposed()) {
browser.dispose();
}
super.dispose();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
import org.eclipse.ui.IViewReference;
import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.WorkbenchException;
import org.eclipse.ui.intro.IIntroManager;
Expand Down Expand Up @@ -147,18 +147,17 @@ public static void openViewById(String viewId) throws InterruptedException {
});
}

public static void closeViewById(String viewId) throws InterruptedException {
Display.getDefault().syncExec(() -> {
IWorkbench workbench = PlatformUI.getWorkbench();
final IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
for (IViewReference view : page.getViewReferences()) {
if (view.getId().equals(viewId)) {
page.hideView(view);
return;
}
}
throw new RuntimeException("View with the id: '" + viewId + "' was not found and could not be closed.");
});
public static void closeViewById(String viewId) {
final long previousTimeout = SWTBotPreferences.TIMEOUT;
try {
// set timeout short, because if the view is not present we don't wait long
SWTBotPreferences.TIMEOUT = 100;
bot.viewById(viewId).close();
} catch (WidgetNotFoundException e) {
// expected, if the view was not present
} finally {
SWTBotPreferences.TIMEOUT = previousTimeout;
}
}

protected static IProject importTestProject(String projectName) throws CoreException {
Expand Down

0 comments on commit d3ee974

Please sign in to comment.