Browse Source

REPORT-5668 单元格元素和悬浮元素编辑器频繁初始化导致的内存激增问题

master
yaoh.wu 7 years ago
parent
commit
237666902f
  1. 162
      designer/src/com/fr/design/actions/cell/AbstractCellElementAction.java
  2. 20
      designer/src/com/fr/design/actions/columnrow/DSColumnConditionAction.java
  3. 14
      designer/src/com/fr/design/mainframe/cell/AbstractDSCellEditorPane.java
  4. 86
      designer/src/com/fr/design/module/DesignerModule.java
  5. 97
      designer/src/com/fr/quickeditor/CellQuickEditor.java
  6. 9
      designer/src/com/fr/quickeditor/cellquick/CellBiasTextPainterEditor.java
  7. 48
      designer/src/com/fr/quickeditor/cellquick/CellDSColumnEditor.java
  8. 11
      designer/src/com/fr/quickeditor/cellquick/CellFormulaQuickEditor.java
  9. 10
      designer/src/com/fr/quickeditor/cellquick/CellImageQuickEditor.java
  10. 10
      designer/src/com/fr/quickeditor/cellquick/CellRichTextEditor.java
  11. 9
      designer/src/com/fr/quickeditor/cellquick/CellStringQuickEditor.java
  12. 8
      designer/src/com/fr/quickeditor/cellquick/CellSubReportEditor.java
  13. 2
      designer/src/com/fr/quickeditor/cellquick/layout/CellElementBarLayout.java
  14. 172
      designer_base/src/com/fr/design/actions/core/ActionFactory.java

162
designer/src/com/fr/design/actions/cell/AbstractCellElementAction.java

@ -1,10 +1,10 @@
package com.fr.design.actions.cell; package com.fr.design.actions.cell;
import com.fr.design.actions.CellSelectionAction; import com.fr.design.actions.CellSelectionAction;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.dialog.BasicDialog; import com.fr.design.dialog.BasicDialog;
import com.fr.design.dialog.BasicPane; import com.fr.design.dialog.BasicPane;
import com.fr.design.dialog.DialogActionAdapter; import com.fr.design.dialog.DialogActionAdapter;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.mainframe.ElementCasePane; import com.fr.design.mainframe.ElementCasePane;
import com.fr.grid.GridUtils; import com.fr.grid.GridUtils;
import com.fr.grid.selection.CellSelection; import com.fr.grid.selection.CellSelection;
@ -14,87 +14,93 @@ import com.fr.report.core.SheetUtils;
import com.fr.report.elementcase.TemplateElementCase; import com.fr.report.elementcase.TemplateElementCase;
import com.fr.report.stable.ReportConstants; import com.fr.report.stable.ReportConstants;
// TODO ALEX_SEP 这个类与AbstractCellAction有什么关系? /**
* TODO ALEX_SEP 这个类与AbstractCellAction有什么关系?
*
* @author null
*/
public abstract class AbstractCellElementAction extends CellSelectionAction { public abstract class AbstractCellElementAction extends CellSelectionAction {
protected AbstractCellElementAction(ElementCasePane t) {
super(t); protected AbstractCellElementAction() {
} super();
}
@Override
protected boolean executeActionReturnUndoRecordNeededWithCellSelection(CellSelection cs) { protected AbstractCellElementAction(ElementCasePane t) {
final ElementCasePane ePane = this.getEditingComponent(); super(t);
final TemplateElementCase tplEC = ePane.getEditingElementCase(); }
TemplateCellElement editCellElement = tplEC.getTemplateCellElement(cs.getColumn(), cs.getRow());
if (editCellElement == null) { @Override
editCellElement = new DefaultTemplateCellElement(cs.getColumn(), cs.getRow()); protected boolean executeActionReturnUndoRecordNeededWithCellSelection(CellSelection cs) {
tplEC.addCellElement(editCellElement); final ElementCasePane ePane = this.getEditingComponent();
} final TemplateElementCase tplEC = ePane.getEditingElementCase();
if (tplEC != null) { TemplateCellElement editCellElement = tplEC.getTemplateCellElement(cs.getColumn(), cs.getRow());
SheetUtils.calculateDefaultParent(tplEC); if (editCellElement == null) {
} editCellElement = new DefaultTemplateCellElement(cs.getColumn(), cs.getRow());
final CellSelection finalCS = cs; tplEC.addCellElement(editCellElement);
final BasicPane bp = populateBasicPane(editCellElement); }
BasicDialog dialog = bp.showWindow(DesignerContext.getDesignerFrame()); SheetUtils.calculateDefaultParent(tplEC);
dialog.addDialogActionListener(new DialogActionAdapter() { final CellSelection finalCS = cs;
@Override final BasicPane bp = populateBasicPane(editCellElement);
public void doOk() { BasicDialog dialog = bp.showWindow(DesignerContext.getDesignerFrame());
// 需要先行后列地增加新元素。 dialog.addDialogActionListener(new DialogActionAdapter() {
for (int j = 0; j < finalCS.getRowSpan(); j++) { @Override
for (int i = 0; i < finalCS.getColumnSpan(); i++) { public void doOk() {
int column = i + finalCS.getColumn(); // 需要先行后列地增加新元素。
int row = j + finalCS.getRow(); for (int j = 0; j < finalCS.getRowSpan(); j++) {
TemplateCellElement editCellElement = tplEC.getTemplateCellElement(column, row); for (int i = 0; i < finalCS.getColumnSpan(); i++) {
if (editCellElement == null) { int column = i + finalCS.getColumn();
editCellElement = new DefaultTemplateCellElement(column, row); int row = j + finalCS.getRow();
tplEC.addCellElement(editCellElement); TemplateCellElement editCellElement = tplEC.getTemplateCellElement(column, row);
} if (editCellElement == null) {
// alex:不加这一句话会导致跨行跨列的格子被多次update editCellElement = new DefaultTemplateCellElement(column, row);
if (editCellElement.getColumn() != column || editCellElement.getRow() != row) { tplEC.addCellElement(editCellElement);
continue; }
} // alex:不加这一句话会导致跨行跨列的格子被多次update
updateBasicPane(bp, editCellElement); if (editCellElement.getColumn() != column || editCellElement.getRow() != row) {
// update cell attributes continue;
if (isNeedShinkToFit()) { }
// shink to fit.(如果value是String) updateBasicPane(bp, editCellElement);
Object editElementValue = editCellElement.getValue(); // update cell attributes
if (editElementValue != null && (editElementValue instanceof String || editElementValue instanceof Number)) { if (isNeedShinkToFit()) {
// TODO ALEX_SEP 暂时用FIT_DEFAULT替代,不取reportsetting里面的设置,因为也不知道是应该放在report里面还是elementcase里面 // shink to fit.(如果value是String)
GridUtils.shrinkToFit(ReportConstants.AUTO_SHRINK_TO_FIT_DEFAULT, tplEC, editCellElement); Object editElementValue = editCellElement.getValue();
} if (editElementValue != null && (editElementValue instanceof String || editElementValue instanceof Number)) {
} // TODO ALEX_SEP 暂时用FIT_DEFAULT替代,不取reportsetting里面的设置,因为也不知道是应该放在report里面还是elementcase里面
} GridUtils.shrinkToFit(ReportConstants.AUTO_SHRINK_TO_FIT_DEFAULT, tplEC, editCellElement);
} }
ePane.fireTargetModified(); }
} }
}); }
ePane.fireTargetModified();
}
});
//控件设置记住dlg,提交入库智能添加单元格后可以show出来 //控件设置记住dlg,提交入库智能添加单元格后可以show出来
DesignerContext.setReportWritePane(dialog); DesignerContext.setReportWritePane(dialog);
dialog.setVisible(true); dialog.setVisible(true);
return false; return false;
} }
/** /**
* 初始化对话框 * 初始化对话框
* *
* @param cellElement * @param cellElement 单元格
* @return * @return 对话框
*/ */
protected abstract BasicPane populateBasicPane(TemplateCellElement cellElement); protected abstract BasicPane populateBasicPane(TemplateCellElement cellElement);
/** /**
* 更新对话框之后改变值 * 更新对话框之后改变值
* *
* @param cellElement * @param cellElement 单元格
* @return */
*/ protected abstract void updateBasicPane(BasicPane basicPane, TemplateCellElement cellElement);
protected abstract void updateBasicPane(BasicPane basicPane, TemplateCellElement cellElement);
/** /**
* if isNeedShinkToFitplease override this method * if isNeedShinkToFitplease override this method
* *
* @return isNeedShinkToFit * @return isNeedShinkToFit
*/ */
protected boolean isNeedShinkToFit() { protected boolean isNeedShinkToFit() {
return false; return false;
} }
} }

20
designer/src/com/fr/design/actions/columnrow/DSColumnConditionAction.java

@ -9,16 +9,34 @@ import com.fr.design.mainframe.ElementCasePane;
import com.fr.general.Inter; import com.fr.general.Inter;
import com.fr.report.cell.TemplateCellElement; import com.fr.report.cell.TemplateCellElement;
/**
* 数据列过滤条件Action
*
* @author null
* @version 2017年11月17日15点11分
* @since 8.0
*/
public class DSColumnConditionAction extends AbstractCellElementAction { public class DSColumnConditionAction extends AbstractCellElementAction {
public DSColumnConditionAction() {
super();
this.setName(Inter.getLocText("Filter"));
this.setMnemonic('E');
this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/expand/cellAttr.gif"));
}
public DSColumnConditionAction(ElementCasePane t) { public DSColumnConditionAction(ElementCasePane t) {
super(t); super(t);
this.setName(Inter.getLocText("Filter")); this.setName(Inter.getLocText("Filter"));
this.setMnemonic('E'); this.setMnemonic('E');
this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/expand/cellAttr.gif")); this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/expand/cellAttr.gif"));
} }
@Override
public void setEditingComponent(ElementCasePane casePane) {
super.setEditingComponent(casePane);
}
@Override @Override
protected BasicPane populateBasicPane(TemplateCellElement cellElement) { protected BasicPane populateBasicPane(TemplateCellElement cellElement) {
DSColumnConditionsPane dSColumnConditionsPane = new DSColumnConditionsPane(); DSColumnConditionsPane dSColumnConditionsPane = new DSColumnConditionsPane();

14
designer/src/com/fr/design/mainframe/cell/CellEditorPane.java → designer/src/com/fr/design/mainframe/cell/AbstractDSCellEditorPane.java

@ -2,10 +2,12 @@ package com.fr.design.mainframe.cell;
import com.fr.design.gui.iscrollbar.UIScrollBar; import com.fr.design.gui.iscrollbar.UIScrollBar;
import com.fr.design.mainframe.CellElementPropertyPane; import com.fr.design.mainframe.CellElementPropertyPane;
import com.fr.quickeditor.cellquick.CellElementBarLayout; import com.fr.quickeditor.cellquick.layout.CellElementBarLayout;
import javax.swing.*; import javax.swing.BorderFactory;
import java.awt.*; import javax.swing.JPanel;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.event.AdjustmentEvent; import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener; import java.awt.event.AdjustmentListener;
import java.awt.event.MouseWheelEvent; import java.awt.event.MouseWheelEvent;
@ -18,9 +20,11 @@ import java.awt.event.MouseWheelListener;
* @version 2017年7月25日 * @version 2017年7月25日
* @since 9.0 * @since 9.0
*/ */
public abstract class CellEditorPane extends JPanel { public abstract class AbstractDSCellEditorPane extends JPanel {
/*滚动条相关配置*/ /**
* 滚动条相关配置
*/
private static final int MAXVALUE = 100; private static final int MAXVALUE = 100;
private static final int TITLE_HEIGHT = 95; private static final int TITLE_HEIGHT = 95;
private static final int CONTENT_PANE_WIDTH_GAP = 3; private static final int CONTENT_PANE_WIDTH_GAP = 3;

86
designer/src/com/fr/design/module/DesignerModule.java

@ -1,13 +1,27 @@
package com.fr.design.module; package com.fr.design.module;
import com.fr.base.*; import com.fr.base.BaseFormula;
import com.fr.base.BaseUtils;
import com.fr.base.ConfigManager;
import com.fr.base.FRContext;
import com.fr.base.Formula;
import com.fr.base.MultiFieldParameter;
import com.fr.base.Style;
import com.fr.base.TempNameStyle;
import com.fr.base.io.XMLEncryptUtils; import com.fr.base.io.XMLEncryptUtils;
import com.fr.base.process.ProcessOperator; import com.fr.base.process.ProcessOperator;
import com.fr.base.remote.RemoteDeziConstants; import com.fr.base.remote.RemoteDeziConstants;
import com.fr.design.DesignerEnvManager; import com.fr.design.DesignerEnvManager;
import com.fr.design.ExtraDesignClassManager; import com.fr.design.ExtraDesignClassManager;
import com.fr.design.actions.core.ActionFactory; import com.fr.design.actions.core.ActionFactory;
import com.fr.design.actions.insert.cell.*; import com.fr.design.actions.insert.cell.BiasCellAction;
import com.fr.design.actions.insert.cell.ChartCellAction;
import com.fr.design.actions.insert.cell.DSColumnCellAction;
import com.fr.design.actions.insert.cell.FormulaCellAction;
import com.fr.design.actions.insert.cell.GeneralCellAction;
import com.fr.design.actions.insert.cell.ImageCellAction;
import com.fr.design.actions.insert.cell.RichTextCellAction;
import com.fr.design.actions.insert.cell.SubReportCellAction;
import com.fr.design.actions.insert.flot.ChartFloatAction; import com.fr.design.actions.insert.flot.ChartFloatAction;
import com.fr.design.actions.insert.flot.FormulaFloatAction; import com.fr.design.actions.insert.flot.FormulaFloatAction;
import com.fr.design.actions.insert.flot.ImageFloatAction; import com.fr.design.actions.insert.flot.ImageFloatAction;
@ -17,7 +31,11 @@ import com.fr.design.fun.ElementUIProvider;
import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.ilable.UILabel;
import com.fr.design.javascript.ProcessTransitionAdapter; import com.fr.design.javascript.ProcessTransitionAdapter;
import com.fr.design.mainframe.*; import com.fr.design.mainframe.App;
import com.fr.design.mainframe.DecodeDialog;
import com.fr.design.mainframe.InformationCollector;
import com.fr.design.mainframe.JTemplate;
import com.fr.design.mainframe.JWorkBook;
import com.fr.design.mainframe.bbs.BBSGuestPane; import com.fr.design.mainframe.bbs.BBSGuestPane;
import com.fr.design.mainframe.form.FormECCompositeProvider; import com.fr.design.mainframe.form.FormECCompositeProvider;
import com.fr.design.mainframe.form.FormECDesignerProvider; import com.fr.design.mainframe.form.FormECDesignerProvider;
@ -27,14 +45,24 @@ import com.fr.design.mainframe.loghandler.DesignerLogImpl;
import com.fr.design.parameter.WorkBookParameterReader; import com.fr.design.parameter.WorkBookParameterReader;
import com.fr.design.utils.gui.GUICoreUtils; import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.file.FILE; import com.fr.file.FILE;
import com.fr.general.*; import com.fr.general.ComparatorUtils;
import com.fr.general.FRLogger;
import com.fr.general.IOUtils;
import com.fr.general.Inter;
import com.fr.general.ModuleContext;
import com.fr.general.xml.GeneralXMLTools; import com.fr.general.xml.GeneralXMLTools;
import com.fr.io.importer.Excel2007ReportImporter; import com.fr.io.importer.Excel2007ReportImporter;
import com.fr.io.importer.ExcelReportImporter; import com.fr.io.importer.ExcelReportImporter;
import com.fr.main.impl.WorkBook; import com.fr.main.impl.WorkBook;
import com.fr.quickeditor.cellquick.CellBiasTextPainterEditor;
import com.fr.quickeditor.cellquick.CellDSColumnEditor;
import com.fr.quickeditor.cellquick.CellFormulaQuickEditor;
import com.fr.quickeditor.cellquick.CellImageQuickEditor;
import com.fr.quickeditor.cellquick.CellRichTextEditor;
import com.fr.quickeditor.cellquick.CellStringQuickEditor;
import com.fr.quickeditor.cellquick.CellSubReportEditor;
import com.fr.quickeditor.chartquick.BasicChartQuickEditor; import com.fr.quickeditor.chartquick.BasicChartQuickEditor;
import com.fr.quickeditor.chartquick.FloatChartQuickEditor; import com.fr.quickeditor.chartquick.FloatChartQuickEditor;
import com.fr.quickeditor.cellquick.*;
import com.fr.quickeditor.floatquick.FloatImageQuickEditor; import com.fr.quickeditor.floatquick.FloatImageQuickEditor;
import com.fr.quickeditor.floatquick.FloatStringQuickEditor; import com.fr.quickeditor.floatquick.FloatStringQuickEditor;
import com.fr.report.cell.CellElementValueConverter; import com.fr.report.cell.CellElementValueConverter;
@ -56,8 +84,11 @@ import com.fr.stable.xml.ObjectXMLWriterFinder;
import com.fr.start.BBSGuestPaneProvider; import com.fr.start.BBSGuestPaneProvider;
import com.fr.xml.ReportXMLUtils; import com.fr.xml.ReportXMLUtils;
import javax.swing.*; import javax.swing.JDialog;
import java.awt.*; import javax.swing.JPanel;
import javax.swing.SwingConstants;
import java.awt.BorderLayout;
import java.awt.Image;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
@ -108,23 +139,27 @@ public class DesignerModule extends DesignModule {
/** /**
* kunsnat:注册单元格选中Editor * kunsnat:注册单元格选中Editor
*/ */
private void registerCellEditor() { private void registerCellEditor() {
ActionFactory.registerCellEditor(String.class, CellStringQuickEditor.class);
ActionFactory.registerCellEditor(Number.class, CellStringQuickEditor.class); ActionFactory.registerCellEditor(String.class, new CellStringQuickEditor());
ActionFactory.registerCellEditor(BaseFormula.class, CellFormulaQuickEditor.class); ActionFactory.registerCellEditor(Number.class, new CellStringQuickEditor());
ActionFactory.registerCellEditor(SubReport.class, CellSubReportEditor.class); ActionFactory.registerCellEditor(BaseFormula.class, new CellFormulaQuickEditor());
ActionFactory.registerCellEditor(RichText.class, CellRichTextEditor.class); ActionFactory.registerCellEditor(SubReport.class, new CellSubReportEditor());
ActionFactory.registerCellEditor(DSColumn.class, CellDSColumnEditor.class); ActionFactory.registerCellEditor(RichText.class, new CellRichTextEditor());
ActionFactory.registerCellEditor(Image.class, CellImageQuickEditor.class); ActionFactory.registerCellEditor(DSColumn.class, new CellDSColumnEditor());
ActionFactory.registerCellEditor(BiasTextPainter.class, CellBiasTextPainterEditor.class); ActionFactory.registerCellEditor(Image.class, new CellImageQuickEditor());
ActionFactory.registerCellEditor(BufferedImage.class, CellImageQuickEditor.class); ActionFactory.registerCellEditor(BiasTextPainter.class, new CellBiasTextPainterEditor());
ActionFactory.registerCellEditor(BufferedImage.class, new CellImageQuickEditor());
ActionFactory.registerChartCellEditorInEditor(BasicChartQuickEditor.class);
ActionFactory.registerChartCellEditorInEditor(new BasicChartQuickEditor());
Set<ElementUIProvider> providers = ExtraDesignClassManager.getInstance().getArray(ElementUIProvider.MARK_STRING); Set<ElementUIProvider> providers = ExtraDesignClassManager.getInstance().getArray(ElementUIProvider.MARK_STRING);
for (ElementUIProvider provider : providers) { for (ElementUIProvider provider : providers) {
ActionFactory.registerCellEditor(provider.targetObjectClass(), provider.quickEditor()); try {
ActionFactory.registerCellEditor(provider.targetObjectClass(), provider.quickEditor().newInstance());
} catch (Exception e) {
FRLogger.getLogger().error(e.getMessage(), e);
}
} }
} }
@ -138,12 +173,13 @@ public class DesignerModule extends DesignModule {
* kunnat: 注册悬浮选中Editor * kunnat: 注册悬浮选中Editor
*/ */
private void registerFloatEditor() { private void registerFloatEditor() {
ActionFactory.registerFloatEditor(String.class, FloatStringQuickEditor.class);
ActionFactory.registerFloatEditor(Formula.class, FloatStringQuickEditor.class); ActionFactory.registerFloatEditor(String.class, new FloatStringQuickEditor());
ActionFactory.registerFloatEditor(Image.class, FloatImageQuickEditor.class); ActionFactory.registerFloatEditor(Formula.class, new FloatStringQuickEditor());
ActionFactory.registerFloatEditor(BufferedImage.class, FloatImageQuickEditor.class); ActionFactory.registerFloatEditor(Image.class, new FloatImageQuickEditor());
ActionFactory.registerFloatEditor(BufferedImage.class, new FloatImageQuickEditor());
ActionFactory.registerChartFloatEditorInEditor(FloatChartQuickEditor.class); ActionFactory.registerChartFloatEditorInEditor(new FloatChartQuickEditor());
} }
/** /**

97
designer/src/com/fr/quickeditor/CellQuickEditor.java

@ -18,13 +18,25 @@ import com.fr.design.menu.ShortCut;
import com.fr.design.selection.QuickEditor; import com.fr.design.selection.QuickEditor;
import com.fr.general.Inter; import com.fr.general.Inter;
import com.fr.grid.selection.CellSelection; import com.fr.grid.selection.CellSelection;
import com.fr.quickeditor.cellquick.CellElementBarLayout; import com.fr.quickeditor.cellquick.layout.CellElementBarLayout;
import com.fr.report.cell.TemplateCellElement; import com.fr.report.cell.TemplateCellElement;
import com.fr.stable.ColumnRow; import com.fr.stable.ColumnRow;
import javax.swing.*; import javax.swing.BorderFactory;
import java.awt.*; import javax.swing.JComponent;
import java.awt.event.*; import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollBar;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import java.util.ArrayList; import java.util.ArrayList;
/** /**
@ -35,19 +47,22 @@ import java.util.ArrayList;
public abstract class CellQuickEditor extends QuickEditor<ElementCasePane> { public abstract class CellQuickEditor extends QuickEditor<ElementCasePane> {
/*面板配置*/ /**
* 面板配置
*/
protected UITextField columnRowTextField; protected UITextField columnRowTextField;
protected TemplateCellElement cellElement; protected TemplateCellElement cellElement;
/*占位label*/ /**
protected static final Dimension LABEL_DIMENSION = new Dimension(60, 20); * 占位label
protected static final UILabel EMPTY_LABEL = new UILabel(); */
protected final Dimension LABEL_DIMENSION = new Dimension(60, 20);
protected final UILabel EMPTY_LABEL = new UILabel();
protected static final int VGAP = 10, HGAP = 8, VGAP_INNER = 3; protected static final int VGAP = 10, HGAP = 8, VGAP_INNER = 3;
static {
EMPTY_LABEL.setPreferredSize(LABEL_DIMENSION);
}
/*滚动条相关配置*/ /**
* 滚动条相关配置
*/
private static final int MAXVALUE = 100; private static final int MAXVALUE = 100;
private static final int CONTENT_PANE_WIDTH_GAP = 3; private static final int CONTENT_PANE_WIDTH_GAP = 3;
private static final int MOUSE_WHEEL_SPEED = 5; private static final int MOUSE_WHEEL_SPEED = 5;
@ -61,8 +76,10 @@ public abstract class CellQuickEditor extends QuickEditor<ElementCasePane> {
private int currentSelectedIndex; private int currentSelectedIndex;
private JPanel leftContentPane; private JPanel leftContentPane;
private UIScrollBar scrollBar; private UIScrollBar scrollBar;
private ActionListener comboBoxActionListener;
public CellQuickEditor() { public CellQuickEditor() {
EMPTY_LABEL.setPreferredSize(LABEL_DIMENSION);
double p = TableLayout.PREFERRED; double p = TableLayout.PREFERRED;
double f = TableLayout.FILL; double f = TableLayout.FILL;
double[] columnSize = {p, f}; double[] columnSize = {p, f};
@ -147,7 +164,39 @@ public abstract class CellQuickEditor extends QuickEditor<ElementCasePane> {
ColumnRow columnRow = ColumnRow.valueOf(cs.getColumn(), cs.getRow()); ColumnRow columnRow = ColumnRow.valueOf(cs.getColumn(), cs.getRow());
columnRowTextField.setText(columnRow.toString()); columnRowTextField.setText(columnRow.toString());
cellElement = tc.getEditingElementCase().getTemplateCellElement(cs.getColumn(), cs.getRow()); cellElement = tc.getEditingElementCase().getTemplateCellElement(cs.getColumn(), cs.getRow());
comboBox.removeActionListener(comboBoxActionListener);
comboBox.removeAllItems();
JTemplate jTemplate = HistoryTemplateListPane.getInstance().getCurrentEditingTemplate();
if (jTemplate != null) {
String[] items = getDefaultComboBoxItems();
for (String item : items) {
comboBox.addItem(item);
}
}
Object comboBoxSelected = getComboBoxSelected();
if (comboBoxSelected != null) {
comboBox.setSelectedItem(((ShortCut) comboBoxSelected).getMenuKeySet().getMenuKeySetName());
} else {
comboBox.setSelectedIndex(1);
}
currentSelectedIndex = comboBox.getSelectedIndex();
comboBoxActionListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
cellInsertActions = ActionFactory.createCellInsertAction(ElementCasePane.class, tc);
selectedIndex = comboBox.getSelectedIndex();
comboBox.setPopupVisible(false);
comboBox.repaint();
if (selectedIndex < cellInsertActions.length) {
cellInsertActions[selectedIndex].actionPerformed(e);
}
comboBox.setSelectedIndex(currentSelectedIndex);
}
};
comboBox.addActionListener(comboBoxActionListener);
refreshDetails(); refreshDetails();
} }
/** /**
@ -165,10 +214,10 @@ public abstract class CellQuickEditor extends QuickEditor<ElementCasePane> {
cellLabel.setPreferredSize(LABEL_DIMENSION); cellLabel.setPreferredSize(LABEL_DIMENSION);
UILabel insertContentLabel = new UILabel(Inter.getLocText("FR-Designer_Insert_Cell_Element")); UILabel insertContentLabel = new UILabel(Inter.getLocText("FR-Designer_Insert_Cell_Element"));
insertContentLabel.setPreferredSize(LABEL_DIMENSION); insertContentLabel.setPreferredSize(LABEL_DIMENSION);
UIComboBox cellElementEditComboBox = initCellElementEditComboBox(); initCellElementEditComboBox();
Component[][] components = new Component[][]{ Component[][] components = new Component[][]{
new Component[]{cellLabel, columnRowTextField = initColumnRowTextField()}, new Component[]{cellLabel, columnRowTextField = initColumnRowTextField()},
new Component[]{insertContentLabel, cellElementEditComboBox}, new Component[]{insertContentLabel, comboBox},
}; };
return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, HGAP, VGAP); return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, HGAP, VGAP);
} }
@ -214,13 +263,12 @@ public abstract class CellQuickEditor extends QuickEditor<ElementCasePane> {
/** /**
* 初始化添加按钮 * 初始化添加按钮
*
* @return UIButton
*/ */
private UIComboBox initCellElementEditComboBox() { private void initCellElementEditComboBox() {
JTemplate jTemplate = HistoryTemplateListPane.getInstance().getCurrentEditingTemplate(); JTemplate jTemplate = HistoryTemplateListPane.getInstance().getCurrentEditingTemplate();
if (jTemplate == null) { if (jTemplate == null) {
return comboBox = new UIComboBox(); comboBox = new UIComboBox();
return;
} }
final String[] items = getDefaultComboBoxItems(); final String[] items = getDefaultComboBoxItems();
comboBox = new UIComboBox(items); comboBox = new UIComboBox(items);
@ -231,18 +279,7 @@ public abstract class CellQuickEditor extends QuickEditor<ElementCasePane> {
comboBox.setSelectedIndex(1); comboBox.setSelectedIndex(1);
} }
currentSelectedIndex = comboBox.getSelectedIndex(); currentSelectedIndex = comboBox.getSelectedIndex();
comboBox.addActionListener(new ActionListener() { comboBox.addActionListener(comboBoxActionListener);
@Override
public void actionPerformed(ActionEvent e) {
cellInsertActions = ActionFactory.createCellInsertAction(ElementCasePane.class, tc);
selectedIndex = comboBox.getSelectedIndex();
comboBox.setPopupVisible(false);
comboBox.repaint();
cellInsertActions[selectedIndex].actionPerformed(e);
comboBox.setSelectedIndex(currentSelectedIndex);
}
});
return comboBox;
} }
private String[] getDefaultComboBoxItems() { private String[] getDefaultComboBoxItems() {

9
designer/src/com/fr/quickeditor/cellquick/CellBiasTextPainterEditor.java

@ -13,8 +13,10 @@ import com.fr.general.Inter;
import com.fr.quickeditor.CellQuickEditor; import com.fr.quickeditor.CellQuickEditor;
import com.fr.report.cell.painter.BiasTextPainter; import com.fr.report.cell.painter.BiasTextPainter;
import javax.swing.*; import javax.swing.JComponent;
import java.awt.*; import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
@ -22,6 +24,9 @@ import java.awt.event.ActionListener;
* 单元格元素斜线编辑器 * 单元格元素斜线编辑器
*/ */
public class CellBiasTextPainterEditor extends CellQuickEditor { public class CellBiasTextPainterEditor extends CellQuickEditor {
public CellBiasTextPainterEditor() {
super();
}
@Override @Override
public JComponent createCenterBody() { public JComponent createCenterBody() {

48
designer/src/com/fr/quickeditor/cellquick/CellDSColumnEditor.java

@ -1,7 +1,6 @@
package com.fr.quickeditor.cellquick; package com.fr.quickeditor.cellquick;
import com.fr.base.BaseFormula; import com.fr.base.BaseFormula;
import com.fr.design.actions.UpdateAction;
import com.fr.design.actions.columnrow.DSColumnConditionAction; import com.fr.design.actions.columnrow.DSColumnConditionAction;
import com.fr.design.actions.core.ActionFactory; import com.fr.design.actions.core.ActionFactory;
import com.fr.design.actions.insert.cell.DSColumnCellAction; import com.fr.design.actions.insert.cell.DSColumnCellAction;
@ -26,7 +25,7 @@ import com.fr.design.gui.itextfield.UITextField;
import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayout;
import com.fr.design.layout.TableLayoutHelper; import com.fr.design.layout.TableLayoutHelper;
import com.fr.design.mainframe.cell.CellEditorPane; import com.fr.design.mainframe.cell.AbstractDSCellEditorPane;
import com.fr.general.IOUtils; import com.fr.general.IOUtils;
import com.fr.general.Inter; import com.fr.general.Inter;
import com.fr.quickeditor.CellQuickEditor; import com.fr.quickeditor.CellQuickEditor;
@ -71,7 +70,6 @@ import static com.fr.report.cell.cellattr.core.group.FilterTypeEnum.UNDEFINE;
* @since 9.0 * @since 9.0
*/ */
public class CellDSColumnEditor extends CellQuickEditor { public class CellDSColumnEditor extends CellQuickEditor {
private static final double P = TableLayout.PREFERRED, F = TableLayout.FILL; private static final double P = TableLayout.PREFERRED, F = TableLayout.FILL;
private static final Color TIP_FONT_COLOR = new Color(0x7F333334, true); private static final Color TIP_FONT_COLOR = new Color(0x7F333334, true);
@ -82,7 +80,7 @@ public class CellDSColumnEditor extends CellQuickEditor {
/** /**
* 基本和高级设置 * 基本和高级设置
*/ */
private ArrayList<CellEditorPane> paneList; private ArrayList<AbstractDSCellEditorPane> paneList;
/** /**
* 基本和高级设置 卡片布局 * 基本和高级设置 卡片布局
*/ */
@ -106,7 +104,7 @@ public class CellDSColumnEditor extends CellQuickEditor {
*/ */
private DSColumnAdvancedEditorPane cellDSColumnAdvancedPane; private DSColumnAdvancedEditorPane cellDSColumnAdvancedPane;
private CellDSColumnEditor() { public CellDSColumnEditor() {
super(); super();
} }
@ -146,6 +144,7 @@ public class CellDSColumnEditor extends CellQuickEditor {
/** /**
* 关闭时候释放 * 关闭时候释放
*/ */
@Override
public void release() { public void release() {
super.release(); super.release();
dsColumnRegion = null; dsColumnRegion = null;
@ -161,7 +160,7 @@ public class CellDSColumnEditor extends CellQuickEditor {
card = new CardLayout(); card = new CardLayout();
cardContainer = new JPanel(card); cardContainer = new JPanel(card);
for (int i = 0; i < paneList.size(); i++) { for (int i = 0; i < paneList.size(); i++) {
CellEditorPane pane = paneList.get(i); AbstractDSCellEditorPane pane = paneList.get(i);
iconArray[i] = pane.getIconPath(); iconArray[i] = pane.getIconPath();
cardContainer.add(pane, pane.title4PopupWindow()); cardContainer.add(pane, pane.title4PopupWindow());
} }
@ -196,7 +195,7 @@ public class CellDSColumnEditor extends CellQuickEditor {
* @version 2017年7月25日 * @version 2017年7月25日
* @since 9.0 * @since 9.0
*/ */
class DSColumnBasicEditorPane extends CellEditorPane { class DSColumnBasicEditorPane extends AbstractDSCellEditorPane {
/** /**
* 数据集和数据列 * 数据集和数据列
@ -211,6 +210,16 @@ public class CellDSColumnEditor extends CellQuickEditor {
*/ */
private JPanel conditionPane; private JPanel conditionPane;
/**
* 条件过滤按钮触发动作
*/
private DSColumnConditionAction condition;
/**
* 条件过滤按钮
*/
private UIButton conditionUIButton;
/** /**
* 分组设置监听器 * 分组设置监听器
*/ */
@ -251,17 +260,16 @@ public class CellDSColumnEditor extends CellQuickEditor {
double[] rowSize = {P}, columnSize = {P, F}; double[] rowSize = {P}, columnSize = {P, F};
UILabel uiLabel = new UILabel(Inter.getLocText("FR-Designer_Filter_Conditions")); UILabel uiLabel = new UILabel(Inter.getLocText("FR-Designer_Filter_Conditions"));
uiLabel.setPreferredSize(LABEL_DIMENSION); uiLabel.setPreferredSize(LABEL_DIMENSION);
UIButton uiButton = new UIButton(); condition = new DSColumnConditionAction();
if (tc != null) { if (tc != null) {
//第一次初始化时tc为空,会引发NullPointerException condition.setEditingComponent(tc);
UpdateAction condition = new DSColumnConditionAction(tc);
//丢掉icon,修改按钮名称为编辑
condition.setSmallIcon(null);
condition.setName(Inter.getLocText("FR-Designer_Edit"));
uiButton = new UIButton(condition);
} }
//丢掉icon,修改按钮名称为编辑
condition.setSmallIcon(null);
condition.setName(Inter.getLocText("FR-Designer_Edit"));
conditionUIButton = new UIButton(condition);
Component[][] components = new Component[][]{ Component[][] components = new Component[][]{
new Component[]{uiLabel, uiButton} new Component[]{uiLabel, conditionUIButton}
}; };
conditionPane = TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, HGAP, VGAP); conditionPane = TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, HGAP, VGAP);
this.createScrollPane(); this.createScrollPane();
@ -291,6 +299,9 @@ public class CellDSColumnEditor extends CellQuickEditor {
public void populate() { public void populate() {
dataPane.populate(null, cellElement); dataPane.populate(null, cellElement);
groupPane.populate(cellElement); groupPane.populate(cellElement);
if (tc != null) {
condition.setEditingComponent(tc);
}
} }
@ -299,6 +310,7 @@ public class CellDSColumnEditor extends CellQuickEditor {
* *
* @return content JPanel * @return content JPanel
*/ */
@Override
protected JPanel createContentPane() { protected JPanel createContentPane() {
double[] columnSize = {F}; double[] columnSize = {F};
@ -316,7 +328,7 @@ public class CellDSColumnEditor extends CellQuickEditor {
} }
class DSColumnAdvancedEditorPane extends CellEditorPane { class DSColumnAdvancedEditorPane extends AbstractDSCellEditorPane {
/** /**
* 排列顺序 * 排列顺序
@ -464,6 +476,7 @@ public class CellDSColumnEditor extends CellQuickEditor {
* *
* @return 内容面板 * @return 内容面板
*/ */
@Override
protected JPanel createContentPane() { protected JPanel createContentPane() {
this.setLayout(FRGUIPaneFactory.createBorderLayout()); this.setLayout(FRGUIPaneFactory.createBorderLayout());
//结果集排序 //结果集排序
@ -539,6 +552,7 @@ public class CellDSColumnEditor extends CellQuickEditor {
multiPane.setBorder(BorderFactory.createEmptyBorder(0, 20, 0, 0)); multiPane.setBorder(BorderFactory.createEmptyBorder(0, 20, 0, 0));
multiNumPane.add(multiPane); multiNumPane.add(multiPane);
useMultiplyNumCheckBox.addActionListener(new ActionListener() { useMultiplyNumCheckBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
checkButtonEnabled(); checkButtonEnabled();
cellDSColumnAdvancedPane.updateMultipleConfig(); cellDSColumnAdvancedPane.updateMultipleConfig();
@ -712,6 +726,7 @@ public class CellDSColumnEditor extends CellQuickEditor {
private JFormulaField bottomFormulaPane; private JFormulaField bottomFormulaPane;
private ActionListener actionListener = new ActionListener() { private ActionListener actionListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) { public void actionPerformed(ActionEvent evt) {
int selectIndex = rsComboBox.getSelectedIndex(); int selectIndex = rsComboBox.getSelectedIndex();
CardLayout setCardPaneLayout = (CardLayout) setCardPane.getLayout(); CardLayout setCardPaneLayout = (CardLayout) setCardPane.getLayout();
@ -1015,6 +1030,7 @@ public class CellDSColumnEditor extends CellQuickEditor {
} }
private ActionListener formulaButtonActionListener = new ActionListener() { private ActionListener formulaButtonActionListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) { public void actionPerformed(ActionEvent evt) {
BaseFormula valueFormula = BaseFormula.createFormulaBuilder().build(); BaseFormula valueFormula = BaseFormula.createFormulaBuilder().build();
String text = formulaTextField.getText(); String text = formulaTextField.getText();

11
designer/src/com/fr/quickeditor/cellquick/CellFormulaQuickEditor.java

@ -9,6 +9,7 @@ import com.fr.design.dialog.DialogActionAdapter;
import com.fr.design.formula.FormulaFactory; import com.fr.design.formula.FormulaFactory;
import com.fr.design.formula.UIFormula; import com.fr.design.formula.UIFormula;
import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.itextfield.UITextField; import com.fr.design.gui.itextfield.UITextField;
import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayout;
import com.fr.design.layout.TableLayoutHelper; import com.fr.design.layout.TableLayoutHelper;
@ -22,10 +23,14 @@ import com.fr.report.cell.DefaultTemplateCellElement;
import com.fr.stable.ColumnRow; import com.fr.stable.ColumnRow;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import javax.swing.*; import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener; import javax.swing.event.DocumentListener;
import java.awt.*; import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter; import java.awt.event.KeyAdapter;
@ -69,7 +74,7 @@ public class CellFormulaQuickEditor extends CellQuickEditor {
}; };
private CellFormulaQuickEditor() { public CellFormulaQuickEditor() {
super(); super();
} }

10
designer/src/com/fr/quickeditor/cellquick/CellImageQuickEditor.java

@ -5,6 +5,7 @@ import com.fr.design.actions.core.ActionFactory;
import com.fr.design.actions.insert.cell.ImageCellAction; import com.fr.design.actions.insert.cell.ImageCellAction;
import com.fr.design.dialog.DialogActionAdapter; import com.fr.design.dialog.DialogActionAdapter;
import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayout;
import com.fr.design.layout.TableLayoutHelper; import com.fr.design.layout.TableLayoutHelper;
import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.DesignerContext;
@ -14,8 +15,11 @@ import com.fr.general.Inter;
import com.fr.quickeditor.CellQuickEditor; import com.fr.quickeditor.CellQuickEditor;
import com.fr.report.cell.cellattr.CellImage; import com.fr.report.cell.cellattr.CellImage;
import javax.swing.*; import javax.swing.JComponent;
import java.awt.*; import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
@ -27,7 +31,7 @@ import java.awt.event.ActionListener;
*/ */
public class CellImageQuickEditor extends CellQuickEditor { public class CellImageQuickEditor extends CellQuickEditor {
private CellImageQuickEditor() { public CellImageQuickEditor() {
super(); super();
} }

10
designer/src/com/fr/quickeditor/cellquick/CellRichTextEditor.java

@ -3,13 +3,17 @@ package com.fr.quickeditor.cellquick;
import com.fr.design.actions.core.ActionFactory; import com.fr.design.actions.core.ActionFactory;
import com.fr.design.actions.insert.cell.RichTextCellAction; import com.fr.design.actions.insert.cell.RichTextCellAction;
import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayout;
import com.fr.design.layout.TableLayoutHelper; import com.fr.design.layout.TableLayoutHelper;
import com.fr.general.Inter; import com.fr.general.Inter;
import com.fr.quickeditor.CellQuickEditor; import com.fr.quickeditor.CellQuickEditor;
import javax.swing.*; import javax.swing.JComponent;
import java.awt.*; import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
/** /**
* 单元格元素富文本编辑器 * 单元格元素富文本编辑器
@ -20,7 +24,7 @@ import java.awt.*;
public class CellRichTextEditor extends CellQuickEditor { public class CellRichTextEditor extends CellQuickEditor {
private UIButton richTextButton; private UIButton richTextButton;
private CellRichTextEditor() { public CellRichTextEditor() {
super(); super();
} }

9
designer/src/com/fr/quickeditor/cellquick/CellStringQuickEditor.java

@ -3,6 +3,7 @@ package com.fr.quickeditor.cellquick;
import com.fr.base.BaseFormula; import com.fr.base.BaseFormula;
import com.fr.base.Style; import com.fr.base.Style;
import com.fr.base.TextFormat; import com.fr.base.TextFormat;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.itextarea.UITextArea; import com.fr.design.gui.itextarea.UITextArea;
import com.fr.grid.GridKeyListener; import com.fr.grid.GridKeyListener;
import com.fr.grid.selection.CellSelection; import com.fr.grid.selection.CellSelection;
@ -12,10 +13,12 @@ import com.fr.report.cell.DefaultTemplateCellElement;
import com.fr.stable.ColumnRow; import com.fr.stable.ColumnRow;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import javax.swing.*; import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener; import javax.swing.event.DocumentListener;
import java.awt.*; import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.KeyAdapter; import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
@ -50,7 +53,7 @@ public class CellStringQuickEditor extends CellQuickEditor {
}; };
private CellStringQuickEditor() { public CellStringQuickEditor() {
super(); super();
} }

8
designer/src/com/fr/quickeditor/cellquick/CellSubReportEditor.java

@ -8,8 +8,10 @@ import com.fr.design.layout.TableLayoutHelper;
import com.fr.general.Inter; import com.fr.general.Inter;
import com.fr.quickeditor.CellQuickEditor; import com.fr.quickeditor.CellQuickEditor;
import javax.swing.*; import javax.swing.JComponent;
import java.awt.*; import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Component;
/** /**
* 单元格元素子报表编辑器 * 单元格元素子报表编辑器
@ -21,7 +23,7 @@ public class CellSubReportEditor extends CellQuickEditor {
private UIButton subReportButton; private UIButton subReportButton;
private CellSubReportEditor() { public CellSubReportEditor() {
super(); super();
} }

2
designer/src/com/fr/quickeditor/cellquick/CellElementBarLayout.java → designer/src/com/fr/quickeditor/cellquick/layout/CellElementBarLayout.java

@ -1,4 +1,4 @@
package com.fr.quickeditor.cellquick; package com.fr.quickeditor.cellquick.layout;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;

172
designer_base/src/com/fr/design/actions/core/ActionFactory.java

@ -7,68 +7,72 @@ import com.fr.design.file.HistoryTemplateListPane;
import com.fr.design.mainframe.JTemplate; import com.fr.design.mainframe.JTemplate;
import com.fr.design.menu.MenuKeySet; import com.fr.design.menu.MenuKeySet;
import com.fr.design.selection.QuickEditor; import com.fr.design.selection.QuickEditor;
import com.fr.general.FRLogger;
import javax.swing.*; import javax.swing.Action;
import javax.swing.KeyStroke;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException; import java.util.ArrayList;
import java.util.*; import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
/** /**
* 插入单元格元素和插入悬浮元素的一些集合方法 * 插入单元格元素和插入悬浮元素的一些集合方法
*
* @author null
* @version 2017年11月17日14点39分
*/ */
public class ActionFactory { public class ActionFactory {
private static LinkedHashSet<Class<?>> actionClasses = new LinkedHashSet<>(); private static LinkedHashSet<Class<?>> actionClasses = new LinkedHashSet<>();
private static LinkedHashSet<Class<?>> floatActionClasses = new LinkedHashSet<>(); private static LinkedHashSet<Class<?>> floatActionClasses = new LinkedHashSet<>();
/**
private ActionFactory() { * 悬浮元素编辑器
} */
private static ConcurrentMap<Class, QuickEditor> floatEditor = new ConcurrentHashMap<>();
private static Map<Class, Class<? extends QuickEditor>> floatEditor = new HashMap<>();
private static Class chartCollectionClass = null; private static Class chartCollectionClass = null;
/**
private static Map<Class, Class<? extends QuickEditor>> cellEditor = new HashMap<>(); * 单元格元素编辑器
*/
private static ConcurrentMap<Class, QuickEditor> cellEditor = new ConcurrentHashMap<>();
private static UpdateAction chartPreStyleAction = null; private static UpdateAction chartPreStyleAction = null;
private static UpdateAction chartMapEditorAction = null; private static UpdateAction chartMapEditorAction = null;
private ActionFactory() {
}
/** /**
* 待说明 * 注册单元格编辑器
* *
* @param clazz 待说明 * @param clazz 单元格属性类型
* @param editor 待说明 * @param editor 单元格编辑器实例
*/ */
public static void registerCellEditor(Class clazz, Class<? extends QuickEditor> editor) { public static void registerCellEditor(Class clazz, QuickEditor editor) {
cellEditor.put(clazz, editor); cellEditor.put(clazz, editor);
} }
/** /**
* 待说明 * 注册悬浮元素编辑器
* *
* @param clazz 待说明 * @param clazz 悬浮元素类型
* @param editor 待说明 * @param editor 悬浮元素编辑器实例
*/ */
public static void registerFloatEditor(Class clazz, Class<? extends QuickEditor> editor) { public static void registerFloatEditor(Class clazz, QuickEditor editor) {
floatEditor.put(clazz, editor); floatEditor.put(clazz, editor);
} }
/** /**
* 注册图表的 预定义样式. * kunsnat: 图表注册 悬浮元素编辑器 , 因为ChartCollecion和ChartQuickEditor一个在Chart,一个在Designer, 所以分开注册.
* *
* @param action 注册的图表预定义样式action * @param clazz 待说明
*/
public static void registerChartPreStyleAction(UpdateAction action) {
chartPreStyleAction = action;
}
/**
* 返回 图表预定义样式Action
*/ */
public static UpdateAction getChartPreStyleAction() { public static void registerChartCollection(Class clazz) {
return chartPreStyleAction; chartCollectionClass = clazz;
} }
/** /**
@ -80,21 +84,14 @@ public class ActionFactory {
chartMapEditorAction = action; chartMapEditorAction = action;
} }
public static UpdateAction getChartMapEditorAction() {
return chartMapEditorAction;
}
/** /**
* kunsnat: 图表注册 悬浮元素编辑器 , 因为ChartCollecion和ChartQuickEditor一个在Chart,一个在Designer, 所以分开注册. * 注册图表的 预定义样式.
* *
* @param clazz 待说明 * @param action 注册的图表预定义样式action
*/ */
public static void registerChartCollection(Class clazz) { public static void registerChartPreStyleAction(UpdateAction action) {
chartCollectionClass = clazz; chartPreStyleAction = action;
}
public static Class getChartCollectionClass() {
return chartCollectionClass;
} }
/** /**
@ -102,7 +99,7 @@ public class ActionFactory {
* *
* @param editor 待说明 * @param editor 待说明
*/ */
public static void registerChartFloatEditorInEditor(Class<? extends QuickEditor> editor) { public static void registerChartFloatEditorInEditor(QuickEditor editor) {
if (chartCollectionClass != null) { if (chartCollectionClass != null) {
floatEditor.put(chartCollectionClass, editor); floatEditor.put(chartCollectionClass, editor);
} }
@ -113,46 +110,58 @@ public class ActionFactory {
* *
* @param editor 待说明 * @param editor 待说明
*/ */
public static void registerChartCellEditorInEditor(Class<? extends QuickEditor> editor) { public static void registerChartCellEditorInEditor(QuickEditor editor) {
if (chartCollectionClass != null) { if (chartCollectionClass != null) {
cellEditor.put(chartCollectionClass, editor); cellEditor.put(chartCollectionClass, editor);
} }
} }
/** /**
* 返回 悬浮元素选中的Editor * 图表预定义样式Action
*
* @return 图表预定义样式Action
*/ */
public static QuickEditor getFloatEditor(Class clazz) { public static UpdateAction getChartPreStyleAction() {
return createEditor(clazz, floatEditor); return chartPreStyleAction;
} }
private static QuickEditor createEditor(Class clazz, Map<Class, Class<? extends QuickEditor>> editorMap) {
Class<? extends QuickEditor> c = findQuickEditorClass(clazz, editorMap); /**
if (c == null) { * 图表编辑器Action
return null; *
} * @return 图表编辑器Action
try { */
Constructor<? extends QuickEditor> constructor = c.getDeclaredConstructor(); public static UpdateAction getChartMapEditorAction() {
constructor.setAccessible(true); return chartMapEditorAction;
return constructor.newInstance();
} catch (Exception e) {
FRContext.getLogger().error(e.getMessage(), e);
}
return null;
} }
private static Class<? extends QuickEditor> findQuickEditorClass(Class clazz, Map<Class, Class<? extends QuickEditor>> editorMap) {
Class<? extends QuickEditor> c = editorMap.get(clazz); /**
if (c == null) { * 获取图表集合类
Class superClazz = clazz.getSuperclass(); *
if (superClazz == null) { * @return 获取图表集合类
return null; */
} public static Class getChartCollectionClass() {
return findQuickEditorClass(superClazz, editorMap); return chartCollectionClass;
}
return c;
} }
/**
* 选中的悬浮元素的编辑器
*
* @param clazz 选中的悬浮元素类型
* @return 编辑器实例
*/
public static QuickEditor getFloatEditor(Class clazz) {
return createEditor(clazz, floatEditor);
}
/**
* 选中的单元格元素编辑器
*
* @param clazz 选中的单元格元素类型
* @return 编辑器实例
*/
public static QuickEditor getCellEditor(Class clazz) { public static QuickEditor getCellEditor(Class clazz) {
return createEditor(clazz, cellEditor); return createEditor(clazz, cellEditor);
} }
@ -289,4 +298,25 @@ public class ActionFactory {
} }
return actions.toArray(new UpdateAction[actions.size()]); return actions.toArray(new UpdateAction[actions.size()]);
} }
private static QuickEditor createEditor(Class clazz, Map<Class, QuickEditor> editorMap) {
QuickEditor c = findQuickEditorClass(clazz, editorMap);
if (c == null) {
FRLogger.getLogger().error("No Such Editor");
return null;
}
return c;
}
private static QuickEditor findQuickEditorClass(Class clazz, Map<Class, QuickEditor> editorMap) {
QuickEditor c = editorMap.get(clazz);
if (c == null) {
Class superClazz = clazz.getSuperclass();
if (superClazz == null) {
return null;
}
return findQuickEditorClass(superClazz, editorMap);
}
return c;
}
} }
Loading…
Cancel
Save