Skip to content

Commit

Permalink
CanvasUiComponentsFactory must not inject AppUI bean #19
Browse files Browse the repository at this point in the history
  • Loading branch information
zaharchenko committed Jun 18, 2019
1 parent b5bde2e commit 3deaaa9
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 100 deletions.
66 changes: 0 additions & 66 deletions modules/web/src/com/haulmont/addon/dashboard/web-screens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,71 +16,5 @@
-->

<screen-config xmlns="http://schemas.haulmont.com/cuba/screens.xsd">
<include file="/com/haulmont/addon/dashboard/screens.xml"/>
<!--dashboard-->
<screen id="dashboard$PersistentDashboard.view"
template="com/haulmont/addon/dashboard/web/dashboard/frames/view/dashboard-view.xml"/>
<screen id="dashboard$PersistentDashboard.edit"
template="/com/haulmont/addon/dashboard/web/dashboard/frames/editor/dashboard-edit.xml"/>
<screen id="dashboard$PersistentDashboard.browse"
template="com/haulmont/addon/dashboard/web/dashboard/frames/browse/persistent-dashboard-browse.xml"/>
<screen id="dashboard$DashboardComponent"
template="/com/haulmont/addon/dashboard/web/dashboard/frames/uicomponent/web-dashboard-frame.xml"/>
<!--dashboard frames-->
<screen id="dashboard$PaletteFrame"
template="/com/haulmont/addon/dashboard/web/dashboard/frames/editor/palette/palette-frame.xml"/>
<screen id="dashboard$CanvasFrame"
template="/com/haulmont/addon/dashboard/web/dashboard/frames/editor/canvas/canvas-frame.xml"/>
<screen id="dashboard$CanvasEditorFrame"
template="/com/haulmont/addon/dashboard/web/dashboard/frames/editor/canvas/canvas-editor-frame.xml"/>
<screen id="dashboard$GridDialog"
template="/com/haulmont/addon/dashboard/web/dashboard/frames/editor/grid/grid-creation-dialog.xml"/>
<screen id="dashboard$CssLayoutDialog"
template="/com/haulmont/addon/dashboard/web/dashboard/frames/editor/css/css-creation-dialog.xml"/>
<screen id="dashboard$WeightDialog"
template="com/haulmont/addon/dashboard/web/dashboard/frames/editor/weight/weight-dialog.xml"/>
<screen id="dashboard$StyleDialog"
template="com/haulmont/addon/dashboard/web/dashboard/frames/editor/style/style-dialog.xml"/>
<screen id="dashboard$ExpandDialog"
template="com/haulmont/addon/dashboard/web/dashboard/frames/editor/expand/expand-dialog.xml"/>
<screen id="dashboard$ColspanDialog"
template="com/haulmont/addon/dashboard/web/dashboard/frames/editor/colspan/colspan-dialog.xml"/>

<!--parameters-->
<screen id="dashboard$ParameterBrowse"
template="com/haulmont/addon/dashboard/web/parameter/parameter-browse.xml"/>
<screen id="dashboard$Parameter.edit"
template="com/haulmont/addon/dashboard/web/parameter/parameter-edit.xml"/>
<!--parameter value frames-->
<screen id="dashboard$SimpleValueFrame"
template="com/haulmont/addon/dashboard/web/parameter/frames/simple-value-frame.xml"/>
<screen id="dashboard$EnumValueFrame"
template="com/haulmont/addon/dashboard/web/parameter/frames/enum-value-frame.xml"/>
<screen id="dashboard$EntitiesListValueFrame"
template="com/haulmont/addon/dashboard/web/parameter/frames/entities-list-value-frame.xml"/>
<screen id="dashboard$EntityValueFrame"
template="com/haulmont/addon/dashboard/web/parameter/frames/entity-value-frame.xml"/>
<screen id="dashboard$EntityValueWindow"
template="com/haulmont/addon/dashboard/web/parameter/frames/entity-value-window.xml"/>
<!--widget-->
<screen id="dashboard$Widget.edit"
template="com/haulmont/addon/dashboard/web/widget/widget-edit.xml"/>
<!--widget template-->
<screen id="dashboard$WidgetTemplate.browse"
template="/com/haulmont/addon/dashboard/web/widgettemplate/widget-template-browse.xml"/>
<screen id="dashboard$WidgetTemplate.edit"
template="com/haulmont/addon/dashboard/web/widgettemplate/widget-template-edit.xml"/>
<!--dashboard groups-->
<screen id="dashboard$DashboardGroup.browse"
template="com/haulmont/addon/dashboard/web/dashboardgroup/dashboard-group-browse.xml"/>
<screen id="dashboard$DashboardGroup.edit"
template="com/haulmont/addon/dashboard/web/dashboardgroup/dashboard-group-edit.xml"/>
<!--widget template groups-->
<screen id="dashboard$WidgetTemplateGroup.browse"
template="com/haulmont/addon/dashboard/web/widgettemplategroup/widget-template-group-browse.xml"/>
<screen id="dashboard$WidgetTemplateGroup.edit"
template="com/haulmont/addon/dashboard/web/widgettemplategroup/widget-template-group-edit.xml"/>
<screen id="dashboard$ResponsiveDialog"
template="com/haulmont/addon/dashboard/web/dashboard/frames/editor/responsive/responsive-creation-dialog.xml"/>

</screen-config>
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -99,7 +100,7 @@ public List<LookupWidget> getLookupWidgets() {

protected <T> void searchWidgets(ComponentContainer layout, Class<T> widgetClass, List<T> 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);
}
Expand All @@ -112,7 +113,7 @@ protected <T> void searchWidgets(ComponentContainer layout, Class<T> widgetClass
}
}

private Component getWidgetFrame(CanvasWidgetLayout layout) {
private ScreenFragment getWidgetFrame(CanvasWidgetLayout layout) {
return layout.getWidgetComponent();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@
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 {

public static final String NAME = "canvasWidgetLayout";

protected VBoxLayout verticalLayout;
protected Widget widget = null;
protected Component widgetComponent;
protected ScreenFragment widgetComponent;
protected Component innerLayout;

public CanvasWidgetLayout init(WidgetLayout model) {
Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,24 @@
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;
import java.util.Map;
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";
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,9 +32,9 @@ public interface WidgetRepository {

List<WidgetTypeInfo> 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<String, Object> getWidgetParams(Widget widget);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -150,7 +150,7 @@ protected void init() {
}

@Override
public void initializeWidgetFields(AbstractFrame widgetFrame, Widget widget) {
public void initializeWidgetFields(ScreenFragment widgetFrame, Widget widget) {
List<Parameter> widgetFieldValues = widget.getWidgetFields();
List<Field> parameterFields = FieldUtils.getFieldsListWithAnnotation(widgetFrame.getClass(), WidgetParam.class);
for (Field parameterField : parameterFields) {
Expand Down Expand Up @@ -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<Field> parameterFields = FieldUtils.getFieldsListWithAnnotation(widgetFrame.getClass(), WidgetParam.class);
for (Field parameterField : parameterFields) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -67,7 +68,7 @@ public class WidgetEdit extends AbstractEditor<Widget> {
protected TextField<String> widgetId;

protected List<WidgetTypeInfo> typesInfo;
protected AbstractFrame widgetEditFrame;
protected ScreenFragment widgetEditFrame;

@Override
public void postInit() {
Expand Down Expand Up @@ -101,7 +102,7 @@ protected void setWidgetType() {
Map<String, Object> 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();
Expand Down

0 comments on commit 3deaaa9

Please sign in to comment.