use of com.haulmont.cuba.gui.screen.FrameOwner in project cuba by cuba-platform.
the class ScreenBuilderProcessor method buildScreen.
@SuppressWarnings("unchecked")
public Screen buildScreen(ScreenBuilder builder) {
FrameOwner origin = builder.getOrigin();
Screens screens = getScreenContext(origin).getScreens();
Screen screen;
if (builder instanceof ScreenClassBuilder) {
ScreenClassBuilder screenClassBuilder = (ScreenClassBuilder) builder;
Class screenClass = screenClassBuilder.getScreenClass();
if (screenClass == null) {
throw new IllegalArgumentException("Screen class is not set");
}
screen = screens.create(screenClass, builder.getLaunchMode(), builder.getOptions());
@SuppressWarnings("unchecked") Consumer<AfterScreenCloseEvent> closeListener = screenClassBuilder.getCloseListener();
if (closeListener != null) {
screen.addAfterCloseListener(new AfterCloseListenerAdapter(closeListener));
}
} else {
if (builder.getScreenId() == null) {
throw new IllegalArgumentException("Screen id is not set");
}
screen = screens.create(builder.getScreenId(), builder.getLaunchMode(), builder.getOptions());
}
return screen;
}
use of com.haulmont.cuba.gui.screen.FrameOwner in project cuba by cuba-platform.
the class ClearAction method execute.
/**
* Executes the action.
*/
@SuppressWarnings("unchecked")
@Override
public void execute() {
// remove entity if it is a composition
Object value = pickerField.getValue();
ValueSource valueSource = pickerField.getValueSource();
if (value != null && !value.equals(pickerField.getEmptyValue()) && valueSource instanceof EntityValueSource) {
EntityValueSource entityValueSource = (EntityValueSource) pickerField.getValueSource();
Entity entity = (Entity) pickerField.getValue();
if (entityValueSource.getMetaPropertyPath() != null && entityValueSource.getMetaPropertyPath().getMetaProperty().getType() == MetaProperty.Type.COMPOSITION) {
FrameOwner screen = pickerField.getFrame().getFrameOwner();
DataContext dataContext = UiControllerUtils.getScreenData(screen).getDataContext();
dataContext.remove(entity);
}
}
// Set the value as if the user had set it
pickerField.setValueFromUser(pickerField.getEmptyValue());
}
use of com.haulmont.cuba.gui.screen.FrameOwner in project cuba by cuba-platform.
the class ScreenBuilders method editor.
/**
* Creates a screen builder using list component.
* <p>
* Example of building a screen for editing a currently selected entity:
* <pre>{@code
* SomeCustomerEditor screen = screenBuilders.editor(customersTable)
* .withScreen(SomeCustomerEditor.class)
* .build();
* }</pre>
* <p>
* Example of building a screen for creating a new entity instance:
* <pre>{@code
* SomeCustomerEditor screen = screenBuilders.editor(customersTable)
* .withScreen(SomeCustomerEditor.class)
* .newEntity()
* .build();
* }</pre>
*
* @param listComponent {@link Table}, {@link DataGrid} or another component containing the list of entities
* @see #editor(Class, FrameOwner)
*/
public <E extends Entity> EditorBuilder<E> editor(ListComponent<E> listComponent) {
checkNotNullArgument(listComponent);
checkNotNullArgument(listComponent.getFrame());
FrameOwner frameOwner = listComponent.getFrame().getFrameOwner();
Class<E> entityClass;
DataUnit items = listComponent.getItems();
if (items instanceof EntityDataUnit) {
entityClass = ((EntityDataUnit) items).getEntityMetaClass().getJavaClass();
} else {
throw new IllegalStateException(String.format("Component %s is not bound to data", listComponent));
}
EditorBuilder<E> builder = new EditorBuilder<>(frameOwner, entityClass, editorBuilderProcessor::buildEditor);
builder.withListComponent(listComponent);
builder.editEntity(listComponent.getSingleSelected());
return builder;
}
use of com.haulmont.cuba.gui.screen.FrameOwner in project cuba by cuba-platform.
the class ScreenBuilders method editor.
/**
* Creates a screen builder using {@link PickerField} component.
* <p>
* Example of building a screen for editing a currently set value:
* <pre>{@code
* SomeCustomerEditor screen = screenBuilders.editor(customerPickerField)
* .withScreen(SomeCustomerEditor.class)
* .build();
* }</pre>
* <p>
* Example of building a screen for creating a new entity instance:
* <pre>{@code
* SomeCustomerEditor screen = screenBuilders.editor(customerPickerField)
* .withScreen(SomeCustomerEditor.class)
* .newEntity()
* .build();
* }</pre>
*
* @param field {@link PickerField}, {@link LookupPickerField} or another picker component
* @see #editor(Class, FrameOwner)
*/
public <E extends Entity> EditorBuilder<E> editor(PickerField<E> field) {
checkNotNullArgument(field);
checkNotNullArgument(field.getFrame());
FrameOwner frameOwner = field.getFrame().getFrameOwner();
Class<E> entityClass;
MetaClass metaClass = field.getMetaClass();
if (metaClass != null) {
entityClass = metaClass.getJavaClass();
} else {
throw new IllegalStateException(String.format("Component %s is not bound to meta class", field));
}
EditorBuilder<E> builder = new EditorBuilder<>(frameOwner, entityClass, editorBuilderProcessor::buildEditor);
builder.withField(field);
builder.editEntity(field.getValue());
return builder;
}
use of com.haulmont.cuba.gui.screen.FrameOwner in project cuba by cuba-platform.
the class ScreensHelper method isEntityAvailable.
protected boolean isEntityAvailable(Element window, Class<? extends FrameOwner> controllerClass, Class entityClass, ScreenType filterScreenType, boolean useComplexSearch) {
Element dsContext = window.element("dsContext");
Element data = window.element("data");
if (dsContext == null && data == null) {
return false;
}
Element dataElement = data != null ? data : dsContext;
if (!useComplexSearch) {
String dataElementId = data != null ? getDataContainerId(window, controllerClass, filterScreenType) : getDatasourceId(window, filterScreenType);
if (StringUtils.isEmpty(dataElementId)) {
return false;
}
return isEntityAvailableInDataElement(entityClass, dataElement, dataElementId);
}
if (!checkWindowType(controllerClass, filterScreenType)) {
return false;
}
List<Element> dataElements = dataElement.elements();
List<String> dataElementIds = dataElements.stream().filter(de -> isEntityAvailableInDataElement(entityClass, de)).map(de -> de.attributeValue("id")).collect(Collectors.toList());
if (!ScreenType.BROWSER.equals(filterScreenType)) {
String editedEntityDataElementId = data != null ? resolveEditedEntityContainerId(controllerClass) : window.attributeValue("datasource");
dataElementIds.addAll(getDataElementsIdForComposition(dataElement, entityClass, editedEntityDataElementId));
}
return dataElementIds.size() > 0;
}
Aggregations