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.
148 lines
5.2 KiB
148 lines
5.2 KiB
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 { |
|
|
|
protected int sortGroupPaneWidth; |
|
protected int sortGroupPaneRightWidth; |
|
List<SortExpression> sortExpressions; |
|
List<JPanel> sortItemPanes = 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<SortExpression> sortExpressions, String selfSortArea) { |
|
this.sortItemListPane.removeAll(); |
|
this.selfSortArea = selfSortArea; |
|
this.sortExpressions = sortExpressions; |
|
this.sortItemPanes = new ArrayList<>(); |
|
for (int i = 0; i < sortExpressions.size(); i++) { |
|
addSortItem(sortExpressions.get(i), i == 0); |
|
} |
|
refresh(); |
|
} |
|
|
|
protected abstract AbstractSortItemPane refreshSortItemPane(int sortItemPaneWidth, int sortItemPaneRightWidth, SortExpression sortExpression); |
|
|
|
public List<SortExpression> updateBean() { |
|
List<SortExpression> sortExpressions = new ArrayList<>(); |
|
for (JPanel sortItemPane : sortItemPanes) { |
|
SortExpression sortExpression = null; |
|
AbstractSortItemPane abstractSortItemPane = null; |
|
if (sortItemPane instanceof AbstractSortItemPane) { |
|
abstractSortItemPane = (AbstractSortItemPane) sortItemPane; |
|
} else if (sortItemPane instanceof SortUIExpandablePane) { |
|
abstractSortItemPane = (AbstractSortItemPane) ((SortUIExpandablePane) sortItemPane).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(sortItemPanes.get(no)); |
|
sortExpressions.remove(no); |
|
sortItemPanes.remove(no); |
|
refresh(); |
|
} |
|
} |
|
|
|
public void registerChangeListener(ComponentChangeListener componentChangeListener) { |
|
this.componentChangeListener = componentChangeListener; |
|
} |
|
|
|
public void addSortItem(SortExpression sortExpression, boolean mainSort) { |
|
int sortItemPaneWidth = sortGroupPaneWidth; |
|
int sortItemPaneRightWidth = sortGroupPaneRightWidth; |
|
if (!mainSort) { |
|
sortItemPaneWidth -= 12; |
|
sortItemPaneRightWidth -= 12; |
|
} |
|
if (sortExpression == null) { |
|
sortExpression = new CellSortExpression(selfSortArea); |
|
sortExpressions.add(sortExpression); |
|
} |
|
|
|
AbstractSortItemPane abstractSortItemPane = |
|
refreshSortItemPane(sortItemPaneWidth, sortItemPaneRightWidth, sortExpression); |
|
|
|
JPanel sortItemPane = abstractSortItemPane; |
|
if (!mainSort) { |
|
sortItemPane = new SortUIExpandablePane(abstractSortItemPane, this); |
|
} |
|
sortItemListPane.add(sortItemPane); |
|
sortItemPanes.add(sortItemPane); |
|
|
|
if (componentChangeListener != null) { |
|
componentChangeListener.initListener(sortItemPane); |
|
} |
|
refresh(); |
|
} |
|
|
|
protected void refresh() { |
|
validate(); |
|
repaint(); |
|
revalidate(); |
|
} |
|
|
|
class AddSortItemBar extends JPanel { |
|
AbstractSortGroupPane sortGroupPane; |
|
|
|
AddSortItemBar(AbstractSortGroupPane sortGroupPane) { |
|
init(); |
|
this.sortGroupPane = sortGroupPane; |
|
} |
|
|
|
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, 20)); |
|
this.add(uiButton); |
|
uiButton.addActionListener(new ActionListener() { |
|
public void actionPerformed(ActionEvent e) { |
|
sortGroupPane.addSortItem(null, false); |
|
} |
|
}); |
|
} |
|
} |
|
}
|
|
|