Search in sources :

Example 1 with BooleanHolder

use of org.eclipse.scout.rt.platform.holders.BooleanHolder in project scout.rt by eclipse.

the class AbstractContextMenu method calculateLocalVisibility.

protected void calculateLocalVisibility() {
    final IActionFilter activeFilter = ActionUtility.createMenuFilterMenuTypes(getCurrentMenuTypes(), true);
    if (activeFilter != null) {
        final BooleanHolder visibleHolder = new BooleanHolder(false);
        acceptVisitor(new IActionVisitor() {

            @Override
            public int visit(IAction action) {
                if (action instanceof IMenu) {
                    IMenu menu = (IMenu) action;
                    if (menu.hasChildActions() || menu.isSeparator() || menu instanceof IContextMenu) {
                        return CONTINUE;
                    } else if (activeFilter.accept(menu)) {
                        visibleHolder.setValue(true);
                        return CANCEL;
                    }
                }
                return CONTINUE;
            }
        });
        setVisible(visibleHolder.getValue());
    }
}
Also used : IActionVisitor(org.eclipse.scout.rt.client.ui.action.IActionVisitor) IMenu(org.eclipse.scout.rt.client.ui.action.menu.IMenu) IAction(org.eclipse.scout.rt.client.ui.action.IAction) IActionFilter(org.eclipse.scout.rt.client.ui.action.IActionFilter) BooleanHolder(org.eclipse.scout.rt.platform.holders.BooleanHolder)

Example 2 with BooleanHolder

use of org.eclipse.scout.rt.platform.holders.BooleanHolder in project scout.rt by eclipse.

the class SessionDataTest method testComputeIfAbsent.

@Test
public void testComputeIfAbsent() {
    final BooleanHolder computedHolder = new BooleanHolder();
    Object value = m_sessionData.computeIfAbsent(TEST_KEY, new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            computedHolder.setValue(true);
            return TEST_DATA;
        }
    });
    assertSame(TEST_DATA, value);
    assertSame(TEST_DATA, m_sessionData.get(TEST_KEY));
    assertTrue(computedHolder.getValue());
}
Also used : BooleanHolder(org.eclipse.scout.rt.platform.holders.BooleanHolder) IOException(java.io.IOException) PlatformException(org.eclipse.scout.rt.platform.exception.PlatformException) AssertionException(org.eclipse.scout.rt.platform.util.Assertions.AssertionException) Test(org.junit.Test)

Example 3 with BooleanHolder

use of org.eclipse.scout.rt.platform.holders.BooleanHolder in project scout.rt by eclipse.

the class JobListenerTest method testCancel.

@Test
public void testCancel() throws Exception {
    JobEventCaptureListener captureListener = new JobEventCaptureListener();
    Jobs.getJobManager().addListener(captureListener);
    final BooleanHolder hasStarted = new BooleanHolder(Boolean.FALSE);
    IFuture<Void> future = Jobs.getJobManager().schedule(new IRunnable() {

        @Override
        public void run() throws Exception {
            hasStarted.setValue(Boolean.TRUE);
        }
    }, Jobs.newInput().withRunContext(RunContexts.empty()).withExecutionTrigger(Jobs.newExecutionTrigger().withStartIn(1, TimeUnit.HOURS)));
    future.cancel(true);
    Jobs.getJobManager().awaitDone(Jobs.newFutureFilterBuilder().andMatchFuture(future).toFilter(), 10, TimeUnit.SECONDS);
    Jobs.getJobManager().shutdown();
    // verify events
    int i = -1;
    List<JobEvent> capturedEvents = captureListener.getCapturedEvents();
    List<JobState> capturedFutureStates = captureListener.getCapturedFutureStates();
    i++;
    assertStateChangedEvent(future, JobState.SCHEDULED, capturedEvents.get(i));
    assertEquals(JobState.SCHEDULED, capturedFutureStates.get(i));
    i++;
    assertStateChangedEvent(future, JobState.PENDING, capturedEvents.get(i));
    assertEquals(JobState.PENDING, capturedFutureStates.get(i));
    i++;
    assertStateChangedEvent(future, JobState.DONE, capturedEvents.get(i));
    assertEquals(JobState.DONE, capturedFutureStates.get(i));
    i++;
    assertJobManagerShutdownEvent(capturedEvents.get(i));
    assertNull(capturedFutureStates.get(i));
    assertEquals(i + 1, capturedEvents.size());
}
Also used : JobEvent(org.eclipse.scout.rt.platform.job.listener.JobEvent) BooleanHolder(org.eclipse.scout.rt.platform.holders.BooleanHolder) IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) Test(org.junit.Test)

Example 4 with BooleanHolder

use of org.eclipse.scout.rt.platform.holders.BooleanHolder in project scout.rt by eclipse.

the class SessionDataTest method testComputeIfAbsentReturningNull.

@Test
public void testComputeIfAbsentReturningNull() {
    final BooleanHolder computedHolder = new BooleanHolder();
    // 1. compute null value
    Object value = m_sessionData.computeIfAbsent(TEST_KEY, new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            computedHolder.setValue(true);
            return null;
        }
    });
    assertNull(value);
    assertTrue(computedHolder.getValue());
    // 2. compute non-null value
    computedHolder.setValue(false);
    value = m_sessionData.computeIfAbsent(TEST_KEY, new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            computedHolder.setValue(true);
            return TEST_DATA;
        }
    });
    assertSame(TEST_DATA, value);
    assertTrue(computedHolder.getValue());
}
Also used : BooleanHolder(org.eclipse.scout.rt.platform.holders.BooleanHolder) IOException(java.io.IOException) PlatformException(org.eclipse.scout.rt.platform.exception.PlatformException) AssertionException(org.eclipse.scout.rt.platform.util.Assertions.AssertionException) Callable(java.util.concurrent.Callable) Test(org.junit.Test)

Example 5 with BooleanHolder

use of org.eclipse.scout.rt.platform.holders.BooleanHolder in project scout.rt by eclipse.

the class InvocationContextTest method testInvokeNotWebMethod.

@Test
public void testInvokeNotWebMethod() {
    final BooleanHolder intercepted = new BooleanHolder(false);
    ServerRunContexts.copyCurrent().withCorrelationId(TESTING_CORRELATION_ID).run(new IRunnable() {

        @Override
        public void run() throws Exception {
            InvocationContext<TestPort> invocationContext = new InvocationContext<>(m_port, "name");
            invocationContext.withEndpointUrl("http://localhost");
            invocationContext.whenInvoke(new InvocationHandler() {

                @Override
                public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                    intercepted.setValue(true);
                    return method.invoke(proxy, args);
                }
            });
            // invoke method which is not annotated with @WebMethod
            invocationContext.getPort().notWebMethod();
        }
    });
    // only methods annotated with @WebMethod are intercepted
    assertFalse(intercepted.getValue());
    // correlationId is not propagated other than web methods
    assertNull(m_port.getRequestContext().get(MessageContexts.PROP_CORRELATION_ID));
    verify(m_port).notWebMethod();
}
Also used : BooleanHolder(org.eclipse.scout.rt.platform.holders.BooleanHolder) IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) Method(java.lang.reflect.Method) WebMethod(javax.jws.WebMethod) InvocationHandler(java.lang.reflect.InvocationHandler) Test(org.junit.Test)

Aggregations

BooleanHolder (org.eclipse.scout.rt.platform.holders.BooleanHolder)5 Test (org.junit.Test)4 IOException (java.io.IOException)2 PlatformException (org.eclipse.scout.rt.platform.exception.PlatformException)2 AssertionException (org.eclipse.scout.rt.platform.util.Assertions.AssertionException)2 IRunnable (org.eclipse.scout.rt.platform.util.concurrent.IRunnable)2 InvocationHandler (java.lang.reflect.InvocationHandler)1 Method (java.lang.reflect.Method)1 Callable (java.util.concurrent.Callable)1 WebMethod (javax.jws.WebMethod)1 IAction (org.eclipse.scout.rt.client.ui.action.IAction)1 IActionFilter (org.eclipse.scout.rt.client.ui.action.IActionFilter)1 IActionVisitor (org.eclipse.scout.rt.client.ui.action.IActionVisitor)1 IMenu (org.eclipse.scout.rt.client.ui.action.menu.IMenu)1 JobEvent (org.eclipse.scout.rt.platform.job.listener.JobEvent)1