use of com.haulmont.cuba.gui.screen.Screen in project cuba by cuba-platform.
the class LookupBuilderProcessor method buildLookup.
@SuppressWarnings("unchecked")
public <E extends Entity> Screen buildLookup(LookupBuilder<E> builder) {
FrameOwner origin = builder.getOrigin();
Screens screens = getScreenContext(origin).getScreens();
Screen screen = createScreen(builder, screens);
if (!(screen instanceof LookupScreen)) {
throw new IllegalArgumentException(String.format("Screen %s does not implement LookupScreen: %s", screen.getId(), screen.getClass()));
}
LookupScreen<E> lookupScreen = (LookupScreen) screen;
if (builder.getField() != null) {
HasValue<E> field = builder.getField();
if (field instanceof com.haulmont.cuba.gui.components.Component.Focusable) {
screen.addAfterCloseListener(event -> {
// move focus to owner
((com.haulmont.cuba.gui.components.Component.Focusable) field).focus();
});
}
lookupScreen.setSelectHandler(items -> handleSelectionWithField(builder, field, items));
}
CollectionContainer<E> container = null;
if (builder.getListComponent() != null) {
ListComponent<E> listComponent = builder.getListComponent();
if (listComponent instanceof com.haulmont.cuba.gui.components.Component.Focusable) {
screen.addAfterCloseListener(event -> {
// move focus to owner
((com.haulmont.cuba.gui.components.Component.Focusable) listComponent).focus();
});
}
if (listComponent.getItems() instanceof ContainerDataUnit) {
container = ((ContainerDataUnit<E>) listComponent.getItems()).getContainer();
}
}
if (builder.getContainer() != null) {
container = builder.getContainer();
}
if (container != null) {
CollectionContainer<E> collectionDc = container;
lookupScreen.setSelectHandler(items -> handleSelectionWithContainer(builder, collectionDc, items));
}
if (builder.getSelectHandler() != null) {
lookupScreen.setSelectHandler(builder.getSelectHandler());
}
if (builder.getSelectValidator() != null) {
lookupScreen.setSelectValidator(builder.getSelectValidator());
}
if (builder instanceof LookupClassBuilder) {
@SuppressWarnings("unchecked") Consumer<AfterScreenCloseEvent> closeListener = ((LookupClassBuilder) builder).getCloseListener();
if (closeListener != null) {
screen.addAfterCloseListener(new AfterCloseListenerAdapter(closeListener));
}
}
return screen;
}
use of com.haulmont.cuba.gui.screen.Screen in project cuba by cuba-platform.
the class LocalizedTaskWrapper method showExecutionError.
protected void showExecutionError(Exception ex) {
Screen ownerFrame = wrappedTask.getOwnerScreen();
if (ownerFrame != null) {
Dialogs dialogs = getScreenContext().getDialogs();
Messages messages = AppBeans.get(Messages.class);
dialogs.createExceptionDialog().withThrowable(ex).withCaption(messages.getMessage(LocalizedTaskWrapper.class, "backgroundWorkProgress.executionError")).withMessage(ex.getLocalizedMessage()).show();
}
}
use of com.haulmont.cuba.gui.screen.Screen in project cuba by cuba-platform.
the class TaskHandlerImpl method timeoutExceeded.
/**
* Cancel with timeout exceeded event
*/
public final void timeoutExceeded() {
uiAccessor.access(() -> {
Screen ownerFrame = getTask().getOwnerScreen();
if (log.isTraceEnabled()) {
if (ownerFrame != null) {
String windowClass = ownerFrame.getClass().getCanonicalName();
log.trace("Task timeout exceeded. Task: {}. Frame: {}", taskExecutor.getTask(), windowClass);
} else {
log.trace("Task timeout exceeded. Task: {}", taskExecutor.getTask());
}
}
checkState(started, "Task is not running");
boolean canceled = taskExecutor.cancelExecution();
if (canceled || timeoutHappens) {
removeAfterDetachListener();
BackgroundTask<T, V> task = taskExecutor.getTask();
boolean handled = task.handleTimeoutException();
if (!handled) {
log.error("Unhandled timeout exception in background task. Task: " + task.toString());
events.publish(new BackgroundTaskTimeoutEvent(this, task));
}
}
if (log.isTraceEnabled()) {
if (ownerFrame != null) {
String windowClass = ownerFrame.getClass().getCanonicalName();
log.trace("Timeout was processed. Task: {}. Frame: {}", taskExecutor.getTask(), windowClass);
} else {
log.trace("Timeout was processed. Task: {}", taskExecutor.getTask());
}
}
});
}
use of com.haulmont.cuba.gui.screen.Screen in project cuba by cuba-platform.
the class TaskHandlerImpl method cancel.
@Override
public final boolean cancel() {
checkState(started, "Task is not running. Task: " + taskExecutor.getTask().toString());
boolean canceled = taskExecutor.cancelExecution();
if (canceled) {
removeAfterDetachListener();
BackgroundTask<T, V> task = taskExecutor.getTask();
task.canceled();
// Notify listeners
for (BackgroundTask.ProgressListener listener : task.getProgressListeners()) {
listener.onCancel();
}
if (log.isTraceEnabled()) {
Screen ownerFrame = getTask().getOwnerScreen();
if (ownerFrame != null) {
String windowClass = ownerFrame.getClass().getCanonicalName();
log.trace("Task was cancelled. Task: {}. User: {}. Frame: {}", taskExecutor.getTask(), getUserSession().getId(), windowClass);
} else {
log.trace("Task was cancelled. Task: {}. User: {}", taskExecutor.getTask(), getUserSession().getId());
}
}
} else {
log.trace("Task wasn't cancelled. Execution is already cancelled. Task: {}", taskExecutor.getTask());
}
return canceled;
}
use of com.haulmont.cuba.gui.screen.Screen in project cuba by cuba-platform.
the class WindowLoader method loadCompanions.
@Deprecated
protected void loadCompanions(Window resultComponent, Element element) {
Screen controller = resultComponent.getFrameOwner();
if (controller instanceof AbstractWindow) {
Element companionsElem = element.element("companions");
if (companionsElem != null) {
StopWatch companionStopWatch = createStopWatch(ScreenLifeCycle.COMPANION, controller.getId());
Object companion = initCompanion(companionsElem, (AbstractWindow) controller);
companionStopWatch.stop();
if (companion != null) {
getComponentContext().addInjectTask((c, w) -> {
CompanionDependencyInjector cdi = new CompanionDependencyInjector((LegacyFrame) controller, companion);
cdi.setBeanLocator(beanLocator);
cdi.inject();
});
}
}
}
}
Aggregations