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