Browse Source

REPORT-62275 表单拖入失败-自动撤销

bugfix/11.0
方磊 3 years ago
parent
commit
e49f8cd9c9
  1. 3
      designer-form/src/main/java/com/fr/design/designer/beans/LayoutAdapter.java
  2. 3
      designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/AbstractLayoutAdapter.java
  3. 8
      designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/FRFitLayoutAdapter.java
  4. 7
      designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/FRNoFixLayoutAdapter.java
  5. 8
      designer-form/src/main/java/com/fr/design/designer/beans/models/AddingModel.java
  6. 6
      designer-form/src/main/java/com/fr/design/designer/beans/models/SelectionModel.java
  7. 17
      designer-form/src/main/java/com/fr/design/mainframe/FormCreatorDropTarget.java
  8. 1
      designer-form/src/main/java/com/fr/design/mainframe/FormDesigner.java

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

3
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) {
}
}

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

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

8
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;
}
}

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

17
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);

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

@ -1210,6 +1210,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
setTransferHandler(handler);
handler.exportAsDrag(this, lastPressEvent, TransferHandler.COPY);
XLayoutContainer parent = XCreatorUtils.getParentXLayoutContainer(xCreator);
parent.getLayoutAdapter().updateAddingModel(addingModel);
parent.getLayoutAdapter().dragStart(xCreator, selectionModel);
this.setDropTarget(new FormCreatorDropTarget(this));
// 触发状态添加模式事件

Loading…
Cancel
Save