diff --git a/designer-form/src/main/java/com/fr/design/designer/beans/LayoutAdapter.java b/designer-form/src/main/java/com/fr/design/designer/beans/LayoutAdapter.java index 438699b86c..7686709a32 100644 --- a/designer-form/src/main/java/com/fr/design/designer/beans/LayoutAdapter.java +++ b/designer-form/src/main/java/com/fr/design/designer/beans/LayoutAdapter.java @@ -3,6 +3,7 @@ package com.fr.design.designer.beans; import com.fr.design.beans.GroupModel; import com.fr.design.designer.beans.adapters.layout.DefaultDesignerBaseOperate; import com.fr.design.designer.beans.adapters.layout.DesignerBaseOperate; +import com.fr.design.designer.beans.models.AddingModel; import com.fr.design.designer.beans.models.SelectionModel; import com.fr.design.designer.creator.XCreator; import com.fr.design.designer.treeview.DefaultXCreatorTreeCellRender; @@ -141,4 +142,6 @@ public interface LayoutAdapter { }; + void updateAddingModel(AddingModel model); + } diff --git a/designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/AbstractLayoutAdapter.java b/designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/AbstractLayoutAdapter.java index 98b6c88558..a2e9b71ff6 100644 --- a/designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/AbstractLayoutAdapter.java +++ b/designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/AbstractLayoutAdapter.java @@ -4,6 +4,7 @@ import com.fr.design.beans.GroupModel; import com.fr.design.designer.beans.ConstraintsGroupModel; import com.fr.design.designer.beans.HoverPainter; import com.fr.design.designer.beans.LayoutAdapter; +import com.fr.design.designer.beans.models.AddingModel; import com.fr.design.designer.beans.models.SelectionModel; import com.fr.design.designer.beans.painters.NullPainter; import com.fr.design.designer.creator.XCreator; @@ -210,5 +211,7 @@ public abstract class AbstractLayoutAdapter implements LayoutAdapter { selectionModel.setSelectedCreator(container); } + public void updateAddingModel(AddingModel model) { + } } diff --git a/designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/FRFitLayoutAdapter.java b/designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/FRFitLayoutAdapter.java index d17e9689e6..747479cbbb 100644 --- a/designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/FRFitLayoutAdapter.java +++ b/designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/FRFitLayoutAdapter.java @@ -8,6 +8,7 @@ import com.fr.design.beans.GroupModel; import com.fr.design.designer.beans.ConstraintsGroupModel; import com.fr.design.designer.beans.HoverPainter; import com.fr.design.designer.beans.LayoutAdapter; +import com.fr.design.designer.beans.models.AddingModel; import com.fr.design.designer.beans.models.SelectionModel; import com.fr.design.designer.creator.XCreator; import com.fr.design.designer.creator.XCreatorUtils; @@ -1243,5 +1244,10 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter { public void dragOver(XCreator xCreator, SelectionModel selectionModel,int x, int y) { frLayoutState.dragOver(xCreator, selectionModel,x,y); - }; + } + + @Override + public void updateAddingModel(AddingModel model) { + frLayoutState.updateAddingModel(model); + } } diff --git a/designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/FRNoFixLayoutAdapter.java b/designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/FRNoFixLayoutAdapter.java index aaeedfc8da..b278e0ffeb 100644 --- a/designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/FRNoFixLayoutAdapter.java +++ b/designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/FRNoFixLayoutAdapter.java @@ -1,5 +1,6 @@ package com.fr.design.designer.beans.adapters.layout; +import com.fr.design.designer.beans.models.AddingModel; import com.fr.design.designer.beans.models.SelectionModel; import com.fr.design.designer.beans.painters.AbstractPainter; import com.fr.design.designer.beans.painters.FRFitLayoutPainter; @@ -144,6 +145,12 @@ public class FRNoFixLayoutAdapter extends AbstractLayoutAdapter { @Override public void dragStart(XCreator xCreator, SelectionModel selectionModel) { selectionModel.removeCreator(xCreator, xCreator.getWidth(), xCreator.getHeight()); + selectionModel.fireCreatorDeleted(); selectionModel.setSelectedCreator(container); } + + @Override + public void updateAddingModel(AddingModel model) { + model.setNeedUndoWhenAddingFailed(true); + } } diff --git a/designer-form/src/main/java/com/fr/design/designer/beans/models/AddingModel.java b/designer-form/src/main/java/com/fr/design/designer/beans/models/AddingModel.java index 1926b57b13..c9a9eb3306 100644 --- a/designer-form/src/main/java/com/fr/design/designer/beans/models/AddingModel.java +++ b/designer-form/src/main/java/com/fr/design/designer/beans/models/AddingModel.java @@ -24,6 +24,7 @@ public class AddingModel { private int currentX; private int currentY; private boolean added; + private boolean needUndoWhenAddingFailed = false; public AddingModel(FormDesigner designer, XCreator xCreator) { this.creator = xCreator; @@ -141,4 +142,11 @@ public class AddingModel { return added; } + public boolean isNeedUndoWhenAddingFailed() { + return needUndoWhenAddingFailed; + } + + public void setNeedUndoWhenAddingFailed(boolean needUndoWhenAddingFailed) { + this.needUndoWhenAddingFailed = needUndoWhenAddingFailed; + } } diff --git a/designer-form/src/main/java/com/fr/design/designer/beans/models/SelectionModel.java b/designer-form/src/main/java/com/fr/design/designer/beans/models/SelectionModel.java index 963f60e6c3..28456f799b 100644 --- a/designer-form/src/main/java/com/fr/design/designer/beans/models/SelectionModel.java +++ b/designer-form/src/main/java/com/fr/design/designer/beans/models/SelectionModel.java @@ -25,7 +25,6 @@ import com.fr.design.fun.FormWidgetOptionProvider; import com.fr.design.mainframe.FormDesigner; import com.fr.design.mainframe.FormSelection; import com.fr.design.mainframe.FormSelectionUtils; -import com.fr.design.mainframe.share.encrypt.clipboard.impl.EncryptSelectionClipboardHandler; import com.fr.design.utils.ComponentUtils; import com.fr.design.utils.gui.LayoutUtils; import com.fr.general.ComparatorUtils; @@ -585,4 +584,9 @@ public class SelectionModel { selection.setSelectedCreators(rebuildSelection); fireCreatorSelected(); } + + public void fireCreatorDeleted() { + designer.getEditListenerTable().fireCreatorModified(selection.getSelectedCreator(), + DesignerEvent.CREATOR_DELETED); + } } diff --git a/designer-form/src/main/java/com/fr/design/mainframe/FormCreatorDropTarget.java b/designer-form/src/main/java/com/fr/design/mainframe/FormCreatorDropTarget.java index 82befa2731..2b9a4f6be1 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/FormCreatorDropTarget.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/FormCreatorDropTarget.java @@ -18,6 +18,7 @@ import com.fr.design.designer.creator.XLayoutContainer; import com.fr.design.designer.creator.XWAbsoluteLayout; import com.fr.design.designer.creator.XWFitLayout; import com.fr.design.designer.creator.XWParameterLayout; +import com.fr.design.file.HistoryTemplateListPane; import com.fr.design.form.util.XCreatorConstants; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.icon.IconPathConstants; @@ -25,6 +26,7 @@ import com.fr.design.mainframe.chart.info.ChartInfoCollector; import com.fr.design.mod.bean.ChangeItem; import com.fr.design.mod.bean.ContentChangeItem; import com.fr.design.mod.event.TableDataModifyEvent; +import com.fr.design.ui.util.UIUtil; import com.fr.design.utils.ComponentUtils; import com.fr.event.EventDispatcher; import com.fr.form.share.SharableWidgetProvider; @@ -152,6 +154,9 @@ public class FormCreatorDropTarget extends DropTarget { if (creator != null) { creator.setSelected(false); } + if (designer.getAddingModel().isNeedUndoWhenAddingFailed()) { + undoWhenDropFail(); + } } // 取消提示 designer.setPainter(null); @@ -159,6 +164,18 @@ public class FormCreatorDropTarget extends DropTarget { designer.stopAddingState(); } + private void undoWhenDropFail() { + JTemplate, ?> jt = HistoryTemplateListPane.getInstance().getCurrentEditingTemplate(); + if (jt != null && jt.getUndoManager().canUndo()) { + UIUtil.invokeLaterIfNeeded(new Runnable() { + @Override + public void run() { + jt.undo(); + } + }); + } + } + private void entering(int x, int y) { // 将要添加的组件图标移动到鼠标下的位置 addingModel.moveTo(x, y); diff --git a/designer-form/src/main/java/com/fr/design/mainframe/FormDesigner.java b/designer-form/src/main/java/com/fr/design/mainframe/FormDesigner.java index 3eb40b6a28..9cf220ff80 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/FormDesigner.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/FormDesigner.java @@ -1210,6 +1210,7 @@ public class FormDesigner extends TargetComponent