From 4e1befc15133b15b0ce29ca357db84451a76629d Mon Sep 17 00:00:00 2001 From: "Henry.Wang" Date: Thu, 6 Jan 2022 18:08:15 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-62440=20=E8=A1=A8=E5=A4=B4=E6=8E=92?= =?UTF-8?q?=E5=BA=8F=E5=86=85=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../design/dscolumn/DSColumnAdvancedPane.java | 151 ++----- .../cell/AbstractDSCellEditorPane.java | 114 +----- .../cell/settingpane/CellExpandAttrPane.java | 20 +- .../CellDSColumnSortGroupPane.java | 40 ++ .../CellDSColumnSortItemPane.java | 40 ++ .../celldscolumn/CellDSColumnSortPane.java | 62 +++ .../cellexpand/CellExpandSortGroupPane.java | 19 + .../cellexpand/CellExpandSortItemPane.java | 37 ++ .../sort/cellexpand/CellExpandSortPane.java | 39 ++ .../sort/common/AbstractSortGroupPane.java | 152 ++++++++ .../sort/common/AbstractSortItemPane.java | 153 ++++++++ .../design/sort/common/AbstractSortPane.java | 112 ++++++ .../design/sort/common/SortColumnRowPane.java | 277 +++++++++++++ .../sort/common/SortUIExpandablePane.java | 119 ++++++ .../CellSortExpressionPane.java | 32 ++ .../CustomSequenceEditPane.java | 190 +++++++++ .../expressionpane/CustomSequencePane.java | 66 ++++ .../CustomSequenceSortExpressionPane.java | 37 ++ .../FormulaSortExpressionPane.java | 42 ++ .../expressionpane/SortExpressionPane.java | 23 ++ .../fr/design/sort/header/HeaderAreaPane.java | 267 +++++++++++++ .../design/sort/header/HeaderSettingPane.java | 81 ++++ .../sort/header/HeaderSortRulePane.java | 279 +++++++++++++ .../fr/design/sort/header/SortHeaderPane.java | 65 ++++ .../cellquick/CellDSColumnEditor.java | 367 +++--------------- 25 files changed, 2255 insertions(+), 529 deletions(-) create mode 100644 designer-realize/src/main/java/com/fr/design/sort/celldscolumn/CellDSColumnSortGroupPane.java create mode 100644 designer-realize/src/main/java/com/fr/design/sort/celldscolumn/CellDSColumnSortItemPane.java create mode 100644 designer-realize/src/main/java/com/fr/design/sort/celldscolumn/CellDSColumnSortPane.java create mode 100644 designer-realize/src/main/java/com/fr/design/sort/cellexpand/CellExpandSortGroupPane.java create mode 100644 designer-realize/src/main/java/com/fr/design/sort/cellexpand/CellExpandSortItemPane.java create mode 100644 designer-realize/src/main/java/com/fr/design/sort/cellexpand/CellExpandSortPane.java create mode 100644 designer-realize/src/main/java/com/fr/design/sort/common/AbstractSortGroupPane.java create mode 100644 designer-realize/src/main/java/com/fr/design/sort/common/AbstractSortItemPane.java create mode 100644 designer-realize/src/main/java/com/fr/design/sort/common/AbstractSortPane.java create mode 100644 designer-realize/src/main/java/com/fr/design/sort/common/SortColumnRowPane.java create mode 100644 designer-realize/src/main/java/com/fr/design/sort/common/SortUIExpandablePane.java create mode 100644 designer-realize/src/main/java/com/fr/design/sort/expressionpane/CellSortExpressionPane.java create mode 100644 designer-realize/src/main/java/com/fr/design/sort/expressionpane/CustomSequenceEditPane.java create mode 100644 designer-realize/src/main/java/com/fr/design/sort/expressionpane/CustomSequencePane.java create mode 100644 designer-realize/src/main/java/com/fr/design/sort/expressionpane/CustomSequenceSortExpressionPane.java create mode 100644 designer-realize/src/main/java/com/fr/design/sort/expressionpane/FormulaSortExpressionPane.java create mode 100644 designer-realize/src/main/java/com/fr/design/sort/expressionpane/SortExpressionPane.java create mode 100644 designer-realize/src/main/java/com/fr/design/sort/header/HeaderAreaPane.java create mode 100644 designer-realize/src/main/java/com/fr/design/sort/header/HeaderSettingPane.java create mode 100644 designer-realize/src/main/java/com/fr/design/sort/header/HeaderSortRulePane.java create mode 100644 designer-realize/src/main/java/com/fr/design/sort/header/SortHeaderPane.java diff --git a/designer-realize/src/main/java/com/fr/design/dscolumn/DSColumnAdvancedPane.java b/designer-realize/src/main/java/com/fr/design/dscolumn/DSColumnAdvancedPane.java index b943778bf..32818de9f 100644 --- a/designer-realize/src/main/java/com/fr/design/dscolumn/DSColumnAdvancedPane.java +++ b/designer-realize/src/main/java/com/fr/design/dscolumn/DSColumnAdvancedPane.java @@ -3,6 +3,7 @@ package com.fr.design.dscolumn; import com.fr.base.BaseFormula; import com.fr.data.util.SortOrder; import com.fr.design.border.UITitledBorder; +import com.fr.design.constants.LayoutConstants; import com.fr.design.data.DesignTableDataManager; import com.fr.design.dialog.BasicPane; import com.fr.design.dialog.DialogActionAdapter; @@ -10,10 +11,10 @@ import com.fr.design.formula.CustomVariableResolver; import com.fr.design.formula.FormulaFactory; import com.fr.design.formula.SortFormulaPane; import com.fr.design.formula.UIFormula; -import com.fr.design.gui.frpane.AbstractAttrNoScrollPane; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.icheckbox.UICheckBox; import com.fr.design.gui.icombobox.UIComboBox; +import com.fr.design.gui.icontainer.UIScrollPane; import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.ispinner.UISpinner; import com.fr.design.gui.itextfield.UITextField; @@ -21,6 +22,7 @@ import com.fr.design.gui.style.TextFormatPane; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayoutHelper; +import com.fr.design.sort.celldscolumn.CellDSColumnSortPane; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.report.cell.CellElement; import com.fr.report.cell.TemplateCellElement; @@ -28,19 +30,11 @@ import com.fr.report.cell.cellattr.CellExpandAttr; import com.fr.report.cell.cellattr.core.group.DSColumn; import com.fr.report.cell.cellattr.core.group.SelectCount; -import javax.swing.BorderFactory; -import javax.swing.Box; -import javax.swing.JComponent; -import javax.swing.JPanel; -import javax.swing.SwingUtilities; -import java.awt.BorderLayout; -import java.awt.CardLayout; -import java.awt.Component; -import java.awt.Dimension; -import java.awt.FlowLayout; -import java.awt.Font; +import javax.swing.*; +import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.util.Arrays; import static com.fr.report.cell.cellattr.core.group.FilterTypeEnum.BOTTOM; import static com.fr.report.cell.cellattr.core.group.FilterTypeEnum.SPECIFY; @@ -64,8 +58,19 @@ public class DSColumnAdvancedPane extends BasicPane { } public DSColumnAdvancedPane(int setting) { - this.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3)); - this.setLayout(FRGUIPaneFactory.createBorderLayout()); + initContentPane(setting); + initScrollPane(); + } + + private void initScrollPane() { + ScrollPane scrollPane = new ScrollPane(contentPane); + this.add(scrollPane); + } + + private void initContentPane(int setting) { + contentPane = new JPanel(); + contentPane.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3)); + contentPane.setLayout(FRGUIPaneFactory.createBorderLayout()); sortPane = new SortPane(); sortPane.setBorder(UITitledBorder.createBorderWithTitle(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Sort_Sort_Order"))); @@ -135,7 +140,7 @@ public class DSColumnAdvancedPane extends BasicPane { TableLayout.PREFERRED, TableLayout.PREFERRED, TableLayout.PREFERRED, TableLayout.PREFERRED}; double[] columnSize = {TableLayout.FILL}; - this.add(TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize), BorderLayout.CENTER); + contentPane.add(TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize), BorderLayout.CENTER); } @Override @@ -148,7 +153,7 @@ public class DSColumnAdvancedPane extends BasicPane { return; } - sortPane.populate(cellElement); + sortPane.populateBean(cellElement); valuePane.populate(cellElement); formatAttrPane.populate(cellElement); @@ -198,7 +203,7 @@ public class DSColumnAdvancedPane extends BasicPane { return; } - sortPane.update(cellElement); + sortPane.updateBean(cellElement); valuePane.update(cellElement); formatAttrPane.update(cellElement); @@ -234,66 +239,25 @@ public class DSColumnAdvancedPane extends BasicPane { } } - private static class SortPane extends SortFormulaPane { - private CellElement cellElement; + private static class ScrollPane extends UIScrollPane { + ScrollPane(Component component) { + super(component); + this.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); + } @Override - public void formulaAction() { - if (cellElement == null) { - return; - } - Object value = cellElement.getValue(); - if (value == null || !(value instanceof DSColumn)) { - return; - } - - String[] displayNames = DesignTableDataManager.getSelectedColumnNames( - DesignTableDataManager.getEditingTableDataSource(), ((DSColumn) value).getDSName()); - - showFormulaDialog(displayNames); + public Dimension getPreferredSize() { + return new Dimension(DSColumnPane.DEFAULT_DIMENSION.width - 20, DSColumnPane.DEFAULT_DIMENSION.height - 100); } + } - void populate(CellElement cellElement) { - if (cellElement == null) { - return; - } - this.cellElement = cellElement; - - Object value = cellElement.getValue(); - if (value == null || !(value instanceof DSColumn)) { - return; - } - DSColumn dSColumn = (DSColumn) value; - - int sort = dSColumn.getOrder(); - this.sortOrderComboBox.setSortOrder(new SortOrder(sort)); - - String sortFormula = dSColumn.getSortFormula(); - sortFormulaTextField.setText(sortFormula); + private static class SortPane extends CellDSColumnSortPane { + SortPane() { + this.setLayout(new FlowLayout(FlowLayout.LEFT)); } - public void update(CellElement cellElement) { - if (cellElement == null) { - return; - } - Object value = cellElement.getValue(); - if (value == null || !(value instanceof DSColumn)) { - return; - } - DSColumn dSColumn = (DSColumn) (cellElement.getValue()); - - dSColumn.setOrder(this.sortOrderComboBox.getSortOrder().getOrder()); - //lance:sort formula - - String sText = null; - if (!(sortFormulaTextField.getText() == null || sortFormulaTextField.getText().trim().equals("") || sortFormulaTextField.getText().trim().equals("$$$"))) { - sText = new String(sortFormulaTextField.getText()); - } - if (!(sText == null || sText.length() < 1)) { - dSColumn.setSortFormula(sText); - } else { - dSColumn.setSortFormula(null); - } + protected boolean needSortHeaderPane() { + return false; } } @@ -548,11 +512,11 @@ public class DSColumnAdvancedPane extends BasicPane { } } - public static class ReLayoutTextFormatPane extends TextFormatPane { + public static class FormatAttrPane extends TextFormatPane { protected void initLayout() { - JComponent[][] components = new JComponent[][] { {typeComboBox, textField, roundingBox} }; - double[] rowSize = new double[] { TableLayout.FILL }; + JComponent[][] components = new JComponent[][]{{typeComboBox, textField, roundingBox}}; + double[] rowSize = new double[]{TableLayout.FILL}; double[] columnSize = {TableLayout.PREFERRED, 200, TableLayout.PREFERRED}; JPanel settingPane = TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, 4, 0); @@ -578,45 +542,6 @@ public class DSColumnAdvancedPane extends BasicPane { } } - - public static class FormatAttrPane extends AbstractAttrNoScrollPane { - private TextFormatPane formatPane; - - @Override - protected JPanel createContentPane() { - this.formatPane = new ReLayoutTextFormatPane(); - return this.formatPane; - } - - @Override - public Dimension getPreferredSize() { - if (formatPane == null) { - return super.getPreferredSize(); - } - return formatPane.getPreferredSize(); - } - - protected void initContentPane() { - leftContentPane = createContentPane(); - if (leftContentPane != null) { - leftContentPane.setBorder(BorderFactory.createEmptyBorder()); - this.add(leftContentPane, BorderLayout.CENTER); - } - } - - public void populate(CellElement cellElement) { - if (cellElement != null && formatPane != null) { - formatPane.populateBean(cellElement.getStyle()); - } - } - - public void update(CellElement cellElement) { - if (cellElement != null && formatPane != null) { - cellElement.setStyle(formatPane.update(cellElement.getStyle())); - } - } - } - private void checkButtonEnabled() { if (useMultiplyNumCheckBox.isSelected()) { multiNumSpinner.setEnabled(true); diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/cell/AbstractDSCellEditorPane.java b/designer-realize/src/main/java/com/fr/design/mainframe/cell/AbstractDSCellEditorPane.java index 8a3b2ded4..dd7d3608c 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/cell/AbstractDSCellEditorPane.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/cell/AbstractDSCellEditorPane.java @@ -1,17 +1,7 @@ package com.fr.design.mainframe.cell; -import com.fr.design.gui.iscrollbar.UIScrollBar; -import com.fr.design.mainframe.CellElementPropertyPane; -import com.fr.quickeditor.cellquick.layout.CellElementBarLayout; - -import javax.swing.BorderFactory; -import javax.swing.JPanel; -import java.awt.Container; -import java.awt.Dimension; -import java.awt.event.AdjustmentEvent; -import java.awt.event.AdjustmentListener; -import java.awt.event.MouseWheelEvent; -import java.awt.event.MouseWheelListener; +import com.fr.design.gui.frpane.AttributeChangeListener; +import com.fr.design.mainframe.AbstractAttrPane; /** * 右侧单元格元素面板抽象类 @@ -20,26 +10,9 @@ import java.awt.event.MouseWheelListener; * @version 2017年7月25日 * @since 9.0 */ -public abstract class AbstractDSCellEditorPane extends JPanel { - - /** - * 滚动条相关配置 - */ - private static final int MAXVALUE = 100; - private static final int TITLE_HEIGHT = 95; - private static final int CONTENT_PANE_WIDTH_GAP = 3; - private static final int SCROLLBAR_WIDTH = 7; - private static final int MOUSE_WHEEL_SPEED = 5; - private int maxHeight = 280; - - private JPanel leftContentPane; - private UIScrollBar scrollBar; - - protected abstract JPanel createContentPane(); +public abstract class AbstractDSCellEditorPane extends AbstractAttrPane { - public abstract String getIconPath(); - - public abstract String title4PopupWindow(); + private static final int FIXED_HEIGHT = 40; /** * 从面板拿数据保存 @@ -51,78 +24,19 @@ public abstract class AbstractDSCellEditorPane extends JPanel { */ public abstract void populate(); - protected void createScrollPane() { - leftContentPane = this.createContentPane(); - this.prepareScrollBar(); - leftContentPane.setBorder(BorderFactory.createMatteBorder(10, 10, 0, 0, this.getBackground())); - - this.setLayout(new CellElementBarLayout(leftContentPane) { - @Override - public void layoutContainer(Container parent) { - maxHeight = CellElementPropertyPane.getInstance().getHeight() - TITLE_HEIGHT; - int beginY; - if ((MAXVALUE - scrollBar.getVisibleAmount()) == 0) { - beginY = 0; - } else { - int preferredHeight = leftContentPane.getPreferredSize().height; - int value = scrollBar.getValue(); - beginY = value * (preferredHeight - maxHeight) / (MAXVALUE - scrollBar.getVisibleAmount()); - } - int width = parent.getWidth(); - int height = parent.getHeight(); - if (leftContentPane.getPreferredSize().height > maxHeight) { - leftContentPane.setBounds(0, -beginY, width - SCROLLBAR_WIDTH - CONTENT_PANE_WIDTH_GAP, height + beginY); - scrollBar.setBounds(width - SCROLLBAR_WIDTH - CONTENT_PANE_WIDTH_GAP, 0, SCROLLBAR_WIDTH + CONTENT_PANE_WIDTH_GAP, height); - } else { - leftContentPane.setBounds(0, 0, width - SCROLLBAR_WIDTH - CONTENT_PANE_WIDTH_GAP, height); - } - } - }); - this.add(scrollBar); - this.add(leftContentPane); - } - - - private void prepareScrollBar() { - scrollBar = new UIScrollBar(UIScrollBar.VERTICAL) { - @Override - public int getVisibleAmount() { - int preferredHeight = leftContentPane.getPreferredSize().height; - int e = MAXVALUE * (maxHeight) / preferredHeight; - setVisibleAmount(e); - return e; - } - - @Override - public int getMaximum() { - return MAXVALUE; - } - }; - - scrollBar.addAdjustmentListener(new AdjustmentListener() { - - @Override - public void adjustmentValueChanged(AdjustmentEvent e) { - doLayout(); - } - }); - this.addMouseWheelListener(new MouseWheelListener() { - - @Override - public void mouseWheelMoved(MouseWheelEvent e) { - int value = scrollBar.getValue(); - value += MOUSE_WHEEL_SPEED * e.getWheelRotation(); - scrollBar.setValue(value); - doLayout(); - } - }); - scrollBar.setPreferredSize(new Dimension(SCROLLBAR_WIDTH + CONTENT_PANE_WIDTH_GAP, this.getHeight())); - scrollBar.setBlockIncrement(SCROLLBAR_WIDTH + CONTENT_PANE_WIDTH_GAP); - scrollBar.setBorder(BorderFactory.createMatteBorder(0, CONTENT_PANE_WIDTH_GAP, 0, 0, this.getBackground())); - } /** * 释放tc */ protected abstract void release(); + + protected abstract AttributeChangeListener getAttributeChangeListener(); + + public void addAttributeChangeListener() { + this.addAttributeChangeListener(getAttributeChangeListener()); + } + + protected int getMaxHeight() { + return Math.max(super.getMaxHeight() - FIXED_HEIGHT, 0); + } } diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/CellExpandAttrPane.java b/designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/CellExpandAttrPane.java index cd454660d..9549a3a7e 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/CellExpandAttrPane.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/CellExpandAttrPane.java @@ -4,7 +4,6 @@ import com.fr.design.constants.LayoutConstants; import com.fr.design.constants.UIConstants; import com.fr.design.expand.ExpandLeftFatherPane; import com.fr.design.expand.ExpandUpFatherPane; -import com.fr.design.expand.SortExpandAttrPane; import com.fr.design.foldablepane.UIExpandablePane; import com.fr.design.gui.ibutton.UIButtonGroup; import com.fr.design.gui.icheckbox.UICheckBox; @@ -13,6 +12,7 @@ import com.fr.design.i18n.Toolkit; import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayoutHelper; import com.fr.design.mainframe.theme.utils.DefaultThemedTemplateCellElementCase; +import com.fr.design.sort.cellexpand.CellExpandSortPane; import com.fr.general.ComparatorUtils; import com.fr.general.IOUtils; import com.fr.report.cell.TemplateCellElement; @@ -38,11 +38,11 @@ public class CellExpandAttrPane extends AbstractCellAttrPane { private ExpandUpFatherPane rightFatherPane; private UICheckBox horizontalExpandableCheckBox; private UICheckBox verticalExpandableCheckBox; - private SortExpandAttrPane sortAfterExpand; private JPanel layoutPane; private JPanel basicPane; private JPanel seniorPane; private CellExpandExtraAttrPane extraPane; + private CellExpandSortPane cellExpandSortPane; /** @@ -62,7 +62,6 @@ public class CellExpandAttrPane extends AbstractCellAttrPane { rightFatherPane = new ExpandUpFatherPane(); horizontalExpandableCheckBox = new UICheckBox(Toolkit.i18nText("Fine-Design_Report_ExpandD_Horizontal_Extendable")); verticalExpandableCheckBox = new UICheckBox(Toolkit.i18nText("Fine-Design_Report_ExpandD_Vertical_Extendable")); - sortAfterExpand = new SortExpandAttrPane(); initAllNames(); return layoutPane(); } @@ -81,8 +80,11 @@ public class CellExpandAttrPane extends AbstractCellAttrPane { seniorPane = new JPanel(); basicPane = new UIExpandablePane(Toolkit.i18nText("Fine-Design_Report_Basic"), 223, 24, basicPane()); seniorPane = new UIExpandablePane(Toolkit.i18nText("Fine-Design_Report_Advanced"), 223, 24, seniorPane()); + JPanel sortUIExpandablePane = new UIExpandablePane(Toolkit.i18nText("Fine-Design_Report_Expend_Sort"), + 223, 24, cellExpandSortPane = new CellExpandSortPane(this)); layoutPane.add(basicPane, BorderLayout.NORTH); layoutPane.add(seniorPane, BorderLayout.CENTER); + layoutPane.add(sortUIExpandablePane, BorderLayout.SOUTH); extraPane = CellExpandExtraAttrPane.getInstance(); @@ -119,16 +121,12 @@ public class CellExpandAttrPane extends AbstractCellAttrPane { private JPanel seniorPane() { double f = TableLayout.FILL; double p = TableLayout.PREFERRED; - UILabel expendSort = new UILabel(Toolkit.i18nText("Fine-Design_Report_Expend_Sort"), SwingConstants.LEFT); - JPanel expendSortPane = new JPanel(new BorderLayout()); - expendSortPane.add(expendSort, BorderLayout.NORTH); horizontalExpandableCheckBox.setBorder(UIConstants.CELL_ATTR_ZEROBORDER); verticalExpandableCheckBox.setBorder(UIConstants.CELL_ATTR_ZEROBORDER); Component[][] components = new Component[][]{ new Component[]{null, null}, new Component[]{horizontalExpandableCheckBox, null}, new Component[]{verticalExpandableCheckBox, null}, - new Component[]{expendSortPane, sortAfterExpand}, }; double[] rowSize = {p, p, p, p, p}; double[] columnSize = {p, f}; @@ -169,9 +167,8 @@ public class CellExpandAttrPane extends AbstractCellAttrPane { } } - sortAfterExpand.populate(cellExpandAttr); - extraPane.populate(cellElement); + cellExpandSortPane.populateBean(cellElement); } @@ -217,11 +214,8 @@ public class CellExpandAttrPane extends AbstractCellAttrPane { } } - if (ComparatorUtils.equals(getGlobalName(), Toolkit.i18nText("Fine-Design_Basic_ExpandD_Sort_After_Expand"))) { - sortAfterExpand.update(cellExpandAttr); - } - extraPane.update(cellElement); + cellExpandSortPane.updateBean(cellElement); } /** diff --git a/designer-realize/src/main/java/com/fr/design/sort/celldscolumn/CellDSColumnSortGroupPane.java b/designer-realize/src/main/java/com/fr/design/sort/celldscolumn/CellDSColumnSortGroupPane.java new file mode 100644 index 000000000..788f1a57c --- /dev/null +++ b/designer-realize/src/main/java/com/fr/design/sort/celldscolumn/CellDSColumnSortGroupPane.java @@ -0,0 +1,40 @@ +package com.fr.design.sort.celldscolumn; + +import com.fr.design.data.DesignTableDataManager; +import com.fr.design.data.tabledata.wrapper.TableDataWrapper; +import com.fr.design.file.HistoryTemplateListCache; +import com.fr.design.sort.common.AbstractSortGroupPane; +import com.fr.design.sort.common.AbstractSortItemPane; +import com.fr.report.cell.cellattr.core.group.DSColumn; +import com.fr.report.core.sort.sortexpression.SortExpression; + +public class CellDSColumnSortGroupPane extends AbstractSortGroupPane { + DSColumn dsColumn; + + public CellDSColumnSortGroupPane(int sortGroupPaneWidth, int sortGroupPaneRightWidth) { + super(sortGroupPaneWidth, sortGroupPaneRightWidth); + } + + public void populateDsColumn(DSColumn dsColumn) { + this.dsColumn = dsColumn; + } + + @Override + protected AbstractSortItemPane refreshSortItemPane(int sortItemPaneWidth, int sortItemPaneRightWidth, SortExpression sortExpression) { + CellDSColumnSortItemPane cellDSColumnSortItemPane = new CellDSColumnSortItemPane(sortItemPaneWidth, sortItemPaneRightWidth); + java.util.Map tableDataWrapperMap = + DesignTableDataManager.getAllEditingDataSet(HistoryTemplateListCache.getInstance().getCurrentEditingTemplate().getTarget()); + TableDataWrapper tableDataWrapper = tableDataWrapperMap.get(dsColumn.getDSName()); + if (tableDataWrapper != null) { + java.util.List columnNameList = tableDataWrapper.calculateColumnNameList(); + String[] columnNames = new String[columnNameList.size()]; + columnNameList.toArray(columnNames); + cellDSColumnSortItemPane.sortAreaUiComboBox.removeAllItems(); + for (String columnName : columnNames) { + cellDSColumnSortItemPane.sortAreaUiComboBox.addItem(columnName); + } + } + cellDSColumnSortItemPane.populateBean(sortExpression); + return cellDSColumnSortItemPane; + } +} diff --git a/designer-realize/src/main/java/com/fr/design/sort/celldscolumn/CellDSColumnSortItemPane.java b/designer-realize/src/main/java/com/fr/design/sort/celldscolumn/CellDSColumnSortItemPane.java new file mode 100644 index 000000000..0c202fe0e --- /dev/null +++ b/designer-realize/src/main/java/com/fr/design/sort/celldscolumn/CellDSColumnSortItemPane.java @@ -0,0 +1,40 @@ +package com.fr.design.sort.celldscolumn; + +import com.fr.design.gui.icombobox.UIComboBox; +import com.fr.design.sort.common.AbstractSortItemPane; +import com.fr.design.sort.common.AbstractSortPane; +import com.fr.report.core.sort.sortexpression.SortExpression; + +import javax.swing.*; +import java.awt.*; + + +public class CellDSColumnSortItemPane extends AbstractSortItemPane { + + UIComboBox sortAreaUiComboBox; + + public CellDSColumnSortItemPane(int sortItemPaneWidth, int sortItemPaneRightWidth) { + super(sortItemPaneWidth, sortItemPaneRightWidth); + } + + @Override + public void initMainSortAreaPane(JPanel sortAreaPane) { + sortAreaUiComboBox = new UIComboBox(new String[0]); + sortAreaUiComboBox.setPreferredSize(new Dimension(sortItemPaneRightWidth, AbstractSortPane.PANE_COMPONENT_HEIGHT)); + sortAreaPane.add(sortAreaUiComboBox); + } + + public void populateBean(SortExpression sortExpression) { + sortAreaUiComboBox.setSelectedItem(sortExpression.getSortArea()); + super.populateBean(sortExpression); + } + + public SortExpression updateBean() { + SortExpression sortExpression = super.updateBean(); + if (sortExpression != null && sortAreaUiComboBox.getSelectedItem() != null) { + sortExpression.setSortArea(sortAreaUiComboBox.getSelectedItem().toString()); + } + return sortExpression; + } + +} \ No newline at end of file diff --git a/designer-realize/src/main/java/com/fr/design/sort/celldscolumn/CellDSColumnSortPane.java b/designer-realize/src/main/java/com/fr/design/sort/celldscolumn/CellDSColumnSortPane.java new file mode 100644 index 000000000..b5175e7fa --- /dev/null +++ b/designer-realize/src/main/java/com/fr/design/sort/celldscolumn/CellDSColumnSortPane.java @@ -0,0 +1,62 @@ +package com.fr.design.sort.celldscolumn; + +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.sort.common.AbstractSortPane; +import com.fr.general.data.TableDataColumn; +import com.fr.report.cell.TemplateCellElement; +import com.fr.report.cell.cellattr.core.group.DSColumn; +import com.fr.report.core.sort.common.CellSortAttr; + +import javax.swing.*; + + +public class CellDSColumnSortPane extends AbstractSortPane { + + public CellDSColumnSortPane() { + super(220, 150); + //this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); + } + + @Override + protected void initSortGroupPane() { + sortGroupPane = new CellDSColumnSortGroupPane(sortPaneWidth, sortPaneRightWidth); + this.add(sortGroupPane); + } + + @Override + protected CellSortAttr getCellSortAttr(TemplateCellElement cellElement) { + if (cellElement.getValue() instanceof DSColumn) { + DSColumn dsColumn = ((DSColumn) cellElement.getValue()); + if (dsColumn.getCellSortAttr() == null) { + dsColumn.setCellSortAttr(new CellSortAttr()); + } + return dsColumn.getCellSortAttr(); + } + return null; + } + + protected void populateSortArea(TemplateCellElement cellElement) { + super.populateSortArea(cellElement); + if (cellElement.getValue() instanceof DSColumn) { + DSColumn dsColumn = ((DSColumn) cellElement.getValue()); + TableDataColumn tableDataColumn = dsColumn.getColumn(); + if (tableDataColumn instanceof TableDataColumn) { + selfSortArea = TableDataColumn.getColumnName(tableDataColumn); + } + } + } + + public void populateBean(TemplateCellElement cellElement) { + if (cellElement.getValue() instanceof DSColumn) { + DSColumn dsColumn = ((DSColumn) cellElement.getValue()); + if (sortGroupPane != null) { + ((CellDSColumnSortGroupPane) sortGroupPane).populateDsColumn(dsColumn); + } + } + super.populateBean(cellElement); + } + + protected boolean needSortHeaderPane() { + return false; + } +} \ No newline at end of file diff --git a/designer-realize/src/main/java/com/fr/design/sort/cellexpand/CellExpandSortGroupPane.java b/designer-realize/src/main/java/com/fr/design/sort/cellexpand/CellExpandSortGroupPane.java new file mode 100644 index 000000000..62cb37e91 --- /dev/null +++ b/designer-realize/src/main/java/com/fr/design/sort/cellexpand/CellExpandSortGroupPane.java @@ -0,0 +1,19 @@ +package com.fr.design.sort.cellexpand; + +import com.fr.design.sort.common.AbstractSortGroupPane; +import com.fr.design.sort.common.AbstractSortItemPane; +import com.fr.report.core.sort.sortexpression.SortExpression; + +public class CellExpandSortGroupPane extends AbstractSortGroupPane { + + public CellExpandSortGroupPane(int sortGroupPaneWidth, int sortGroupPaneRightWidth) { + super(sortGroupPaneWidth, sortGroupPaneRightWidth); + } + + @Override + protected AbstractSortItemPane refreshSortItemPane(int sortItemPaneWidth, int sortItemPaneRightWidth, SortExpression sortExpression) { + AbstractSortItemPane abstractSortItemPane = new CellExpandSortItemPane( sortItemPaneWidth, sortItemPaneRightWidth); + abstractSortItemPane.populateBean(sortExpression); + return abstractSortItemPane; + } +} diff --git a/designer-realize/src/main/java/com/fr/design/sort/cellexpand/CellExpandSortItemPane.java b/designer-realize/src/main/java/com/fr/design/sort/cellexpand/CellExpandSortItemPane.java new file mode 100644 index 000000000..4b14dc692 --- /dev/null +++ b/designer-realize/src/main/java/com/fr/design/sort/cellexpand/CellExpandSortItemPane.java @@ -0,0 +1,37 @@ +package com.fr.design.sort.cellexpand; + +import com.fr.design.sort.common.AbstractSortPane; +import com.fr.design.sort.common.SortColumnRowPane; +import com.fr.design.sort.common.AbstractSortItemPane; +import com.fr.report.core.sort.sortexpression.SortExpression; +import com.fr.stable.ColumnRow; + +import javax.swing.*; + +public class CellExpandSortItemPane extends AbstractSortItemPane { + SortColumnRowPane columnRowPane; + + public CellExpandSortItemPane(int sortItemPaneWidth, int sortItemPaneRightWidth) { + super(sortItemPaneWidth, sortItemPaneRightWidth); + } + + @Override + public void initMainSortAreaPane(JPanel sortAreaPane) { + columnRowPane = new SortColumnRowPane(sortItemPaneRightWidth + 4, AbstractSortPane.PANE_COMPONENT_HEIGHT); + sortAreaPane.add(columnRowPane); + } + + public void populateBean(SortExpression sortExpression) { + columnRowPane.populateBean(ColumnRow.valueOf(sortExpression.getSortArea())); + super.populateBean(sortExpression); + } + + public SortExpression updateBean() { + SortExpression sortExpression = super.updateBean(); + if (sortExpression != null) { + ColumnRow columnRow = columnRowPane.updateBean(); + sortExpression.setSortArea(columnRow == null ? null : columnRow.toString()); + } + return sortExpression; + } +} diff --git a/designer-realize/src/main/java/com/fr/design/sort/cellexpand/CellExpandSortPane.java b/designer-realize/src/main/java/com/fr/design/sort/cellexpand/CellExpandSortPane.java new file mode 100644 index 000000000..5bfc20eea --- /dev/null +++ b/designer-realize/src/main/java/com/fr/design/sort/cellexpand/CellExpandSortPane.java @@ -0,0 +1,39 @@ +package com.fr.design.sort.cellexpand; + + +import com.fr.design.mainframe.cell.settingpane.CellExpandAttrPane; +import com.fr.design.sort.common.AbstractSortPane; +import com.fr.report.cell.TemplateCellElement; +import com.fr.report.cell.cellattr.CellExpandAttr; +import com.fr.report.core.sort.common.CellSortAttr; + + +import javax.swing.*; + +public class CellExpandSortPane extends AbstractSortPane { + CellExpandAttrPane cellExpandAttrPane; + + public CellExpandSortPane(CellExpandAttrPane cellExpandAttrPane) { + super(227, 155); + this.cellExpandAttrPane = cellExpandAttrPane; + this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); + } + + @Override + protected void initSortGroupPane() { + sortGroupPane = new CellExpandSortGroupPane(sortPaneWidth, sortPaneRightWidth); + this.add(sortGroupPane); + } + + @Override + protected CellSortAttr getCellSortAttr(TemplateCellElement cellElement) { + CellExpandAttr cellExpandAttr = cellElement.getCellExpandAttr(); + if (cellExpandAttr != null) { + if (cellExpandAttr.getCellSortAttr() == null) { + cellExpandAttr.setCellSortAttr(new CellSortAttr()); + } + return cellExpandAttr.getCellSortAttr(); + } + return null; + } +} diff --git a/designer-realize/src/main/java/com/fr/design/sort/common/AbstractSortGroupPane.java b/designer-realize/src/main/java/com/fr/design/sort/common/AbstractSortGroupPane.java new file mode 100644 index 000000000..db6f574bd --- /dev/null +++ b/designer-realize/src/main/java/com/fr/design/sort/common/AbstractSortGroupPane.java @@ -0,0 +1,152 @@ +package com.fr.design.sort.common; + +import com.fr.base.svg.IconUtils; +import com.fr.design.event.ComponentChangeListener; +import com.fr.design.event.ComponentChangeObserver; +import com.fr.design.gui.ibutton.UIButton; +import com.fr.design.i18n.Toolkit; +import com.fr.report.core.sort.sortexpression.CellSortExpression; +import com.fr.report.core.sort.sortexpression.SortExpression; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.ArrayList; +import java.util.List; + + +public abstract class AbstractSortGroupPane extends JPanel implements ComponentChangeObserver { + + private static final int SECOND_SORT_LENGTH_REDUCTION = 13; + + protected int sortGroupPaneWidth; + protected int sortGroupPaneRightWidth; + List sortExpressions; + List sortUIExpandablePanes = new ArrayList<>(); + AddSortItemBar addSortItemBar; + JPanel sortItemListPane; + UIButton uiButton; + String selfSortArea; + + ComponentChangeListener componentChangeListener; + + public AbstractSortGroupPane(int sortGroupPaneWidth, int sortGroupPaneRightWidth) { + this.sortGroupPaneRightWidth = sortGroupPaneRightWidth; + this.sortGroupPaneWidth = sortGroupPaneWidth; + this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); + initComponents(); + } + + private void initComponents() { + addSortItemBar = new AddSortItemBar(this); + sortItemListPane = new JPanel(); + sortItemListPane.setLayout(new BoxLayout(sortItemListPane, BoxLayout.Y_AXIS)); + this.add(sortItemListPane); + this.add(addSortItemBar); + } + + public void populateBean(List sortExpressions, String selfSortArea) { + this.sortItemListPane.removeAll(); + this.selfSortArea = selfSortArea; + this.sortExpressions = sortExpressions; + this.sortUIExpandablePanes = new ArrayList<>(); + for (int i = 0; i < sortExpressions.size(); i++) { + addSortItem(sortExpressions.get(i)); + } + refresh(); + } + + protected abstract AbstractSortItemPane refreshSortItemPane(int sortItemPaneWidth, int sortItemPaneRightWidth, SortExpression sortExpression); + + public List updateBean() { + List sortExpressions = new ArrayList<>(); + for (SortUIExpandablePane sortUIExpandablePane : sortUIExpandablePanes) { + SortExpression sortExpression = null; + if (sortUIExpandablePane != null) { + AbstractSortItemPane abstractSortItemPane + = (AbstractSortItemPane) sortUIExpandablePane.getContentPane(); + if (abstractSortItemPane != null) { + sortExpression = abstractSortItemPane.updateBean(); + } + } + if (sortExpression != null) { + sortExpressions.add(sortExpression); + } + } + return sortExpressions; + } + + + public void removeSortItem(int no) { + if (no < sortExpressions.size()) { + sortItemListPane.remove(sortUIExpandablePanes.get(no)); + sortExpressions.remove(no); + sortUIExpandablePanes.remove(no); + refresh(); + } + } + + public void removeSortItem(SortUIExpandablePane sortUIExpandablePane) { + for (int i = 0; i < sortUIExpandablePanes.size(); i++) { + if (sortUIExpandablePanes.get(i) == sortUIExpandablePane) { + removeSortItem(i); + return; + } + } + + } + + public void registerChangeListener(ComponentChangeListener componentChangeListener) { + this.componentChangeListener = componentChangeListener; + } + + public void addSortItem(SortExpression sortExpression) { + int sortItemPaneWidth = sortGroupPaneWidth - SECOND_SORT_LENGTH_REDUCTION; + int sortItemPaneRightWidth = sortGroupPaneRightWidth - SECOND_SORT_LENGTH_REDUCTION; + + if (sortExpression == null) { + sortExpression = new CellSortExpression(selfSortArea); + sortExpressions.add(sortExpression); + } + + AbstractSortItemPane abstractSortItemPane = + refreshSortItemPane(sortItemPaneWidth, sortItemPaneRightWidth, sortExpression); + + SortUIExpandablePane sortUIExpandablePane = new SortUIExpandablePane(abstractSortItemPane, this); + sortItemListPane.add(sortUIExpandablePane); + sortUIExpandablePanes.add(sortUIExpandablePane); + if (componentChangeListener != null) { + componentChangeListener.initListener(sortUIExpandablePane); + } + refresh(); + } + + protected void refresh() { + validate(); + repaint(); + revalidate(); + } + + class AddSortItemBar extends JPanel { + AbstractSortGroupPane sortGroupPane; + + AddSortItemBar(AbstractSortGroupPane sortGroupPane) { + init(); + this.sortGroupPane = sortGroupPane; + this.setLayout(new FlowLayout(FlowLayout.CENTER, 0, 5)); + } + + void init() { + uiButton = new UIButton(Toolkit.i18nText("Fine-Design_Sort_Add_Second_Sort"), + IconUtils.readIcon("/com/fr/design/images/sort/add.png")); + uiButton.setPreferredSize(new Dimension(sortGroupPaneWidth - 4, AbstractSortPane.PANE_COMPONENT_HEIGHT)); + this.add(uiButton); + uiButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + sortGroupPane.addSortItem(null); + } + }); + } + } +} diff --git a/designer-realize/src/main/java/com/fr/design/sort/common/AbstractSortItemPane.java b/designer-realize/src/main/java/com/fr/design/sort/common/AbstractSortItemPane.java new file mode 100644 index 000000000..82d14bb7e --- /dev/null +++ b/designer-realize/src/main/java/com/fr/design/sort/common/AbstractSortItemPane.java @@ -0,0 +1,153 @@ +package com.fr.design.sort.common; + +import com.fr.design.gui.icombobox.UIComboBox; +import com.fr.design.gui.ilable.UILabel; + +import com.fr.design.i18n.Toolkit; +import com.fr.design.sort.expressionpane.CellSortExpressionPane; +import com.fr.design.sort.expressionpane.CustomSequenceSortExpressionPane; +import com.fr.design.sort.expressionpane.FormulaSortExpressionPane; +import com.fr.design.sort.expressionpane.SortExpressionPane; +import com.fr.report.core.sort.sortexpression.SortExpression; +import com.fr.report.core.sort.common.SortRule; +import com.fr.stable.StringUtils; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.util.ArrayList; +import java.util.List; + +public abstract class AbstractSortItemPane extends JPanel { + protected int sortItemPaneWidth; + protected int sortItemPaneRightWidth; + List sortExpressionPanes = new ArrayList<>(); + SortExpressionPane currentSortExpressionPane = null; + JPanel sortBasisPanel = null; + UIComboBox sortRuleUiComboBox; + UIComboBox sortBasisUiComboBox; + JPanel sortAreaPane; + JPanel sortRulePane; + + public AbstractSortItemPane(int sortItemPaneWidth, int sortItemPaneRightWidth) { + this.sortItemPaneWidth = sortItemPaneWidth; + this.sortItemPaneRightWidth = sortItemPaneRightWidth; + this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); + registerSortExpressionPanes(); + initComponents(); + } + + private void initComponents() { + initSortAreaPane(); + initSortBasisPanel(); + initSortRulePane(); + } + + private void registerSortExpressionPanes() { + sortExpressionPanes.add(new CellSortExpressionPane(sortItemPaneRightWidth)); + sortExpressionPanes.add(new FormulaSortExpressionPane(sortItemPaneRightWidth)); + sortExpressionPanes.add(new CustomSequenceSortExpressionPane(sortItemPaneWidth, sortItemPaneRightWidth)); + } + + void initSortAreaPane() { + sortAreaPane = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, AbstractSortPane.PANE_COMPONENT_V_GAP)); + sortAreaPane.add(new UILabel(Toolkit.i18nText("Fine-Design_Sort_Sort_Area"), SwingConstants.LEFT)); + sortAreaPane.add(AbstractSortPane.createIntervalUILabel()); + initMainSortAreaPane(sortAreaPane); + this.add(sortAreaPane); + } + + public abstract void initMainSortAreaPane(JPanel sortAreaPane); + + void initSortRulePane() { + sortRulePane = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, AbstractSortPane.PANE_COMPONENT_V_GAP)); + sortRuleUiComboBox = new UIComboBox(new String[]{SortRule.ASC.getDescription(), + SortRule.DES.getDescription(), SortRule.NO_SORT.getDescription()}); + sortRuleUiComboBox.setPreferredSize(new Dimension(sortItemPaneRightWidth, AbstractSortPane.PANE_COMPONENT_HEIGHT)); + sortRulePane.add(new UILabel(Toolkit.i18nText("Fine-Design_Sort_Sort_Rule"), SwingConstants.LEFT)); + sortRulePane.add(AbstractSortPane.createIntervalUILabel()); + sortRulePane.add(sortRuleUiComboBox); + this.add(sortRulePane); + } + + void initSortBasisPanel() { + sortBasisPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, AbstractSortPane.PANE_COMPONENT_V_GAP)); + sortBasisUiComboBox = new UIComboBox(getSortNames()); + sortBasisUiComboBox.setPreferredSize(new Dimension(sortItemPaneRightWidth, AbstractSortPane.PANE_COMPONENT_HEIGHT)); + sortBasisUiComboBox.addItemListener(new ItemListener() { + @Override + public void itemStateChanged(ItemEvent e) { + if (sortExpressionPanes.get(sortBasisUiComboBox.getSelectedIndex()) != currentSortExpressionPane) { + if (currentSortExpressionPane != null) { + currentSortExpressionPane.setVisible(false); + } + currentSortExpressionPane = sortExpressionPanes.get(sortBasisUiComboBox.getSelectedIndex()); + refreshCurrentSortExpressionPane(); + } + } + }); + sortBasisPanel.add(new UILabel(Toolkit.i18nText("Fine-Design_Sort_Sort_Basis"), SwingConstants.LEFT)); + sortBasisPanel.add(AbstractSortPane.createIntervalUILabel()); + sortBasisPanel.add(sortBasisUiComboBox); + this.add(sortBasisPanel); + for (SortExpressionPane sortExpressionPane : sortExpressionPanes) { + this.add(sortExpressionPane); + sortExpressionPane.setVisible(false); + } + } + + private void refreshCurrentSortExpressionPane() { + currentSortExpressionPane.setVisible(true); + sortAreaPane.setVisible(currentSortExpressionPane.needSortArea()); + sortRulePane.setVisible(currentSortExpressionPane.needSortRule()); + } + + private String[] getSortNames() { + String[] sortNames = new String[sortExpressionPanes.size()]; + for (int i = 0; i < sortExpressionPanes.size(); i++) { + sortNames[i] = sortExpressionPanes.get(i).getSortName(); + } + return sortNames; + } + + public void populateBean(SortExpression sortExpression) { + if (sortExpression.getSortRule() == SortRule.ASC) { + sortRuleUiComboBox.setSelectedIndex(0); + } else if (sortExpression.getSortRule() == SortRule.DES) { + sortRuleUiComboBox.setSelectedIndex(1); + } else if (sortExpression.getSortRule() == SortRule.NO_SORT) { + sortRuleUiComboBox.setSelectedIndex(2); + } + for (int i = 0; i < sortExpressionPanes.size(); i++) { + if (StringUtils.equals(sortExpression.getSortName(), sortExpressionPanes.get(i).getSortName())) { + if (currentSortExpressionPane != null) { + currentSortExpressionPane.setVisible(false); + } + currentSortExpressionPane = sortExpressionPanes.get(i); + currentSortExpressionPane.populateBean(sortExpression); + sortBasisUiComboBox.setSelectedIndex(i); + refreshCurrentSortExpressionPane(); + break; + } + } + refresh(); + } + + public SortExpression updateBean() { + SortExpression sortExpression = currentSortExpressionPane.updateBean(); + if (sortExpression != null) { + String sortRule = sortRuleUiComboBox.getSelectedItem().toString(); + if (StringUtils.isNotBlank(sortRule)) { + sortExpression.setSortRule(SortRule.parse(sortRule)); + } + } + return sortExpression; + } + + protected void refresh() { + validate(); + repaint(); + revalidate(); + } +} diff --git a/designer-realize/src/main/java/com/fr/design/sort/common/AbstractSortPane.java b/designer-realize/src/main/java/com/fr/design/sort/common/AbstractSortPane.java new file mode 100644 index 000000000..6491d04a8 --- /dev/null +++ b/designer-realize/src/main/java/com/fr/design/sort/common/AbstractSortPane.java @@ -0,0 +1,112 @@ +package com.fr.design.sort.common; + +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.sort.header.SortHeaderPane; +import com.fr.report.cell.TemplateCellElement; +import com.fr.report.core.sort.common.CellSortAttr; +import com.fr.report.core.sort.sortexpression.CellSortExpression; +import com.fr.report.core.sort.sortexpression.SortExpression; +import com.fr.report.core.sort.header.SortHeader; +import com.fr.stable.ColumnRow; + +import javax.swing.*; +import java.awt.*; +import java.util.ArrayList; +import java.util.List; + + +public abstract class AbstractSortPane extends JPanel { + protected int sortPaneWidth; + protected int sortPaneRightWidth; + public static final int PANE_COMPONENT_HEIGHT = 20; + public static final int PANE_COMPONENT_V_GAP = 4; + public static final int PANE_COMPONENT_H_GAP = 14; + protected AbstractSortGroupPane sortGroupPane; + protected SortHeaderPane sortHeaderPane; + protected String selfSortArea; + protected String defaultHeaderArea; + + public AbstractSortPane(int sortPaneWidth, int sortPaneRightWidth) { + this.sortPaneWidth = sortPaneWidth; + this.sortPaneRightWidth = sortPaneRightWidth; + initComponents(); + } + + private void initComponents() { + initSortGroupPane(); + if (needSortHeaderPane()) { + sortHeaderPane = new SortHeaderPane(sortPaneWidth, sortPaneRightWidth + 5); + this.add(sortHeaderPane); + } + } + + protected abstract void initSortGroupPane(); + + + protected boolean needSortHeaderPane() { + return true; + } + + protected abstract CellSortAttr getCellSortAttr(TemplateCellElement cellElement); + + public void populateBean(TemplateCellElement cellElement) { + populateSortArea(cellElement); + List sortExpressions = null; + CellSortAttr cellSortAttr = getCellSortAttr(cellElement); + if (cellSortAttr != null) { + sortExpressions = cellSortAttr.getSortExpressions(); + } + if (sortExpressions == null) { + sortExpressions = new ArrayList<>(); + } + sortGroupPane.populateBean(sortExpressions, selfSortArea); + if (needSortHeaderPane()) { + SortHeader sortHeader = null; + if (cellSortAttr != null) { + sortHeader = cellSortAttr.getSortHeader(); + } + sortHeaderPane.populateBean(sortHeader, defaultHeaderArea); + } + refresh(); + } + + protected void populateSortArea(TemplateCellElement cellElement) { + int row = cellElement.getRow(); + int column = cellElement.getColumn(); + selfSortArea = ColumnRow.valueOf(column, row).toString(); + if (row > 0) { + defaultHeaderArea = ColumnRow.valueOf(column, row - 1).toString(); + } else { + defaultHeaderArea = null; + } + } + + public void updateBean(TemplateCellElement cellElement) { + List sortExpressions = sortGroupPane.updateBean(); + CellSortAttr cellSortAttr = getCellSortAttr(cellElement); + cellSortAttr.setSortExpressions(sortExpressions); + if (needSortHeaderPane()) { + SortHeader sortHeader = sortHeaderPane.updateBean(cellElement); + if (sortHeader != null) { + sortHeader.setSortArea(selfSortArea); + } + cellSortAttr.setSortHeader(sortHeader); + } + } + + protected void refresh() { + validate(); + repaint(); + revalidate(); + } + + public static UILabel createIntervalUILabel() { + return createIntervalUILabel(PANE_COMPONENT_H_GAP); + } + + public static UILabel createIntervalUILabel(int vGap) { + UILabel uiLabel = new UILabel(); + uiLabel.setPreferredSize(new Dimension(vGap, 10)); + return uiLabel; + } +} diff --git a/designer-realize/src/main/java/com/fr/design/sort/common/SortColumnRowPane.java b/designer-realize/src/main/java/com/fr/design/sort/common/SortColumnRowPane.java new file mode 100644 index 000000000..67a9aaff1 --- /dev/null +++ b/designer-realize/src/main/java/com/fr/design/sort/common/SortColumnRowPane.java @@ -0,0 +1,277 @@ +package com.fr.design.sort.common; + +import com.fr.base.Style; +import com.fr.base.background.ColorBackground; +import com.fr.base.svg.IconUtils; +import com.fr.design.designer.TargetComponent; +import com.fr.design.event.UIObserver; +import com.fr.design.event.UIObserverListener; +import com.fr.design.file.HistoryTemplateListCache; +import com.fr.design.gui.ibutton.UIButton; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.design.selection.SelectionEvent; +import com.fr.design.selection.SelectionListener; +import com.fr.design.sort.header.HeaderAreaPane; +import com.fr.grid.selection.CellSelection; +import com.fr.grid.selection.Selection; +import com.fr.log.FineLoggerFactory; +import com.fr.report.cell.DefaultTemplateCellElement; +import com.fr.report.cell.TemplateCellElement; +import com.fr.report.cell.cellattr.CellExpandAttr; +import com.fr.report.cell.cellattr.core.group.DSColumn; +import com.fr.report.core.sort.common.CellSortable; +import com.fr.report.core.sort.header.SortHeader; +import com.fr.report.elementcase.TemplateElementCase; +import com.fr.stable.ColumnRow; +import com.fr.stable.EssentialUtils; +import com.fr.stable.StringUtils; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +public class SortColumnRowPane extends JPanel implements UIObserver { + int paneWidth; + int paneHeight; + int jTextFieldWidth; + JTextField colJTextField; + JTextField rowJTextField; + UIButton selectButton; + private boolean isAlreadyAddListener = false; + private CellSelection oldSelection; + private SelectionListener gridSelectionChangeListener; + UIObserverListener uiObserverListener; + private final static Icon DISABLED_ICON = IconUtils.readIcon("/com/fr/design/images/buttonicon/select_disabled.svg"); + private final static Icon ENABLE_ICON = IconUtils.readIcon("/com/fr/design/images/buttonicon/select_normal.svg"); + private boolean enabled; + + HeaderAreaPane.CellSelectionManager cellSelectionManager; + + public SortColumnRowPane(int paneWidth, int paneHeight) { + this.paneWidth = paneWidth; + this.paneHeight = paneHeight; + initComponents(); + } + + private void initComponents() { + initSize(); + this.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0)); + intUILabel(); + initTextField(); + initSelectButton(); + this.setSize(new Dimension(paneWidth, paneHeight)); + } + + void initSize() { + jTextFieldWidth = (paneWidth - 40) / 2; + } + + void intUILabel() { + UILabel uiLabel = new UILabel(IconUtils.readIcon("/com/fr/design/images/buttonicon/propertiestab/cellelement_normal.png")); + this.add(uiLabel); + } + + public static boolean isAvailableColumnRow(ColumnRow columnRow) { + return columnRow != null && columnRow.getRow() != -1 && columnRow.getColumn() != -1; + } + + void initTextField() { + colJTextField = new JTextField(); + colJTextField.setEditable(false); + rowJTextField = new JTextField(); + rowJTextField.setEditable(false); + colJTextField.setPreferredSize(new Dimension(jTextFieldWidth, paneHeight)); + rowJTextField.setPreferredSize(new Dimension(jTextFieldWidth, paneHeight)); + this.add(colJTextField); + this.add(rowJTextField); + } + + void initSelectButton() { + selectButton = new UIButton(ENABLE_ICON); + selectButton.addMouseListener(new SelectActionListener(this)); + this.add(selectButton); + } + + public void populateBean(ColumnRow columnRow, boolean enabled, HeaderAreaPane.CellSelectionManager cellSelectionManager) { + this.cellSelectionManager = cellSelectionManager; + populateBean(columnRow, enabled); + } + + public void populateBean(ColumnRow columnRow) { + populateBean(columnRow, true); + } + + public void populateBean(ColumnRow columnRow, boolean enabled) { + this.enabled = enabled; + if (SortColumnRowPane.isAvailableColumnRow(columnRow)) { + colJTextField.setText(EssentialUtils.convertIntToABC(columnRow.column + 1)); + rowJTextField.setText(String.valueOf(columnRow.row + 1)); + } else { + colJTextField.setText(StringUtils.EMPTY); + rowJTextField.setText(StringUtils.EMPTY); + } + if (enabled) { + selectButton.setIcon(ENABLE_ICON); + } else { + selectButton.setIcon(DISABLED_ICON); + } + selectButton.setEnabled(false); + refresh(); + } + + public void setColumnRow(ColumnRow columnRow) { + populateBean(columnRow); + uiObserverListener.doChange(); + } + + public ColumnRow updateBean() { + if (StringUtils.isNotBlank(colJTextField.getText()) && StringUtils.isNotBlank(rowJTextField.getText())) { + return ColumnRow.valueOf(colJTextField.getText() + rowJTextField.getText()); + } + return ColumnRow.ERROR; + } + + @Override + public void registerChangeListener(UIObserverListener listener) { + this.uiObserverListener = listener; + } + + @Override + public boolean shouldResponseChangeListener() { + return true; + } + + class SelectActionListener extends MouseAdapter { + SortColumnRowPane columnRowPane; + ColumnRow oldColumnRow; + + Map disableHeaderCellsStyleMap = new HashMap<>(); + java.util.List tempHeaderCells = new ArrayList<>(); + + SelectActionListener(SortColumnRowPane columnRowPane) { + this.columnRowPane = columnRowPane; + } + + @Override + public void mouseClicked(MouseEvent e) { + if (enabled) { + ElementCasePane elementCasePane = getCurrentElementCase(); + if (elementCasePane == null || isAlreadyAddListener) { + return; + } + oldColumnRow = columnRowPane.updateBean(); + prepareSelectHeader(elementCasePane); + gridSelectionChangeListener = new SelectionListener() { + @Override + public void selectionChanged(SelectionEvent e) { + completeSelectHeader(elementCasePane); + } + }; + elementCasePane.addSelectionChangeListener(gridSelectionChangeListener); + isAlreadyAddListener = true; + } + } + + private void prepareSelectHeader(ElementCasePane elementCasePane) { + ashDisableHeaderCellsStyle(elementCasePane.getEditingElementCase()); + oldSelection = (CellSelection) elementCasePane.getSelection(); + elementCasePane.getGrid().setNotShowingTableSelectPane(false); + elementCasePane.setRepeatSelection(true); + elementCasePane.setEditable(false); + elementCasePane.repaint(10); + } + + private void completeSelectHeader(ElementCasePane elementCasePane) { + Selection selection = elementCasePane.getSelection(); + if (selection instanceof CellSelection) { + CellSelection cellselection = (CellSelection) selection; + ColumnRow columnRow = ColumnRow.valueOf(cellselection.getColumn(), cellselection.getRow()); + elementCasePane.setOldSelecton(oldSelection); + oldSelection.getQuickEditor(elementCasePane); + if (cellSelectionManager == null || !cellSelectionManager.isNotSelectables(columnRow)) { + if (cellSelectionManager != null) { + cellSelectionManager.removeNotSelectables(oldColumnRow); + cellSelectionManager.addNotSelectables(columnRow); + } + columnRowPane.setColumnRow(columnRow); + } + restoreDisableHeaderCellsStyle(elementCasePane.getEditingElementCase()); + } + elementCasePane.removeSelectionChangeListener(gridSelectionChangeListener); + isAlreadyAddListener = false; + elementCasePane.getGrid().setNotShowingTableSelectPane(true); + elementCasePane.setRepeatSelection(false); + elementCasePane.setEditable(true); + elementCasePane.repaint(); + oldColumnRow = null; + } + + private void ashDisableHeaderCellsStyle(TemplateElementCase elementCase) { + if (cellSelectionManager != null) { + java.util.List notSelectables = cellSelectionManager.getNotSelectables(); + disableHeaderCellsStyleMap = new HashMap<>(); + tempHeaderCells = new ArrayList<>(); + for (ColumnRow columnRow : notSelectables) { + TemplateCellElement templateCellElement + = elementCase.getTemplateCellElement(columnRow.column, columnRow.row); + if (templateCellElement == null) { + templateCellElement = new DefaultTemplateCellElement(columnRow.column, columnRow.row); + elementCase.addCellElement(templateCellElement); + tempHeaderCells.add(templateCellElement); + } + Style style = templateCellElement.getStyle(); + disableHeaderCellsStyleMap.put(columnRow, style); + style = style.deriveBackground(ColorBackground.getInstance(Color.gray)); + templateCellElement.setStyle(style); + } + } + + } + + private void restoreDisableHeaderCellsStyle(TemplateElementCase elementCase) { + if (cellSelectionManager != null) { + try { + for (ColumnRow headerColumnRow : disableHeaderCellsStyleMap.keySet()) { + TemplateCellElement headerTemplateCellElement + = elementCase.getTemplateCellElement(headerColumnRow.column, headerColumnRow.row); + headerTemplateCellElement.setStyle(disableHeaderCellsStyleMap.get(headerColumnRow)); + } + for (TemplateCellElement templateCellElement : tempHeaderCells) { + elementCase.removeCellElement(templateCellElement); + } + disableHeaderCellsStyleMap = new HashMap<>(); + tempHeaderCells = new ArrayList<>(); + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e, e.getMessage()); + } + } + + } + } + + + protected void refresh() { + validate(); + repaint(); + revalidate(); + } + + public static ElementCasePane getCurrentElementCase() { + try { + TargetComponent targetComponent + = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate().getCurrentElementCasePane(); + if (targetComponent instanceof ElementCasePane) { + return (ElementCasePane) targetComponent; + } + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e, e.getMessage()); + } + return null; + } +} \ No newline at end of file diff --git a/designer-realize/src/main/java/com/fr/design/sort/common/SortUIExpandablePane.java b/designer-realize/src/main/java/com/fr/design/sort/common/SortUIExpandablePane.java new file mode 100644 index 000000000..6de6636f4 --- /dev/null +++ b/designer-realize/src/main/java/com/fr/design/sort/common/SortUIExpandablePane.java @@ -0,0 +1,119 @@ +package com.fr.design.sort.common; + +import com.fr.base.BaseUtils; +import com.fr.base.svg.IconUtils; +import com.fr.design.event.UIObserver; +import com.fr.design.event.UIObserverListener; +import com.fr.design.gui.ibutton.UIButton; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.i18n.Toolkit; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; + + +public class SortUIExpandablePane extends JPanel { + private static final long serialVersionUID = 1L; + private HeaderPane headerPane; + private AbstractSortItemPane contentPane; + private AbstractSortGroupPane sortGroupPane; + + private JPanel wrapPane; + private SortUIExpandablePane self = this; + + public JPanel getContentPane() { + return contentPane; + } + + + public SortUIExpandablePane(AbstractSortItemPane contentPane, AbstractSortGroupPane sortGroupPane) { + super(); + this.sortGroupPane = sortGroupPane; + this.contentPane = contentPane; + initComponents(); + wrapPane.setBorder(BorderFactory.createLineBorder(new Color(217, 218, 221), 1)); + wrapPane.setBackground(Color.WHITE); + this.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 5)); + } + + + private void initComponents() { + wrapPane = new JPanel(); + wrapPane.setLayout(new BorderLayout()); + headerPane = new HeaderPane(sortGroupPane); + headerPane.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + setContentPanelShow(!contentPane.isVisible()); + } + }); + headerPane.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, new Color(217, 218, 221))); + contentPane.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5)); + wrapPane.add(headerPane, BorderLayout.NORTH); + wrapPane.add(contentPane, BorderLayout.CENTER); + setContentPanelShow(true); + this.add(wrapPane); + } + + + private void setContentPanelShow(Boolean show) { + contentPane.setVisible(show); + headerPane.setShow(show); + } + + class HeaderPane extends JPanel implements UIObserver { + UILabel iconUiLabel; + UILabel closeButton; + AbstractSortGroupPane sortGroupPane; + UIObserverListener uiObserverListener; + + HeaderPane(AbstractSortGroupPane sortGroupPane) { + this.sortGroupPane = sortGroupPane; + this.setLayout(new FlowLayout(FlowLayout.LEFT, 3, 0)); + initComponents(); + } + + private void initComponents() { + iconUiLabel = new UILabel(); + this.add(iconUiLabel); + UILabel uiLabel = new UILabel(Toolkit.i18nText("Fine-Design_Sort_Second_Sort")); + this.add(uiLabel); + this.add(AbstractSortPane.createIntervalUILabel(108)); + + closeButton = new UILabel(IconUtils.readIcon("/com/fr/design/images/control/close.png")); + closeButton.setPreferredSize(new Dimension(16, 20)); + this.add(closeButton); + closeButton.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + sortGroupPane.removeSortItem(self); + if (uiObserverListener != null) { + uiObserverListener.doChange(); + } + } + }); + this.setPreferredSize(new Dimension(contentPane.sortItemPaneWidth + 7, AbstractSortPane.PANE_COMPONENT_HEIGHT)); + } + + public void setShow(boolean show) { + if (show) { + iconUiLabel.setIcon(IconUtils.readIcon("/com/fr/design/images/sort/down_arrow.png")); + } else { + iconUiLabel.setIcon(IconUtils.readIcon("/com/fr/design/images/sort/left_arrow.png")); + } + } + + @Override + public void registerChangeListener(UIObserverListener uiObserverListener) { + this.uiObserverListener = uiObserverListener; + } + + @Override + public boolean shouldResponseChangeListener() { + return true; + } + } + +} \ No newline at end of file diff --git a/designer-realize/src/main/java/com/fr/design/sort/expressionpane/CellSortExpressionPane.java b/designer-realize/src/main/java/com/fr/design/sort/expressionpane/CellSortExpressionPane.java new file mode 100644 index 000000000..1381b92cf --- /dev/null +++ b/designer-realize/src/main/java/com/fr/design/sort/expressionpane/CellSortExpressionPane.java @@ -0,0 +1,32 @@ +package com.fr.design.sort.expressionpane; + +import com.fr.design.i18n.Toolkit; +import com.fr.locale.InterProviderFactory; +import com.fr.report.core.sort.sortexpression.CellSortExpression; + + +import java.awt.*; + + +public class CellSortExpressionPane extends SortExpressionPane { + public CellSortExpressionPane(int with) { + this.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0)); + } + + @Override + public String getSortName() { + return InterProviderFactory.getProvider().getLocText("Fine-Engine_Sort_Cell"); + } + + @Override + public void populateBean(CellSortExpression cellSortExpression) { + + } + + @Override + public CellSortExpression updateBean() { + return new CellSortExpression(); + } + + +} diff --git a/designer-realize/src/main/java/com/fr/design/sort/expressionpane/CustomSequenceEditPane.java b/designer-realize/src/main/java/com/fr/design/sort/expressionpane/CustomSequenceEditPane.java new file mode 100644 index 000000000..c65657836 --- /dev/null +++ b/designer-realize/src/main/java/com/fr/design/sort/expressionpane/CustomSequenceEditPane.java @@ -0,0 +1,190 @@ +package com.fr.design.sort.expressionpane; + +import com.fr.design.dialog.BasicPane; +import com.fr.design.gui.icontainer.UIScrollPane; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.gui.ilist.UIList; +import com.fr.design.i18n.Toolkit; +import com.fr.design.mainframe.alphafine.listener.DocumentAdapter; +import com.fr.design.mainframe.dnd.SerializableTransferable; +import com.fr.design.mainframe.share.ui.base.PlaceholderTextArea; +import com.fr.locale.InterProviderFactory; +import com.fr.report.core.sort.sortexpression.CustomSequenceSortExpression; +import com.fr.stable.StringUtils; + +import javax.swing.*; +import javax.swing.event.DocumentEvent; +import java.awt.*; +import java.awt.datatransfer.DataFlavor; +import java.awt.datatransfer.Transferable; +import java.awt.dnd.DnDConstants; +import java.awt.dnd.DragGestureEvent; +import java.awt.dnd.DragGestureListener; +import java.awt.dnd.DragSource; +import java.awt.dnd.DragSourceAdapter; +import java.awt.dnd.DropTarget; +import java.awt.dnd.DropTargetAdapter; +import java.awt.dnd.DropTargetDropEvent; +import java.util.ArrayList; +import java.util.List; + +public class CustomSequenceEditPane extends BasicPane { + java.util.List customSequence; + JSplitPane jSplitPane; + JPanel referenceSequencePanel; + JPanel editSequencePanel; + JTextArea jTextArea; + + CustomSequenceEditPane(java.util.List customSequence) { + this.customSequence = customSequence; + initComponents(); + } + + void initComponents() { + this.setLayout(new BorderLayout()); + initReferenceSequencePanel(); + initEditSequencePanel(); + initSplitPane(); + } + + void initSplitPane() { + jSplitPane = new JSplitPane(); + this.add(jSplitPane); + jSplitPane.setOneTouchExpandable(true); + jSplitPane.setContinuousLayout(true); + jSplitPane.setOrientation(JSplitPane.HORIZONTAL_SPLIT); + jSplitPane.setLeftComponent(referenceSequencePanel); + jSplitPane.setRightComponent(editSequencePanel); + jSplitPane.setDividerSize(10); + jSplitPane.setDividerLocation(200); + } + + void initReferenceSequencePanel() { + referenceSequencePanel = new JPanel(); + referenceSequencePanel.setLayout(new BoxLayout(referenceSequencePanel, BoxLayout.Y_AXIS)); + JPanel titlePane = new JPanel(new FlowLayout(FlowLayout.LEFT)); + UILabel uiLabel = new UILabel(Toolkit.i18nText("Fine-Design_Sort_Reference_Sequence")); + titlePane.add(uiLabel); + referenceSequencePanel.add(titlePane); + UIScrollPane uiScrollPane = new UIScrollPane(getReferenceSequenceList()); + uiScrollPane.setPreferredSize(new Dimension(200, 300)); + referenceSequencePanel.add(uiScrollPane); + referenceSequencePanel.setSize(new Dimension(200, 400)); + } + + private UIList getReferenceSequenceList() { + UIList uiList = new UIList(getReferenceSequenceModel()); + new CustomSequenceEditDragSource(uiList, DnDConstants.ACTION_MOVE); + return uiList; + } + + private String[] getReferenceSequenceModel() { + List> customSequences = CustomSequenceSortExpression.getReferenceCustomSequences(); + String[] listModel = new String[customSequences.size()]; + for (int i = 0; i < customSequences.size(); i++) { + listModel[i] = CustomSequenceSortExpression.customSequenceToString(customSequences.get(i), ","); + } + return listModel; + } + + void initEditSequencePanel() { + editSequencePanel = new JPanel(); + editSequencePanel.setLayout(new BoxLayout(editSequencePanel, BoxLayout.Y_AXIS)); + JPanel titlePane = new JPanel(new FlowLayout(FlowLayout.LEFT)); + UILabel uiLabel = new UILabel(Toolkit.i18nText("Fine-Design_Sort_Input_Sequence")); + titlePane.add(uiLabel); + UILabel uiLabel2 = new UILabel(Toolkit.i18nText("Fine-Design_Sort_Please_Interlace_Sequence_Elements")); + uiLabel2.setForeground(Color.lightGray); + titlePane.add(uiLabel2); + editSequencePanel.add(titlePane); + jTextArea = getTextArea(); + UIScrollPane uiScrollPane = new UIScrollPane(jTextArea); + uiScrollPane.setPreferredSize(new Dimension(475, 300)); + editSequencePanel.add(uiScrollPane); + editSequencePanel.setSize(new Dimension(475, 300)); + } + + + JTextArea getTextArea() { + PlaceholderTextArea placeholderTextArea = new PlaceholderTextArea(10, 10, getPlaceholderText()); + new CustomSequenceEditDropTarget(placeholderTextArea, CustomSequenceSortExpression.getReferenceCustomSequences()); + placeholderTextArea.setText(CustomSequenceSortExpression.customSequenceToString(customSequence, "\n")); + placeholderTextArea.getDocument().addDocumentListener(new DocumentAdapter() { + @Override + protected void textChanged(DocumentEvent e) { + placeholderTextArea.repaint(); + } + }); + return placeholderTextArea; + } + + String getPlaceholderText() { + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append(Toolkit.i18nText("Fine-Design_Sort_Please_Interlace_Sequence_Elements_Such_As") + "\n"); + stringBuilder.append(Toolkit.i18nText("Fine-Design_Sort_Department_One") + "\n"); + stringBuilder.append(Toolkit.i18nText("Fine-Design_Sort_Department_Two") + "\n"); + stringBuilder.append(Toolkit.i18nText("Fine-Design_Sort_Department_Three") + "\n"); + return stringBuilder.toString(); + } + + @Override + protected String title4PopupWindow() { + return InterProviderFactory.getProvider().getLocText("Fine-Engine_Sort_Custom_Sequence"); + } + + + class CustomSequenceEditDragSource extends DragSourceAdapter implements DragGestureListener { + private DragSource source; + + public CustomSequenceEditDragSource(UIList uiList, int actions) { + source = new DragSource(); + source.createDefaultDragGestureRecognizer(uiList, actions, this); + } + + public void dragGestureRecognized(DragGestureEvent dge) { + Component comp = dge.getComponent(); + if (comp instanceof UIList) { + UIList uiList = (UIList) comp; + source.startDrag(dge, DragSource.DefaultLinkDrop, new SerializableTransferable(uiList.getSelectedIndex()), this); + } + } + } + + + class CustomSequenceEditDropTarget extends DropTargetAdapter { + java.util.List> customSequences = new ArrayList<>(); + + public CustomSequenceEditDropTarget(PlaceholderTextArea jPanel, java.util.List> customSequences) { + new DropTarget(jPanel, this); + this.customSequences = customSequences; + } + + @Override + public void drop(DropTargetDropEvent dtde) { + try { + Transferable transferable = dtde.getTransferable(); + DataFlavor[] dataFlavors = transferable.getTransferDataFlavors(); + if (dataFlavors.length == 1) { + Integer index = (Integer) transferable.getTransferData(dataFlavors[0]); + JTextArea jTextArea = (JTextArea) dtde.getDropTargetContext().getComponent(); + String text = jTextArea.getText(); + if (StringUtils.isNotEmpty(text) && !text.endsWith("\n")) { + text += "\n"; + } + java.util.List customSequence = customSequences.get(index); + for (int i = 0; i < customSequence.size(); i++) { + text += customSequence.get(i) + "\n"; + } + jTextArea.setText(text); + } + } catch (Exception e) { + + } + } + } + + public List updateBean() { + return CustomSequenceSortExpression.stringToCustomSequence(jTextArea.getText(), "\n"); + } + +} diff --git a/designer-realize/src/main/java/com/fr/design/sort/expressionpane/CustomSequencePane.java b/designer-realize/src/main/java/com/fr/design/sort/expressionpane/CustomSequencePane.java new file mode 100644 index 000000000..34fca093b --- /dev/null +++ b/designer-realize/src/main/java/com/fr/design/sort/expressionpane/CustomSequencePane.java @@ -0,0 +1,66 @@ +package com.fr.design.sort.expressionpane; + +import com.fr.base.svg.IconUtils; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.design.gui.ibutton.UIButton; +import com.fr.design.gui.itextfield.UITextField; +import com.fr.design.mainframe.DesignerContext; +import com.fr.design.sort.common.AbstractSortPane; +import com.fr.report.core.sort.sortexpression.CustomSequenceSortExpression; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.util.List; + + +public class CustomSequencePane extends JPanel { + protected UITextField textField; + protected UIButton button; + List customSequence; + + public CustomSequencePane(int width) { + this.setLayout(new FlowLayout(FlowLayout.RIGHT, 0, 0)); + this.initComponents(width); + } + + protected void initComponents(int width) { + textField = new UITextField(); + textField.setEditable(false); + textField.setPreferredSize(new Dimension(width - 20, AbstractSortPane.PANE_COMPONENT_HEIGHT)); + Icon icon = IconUtils.readIcon("/com/fr/design/images/sort/sequence.png"); + button = new UIButton(icon); + button.setBackground(Color.RED); + button.setOpaque(false); + button.setCursor(new Cursor(Cursor.HAND_CURSOR)); + button.setPreferredSize(new Dimension(20, AbstractSortPane.PANE_COMPONENT_HEIGHT)); + MouseAdapter mouseAdapter = new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + CustomSequenceEditPane customSequenceEditPane = new CustomSequenceEditPane(customSequence); + customSequenceEditPane.showWindowWithCustomSize(DesignerContext.getDesignerFrame(), new DialogActionAdapter() { + @Override + public void doOk() { + customSequence = customSequenceEditPane.updateBean(); + textField.setText(CustomSequenceSortExpression.customSequenceToString(customSequence, ",")); + } + }, new Dimension(700, 400)).setVisible(true); + } + }; + button.addMouseListener(mouseAdapter); + textField.addMouseListener(mouseAdapter); + this.add(textField); + this.add(button); + } + + + public List updateBean() { + return customSequence; + } + + public void populateBean(List customSequence) { + this.customSequence = customSequence; + textField.setText(CustomSequenceSortExpression.customSequenceToString(customSequence, ",")); + } +} \ No newline at end of file diff --git a/designer-realize/src/main/java/com/fr/design/sort/expressionpane/CustomSequenceSortExpressionPane.java b/designer-realize/src/main/java/com/fr/design/sort/expressionpane/CustomSequenceSortExpressionPane.java new file mode 100644 index 000000000..69dac2a2a --- /dev/null +++ b/designer-realize/src/main/java/com/fr/design/sort/expressionpane/CustomSequenceSortExpressionPane.java @@ -0,0 +1,37 @@ +package com.fr.design.sort.expressionpane; + +import com.fr.design.sort.common.AbstractSortPane; +import com.fr.locale.InterProviderFactory; +import com.fr.report.core.sort.sortexpression.CustomSequenceSortExpression; + +import javax.swing.*; +import java.awt.*; +import java.util.List; + + +public class CustomSequenceSortExpressionPane extends SortExpressionPane { + CustomSequencePane customSequencePane; + + public CustomSequenceSortExpressionPane(int width, int rightWidth) { + this.setLayout(new FlowLayout(FlowLayout.RIGHT, 2, 0)); + customSequencePane = new CustomSequencePane(rightWidth + 5); + this.add(customSequencePane); + } + + @Override + public String getSortName() { + return InterProviderFactory.getProvider().getLocText("Fine-Engine_Sort_Custom_Sequence"); + } + + @Override + public void populateBean(CustomSequenceSortExpression customSequenceSortExpression) { + List customSequence = customSequenceSortExpression.getCustomSequence(); + customSequencePane.populateBean(customSequence); + } + + @Override + public CustomSequenceSortExpression updateBean() { + List customSequence = customSequencePane.updateBean(); + return new CustomSequenceSortExpression(customSequence); + } +} diff --git a/designer-realize/src/main/java/com/fr/design/sort/expressionpane/FormulaSortExpressionPane.java b/designer-realize/src/main/java/com/fr/design/sort/expressionpane/FormulaSortExpressionPane.java new file mode 100644 index 000000000..3785a7e97 --- /dev/null +++ b/designer-realize/src/main/java/com/fr/design/sort/expressionpane/FormulaSortExpressionPane.java @@ -0,0 +1,42 @@ +package com.fr.design.sort.expressionpane; + +import com.fr.design.formula.TinyFormulaPane; +import com.fr.design.sort.common.AbstractSortPane; +import com.fr.locale.InterProviderFactory; +import com.fr.report.core.sort.sortexpression.FormulaSortExpression; + +import java.awt.*; + +public class FormulaSortExpressionPane extends SortExpressionPane { + + TinyFormulaPane tinyFormulaPane; + + public FormulaSortExpressionPane(int width) { + this.setLayout(new FlowLayout(FlowLayout.RIGHT, 2, 0)); + tinyFormulaPane = new TinyFormulaPane(); + tinyFormulaPane.setPreferredSize(new Dimension(width + 5, AbstractSortPane.PANE_COMPONENT_HEIGHT)); + this.add(tinyFormulaPane); + } + + @Override + public String getSortName() { + return InterProviderFactory.getProvider().getLocText("Fine-Engine_Sort_Formula"); + } + + @Override + public void populateBean(FormulaSortExpression formulaSortExpression) { + String formula = formulaSortExpression.getFormula(); + tinyFormulaPane.getUITextField().setText(formula); + } + + @Override + public FormulaSortExpression updateBean() { + String formula = tinyFormulaPane.getUITextField().getText(); + return new FormulaSortExpression(formula); + } + + public boolean needSortArea() { + return false; + } + +} diff --git a/designer-realize/src/main/java/com/fr/design/sort/expressionpane/SortExpressionPane.java b/designer-realize/src/main/java/com/fr/design/sort/expressionpane/SortExpressionPane.java new file mode 100644 index 000000000..69af8464c --- /dev/null +++ b/designer-realize/src/main/java/com/fr/design/sort/expressionpane/SortExpressionPane.java @@ -0,0 +1,23 @@ +package com.fr.design.sort.expressionpane; + +import com.fr.report.core.sort.sortexpression.SortExpression; + +import javax.swing.*; + + +public abstract class SortExpressionPane extends JPanel { + + public abstract String getSortName(); + + public abstract void populateBean(T sortExpression); + + public abstract T updateBean(); + + public boolean needSortArea() { + return true; + } + + public boolean needSortRule() { + return true; + } +} diff --git a/designer-realize/src/main/java/com/fr/design/sort/header/HeaderAreaPane.java b/designer-realize/src/main/java/com/fr/design/sort/header/HeaderAreaPane.java new file mode 100644 index 000000000..5ae972dbc --- /dev/null +++ b/designer-realize/src/main/java/com/fr/design/sort/header/HeaderAreaPane.java @@ -0,0 +1,267 @@ +package com.fr.design.sort.header; + +import com.fr.design.designer.TargetComponent; +import com.fr.design.file.HistoryTemplateListCache; +import com.fr.design.gui.icombobox.UIComboBox; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.i18n.Toolkit; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.design.sort.common.AbstractSortPane; +import com.fr.design.sort.common.SortColumnRowPane; +import com.fr.log.FineLoggerFactory; +import com.fr.report.cell.TemplateCellElement; +import com.fr.report.cell.cellattr.CellExpandAttr; +import com.fr.report.cell.cellattr.core.group.DSColumn; +import com.fr.report.core.sort.common.CellSortable; +import com.fr.report.core.sort.header.SortHeader; +import com.fr.report.elementcase.TemplateElementCase; +import com.fr.stable.ColumnRow; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + + +public class HeaderAreaPane extends JPanel { + protected int headerAreaPaneWidth; + protected int headerAreaPaneRightWidth; + private CellSelectionManager cellSelectionManager = new CellSelectionManager(); + + + AreaJLayeredPane areaJLayeredPane; + + HeaderAreaPane(int headerAreaPaneWidth, int headerAreaPaneRightWidth) { + this.headerAreaPaneWidth = headerAreaPaneWidth; + this.headerAreaPaneRightWidth = headerAreaPaneRightWidth; + this.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0)); + initComponents(); + } + + void initComponents() { + initUILabel(); + initLayeredPane(); + } + + void initUILabel() { + UILabel uiLabel = new UILabel(Toolkit.i18nText("Fine-Design_Sort_Header_Area"), SwingConstants.LEFT); + this.add(uiLabel); + this.add(AbstractSortPane.createIntervalUILabel()); + } + + void initLayeredPane() { + areaJLayeredPane = new AreaJLayeredPane(); + this.add(areaJLayeredPane); + } + + public void populateBean(ColumnRow columnRow, boolean showHeaderArea) { + boolean enabled = true; + ElementCasePane elementCasePane = getCurrentElementCase(); + if (elementCasePane != null) { + enabled = elementCasePane.isSelectedOneCell(); + } + areaJLayeredPane.populateBean(columnRow, showHeaderArea, enabled); + } + + public ColumnRow updateBean(TemplateCellElement cellElement) { + ElementCasePane elementCasePane = getCurrentElementCase(); + if (elementCasePane != null) { + if (!elementCasePane.isSelectedOneCell()) { + return getOldColumnRow(cellElement); + } + } + return areaJLayeredPane.updateBean(); + } + + private ColumnRow getOldColumnRow(TemplateCellElement cellElement) { + try { + SortHeader sortHeader + = cellElement.getCellExpandAttr().getCellSortAttr().getSortHeader(); + String headerArea = sortHeader.getHeaderArea(); + if (headerArea == null) { + return null; + } else { + return ColumnRow.valueOf(headerArea); + } + } catch (Exception ignore) { + return null; + } + } + + private ElementCasePane getCurrentElementCase() { + try { + TargetComponent targetComponent + = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate().getCurrentElementCasePane(); + if (targetComponent instanceof ElementCasePane) { + return (ElementCasePane) targetComponent; + } + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e, e.getMessage()); + } + return null; + } + + class AreaJLayeredPane extends JPanel { + SortColumnRowPane columnRowPane; + JLayeredPane jLayeredPane; + UIComboBox uiComboBox; + boolean populateBeaning; + + AreaJLayeredPane() { + this.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0)); + initComponents(); + } + + private void initComponents() { + initUIComboBox(); + initJLayeredPane(); + } + + + void initUIComboBox() { + uiComboBox = new UIComboBox(new String[]{Toolkit.i18nText("Fine-Design_Basic_None"), Toolkit.i18nText("Fine-Design_Basic_Custom")}); + uiComboBox.setSize(new Dimension(headerAreaPaneRightWidth, AbstractSortPane.PANE_COMPONENT_HEIGHT)); + uiComboBox.addItemListener(new ItemListener() { + @Override + public void itemStateChanged(ItemEvent e) { + if (e.getStateChange() != uiComboBox.getSelectedIndex()) { + setSortColumnRowPaneShow(uiComboBox.getSelectedIndex() == 1); + } + + } + + + }); + uiComboBox.setEnabled(false); + } + + void setSortColumnRowPaneShow(boolean show) { + if (show) { + jLayeredPane.setLayer(columnRowPane, JLayeredPane.POPUP_LAYER); + jLayeredPane.setLayer(uiComboBox, JLayeredPane.MODAL_LAYER); + if (!populateBeaning) { + ColumnRow columnRow = columnRowPane.updateBean(); + if (cellSelectionManager.isNotSelectables(columnRow)) { + columnRowPane.setColumnRow(ColumnRow.ERROR); + } else { + cellSelectionManager.addNotSelectables(columnRow); + } + } + } else { + jLayeredPane.setLayer(uiComboBox, JLayeredPane.POPUP_LAYER); + jLayeredPane.setLayer(columnRowPane, JLayeredPane.MODAL_LAYER); + if (!populateBeaning) { + cellSelectionManager.removeNotSelectables(columnRowPane.updateBean()); + } + } + refresh(); + } + + void initJLayeredPane() { + jLayeredPane = new JLayeredPane(); + columnRowPane = new SortColumnRowPane(headerAreaPaneRightWidth - 18, AbstractSortPane.PANE_COMPONENT_HEIGHT); + jLayeredPane.setPreferredSize(new Dimension(headerAreaPaneRightWidth, AbstractSortPane.PANE_COMPONENT_HEIGHT)); + jLayeredPane.add(columnRowPane, JLayeredPane.MODAL_LAYER); + jLayeredPane.add(uiComboBox, JLayeredPane.POPUP_LAYER); + this.add(jLayeredPane); + } + + public void populateBean(ColumnRow columnRow, boolean showHeaderArea, boolean enabled) { + populateBeaning = true; + cellSelectionManager.build(); + columnRowPane.populateBean(columnRow, enabled, cellSelectionManager); + if (showHeaderArea) { + uiComboBox.setSelectedIndex(1); + } else { + uiComboBox.setSelectedIndex(0); + } + uiComboBox.setEnabled(enabled); + populateBeaning = false; + } + + public ColumnRow updateBean() { + if (uiComboBox.getSelectedIndex() == 0) { + return null; + } else { + return columnRowPane.updateBean(); + } + } + + public void refresh() { + validate(); + repaint(); + revalidate(); + } + + } + + public static class CellSelectionManager { + ElementCasePane elementCase; + java.util.List notSelectables = new ArrayList<>(); + + void build() { + ElementCasePane elementCase = SortColumnRowPane.getCurrentElementCase(); + if (elementCase != null && this.elementCase != elementCase) { + this.elementCase = elementCase; + notSelectables = new ArrayList<>(); + buildNotSelectables(elementCase.getEditingElementCase()); + } + } + + public java.util.List getNotSelectables() { + return this.notSelectables; + } + + + public boolean isNotSelectables(ColumnRow columnRow) { + return notSelectables != null && notSelectables.contains(columnRow); + } + + public void addNotSelectables(ColumnRow columnRow) { + if (columnRow != null) { + removeNotSelectables(columnRow); + notSelectables.add(columnRow); + } + } + + public void removeNotSelectables(ColumnRow columnRow) { + notSelectables.remove(columnRow); + } + + private void buildNotSelectables(TemplateElementCase elementCase) { + Iterator iterator = elementCase.cellIterator(); + while (iterator.hasNext()) { + TemplateCellElement templateCellElement = (TemplateCellElement) iterator.next(); + CellExpandAttr cellExpandAttr = templateCellElement.getCellExpandAttr(); + if (cellExpandAttr != null) { + handleDisableHeaderCell(cellExpandAttr); + } + Object value = templateCellElement.getValue(); + if (value instanceof DSColumn) { + handleDisableHeaderCell((DSColumn) value); + } + } + } + + private void handleDisableHeaderCell(CellSortable cellSortable) { + if (cellSortable.getCellSortAttr() != null) { + SortHeader sortHeader = cellSortable.getCellSortAttr().getSortHeader(); + if (sortHeader != null) { + String headerArea = sortHeader.getHeaderArea(); + if (headerArea != null) { + ColumnRow headerColumnRow = ColumnRow.valueOf(headerArea); + addNotSelectables(headerColumnRow); + } + } + } + } + } +} \ No newline at end of file diff --git a/designer-realize/src/main/java/com/fr/design/sort/header/HeaderSettingPane.java b/designer-realize/src/main/java/com/fr/design/sort/header/HeaderSettingPane.java new file mode 100644 index 000000000..f31c40929 --- /dev/null +++ b/designer-realize/src/main/java/com/fr/design/sort/header/HeaderSettingPane.java @@ -0,0 +1,81 @@ +package com.fr.design.sort.header; + +import com.fr.design.gui.icheckbox.UICheckBox; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.i18n.Toolkit; +import com.fr.design.sort.common.AbstractSortPane; +import com.fr.report.core.sort.header.SortHeader; + +import javax.swing.*; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import java.awt.*; + +public class HeaderSettingPane extends JPanel { + protected int headerSettingPaneWidth; + protected int headerSettingPaneRightWidth; + HeaderSortRulePane headerSortRulePane; + UICheckBox uiCheckBox; + + HeaderSettingPane(int headerSettingPaneWidth, int headerSettingPaneRightWidth) { + this.headerSettingPaneWidth = headerSettingPaneWidth; + this.headerSettingPaneRightWidth = headerSettingPaneRightWidth; + this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); + initComponents(); + } + + void initComponents() { + initUILabel(); + initHeaderSortRulePane(); + } + + void initUILabel() { + JPanel jPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 2)); + UILabel uiLabel = new UILabel(Toolkit.i18nText("Fine-Design_Sort_Header_Setting")); + UILabel emptyUILabel = new UILabel(); + emptyUILabel.setPreferredSize(new Dimension(10, 10)); + + uiCheckBox = new UICheckBox(Toolkit.i18nText("Fine-Design_Sort_Allow_User_Click_Sort_Order")); + uiCheckBox.setPreferredSize(new Dimension(headerSettingPaneRightWidth - 10, AbstractSortPane.PANE_COMPONENT_HEIGHT)); + uiCheckBox.addChangeListener(new ChangeListener() { + @Override + public void stateChanged(ChangeEvent e) { + headerSortRulePane.setVisible(uiCheckBox.isSelected()); + } + }); + jPanel.add(uiLabel); + jPanel.add(emptyUILabel); + jPanel.add(uiCheckBox); + this.add(jPanel); + } + + void initHeaderSortRulePane() { + headerSortRulePane = new HeaderSortRulePane(); + this.add(headerSortRulePane); + headerSortRulePane.setVisible(false); + } + + protected void refresh() { + validate(); + repaint(); + revalidate(); + } + + public void populateBean(SortHeader.SortItem[] sortItems) { + if (sortItems == null) { + uiCheckBox.setSelected(false); + } else { + uiCheckBox.setSelected(true); + } + headerSortRulePane.populateBean(sortItems); + } + + public SortHeader.SortItem[] updateBean() { + if (uiCheckBox.isSelected()) { + return headerSortRulePane.updateBean(); + } else { + return null; + } + } + +} diff --git a/designer-realize/src/main/java/com/fr/design/sort/header/HeaderSortRulePane.java b/designer-realize/src/main/java/com/fr/design/sort/header/HeaderSortRulePane.java new file mode 100644 index 000000000..79f939639 --- /dev/null +++ b/designer-realize/src/main/java/com/fr/design/sort/header/HeaderSortRulePane.java @@ -0,0 +1,279 @@ +package com.fr.design.sort.header; + +import com.fr.base.svg.SVGIcon; +import com.fr.base.svg.SVGTranscoder; +import com.fr.design.event.UIObserver; +import com.fr.design.event.UIObserverListener; +import com.fr.design.gui.icheckbox.UICheckBox; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.i18n.Toolkit; +import com.fr.design.layout.TableLayoutHelper; +import com.fr.design.mainframe.theme.edit.ui.ColorListPane; +import com.fr.general.IOUtils; +import com.fr.log.FineLoggerFactory; +import com.fr.report.core.sort.header.SortHeader; +import com.fr.report.core.sort.common.SortRule; +import org.apache.batik.transcoder.TranscoderInput; + +import javax.swing.*; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import java.awt.*; +import java.awt.image.BufferedImage; +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +public class HeaderSortRulePane extends JPanel { + private static final String ASC_ICON_TEMPLATE_PATH = "/com/fr/design/images/sort/asc.svg"; + private static final String DES_ICON_TEMPLATE_PATH = "/com/fr/design/images/sort/des.svg"; + private static final String NOSORT_ICON_TEMPLATE_PATH = "/com/fr/design/images/sort/nosort.svg"; + private static final double ICON_SCALE = SVGIcon.SYSTEM_SCALE * 1.25; + private static final int ICON_LENGTH = (int) Math.ceil(16 * ICON_SCALE); + IconButton ascIconButton; + IconButton desIconButton; + IconButton nosortIconButton; + UICheckBox ascUICheckBox; + UICheckBox desUICheckBox; + UICheckBox nosortUICheckBox; + static Map originalSvgTextMap = new HashMap<>(); + + HeaderSortRulePane() { + initComponents(); + initState(true); + this.setBorder(BorderFactory.createEmptyBorder(0, 15, 0, 15)); + } + + void initComponents() { + this.setLayout(new BorderLayout()); + initUILabel(); + initSortRuleItem(); + this.setPreferredSize(new Dimension(160, 160)); + } + + void initUILabel() { + UILabel uiLabel = new UILabel(Toolkit.i18nText("Fine-Design_Sort_Header_Sort_Basis"), SwingConstants.LEFT); + this.add(uiLabel, BorderLayout.NORTH); + } + + void initSortRuleItem() { + Component[][] components = new Component[][]{ + new Component[]{ascUICheckBox = new UICheckBox(SortRule.ASC.getDescription()), ascIconButton = new IconButton(ASC_ICON_TEMPLATE_PATH)}, + new Component[]{desUICheckBox = new UICheckBox(SortRule.DES.getDescription()), desIconButton = new IconButton(DES_ICON_TEMPLATE_PATH)}, + new Component[]{nosortUICheckBox = new UICheckBox(SortRule.NO_SORT.getDescription()), nosortIconButton = new IconButton(NOSORT_ICON_TEMPLATE_PATH)}, + }; + double[] rowSize = {ICON_LENGTH + 10, ICON_LENGTH + 10, ICON_LENGTH + 10}; + double[] columnSize = {80, ICON_LENGTH + 10}; + JPanel sortRuleItem = TableLayoutHelper.createCommonTableLayoutPane(components, rowSize, columnSize, 0); + this.add(sortRuleItem, BorderLayout.CENTER); + initUICheckBoxChange(ascUICheckBox, ascIconButton); + initUICheckBoxChange(desUICheckBox, desIconButton); + initUICheckBoxChange(nosortUICheckBox, nosortIconButton); + } + + void initUICheckBoxChange(UICheckBox uiCheckBox, IconButton iconButton) { + uiCheckBox.addChangeListener(new ChangeListener() { + @Override + public void stateChanged(ChangeEvent e) { + iconButton.setActiveState(uiCheckBox.isSelected()); + } + }); + } + + void initState(boolean selected) { + ascUICheckBox.setSelected(selected); + desUICheckBox.setSelected(selected); + nosortUICheckBox.setSelected(selected); + ascIconButton.refreshIconLabelColor(new Color(33, 33, 34)); + desIconButton.refreshIconLabelColor(new Color(33, 33, 34)); + nosortIconButton.refreshIconLabelColor(new Color(33, 33, 34)); + } + + class IconButton extends JPanel implements UIObserver { + JLayeredPane jLayeredPane; + String iconTemplatePath; + UILabel iconLabel; + ColorListPane.ColorButton colorButton; + Color color; + BufferedImage bufferedImage; + UIObserverListener uiObserverListener; + boolean activeState; + UILabel borderUiLabel; + + IconButton(String iconTemplatePath) { + this.iconTemplatePath = iconTemplatePath; + initComponents(); + } + + public boolean isActiveState() { + return activeState; + } + + public void setActiveState(boolean activeState) { + if (activeState) { + borderUiLabel.setBorder(BorderFactory.createLineBorder(Color.gray, 1)); + colorButton.setVisible(true); + } else { + borderUiLabel.setBorder(null); + colorButton.setVisible(false); + } + this.activeState = activeState; + } + + void initComponents() { + jLayeredPane = new JLayeredPane(); + iconLabel = getIconLabel(iconTemplatePath); + borderUiLabel = new UILabel(); + borderUiLabel.setSize(ICON_LENGTH, ICON_LENGTH); + borderUiLabel.setOpaque(true); + borderUiLabel.setBackground(Color.WHITE); + iconLabel.setSize(ICON_LENGTH, ICON_LENGTH); + colorButton = new ColorListPane.ColorButton(Color.CYAN); + colorButton.setSize(ICON_LENGTH, ICON_LENGTH); + colorButton.addChangeListener(new ChangeListener() { + @Override + public void stateChanged(ChangeEvent e) { + color = colorButton.getSelectObject(); + refreshIconLabelColor(color); + uiObserverListener.doChange(); + } + }); + jLayeredPane.setPreferredSize(new Dimension(ICON_LENGTH, ICON_LENGTH)); + + jLayeredPane.add(iconLabel, JLayeredPane.POPUP_LAYER); + jLayeredPane.add(borderUiLabel, JLayeredPane.MODAL_LAYER); + jLayeredPane.add(colorButton, JLayeredPane.PALETTE_LAYER); + this.add(jLayeredPane); + } + + void refreshIconLabelColor(Color color) { + Icon icon = getIcon(iconTemplatePath, color); + refreshIconLabel(icon); + } + + void refreshIconLabel(BufferedImage bufferedImage) { + if (bufferedImage != null) { + this.bufferedImage = bufferedImage; + Icon icon = new SVGIcon(bufferedImage); + refreshIconLabel(icon); + } + } + + void refreshIconLabel(Icon icon) { + if (icon != null) { + iconLabel.removeAll(); + iconLabel.setIcon(icon); + iconLabel.repaint(); + } + } + + UILabel getIconLabel(String iconPath) { + return getIconLabel(iconPath, new Color(33, 33, 34)); + } + + UILabel getIconLabel(String iconPath, Color color) { + Icon svgIcon = getIcon(iconPath, color); + return new UILabel(svgIcon); + } + + Icon getIcon(String iconPath, Color color) { + try { + String originalSvgText = getOriginalSvgText(iconPath); + String svgText = originalSvgText.replaceAll("\\{fillColor\\}", shiftColor(color)); + InputStream svgInputStream = new ByteArrayInputStream(svgText.getBytes(StandardCharsets.UTF_8)); + TranscoderInput input = new TranscoderInput(svgInputStream); + bufferedImage = SVGTranscoder.createImage(ICON_SCALE, input).getImage(); + SVGIcon svgIcon = new SVGIcon(bufferedImage); + return svgIcon; + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e, e.getMessage()); + } + return null; + } + + String getOriginalSvgText(String iconPath) throws Exception { + String originalSvgText = originalSvgTextMap.get(iconPath); + if (originalSvgText == null) { + InputStream inputStream = IOUtils.getResourceAsStream(iconPath, HeaderSortRulePane.class); + originalSvgText = getSvgText(inputStream); + originalSvgTextMap.put(iconPath, originalSvgText); + } + return originalSvgText; + } + + String shiftColor(Color color) { + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append(shiftValue(color.getRed())); + stringBuilder.append(shiftValue(color.getGreen())); + stringBuilder.append(shiftValue(color.getBlue())); + return stringBuilder.toString(); + } + + String shiftValue(int value) { + String resultValue = Integer.toHexString(value); + if (resultValue.length() == 1) { + resultValue = "0" + resultValue; + } + return resultValue; + } + + private String getSvgText(InputStream inputStream) throws Exception { + StringBuffer stringBuffer = new StringBuffer(); + byte[] b = new byte[1024]; + for (int n; (n = inputStream.read(b)) != -1; ) { + stringBuffer.append(new String(b, 0, n)); + } + return stringBuffer.toString(); + } + + @Override + public void registerChangeListener(UIObserverListener uiObserverListener) { + this.uiObserverListener = uiObserverListener; + } + + @Override + public boolean shouldResponseChangeListener() { + return true; + } + } + + public void populateBean(SortHeader.SortItem[] sortItems) { + initState(sortItems == null); + if (sortItems != null) { + for (SortHeader.SortItem sortItem : sortItems) { + SortRule sortRule = sortItem.getSortRule(); + BufferedImage bufferedImage = sortItem.getBufferedImage(); + if (sortRule == SortRule.ASC) { + ascIconButton.refreshIconLabel(bufferedImage); + ascUICheckBox.setSelected(true); + } else if (sortRule == SortRule.DES) { + desIconButton.refreshIconLabel(bufferedImage); + desUICheckBox.setSelected(true); + } else if (sortRule == SortRule.NO_SORT) { + nosortIconButton.refreshIconLabel(bufferedImage); + nosortUICheckBox.setSelected(true); + } + + } + } + } + + public SortHeader.SortItem[] updateBean() { + java.util.List items = new ArrayList<>(); + if (ascUICheckBox.isSelected()) { + items.add(new SortHeader.SortItem(SortRule.ASC, ascIconButton.bufferedImage)); + } + if (desUICheckBox.isSelected()) { + items.add(new SortHeader.SortItem(SortRule.DES, desIconButton.bufferedImage)); + } + if (nosortUICheckBox.isSelected()) { + items.add(new SortHeader.SortItem(SortRule.NO_SORT, nosortIconButton.bufferedImage)); + } + SortHeader.SortItem[] resultItems = new SortHeader.SortItem[items.size()]; + return items.toArray(resultItems); + } + +} diff --git a/designer-realize/src/main/java/com/fr/design/sort/header/SortHeaderPane.java b/designer-realize/src/main/java/com/fr/design/sort/header/SortHeaderPane.java new file mode 100644 index 000000000..a68d0eebe --- /dev/null +++ b/designer-realize/src/main/java/com/fr/design/sort/header/SortHeaderPane.java @@ -0,0 +1,65 @@ +package com.fr.design.sort.header; + +import com.fr.design.sort.common.SortColumnRowPane; +import com.fr.report.cell.TemplateCellElement; +import com.fr.report.core.sort.header.SortHeader; +import com.fr.stable.ColumnRow; + +import javax.swing.*; + +public class SortHeaderPane extends JPanel { + int sortHeaderPaneWidth; + int sortHeaderPaneRightWidth; + SortHeader sortHeader; + HeaderAreaPane headerAreaPane; + HeaderSettingPane headerSettingPane; + TemplateCellElement cellElement; + + public SortHeaderPane(int sortHeaderPaneWidth, int sortHeaderPaneRightWidth) { + this.sortHeaderPaneWidth = sortHeaderPaneWidth; + this.sortHeaderPaneRightWidth = sortHeaderPaneRightWidth; + this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); + initHeaderArea(); + initHeaderSetting(); + this.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0)); + } + + void initHeaderArea() { + this.headerAreaPane = new HeaderAreaPane(sortHeaderPaneWidth, sortHeaderPaneRightWidth); + this.add(headerAreaPane); + } + + void initHeaderSetting() { + this.headerSettingPane = new HeaderSettingPane(sortHeaderPaneWidth, sortHeaderPaneRightWidth); + this.add(headerSettingPane); + } + + public void populateBean(SortHeader sortHeader, String defaultHeaderArea) { + this.sortHeader = sortHeader; + boolean showHeaderArea = false; + SortHeader.SortItem[] sortItems = null; + String headerArea = defaultHeaderArea; + ColumnRow columnRow = ColumnRow.valueOf(headerArea); + if (sortHeader != null) { + headerArea = sortHeader.getHeaderArea(); + sortItems = sortHeader.getSortItems(); + if (headerArea != null) { + showHeaderArea = true; + columnRow = ColumnRow.valueOf(headerArea); + } + } + headerAreaPane.populateBean(columnRow, showHeaderArea); + headerSettingPane.populateBean(sortItems); + } + + public SortHeader updateBean(TemplateCellElement cellElement) { + ColumnRow columnRow = headerAreaPane.updateBean( cellElement); + SortHeader.SortItem[] items = headerSettingPane.updateBean(); + String headerArea = null; + if (columnRow != null) { + headerArea = columnRow.toString(); + } + SortHeader sortHeader = new SortHeader(headerArea, null, items); + return sortHeader; + } +} \ No newline at end of file diff --git a/designer-realize/src/main/java/com/fr/quickeditor/cellquick/CellDSColumnEditor.java b/designer-realize/src/main/java/com/fr/quickeditor/cellquick/CellDSColumnEditor.java index 0ede5114f..2a4852ee8 100644 --- a/designer-realize/src/main/java/com/fr/quickeditor/cellquick/CellDSColumnEditor.java +++ b/designer-realize/src/main/java/com/fr/quickeditor/cellquick/CellDSColumnEditor.java @@ -11,6 +11,7 @@ import com.fr.design.dscolumn.DSColumnAdvancedPane; import com.fr.design.dscolumn.ResultSetGroupDockingPane; import com.fr.design.dscolumn.SelectedDataColumnPane; import com.fr.design.event.UIObserverListener; +import com.fr.design.foldablepane.UIExpandablePane; import com.fr.design.formula.CustomVariableResolver; import com.fr.design.formula.FormulaFactory; import com.fr.design.formula.UIFormula; @@ -31,6 +32,7 @@ import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayoutHelper; import com.fr.design.mainframe.cell.AbstractDSCellEditorPane; +import com.fr.design.sort.celldscolumn.CellDSColumnSortPane; import com.fr.design.utils.gui.UIComponentUtils; import com.fr.design.widget.FRWidgetFactory; import com.fr.general.IOUtils; @@ -221,62 +223,6 @@ public class CellDSColumnEditor extends CellQuickEditor { */ private UIButton conditionUIButton; - /** - * 分组设置监听器 - */ - private ItemListener groupListener = new ItemListener() { - @Override - public void itemStateChanged(ItemEvent e) { - if (e == null) { - //分组-高级-自定义点确定的时候传进来null的e,但是这时候应该触发保存 - groupPane.update(); - fireTargetModified(); - return; - } - if (e.getStateChange() == ItemEvent.DESELECTED) { - groupPane.update(); - fireTargetModified(); - } - } - }; - /** - * 数据集列设置监听器 - */ - private ItemListener dataListener = new ItemListener() { - @Override - public void itemStateChanged(ItemEvent e) { - if (e.getStateChange() == ItemEvent.SELECTED) { - dataPane.update(cellElement); - fireTargetModified(); - } - } - }; - - DSColumnBasicEditorPane() { - dataPane = new SelectedDataColumnPane(true, true); - groupPane = new ResultSetGroupDockingPane(); - dataPane.setListener(dataListener); - groupPane.setListener(groupListener); - - double[] rowSize = {P}, columnSize = {60, F}; - UILabel uiLabel = FRWidgetFactory.createLineWrapLabel(Toolkit.i18nText("Fine-Design_Report_Filter_Conditions")); - condition = new DSColumnConditionAction(); - if (tc != null) { - condition.setEditingComponent(tc); - } - //丢掉icon,修改按钮名称为编辑 - condition.setSmallIcon(UIConstants.EMPTY_ICON); - condition.setName(Toolkit.i18nText("Fine-Design_Basic_Edit")); - conditionUIButton = new UIButton(condition); - Component[][] components = new Component[][]{ - new Component[]{uiLabel, UIComponentUtils.wrapWithBorderLayoutPane(conditionUIButton)} - }; - conditionPane = TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, HGAP, VGAP); - this.createScrollPane(); - this.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0)); - - } - @Override public String getIconPath() { @@ -297,11 +243,13 @@ public class CellDSColumnEditor extends CellQuickEditor { @Override public void populate() { + this.removeAttributeChangeListener(); dataPane.populate(DesignTableDataManager.getEditingTableDataSource(), cellElement, tc); groupPane.populate(cellElement); if (tc != null) { condition.setEditingComponent(tc); } + this.addAttributeChangeListener(); } @Override @@ -318,7 +266,7 @@ public class CellDSColumnEditor extends CellQuickEditor { */ @Override protected JPanel createContentPane() { - + initComponents(); double[] columnSize = {F}; double[] rowSize = {P, P, P}; Component[][] components = new Component[][]{ @@ -331,16 +279,43 @@ public class CellDSColumnEditor extends CellQuickEditor { }; return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, HGAP, VGAP); } + + private void initComponents(){ + dataPane = new SelectedDataColumnPane(true, true); + groupPane = new ResultSetGroupDockingPane(); + + double[] rowSize = {P}, columnSize = {60, F}; + UILabel uiLabel = FRWidgetFactory.createLineWrapLabel(Toolkit.i18nText("Fine-Design_Report_Filter_Conditions")); + condition = new DSColumnConditionAction(); + if (tc != null) { + condition.setEditingComponent(tc); + } + //丢掉icon,修改按钮名称为编辑 + condition.setSmallIcon(UIConstants.EMPTY_ICON); + condition.setName(Toolkit.i18nText("Fine-Design_Basic_Edit")); + conditionUIButton = new UIButton(condition); + Component[][] components = new Component[][]{ + new Component[]{uiLabel, UIComponentUtils.wrapWithBorderLayoutPane(conditionUIButton)} + }; + conditionPane = TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, HGAP, VGAP); + this.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0)); + } + @Override + protected AttributeChangeListener getAttributeChangeListener() { + return new AttributeChangeListener() { + @Override + public void attributeChange() { + update(); + fireTargetModified(); + } + }; + } } class DSColumnAdvancedEditorPane extends AbstractDSCellEditorPane { /*pane begin*/ - /** - * 排列顺序 - */ - private ResultSetSortConfigPane sortPane; /** * 结果集筛选 */ @@ -373,88 +348,13 @@ public class CellDSColumnEditor extends CellQuickEditor { * 补充空白数据数目面板 可隐藏 */ private JPanel multiPane; - /*pane end*/ - - /*listeners begin*/ - private UIObserverListener sortPaneFormulaChangeListener = new UIObserverListener() { - @Override - public void doChange() { - sortPane.update(cellElement); - fireTargetModified(); - } - }; - - private ChangeListener sortTypeBtnGroupChangeListener = new ChangeListener() { - @Override - public void stateChanged(ChangeEvent e) { - sortPane.update(cellElement); - fireTargetModified(); - } - }; - - private UIObserverListener filterPaneChangeListener = new UIObserverListener() { - @Override - public void doChange() { - filterPane.update(cellElement); - fireTargetModified(); - } - }; - - private UIObserverListener customValuePaneChangeListener = new UIObserverListener() { - @Override - public void doChange() { - valuePane.update(cellElement); - fireTargetModified(); - } - }; - - private AttributeChangeListener formatChangeListener = new AttributeChangeListener() { - @Override - public void attributeChange() { - formatAttrPane.update(cellElement); - fireTargetModified(); - } - }; - - private ChangeListener heCheckBoxChangeListener = new ChangeListener() { - @Override - public void stateChanged(ChangeEvent e) { - cellDSColumnAdvancedPane.updateExtendConfig(); - fireTargetModified(); - } - }; - - private ChangeListener veCheckBoxChangeListener = new ChangeListener() { - @Override - public void stateChanged(ChangeEvent e) { - cellDSColumnAdvancedPane.updateExtendConfig(); - fireTargetModified(); - } - }; - - private ActionListener useMultiNumCheckBoxChangeListener = new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - checkButtonEnabled(); - cellDSColumnAdvancedPane.updateMultipleConfig(); - fireTargetModified(); - } - }; - - private ChangeListener multiNumSpinnerChangeListener = new ChangeListener() { - @Override - public void stateChanged(ChangeEvent e) { - cellDSColumnAdvancedPane.updateMultipleConfig(); - fireTargetModified(); - } - }; - /*listeners end*/ + private CellDSColumnSortPane cellDSColumnSortPane; + /*pane end*/ public DSColumnAdvancedEditorPane() { this.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0)); - this.createScrollPane(); } @@ -469,10 +369,10 @@ public class CellDSColumnEditor extends CellQuickEditor { } + @Override public void update() { if (cellElement != null) { - sortPane.update(cellElement); valuePane.update(cellElement); formatAttrPane.update(cellElement); filterPane.update(cellElement); @@ -480,14 +380,14 @@ public class CellDSColumnEditor extends CellQuickEditor { updateExtendConfig(); //更新补充空白设置 updateMultipleConfig(); + cellDSColumnSortPane.updateBean(cellElement); } } @Override public void populate() { if (cellElement != null) { - disableListener(); - sortPane.populate(cellElement); + this.removeAttributeChangeListener(); valuePane.populate(cellElement); formatAttrPane.populate(cellElement); filterPane.populate(cellElement); @@ -524,8 +424,11 @@ public class CellDSColumnEditor extends CellQuickEditor { useMultiNumCheckBox.setSelected(true); multiNumSpinner.setValue(cellExpandAttr.getMultipleNumber()); } + if (cellDSColumnSortPane != null) { + cellDSColumnSortPane.populateBean(cellElement); + } this.checkButtonEnabled(); - enableListener(); + this.addAttributeChangeListener(); } } @@ -534,6 +437,17 @@ public class CellDSColumnEditor extends CellQuickEditor { } + @Override + protected AttributeChangeListener getAttributeChangeListener() { + return new AttributeChangeListener() { + @Override + public void attributeChange() { + update(); + fireTargetModified(); + } + }; + } + /** * 更新单元格扩展属性 */ @@ -578,11 +492,8 @@ public class CellDSColumnEditor extends CellQuickEditor { */ @Override protected JPanel createContentPane() { + JPanel contentPane = new JPanel(new BorderLayout()); this.setLayout(FRGUIPaneFactory.createBorderLayout()); - - //结果集排序 - sortPane = new ResultSetSortConfigPane(); - //结果筛选 filterPane = new ResultSetFilterConfigPane(); @@ -616,10 +527,7 @@ public class CellDSColumnEditor extends CellQuickEditor { multiPane.setBorder(BorderFactory.createEmptyBorder(0, 20, 0, 0)); multiNumPane.add(multiPane); - enableListener(); - Component[][] components = new Component[][]{ - {sortPane}, {filterPane}, {valuePane}, {formatAttrPane}, @@ -630,32 +538,15 @@ public class CellDSColumnEditor extends CellQuickEditor { double[] rowSize = new double[components.length]; Arrays.fill(rowSize, P); double[] columnSize = {F}; - - return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, HGAP, VGAP); - } - - public void enableListener() { - sortPane.addListener(sortPaneFormulaChangeListener, sortTypeBtnGroupChangeListener); - filterPane.addListener(filterPaneChangeListener); - valuePane.addListener(customValuePaneChangeListener); - formatAttrPane.addAttributeChangeListener(formatChangeListener); - heCheckBox.addChangeListener(heCheckBoxChangeListener); - veCheckBox.addChangeListener(veCheckBoxChangeListener); - useMultiNumCheckBox.addActionListener(useMultiNumCheckBoxChangeListener); - multiNumSpinner.addChangeListener(multiNumSpinnerChangeListener); - } - - public void disableListener() { - sortPane.removeListener(sortTypeBtnGroupChangeListener); - filterPane.removeListener(); - valuePane.removeListener(); - heCheckBox.removeChangeListener(heCheckBoxChangeListener); - veCheckBox.removeChangeListener(veCheckBoxChangeListener); - useMultiNumCheckBox.removeActionListener(useMultiNumCheckBoxChangeListener); - multiNumSpinner.removeChangeListener(multiNumSpinnerChangeListener); + JPanel advancePropertyPane = TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, HGAP, VGAP); + contentPane.add(advancePropertyPane, BorderLayout.NORTH); + UIExpandablePane sortUIExpandablePane = + new UIExpandablePane(Toolkit.i18nText("Fine-Design_Sort_Data_Column_Sort"), + 223, 24, cellDSColumnSortPane = new CellDSColumnSortPane()); + contentPane.add(sortUIExpandablePane, BorderLayout.CENTER); + return contentPane; } - private void checkButtonEnabled() { if (useMultiNumCheckBox.isSelected()) { multiNumSpinner.setEnabled(true); @@ -666,136 +557,6 @@ public class CellDSColumnEditor extends CellQuickEditor { } } - /** - * 单元格元素>数据集>高级设置>结果排序设置面板 - * - * @see com.fr.design.expand.SortExpandAttrPane - * @see DSColumnAdvancedPane.SortPane - */ - public class ResultSetSortConfigPane extends JPanel { - private static final String DEFAULT_VALUE = "="; - private JPanel contentPane; - private UIButtonGroup sortTypePane; - private JFormulaField formulaField; - private CardLayout cardLayout; - private JPanel centerPane; - - - public ResultSetSortConfigPane() { - this.setLayout(new BorderLayout()); - Icon[] iconArray = { - IOUtils.readIcon("/com/fr/design/images/expand/none16x16.png"), - IOUtils.readIcon("/com/fr/design/images/expand/asc.png"), - IOUtils.readIcon("/com/fr/design/images/expand/des.png") - }; - String[] nameArray = {Toolkit.i18nText("Fine-Design_Report_Sort_Original"), Toolkit.i18nText("Fine-Design_Report_Sort_Ascending"), Toolkit.i18nText("Fine-Design_Report_Sort_Descending")}; - sortTypePane = new UIButtonGroup(iconArray); - sortTypePane.setAllToolTips(nameArray); - sortTypePane.setGlobalName(Toolkit.i18nText("Fine-Design_Basic_ExpandD_Sort_After_Expand")); - - cardLayout = new CardLayout(); - centerPane = new JPanel(cardLayout); - formulaField = new JFormulaField(DEFAULT_VALUE); - centerPane.add(new JPanel(), "none"); - centerPane.add(formulaField, "content"); - UILabel sortLabel = new UILabel(Toolkit.i18nText("Fine-Design_Report_Sort_Sort_Order")); - sortLabel.setPreferredSize(LABEL_DIMENSION); - sortTypePane.addChangeListener(new ChangeListener() { - @Override - public void stateChanged(ChangeEvent e) { - boolean noContent = sortTypePane.getSelectedIndex() == 0; - cardLayout.show(centerPane, noContent ? "none" : "content"); - if (noContent) { - centerPane.setPreferredSize(new Dimension(0, 0)); - TableLayoutHelper.modifyTableLayoutIndexVGap(contentPane, 2, 0); - } else { - centerPane.setPreferredSize(new Dimension(165, 20)); - TableLayoutHelper.modifyTableLayoutIndexVGap(contentPane, 2, VGAP); - } - } - }); - - Component[][] components = new Component[][]{ - new Component[]{sortLabel, sortTypePane}, - new Component[]{null, centerPane} - }; - - double[] rowSize = {P, P}, columnSize = {P, F}; - contentPane = TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, HGAP, VGAP); - this.add(contentPane, BorderLayout.CENTER); - } - - - /** - * 刷新面板信息 - * - * @param cellElement 单元格 - */ - public void populate(TemplateCellElement cellElement) { - if (cellElement != null) { - Object value = cellElement.getValue(); - if (value instanceof DSColumn) { - this.formulaField.populateElement(cellElement); - DSColumn dSColumn = (DSColumn) value; - int sort = dSColumn.getOrder(); - this.sortTypePane.setSelectedIndex(sort); - boolean noContent = sortTypePane.getSelectedIndex() == 0; - cardLayout.show(centerPane, noContent ? "none" : "content"); - if (noContent) { - centerPane.setPreferredSize(new Dimension(0, 0)); - TableLayoutHelper.modifyTableLayoutIndexVGap(contentPane, 2, 0); - } else { - centerPane.setPreferredSize(new Dimension(156, 20)); - TableLayoutHelper.modifyTableLayoutIndexVGap(contentPane, 2, VGAP); - } - String sortFormula = dSColumn.getSortFormula(); - if (sortFormula != null && sortFormula.length() >= 1) { - this.formulaField.populate(sortFormula); - } else { - this.formulaField.populate(DEFAULT_VALUE); - } - } - } - } - - /** - * 保存面板配置信息 - * - * @param cellElement 单元格 - */ - public void update(CellElement cellElement) { - if (cellElement != null) { - Object value = cellElement.getValue(); - if (value instanceof DSColumn) { - DSColumn dSColumn = (DSColumn) value; - dSColumn.setOrder(this.sortTypePane.getSelectedIndex()); - dSColumn.setSortFormula(this.formulaField.getFormulaText()); - } - } - } - - /** - * 添加事件监听器 - * - * @param formulaChangeListener 公式输入框改动事件监听器 - * @param changeListener 排序类型下拉框改动事件监听器 - */ - public void addListener(UIObserverListener formulaChangeListener, ChangeListener changeListener) { - formulaField.addListener(formulaChangeListener); - sortTypePane.addChangeListener(changeListener); - } - - /** - * 去除事件监听器 - * - * @param changeListener 排序类型下拉框改动事件监听器 - */ - public void removeListener(ChangeListener changeListener) { - formulaField.removeListener(); - sortTypePane.removeChangeListener(changeListener); - } - } - /** * 单元格元素>数据集>高级设置>结果集筛选设置面板 *