use of org.eclipse.e4.core.di.extensions.Service in project ACS by ACS-Community.
the class CopyDetailsToClipboardHandler method execute.
/**
* Receives the selection from the event detail part.
* <p>
* It may be my lack of understanding of good Eclipse 4 RCP practices that I wish
* I could handle the mouse menu action locally in the event detail part,
* instead of sending the data via selection service to separate handler.
* Perhaps to be refactored once this becomes clearer.
*/
@Execute
public void execute(@Named(IServiceConstants.ACTIVE_SELECTION) ParsedAnyData[] parsedAnyData) throws ExecutionException {
if (parsedAnyData == null || parsedAnyData.length == 0) {
return;
}
System.out.println("Will copy event details to the clipboard...");
// Convert selected table rows into a multi-line String
StringBuilder sb = new StringBuilder();
for (ParsedAnyData parsedAny : parsedAnyData) {
sb.append(parsedAnyDataToString(parsedAny));
}
// Write that data to the system clipboard
Clipboard cb = new Clipboard(Display.getCurrent());
TextTransfer textTransfer = TextTransfer.getInstance();
cb.setContents(new Object[] { sb.toString() }, new Transfer[] { textTransfer });
cb.dispose();
}
use of org.eclipse.e4.core.di.extensions.Service in project org.csstudio.display.builder by kasemir.
the class RuntimeViewPart method findPlaceholder.
/**
* Find the MPlaceholder corresponding to this MPart in the MPerspective. This
* may have persisted information relevant to loading this view.
* @return corresponding placeholder or <code>null</code>
*/
private MPlaceholder findPlaceholder() {
final IEclipseContext localContext = getViewSite().getService(IEclipseContext.class);
final MPart part = localContext.get(MPart.class);
final EModelService service = PlatformUI.getWorkbench().getService(EModelService.class);
final IEclipseContext globalContext = PlatformUI.getWorkbench().getService(IEclipseContext.class);
final MApplication app = globalContext.get(MApplication.class);
final List<MPlaceholder> phs = service.findElements(app, null, MPlaceholder.class, null);
for (MPlaceholder ph : phs) if (ph.getRef() == part)
return ph;
return null;
}
use of org.eclipse.e4.core.di.extensions.Service in project n4js by eclipse.
the class N4JSApplicationWorkbenchWindowAdvisor method reviewDisabledCategoriesFromAppModel.
/**
* The 'Show View' dialog behavior slightly changed with E4. Even if the views are properly removed via activities
* (by the unique view IDs) the content provider creates the root category for the unavailable views as well since
* it is using the {@link MApplication}.
*/
private void reviewDisabledCategoriesFromAppModel() {
final IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
final MApplication service = workbenchWindow.getService(MApplication.class);
for (Iterator<MPartDescriptor> itr = service.getDescriptors().iterator(); itr.hasNext(); ) /**/
{
final MPartDescriptor descriptor = itr.next();
if (isView(descriptor) && isDisabledView(descriptor)) {
itr.remove();
}
}
}
use of org.eclipse.e4.core.di.extensions.Service in project portfolio by buchen.
the class Preference2EnvAddon method setAlphavantageApiKey.
@Inject
@Optional
public void setAlphavantageApiKey(@Preference(value = UIConstants.Preferences.ALPHAVANTAGE_API_KEY) String alphavantageApiKey) {
// this is a hack to pass the eclipse-based preference via environment
// to the AlphavantageQuoteFeed implementation which is not created via
// dependency injection but via Java Service Locator.
AlphavantageQuoteFeed quoteFeed = (AlphavantageQuoteFeed) Factory.getQuoteFeedProvider(AlphavantageQuoteFeed.ID);
quoteFeed.setApiKey(alphavantageApiKey);
}
use of org.eclipse.e4.core.di.extensions.Service in project eclipse.platform.runtime by eclipse.
the class ServiceSupplierTestCase method testOptionalReferences.
@Test
public void testOptionalReferences() throws InterruptedException {
BundleContext context = FrameworkUtil.getBundle(getClass()).getBundleContext();
IEclipseContext serviceContext = EclipseContextFactory.getServiceContext(context);
TestDisabledBean bean = ContextInjectionFactory.make(TestDisabledBean.class, serviceContext);
assertNull(bean.disabledService);
assertEquals(0, bean.services.size());
ServiceReference<ComponentEnabler> ref = context.getServiceReference(ComponentEnabler.class);
ComponentEnabler enabler = context.getService(ref);
try {
enabler.enableDisabledServiceA();
// give the service registry and the injection some time
Thread.sleep(100);
assertNotNull(bean.disabledService);
assertEquals(1, bean.services.size());
assertSame(DisabledServiceA.class, bean.disabledService.getClass());
enabler.enableDisabledServiceB();
// give the service registry and the injection some time
Thread.sleep(100);
assertNotNull(bean.disabledService);
assertEquals(2, bean.services.size());
assertSame(DisabledServiceB.class, bean.disabledService.getClass());
enabler.disableDisabledServiceB();
// give the service registry and the injection some time
Thread.sleep(100);
assertNotNull(bean.disabledService);
assertEquals(1, bean.services.size());
assertSame(DisabledServiceA.class, bean.disabledService.getClass());
enabler.disableDisabledServiceA();
// give the service registry and the injection some time
Thread.sleep(100);
assertNull(bean.disabledService);
assertEquals(0, bean.services.size());
} finally {
enabler.disableDisabledServiceA();
enabler.disableDisabledServiceB();
// give the service registry and the injection some time to ensure
// clear state after this test
Thread.sleep(100);
}
}
Aggregations