Search in sources :

Example 81 with IRunnable

use of org.eclipse.scout.rt.platform.util.concurrent.IRunnable in project scout.rt by eclipse.

the class UiSession method startDesktop.

protected void startDesktop(Map<String, String> sessionStartupParams) {
    final IFuture<Void> future = ModelJobs.schedule(new IRunnable() {

        @Override
        public void run() throws Exception {
            IDesktop desktop = m_clientSession.getDesktop();
            IDesktopUIFacade uiFacade = desktop.getUIFacade();
            boolean desktopOpen = desktop.isOpened();
            if (!desktopOpen) {
                uiFacade.openFromUI();
            }
            // Don't handle deep links for persistent sessions,
            // in that case the client state shall be recovered rather than following the deep link
            PropertyMap.CURRENT.get().put(DeepLinkUrlParameter.HANDLE_DEEP_LINK, !isPersistent() || !desktopOpen);
            uiFacade.fireGuiAttached();
        }
    }, ModelJobs.newInput(ClientRunContexts.copyCurrent().withSession(m_clientSession, true).withProperties(// Make startup parameters available at {@link PropertyMap#CURRENT} during desktop attaching
    sessionStartupParams)).withName("Starting Desktop").withExceptionHandling(null, false));
    BEANS.get(UiJobs.class).awaitAndGet(future);
}
Also used : IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) IDesktopUIFacade(org.eclipse.scout.rt.client.ui.desktop.IDesktopUIFacade) IDesktop(org.eclipse.scout.rt.client.ui.desktop.IDesktop)

Example 82 with IRunnable

use of org.eclipse.scout.rt.platform.util.concurrent.IRunnable in project scout.rt by eclipse.

the class ClientSessionTest method testStopWithBlockingClientCallback.

@Test
public void testStopWithBlockingClientCallback() throws Exception {
    TestingUtility.registerBean(new BeanMetaData(TestEnvironmentClientSession.class));
    TestingUtility.registerBean(new BeanMetaData(JobCompletionDelayOnSessionShutdown.class).withProducer(new IBeanInstanceProducer<JobCompletionDelayOnSessionShutdown>() {

        @Override
        public JobCompletionDelayOnSessionShutdown produce(IBean<JobCompletionDelayOnSessionShutdown> bean) {
            return new JobCompletionDelayOnSessionShutdown() {

                @Override
                protected Long getDefaultValue() {
                    return 1000L;
                }
            };
        }
    }));
    session = BEANS.get(ClientSessionProvider.class).provide(ClientRunContexts.empty().withUserAgent(UserAgents.createDefault()));
    // request a geo location
    Future<Coordinates> geo = ModelJobs.schedule(new Callable<Future<Coordinates>>() {

        @Override
        public Future<Coordinates> call() throws Exception {
            return IDesktop.CURRENT.get().requestGeolocation();
        }
    }, ModelJobs.newInput(ClientRunContexts.empty().withSession(session, true))).awaitDoneAndGet();
    assertFalse(geo.isDone());
    // close from ui
    ModelJobs.schedule(new IRunnable() {

        @Override
        public void run() throws Exception {
            session.getDesktop().getUIFacade().closeFromUI(true);
        }
    }, ModelJobs.newInput(ClientRunContexts.empty().withSession(session, true))).awaitDone();
    assertTrue(geo.isCancelled());
}
Also used : BeanMetaData(org.eclipse.scout.rt.platform.BeanMetaData) IBeanInstanceProducer(org.eclipse.scout.rt.platform.IBeanInstanceProducer) Coordinates(org.eclipse.scout.rt.client.ui.Coordinates) JobCompletionDelayOnSessionShutdown(org.eclipse.scout.rt.client.ClientConfigProperties.JobCompletionDelayOnSessionShutdown) IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) IBean(org.eclipse.scout.rt.platform.IBean) Callable(java.util.concurrent.Callable) TestEnvironmentClientSession(org.eclipse.scout.rt.client.testenvironment.TestEnvironmentClientSession) Test(org.junit.Test)

Example 83 with IRunnable

use of org.eclipse.scout.rt.platform.util.concurrent.IRunnable in project scout.rt by eclipse.

the class ClientRunContextTest method testCurrentTransactionScope.

@Test
public void testCurrentTransactionScope() {
    RunContexts.empty().run(new IRunnable() {

        @Override
        public void run() throws Exception {
            assertEquals(TransactionScope.REQUIRED, ClientRunContexts.copyCurrent().getTransactionScope());
        }
    });
    RunContexts.empty().withTransactionScope(TransactionScope.REQUIRES_NEW).run(new IRunnable() {

        @Override
        public void run() throws Exception {
            assertEquals(TransactionScope.REQUIRED, ClientRunContexts.copyCurrent().getTransactionScope());
        }
    });
}
Also used : IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) AssertionException(org.eclipse.scout.rt.platform.util.Assertions.AssertionException) Test(org.junit.Test)

Example 84 with IRunnable

use of org.eclipse.scout.rt.platform.util.concurrent.IRunnable in project scout.rt by eclipse.

the class AbstractWizard method initConfig.

@SuppressWarnings({ "boxing", "unchecked" })
protected void initConfig() {
    setTitle(getConfiguredTitle());
    setSubTitle(getConfiguredSubTitle());
    // initially the wizard is in state "closed"
    setClosedInternal(true);
    setCloseTypeInternal(CloseType.Unknown);
    m_contributionHolder = new ContributionComposite(AbstractWizard.this);
    m_containerForm = createContainerForm();
    Assertions.assertNotNull(m_containerForm, "Missing container form");
    interceptDecorateContainerForm();
    // Run the initialization on behalf of the container form.
    runWithinContainerForm(new IRunnable() {

        @Override
        public void run() throws Exception {
            // steps
            List<Class<? extends IWizardStep<? extends IForm>>> configuredAvailableSteps = getConfiguredAvailableSteps();
            List<IWizardStep> contributedSteps = m_contributionHolder.getContributionsByClass(IWizardStep.class);
            OrderedCollection<IWizardStep<? extends IForm>> steps = new OrderedCollection<IWizardStep<? extends IForm>>();
            for (Class<? extends IWizardStep<? extends IForm>> element : configuredAvailableSteps) {
                IWizardStep<? extends IForm> step = ConfigurationUtility.newInnerInstance(AbstractWizard.this, element);
                steps.addOrdered(step);
            }
            for (IWizardStep step : contributedSteps) {
                steps.addOrdered(step);
            }
            injectStepsInternal(steps);
            ExtensionUtility.moveModelObjects(steps);
            setAvailableSteps(steps.getOrderedList());
            // add listener to listen on any field in active form
            m_anyFieldChangeListener = new PropertyChangeListener() {

                @Override
                public void propertyChange(PropertyChangeEvent e) {
                    try {
                        interceptAnyFieldChanged((IFormField) e.getSource());
                    } catch (RuntimeException | PlatformError t) {
                        LOG.error("{} {}={}", e.getSource(), e.getPropertyName(), e.getNewValue(), t);
                    }
                }
            };
            propertySupport.addPropertyChangeListener(PROP_WIZARD_FORM, new PropertyChangeListener() {

                @Override
                public void propertyChange(PropertyChangeEvent e) {
                    IForm oldForm = (IForm) e.getOldValue();
                    IForm newForm = (IForm) e.getNewValue();
                    if (oldForm != null) {
                        oldForm.getRootGroupBox().removeSubtreePropertyChangeListener(IValueField.PROP_VALUE, m_anyFieldChangeListener);
                    }
                    if (newForm != null) {
                        newForm.getRootGroupBox().addSubtreePropertyChangeListener(IValueField.PROP_VALUE, m_anyFieldChangeListener);
                    }
                }
            });
        }
    });
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) ContributionComposite(org.eclipse.scout.rt.shared.extension.ContributionComposite) OrderedCollection(org.eclipse.scout.rt.platform.util.collection.OrderedCollection) IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) IForm(org.eclipse.scout.rt.client.ui.form.IForm) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException) PlatformError(org.eclipse.scout.rt.platform.exception.PlatformError) EventListenerList(org.eclipse.scout.rt.platform.util.EventListenerList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 85 with IRunnable

use of org.eclipse.scout.rt.platform.util.concurrent.IRunnable in project scout.rt by eclipse.

the class AbstractWizard method start.

@Override
public void start() {
    assertClosed();
    if (m_blockingCondition.isBlocking()) {
        throw new ProcessingException("The wizard " + getClass().getSimpleName() + " has already been started");
    }
    m_blockingCondition.setBlocking(true);
    setClosedInternal(false);
    setCloseTypeInternal(CloseType.Unknown);
    // Run the initialization on behalf of this Form.
    runWithinContainerForm(new IRunnable() {

        @Override
        public void run() throws Exception {
            interceptStart();
            if (m_containerForm.isFormStartable()) {
                m_containerForm.startWizard();
            }
            interceptPostStart();
        }
    });
}
Also used : IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException)

Aggregations

IRunnable (org.eclipse.scout.rt.platform.util.concurrent.IRunnable)260 Test (org.junit.Test)210 AssertionException (org.eclipse.scout.rt.platform.util.Assertions.AssertionException)82 BlockingCountDownLatch (org.eclipse.scout.rt.testing.platform.util.BlockingCountDownLatch)68 ProcessingException (org.eclipse.scout.rt.platform.exception.ProcessingException)40 ArrayList (java.util.ArrayList)36 PlatformException (org.eclipse.scout.rt.platform.exception.PlatformException)32 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)26 TimedOutError (org.eclipse.scout.rt.platform.util.concurrent.TimedOutError)21 IBlockingCondition (org.eclipse.scout.rt.platform.job.IBlockingCondition)20 IExecutionSemaphore (org.eclipse.scout.rt.platform.job.IExecutionSemaphore)20 ThreadInterruptedError (org.eclipse.scout.rt.platform.util.concurrent.ThreadInterruptedError)20 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)19 JobEvent (org.eclipse.scout.rt.platform.job.listener.JobEvent)17 VetoException (org.eclipse.scout.rt.platform.exception.VetoException)13 Times (org.eclipse.scout.rt.testing.platform.runner.Times)12 AtomicReference (java.util.concurrent.atomic.AtomicReference)11 IFuture (org.eclipse.scout.rt.platform.job.IFuture)10 IJobManager (org.eclipse.scout.rt.platform.job.IJobManager)10 JMSException (javax.jms.JMSException)9