use of io.jmix.ui.screen.MapScreenOptions in project jmix by jmix-framework.
the class RelatedEntitiesBean method openRelatedScreen.
@Override
public void openRelatedScreen(Collection<? extends Entity> selectedEntities, MetaClass metaClass, MetaProperty metaProperty, @Nullable RelatedScreenDescriptor descriptor) {
checkNotNullArgument(metaClass, "MetaClass can't be null");
checkNotNullArgument(metaProperty, "MetaProperty can't be null");
WindowManager windowManager = windowManagerProvider.get();
if (!selectedEntities.isEmpty()) {
Map<String, Object> params = new HashMap<>();
WindowParams.DISABLE_AUTO_REFRESH.set(params, true);
WindowParams.DISABLE_RESUME_SUSPENDED.set(params, true);
if (descriptor != null && descriptor.getScreenParams() != null) {
params.putAll(descriptor.getScreenParams());
}
String screenId;
if (descriptor != null && StringUtils.isNotEmpty(descriptor.getScreenId())) {
screenId = descriptor.getScreenId();
} else {
screenId = windowConfig.getBrowseScreenId(metaProperty.getRange().asClass());
}
if (StringUtils.isEmpty(screenId)) {
String message = String.format("Can't show related entities: passed screenId is null and " + "there is no default browse screen for %s", metaClass.getName());
throw new IllegalStateException(message);
}
WindowManager.OpenType openType = WindowManager.OpenType.THIS_TAB;
if (descriptor != null) {
openType = descriptor.getOpenType();
}
Screen screen = ((CubaScreens) windowManager).create(screenId, openType.getOpenMode(), new MapScreenOptions(params));
boolean found = ComponentsHelper.walkComponents(screen.getWindow(), screenComponent -> {
if (!(screenComponent instanceof Filter)) {
return false;
} else {
MetaClass actualMetaClass = ((FilterImplementation) screenComponent).getEntityMetaClass();
MetaClass relatedMetaClass = metaProperty.getRange().asClass();
MetaClass effectiveMetaClass = extendedEntities.getEffectiveMetaClass(relatedMetaClass);
if (Objects.equals(actualMetaClass, effectiveMetaClass)) {
MetaDataDescriptor metaDataDescriptor = new MetaDataDescriptor(metaClass, metaProperty);
applyFilter(((Filter) screenComponent), selectedEntities, descriptor, metaDataDescriptor);
return true;
}
return false;
}
});
screen.show();
if (!found) {
windowManager.showNotification(messages.getMainMessage("actions.Related.FilterNotFound"), NotificationType.WARNING);
}
if (screen instanceof LegacyFrame) {
LegacyFrame legacyFrame = (LegacyFrame) screen;
((DsContextImplementation) legacyFrame.getDsContext()).resumeSuspended();
}
} else {
windowManager.showNotification(messages.getMainMessage("actions.Related.NotSelected"), NotificationType.HUMANIZED);
}
}
use of io.jmix.ui.screen.MapScreenOptions in project jmix by jmix-framework.
the class InspectorFormBuilder method addField.
/**
* Adds field to the specified form.
* If the field should be custom, adds it to the specified customFields collection
* which can be used later to create fieldGenerators
*
* @param metaProperty meta property of the item's property which field is creating
* @param form field group to which created field will be added
*/
protected void addField(InstanceContainer container, Form form, MetaProperty metaProperty, boolean isReadonly) {
MetaClass metaClass = container.getEntityMetaClass();
Range range = metaProperty.getRange();
boolean isRequired = isRequired(metaProperty);
UiEntityAttributeContext attributeContext = new UiEntityAttributeContext(metaClass, metaProperty.getName());
accessManager.applyRegisteredConstraints(attributeContext);
if (!attributeContext.canView())
return;
if (range.isClass()) {
UiEntityContext entityContext = new UiEntityContext(range.asClass());
accessManager.applyRegisteredConstraints(entityContext);
if (!entityContext.isViewPermitted()) {
return;
}
}
ValueSource valueSource = new ContainerValueSource<>(container, metaProperty.getName());
ComponentGenerationContext componentContext = new ComponentGenerationContext(metaClass, metaProperty.getName());
componentContext.setValueSource(valueSource);
Field field = (Field) uiComponentsGenerator.generate(componentContext);
if (requireTextArea(metaProperty, getItem(), MAX_TEXTFIELD_STRING_LENGTH)) {
field = uiComponents.create(TextArea.NAME);
}
if (isBoolean(metaProperty)) {
field = createBooleanField();
}
if (range.isClass()) {
EntityPicker pickerField = uiComponents.create(EntityPicker.class);
EntityLookupAction lookupAction = actions.create(EntityLookupAction.class);
lookupAction.setScreenClass(EntityInspectorBrowser.class);
lookupAction.setScreenOptionsSupplier(() -> new MapScreenOptions(ParamsMap.of("entity", metaProperty.getRange().asClass().getName())));
lookupAction.setOpenMode(OpenMode.THIS_TAB);
pickerField.addAction(lookupAction);
pickerField.addAction(actions.create(EntityClearAction.class));
field = pickerField;
}
field.setValueSource(valueSource);
field.setCaption(getPropertyCaption(metaClass, metaProperty));
field.setRequired(isRequired);
isReadonly = isReadonly || (disabledProperties != null && disabledProperties.contains(metaProperty.getName()));
if (range.isClass() && !metadataTools.isEmbedded(metaProperty)) {
field.setEditable(metadataTools.isOwningSide(metaProperty) && !isReadonly);
} else {
field.setEditable(!isReadonly);
}
field.setWidth(fieldWidth);
if (isRequired) {
field.setRequiredMessage(messageTools.getDefaultRequiredMessage(metaClass, metaProperty.getName()));
}
form.add(field);
}
use of io.jmix.ui.screen.MapScreenOptions in project jmix by jmix-framework.
the class AddToSetAction method actionPerform.
@Override
public void actionPerform(Component component) {
MetaClass entityMetaClass;
if (target.getItems() instanceof EntityDataUnit) {
entityMetaClass = ((EntityDataUnit) target.getItems()).getEntityMetaClass();
} else {
throw new UnsupportedOperationException("Unsupported data unit " + target.getItems());
}
String query;
if (filter.getDatasource() != null) {
query = filter.getDatasource().getQuery();
} else {
query = filter.getDataLoader().getQuery();
}
String[] strings = ValuePathHelper.parse(CubaComponentsHelper.getFilterComponentPath(filter));
String componentId = ValuePathHelper.pathSuffix(strings);
Set ownerSelection = target.getSelected();
Map<String, Object> params = new HashMap<>();
params.put("entityType", entityMetaClass.getName());
params.put("items", ownerSelection);
params.put("componentPath", CubaComponentsHelper.getFilterComponentPath(filter));
params.put("componentId", componentId);
params.put("foldersPane", filterHelper.getFoldersPane());
params.put("entityClass", entityMetaClass.getJavaClass().getName());
params.put("query", query);
params.put("username", userSessionSource.getUserSession().getUser().getUsername());
Screens screens = ComponentsHelper.getScreenContext(filter).getScreens();
screens.create("saveSetInFolder", OpenMode.DIALOG, new MapScreenOptions(params)).show();
}
use of io.jmix.ui.screen.MapScreenOptions in project jmix by jmix-framework.
the class CubaScreens method openLookup.
@Override
public com.haulmont.cuba.gui.components.Window.Lookup openLookup(WindowInfo windowInfo, com.haulmont.cuba.gui.components.Window.Lookup.Handler handler, OpenType openType) {
Map<String, Object> params = createParametersMap(windowInfo, Collections.emptyMap());
MapScreenOptions options = new MapScreenOptions(params);
Screen screen = createScreen(windowInfo, openType.getOpenMode(), options);
applyOpenTypeParameters(screen.getWindow(), openType);
((LookupScreen) screen).setSelectHandler(new SelectHandlerAdapter(handler));
show(screen);
return screen instanceof com.haulmont.cuba.gui.components.Window.Lookup ? (com.haulmont.cuba.gui.components.Window.Lookup) screen : new ScreenLookupWrapper(screen);
}
use of io.jmix.ui.screen.MapScreenOptions in project jmix by jmix-framework.
the class CubaScreens method openEditor.
@Override
public com.haulmont.cuba.gui.components.Window.Editor openEditor(WindowInfo windowInfo, Entity item, OpenType openType) {
Map<String, Object> params = createParametersMap(windowInfo, Collections.singletonMap(WindowParams.ITEM.name(), item));
MapScreenOptions options = new MapScreenOptions(params);
Screen screen = createScreen(windowInfo, openType.getOpenMode(), options);
applyOpenTypeParameters(screen.getWindow(), openType);
EditorScreen editorScreen = (EditorScreen) screen;
editorScreen.setEntityToEdit(item);
show(screen);
return screen instanceof com.haulmont.cuba.gui.components.Window.Editor ? (com.haulmont.cuba.gui.components.Window.Editor) screen : new ScreenEditorWrapper(screen);
}
Aggregations