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