diff --git a/designer-base/src/main/java/com/fr/design/fun/RightSelectionHandlerProvider.java b/designer-base/src/main/java/com/fr/design/fun/RightSelectionHandlerProvider.java new file mode 100644 index 0000000000..5e7d414236 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/fun/RightSelectionHandlerProvider.java @@ -0,0 +1,55 @@ +package com.fr.design.fun; + +import com.fr.design.actions.UpdateAction; +import com.fr.design.designer.TargetComponent; +import com.fr.design.gui.imenu.UIPopupMenu; +import com.fr.design.mainframe.BaseFormDesigner; +import com.fr.design.selection.SelectableElement; +import com.fr.stable.fun.mark.Mutable; + +import java.util.List; + +/** + * 设计器右键菜单接口 + */ +public interface RightSelectionHandlerProvider extends Mutable { + + int CURRENT_LEVEL = 1; + + String XML_TAG = "RightSelectionHandlerProvider"; + + + /** + * 对单元格或者悬浮元素的右键菜单项进行增删改 + * + * @param ePane 选择的元素 + * @param popupMenu 右键主菜单 + */ + void dmlMenu(TargetComponent ePane, UIPopupMenu popupMenu); + + + /** + * 当前实现是否可以作用于当前元素 + * + * @param selectableElement 当前选中元素分为CellSelection和FloatSelection(单元格和悬浮元素) + * @return + */ + boolean accept(SelectableElement selectableElement); + + + /** + * 对表单,参数面板内置的右键选项进行增删改处理 + * + * @param actions 默认的action集合 注意:主体代码要求这边的action必须是UndoableAction 的子类而非updateAction + */ + void dmlUpdateActions(BaseFormDesigner formDesigner, List actions); + + /** + * 当前实现是否可以作用于当前元素 + * + * @param formDesigner 当前选中元素分为表单编辑器和参数面板(表单组件元素以及各种控件) + * @return + */ + boolean accept(BaseFormDesigner formDesigner); + +} \ No newline at end of file diff --git a/designer-base/src/main/java/com/fr/design/fun/impl/AbstractRightSelectionHandlerProvider.java b/designer-base/src/main/java/com/fr/design/fun/impl/AbstractRightSelectionHandlerProvider.java new file mode 100644 index 0000000000..6ec8282ed8 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/fun/impl/AbstractRightSelectionHandlerProvider.java @@ -0,0 +1,45 @@ +package com.fr.design.fun.impl; + +import com.fr.design.actions.UpdateAction; +import com.fr.design.designer.TargetComponent; +import com.fr.design.fun.RightSelectionHandlerProvider; +import com.fr.design.gui.imenu.UIPopupMenu; +import com.fr.design.mainframe.BaseFormDesigner; +import com.fr.design.selection.SelectableElement; +import com.fr.stable.fun.impl.AbstractProvider; +import com.fr.stable.fun.mark.API; + +import java.util.List; + +@API(level = RightSelectionHandlerProvider.CURRENT_LEVEL) +public abstract class AbstractRightSelectionHandlerProvider extends AbstractProvider implements RightSelectionHandlerProvider { + @Override + public int currentAPILevel() { + return CURRENT_LEVEL; + } + + @Override + public String mark4Provider() { + return getClass().getName(); + } + + @Override + public void dmlUpdateActions(BaseFormDesigner formDesigner, List actions) { + + } + + @Override + public boolean accept(BaseFormDesigner formDesigner) { + return false; + } + + @Override + public void dmlMenu(TargetComponent ePane, UIPopupMenu popupMenu) { + + } + + @Override + public boolean accept(SelectableElement selectableElement) { + return false; + } +} \ No newline at end of file diff --git a/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java b/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java index c2557a5b9c..fa9b181a57 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java @@ -419,7 +419,7 @@ public abstract class JTemplate> fireSuperTargetModified(); } - protected boolean accept(Object o) { + public boolean accept(Object o) { return true; } diff --git a/designer-form/src/main/java/com/fr/design/form/parameter/FormParaDesigner.java b/designer-form/src/main/java/com/fr/design/form/parameter/FormParaDesigner.java index 0895d4c1dc..62cea356d6 100644 --- a/designer-form/src/main/java/com/fr/design/form/parameter/FormParaDesigner.java +++ b/designer-form/src/main/java/com/fr/design/form/parameter/FormParaDesigner.java @@ -11,6 +11,7 @@ import java.awt.Image; import java.awt.Insets; import java.awt.Rectangle; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import javax.swing.BorderFactory; @@ -324,10 +325,11 @@ public class FormParaDesigner extends FormDesigner implements ParameterDesignerP */ public UpdateAction[] getActions() { if (designerActions == null) { - designerActions = new UpdateAction[]{new CutAction(this), new CopyAction(this), new PasteAction(this), - new FormDeleteAction(this)}; + designerActions = new ArrayList(Arrays.asList(new UpdateAction[]{new CutAction(this), new CopyAction(this), new PasteAction(this), + new FormDeleteAction(this)})); + dmlActions(designerActions); } - return designerActions; + return designerActions.toArray(new UpdateAction[designerActions.size()]); } private boolean searchQueryCreators(XLayoutContainer rootContainer) { 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 b313bc1433..fd0de4b257 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 @@ -1,9 +1,11 @@ package com.fr.design.mainframe; +import com.fr.base.FRContext; import com.fr.base.Parameter; import com.fr.base.ScreenResolution; import com.fr.base.vcs.DesignerMode; import com.fr.design.DesignState; +import com.fr.design.ExtraDesignClassManager; import com.fr.design.actions.UpdateAction; import com.fr.design.base.mode.DesignModeContext; import com.fr.design.designer.TargetComponent; @@ -39,6 +41,7 @@ import com.fr.design.designer.properties.FormWidgetAuthorityEditPane; import com.fr.design.event.DesignerOpenedListener; import com.fr.design.file.HistoryTemplateListPane; import com.fr.design.form.util.XCreatorConstants; +import com.fr.design.fun.RightSelectionHandlerProvider; import com.fr.design.mainframe.toolbar.ToolBarMenuDockPlus; import com.fr.design.menu.MenuDef; import com.fr.design.menu.ShortCut; @@ -89,6 +92,7 @@ import java.lang.reflect.Proxy; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Set; /** * 设计界面组件。该组件是界面设计工具的核心,主要负责的是被设计界面的显示,界面设计操作状态的 显示,编辑状态的显示等等。 @@ -132,7 +136,7 @@ public class FormDesigner extends TargetComponent
implements TreeSelection private int resolution = ScreenResolution.getScreenResolution(); // 编辑状态的事件表 private CreatorEventListenerTable edit; - protected UpdateAction[] designerActions; + protected List designerActions; private FormDesignerModeForSpecial desigerMode; private Action switchAction; private FormElementCaseContainerProvider elementCaseContainer; @@ -1180,11 +1184,28 @@ public class FormDesigner extends TargetComponent implements TreeSelection */ public UpdateAction[] getActions() { if (designerActions == null) { - designerActions = new UpdateAction[]{new CutAction(this), new CopyAction(this), new PasteAction(this), + designerActions = new ArrayList(Arrays.asList(new UpdateAction[]{new CutAction(this), new CopyAction(this), new PasteAction(this), new FormDeleteAction(this), new MoveToTopAction(this), new MoveToBottomAction(this), - new MoveUpAction(this), new MoveDownAction(this)}; + new MoveUpAction(this), new MoveDownAction(this)})); + dmlActions(designerActions); + } + return designerActions.toArray(new UpdateAction[designerActions.size()]); + } + /** + * 扩展菜单项 + * @param actions + */ + public void dmlActions(List actions) { + try { + Set selectionHandlerProviders = ExtraDesignClassManager.getInstance().getArray(RightSelectionHandlerProvider.XML_TAG); + for (RightSelectionHandlerProvider handler : selectionHandlerProviders) { + if (handler.accept(this)) { + handler.dmlUpdateActions(this,actions); + } + } + } catch (Exception e) { + FRContext.getLogger().error(e.getMessage(), e); } - return designerActions; } // 当前选中控件可以上移一层吗? diff --git a/designer-form/src/main/java/com/fr/design/mainframe/JForm.java b/designer-form/src/main/java/com/fr/design/mainframe/JForm.java index ec8020fd21..cc3ba96f5c 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/JForm.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/JForm.java @@ -160,7 +160,7 @@ public class JForm extends JTemplate implements BaseJForm { } @Override - protected boolean accept(Object o) { + public boolean accept(Object o) { return !(o instanceof FloatElementsProvider); } diff --git a/designer-realize/src/main/java/com/fr/design/cell/clipboard/CellElementsClip.java b/designer-realize/src/main/java/com/fr/design/cell/clipboard/CellElementsClip.java index 2579e37c2e..84edad71fb 100644 --- a/designer-realize/src/main/java/com/fr/design/cell/clipboard/CellElementsClip.java +++ b/designer-realize/src/main/java/com/fr/design/cell/clipboard/CellElementsClip.java @@ -3,9 +3,6 @@ */ package com.fr.design.cell.clipboard; -import java.util.Arrays; -import java.util.Iterator; - import com.fr.base.FRContext; import com.fr.grid.selection.CellSelection; import com.fr.report.cell.CellElement; @@ -15,6 +12,9 @@ import com.fr.report.elementcase.TemplateElementCase; import com.fr.stable.StringUtils; import com.fr.stable.unit.FU; +import java.util.Arrays; +import java.util.Iterator; + /** * The clip of CellElement. */ @@ -39,7 +39,47 @@ public class CellElementsClip implements Cloneable, java.io.Serializable { this.clips = clips; } - public String compateExcelPaste() { + public int getColumnSpan() { + return columnSpan; + } + + public void setColumnSpan(int columnSpan) { + this.columnSpan = columnSpan; + } + + public int getRowSpan() { + return rowSpan; + } + + public void setRowSpan(int rowSpan) { + this.rowSpan = rowSpan; + } + + public FU[] getColumnWidth() { + return columnWidth; + } + + public void setColumnWidth(FU[] columnWidth) { + this.columnWidth = columnWidth; + } + + public FU[] getRowHeight() { + return rowHeight; + } + + public void setRowHeight(FU[] rowHeight) { + this.rowHeight = rowHeight; + } + + public TemplateCellElement[] getClips() { + return clips; + } + + public void setClips(TemplateCellElement[] clips) { + this.clips = clips; + } + + public String compateExcelPaste() { Arrays.sort(this.clips, CellElementComparator.getRowFirstComparator()); // 排序 diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/ElementCasePane.java b/designer-realize/src/main/java/com/fr/design/mainframe/ElementCasePane.java index c47b142c1c..4112ac6c44 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/ElementCasePane.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/ElementCasePane.java @@ -663,7 +663,7 @@ public abstract class ElementCasePane extends Tar } } - private Object getClipObject() { + public Object getClipObject() { // 需要检查是否可以编辑。 Clipboard clipboard = DesignerContext.getClipboard(this.getGrid()); Transferable clipData = clipboard.getContents(this); diff --git a/designer-realize/src/main/java/com/fr/grid/selection/Selection.java b/designer-realize/src/main/java/com/fr/grid/selection/Selection.java index 6787e36a5c..1d7a8b3fcf 100644 --- a/designer-realize/src/main/java/com/fr/grid/selection/Selection.java +++ b/designer-realize/src/main/java/com/fr/grid/selection/Selection.java @@ -1,19 +1,22 @@ package com.fr.grid.selection; -import java.io.Serializable; - -import javax.swing.JPopupMenu; - import com.fr.base.FRContext; +import com.fr.design.ExtraDesignClassManager; import com.fr.design.cell.clipboard.CellElementsClip; import com.fr.design.cell.clipboard.ElementsTransferable; import com.fr.design.cell.clipboard.FloatElementsClip; +import com.fr.design.fun.RightSelectionHandlerProvider; +import com.fr.design.gui.imenu.UIPopupMenu; import com.fr.design.mainframe.ElementCasePane; -import com.fr.report.elementcase.TemplateElementCase; import com.fr.design.selection.SelectableElement; +import com.fr.report.elementcase.TemplateElementCase; import com.fr.stable.ColumnRow; import com.fr.stable.FCloneable; +import javax.swing.JPopupMenu; +import java.io.Serializable; +import java.util.Set; + /* * TODO ALEX_SEP Selection是跟ElementCasePane绑定的,能不能把ElementCasePane保存在Selection里面呢? * @@ -65,6 +68,20 @@ public abstract class Selection implements FCloneable, Serializable , Selectable // ///////////////////////////////popup//////////////////////////////// public abstract JPopupMenu createPopupMenu(ElementCasePane ePane); + /** + * 添加插件菜单(增删改都可以) + * @param ePane + * @param popupMenu + */ + public void addExtraMenu(ElementCasePane ePane, UIPopupMenu popupMenu) { + Set selectionHandlerProviders = ExtraDesignClassManager.getInstance().getArray(RightSelectionHandlerProvider.XML_TAG); + for (RightSelectionHandlerProvider handler : selectionHandlerProviders) { + if (handler.accept(this)) { + handler.dmlMenu(ePane, popupMenu); + } + } + } + // ///////////////////////////////clear//////////////////////////////// public abstract boolean clear(ElementCasePane.Clear type, ElementCasePane ePane);