Java Code Examples for org.eclipse.e4.core.contexts.IEclipseContext#get()
The following examples show how to use
org.eclipse.e4.core.contexts.IEclipseContext#get() .
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: CustomPopupMenuExtender.java From bonita-studio with GNU General Public License v2.0 | 6 votes |
private void cleanUpContributionCache() { if (!actionContributionCache.isEmpty()) { PluginActionContributionItem[] items = actionContributionCache .toArray(new PluginActionContributionItem[actionContributionCache.size()]); actionContributionCache.clear(); for (PluginActionContributionItem item : items) { item.dispose(); } } if (modelPart == null || menuModel == null) { return; } IEclipseContext modelContext = modelPart.getContext(); if (modelContext != null) { IRendererFactory factory = modelContext.get(IRendererFactory.class); if (factory != null) { AbstractPartRenderer obj = factory.getRenderer(menuModel, null); if (obj instanceof MenuManagerRenderer) { MenuManagerRenderer renderer = (MenuManagerRenderer) obj; renderer.cleanUp(menuModel); } } } }
Example 2
Source File: EsbEditorEvent.java From developer-studio with Apache License 2.0 | 5 votes |
public static void CreateBroker(String pluginId) { Bundle bundle = Platform.getBundle(pluginId); IEclipseContext eclipseContext = EclipseContextFactory.getServiceContext(bundle.getBundleContext()); eclipseContext.set(org.eclipse.e4.core.services.log.Logger.class, null); iEventBroker = eclipseContext.get(IEventBroker.class); }
Example 3
Source File: DemoGeometryPageFactoryContextFunction.java From ice with Eclipse Public License 1.0 | 5 votes |
@Override public Object compute(IEclipseContext context, String contextKey) { IPageFactory factory = ContextInjectionFactory .make(DemoGeometryPageFactory.class, context); // add the new object to the application context MApplication application = context.get(MApplication.class); IEclipseContext ctx = application.getContext(); ctx.set(IPageFactory.class, factory); return factory; }
Example 4
Source File: DemoGeometryPageContextFunction.java From ice with Eclipse Public License 1.0 | 5 votes |
@Override public Object compute(IEclipseContext context, String contextKey) { IPageProvider provider = ContextInjectionFactory .make(DemoGeometryPageProvider.class, context); // add the new object to the application context MApplication application = context.get(MApplication.class); IEclipseContext ctx = application.getContext(); ctx.set(IPageProvider.class, provider); return provider; }
Example 5
Source File: DemoEntryCompositeContextFunction.java From ice with Eclipse Public License 1.0 | 5 votes |
@Override public Object compute(IEclipseContext context, String contextKey) { IEntryCompositeProvider provider = ContextInjectionFactory .make(DemoEntryCompositeProvider.class, context); // add the new object to the application context MApplication application = context.get(MApplication.class); IEclipseContext ctx = application.getContext(); ctx.set(IEntryCompositeProvider.class, provider); return provider; }
Example 6
Source File: DefaultPageFactoryContextFunction.java From ice with Eclipse Public License 1.0 | 5 votes |
@Override public Object compute(IEclipseContext context, String contextKey) { IPageFactory factory = ContextInjectionFactory .make(DefaultPageFactory.class, context); // add the new object to the application context MApplication application = context.get(MApplication.class); IEclipseContext ctx = application.getContext(); ctx.set(IPageFactory.class, factory); return factory; }
Example 7
Source File: WindowJoinCmd.java From e4macs with Eclipse Public License 1.0 | 5 votes |
void closePart(MPart part) { // based on org.eclipse.e4.ui.workbench.renderers.swt.StackRenderer.closePart() IEclipseContext context = part.getContext(); if (context != null && part.isCloseable()) { EPartService partService = context.get(EPartService.class); partService.hidePart(part,true); } }
Example 8
Source File: CoolbarToolControl.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
public void registerHandlers(final IEclipseContext context, final IWorkbenchPage page) { EPartService partService = context.get(EPartService.class); ESelectionService selectionService = context.get(ESelectionService.class); if (!isRegistered && partService != null && selectionService != null) { partService.addPartListener(CoolbarToolControl.this); selectionService.addSelectionListener(CoolbarToolControl.this); isRegistered = true; } }
Example 9
Source File: AbortLocalDocumentHandler.java From elexis-3-core with Eclipse Public License 1.0 | 5 votes |
@Override public Object execute(ExecutionEvent event) throws ExecutionException{ IEclipseContext iEclipseContext = PlatformUI.getWorkbench().getService(IEclipseContext.class); StructuredSelection selection = (StructuredSelection) iEclipseContext .get(event.getCommand().getId().concat(".selection")); iEclipseContext.remove(event.getCommand().getId().concat(".selection")); if (selection != null && !selection.isEmpty()) { List<?> selected = selection.toList(); Shell parentShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); for (Object object : selected) { LocalDocumentServiceHolder.getService().ifPresent(service -> { if (service.contains(object)) { Optional<LocalLock> lock = LocalLock.getManagedLock(object); lock.ifPresent(localDocumentLock -> localDocumentLock.unlock()); service.remove(object); } else { MessageDialog.openInformation(parentShell, Messages.AbortLocalDocumentHandler_infotitle, Messages.AbortLocalDocumentHandler_infomessage); } }); } } return null; }
Example 10
Source File: UIHelper.java From tlaplus with MIT License | 4 votes |
/** * Parts (Editors and Views) can be stacked if the user drags them on top of * each other. This method returns true, if the given part (first parameter) * and the second part (identified by its Id) are indeed stacked. * * @param part * The one part (not null) for which to check if the second part * (otherId) are on the same part stack. * @param otherId * The second part's id (not null). * @return true iff both parts are stacked on top of each other, false * otherwise. */ public static boolean isInSameStack(final IWorkbenchPart part, final String otherId) { Assert.isNotNull(part); Assert.isNotNull(otherId); // The implementation below uses Eclipse's new UI model (e4) that is the // default starting with the 4.x series. It does *not* exist on any 3.x // release of Eclipse. Thus, if the Toolbox ever has to run on 3.x // again, just remove the implementation below and return false. The // only place where this method is used at the time of writing is to // prevent a stack overflow when the ModelEditor and TLCErrorView are // stacked. This isn't possible with 3.x anyway as Views (TLCErrorView) // and Editors (ModelEditor) could not be stacked upon each other (this // was actually an artificial restriction and missed by many). That is // also the very reason, why the Eclipse 3.x API does not support // finding out if an editor and a view are stacked // (IWorkbenchPage#getViewRefererences() and // IWorkbenchPage#getEditorReferences() are mutually exclusive). // Obtain the e4's part context IEclipseContext (each logical UI element // (parts, perspectives, application windows... have a corresponding // context). final IEclipseContext ctx = (IEclipseContext) part.getSite().getService(IEclipseContext.class); if (ctx == null) { // I don't see in which case the ctx is null, but lets be on the safe side. return false; } // The ctx also has the e4 UI model counterpart (MPart) to the technical // IWorkbenchPart instance (the UI model is a logical representation of // the UI state of the Toolbox). final MPart e4ModelPart = ctx.get(MPart.class); // e4 Model elements have references to their respective parents. In // case of our MPart/IWorkbenchPart, it is a stack if it happens to be // rendered in one at the moment. final MElementContainer<MUIElement> stack = e4ModelPart.getParent(); if (stack == null) { // The part has no parent, e.g when it's not stacked return false; } // A MPartStack's children are the MParts currently rendered in it // (visible or not). Since it is the MPartStack of the IWorkbenchPart, // we just check if another child has the Id of the other part we are // interested in. If this is the case, both parts are indeed shown in // the same part stack on top of each other. final List<MUIElement> children = stack.getChildren(); for (final MUIElement muiElement : children) { final String elementId = muiElement.getElementId(); if (elementId != null && elementId.equals(otherId)) { return true; } } return false; }
Example 11
Source File: E4PreferenceRegistry.java From e4Preferences with Eclipse Public License 1.0 | 4 votes |
/** Read the e4PreferenceStoreProvider extension point */ private void initialisePreferenceStoreProviders(IEclipseContext context) { if (psProviders == null) { IContributionFactory factory = context.get(IContributionFactory.class); psProviders = new HashMap<String, Object>(); IExtensionRegistry registry = context.get(IExtensionRegistry.class); // Read extensions and fill the map... for (IConfigurationElement elmt : registry.getConfigurationElementsFor(PREF_STORE_PROVIDER)) { String declaringBundle = elmt.getNamespaceIdentifier(); String pluginId = elmt.getAttribute(ATTR_PLUGIN_ID); if (isEmpty(pluginId)) { logger.warn("missing plugin Id in extension " + PREF_STORE_PROVIDER + " check the plugin " + declaringBundle); continue; } String classname = elmt.getAttribute(ATTR_CLASS); String objectId = elmt.getAttribute(ATTR_ID_IN_WBCONTEXT); if ((isEmpty(classname) && isEmpty(objectId)) || (((classname != null) && classname.length() > 0) && ((objectId != null) && objectId.length() > 0))) { logger.warn("In extension " + PREF_STORE_PROVIDER + " only one of the two attributes (pluginId or idInWorkbenchContext) must be set. Check the plugin " + declaringBundle); continue; } // Ok can now work with data... Object data = objectId; if (classname != null) { data = factory.create(classname, context); if (!(data instanceof IPreferenceStoreProvider)) { logger.warn("In extension " + PREF_STORE_PROVIDER + " the class must implements IPreferenceStoreProvider. Check the plugin " + declaringBundle); continue; } } psProviders.put(pluginId, data); } context.set(KEY_PREF_STORE_PROVIDERS, psProviders); } }
Example 12
Source File: AbstractFormPage.java From bonita-studio with GNU General Public License v2.0 | 4 votes |
public AbstractFormPage(String id, String title, IEclipseContext context) { super(id, title); this.repositoryAccessor = repositoryAccessor(); eCommandService = context.get(ECommandService.class); eHandlerService = context.get(EHandlerService.class); }
Example 13
Source File: DummyEditorSite.java From bonita-studio with GNU General Public License v2.0 | 4 votes |
@Override public IWorkbenchWindow getWorkbenchWindow() { final IEclipseContext context = ((Workbench) PlatformUI.getWorkbench()).getContext(); return (IWorkbenchWindow) context.get(ISources.ACTIVE_WORKBENCH_WINDOW_NAME); }
Example 14
Source File: CoolbarToolControl.java From bonita-studio with GNU General Public License v2.0 | 4 votes |
protected MTrimBar getTrimBar(final IEclipseContext context, final String trimBarId) { final EModelService modelService = context.get(EModelService.class); final MWindow window = context.get(MWindow.class); final MTrimBar topTrim = (MTrimBar) modelService.find(trimBarId, window); return topTrim; }
Example 15
Source File: EndLocalDocumentHandler.java From elexis-3-core with Eclipse Public License 1.0 | 4 votes |
@Override public Object execute(ExecutionEvent event) throws ExecutionException{ IEclipseContext iEclipseContext = PlatformUI.getWorkbench().getService(IEclipseContext.class); StructuredSelection selection = (StructuredSelection) iEclipseContext .get(event.getCommand().getId().concat(".selection")); iEclipseContext.remove(event.getCommand().getId().concat(".selection")); if (selection != null && !selection.isEmpty()) { List<?> selected = selection.toList(); Shell parentShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); for (Object object : selected) { LocalDocumentServiceHolder.getService().ifPresent(service -> { if (service.contains(object)) { Optional<LocalLock> lock = LocalLock.getManagedLock(object); lock.ifPresent(localDocumentLock -> localDocumentLock.unlock()); if (!service.save(object)) { MessageDialog.openError(parentShell, Messages.EndLocalDocumentHandler_errorttitle, Messages.EndLocalDocumentHandler_errormessage); } service.remove(object, new IConflictHandler() { @Override public Result getResult(){ if (MessageDialog.openQuestion(parentShell, Messages.EndLocalDocumentHandler_conflicttitle, Messages.EndLocalDocumentHandler_conflictmessage)) { return Result.OVERWRITE; } else { return Result.ABORT; } } }); } else { MessageDialog.openInformation(parentShell, Messages.EndLocalDocumentHandler_infotitle, Messages.EndLocalDocumentHandler_infomessage); } }); } } return null; }