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));
}
}
}
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;
}
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));
}
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));
}
}
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++;
}
}
Aggregations