| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| SWTBotPerspective |
|
| 1.3333333333333333;1.333 | ||||
| SWTBotPerspective$1 |
|
| 1.3333333333333333;1.333 |
| 1 | 2 | /******************************************************************************* |
| 2 | * Copyright (c) 2009 SWTBot Committers and others | |
| 3 | * All rights reserved. This program and the accompanying materials | |
| 4 | * are made available under the terms of the Eclipse Public License v1.0 | |
| 5 | * which accompanies this distribution, and is available at | |
| 6 | * http://www.eclipse.org/legal/epl-v10.html | |
| 7 | * | |
| 8 | * Contributors: | |
| 9 | * Ralf Ebert www.ralfebert.de - (bug 271630) SWTBot Improved RCP / Workbench support | |
| 10 | *******************************************************************************/ | |
| 11 | package org.eclipse.swtbot.eclipse.finder.widgets; | |
| 12 | ||
| 13 | import org.eclipse.core.runtime.Assert; | |
| 14 | import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; | |
| 15 | import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException; | |
| 16 | import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable; | |
| 17 | import org.eclipse.swtbot.swt.finder.results.VoidResult; | |
| 18 | import org.eclipse.ui.IPerspectiveDescriptor; | |
| 19 | import org.eclipse.ui.IWorkbench; | |
| 20 | import org.eclipse.ui.PlatformUI; | |
| 21 | ||
| 22 | /** | |
| 23 | * This represents an eclipse workbench perspective. | |
| 24 | * | |
| 25 | * @author Ralf Ebert www.ralfebert.de (bug 271630) | |
| 26 | */ | |
| 27 | public class SWTBotPerspective { | |
| 28 | ||
| 29 | private final SWTWorkbenchBot bot; | |
| 30 | 2 | private final IPerspectiveDescriptor perspectiveDescriptor; |
| 31 | ||
| 32 | /** | |
| 33 | * Constructs an instance of the given object. | |
| 34 | * | |
| 35 | * @param perspectiveDescriptor the perspective descriptor. | |
| 36 | * @param bot the instance of {@link SWTWorkbenchBot} which will be used to drive operations on behalf of this | |
| 37 | * object. | |
| 38 | * @throws WidgetNotFoundException if the widget is <code>null</code> or widget has been disposed. | |
| 39 | * @since 2.0 | |
| 40 | */ | |
| 41 | 4 | public SWTBotPerspective(IPerspectiveDescriptor perspectiveDescriptor, SWTWorkbenchBot bot) throws WidgetNotFoundException { |
| 42 | 4 | this.bot = bot; |
| 43 | 4 | Assert.isNotNull(perspectiveDescriptor, "The perspective descriptor cannot be null"); //$NON-NLS-1$ |
| 44 | 4 | this.perspectiveDescriptor = perspectiveDescriptor; |
| 45 | 4 | } |
| 46 | ||
| 47 | /** | |
| 48 | * Switches the active workbench page to this perspective. | |
| 49 | */ | |
| 50 | public void activate() { | |
| 51 | 2 | UIThreadRunnable.syncExec(new VoidResult() { |
| 52 | public void run() { | |
| 53 | try { | |
| 54 | 2 | IWorkbench workbench = PlatformUI.getWorkbench(); |
| 55 | 2 | workbench.showPerspective(perspectiveDescriptor.getId(), workbench.getActiveWorkbenchWindow()); |
| 56 | 0 | } catch (Exception e) { |
| 57 | // TODO: what's the correct exception for such an error? Own exception class? | |
| 58 | 0 | throw new WidgetNotFoundException(e.getMessage(), e); |
| 59 | } | |
| 60 | 2 | } |
| 61 | }); | |
| 62 | 2 | } |
| 63 | ||
| 64 | /** | |
| 65 | * @return true if this perspective is active in the active workbench page | |
| 66 | */ | |
| 67 | public boolean isActive() { | |
| 68 | 0 | return bot.activePerspective().perspectiveDescriptor.getId().equals(this.perspectiveDescriptor.getId()); |
| 69 | } | |
| 70 | ||
| 71 | /** | |
| 72 | * @return the perspective label | |
| 73 | */ | |
| 74 | public String getLabel() { | |
| 75 | 0 | return this.perspectiveDescriptor.getLabel(); |
| 76 | } | |
| 77 | ||
| 78 | public String toString() { | |
| 79 | 0 | return "SWTBotEclipsePerspective[id=\"" + perspectiveDescriptor.getLabel() + "\", label=\"" + perspectiveDescriptor.getLabel() |
| 80 | 0 | + "\"]"; |
| 81 | } | |
| 82 | ||
| 83 | } |