Search in sources :

Example 1 with DevelopmentException

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

the class PropertyDatasourceImpl method getView.

@Override
public FetchPlan getView() {
    if (view == null) {
        MetaClass metaMetaClass = masterDs.getMetaClass();
        if (metadata.getTools().isJpaEntity(metaMetaClass) || metadata.getTools().isJpaEmbeddable(metaMetaClass)) {
            FetchPlan masterView = masterDs.getView();
            if (masterView == null) {
                throw new DevelopmentException("No view for datasource " + masterDs.getId(), ParamsMap.of("masterDs", masterDs.getId(), "propertyDs", getId()));
            }
            FetchPlanProperty property = masterView.getProperty(metaProperty.getName());
            if (property == null) {
                return null;
            }
            if (property.getFetchPlan() == null) {
                throw new DevelopmentException(String.format("Invalid view definition: %s. Property '%s' must have a view", masterView, property), ParamsMap.of("masterDs", masterDs.getId(), "propertyDs", getId(), "masterView", masterView, "property", property));
            }
            view = metadata.getViewRepository().getView(getMetaClass(), property.getFetchPlan().getName());
            // anonymous (nameless) view
            if (view == null)
                view = property.getFetchPlan();
        }
    }
    return view;
}
Also used : MetaClass(io.jmix.core.metamodel.model.MetaClass) FetchPlanProperty(io.jmix.core.FetchPlanProperty) FetchPlan(io.jmix.core.FetchPlan) DevelopmentException(io.jmix.core.DevelopmentException)

Example 2 with DevelopmentException

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

the class CubaFragmentHelper method createController.

@Override
public ScreenFragment createController(WindowInfo windowInfo, Fragment fragment) {
    Class screenClass = windowInfo.getControllerClass();
    if (AbstractWindow.class.isAssignableFrom(screenClass)) {
        AbstractWindow legacyScreen;
        try {
            legacyScreen = (AbstractWindow) invokeConstructor(screenClass);
        } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException e) {
            throw new DevelopmentException("Unable to create " + screenClass);
        }
        LegacyFragmentAdapter adapter = new LegacyFragmentAdapter(legacyScreen);
        legacyScreen.setFrame(fragment);
        adapter.setWrappedFrame(fragment);
        log.warn("Fragment class '{}' should not be inherited from AbstractWindow. " + "It may cause problems with controller life cycle. " + "Fragment controllers should inherit ScreenFragment.", screenClass.getSimpleName());
        return adapter;
    }
    return super.createController(windowInfo, fragment);
}
Also used : AbstractWindow(com.haulmont.cuba.gui.components.AbstractWindow) LegacyFragmentAdapter(com.haulmont.cuba.gui.components.compatibility.LegacyFragmentAdapter) InvocationTargetException(java.lang.reflect.InvocationTargetException) DevelopmentException(io.jmix.core.DevelopmentException)

Example 3 with DevelopmentException

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

the class WebTreeDataGrid method addGeneratedColumn.

@Override
public DataGrid.Column<E> addGeneratedColumn(String columnId, GenericColumnGenerator<E, ?> generator) {
    DataGrid.Column<E> column = (DataGrid.Column<E>) getColumn(columnId);
    if (column == null) {
        throw new DevelopmentException("Unable to set ColumnGenerator for non-existing column: " + columnId);
    }
    Class<? extends Renderer> rendererType = null;
    Renderer renderer = column.getRenderer();
    if (renderer != null) {
        Class<?>[] rendererInterfaces = renderer.getClass().getInterfaces();
        rendererType = (Class<? extends Renderer>) Arrays.stream(rendererInterfaces).filter(Renderer.class::isAssignableFrom).findFirst().orElseThrow(() -> new DevelopmentException("Renderer should be specified explicitly for generated column: " + columnId));
    }
    io.jmix.ui.component.DataGrid.Column<E> generatedColumn = addGeneratedColumn(columnId, new ColumnGenerator<E, Object>() {

        @Override
        public Object getValue(ColumnGeneratorEvent<E> event) {
            return generator.getValue(event);
        }

        @Override
        public Class<Object> getType() {
            return column.getGeneratedType();
        }
    });
    if (renderer != null) {
        generatedColumn.setRenderer(createRenderer(rendererType));
    }
    return column;
}
Also used : TreeDataGrid(com.haulmont.cuba.gui.components.TreeDataGrid) DataGrid(com.haulmont.cuba.gui.components.DataGrid) AbstractDataGrid(io.jmix.ui.component.impl.AbstractDataGrid) DevelopmentException(io.jmix.core.DevelopmentException)

Example 4 with DevelopmentException

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

the class InstanceContainerImpl method setItem.

@Override
public void setItem(@Nullable E item) {
    E prevItem = this.item;
    if (this.item != null) {
        detachListener(this.item);
    }
    if (item != null) {
        MetaClass aClass = item instanceof HasInstanceMetaClass ? ((HasInstanceMetaClass) item).getInstanceMetaClass() : metadata.getClass(item);
        if (!aClass.equals(entityMetaClass) && !entityMetaClass.getDescendants().contains(aClass)) {
            throw new DevelopmentException(String.format("Invalid item's metaClass '%s'", aClass), ParamsMap.of("container", toString(), "metaClass", aClass));
        }
        detachListener(item);
        attachListener(item);
    }
    this.item = item;
    fireItemChanged(prevItem);
}
Also used : HasInstanceMetaClass(io.jmix.core.entity.HasInstanceMetaClass) MetaClass(io.jmix.core.metamodel.model.MetaClass) HasInstanceMetaClass(io.jmix.core.entity.HasInstanceMetaClass) DevelopmentException(io.jmix.core.DevelopmentException)

Example 5 with DevelopmentException

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

the class UiControllerDependencyInjector method initInstallMethods.

protected void initInstallMethods(FrameOwner frameOwner, ScreenIntrospectionData screenIntrospectionData) {
    List<AnnotatedMethod<Install>> installMethods = screenIntrospectionData.getInstallMethods();
    for (AnnotatedMethod<Install> annotatedMethod : installMethods) {
        Install annotation = annotatedMethod.getAnnotation();
        Frame frame = UiControllerUtils.getFrame(frameOwner);
        Object targetInstance = getInstallTargetInstance(frameOwner, annotation, frame);
        if (targetInstance == null) {
            if (annotation.required()) {
                throw new DevelopmentException(String.format("Unable to find @Install target for method %s in %s", annotatedMethod.getMethod(), frameOwner.getClass()));
            }
            log.trace("Skip @Install method {} of {} : it is not required and target not found", annotatedMethod.getMethod().getName(), frameOwner.getClass());
            continue;
        }
        Class<?> instanceClass = targetInstance.getClass();
        Method installMethod = annotatedMethod.getMethod();
        MethodHandle targetSetterMethod = getInstallTargetSetterMethod(annotation, frame, instanceClass, installMethod);
        Class<?> targetParameterType = targetSetterMethod.type().parameterList().get(1);
        Object handler = null;
        if (targetInstance instanceof InstallTargetHandler) {
            handler = ((InstallTargetHandler) targetInstance).createInstallHandler(targetParameterType, frameOwner, installMethod);
        }
        if (handler == null) {
            handler = createInstallHandler(frameOwner, installMethod, targetParameterType);
        }
        try {
            targetSetterMethod.invoke(targetInstance, handler);
        } catch (Error e) {
            throw e;
        } catch (Throwable e) {
            throw new RuntimeException("Unable to set declarative @Install handler for " + installMethod, e);
        }
    }
}
Also used : AnnotatedMethod(io.jmix.ui.sys.UiControllerReflectionInspector.AnnotatedMethod) AnnotatedMethod(io.jmix.ui.sys.UiControllerReflectionInspector.AnnotatedMethod) DevelopmentException(io.jmix.core.DevelopmentException) MethodHandle(java.lang.invoke.MethodHandle)

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