|
|
|
package com.fr.design.sort.common;
|
|
|
|
|
|
|
|
import com.fr.design.gui.ilable.UILabel;
|
|
|
|
import com.fr.design.i18n.DesignSizeI18nManager;
|
|
|
|
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(Dimension dimension) {
|
|
|
|
this(dimension.width, dimension.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
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, cellElement);
|
|
|
|
}
|
|
|
|
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() {
|
|
|
|
int height = (int) DesignSizeI18nManager.getInstance().i18nDimension("com.fr.design.sort.common.AbstractSortPane.IntervalUILabel").getHeight();
|
|
|
|
return createIntervalUILabel(new Dimension(PANE_COMPONENT_H_GAP, height));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static UILabel createIntervalUILabel(Dimension dimension) {
|
|
|
|
UILabel uiLabel = new UILabel();
|
|
|
|
uiLabel.setPreferredSize(dimension);
|
|
|
|
return uiLabel;
|
|
|
|
}
|
|
|
|
}
|