From 3deaaa9974007b25419e00c76abd6c84801ea98c Mon Sep 17 00:00:00 2001 From: zaharchenko Date: Tue, 18 Jun 2019 15:08:27 +0400 Subject: [PATCH] CanvasUiComponentsFactory must not inject `AppUI` bean #19 --- .../haulmont/addon/dashboard/web-screens.xml | 66 ------------------- .../frames/editor/canvas/CanvasFrame.java | 5 +- .../frames/uicomponent/WebDashboardFrame.java | 2 +- .../dashboard/layouts/CanvasWidgetLayout.java | 7 +- .../web/dashboard/tools/DropLayoutTools.java | 6 +- .../CanvasUiComponentsFactory.java | 28 ++++---- .../ParameterTransformer.java | 4 +- .../ParameterTransformerImpl.java | 4 +- .../web/repository/WidgetRepository.java | 6 +- .../web/repository/WidgetRepositoryImpl.java | 6 +- .../dashboard/web/widget/WidgetEdit.java | 5 +- 11 files changed, 39 insertions(+), 100 deletions(-) diff --git a/modules/web/src/com/haulmont/addon/dashboard/web-screens.xml b/modules/web/src/com/haulmont/addon/dashboard/web-screens.xml index 201cbc8c..ab3919d6 100644 --- a/modules/web/src/com/haulmont/addon/dashboard/web-screens.xml +++ b/modules/web/src/com/haulmont/addon/dashboard/web-screens.xml @@ -16,71 +16,5 @@ --> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/modules/web/src/com/haulmont/addon/dashboard/web/dashboard/frames/editor/canvas/CanvasFrame.java b/modules/web/src/com/haulmont/addon/dashboard/web/dashboard/frames/editor/canvas/CanvasFrame.java index 8d373215..2b48685f 100644 --- a/modules/web/src/com/haulmont/addon/dashboard/web/dashboard/frames/editor/canvas/CanvasFrame.java +++ b/modules/web/src/com/haulmont/addon/dashboard/web/dashboard/frames/editor/canvas/CanvasFrame.java @@ -29,6 +29,7 @@ import com.haulmont.cuba.gui.components.Component; import com.haulmont.cuba.gui.components.ComponentContainer; import com.haulmont.cuba.gui.components.OrderedContainer; +import com.haulmont.cuba.gui.screen.ScreenFragment; import com.haulmont.cuba.gui.screen.UiController; import com.haulmont.cuba.gui.screen.UiDescriptor; @@ -99,7 +100,7 @@ public List getLookupWidgets() { protected void searchWidgets(ComponentContainer layout, Class widgetClass, List wbList) { if (layout instanceof CanvasWidgetLayout) { - Component wb = getWidgetFrame((CanvasWidgetLayout) layout); + ScreenFragment wb = getWidgetFrame((CanvasWidgetLayout) layout); if (wb != null && widgetClass.isAssignableFrom(wb.getClass())) { wbList.add((T) wb); } @@ -112,7 +113,7 @@ protected void searchWidgets(ComponentContainer layout, Class widgetClass } } - private Component getWidgetFrame(CanvasWidgetLayout layout) { + private ScreenFragment getWidgetFrame(CanvasWidgetLayout layout) { return layout.getWidgetComponent(); } diff --git a/modules/web/src/com/haulmont/addon/dashboard/web/dashboard/frames/uicomponent/WebDashboardFrame.java b/modules/web/src/com/haulmont/addon/dashboard/web/dashboard/frames/uicomponent/WebDashboardFrame.java index c2a23fb5..421e8bf2 100644 --- a/modules/web/src/com/haulmont/addon/dashboard/web/dashboard/frames/uicomponent/WebDashboardFrame.java +++ b/modules/web/src/com/haulmont/addon/dashboard/web/dashboard/frames/uicomponent/WebDashboardFrame.java @@ -308,7 +308,7 @@ protected ScreenFragment searchWidgetFrame(Component layout, String widgetId) { if (CanvasWidgetLayout.class.isAssignableFrom(layout.getClass())) { CanvasWidgetLayout canvasWidgetLayout = (CanvasWidgetLayout) layout; if (widgetId.equals(canvasWidgetLayout.getWidget().getWidgetId())) { - return (ScreenFragment) canvasWidgetLayout.getWidgetComponent(); + return canvasWidgetLayout.getWidgetComponent(); } return null; } diff --git a/modules/web/src/com/haulmont/addon/dashboard/web/dashboard/layouts/CanvasWidgetLayout.java b/modules/web/src/com/haulmont/addon/dashboard/web/dashboard/layouts/CanvasWidgetLayout.java index 50b2bc1a..2bbe25a2 100644 --- a/modules/web/src/com/haulmont/addon/dashboard/web/dashboard/layouts/CanvasWidgetLayout.java +++ b/modules/web/src/com/haulmont/addon/dashboard/web/dashboard/layouts/CanvasWidgetLayout.java @@ -20,6 +20,7 @@ import com.haulmont.addon.dashboard.model.visualmodel.WidgetLayout; import com.haulmont.cuba.gui.components.Component; import com.haulmont.cuba.gui.components.VBoxLayout; +import com.haulmont.cuba.gui.screen.ScreenFragment; public class CanvasWidgetLayout extends AbstractCanvasLayout { @@ -27,7 +28,7 @@ public class CanvasWidgetLayout extends AbstractCanvasLayout { protected VBoxLayout verticalLayout; protected Widget widget = null; - protected Component widgetComponent; + protected ScreenFragment widgetComponent; protected Component innerLayout; public CanvasWidgetLayout init(WidgetLayout model) { @@ -49,11 +50,11 @@ public void setWidget(Widget widget) { this.widget = widget; } - public Component getWidgetComponent() { + public ScreenFragment getWidgetComponent() { return widgetComponent; } - public void setWidgetComponent(Component widgetComponent) { + public void setWidgetComponent(ScreenFragment widgetComponent) { this.widgetComponent = widgetComponent; } diff --git a/modules/web/src/com/haulmont/addon/dashboard/web/dashboard/tools/DropLayoutTools.java b/modules/web/src/com/haulmont/addon/dashboard/web/dashboard/tools/DropLayoutTools.java index c4a4d9e0..68a3e7a0 100644 --- a/modules/web/src/com/haulmont/addon/dashboard/web/dashboard/tools/DropLayoutTools.java +++ b/modules/web/src/com/haulmont/addon/dashboard/web/dashboard/tools/DropLayoutTools.java @@ -32,7 +32,7 @@ import com.haulmont.cuba.core.global.Metadata; import com.haulmont.cuba.core.global.MetadataTools; import com.haulmont.cuba.gui.ScreenBuilders; -import com.haulmont.cuba.gui.components.AbstractFrame; +import com.haulmont.cuba.gui.components.Frame; import com.haulmont.cuba.gui.components.Window; import com.haulmont.cuba.gui.data.Datasource; import com.haulmont.cuba.gui.data.impl.AbstractDatasource; @@ -257,8 +257,8 @@ public void moveComponent(DashboardLayout layout, UUID targetLayoutId, WidgetDro } } - public AbstractFrame getFrame() { - return (AbstractFrame) frame.getFrame(); + public Frame getFrame() { + return frame.getFrame(); } private boolean applyMoveAction(DashboardLayout layout, DashboardLayout target, DashboardLayout parent, DashboardLayout dashboardModel) { diff --git a/modules/web/src/com/haulmont/addon/dashboard/web/dashboard/tools/componentfactory/CanvasUiComponentsFactory.java b/modules/web/src/com/haulmont/addon/dashboard/web/dashboard/tools/componentfactory/CanvasUiComponentsFactory.java index a5e96c4d..9f260988 100644 --- a/modules/web/src/com/haulmont/addon/dashboard/web/dashboard/tools/componentfactory/CanvasUiComponentsFactory.java +++ b/modules/web/src/com/haulmont/addon/dashboard/web/dashboard/tools/componentfactory/CanvasUiComponentsFactory.java @@ -25,15 +25,16 @@ import com.haulmont.bali.util.ParamsMap; import com.haulmont.cuba.core.global.Messages; import com.haulmont.cuba.gui.UiComponents; -import com.haulmont.cuba.gui.components.AbstractFrame; +import com.haulmont.cuba.gui.components.Component; +import com.haulmont.cuba.gui.components.Fragment; import com.haulmont.cuba.gui.components.Label; import com.haulmont.cuba.gui.components.VBoxLayout; import com.haulmont.cuba.gui.screen.MapScreenOptions; +import com.haulmont.cuba.gui.screen.ScreenFragment; import com.haulmont.cuba.web.AppUI; import org.apache.commons.lang3.BooleanUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Component; import javax.inject.Inject; import java.util.HashMap; @@ -41,7 +42,7 @@ import java.util.Optional; import java.util.UUID; -@Component("dashboard_uiComponentsFactory") +@org.springframework.stereotype.Component("dashboard_uiComponentsFactory") public class CanvasUiComponentsFactory implements CanvasComponentsFactory { public static final String WIDGET = "widget"; @@ -59,9 +60,6 @@ public class CanvasUiComponentsFactory implements CanvasComponentsFactory { @Inject protected Messages messages; - @Inject - protected AppUI appUI; - @Override public CanvasVerticalLayout createCanvasVerticalLayout(VerticalLayout verticalLayout) { CanvasVerticalLayout layout = components.create(CanvasVerticalLayout.class).init(verticalLayout); @@ -121,11 +119,15 @@ public CanvasWidgetLayout createCanvasWidgetLayout(CanvasFrame frame, WidgetLayo )); params.putAll(widgetRepository.getWidgetParams(widget)); - AbstractFrame widgetFrame = (AbstractFrame) appUI.getFragments().create(frame, frameId, new MapScreenOptions(params)).init(); + ScreenFragment screenFragment = AppUI.getCurrent().getFragments() + .create(frame, frameId, new MapScreenOptions(params)) + .init(); + Fragment fragment = screenFragment + .getFragment(); - widgetFrame.setSizeFull(); + fragment.setSizeFull(); - com.haulmont.cuba.gui.components.Component widgetComponent = widgetFrame; + Component widgetComponent = fragment; if (BooleanUtils.isTrue(widget.getShowWidgetCaption())) { VBoxLayout vBoxLayout = components.create(VBoxLayout.class); @@ -138,17 +140,17 @@ public CanvasWidgetLayout createCanvasWidgetLayout(CanvasFrame frame, WidgetLayo label.setStyleName("h2"); vBoxLayout.add(label); - vBoxLayout.add(widgetFrame); - vBoxLayout.expand(widgetFrame); + vBoxLayout.add(fragment); + vBoxLayout.expand(fragment); widgetComponent = vBoxLayout; } else { - widgetFrame.setMargin(true); + fragment.setMargin(true); } CanvasWidgetLayout layout = components.create(CanvasWidgetLayout.class).init(widgetLayout); layout.setUuid(UUID.randomUUID()); layout.addComponent(widgetComponent); - layout.setWidgetComponent(widgetFrame); + layout.setWidgetComponent(screenFragment); layout.setInnerLayout(widgetComponent); layout.setWidget(widget); layout.getDelegate().expand(widgetComponent); diff --git a/modules/web/src/com/haulmont/addon/dashboard/web/parametertransformer/ParameterTransformer.java b/modules/web/src/com/haulmont/addon/dashboard/web/parametertransformer/ParameterTransformer.java index 524f25ea..a29b9fd5 100644 --- a/modules/web/src/com/haulmont/addon/dashboard/web/parametertransformer/ParameterTransformer.java +++ b/modules/web/src/com/haulmont/addon/dashboard/web/parametertransformer/ParameterTransformer.java @@ -18,7 +18,7 @@ import com.haulmont.addon.dashboard.model.ParameterType; import com.haulmont.addon.dashboard.model.paramtypes.ParameterValue; -import com.haulmont.cuba.gui.components.AbstractFrame; +import com.haulmont.cuba.gui.screen.ScreenFragment; import java.lang.reflect.Field; @@ -29,5 +29,5 @@ public interface ParameterTransformer { boolean compareParameterTypes(ParameterType parameterType, Field field); - ParameterValue createParameterValue(Field field, AbstractFrame widgetFrame); + ParameterValue createParameterValue(Field field, ScreenFragment widgetFrame); } diff --git a/modules/web/src/com/haulmont/addon/dashboard/web/parametertransformer/ParameterTransformerImpl.java b/modules/web/src/com/haulmont/addon/dashboard/web/parametertransformer/ParameterTransformerImpl.java index 67bd6a24..29b040d6 100644 --- a/modules/web/src/com/haulmont/addon/dashboard/web/parametertransformer/ParameterTransformerImpl.java +++ b/modules/web/src/com/haulmont/addon/dashboard/web/parametertransformer/ParameterTransformerImpl.java @@ -24,7 +24,7 @@ import com.haulmont.cuba.core.global.DataManager; import com.haulmont.cuba.core.global.LoadContext; import com.haulmont.cuba.core.global.Metadata; -import com.haulmont.cuba.gui.components.AbstractFrame; +import com.haulmont.cuba.gui.screen.ScreenFragment; import org.apache.commons.lang3.reflect.FieldUtils; import org.springframework.stereotype.Service; @@ -128,7 +128,7 @@ public ParameterType getParameterType(Field field) { } @Override - public ParameterValue createParameterValue(Field field, AbstractFrame widgetFrame) { + public ParameterValue createParameterValue(Field field, ScreenFragment widgetFrame) { ParameterValue parameterValue = null; ParameterType parameterType = getParameterType(field); try { diff --git a/modules/web/src/com/haulmont/addon/dashboard/web/repository/WidgetRepository.java b/modules/web/src/com/haulmont/addon/dashboard/web/repository/WidgetRepository.java index 5f33bf44..7aa17481 100644 --- a/modules/web/src/com/haulmont/addon/dashboard/web/repository/WidgetRepository.java +++ b/modules/web/src/com/haulmont/addon/dashboard/web/repository/WidgetRepository.java @@ -18,7 +18,7 @@ import com.haulmont.addon.dashboard.model.Widget; -import com.haulmont.cuba.gui.components.AbstractFrame; +import com.haulmont.cuba.gui.screen.ScreenFragment; import java.util.List; import java.util.Map; @@ -32,9 +32,9 @@ public interface WidgetRepository { List getWidgetTypesInfo(); - void initializeWidgetFields(AbstractFrame widgetFrame, Widget widget); + void initializeWidgetFields(ScreenFragment widgetFrame, Widget widget); - void serializeWidgetFields(AbstractFrame widgetFrame, Widget widget); + void serializeWidgetFields(ScreenFragment widgetFrame, Widget widget); Map getWidgetParams(Widget widget); diff --git a/modules/web/src/com/haulmont/addon/dashboard/web/repository/WidgetRepositoryImpl.java b/modules/web/src/com/haulmont/addon/dashboard/web/repository/WidgetRepositoryImpl.java index 7d753b92..ccc56eab 100644 --- a/modules/web/src/com/haulmont/addon/dashboard/web/repository/WidgetRepositoryImpl.java +++ b/modules/web/src/com/haulmont/addon/dashboard/web/repository/WidgetRepositoryImpl.java @@ -25,9 +25,9 @@ import com.haulmont.cuba.core.global.Messages; import com.haulmont.cuba.core.global.Metadata; import com.haulmont.cuba.core.global.Resources; -import com.haulmont.cuba.gui.components.AbstractFrame; import com.haulmont.cuba.gui.config.WindowConfig; import com.haulmont.cuba.gui.config.WindowInfo; +import com.haulmont.cuba.gui.screen.ScreenFragment; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.reflect.FieldUtils; import org.slf4j.Logger; @@ -150,7 +150,7 @@ protected void init() { } @Override - public void initializeWidgetFields(AbstractFrame widgetFrame, Widget widget) { + public void initializeWidgetFields(ScreenFragment widgetFrame, Widget widget) { List widgetFieldValues = widget.getWidgetFields(); List parameterFields = FieldUtils.getFieldsListWithAnnotation(widgetFrame.getClass(), WidgetParam.class); for (Field parameterField : parameterFields) { @@ -198,7 +198,7 @@ private String getAlias(Parameter p) { } @Override - public void serializeWidgetFields(AbstractFrame widgetFrame, Widget widget) { + public void serializeWidgetFields(ScreenFragment widgetFrame, Widget widget) { widget.getWidgetFields().clear(); List parameterFields = FieldUtils.getFieldsListWithAnnotation(widgetFrame.getClass(), WidgetParam.class); for (Field parameterField : parameterFields) { diff --git a/modules/web/src/com/haulmont/addon/dashboard/web/widget/WidgetEdit.java b/modules/web/src/com/haulmont/addon/dashboard/web/widget/WidgetEdit.java index 3dfe0563..2eb1a1f5 100644 --- a/modules/web/src/com/haulmont/addon/dashboard/web/widget/WidgetEdit.java +++ b/modules/web/src/com/haulmont/addon/dashboard/web/widget/WidgetEdit.java @@ -27,6 +27,7 @@ import com.haulmont.cuba.gui.data.Datasource; import com.haulmont.cuba.gui.data.impl.AbstractDatasource; import com.haulmont.cuba.gui.screen.MapScreenOptions; +import com.haulmont.cuba.gui.screen.ScreenFragment; import com.haulmont.cuba.gui.screen.UiController; import com.haulmont.cuba.gui.screen.UiDescriptor; import org.apache.commons.lang3.StringUtils; @@ -67,7 +68,7 @@ public class WidgetEdit extends AbstractEditor { protected TextField widgetId; protected List typesInfo; - protected AbstractFrame widgetEditFrame; + protected ScreenFragment widgetEditFrame; @Override public void postInit() { @@ -101,7 +102,7 @@ protected void setWidgetType() { Map params = new HashMap<>(ParamsMap.of(ITEM_DS, widgetDs)); params.putAll(widgetRepository.getWidgetParams(widgetDs.getItem())); if (StringUtils.isNotEmpty(widgetType.getEditFrameId())) { - widgetEditFrame = (AbstractFrame) fragments.create(this, + widgetEditFrame = fragments.create(this, widgetType.getEditFrameId(), new MapScreenOptions(params)) .init();