org.eclipse.ui.IEditorSite#getService ( )源码实例Demo

下面列出了org.eclipse.ui.IEditorSite#getService ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: google-cloud-eclipse   文件: ServiceUtils.java
/**
 * Returns an OSGi service from {@link ExecutionEvent}. It looks up a service in the following
 * locations (if exist) in the given order:
 *
 * {@code HandlerUtil.getActiveSite(event)}
 * {@code HandlerUtil.getActiveEditor(event).getEditorSite()}
 * {@code HandlerUtil.getActiveEditor(event).getSite()}
 * {@code HandlerUtil.getActiveWorkbenchWindow(event)}
 * {@code PlatformUI.getWorkbench()}
 */
public static <T> T getService(ExecutionEvent event, Class<T> api) {
  IWorkbenchSite activeSite = HandlerUtil.getActiveSite(event);
  if (activeSite != null) {
    return activeSite.getService(api);
  }

  IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
  if (activeEditor != null) {
    IEditorSite editorSite = activeEditor.getEditorSite();
    if (editorSite != null) {
      return editorSite.getService(api);
    }
    IWorkbenchPartSite site = activeEditor.getSite();
    if (site != null) {
      return site.getService(api);
    }
  }

  IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
  if (workbenchWindow != null) {
    return workbenchWindow.getService(api);
  }

  return PlatformUI.getWorkbench().getService(api);
}
 
源代码2 项目: KaiZen-OpenAPI-Editor   文件: JsonEditor.java
@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
    super.init(site, input);
    IContextService contextService = (IContextService) site.getService(IContextService.class);
    contextService.activateContext(CONTEXT);
}
 
源代码3 项目: ice   文件: ICEFormEditor.java
/**
 * This operation overrides init so that the ICE Form, passed as an
 * IEditorInput, can be stored.
 * 
 * @param site
 *            the site on the workbench where the Form is drawn
 * @param input
 *            the input for this editor
 */
@Override
public void init(IEditorSite site, IEditorInput input)
		throws RuntimeException {

	// Get the E4 Context. This is how you get into the E4 application model
	// if you are running from a 3.x part and don't have your own
	// application model. See bugs.eclipse.org/bugs/show_bug.cgi?id=376486
	// and chapter 101 of Lar Vogel's e4 book.
	e4Context = site.getService(IEclipseContext.class);

	// Instruct the framework to perform dependency injection for
	// this Form using the ContextInjectionFactory.
	ContextInjectionFactory.inject(this, e4Context);

	// Get the Client Reference
	IClient client = null;
	try {
		client = IClient.getClient();
	} catch (CoreException e1) {
		e1.printStackTrace();
	}

	// Set the site
	setSite(site);

	// Grab the form from the input or the client depending on the type of
	// the input. This should only be a temporary switch until we remove the
	// ICEFormInput and redirect the way the client works.
	if (input instanceof ICEFormInput) {
		ICEFormInput = (ICEFormInput) input;
		iceDataForm = ICEFormInput.getForm();

		// Set the part name to be the file name
		setPartName(iceDataForm.getName() + ".xml");

		// Set the input
		setInput(input);
	} else if (input instanceof FileEditorInput && client != null) {
		// Grab the file and load the form
		IFile formFile = ((FileEditorInput) input).getFile();
		// try {
		// IClient client = IClient.getClient();
		iceDataForm = client.loadItem(formFile);
		logger.info("IClient and Form loaded.");
		// Set *correct* input via a little short circuit.
		ICEFormInput = new ICEFormInput(iceDataForm);
		setInput(ICEFormInput);

		// Set the IFormWidget on the IClient
		client.addFormWidget(new EclipseFormWidget(this));

		// Set the part name to be the file name
		setPartName(input.getName());

		// Register the client as a listener
		// of specific form editor events.
		try {
			registerUpdateListener(
					IUpdateEventListener.getUpdateEventListener());
			registerProcessListener(
					IProcessEventListener.getProcessEventListener());
			registerResourceProvider(
					ISimpleResourceProvider.getSimpleResourceProvider());
		} catch (CoreException e) {
			// Complain
			logger.error(
					"Unable to get register the update, process, or simpleresource implementations!",
					e);
		}

	} else {
		// Throw errors if the type is wrong
		logger.error("Unable to load Form Editor!");
		throw new RuntimeException("Input passed to ICEFormEditor.init()"
				+ " is not of type ICEFormInput or FileEditorInput, or the IClient instance is null.");
	}

	// Get the Item Name for the Form Header.
	for (Identifiable i : client.getItems()) {
		if (iceDataForm.getItemID() == i.getId()) {
			itemName = i.getClass().getSimpleName() + " Item " + i.getId();
			break;
		}
	}

	// Register this ICEFormEditor with the provided Form
	iceDataForm.register(this);

	return;
}