Search in sources :

Example 1 with Preference

use of org.eclipse.e4.core.di.extensions.Preference 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 2 with Preference

use of org.eclipse.e4.core.di.extensions.Preference in project eclipse.platform.runtime by eclipse.

the class PreferencesObjectSupplier method getNodePath.

private String getNodePath(IObjectDescriptor descriptor, Class<?> requestingObject) {
    if (descriptor == null)
        return null;
    Preference qualifier = descriptor.getQualifier(Preference.class);
    String nodePath = qualifier.nodePath();
    if (nodePath == null || nodePath.length() == 0) {
        if (requestingObject == null)
            return null;
        nodePath = FrameworkUtil.getBundle(requestingObject).getSymbolicName();
    }
    return nodePath;
}
Also used : Preference(org.eclipse.e4.core.di.extensions.Preference)

Example 3 with Preference

use of org.eclipse.e4.core.di.extensions.Preference in project eclipse.platform.runtime by eclipse.

the class InjectionPreferencesTest method testPreferencesQualifier.

@Test
public void testPreferencesQualifier() throws BackingStoreException {
    setPreference(TEST_PREFS_KEY, "abc");
    setPreference(TEST_PREFS_KEY, TEST_PREFS_NODE, "123");
    IEclipseContext context = EclipseContextFactory.create();
    InjectTarget target = ContextInjectionFactory.make(InjectTarget.class, context);
    // default node
    assertEquals(1, target.counter);
    assertEquals("abc", target.pref);
    // specific node
    assertEquals(1, target.counterNode);
    assertEquals("123", target.prefNode);
    // optional preference
    assertEquals(1, target.counterOptional);
    assertNull(target.prefOptional1);
    assertEquals("abc", target.prefOptional2);
    // change
    setPreference(TEST_PREFS_KEY, "xyz");
    setPreference(TEST_PREFS_KEY, TEST_PREFS_NODE, "456");
    // default node
    assertEquals(2, target.counter);
    assertEquals("xyz", target.pref);
    // specific node
    assertEquals(2, target.counterNode);
    assertEquals("456", target.prefNode);
    // optional preference
    assertEquals(2, target.counterOptional);
    assertNull(target.prefOptional1);
    assertEquals("xyz", target.prefOptional2);
}
Also used : IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Test(org.junit.Test)

Example 4 with Preference

use of org.eclipse.e4.core.di.extensions.Preference in project portfolio by buchen.

the class StartupAddon method checkForUpdates.

@Inject
@Optional
public // NOSONAR
void checkForUpdates(// NOSONAR
@UIEventTopic(UIEvents.UILifeCycle.APP_STARTUP_COMPLETE) Event event, final IWorkbench workbench, final EPartService partService, @Preference(value = UIConstants.Preferences.AUTO_UPDATE) boolean autoUpdate) {
    if (autoUpdate) {
        Job job = new Job(Messages.JobMsgCheckingForUpdates) {

            @Override
            protected IStatus run(IProgressMonitor monitor) {
                try {
                    monitor.beginTask(Messages.JobMsgCheckingForUpdates, 200);
                    UpdateHelper updateHelper = new UpdateHelper(workbench, partService);
                    updateHelper.runUpdate(monitor, true);
                } catch (// NOSONAR
                CoreException e) {
                    PortfolioPlugin.log(e.getStatus());
                }
                return Status.OK_STATUS;
            }
        };
        job.setSystem(true);
        job.schedule(500);
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) UpdateHelper(name.abuchen.portfolio.ui.update.UpdateHelper) CoreException(org.eclipse.core.runtime.CoreException) Job(org.eclipse.core.runtime.jobs.Job) Inject(javax.inject.Inject) Optional(org.eclipse.e4.core.di.annotations.Optional)

Aggregations

Inject (javax.inject.Inject)2 Optional (org.eclipse.e4.core.di.annotations.Optional)2 AlphavantageQuoteFeed (name.abuchen.portfolio.online.impl.AlphavantageQuoteFeed)1 UpdateHelper (name.abuchen.portfolio.ui.update.UpdateHelper)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 Job (org.eclipse.core.runtime.jobs.Job)1 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)1 Preference (org.eclipse.e4.core.di.extensions.Preference)1 Test (org.junit.Test)1