use of com.haulmont.cuba.gui.theme.ThemeConstantsManager in project cuba by cuba-platform.
the class ScreenXmlParser method replaceAssignParameters.
protected void replaceAssignParameters(Document document) {
Map<String, String> assignedParams = new HashMap<>();
List<Element> assignElements = Dom4j.elements(document.getRootElement(), "assign");
ThemeConstantsManager themeManager = AppBeans.get(ThemeConstantsManager.NAME);
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);
}
});
}
}
}
use of com.haulmont.cuba.gui.theme.ThemeConstantsManager in project cuba by cuba-platform.
the class BulkEditAction method actionPerform.
@Override
public void actionPerform(Component component) {
if (beforeActionPerformedHandler != null) {
if (!beforeActionPerformedHandler.beforeActionPerformed())
return;
}
if (!userSession.isSpecificPermitted(BulkEditor.PERMISSION)) {
target.getFrame().showNotification(messages.getMainMessage("accessDenied.message"), Frame.NotificationType.ERROR);
return;
}
if (target.getSelected().isEmpty()) {
target.getFrame().showNotification(messages.getMainMessage("actions.BulkEdit.emptySelection"), Frame.NotificationType.HUMANIZED);
return;
}
if (openType.getOpenMode() == OpenMode.DIALOG) {
ThemeConstantsManager themeManager = AppBeans.get(ThemeConstantsManager.NAME);
ThemeConstants theme = themeManager.getConstants();
target.getFrame().getDialogParams().setWidth(theme.get("cuba.gui.BulkEditAction.editorDialog.width")).setHeight(theme.get("cuba.gui.BulkEditAction.editorDialog.height")).setResizable(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).create();
Window bulkEditor = target.getFrame().openWindow("bulkEditor", openType, params);
bulkEditor.addCloseListener(actionId -> {
if (Window.COMMIT_ACTION_ID.equals(actionId)) {
target.getDatasource().refresh();
}
target.requestFocus();
});
}
use of com.haulmont.cuba.gui.theme.ThemeConstantsManager in project cuba by cuba-platform.
the class ControllerDependencyInjector method getInjectedInstance.
protected Object getInjectedInstance(Class<?> type, String name, Class annotationClass, AnnotatedElement element) {
if (annotationClass == WindowParam.class) {
// Injecting a parameter
return params.get(name);
} else if (Component.class.isAssignableFrom(type)) {
// Injecting a UI component
return frame.getComponent(name);
} else if (Datasource.class.isAssignableFrom(type)) {
// Injecting a datasource
return frame.getDsContext().get(name);
} else if (DsContext.class.isAssignableFrom(type)) {
// Injecting the DsContext
return frame.getDsContext();
} else if (DataSupplier.class.isAssignableFrom(type)) {
// Injecting the DataSupplier
return frame.getDsContext().getDataSupplier();
} 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 (ExportDisplay.class.isAssignableFrom(type)) {
// Injecting an ExportDisplay
return AppConfig.createExportDisplay(frame);
} else if (ThemeConstants.class.isAssignableFrom(type)) {
// Injecting a Theme
ThemeConstantsManager themeManager = (ThemeConstantsManager) applicationContext.getBean(ThemeConstantsManager.NAME);
return themeManager.getConstants();
} else if (Config.class.isAssignableFrom(type)) {
ClientConfiguration configuration = (ClientConfiguration) applicationContext.getBean(Configuration.NAME);
// noinspection unchecked
return configuration.getConfigCached((Class<? extends Config>) type);
} else if (Logger.class == type && element instanceof Field) {
return LoggerFactory.getLogger(((Field) element).getDeclaringClass());
} else {
Object instance;
// Try to find a Spring bean
Map<String, ?> beans = applicationContext.getBeansOfType(type, true, true);
if (!beans.isEmpty()) {
instance = beans.get(name);
// If a bean with required name found, return it. Otherwise return first found.
if (instance != null) {
return instance;
} else {
return beans.values().iterator().next();
}
}
// There are no Spring beans of required type - the last option is Companion
if (frame instanceof AbstractFrame) {
instance = ((AbstractFrame) frame).getCompanion();
if (instance != null && type.isAssignableFrom(instance.getClass())) {
return instance;
}
}
}
return null;
}
Aggregations