Search in sources :

Example 76 with Component

use of io.jmix.ui.component.Component in project jmix by jmix-framework.

the class FileMultiUploadFieldLoader method loadDropZone.

protected void loadDropZone(UploadField uploadField, Element element) {
    String dropZoneId = element.attributeValue("dropZone");
    if (StringUtils.isNotEmpty(dropZoneId)) {
        Component dropZone = findComponent(dropZoneId);
        if (dropZone instanceof BoxLayout) {
            uploadField.setDropZone(new UploadField.DropZone((BoxLayout) dropZone));
        } else if (dropZone != null) {
            throw new GuiDevelopmentException("Unsupported dropZone class " + dropZone.getClass().getName(), context);
        } else {
            throw new GuiDevelopmentException("Unable to find dropZone component with id: " + dropZoneId, context);
        }
    }
    String dropZonePrompt = element.attributeValue("dropZonePrompt");
    if (StringUtils.isNotEmpty(dropZonePrompt)) {
        uploadField.setDropZonePrompt(loadResourceString(dropZonePrompt));
    }
}
Also used : BoxLayout(io.jmix.ui.component.BoxLayout) UploadField(io.jmix.ui.component.UploadField) FileMultiUploadField(io.jmix.ui.component.FileMultiUploadField) GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException) Component(io.jmix.ui.component.Component)

Example 77 with Component

use of io.jmix.ui.component.Component in project jmix by jmix-framework.

the class DeclarativeColumnGenerator method findGeneratorMethod.

// Find method with one parameter of type extends Entity and result extends Component
@Nullable
protected Method findGeneratorMethod(Class cls, String methodName) {
    Method exactMethod = MethodUtils.getAccessibleMethod(cls, methodName, Entity.class);
    if (exactMethod != null) {
        return exactMethod;
    }
    // search through all methods
    Method[] methods = cls.getMethods();
    for (Method availableMethod : methods) {
        if (availableMethod.getName().equals(methodName)) {
            if (availableMethod.getParameterCount() == 1 && Component.class.isAssignableFrom(availableMethod.getReturnType())) {
                if (Entity.class.isAssignableFrom(availableMethod.getParameterTypes()[0])) {
                    // get accessible version of method
                    return MethodUtils.getAccessibleMethod(availableMethod);
                }
            }
        }
    }
    return null;
}
Also used : Method(java.lang.reflect.Method) Component(io.jmix.ui.component.Component) Nullable(javax.annotation.Nullable)

Example 78 with Component

use of io.jmix.ui.component.Component in project jmix by jmix-framework.

the class UiControllerPropertyInjector method findComponent.

@Nullable
protected Component findComponent(String componentId) {
    Component component = null;
    Window window = null;
    if (sourceScreen != null) {
        window = sourceScreen.getWindow();
    } else if (frameOwner instanceof ScreenFragment) {
        FrameOwner host = ((ScreenFragment) frameOwner).getHostController();
        if (host instanceof Screen) {
            window = ((Screen) host).getWindow();
        }
    } else if (frameOwner instanceof Screen) {
        window = ((Screen) frameOwner).getWindow();
    }
    if (window != null) {
        component = window.getComponent(componentId);
    }
    return component;
}
Also used : Window(io.jmix.ui.component.Window) ScreenFragment(io.jmix.ui.screen.ScreenFragment) FrameOwner(io.jmix.ui.screen.FrameOwner) Screen(io.jmix.ui.screen.Screen) Component(io.jmix.ui.component.Component) Nullable(javax.annotation.Nullable)

Example 79 with Component

use of io.jmix.ui.component.Component in project jmix by jmix-framework.

the class GridLayoutLoader method createSubComponents.

protected void createSubComponents(GridLayout gridLayout, Element element, int row) {
    LayoutLoader loader = getLayoutLoader();
    int col = 0;
    for (Element subElement : element.elements()) {
        ComponentLoader componentLoader = loader.createComponent(subElement);
        pendingLoadComponents.add(componentLoader);
        Component subComponent = componentLoader.getResultComponent();
        String colspan = subElement.attributeValue("colspan");
        String rowspan = subElement.attributeValue("rowspan");
        if (col >= spanMatrix.length) {
            Map<String, Object> params = new HashMap<>();
            params.put("Grid ID", gridLayout.getId());
            String rowId = element.attributeValue("id");
            if (StringUtils.isNotEmpty(rowId)) {
                params.put("Row ID", rowId);
            } else {
                params.put("Row Index", row);
            }
            throw new GuiDevelopmentException("Grid column count is less than number of components in grid row", context, params);
        }
        while (spanMatrix[col][row]) {
            col++;
        }
        if (StringUtils.isEmpty(colspan) && StringUtils.isEmpty(rowspan)) {
            addSubComponent(gridLayout, subComponent, col, row, col, row);
        } else {
            int cSpan = 1;
            int rSpan = 1;
            if (StringUtils.isNotEmpty(colspan)) {
                cSpan = Integer.parseInt(colspan);
                if (cSpan < 1) {
                    throw new GuiDevelopmentException("GridLayout colspan can not be less than 1", context, "colspan", cSpan);
                }
                if (cSpan == 1) {
                    LoggerFactory.getLogger(GridLayoutLoader.class).warn("Do not use colspan=\"1\", it will have no effect");
                }
            }
            if (StringUtils.isNotEmpty(rowspan)) {
                rSpan = Integer.parseInt(rowspan);
                if (rSpan < 1) {
                    throw new GuiDevelopmentException("GridLayout rowspan can not be less than 1", context, "rowspan", rSpan);
                }
                if (rSpan == 1) {
                    LoggerFactory.getLogger(GridLayoutLoader.class).warn("Do not use rowspan=\"1\", it will have no effect");
                }
            }
            fillSpanMatrix(col, row, cSpan, rSpan);
            int endColumn = col + cSpan - 1;
            int endRow = row + rSpan - 1;
            addSubComponent(gridLayout, subComponent, col, row, endColumn, endRow);
        }
        col++;
    }
}
Also used : HashMap(java.util.HashMap) Element(org.dom4j.Element) GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException) Component(io.jmix.ui.component.Component) ComponentLoader(io.jmix.ui.xml.layout.ComponentLoader)

Example 80 with Component

use of io.jmix.ui.component.Component in project jmix by jmix-framework.

the class AbstractAssignActionPostInitTask method execute.

@Override
public void execute(ComponentLoader.ComponentContext context, Frame frame) {
    String[] elements = ValuePathHelper.parse(actionId);
    if (elements.length > 1) {
        String id = elements[elements.length - 1];
        // using this.frame to look up the component inside the actual frame
        String prefix = ValuePathHelper.pathPrefix(elements);
        Component holder = this.frame.getComponent(prefix);
        if (holder == null) {
            throw new GuiDevelopmentException(String.format("Can't find component: %s for action: %s", prefix, actionId), context, "Component ID", prefix);
        }
        if (!(holder instanceof ActionsHolder)) {
            throw new GuiDevelopmentException(String.format("Component '%s' can't contain actions", holder.getId()), context, "Holder ID", holder.getId());
        }
        Action action = ((ActionsHolder) holder).getAction(id);
        if (action == null) {
            throw new GuiDevelopmentException(String.format("Can't find action '%s' in '%s'", id, holder.getId()), context, "Holder ID", holder.getId());
        }
        addAction(action);
    } else if (elements.length == 1) {
        String id = elements[0];
        Action action = getActionRecursively(this.frame, id);
        if (action == null) {
            if (!hasOwnAction(id)) {
                String message = getExceptionMessage(id);
                throw new GuiDevelopmentException(message, context.getFullFrameId());
            }
        } else {
            addAction(action);
        }
    } else {
        throw new GuiDevelopmentException("Empty action name", context.getFullFrameId());
    }
}
Also used : Action(io.jmix.ui.action.Action) ActionsHolder(io.jmix.ui.component.ActionsHolder) GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException) Component(io.jmix.ui.component.Component)

Aggregations

Component (io.jmix.ui.component.Component)81 GuiDevelopmentException (io.jmix.ui.GuiDevelopmentException)16 Datasource (com.haulmont.cuba.gui.data.Datasource)12 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)11 Test (org.junit.jupiter.api.Test)11 Element (org.dom4j.Element)10 Consumer (java.util.function.Consumer)9 ListComponent (com.haulmont.cuba.gui.components.ListComponent)8 MetaClass (io.jmix.core.metamodel.model.MetaClass)7 Action (io.jmix.ui.action.Action)7 HasValue (io.jmix.ui.component.HasValue)7 FrameOwner (io.jmix.ui.screen.FrameOwner)7 ArrayList (java.util.ArrayList)7 DatasourceImpl (com.haulmont.cuba.gui.data.impl.DatasourceImpl)6 FetchPlan (io.jmix.core.FetchPlan)6 UUID (java.util.UUID)6 Nullable (javax.annotation.Nullable)6 User (com.haulmont.cuba.core.model.common.User)5 DsBuilder (com.haulmont.cuba.gui.data.DsBuilder)5 Entity (io.jmix.core.Entity)5