Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package my.e4test.swtbot;
- import java.util.List;
- import org.eclipse.e4.core.contexts.IEclipseContext;
- import org.eclipse.e4.ui.internal.workbench.E4Workbench;
- import org.eclipse.e4.ui.model.application.MApplication;
- import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective;
- import org.eclipse.e4.ui.model.application.ui.basic.MPart;
- import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
- import org.eclipse.e4.ui.workbench.modeling.EModelService;
- import org.eclipse.e4.ui.workbench.modeling.EPartService;
- import org.eclipse.swt.widgets.Display;
- import org.eclipse.swtbot.swt.finder.SWTBot;
- public class E4Bot extends SWTBot {
- private IEclipseContext serviceContext;
- @SuppressWarnings("restriction")
- public E4Bot() {
- serviceContext = E4Workbench.getServiceContext();
- }
- /** used to switch perspective */
- public void switchPerspective(final String perspectiveId) {
- Display.getDefault().asyncExec(new Runnable() {
- @Override
- public void run() {
- @SuppressWarnings("restriction")
- IEclipseContext serviceContext =
- E4Workbench.getServiceContext();
- IEclipseContext context = serviceContext.getActiveLeaf();
- // model and app needed
- EModelService modelService = context.get(EModelService.class);
- MApplication application = context.get(MApplication.class);
- // service to switch
- EPartService partService = context.get(EPartService.class);
- // get the element
- MPerspective element =
- (MPerspective) modelService.find(perspectiveId,
- application);
- // Now switch perspective
- partService.switchPerspective(element);
- }
- });
- }
- /** used to show view */
- public void showPart(final String partId) {
- Display.getDefault().asyncExec(new Runnable() {
- @Override
- public void run() {
- @SuppressWarnings("restriction")
- IEclipseContext serviceContext =
- E4Workbench.getServiceContext();
- IEclipseContext context = serviceContext.getActiveLeaf();
- // model and app needed
- EModelService modelService = context.get(EModelService.class);
- MApplication app = context.get(MApplication.class);
- MWindow window = (MWindow) app.getChildren().get(0);
- // service to switch
- EPartService partService = context.get(EPartService.class);
- // get the matching parts
- List<MPart> parts =
- modelService.findElements(window, partId, MPart.class,
- null, EModelService.OUTSIDE_PERSPECTIVE
- | EModelService.IN_ANY_PERSPECTIVE
- | EModelService.IN_SHARED_AREA);
- // activate and bring to top
- for (MPart part : parts) {
- partService.activate(part, true);
- partService.bringToTop(part);
- }
- }
- });
- }
- }
Add Comment
Please, Sign In to add comment