|
|
|
@ -1,5 +1,7 @@
|
|
|
|
|
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; |
|
|
|
@ -10,9 +12,18 @@ 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.ui.util.UIUtil; |
|
|
|
|
import com.fr.general.Background; |
|
|
|
|
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; |
|
|
|
@ -21,6 +32,12 @@ import javax.swing.*;
|
|
|
|
|
import java.awt.*; |
|
|
|
|
import java.awt.event.ActionEvent; |
|
|
|
|
import java.awt.event.ActionListener; |
|
|
|
|
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; |
|
|
|
@ -75,7 +92,7 @@ public class SortColumnRowPane extends JPanel implements UIObserver {
|
|
|
|
|
|
|
|
|
|
void initSelectButton() { |
|
|
|
|
selectButton = new UIButton(IconUtils.readIcon("/com/fr/design/images/buttonicon/select.png")); |
|
|
|
|
selectButton.addActionListener(new SelectActionListener(this)); |
|
|
|
|
selectButton.addMouseListener(new SelectActionListener(this)); |
|
|
|
|
this.add(selectButton); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -90,7 +107,7 @@ public class SortColumnRowPane extends JPanel implements UIObserver {
|
|
|
|
|
refresh(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void setColumnRow(ColumnRow columnRow){ |
|
|
|
|
public void setColumnRow(ColumnRow columnRow) { |
|
|
|
|
populateBean(columnRow); |
|
|
|
|
uiObserverListener.doChange(); |
|
|
|
|
} |
|
|
|
@ -112,59 +129,145 @@ public class SortColumnRowPane extends JPanel implements UIObserver {
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class SelectActionListener implements ActionListener { |
|
|
|
|
class SelectActionListener extends MouseAdapter { |
|
|
|
|
SortColumnRowPane columnRowPane; |
|
|
|
|
|
|
|
|
|
Map<ColumnRow, Style> disableHeaderCellsStyleMap = new HashMap<>(); |
|
|
|
|
java.util.List<TemplateCellElement> tempHeaderCells = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
SelectActionListener(SortColumnRowPane columnRowPane) { |
|
|
|
|
this.columnRowPane = columnRowPane; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void actionPerformed(ActionEvent e) { |
|
|
|
|
public void mouseClicked(MouseEvent e) { |
|
|
|
|
ElementCasePane elementCasePane = getCurrentElementCase(); |
|
|
|
|
if (elementCasePane == null || isAlreadyAddListener) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
oldSelection = (CellSelection) elementCasePane.getSelection(); |
|
|
|
|
elementCasePane.getGrid().setNotShowingTableSelectPane(false); |
|
|
|
|
elementCasePane.setEditable(false); |
|
|
|
|
elementCasePane.repaint(10); |
|
|
|
|
|
|
|
|
|
prepareSelectHeader(elementCasePane); |
|
|
|
|
gridSelectionChangeListener = new SelectionListener() { |
|
|
|
|
@Override |
|
|
|
|
public void selectionChanged(SelectionEvent e) { |
|
|
|
|
Selection selection = elementCasePane.getSelection(); |
|
|
|
|
if (selection instanceof CellSelection) { |
|
|
|
|
CellSelection cellselection = (CellSelection) selection; |
|
|
|
|
ColumnRow cr = ColumnRow.valueOf(cellselection.getColumn(), cellselection.getRow()); |
|
|
|
|
elementCasePane.setOldSelecton(oldSelection); |
|
|
|
|
columnRowPane.setColumnRow(cr); |
|
|
|
|
} |
|
|
|
|
elementCasePane.removeSelectionChangeListener(gridSelectionChangeListener); |
|
|
|
|
isAlreadyAddListener = false; |
|
|
|
|
elementCasePane.getGrid().setNotShowingTableSelectPane(true); |
|
|
|
|
elementCasePane.setEditable(true); |
|
|
|
|
elementCasePane.repaint(); |
|
|
|
|
completeSelectHeader(elementCasePane); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
elementCasePane.addSelectionChangeListener(gridSelectionChangeListener); |
|
|
|
|
isAlreadyAddListener = true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private ElementCasePane getCurrentElementCase() { |
|
|
|
|
try { |
|
|
|
|
TargetComponent targetComponent |
|
|
|
|
= HistoryTemplateListCache.getInstance().getCurrentEditingTemplate().getCurrentElementCasePane(); |
|
|
|
|
if (targetComponent instanceof ElementCasePane) { |
|
|
|
|
return (ElementCasePane) targetComponent; |
|
|
|
|
private void prepareSelectHeader(ElementCasePane elementCasePane) { |
|
|
|
|
ashDisableHeaderCellsStyle(elementCasePane.getEditingElementCase()); |
|
|
|
|
oldSelection = (CellSelection) elementCasePane.getSelection(); |
|
|
|
|
elementCasePane.getGrid().setNotShowingTableSelectPane(false); |
|
|
|
|
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 (!disableHeaderCellsStyleMap.keySet().contains(columnRow)) { |
|
|
|
|
columnRowPane.setColumnRow(columnRow); |
|
|
|
|
} |
|
|
|
|
restoreDisableHeaderCellsStyle(elementCasePane.getEditingElementCase()); |
|
|
|
|
} |
|
|
|
|
elementCasePane.removeSelectionChangeListener(gridSelectionChangeListener); |
|
|
|
|
isAlreadyAddListener = false; |
|
|
|
|
elementCasePane.getGrid().setNotShowingTableSelectPane(true); |
|
|
|
|
elementCasePane.setEditable(true); |
|
|
|
|
elementCasePane.repaint(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void ashDisableHeaderCellsStyle(TemplateElementCase elementCase) { |
|
|
|
|
disableHeaderCellsStyleMap = new HashMap<>(); |
|
|
|
|
tempHeaderCells = new ArrayList<>(); |
|
|
|
|
Map<ColumnRow, TemplateCellElement> disableHeaderCellsMap = getDisableHeaderCellsMap(elementCase); |
|
|
|
|
for (ColumnRow headerColumnRow : disableHeaderCellsMap.keySet()) { |
|
|
|
|
TemplateCellElement headerCell = disableHeaderCellsMap.get(headerColumnRow); |
|
|
|
|
if (headerCell == null) { |
|
|
|
|
headerCell = new DefaultTemplateCellElement(headerColumnRow.column, headerColumnRow.row); |
|
|
|
|
elementCase.addCellElement(headerCell); |
|
|
|
|
tempHeaderCells.add(headerCell); |
|
|
|
|
} |
|
|
|
|
Style style = headerCell.getStyle(); |
|
|
|
|
disableHeaderCellsStyleMap.put(headerColumnRow, style); |
|
|
|
|
style = style.deriveBackground(ColorBackground.getInstance(Color.gray)); |
|
|
|
|
headerCell.setStyle(style); |
|
|
|
|
} |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
FineLoggerFactory.getLogger().error(e, e.getMessage()); |
|
|
|
|
} |
|
|
|
|
return null; |
|
|
|
|
|
|
|
|
|
private void restoreDisableHeaderCellsStyle(TemplateElementCase elementCase) { |
|
|
|
|
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()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private Map<ColumnRow, TemplateCellElement> getDisableHeaderCellsMap(TemplateElementCase elementCase) { |
|
|
|
|
Map<ColumnRow, TemplateCellElement> headerCellsMap = new HashMap<>(); |
|
|
|
|
Iterator iterator = elementCase.cellIterator(); |
|
|
|
|
while (iterator.hasNext()) { |
|
|
|
|
TemplateCellElement templateCellElement = (TemplateCellElement) iterator.next(); |
|
|
|
|
CellExpandAttr cellExpandAttr = templateCellElement.getCellExpandAttr(); |
|
|
|
|
if (cellExpandAttr != null) { |
|
|
|
|
handleDisableHeaderCell(elementCase, cellExpandAttr, headerCellsMap); |
|
|
|
|
} |
|
|
|
|
Object value = templateCellElement.getValue(); |
|
|
|
|
if (value instanceof DSColumn) { |
|
|
|
|
handleDisableHeaderCell(elementCase, (DSColumn) value, headerCellsMap); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return headerCellsMap; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void handleDisableHeaderCell(TemplateElementCase elementCase, CellSortable cellSortable, Map<ColumnRow, TemplateCellElement> headerCellsMap) { |
|
|
|
|
if (cellSortable.getCellSortAttr() != null) { |
|
|
|
|
SortHeader sortHeader = cellSortable.getCellSortAttr().getSortHeader(); |
|
|
|
|
if (sortHeader != null) { |
|
|
|
|
String headerArea = sortHeader.getHeaderArea(); |
|
|
|
|
if (headerArea != null) { |
|
|
|
|
ColumnRow headerColumnRow = ColumnRow.valueOf(headerArea); |
|
|
|
|
ColumnRow columnRow = columnRowPane.updateBean(); |
|
|
|
|
if (!headerColumnRow.equals(columnRow)) { |
|
|
|
|
TemplateCellElement headerCell |
|
|
|
|
= elementCase.getTemplateCellElement(headerColumnRow.column, headerColumnRow.row); |
|
|
|
|
headerCellsMap.put(headerColumnRow, headerCell); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected void refresh() { |
|
|
|
|
validate(); |
|
|
|
|
repaint(); |
|
|
|
|