use of org.eclipse.scout.rt.platform.util.concurrent.IRunnable in project scout.rt by eclipse.
the class ClientNotificationDispatcher method dispatchForNode.
/**
* the notification will be applied sync if the method invocation is done in with a {@link IClientSession} in the
* {@link RunContext}. The sync execution is due to piggyback notifications expected to be applied after a successful
* backendcall. In case no {@link IClientSession} is in the current {@link RunContext} the notification is applied
* async.
*
* @param notification
*/
public void dispatchForNode(final Serializable notification, final IClientNotificationAddress address) {
if (IClientSession.CURRENT.get() != null) {
// dispatch sync for piggyback notifications
dispatchSync(notification, address);
} else {
// dispatch async
IFuture<Void> future = Jobs.schedule(new IRunnable() {
@Override
public void run() throws Exception {
dispatchSync(notification, address);
}
}, Jobs.newInput().withRunContext(ClientRunContexts.copyCurrent()).withName("Dispatching client notification"));
addPendingNotification(future);
future.whenDone(new P_NotificationFutureCallback(future), null);
}
}
use of org.eclipse.scout.rt.platform.util.concurrent.IRunnable in project scout.rt by eclipse.
the class AbstractForm method callInitializer.
protected void callInitializer() {
if (isInitialized()) {
return;
}
// Remember the initial ClientRunContext to not loose the Form from current calling context.
m_initialClientRunContext = ClientRunContexts.copyCurrent();
// Run the initialization on behalf of this Form.
ClientRunContexts.copyCurrent().withForm(this).run(new IRunnable() {
@Override
public void run() throws Exception {
interceptInitConfig();
postInitConfig();
setInitialized();
}
});
}
use of org.eclipse.scout.rt.platform.util.concurrent.IRunnable in project scout.rt by eclipse.
the class AbstractForm method installFormCloseTimer.
/**
* Installs the timer to close the Form once the given seconds elapse
*/
private IFuture<?> installFormCloseTimer(final long seconds) {
final long startMillis = System.currentTimeMillis();
final long delayMillis = TimeUnit.SECONDS.toMillis(seconds);
return ModelJobs.schedule(new IRunnable() {
@Override
public void run() throws Exception {
final long elapsedMillis = System.currentTimeMillis() - startMillis;
final long remainingSeconds = TimeUnit.MILLISECONDS.toSeconds(delayMillis - elapsedMillis);
if (!isCloseTimerArmed()) {
setSubTitle(null);
} else if (remainingSeconds > 0) {
setSubTitle("" + remainingSeconds);
} else {
// cancel the periodic action
setCloseTimerArmed(false);
try {
interceptCloseTimer();
} catch (RuntimeException | PlatformError e) {
throw BEANS.get(PlatformExceptionTranslator.class).translate(e).withContextInfo("form", getClass().getName());
}
}
}
}, ModelJobs.newInput(ClientRunContexts.copyCurrent()).withName("Close timer").withExceptionHandling(null, false).withExecutionTrigger(Jobs.newExecutionTrigger().withSchedule(SimpleScheduleBuilder.repeatSecondlyForever())));
}
use of org.eclipse.scout.rt.platform.util.concurrent.IRunnable in project scout.rt by eclipse.
the class AbstractPage method getTable.
@Override
public T getTable(boolean create) {
if (create && m_table == null) {
if (isInitializing()) {
LOG.warn("Table in page {} is created during page init. This is not recommended. The table should be created lazily when the page is activated. " + "Use e.g. the execInitTable() callback to access the table after it has been created.", getClass(), new Exception("origin"));
}
createDisplayParentRunContext().run(new IRunnable() {
@Override
public void run() throws Exception {
runInExtensionContext(new Runnable() {
@Override
public void run() {
m_table = createTable();
if (m_table != null) {
// calls execInitTable of AbstractTable
m_table.initTable();
firePageChanged();
addDefaultTableControls();
// calls execInitTable of AbstractPage
interceptInitTable();
fireAfterTableInit();
}
}
});
}
});
}
return m_table;
}
use of org.eclipse.scout.rt.platform.util.concurrent.IRunnable in project scout.rt by eclipse.
the class AbstractPage method lazyCreateAndInitializeMenus.
@Override
protected List<IMenu> lazyCreateAndInitializeMenus() {
/* NOSONAR
if (isInitializing()) {
//do not warn in 15.4, this code was introduced in 16.0
LOG.warn(
"Menus in page {} are now created during page init. This is not recommended. The menus should be created lazily when the page is activated. "
+ "Use e.g. the execInitTable() callback to access the table after it has been created.",
getClass(), new Exception("origin"));
}
*/
final AtomicReference<List<IMenu>> ref = new AtomicReference<>();
createDisplayParentRunContext().run(new IRunnable() {
@Override
public void run() throws Exception {
runInExtensionContext(new Runnable() {
@Override
public void run() {
ref.set(AbstractPage.super.lazyCreateAndInitializeMenus());
}
});
}
});
return ref.get();
}
Aggregations