use of com.haulmont.cuba.gui.GuiDevelopmentException in project cuba by cuba-platform.
the class AssignActionPostInitTask method execute.
@Override
public void execute(ComponentLoader.Context context, Frame window) {
String[] elements = ValuePathHelper.parse(actionName);
if (elements.length > 1) {
final String id = elements[elements.length - 1];
String[] subPath = (String[]) ArrayUtils.subarray(elements, 0, elements.length - 1);
// using this.frame to look up the component inside the actual frame
Component holder = this.frame.getComponent(ValuePathHelper.format(subPath));
if (holder == null) {
throw new GuiDevelopmentException("Can't find component: " + Arrays.toString(subPath) + " for action: " + actionName, context.getFullFrameId(), "Component ID", Arrays.toString(subPath));
}
if (!(holder instanceof Component.ActionsHolder)) {
throw new GuiDevelopmentException(String.format("Component '%s' can't contain actions", holder.getId()), context.getFullFrameId(), "Holder ID", holder.getId());
}
Action action = ((Component.ActionsHolder) holder).getAction(id);
if (action == null) {
throw new GuiDevelopmentException(String.format("Can't find action '%s' in '%s'", id, holder.getId()), context.getFullFrameId(), "Holder ID", holder.getId());
}
this.component.setAction(action);
} else if (elements.length == 1) {
final String id = elements[0];
Action action = getActionRecursively(frame, id);
if (action == null) {
String message = "Can't find action " + id;
if (Window.Editor.WINDOW_COMMIT.equals(id) || Window.Editor.WINDOW_COMMIT_AND_CLOSE.equals(id))
message += ". This may happen if you are opening an AbstractEditor-based screen by openWindow() method, " + "for example from the main menu. Use openEditor() method or give the screen a name ended " + "with '.edit' to open it as editor from the main menu.";
throw new GuiDevelopmentException(message, context.getFullFrameId());
}
this.component.setAction(action);
} else {
throw new GuiDevelopmentException("Empty action name", context.getFullFrameId());
}
}
use of com.haulmont.cuba.gui.GuiDevelopmentException in project cuba by cuba-platform.
the class BulkEditorLoader method loadComponent.
@Override
public void loadComponent() {
assignXmlDescriptor(resultComponent, element);
assignFrame(resultComponent);
loadEnable(resultComponent, element);
loadVisible(resultComponent, element);
loadStyleName(resultComponent, element);
loadCaption(resultComponent, element);
loadDescription(resultComponent, element);
loadIcon(resultComponent, element);
loadWidth(resultComponent, element);
loadAlign(resultComponent, element);
loadResponsive(resultComponent, element);
loadTabIndex(resultComponent, element);
if (!userSessionSource.getUserSession().isSpecificPermitted(BulkEditor.PERMISSION)) {
resultComponent.setVisible(false);
}
String openType = element.attributeValue("openType");
if (StringUtils.isNotEmpty(openType)) {
resultComponent.setOpenType(WindowManager.OpenType.valueOf(openType));
}
String exclude = element.attributeValue("exclude");
String includeProperties = element.attributeValue("includeProperties");
if (StringUtils.isNotBlank(exclude) && StringUtils.isNotBlank(includeProperties)) {
throw new GuiDevelopmentException("BulkEditor cannot define simultaneously exclude and includeProperties attributes", getContext().getCurrentFrameId());
}
if (StringUtils.isNotBlank(exclude)) {
resultComponent.setExcludePropertiesRegex(exclude.replace(" ", ""));
}
if (StringUtils.isNotBlank(includeProperties)) {
resultComponent.setIncludeProperties(Splitter.on(',').omitEmptyStrings().trimResults().splitToList(includeProperties));
}
String listComponent = element.attributeValue("for");
if (StringUtils.isEmpty(listComponent)) {
throw new GuiDevelopmentException("'for' attribute of bulk editor is not specified", context.getFullFrameId(), "componentId", resultComponent.getId());
}
String loadDynamicAttributes = element.attributeValue("loadDynamicAttributes");
if (StringUtils.isNotEmpty(loadDynamicAttributes)) {
resultComponent.setLoadDynamicAttributes(Boolean.parseBoolean(loadDynamicAttributes));
}
context.addPostInitTask((context1, window) -> {
// todo artamonov here we can use post wrap instead of post init
if (resultComponent.getListComponent() == null) {
Component bindComponent = resultComponent.getFrame().getComponent(listComponent);
if (!(bindComponent instanceof ListComponent)) {
throw new GuiDevelopmentException("Specify 'for' attribute: id of table or tree", context1.getFullFrameId(), "componentId", resultComponent.getId());
}
resultComponent.setListComponent((ListComponent) bindComponent);
}
});
loadValidators(resultComponent, element);
loadFocusable(resultComponent, element);
}
use of com.haulmont.cuba.gui.GuiDevelopmentException in project cuba by cuba-platform.
the class ContainerLoader method loadSubComponentsAndExpand.
protected void loadSubComponentsAndExpand(ExpandingLayout layout, Element element) {
loadSubComponents();
String expand = element.attributeValue("expand");
if (!StringUtils.isEmpty(expand)) {
String[] parts = expand.split(";");
String targetId = parts[0];
Component componentToExpand = layout.getOwnComponent(targetId);
if (componentToExpand != null) {
String height = find(parts, "height");
String width = find(parts, "width");
layout.expand(componentToExpand, height, width);
} else {
throw new GuiDevelopmentException("Illegal expand target '" + targetId + "' for container", context.getFullFrameId(), "component", targetId);
}
}
}
use of com.haulmont.cuba.gui.GuiDevelopmentException in project cuba by cuba-platform.
the class DataGridLoader method loadComponent.
@Override
public void loadComponent() {
assignXmlDescriptor(resultComponent, element);
assignFrame(resultComponent);
loadEnable(resultComponent, element);
loadVisible(resultComponent, element);
loadSettingsEnabled(resultComponent, element);
loadAlign(resultComponent, element);
loadStyleName(resultComponent, element);
loadHeight(resultComponent, element);
loadWidth(resultComponent, element);
loadIcon(resultComponent, element);
loadCaption(resultComponent, element);
loadDescription(resultComponent, element);
loadEditorEnabled(resultComponent, element);
loadEditorBuffered(resultComponent, element);
loadEditorSaveCaption(resultComponent, element);
loadEditorCancelCaption(resultComponent, element);
loadActions(resultComponent, element);
loadContextMenuEnabled(resultComponent, element);
loadColumnsHidingAllowed(resultComponent, element);
loadColumnResizeMode(resultComponent, element);
loadSortable(resultComponent, element);
loadResponsive(resultComponent, element);
loadReorderingAllowed(resultComponent, element);
loadHeaderVisible(resultComponent, element);
loadTextSelectionEnabled(resultComponent, element);
Element columnsElement = element.element("columns");
loadButtonsPanel(resultComponent);
// must be before datasource setting
loadRowsCount(resultComponent, element);
String datasource = element.attributeValue("datasource");
if (StringUtils.isBlank(datasource)) {
throw new GuiDevelopmentException("DataGrid element doesn't have 'datasource' attribute", context.getCurrentFrameId(), "DataGrid ID", element.attributeValue("id"));
}
Datasource ds = context.getDsContext().get(datasource);
if (ds == null) {
throw new GuiDevelopmentException("Can't find datasource by name: " + datasource, context.getCurrentFrameId());
}
if (!(ds instanceof CollectionDatasource)) {
throw new GuiDevelopmentException("Not a CollectionDatasource: " + datasource, context.getCurrentFrameId());
}
CollectionDatasource cds = (CollectionDatasource) ds;
List<Column> availableColumns;
if (columnsElement != null) {
availableColumns = loadColumns(resultComponent, columnsElement, cds);
} else {
availableColumns = new ArrayList<>();
}
addDynamicAttributes(resultComponent, ds, availableColumns);
resultComponent.setDatasource(cds);
loadSelectionMode(resultComponent, element);
loadFrozenColumnCount(resultComponent, element);
loadTabIndex(resultComponent, element);
}
use of com.haulmont.cuba.gui.GuiDevelopmentException in project cuba by cuba-platform.
the class DatePickerLoader method loadRangeStart.
protected void loadRangeStart(DatePicker resultComponent, Element element) {
String rangeStart = element.attributeValue("rangeStart");
if (StringUtils.isNotEmpty(rangeStart)) {
try {
SimpleDateFormat rangeDF = new SimpleDateFormat(DATE_PATTERN);
resultComponent.setRangeStart(rangeDF.parse(rangeStart));
} catch (ParseException e) {
throw new GuiDevelopmentException("'rangeStart' parsing error for date picker: " + rangeStart, context.getFullFrameId(), "DatePicker ID", resultComponent.getId());
}
}
}
Aggregations