use of io.jmix.ui.theme.ThemeConstantsManager in project jmix by jmix-framework.
the class AbstractTable method initComponent.
protected void initComponent(T component) {
component.setMultiSelect(false);
component.setValidationVisible(false);
component.setShowBufferedSourceException(false);
component.setCustomCellValueFormatter(this::formatCellValue);
component.addValueChangeListener(this::tableSelectionChanged);
component.setSpecificVariablesHandler(this::handleSpecificVariables);
component.setIconProvider(this::getItemIcon);
component.setBeforePaintListener(this::beforeComponentPaint);
component.addColumnReorderListener(this::onColumnReorder);
component.setSortAscendingLabel(messages.getMessage("tableSort.ascending"));
component.setSortResetLabel(messages.getMessage("tableSort.reset"));
component.setSortDescendingLabel(messages.getMessage("tableSort.descending"));
component.setSelectAllLabel(messages.getMessage("tableColumnSelector.selectAll"));
component.setDeselectAllLabel(messages.getMessage("tableColumnSelector.deselectAll"));
int defaultRowHeaderWidth = 16;
ThemeConstantsManager themeConstantsManager = applicationContext.getBean(ThemeConstantsManager.class, ThemeConstantsManager.class);
ThemeConstants theme = themeConstantsManager.getConstants();
if (theme != null) {
defaultRowHeaderWidth = theme.getInt("jmix.ui.Table.defaultRowHeaderWidth", 16);
}
component.setColumnWidth(ROW_HEADER_PROPERTY_ID, defaultRowHeaderWidth);
contextMenuPopup.setParent(component);
component.setContextMenuPopup(contextMenuPopup);
shortcutsDelegate.setAllowEnterShortcut(false);
component.addShortcutListener(new ShortcutListenerDelegate("tableEnter", KeyCode.ENTER, null).withHandler((sender, target) -> {
T tableImpl = AbstractTable.this.component;
AppUI ui = (AppUI) tableImpl.getUI();
if (!ui.isAccessibleForUser(tableImpl)) {
LoggerFactory.getLogger(AbstractTable.class).debug("Ignore click attempt because Table is inaccessible for user");
return;
}
if (target == this.component) {
if (enterPressAction != null) {
enterPressAction.actionPerform(this);
} else {
handleClickAction();
}
}
}));
component.addShortcutListener(new ShortcutListenerDelegate("tableSelectAll", KeyCode.A, new int[] { com.vaadin.event.ShortcutAction.ModifierKey.CTRL }).withHandler((sender, target) -> {
if (target == this.component) {
selectAll();
}
}));
component.addItemClickListener(event -> {
if (event.isDoubleClick() && event.getItem() != null) {
T tableImpl = AbstractTable.this.component;
AppUI ui = (AppUI) tableImpl.getUI();
if (!ui.isAccessibleForUser(tableImpl)) {
LoggerFactory.getLogger(AbstractTable.class).debug("Ignore click attempt because Table is inaccessible for user");
return;
}
handleClickAction();
}
});
component.setAfterUnregisterComponentHandler(this::onAfterUnregisterComponent);
component.setBeforeRefreshRowCacheHandler(this::onBeforeRefreshRowCache);
component.setSelectable(true);
component.setTableFieldFactory(createFieldFactory());
component.setColumnCollapsingAllowed(true);
component.setColumnReorderingAllowed(true);
setEditable(false);
componentComposition = new TableComposition();
componentComposition.setTable(component);
componentComposition.setPrimaryStyleName("jmix-table-composition");
componentComposition.addComponent(component);
component.setCellStyleGenerator(createStyleGenerator());
component.addColumnCollapseListener(this::handleColumnCollapsed);
// force default sizes
componentComposition.setHeightUndefined();
componentComposition.setWidthUndefined();
setClientCaching();
initEmptyState();
}
use of io.jmix.ui.theme.ThemeConstantsManager in project jmix by jmix-framework.
the class DialogWindowImpl method setupDefaultSize.
protected void setupDefaultSize() {
ThemeConstantsManager themeConstantsManager = applicationContext.getBean(ThemeConstantsManager.class);
ThemeConstants theme = themeConstantsManager.getConstants();
dialogWindow.setWidth(theme.get("jmix.ui.WebWindowManager.dialog.width"));
dialogWindow.setHeightUndefined();
component.setWidth(100, Sizeable.Unit.PERCENTAGE);
component.setHeightUndefined();
}
use of io.jmix.ui.theme.ThemeConstantsManager in project jmix by jmix-framework.
the class BulkEditAction method actionPerform.
@Override
public void actionPerform(Component component) {
if (beforeActionPerformedHandler != null && !beforeActionPerformedHandler.beforeActionPerformed()) {
return;
}
Security security = AppBeans.get(Security.class);
if (!security.isSpecificPermitted(BulkEditor.PERMISSION)) {
Messages messages = AppBeans.get(Messages.class);
Notifications notifications = getScreenContext(target.getFrame()).getNotifications();
notifications.create(NotificationType.ERROR).withCaption(messages.getMessage("accessDenied.message")).show();
return;
}
if (target.getSelected().isEmpty()) {
Messages messages = AppBeans.get(Messages.class);
Notifications notifications = getScreenContext(target.getFrame()).getNotifications();
notifications.create(NotificationType.HUMANIZED).withCaption(messages.getMessage("actions.BulkEdit.emptySelection")).show();
return;
}
OpenType openType = this.openType;
if (openType.getOpenMode() == OpenMode.DIALOG) {
ThemeConstantsManager themeManager = AppBeans.get(ThemeConstantsManager.class);
ThemeConstants theme = themeManager.getConstants();
openType = openType.copy().width(theme.get("cuba.gui.BulkEditAction.editorDialog.width")).height(theme.get("cuba.gui.BulkEditAction.editorDialog.height")).resizable(true);
}
Map<String, Object> params = ParamsMap.of().pair("metaClass", target.getDatasource().getMetaClass()).pair("selected", target.getSelected()).pair("exclude", exclude).pair("includeProperties", includeProperties != null ? includeProperties : Collections.EMPTY_LIST).pair("fieldValidators", fieldValidators).pair("modelValidators", modelValidators).pair("loadDynamicAttributes", loadDynamicAttributes).pair("useConfirmDialog", useConfirmDialog).pair("columnsMode", columnsMode).create();
WindowManager wm = ((WindowManager) getScreenContext(target.getFrame()).getScreens());
WindowInfo windowInfo = AppBeans.get(WindowConfig.class).getWindowInfo("bulkEditor");
Window bulkEditor = wm.openWindow(windowInfo, openType, params);
bulkEditor.addCloseListener(actionId -> {
if (Window.COMMIT_ACTION_ID.equals(actionId)) {
target.getDatasource().refresh();
}
if (target instanceof Component.Focusable) {
((Component.Focusable) target).focus();
}
});
}
use of io.jmix.ui.theme.ThemeConstantsManager in project jmix by jmix-framework.
the class UiControllerDependencyInjector method getInjectedInstance.
@Nullable
protected Object getInjectedInstance(Class<?> type, String name, InjectElement injectElement, FrameOwner frameOwner, ScreenOptions options) {
AnnotatedElement element = injectElement.getElement();
Class annotationClass = injectElement.getAnnotationClass();
Frame frame = UiControllerUtils.getFrame(frameOwner);
if (annotationClass == WindowParam.class) {
if (options instanceof MapScreenOptions) {
return ((MapScreenOptions) options).getParams().get(name);
}
// Injecting a parameter
return null;
} else if (ScreenFragment.class.isAssignableFrom(type)) {
// Injecting inner fragment controller
Component fragment = frame.getComponent(name);
if (fragment == null) {
return null;
}
return ((Fragment) fragment).getFrameOwner();
} else if (Component.class.isAssignableFrom(type)) {
// / if legacy frame - inject controller
Component component = frame.getComponent(name);
if (component instanceof Fragment) {
ScreenFragment fragmentFrameOwner = ((Fragment) component).getFrameOwner();
if (type.isAssignableFrom(fragmentFrameOwner.getClass())) {
return fragmentFrameOwner;
}
}
// Injecting a UI component
return component;
} else if (InstanceContainer.class.isAssignableFrom(type)) {
// Injecting a container
ScreenData data = getScreenData(frameOwner);
return data.getContainer(name);
} else if (DataLoader.class.isAssignableFrom(type)) {
// Injecting a loader
ScreenData data = getScreenData(frameOwner);
return data.getLoader(name);
} else if (DataContext.class.isAssignableFrom(type)) {
// Injecting the data context
ScreenData data = getScreenData(frameOwner);
return data.getDataContext();
} else if (FrameContext.class.isAssignableFrom(type)) {
// Injecting the FrameContext
return frame.getContext();
} else if (Action.class.isAssignableFrom(type)) {
// Injecting an action
return ComponentsHelper.findAction(name, frame);
} else if (Facet.class.isAssignableFrom(type)) {
// Injecting non-visual component
String[] elements = ValuePathHelper.parse(name);
if (elements.length == 1) {
return frame.getFacet(name);
}
String prefix = pathPrefix(elements);
Component component = frame.getComponent(prefix);
if (component == null) {
return null;
}
if (!(component instanceof Fragment)) {
throw new UnsupportedOperationException(String.format("Unable to inject facet with id %s and type %s. Component %s is not a fragment", name, type, prefix));
}
String facetId = elements[elements.length - 1];
return ((Fragment) component).getFacet(facetId);
} else if (Downloader.class.isAssignableFrom(type)) {
// Injecting a Downloader
return applicationContext.getBean(Downloader.class);
} else if (MessageBundle.class == type) {
return createMessageBundle(element, frameOwner, frame);
} else if (ThemeConstants.class == type) {
// Injecting a Theme
ThemeConstantsManager themeManager = applicationContext.getBean(ThemeConstantsManager.class);
return themeManager.getConstants();
} else if (BeanFactory.class.isAssignableFrom(type)) {
return applicationContext;
} else if (ObjectProvider.class.isAssignableFrom(type)) {
if (!(element instanceof Field && ((Field) element).getGenericType() instanceof ParameterizedType) && !(element instanceof Method && ((Method) element).getGenericParameterTypes().length > 0 && ((Method) element).getGenericParameterTypes()[0] instanceof ParameterizedType)) {
throw new UnsupportedOperationException("Unable to inject ObjectProvider without generic parameter");
}
Type genericType;
if (element instanceof Field) {
genericType = ((ParameterizedType) ((Field) element).getGenericType()).getActualTypeArguments()[0];
} else {
genericType = ((ParameterizedType) ((Method) element).getGenericParameterTypes()[0]).getActualTypeArguments()[0];
}
if (genericType instanceof ParameterizedType) {
genericType = ((ParameterizedType) genericType).getRawType();
}
return applicationContext.getBeanProvider((Class<?>) genericType);
} else if (ActionsAwareDialogFacet.DialogAction.class.isAssignableFrom(type)) {
// facet's action
Facet facet;
String actionId;
String[] path = ValuePathHelper.parse(name);
if (path.length == 2) {
facet = frame.getFacet(path[0]);
actionId = path[1];
} else {
String prefix = ValuePathHelper.pathPrefix(path, 2);
Component component = frame.getComponent(prefix);
if (component == null) {
return null;
}
if (!(component instanceof Fragment)) {
throw new UnsupportedOperationException(String.format("Unable to inject dialog action with id '%s'. Component '%s' is not a fragment", name, prefix));
}
actionId = path[path.length - 1];
facet = ((Fragment) component).getFacet(path[path.length - 2]);
}
if (!(facet instanceof ActionsAwareDialogFacet)) {
return null;
}
// noinspection unchecked
Collection<ActionsAwareDialogFacet.DialogAction<Facet>> actions = ((ActionsAwareDialogFacet<Facet>) facet).getActions();
if (CollectionUtils.isNotEmpty(actions)) {
return actions.stream().filter(action -> action.getId().equals(actionId)).findFirst().orElse(null);
}
} else {
Object instance;
// Try to find a Spring bean
Map<String, ?> beans = applicationContext.getBeansOfType(type);
if (!beans.isEmpty()) {
instance = beans.get(name);
// If a bean with required name found, return it
if (instance != null) {
return instance;
} else {
// Otherwise get a bean from the context again to respect @Primary annotation
return applicationContext.getBean(type);
}
}
}
return null;
}
use of io.jmix.ui.theme.ThemeConstantsManager in project jmix by jmix-framework.
the class ScreenXmlParser method replaceAssignParameters.
protected void replaceAssignParameters(Document document) {
Map<String, String> assignedParams = new HashMap<>();
List<Element> assignElements = document.getRootElement().elements("assign");
ThemeConstantsManager themeManager = this.themeConstantsManager;
for (Element assignElement : assignElements) {
String name = assignElement.attributeValue("name");
if (StringUtils.isEmpty(name)) {
throw new RuntimeException("'name' attribute of assign tag is empty");
}
String value = assignElement.attributeValue("value");
if (StringUtils.isEmpty(value)) {
throw new RuntimeException("'value' attribute of assign tag is empty");
}
if (StringUtils.startsWith(value, ThemeConstants.PREFIX)) {
ThemeConstants theme = themeManager.getConstants();
value = theme.get(value.substring(ThemeConstants.PREFIX.length()));
}
assignedParams.put(name, value);
}
if (!assignedParams.isEmpty()) {
Element layoutElement = document.getRootElement().element("layout");
if (layoutElement != null) {
Dom4j.walkAttributesRecursive(layoutElement, (element, attribute) -> {
String attributeValue = attribute.getValue();
if (StringUtils.isNotEmpty(attributeValue) && attributeValue.startsWith("${") && attributeValue.endsWith("}")) {
String paramKey = attributeValue.substring(2, attributeValue.length() - 1);
String assignedValue = assignedParams.get(paramKey);
if (assignedValue == null) {
throw new RuntimeException("Unable to find value of assign param: " + paramKey);
}
attribute.setValue(assignedValue);
}
});
}
}
}
Aggregations