You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
113 lines
3.7 KiB
113 lines
3.7 KiB
3 years ago
|
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<SortExpression> 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<SortExpression> 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;
|
||
|
}
|
||
|
}
|