| 1 | 6 | |
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
package org.eclipse.swtbot.eclipse.finder; |
| 12 | |
|
| 13 | |
import java.util.List; |
| 14 | |
|
| 15 | |
import org.eclipse.swt.widgets.Widget; |
| 16 | |
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor; |
| 17 | |
import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable; |
| 18 | |
import org.eclipse.swtbot.swt.finder.results.Result; |
| 19 | |
import org.eclipse.swtbot.swt.finder.results.VoidResult; |
| 20 | |
import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell; |
| 21 | |
import org.eclipse.ui.IPerspectiveDescriptor; |
| 22 | |
import org.eclipse.ui.IWorkbenchPage; |
| 23 | |
import org.eclipse.ui.IWorkbenchWindow; |
| 24 | |
import org.eclipse.ui.PlatformUI; |
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
class DefaultWorkbench { |
| 37 | |
|
| 38 | |
|
| 39 | |
private final SWTWorkbenchBot bot; |
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | 5 | DefaultWorkbench(SWTWorkbenchBot bot) { |
| 47 | 5 | this.bot = bot; |
| 48 | 5 | } |
| 49 | |
|
| 50 | |
DefaultWorkbench resetActivePerspective() { |
| 51 | 2 | UIThreadRunnable.syncExec(new VoidResult() { |
| 52 | |
public void run() { |
| 53 | 2 | activePage().resetPerspective(); |
| 54 | 2 | } |
| 55 | |
}); |
| 56 | 2 | return this; |
| 57 | |
} |
| 58 | |
|
| 59 | |
DefaultWorkbench resetWorkbench() { |
| 60 | 0 | return closeAllShells().saveAllEditors().closeAllEditors(); |
| 61 | |
} |
| 62 | |
|
| 63 | |
DefaultWorkbench closeAllShells() { |
| 64 | 1 | SWTBotShell[] shells = bot.shells(); |
| 65 | 2 | for (SWTBotShell shell : shells) { |
| 66 | 1 | if (!isEclipseShell(shell)) { |
| 67 | 0 | shell.close(); |
| 68 | |
} |
| 69 | |
} |
| 70 | 1 | return this; |
| 71 | |
} |
| 72 | |
|
| 73 | |
DefaultWorkbench saveAllEditors() { |
| 74 | 1 | List<? extends SWTBotEditor> editors = bot.editors(); |
| 75 | 2 | for (SWTBotEditor editor : editors) { |
| 76 | 0 | editor.save(); |
| 77 | |
} |
| 78 | 1 | return this; |
| 79 | |
} |
| 80 | |
|
| 81 | |
DefaultWorkbench closeAllEditors() { |
| 82 | 1 | List<? extends SWTBotEditor> editors = bot.editors(); |
| 83 | 2 | for (SWTBotEditor editor : editors) { |
| 84 | 0 | editor.close(); |
| 85 | |
} |
| 86 | 1 | return this; |
| 87 | |
} |
| 88 | |
|
| 89 | |
private boolean isEclipseShell(final SWTBotShell shell) { |
| 90 | 1 | return getActiveWorkbenchWindowShell() == shell.widget; |
| 91 | |
} |
| 92 | |
|
| 93 | |
private IWorkbenchWindow getActiveWorkbenchWindow() { |
| 94 | 3 | return UIThreadRunnable.syncExec(bot.getDisplay(), new Result<IWorkbenchWindow>() { |
| 95 | |
public IWorkbenchWindow run() { |
| 96 | 3 | return PlatformUI.getWorkbench().getActiveWorkbenchWindow(); |
| 97 | |
} |
| 98 | |
}); |
| 99 | |
} |
| 100 | |
|
| 101 | |
private Widget getActiveWorkbenchWindowShell() { |
| 102 | 1 | return getActiveWorkbenchWindow().getShell(); |
| 103 | |
} |
| 104 | |
|
| 105 | 2 | private IWorkbenchPage activePage() { |
| 106 | 2 | return getActiveWorkbenchWindow().getActivePage(); |
| 107 | |
} |
| 108 | |
|
| 109 | |
private IPerspectiveDescriptor[] perspectives() { |
| 110 | 0 | return PlatformUI.getWorkbench().getPerspectiveRegistry().getPerspectives(); |
| 111 | |
} |
| 112 | |
|
| 113 | |
} |