Java Code Examples for org.eclipse.ui.PlatformUI#getWorkbench()

The following examples show how to use org.eclipse.ui.PlatformUI#getWorkbench() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: YangSyntax.java    From yang-design-studio with Eclipse Public License 1.0 6 votes vote down vote up
public MessageConsoleStream getMessageStream() {
	MessageConsole myConsole = findConsole("Yang Console"); //calls function to find/create the Yang console
	if (myConsole != null) {

		IWorkbench wb = PlatformUI.getWorkbench();
		IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
		IWorkbenchPage page = win.getActivePage();
		String id = IConsoleConstants.ID_CONSOLE_VIEW;
		IConsoleView view;
		try {

			view = (IConsoleView) page.showView(id);
			view.display(myConsole);

			return myConsole.newMessageStream();
		} catch (PartInitException e) {
			e.printStackTrace();
		}
	}
	return null;
}
 
Example 2
Source File: BonitaPerspectivesUtils.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Switch to the perspective with id given as parameter
 * 
 * @param perspectiveID
 */
public static synchronized void switchToPerspective(final String perspectiveID) {
    final IWorkbench workbench = PlatformUI.getWorkbench();
    final IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
    if (window != null) {
        final IWorkbenchPage activePage = window.getActivePage();
        if (activePage != null) {
            final IPerspectiveDescriptor activePerspective = activePage.getPerspective();
            if (activePerspective == null || !activePerspective.getId().equals(perspectiveID)) {
                final IPerspectiveRegistry registry = workbench.getPerspectiveRegistry();
                final IWorkbenchPage page = window.getActivePage();
                final IPerspectiveDescriptor desc = registry.findPerspectiveWithId(perspectiveID);
                page.setPerspective(desc);
            }
        }
    }
}
 
Example 3
Source File: ViewUtils.java    From saros with GNU General Public License v2.0 6 votes vote down vote up
public static void openSarosView() {
  /*
   * TODO What to do if no WorkbenchWindows are are active?
   */
  final IWorkbench workbench = PlatformUI.getWorkbench();

  if (workbench == null) return;

  final IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();

  if (window == null) return;

  try {
    window.getActivePage().showView(SarosView.ID, null, IWorkbenchPage.VIEW_CREATE);
  } catch (PartInitException e) {
    log.error("could not open Saros view (id: " + SarosView.ID + ")", e); // $NON-NLS-1$
  }
}
 
Example 4
Source File: ASMDEditorUtils.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/** {@inheritDoc} */
public XtextEditor getActiveXtextEditor() {
  IWorkbench workbench = PlatformUI.getWorkbench();
  IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
  if (workbenchWindow == null) {
    return null;
  }
  IWorkbenchPage activePage = workbenchWindow.getActivePage();
  if (activePage == null) {
    return null;
  }
  IEditorPart activeEditor = activePage.getActiveEditor();
  if (activeEditor instanceof XtextEditor) {
    return (XtextEditor) activeEditor;
    // return null;
  }
  // XtextEditor xtextEditor = (XtextEditor) activeEditor.getAdapter(XtextEditor.class);
  // return xtextEditor;
  return null;
}
 
Example 5
Source File: SegmentTableTest.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Create the table viewer to test
 *
 * @return the table viewer bot
 */
protected AbstractSegmentStoreTableView openTable() {
    AbstractSegmentStoreTableView tableView = getTableView();
    if (tableView != null) {
        return tableView;
    }
    IViewPart vp = null;
    final IWorkbench workbench = PlatformUI.getWorkbench();
    vp = UIThreadRunnable.syncExec((Result<IViewPart>) () -> {
        try {
            return workbench.getActiveWorkbenchWindow().getActivePage().showView(TestSegmentStoreTableView.ID);
        } catch (PartInitException e) {
            return null;
        }
    });
    assertNotNull(vp);
    assertTrue(vp instanceof TestSegmentStoreTableView);
    TestSegmentStoreTableView testSegmentStoreTableView = (TestSegmentStoreTableView) vp;
    testSegmentStoreTableView.setTest(this);
    fTableView = testSegmentStoreTableView;

    return fTableView;
}
 
Example 6
Source File: ExtensionContextInjectionFactory.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
public static IEclipseContext workbenchContext() {
    if (PlatformUI.isWorkbenchRunning()) {
        final Workbench workbench = (Workbench) PlatformUI.getWorkbench();
        if (workbench != null) {
            final IEclipseContext context = workbench.getContext();
            checkNotNull(context, "Workbench eclipse context is null");
            return context;
        }
        throw new IllegalStateException("No workbench available");
    }
    return headlessContext();
}
 
Example 7
Source File: WorkbenchStartup.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@Override
public void earlyStartup() {
  final IWorkbench workbench = PlatformUI.getWorkbench();
  GcpStatusMonitoringService service = workbench.getService(GcpStatusMonitoringService.class);
  if (service != null) {
    service.addStatusChangeListener(
        result -> {
          ICommandService commandService = workbench.getService(ICommandService.class);
          if (commandService != null) {
            commandService.refreshElements(
                "com.google.cloud.tools.eclipse.ui.status.showGcpStatus", null);
          }
        });
  }
}
 
Example 8
Source File: RunAppEngineShortcutTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@Test
public void testRunAppEngine_hiddenEvenIfAppEngineProjectFileIsOpen() throws CoreException {
  IProject emptyProject = emptyProjectCreator.getProject();

  // Create an empty file in the App Engine project, and open it in an editor.
  IProject appEngineProject = appEngineProjectCreator.getProject();
  IFile file = appEngineProject.getFile("textfile.txt");
  file.create(new ByteArrayInputStream(new byte[0]), IFile.FORCE, null);

  IWorkbench workbench = PlatformUI.getWorkbench();
  assertNotNull(WorkbenchUtil.openInEditor(workbench, file));

  assertFalse(appEngineMenuExists(emptyProject));
}
 
Example 9
Source File: CreateJavaTypeQuickfixes.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected WizardDialog createWizardDialog(NewElementWizard newXtendClassWizard) {
	IWorkbench workbench = PlatformUI.getWorkbench();
	Shell shell = workbench.getActiveWorkbenchWindow().getShell();
	newXtendClassWizard.init(workbench, new StructuredSelection());
	WizardDialog dialog = new WizardDialog(shell, newXtendClassWizard);
	dialog.create();
	return dialog;
}
 
Example 10
Source File: Application.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
public void stop() {
	if (!PlatformUI.isWorkbenchRunning())
		return;
	final IWorkbench workbench = PlatformUI.getWorkbench();
	final Display display = workbench.getDisplay();
	display.syncExec(new Runnable() {
		public void run() {
			if (!display.isDisposed())
				workbench.close();
		}
	});
}
 
Example 11
Source File: UIHelper.java    From tlaplus with MIT License 5 votes vote down vote up
/**
 * Switch current perspective
 * 
 * @param perspectiveId
 * @return
 */
public static IWorkbenchPage switchPerspective(String perspectiveId) {
	Assert.isNotNull(perspectiveId, "PerspectiveId is null");
	IWorkbench workbench = PlatformUI.getWorkbench();
	IWorkbenchWindow window = getActiveWindow();
	Assert.isNotNull(workbench, "Workbench is null");
	Assert.isNotNull(window, "Window is null");
	try {
		IWorkbenchPage page = workbench.showPerspective(perspectiveId, window);

		// show intro
		if (InitialPerspective.ID.equals(perspectiveId) && workbench.getIntroManager().hasIntro()) {
			page.resetPerspective();
			// We are no longer showing the Intro view. The following will
			// probably
			// be replaced by something that shows the view we want. 09 Oct
			// 2009
			// workbench.getIntroManager().showIntro(window, false);
			openView(ToolboxWelcomeView.ID);

		}

		return page;
	} catch (WorkbenchException e) {
		Activator.getDefault().logError("Error switching a perspective to " + perspectiveId, e);
	}

	return null;
}
 
Example 12
Source File: EditorsUtil.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
static private final IWorkbenchPage unsafeGetWorkbenchPage() {
	IWorkbenchPage page = null;
	if (PlatformUI.isWorkbenchRunning()) {
		IWorkbench wb = PlatformUI.getWorkbench();
		IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
		page = win.getActivePage();
	}
	return page;
}
 
Example 13
Source File: H5ValuePage.java    From dawnsci with Eclipse Public License 1.0 5 votes vote down vote up
private static IWorkbenchPage getActivePage() {
	final IWorkbench bench = PlatformUI.getWorkbench();
	if (bench == null) return null;
	final IWorkbenchWindow window = bench.getActiveWorkbenchWindow();
	if (window == null) return null;
	return window.getActivePage();
}
 
Example 14
Source File: ExamplesApplication.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void stop() {
	final IWorkbench workbench = PlatformUI.getWorkbench();
	if (workbench == null) {
		return;
	}
	final Display display = workbench.getDisplay();
	display.syncExec(() -> {
		if (!display.isDisposed()) {
			workbench.close();
		}
	});
}
 
Example 15
Source File: TmfViewFactory.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Create a new view. <br>
 * If a view with the corresponding id already exists and no suffix were
 * added the existing view will be given focus.
 *
 * @param viewId
 *            The id of the view to be created. <br>
 *            Format: primary_id[:secondary_id[&uuid]|:uuid]
 * @param generateSuffix
 *            Add or replace a generated suffix id (UUID). This allows
 *            multiple views with the same id to be displayed.
 * @return The view instance, or null if an error occurred.
 */
@NonNullByDefault
public static @Nullable IViewPart newView(String viewId, boolean generateSuffix) {
    IViewPart viewPart = null;
    String primaryId = null;
    String secondaryId = null;

    /* Parse the view id */
    int index = viewId.indexOf(TmfView.VIEW_ID_SEPARATOR);
    if (index != -1) {
        primaryId = viewId.substring(0, index);
        secondaryId = getBaseSecId(viewId.substring(index + 1));
    } else {
        primaryId = viewId;
    }

    if (generateSuffix) {
        if (secondaryId == null) {
            secondaryId = UUID.randomUUID().toString();
        } else {
            secondaryId += INTERNAL_SECONDARY_ID_SEPARATOR + UUID.randomUUID().toString();
        }
    }

    IWorkbench workbench = PlatformUI.getWorkbench();
    IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
    IWorkbenchPage page = workbenchWindow.getActivePage();
    try {
        viewPart = page.showView(primaryId, secondaryId, IWorkbenchPage.VIEW_ACTIVATE);
        page.activate(viewPart);
    } catch (PartInitException e) {
        /* Simply return null on error */
    }

    return viewPart;
}
 
Example 16
Source File: OpenNewMRClassWizardAction.java    From RDFS with Apache License 2.0 5 votes vote down vote up
public void run(String[] params, ICheatSheetManager manager) {

    if ((params != null) && (params.length > 0)) {
      IWorkbench workbench = PlatformUI.getWorkbench();
      INewWizard wizard = getWizard(params[0]);
      wizard.init(workbench, new StructuredSelection());
      WizardDialog dialog = new WizardDialog(PlatformUI.getWorkbench()
          .getActiveWorkbenchWindow().getShell(), wizard);
      dialog.create();
      dialog.open();

      // did the wizard succeed ?
      notifyResult(dialog.getReturnCode() == Window.OK);
    }
  }
 
Example 17
Source File: WorkbenchUtils.java    From xds-ide with Eclipse Public License 1.0 4 votes vote down vote up
public static IWorkbenchWindow[] getWorkbenchWindows() {
	IWorkbench workbench = PlatformUI.getWorkbench();
	 return workbench.getWorkbenchWindows();
}
 
Example 18
Source File: AllInOneWorkbenchListener.java    From typescript.java with MIT License 4 votes vote down vote up
public void dispose() {
	final IWorkbench workbench = PlatformUI.getWorkbench();
	unhookListeners(workbench);
}
 
Example 19
Source File: WorkbenchHelper.java    From gama with GNU General Public License v3.0 4 votes vote down vote up
public static IWorkbench getWorkbench() {
	return PlatformUI.getWorkbench();
}
 
Example 20
Source File: JarPackageActionDelegate.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
protected IWorkbench getWorkbench() {
	return PlatformUI.getWorkbench();
}