Browse Source

REPORT-64149

feature/x
方磊 3 years ago
parent
commit
a2d95f38ea
  1. 4
      designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/FRFitLayoutAdapter.java
  2. 39
      designer-form/src/main/java/com/fr/design/designer/beans/models/AddingModel.java
  3. 4
      designer-form/src/main/java/com/fr/design/mainframe/DesignerTransferHandler.java
  4. 30
      designer-form/src/main/java/com/fr/design/mainframe/FormCreatorDropTarget.java
  5. 31
      designer-form/src/main/java/com/fr/design/mainframe/FormDesigner.java
  6. 210
      designer-form/src/test/java/com/fr/design/designer/beans/models/AddingModelTest.java
  7. 13
      designer-realize/src/main/java/com/fr/design/mainframe/guide/creator/GuideCreateUtils.java
  8. 4
      designer-realize/src/main/java/com/fr/design/mainframe/guide/creator/layout/ChangeLayoutComponentGuide.java
  9. 2
      designer-realize/src/main/java/com/fr/design/mainframe/guide/creator/layout/UseLayoutAndComponentGuide.java

4
designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/FRFitLayoutAdapter.java

@ -8,7 +8,6 @@ import com.fr.design.beans.GroupModel;
import com.fr.design.designer.beans.ConstraintsGroupModel; import com.fr.design.designer.beans.ConstraintsGroupModel;
import com.fr.design.designer.beans.HoverPainter; import com.fr.design.designer.beans.HoverPainter;
import com.fr.design.designer.beans.LayoutAdapter; import com.fr.design.designer.beans.LayoutAdapter;
import com.fr.design.designer.beans.models.AddingModel;
import com.fr.design.designer.beans.models.DraggingModel; import com.fr.design.designer.beans.models.DraggingModel;
import com.fr.design.designer.beans.models.SelectionModel; import com.fr.design.designer.beans.models.SelectionModel;
import com.fr.design.designer.creator.XCreator; import com.fr.design.designer.creator.XCreator;
@ -1262,10 +1261,9 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
if (dragEvent.getPoint().distance(lastPressEvent.getPoint()) > 5) { if (dragEvent.getPoint().distance(lastPressEvent.getPoint()) > 5) {
if (creator.isSupportDrag()) { if (creator.isSupportDrag()) {
designer.setAddingModel(new AddingModel(creator, dragEvent.getX(), dragEvent.getY()));
designer.bindTransferHandler(lastPressEvent); designer.bindTransferHandler(lastPressEvent);
designer.fireParentLayoutDragStart(creator); designer.fireParentLayoutDragStart(creator);
designer.setDropTarget(new FormCreatorDropTarget(designer)); designer.setDropTarget(new FormCreatorDropTarget(designer, creator));
// 触发状态添加模式事件 // 触发状态添加模式事件
designer.repaint(); designer.repaint();
} }

39
designer-form/src/main/java/com/fr/design/designer/beans/models/AddingModel.java

@ -1,12 +1,8 @@
package com.fr.design.designer.beans.models; package com.fr.design.designer.beans.models;
import com.fr.design.designer.beans.AdapterBus;
import com.fr.design.designer.beans.ComponentAdapter;
import com.fr.design.designer.beans.adapters.component.CompositeComponentAdapter;
import com.fr.design.designer.creator.XCreator; import com.fr.design.designer.creator.XCreator;
import com.fr.design.designer.creator.XCreatorUtils; import com.fr.design.designer.creator.XCreatorUtils;
import com.fr.design.designer.creator.XLayoutContainer; import com.fr.design.designer.creator.XLayoutContainer;
import com.fr.design.designer.creator.XWParameterLayout;
import com.fr.design.mainframe.FormDesigner; import com.fr.design.mainframe.FormDesigner;
import com.fr.design.utils.ComponentUtils; import com.fr.design.utils.ComponentUtils;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
@ -23,41 +19,8 @@ public class AddingModel {
private boolean added; private boolean added;
private boolean addedIllegal = false; // 有时候是添加完成了,但是添加会造成某些控件size不合法,例如tab private boolean addedIllegal = false; // 有时候是添加完成了,但是添加会造成某些控件size不合法,例如tab
public AddingModel(FormDesigner designer, XCreator xCreator) { public AddingModel(XCreator xCreator) {
this.creator = xCreator; this.creator = xCreator;
instantiateCreator(designer);
}
/**
* 待说明
*
* @param designer 设计器
*/
public void instantiateCreator(FormDesigner designer) {
ModelUtil.renameWidgetName(designer.getTarget(), creator);
ComponentAdapter adapter = new CompositeComponentAdapter(designer, creator);
adapter.initialize();
creator.addNotify();
creator.putClientProperty(AdapterBus.CLIENT_PROPERTIES, adapter);
}
public AddingModel(XCreator xCreator, int x, int y) {
this.creator = xCreator;
this.creator.backupCurrentSize();
this.creator.backupParent();
}
public String getXCreatorName(FormDesigner designer, XCreator x) {
String def = x.createDefaultName();
if (x.acceptType(XWParameterLayout.class)) {
return def;
}
int i = 0;
while (designer.getTarget().isNameExist(def + i)) {
i++;
}
return def + i;
} }
public XCreator getXCreator() { public XCreator getXCreator() {

4
designer-form/src/main/java/com/fr/design/mainframe/DesignerTransferHandler.java

@ -10,16 +10,14 @@ import java.awt.datatransfer.Transferable;
public class DesignerTransferHandler extends TransferHandler { public class DesignerTransferHandler extends TransferHandler {
private FormDesigner designer; private FormDesigner designer;
private AddingModel addingModel;
public DesignerTransferHandler(FormDesigner designer, AddingModel addingModel) { public DesignerTransferHandler(FormDesigner designer, AddingModel addingModel) {
super("rootComponent"); super("rootComponent");
this.designer = designer; this.designer = designer;
this.addingModel = addingModel;
} }
protected void exportDone(JComponent source, Transferable data, int action) { protected void exportDone(JComponent source, Transferable data, int action) {
if (!addingModel.isCreatorAdded()) { if (designer.getAddingModel() != null && !designer.getAddingModel().isCreatorAdded()) {
undoWhenAddingFailed(); undoWhenAddingFailed();
} }
} }

30
designer-form/src/main/java/com/fr/design/mainframe/FormCreatorDropTarget.java

@ -5,7 +5,6 @@ import com.fr.design.designer.beans.AdapterBus;
import com.fr.design.designer.beans.HoverPainter; import com.fr.design.designer.beans.HoverPainter;
import com.fr.design.designer.beans.Painter; import com.fr.design.designer.beans.Painter;
import com.fr.design.designer.beans.events.AddingWidgetListener; import com.fr.design.designer.beans.events.AddingWidgetListener;
import com.fr.design.designer.beans.models.AddingModel;
import com.fr.design.designer.creator.XCreator; import com.fr.design.designer.creator.XCreator;
import com.fr.design.designer.creator.XCreatorUtils; import com.fr.design.designer.creator.XCreatorUtils;
import com.fr.design.designer.creator.XLayoutContainer; import com.fr.design.designer.creator.XLayoutContainer;
@ -43,20 +42,16 @@ public class FormCreatorDropTarget extends DropTarget {
* 当前鼠标的设计组件 * 当前鼠标的设计组件
*/ */
private Component current; private Component current;
/**
* 当前添加模式对应的model
*/
private AddingModel addingModel;
private static final int GAP = 30; private static final int GAP = 30;
private TabDragInner tabDragInner; private TabDragInner tabDragInner;
private XCreator creator;
private JWindow promptWindow = new JWindow(); private JWindow promptWindow = new JWindow();
private UIButton promptButton = new UIButton("", BaseUtils.readIcon(IconPathConstants.FORBID_ICON_PATH)); private UIButton promptButton = new UIButton("", BaseUtils.readIcon(IconPathConstants.FORBID_ICON_PATH));
public FormCreatorDropTarget(FormDesigner designer) { public FormCreatorDropTarget(FormDesigner designer, XCreator creator) {
this.designer = designer; this.designer = designer;
this.addingModel = designer.getAddingModel(); this.creator = creator;
this.promptWindow.add(promptButton); this.promptWindow.add(promptButton);
this.tabDragInner = new TabDragInner(designer); this.tabDragInner = new TabDragInner(designer);
initAddingListener(); initAddingListener();
@ -71,7 +66,9 @@ public class FormCreatorDropTarget extends DropTarget {
@Override @Override
public void afterAdded(boolean addResult) { public void afterAdded(boolean addResult) {
tabDragInner.reset(); if (addResult) {
tabDragInner.reset();
}
} }
}); });
} }
@ -145,15 +142,15 @@ public class FormCreatorDropTarget extends DropTarget {
rect.y -= designer.getArea().getVerticalValue(); rect.y -= designer.getArea().getVerticalValue();
painter.setRenderingBounds(rect); painter.setRenderingBounds(rect);
painter.setHotspot(new Point(x, y)); painter.setHotspot(new Point(x, y));
painter.setCreator(addingModel.getXCreator()); painter.setCreator(creator);
} }
} }
private void promptUser(int x, int y, XLayoutContainer container) { private void promptUser(int x, int y, XLayoutContainer container) {
if (!addingModel.getXCreator().canEnterIntoParaPane() && container.acceptType(XWParameterLayout.class)) { if (!creator.canEnterIntoParaPane() && container.acceptType(XWParameterLayout.class)) {
promptButton.setText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Forbid_Drag_Into_Para_Pane")); promptButton.setText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Forbid_Drag_Into_Para_Pane"));
promptWidgetForbidEnter(x, y, container); promptWidgetForbidEnter(x, y, container);
} else if (!addingModel.getXCreator().canEnterIntoAdaptPane() && container.acceptType(XWFitLayout.class)) { } else if (!creator.canEnterIntoAdaptPane() && container.acceptType(XWFitLayout.class)) {
promptButton.setText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Forbid_Drag_Into_Adapt_Pane")); promptButton.setText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Forbid_Drag_Into_Adapt_Pane"));
promptWidgetForbidEnter(x, y, container); promptWidgetForbidEnter(x, y, container);
} else { } else {
@ -201,10 +198,9 @@ public class FormCreatorDropTarget extends DropTarget {
hovering(x, y); hovering(x, y);
tabDragInner.setTabDragInAble(designer.getComponentAt(x, y), x, y); tabDragInner.setTabDragInAble(designer.getComponentAt(x, y), x, y);
XCreator xCreator = designer.getAddingModel().getXCreator(); XLayoutContainer parent = XCreatorUtils.getParentXLayoutContainer(creator);
XLayoutContainer parent = XCreatorUtils.getParentXLayoutContainer(xCreator);
if (parent!= null && parent.getLayoutAdapter()!=null){ if (parent!= null && parent.getLayoutAdapter()!=null){
parent.getLayoutAdapter().dragOver(xCreator, designer.getSelectionModel(), x, y); parent.getLayoutAdapter().dragOver(creator, designer.getSelectionModel(), x, y);
} }
// 触发状态添加模式事件 // 触发状态添加模式事件
@ -243,7 +239,7 @@ public class FormCreatorDropTarget extends DropTarget {
dropXCreator(dtde); dropXCreator(dtde);
} catch (Exception e) { } catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e); FineLoggerFactory.getLogger().error(e.getMessage(), e);
if (addingModel.getXCreator().isShared()) { if (creator.isShared()) {
FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(),
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Share_Drag_Component_Error_Info"), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Share_Drag_Component_Error_Info"),
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Error"), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Error"),
@ -258,7 +254,7 @@ public class FormCreatorDropTarget extends DropTarget {
private void dropXCreator(DropTargetDropEvent dtde) { private void dropXCreator(DropTargetDropEvent dtde) {
cancelPromptWidgetForbidEnter(); cancelPromptWidgetForbidEnter();
Point loc = dtde.getLocation(); Point loc = dtde.getLocation();
designer.addWidgetToForm(designer.getRelativeX(loc.x), designer.getRelativeY(loc.y)); designer.addWidgetToForm(creator, designer.getRelativeX(loc.x), designer.getRelativeY(loc.y));
// 放到事件末尾执行 // 放到事件末尾执行
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@Override @Override

31
designer-form/src/main/java/com/fr/design/mainframe/FormDesigner.java

@ -14,6 +14,7 @@ import com.fr.design.data.DesignTableDataManager;
import com.fr.design.data.datapane.TableDataTreePane; import com.fr.design.data.datapane.TableDataTreePane;
import com.fr.design.designer.TargetComponent; import com.fr.design.designer.TargetComponent;
import com.fr.design.designer.beans.AdapterBus; import com.fr.design.designer.beans.AdapterBus;
import com.fr.design.designer.beans.ComponentAdapter;
import com.fr.design.designer.beans.LayoutAdapter; import com.fr.design.designer.beans.LayoutAdapter;
import com.fr.design.designer.beans.Painter; import com.fr.design.designer.beans.Painter;
import com.fr.design.designer.beans.actions.CopyAction; import com.fr.design.designer.beans.actions.CopyAction;
@ -24,6 +25,7 @@ import com.fr.design.designer.beans.actions.MoveToBottomAction;
import com.fr.design.designer.beans.actions.MoveToTopAction; import com.fr.design.designer.beans.actions.MoveToTopAction;
import com.fr.design.designer.beans.actions.MoveUpAction; import com.fr.design.designer.beans.actions.MoveUpAction;
import com.fr.design.designer.beans.actions.PasteAction; import com.fr.design.designer.beans.actions.PasteAction;
import com.fr.design.designer.beans.adapters.component.CompositeComponentAdapter;
import com.fr.design.designer.beans.adapters.layout.DefaultDesignerBaseOperate; import com.fr.design.designer.beans.adapters.layout.DefaultDesignerBaseOperate;
import com.fr.design.designer.beans.adapters.layout.DesignerBaseOperate; import com.fr.design.designer.beans.adapters.layout.DesignerBaseOperate;
import com.fr.design.designer.beans.adapters.layout.FRParameterLayoutAdapter; import com.fr.design.designer.beans.adapters.layout.FRParameterLayoutAdapter;
@ -36,6 +38,7 @@ import com.fr.design.designer.beans.location.Location;
import com.fr.design.designer.beans.location.RootResizeDirection; import com.fr.design.designer.beans.location.RootResizeDirection;
import com.fr.design.designer.beans.models.AddingModel; import com.fr.design.designer.beans.models.AddingModel;
import com.fr.design.designer.beans.models.DraggingModel; import com.fr.design.designer.beans.models.DraggingModel;
import com.fr.design.designer.beans.models.ModelUtil;
import com.fr.design.designer.beans.models.SelectionModel; import com.fr.design.designer.beans.models.SelectionModel;
import com.fr.design.designer.beans.models.StateModel; import com.fr.design.designer.beans.models.StateModel;
import com.fr.design.designer.creator.XChartEditor; import com.fr.design.designer.creator.XChartEditor;
@ -1163,18 +1166,10 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
return addingModel; return addingModel;
} }
public void setAddingModel(AddingModel addingModel) {
this.addingModel = addingModel;
}
public DraggingModel getDraggingModel() { public DraggingModel getDraggingModel() {
return draggingModel; return draggingModel;
} }
public void setDraggingModel(DraggingModel draggingModel) {
this.draggingModel = draggingModel;
}
public XCreator getComponentAt(MouseEvent e) { public XCreator getComponentAt(MouseEvent e) {
return getComponentAt(e.getX(), e.getY()); return getComponentAt(e.getX(), e.getY());
} }
@ -1257,11 +1252,20 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
.creator(xCreator) .creator(xCreator)
.startDragEvent(startDragEvent) .startDragEvent(startDragEvent)
.currentDragEvent(currentDragEvent); .currentDragEvent(currentDragEvent);
addingModel = new AddingModel(this, xCreator); instantiateCreator(xCreator);
this.setDropTarget(new FormCreatorDropTarget(this)); addingModel = new AddingModel(xCreator);
this.setDropTarget(new FormCreatorDropTarget(this, xCreator));
repaint(); repaint();
} }
public void instantiateCreator(XCreator creator) {
ModelUtil.renameWidgetName(this.getTarget(), creator);
ComponentAdapter adapter = new CompositeComponentAdapter(this, creator);
adapter.initialize();
creator.addNotify();
creator.putClientProperty(AdapterBus.CLIENT_PROPERTIES, adapter);
}
/** /**
* 拖拽表单上的组件 * 拖拽表单上的组件
* *
@ -1275,6 +1279,8 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
.creator(xCreator) .creator(xCreator)
.startDragEvent(startDragEvent) .startDragEvent(startDragEvent)
.currentDragEvent(currentDragEvent); .currentDragEvent(currentDragEvent);
xCreator.backupCurrentSize();
xCreator.backupParent();
XLayoutContainer container = this.getDraggingHotspotLayout(); XLayoutContainer container = this.getDraggingHotspotLayout();
LayoutAdapter adapter = container.getLayoutAdapter(); LayoutAdapter adapter = container.getLayoutAdapter();
adapter.dragging(this.getDraggingModel()); adapter.dragging(this.getDraggingModel());
@ -1981,11 +1987,12 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
return spacingLineDrawer; return spacingLineDrawer;
} }
public void addWidgetToForm(int x, int y) { public void addWidgetToForm(XCreator creator, int x, int y) {
if(addingModel == null) { if(creator == null) {
return; return;
} }
addingModel = new AddingModel(creator);
// 当前鼠标所在的组件 // 当前鼠标所在的组件
XCreator hoveredComponent = this.getComponentAt(x, y); XCreator hoveredComponent = this.getComponentAt(x, y);
// 获取该组件所在的焦点容器 // 获取该组件所在的焦点容器

210
designer-form/src/test/java/com/fr/design/designer/beans/models/AddingModelTest.java

@ -1,210 +0,0 @@
package com.fr.design.designer.beans.models;
import com.fr.base.chart.BaseChartCollection;
import com.fr.config.dao.DaoContext;
import com.fr.config.dao.impl.LocalClassHelperDao;
import com.fr.config.dao.impl.LocalEntityDao;
import com.fr.config.dao.impl.LocalXmlEntityDao;
import com.fr.design.designer.creator.CRPropertyDescriptor;
import com.fr.design.designer.creator.XChartEditor;
import com.fr.design.designer.creator.XCreator;
import com.fr.design.designer.creator.XLayoutContainer;
import com.fr.design.designer.creator.XWTitleLayout;
import com.fr.design.designer.creator.cardlayout.XWCardLayout;
import com.fr.design.gui.chart.MiddleChartComponent;
import com.fr.design.mainframe.FormDesigner;
import com.fr.design.module.DesignModuleFactory;
import com.fr.form.main.Form;
import com.fr.form.ui.ChartEditor;
import com.fr.form.ui.Widget;
import com.fr.form.ui.container.WAbsoluteLayout;
import com.fr.form.ui.container.WCardLayout;
import com.fr.form.ui.container.WTitleLayout;
import com.fr.stable.core.PropertyChangeListener;
import org.easymock.EasyMock;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import javax.swing.JComponent;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.beans.IntrospectionException;
@PrepareForTest({DesignModuleFactory.class})
@PowerMockIgnore({"com.sun.*", "javax.*", "com.fr.jvm.assist.*"})
@RunWith(PowerMockRunner.class)
public class AddingModelTest {
@Before
public void setUp() {
DaoContext.setXmlEntityDao(new LocalXmlEntityDao());
DaoContext.setClassHelperDao(new LocalClassHelperDao());
DaoContext.setEntityDao(new LocalEntityDao());
}
@After
public void tearDown() {
DaoContext.setXmlEntityDao(null);
DaoContext.setClassHelperDao(null);
DaoContext.setEntityDao(null);
}
/**
* 默认名字 + i
*/
@Test
public void testInstantiateCreator() throws Exception {
Dimension dimension = new Dimension(20, 20);
ChartEditor chartEditor1 = new ChartEditor();
XCreator xCreator1 = new DemoCreator(chartEditor1, dimension, "test");
ChartEditor chartEditor2 = new ChartEditor();
chartEditor2.setWidgetName("test02");
XCreator xCreator2 = new DemoCreator(chartEditor2, dimension, "test02");
xCreator1.add(xCreator2);
ChartEditor chartEditor3 = new ChartEditor();
chartEditor3.setWidgetName("test03");
WAbsoluteLayout.BoundsWidget boundsWidget = new WAbsoluteLayout.BoundsWidget(chartEditor3, new Rectangle(dimension));
WTitleLayout wTitleLayout03 = new WTitleLayout();
wTitleLayout03.addWidget(boundsWidget);
//需要和内部的 widget 一样
wTitleLayout03.setWidgetName("test03");
XWTitleLayout xCreator3 = new XWTitleLayout(wTitleLayout03, dimension);
xCreator1.add(xCreator3);
AddingModel addingModel = new AddingModel(xCreator1, 20, 20);
Form form = EasyMock.mock(Form.class);
EasyMock.expect(form.isNameExist("test0")).andReturn(true).once();
EasyMock.expect(form.isNameExist("test03")).andReturn(true).once();
EasyMock.expect(form.isNameExist(EasyMock.anyString())).andReturn(false).anyTimes();
EasyMock.replay(form);
FormDesigner mock = EasyMock.mock(FormDesigner.class);
EasyMock.expect(mock.getTarget()).andReturn(form).anyTimes();
EasyMock.replay(mock);
addingModel.instantiateCreator(mock);
//没有默认参数, 但已经存在 test
Assert.assertEquals("test1", xCreator1.toData().getWidgetName());
//直接返回
Assert.assertEquals("test020", xCreator2.toData().getWidgetName());
//已经存在,后接0
Assert.assertEquals("test030", xCreator3.toData().getWidgetName());
}
@Test
public void testInstantiateCreator_cardLayout() throws Exception {
Form form = EasyMock.mock(Form.class);
EasyMock.expect(form.isNameExist("cardlayout0")).andReturn(true).once();
EasyMock.expect(form.isNameExist("cardlayout1")).andReturn(true).once();
EasyMock.expect(form.isNameExist(EasyMock.anyString())).andReturn(false).anyTimes();
EasyMock.replay(form);
FormDesigner mock = EasyMock.mock(FormDesigner.class);
EasyMock.expect(mock.getTarget()).andReturn(form).anyTimes();
EasyMock.replay(mock);
WCardLayout wCardLayout = new WCardLayout(20, 20);
XWCardLayout xwCardLayout = new XWCardLayout(wCardLayout, new Dimension(40, 40));
AddingModel addingModel = new AddingModel(mock, xwCardLayout);
Assert.assertEquals("cardlayout2", xwCardLayout.toData().getWidgetName());
//依赖于 cardlayout 创建 container
XLayoutContainer parentLayOut = xwCardLayout.initCreatorWrapper(80);
//组件默认名 tablelayout2
AddingModel parentModel = new AddingModel(mock, parentLayOut);
//经过处理 tablayout20
Assert.assertEquals("tablayout20", parentLayOut.toData().getWidgetName());
Assert.assertEquals("tabpane20", ((XCreator) (parentLayOut.getComponent(0))).getXCreator().toData().getWidgetName());
Assert.assertEquals("cardlayout20", xwCardLayout.toData().getWidgetName());
}
@Test
public void testInstantiateCreator_containsNotXCreator() throws Exception {
Form form = EasyMock.mock(Form.class);
EasyMock.expect(form.isNameExist(EasyMock.anyString())).andReturn(false).anyTimes();
EasyMock.replay(form);
FormDesigner mock = EasyMock.mock(FormDesigner.class);
EasyMock.expect(mock.getTarget()).andReturn(form).anyTimes();
EasyMock.replay(mock);
PowerMock.mockStaticPartial(DesignModuleFactory.class, "getChartComponent");
EasyMock.expect(DesignModuleFactory.getChartComponent(EasyMock.anyObject(BaseChartCollection.class))).andReturn(new MiddleChartComponent() {
@Override
public void populate(BaseChartCollection cc) {
}
@Override
public BaseChartCollection update() {
return null;
}
@Override
public void reset() {
}
@Override
public void addStopEditingListener(PropertyChangeListener list) {
}
}).anyTimes();
PowerMock.replayAll();
Dimension dimension = new Dimension(20, 20);
ChartEditor chartEditor1 = new ChartEditor();
XCreator xCreator1 = new XChartEditor(chartEditor1, dimension);
AddingModel chartModel = new AddingModel(mock, xCreator1);
Assert.assertEquals("chart0", xCreator1.toData().getWidgetName());
}
private static class DemoCreator extends XCreator {
private String widgetName;
public DemoCreator(Widget ob, Dimension initSize, String defaultName) {
super(ob, initSize);
this.widgetName = defaultName;
}
@Override
public CRPropertyDescriptor[] supportedDescriptor() throws IntrospectionException {
return new CRPropertyDescriptor[0];
}
@Override
protected JComponent initEditor() {
return null;
}
@Override
protected void initXCreatorProperties() {
}
@Override
public String createDefaultName() {
return this.widgetName;
}
}
}

13
designer-realize/src/main/java/com/fr/design/mainframe/guide/creator/GuideCreateUtils.java

@ -1,6 +1,5 @@
package com.fr.design.mainframe.guide.creator; package com.fr.design.mainframe.guide.creator;
import com.fr.design.designer.beans.models.AddingModel;
import com.fr.design.designer.creator.XCreator; import com.fr.design.designer.creator.XCreator;
import com.fr.design.designer.creator.XLayoutContainer; import com.fr.design.designer.creator.XLayoutContainer;
import com.fr.design.dialog.FineJOptionPane; import com.fr.design.dialog.FineJOptionPane;
@ -126,22 +125,14 @@ public class GuideCreateUtils {
return null; return null;
} }
public static void addXCreatorToXLayoutContainer(XCreator xCreator, XLayoutContainer xLayoutContainer, boolean isDragComponent) { public static void addXCreatorToXLayoutContainer(XCreator xCreator, XLayoutContainer xLayoutContainer) {
if (xCreator == null) { if (xCreator == null) {
return; return;
} }
FormDesigner designer = GuideCreateUtils.getFormDesigner(); FormDesigner designer = GuideCreateUtils.getFormDesigner();
designer.getSelectionModel().selectACreator(xLayoutContainer); designer.getSelectionModel().selectACreator(xLayoutContainer);
if (isDragComponent) { designer.addWidgetToForm(xCreator, xLayoutContainer.getX(), xLayoutContainer.getY());
designer.setAddingModel(new AddingModel(xCreator, 0,0));
} else {
designer.setAddingModel(new AddingModel(designer, xCreator));
}
designer.repaint();
designer.addWidgetToForm(xLayoutContainer.getX(), xLayoutContainer.getY());
designer.getSelectionModel().selectACreator(xCreator); designer.getSelectionModel().selectACreator(xCreator);
} }

4
designer-realize/src/main/java/com/fr/design/mainframe/guide/creator/layout/ChangeLayoutComponentGuide.java

@ -136,8 +136,8 @@ public class ChangeLayoutComponentGuide {
formDesigner.getSelectionModel().removeCreator(from, from.getWidth(), from.getHeight()); formDesigner.getSelectionModel().removeCreator(from, from.getWidth(), from.getHeight());
formDesigner.getSelectionModel().removeCreator(to, to.getWidth(),to.getHeight()); formDesigner.getSelectionModel().removeCreator(to, to.getWidth(),to.getHeight());
GuideCreateUtils.addXCreatorToXLayoutContainer(from, (XLayoutContainer) GuideCreateUtils.getXCreatorFormDesigner("box1"), true); GuideCreateUtils.addXCreatorToXLayoutContainer(from, (XLayoutContainer) GuideCreateUtils.getXCreatorFormDesigner("box1"));
GuideCreateUtils.addXCreatorToXLayoutContainer(to, (XLayoutContainer) GuideCreateUtils.getXCreatorFormDesigner("box0"), true); GuideCreateUtils.addXCreatorToXLayoutContainer(to, (XLayoutContainer) GuideCreateUtils.getXCreatorFormDesigner("box0"));
return true; return true;
} }
}); });

2
designer-realize/src/main/java/com/fr/design/mainframe/guide/creator/layout/UseLayoutAndComponentGuide.java

@ -246,7 +246,7 @@ public class UseLayoutAndComponentGuide {
LocalWidgetBlock block = getLocalWidgetBlock(shareID); LocalWidgetBlock block = getLocalWidgetBlock(shareID);
XCreator xCreator = block.transformXCreator(block); XCreator xCreator = block.transformXCreator(block);
XOccupiedLayout xOccupiedLayout = getXOccupiedLayout(name); XOccupiedLayout xOccupiedLayout = getXOccupiedLayout(name);
GuideCreateUtils.addXCreatorToXLayoutContainer(xCreator, xOccupiedLayout, false); GuideCreateUtils.addXCreatorToXLayoutContainer(xCreator, xOccupiedLayout);
return true; return true;
} }
}); });

Loading…
Cancel
Save