Search in sources :

Example 41 with GuiDevelopmentException

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());
    }
}
Also used : GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException)

Example 42 with GuiDevelopmentException

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);
}
Also used : GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException) ListComponent(com.haulmont.cuba.gui.components.ListComponent) ListComponent(com.haulmont.cuba.gui.components.ListComponent) Component(com.haulmont.cuba.gui.components.Component)

Example 43 with GuiDevelopmentException

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);
        }
    }
}
Also used : GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException) Component(com.haulmont.cuba.gui.components.Component)

Example 44 with GuiDevelopmentException

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);
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) Column(com.haulmont.cuba.gui.components.DataGrid.Column) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) Element(org.dom4j.Element) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException)

Example 45 with GuiDevelopmentException

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());
        }
    }
}
Also used : GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

GuiDevelopmentException (com.haulmont.cuba.gui.GuiDevelopmentException)55 Element (org.dom4j.Element)23 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)8 Component (com.haulmont.cuba.gui.components.Component)7 Datasource (com.haulmont.cuba.gui.data.Datasource)7 InvocationTargetException (java.lang.reflect.InvocationTargetException)6 MetaClass (com.haulmont.chile.core.model.MetaClass)5 ComponentLoader (com.haulmont.cuba.gui.xml.layout.ComponentLoader)4 MetaProperty (com.haulmont.chile.core.model.MetaProperty)3 MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)3 CategoryAttribute (com.haulmont.cuba.core.entity.CategoryAttribute)3 MetadataTools (com.haulmont.cuba.core.global.MetadataTools)3 WindowConfig (com.haulmont.cuba.gui.config.WindowConfig)3 LayoutLoader (com.haulmont.cuba.gui.xml.layout.LayoutLoader)3 FileDescriptor (com.haulmont.cuba.core.entity.FileDescriptor)2 WindowManager (com.haulmont.cuba.gui.WindowManager)2 Column (com.haulmont.cuba.gui.components.DataGrid.Column)2 ListComponent (com.haulmont.cuba.gui.components.ListComponent)2 DsContext (com.haulmont.cuba.gui.data.DsContext)2 ByteArrayDataProvider (com.haulmont.cuba.gui.export.ByteArrayDataProvider)2