Search in sources :

Example 1 with Component

use of com.haulmont.cuba.gui.components.Component in project cuba by cuba-platform.

the class DeclarativeAction method actionPerform.

@Override
public void actionPerform(Component component) {
    if (StringUtils.isEmpty(methodName)) {
        return;
    }
    Object controller = ComponentsHelper.getFrameController(frame);
    Method method;
    try {
        method = controller.getClass().getMethod(methodName, Component.class);
        try {
            method.invoke(controller, component);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    } catch (NoSuchMethodException e) {
        try {
            method = controller.getClass().getMethod(methodName);
            try {
                method.invoke(controller);
            } catch (Exception e1) {
                throw new RuntimeException(e1);
            }
        } catch (NoSuchMethodException e1) {
            throw new IllegalStateException(String.format("No suitable methods named %s for action %s", methodName, id));
        }
    }
}
Also used : Method(java.lang.reflect.Method) Component(com.haulmont.cuba.gui.components.Component)

Example 2 with Component

use of com.haulmont.cuba.gui.components.Component in project cuba by cuba-platform.

the class DeclarativeColumnGenerator method findGeneratorMethod.

// Find method with one parameter of type extends Entity and result extends Component
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(com.haulmont.cuba.gui.components.Component)

Example 3 with Component

use of com.haulmont.cuba.gui.components.Component in project cuba by cuba-platform.

the class DeclarativeFieldGenerator method generateField.

@Override
public Component generateField(Datasource datasource, String propertyId) {
    Frame frame = fieldGroup.getFrame();
    if (frame == null) {
        throw new IllegalStateException("Table should be attached to frame");
    }
    Frame controller = ComponentsHelper.getFrameController(frame);
    Class<? extends Frame> cCls = controller.getClass();
    Method exactMethod = getAccessibleMethod(cCls, methodName, new Class[] { Datasource.class, String.class });
    if (exactMethod != null) {
        checkGeneratorMethodResultType(exactMethod, frame);
        try {
            return (Component) exactMethod.invoke(controller, datasource, propertyId);
        } catch (Exception e) {
            throw new RuntimeException("Exception in declarative FieldGroup Field generator " + methodName, e);
        }
    }
    Method dsMethod = getAccessibleMethod(cCls, methodName, new Class[] { Datasource.class });
    if (dsMethod != null) {
        checkGeneratorMethodResultType(dsMethod, frame);
        try {
            return (Component) dsMethod.invoke(controller, datasource);
        } catch (Exception e) {
            throw new RuntimeException("Exception in declarative FieldGroup Field generator " + methodName, e);
        }
    }
    Method parameterLessMethod = getAccessibleMethod(cCls, methodName, new Class[] {});
    if (parameterLessMethod != null) {
        checkGeneratorMethodResultType(parameterLessMethod, frame);
        try {
            return (Component) parameterLessMethod.invoke(controller);
        } catch (Exception e) {
            throw new RuntimeException("Exception in declarative FieldGroup Field generator " + methodName, e);
        }
    }
    String fieldGroupId = fieldGroup.getId() == null ? "" : fieldGroup.getId();
    throw new IllegalStateException(String.format("No suitable method named %s for column generator of table %s", methodName, fieldGroupId));
}
Also used : Frame(com.haulmont.cuba.gui.components.Frame) MethodUtils.getAccessibleMethod(org.apache.commons.lang.reflect.MethodUtils.getAccessibleMethod) Method(java.lang.reflect.Method) Component(com.haulmont.cuba.gui.components.Component) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException)

Example 4 with Component

use of com.haulmont.cuba.gui.components.Component in project cuba by cuba-platform.

the class FileUploadFieldLoader method loadDropZone.

protected void loadDropZone(UploadField uploadField, Element element) {
    String dropZoneId = element.attributeValue("dropZone");
    if (StringUtils.isNotEmpty(dropZoneId)) {
        Component dropZone = context.getFrame().getComponent(dropZoneId);
        if (dropZone instanceof BoxLayout) {
            uploadField.setDropZone(new UploadField.DropZone((BoxLayout) dropZone));
        } else if (dropZone != null) {
            log.warn("Unsupported dropZone class {}", dropZone.getClass().getName());
        } else {
            log.warn("Unable to find dropZone component with id: {}", dropZoneId);
        }
    }
    String dropZonePrompt = element.attributeValue("dropZonePrompt");
    if (StringUtils.isNotEmpty(dropZonePrompt)) {
        uploadField.setDropZonePrompt(loadResourceString(dropZonePrompt));
    }
}
Also used : BoxLayout(com.haulmont.cuba.gui.components.BoxLayout) UploadField(com.haulmont.cuba.gui.components.UploadField) FileUploadField(com.haulmont.cuba.gui.components.FileUploadField) Component(com.haulmont.cuba.gui.components.Component)

Example 5 with Component

use of com.haulmont.cuba.gui.components.Component in project cuba by cuba-platform.

the class GridLayoutLoader method createSubComponents.

protected void createSubComponents(GridLayout gridLayout, Element element, int row) {
    LayoutLoader loader = new LayoutLoader(context, factory, layoutLoaderConfig);
    loader.setLocale(getLocale());
    loader.setMessagesPack(getMessagesPack());
    int col = 0;
    // noinspection unchecked
    for (Element subElement : (Collection<Element>) 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.getFullFrameId(), 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.getFullFrameId(), "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.getFullFrameId(), "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 : LayoutLoader(com.haulmont.cuba.gui.xml.layout.LayoutLoader) Element(org.dom4j.Element) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException) Component(com.haulmont.cuba.gui.components.Component) ComponentLoader(com.haulmont.cuba.gui.xml.layout.ComponentLoader)

Aggregations

Component (com.haulmont.cuba.gui.components.Component)78 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)10 Datasource (com.haulmont.cuba.gui.data.Datasource)10 User (com.haulmont.cuba.security.entity.User)9 List (java.util.List)9 GuiDevelopmentException (com.haulmont.cuba.gui.GuiDevelopmentException)8 ArrayList (java.util.ArrayList)8 UUID (java.util.UUID)8 LookupPickerField (com.haulmont.cuba.gui.components.LookupPickerField)7 Group (com.haulmont.cuba.security.entity.Group)7 Assert.assertEquals (org.junit.Assert.assertEquals)7 Assert.assertNotNull (org.junit.Assert.assertNotNull)7 Assert.assertTrue (org.junit.Assert.assertTrue)7 Ignore (org.junit.Ignore)7 Test (org.junit.Test)7 Element (org.dom4j.Element)6 ButtonTabComponent (com.haulmont.cuba.desktop.sys.ButtonTabComponent)5 AbstractAction (com.haulmont.cuba.gui.components.AbstractAction)5 Frame (com.haulmont.cuba.gui.components.Frame)4 AbstractComponent (com.vaadin.ui.AbstractComponent)4