Search in sources :

Example 1 with Service

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();
}
Also used : ParsedAnyData(alma.acs.eventbrowser.parts.ParsedAnyData) Clipboard(org.eclipse.swt.dnd.Clipboard) TextTransfer(org.eclipse.swt.dnd.TextTransfer) CanExecute(org.eclipse.e4.core.di.annotations.CanExecute) Execute(org.eclipse.e4.core.di.annotations.Execute)

Example 2 with Service

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;
}
Also used : MPart(org.eclipse.e4.ui.model.application.ui.basic.MPart) EModelService(org.eclipse.e4.ui.workbench.modeling.EModelService) MPlaceholder(org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) MApplication(org.eclipse.e4.ui.model.application.MApplication)

Example 3 with Service

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();
        }
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) MPartDescriptor(org.eclipse.e4.ui.model.application.descriptor.basic.MPartDescriptor) MApplication(org.eclipse.e4.ui.model.application.MApplication)

Example 4 with Service

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);
}
Also used : AlphavantageQuoteFeed(name.abuchen.portfolio.online.impl.AlphavantageQuoteFeed) Inject(javax.inject.Inject) Optional(org.eclipse.e4.core.di.annotations.Optional)

Example 5 with Service

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);
    }
}
Also used : IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Aggregations

IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)7 Test (org.junit.Test)5 BundleContext (org.osgi.framework.BundleContext)4 MApplication (org.eclipse.e4.ui.model.application.MApplication)3 MPlaceholder (org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder)2 MPart (org.eclipse.e4.ui.model.application.ui.basic.MPart)2 EModelService (org.eclipse.e4.ui.workbench.modeling.EModelService)2 Bundle (org.osgi.framework.Bundle)2 ParsedAnyData (alma.acs.eventbrowser.parts.ParsedAnyData)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 Inject (javax.inject.Inject)1 AlphavantageQuoteFeed (name.abuchen.portfolio.online.impl.AlphavantageQuoteFeed)1 CanExecute (org.eclipse.e4.core.di.annotations.CanExecute)1 Execute (org.eclipse.e4.core.di.annotations.Execute)1 Optional (org.eclipse.e4.core.di.annotations.Optional)1 Service (org.eclipse.e4.core.di.extensions.Service)1