Search in sources :

Example 6 with DevelopmentException

use of io.jmix.core.DevelopmentException in project jmix by jmix-framework.

the class EditorScreenFacetImpl method createEditorBuilder.

@SuppressWarnings("unchecked")
protected EditorBuilder<E> createEditorBuilder(Frame owner, @Nullable E entityToEdit) {
    EditorBuilder<E> builder;
    ScreenBuilders screenBuilders = applicationContext.getBean(ScreenBuilders.class);
    if (entityClass != null) {
        builder = screenBuilders.editor(entityClass, owner.getFrameOwner());
    } else if (entityToEdit != null) {
        builder = (EditorBuilder<E>) screenBuilders.editor(entityToEdit.getClass(), owner.getFrameOwner());
    } else if (listComponent != null) {
        builder = screenBuilders.editor(listComponent);
    } else if (entityPicker != null) {
        builder = screenBuilders.editor(entityPicker);
    } else {
        throw new IllegalStateException("Unable to create EditorScreenFacet. At least one of entityClass," + "listComponent or field must be specified");
    }
    if (editMode == EditMode.CREATE) {
        builder.newEntity(entityProvider != null ? entityToEdit : null);
    } else {
        if (entityToEdit != null) {
            builder.editEntity(entityToEdit);
        } else {
            throw new DevelopmentException("No entity to edit is passed for EditorScreen");
        }
    }
    if (screenClass != null) {
        builder = builder.withScreenClass(screenClass);
    } else {
        builder.withScreenId(screenId);
    }
    return builder;
}
Also used : EditorBuilder(io.jmix.ui.builder.EditorBuilder) ScreenBuilders(io.jmix.ui.ScreenBuilders) DevelopmentException(io.jmix.core.DevelopmentException)

Example 7 with DevelopmentException

use of io.jmix.core.DevelopmentException in project jmix by jmix-framework.

the class DsContextLoader method loadProperties.

private void loadProperties(Element element, ValueDatasource datasource) {
    Element propsEl = element.element("properties");
    if (propsEl != null) {
        for (Element propEl : propsEl.elements()) {
            String name = propEl.attributeValue("name");
            String className = propEl.attributeValue("class");
            if (className != null) {
                datasource.addProperty(name, ReflectionHelper.getClass(className));
            } else {
                String typeName = propEl.attributeValue("datatype");
                Datatype datatype = typeName == null ? Datatypes.getNN(String.class) : Datatypes.get(typeName);
                datasource.addProperty(name, datatype);
            }
        }
        String idProperty = propsEl.attributeValue("idProperty");
        if (idProperty != null) {
            if (datasource.getMetaClass().findProperty(idProperty) == null)
                throw new DevelopmentException(String.format("Property '%s' is not defined", idProperty));
            datasource.setIdName(idProperty);
        }
    }
}
Also used : Element(org.dom4j.Element) Datatype(io.jmix.core.metamodel.datatype.Datatype) DevelopmentException(io.jmix.core.DevelopmentException)

Example 8 with DevelopmentException

use of io.jmix.core.DevelopmentException in project jmix by jmix-framework.

the class DsContextLoader method loadHierarchicalDatasource.

protected Datasource loadHierarchicalDatasource(Element element) {
    MetaClass metaClass = loadMetaClass(element);
    if (metaClass == null)
        throw new DevelopmentException("'class' attribute is not set for the datasource");
    initCollectionDatasourceAttributes(element, metaClass);
    HierarchicalDatasource datasource = builder.setDsClass(getDatasourceClass(element)).buildHierarchicalDatasource();
    String hierarchyProperty = element.attributeValue("hierarchyProperty");
    if (!StringUtils.isEmpty(hierarchyProperty)) {
        datasource.setHierarchyPropertyName(hierarchyProperty);
    }
    if (datasource instanceof CollectionDatasource.Suspendable)
        ((CollectionDatasource.Suspendable) datasource).setSuspended(true);
    loadQuery(element, datasource);
    loadDatasources(element, datasource);
    return datasource;
}
Also used : MetaClass(io.jmix.core.metamodel.model.MetaClass) DevelopmentException(io.jmix.core.DevelopmentException)

Example 9 with DevelopmentException

use of io.jmix.core.DevelopmentException in project jmix by jmix-framework.

the class DsContextLoader method loadCollectionDatasource.

protected CollectionDatasource loadCollectionDatasource(Element element) {
    MetaClass metaClass = loadMetaClass(element);
    if (metaClass == null)
        throw new DevelopmentException("'class' attribute is not set for the datasource");
    initCollectionDatasourceAttributes(element, metaClass);
    CollectionDatasource datasource = builder.setDsClass(getDatasourceClass(element)).buildCollectionDatasource();
    String maxResults = element.attributeValue("maxResults");
    if (!StringUtils.isEmpty(maxResults))
        datasource.setMaxResults(Integer.parseInt(maxResults));
    if (datasource instanceof CollectionDatasource.Suspendable)
        ((CollectionDatasource.Suspendable) datasource).setSuspended(true);
    loadQuery(element, datasource);
    loadDatasources(element, datasource);
    return datasource;
}
Also used : MetaClass(io.jmix.core.metamodel.model.MetaClass) DevelopmentException(io.jmix.core.DevelopmentException)

Example 10 with DevelopmentException

use of io.jmix.core.DevelopmentException in project jmix by jmix-framework.

the class EntityLookupAction method execute.

/**
 * Executes the action.
 */
@SuppressWarnings("unchecked")
@Override
public void execute() {
    MetaClass metaClass = entityPicker.getMetaClass();
    if (metaClass == null) {
        throw new DevelopmentException("Neither metaClass nor dataContainer/property is specified " + "for the EntityPicker", "action ID", getId());
    }
    LookupBuilder builder = screenBuilders.lookup(entityPicker);
    builder = screenInitializer.initBuilder(builder);
    if (selectValidator != null) {
        builder = builder.withSelectValidator(selectValidator);
    }
    if (transformation != null) {
        builder = builder.withTransformation(transformation);
    }
    Screen lookupScreen = builder.build();
    screenInitializer.initScreen(lookupScreen);
    lookupScreen.show();
}
Also used : MetaClass(io.jmix.core.metamodel.model.MetaClass) LookupBuilder(io.jmix.ui.builder.LookupBuilder) DevelopmentException(io.jmix.core.DevelopmentException)

Aggregations

DevelopmentException (io.jmix.core.DevelopmentException)26 MetaClass (io.jmix.core.metamodel.model.MetaClass)10 MethodHandle (java.lang.invoke.MethodHandle)3 DataGrid (com.haulmont.cuba.gui.components.DataGrid)2 FetchPlanProperty (io.jmix.core.FetchPlanProperty)2 MetaProperty (io.jmix.core.metamodel.model.MetaProperty)2 EditorBuilder (io.jmix.ui.builder.EditorBuilder)2 AbstractDataGrid (io.jmix.ui.component.impl.AbstractDataGrid)2 AnnotatedMethod (io.jmix.ui.sys.UiControllerReflectionInspector.AnnotatedMethod)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Method (java.lang.reflect.Method)2 Map (java.util.Map)2 NamePattern (com.haulmont.chile.core.annotations.NamePattern)1 LoadContext (com.haulmont.cuba.core.global.LoadContext)1 ViewBuilder (com.haulmont.cuba.core.global.ViewBuilder)1 Server (com.haulmont.cuba.core.model.common.Server)1 CoreTest (com.haulmont.cuba.core.testsupport.CoreTest)1 AbstractWindow (com.haulmont.cuba.gui.components.AbstractWindow)1 TreeDataGrid (com.haulmont.cuba.gui.components.TreeDataGrid)1 LegacyFragmentAdapter (com.haulmont.cuba.gui.components.compatibility.LegacyFragmentAdapter)1