|
|
|
package com.fr.design.sort.expressionpane;
|
|
|
|
|
|
|
|
import com.fine.swing.ui.layout.Column;
|
|
|
|
import com.fine.theme.utils.FineLayoutBuilder;
|
|
|
|
import com.fine.theme.utils.FineUIScale;
|
|
|
|
import com.fine.theme.utils.FineUIStyle;
|
|
|
|
import com.fr.design.border.FineBorderFactory;
|
|
|
|
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;
|
|
|
|
|
|
|
|
import static com.fine.theme.utils.FineUIScale.scale;
|
|
|
|
|
|
|
|
public class CustomSequenceEditPane extends BasicPane {
|
|
|
|
java.util.List<String> customSequence;
|
|
|
|
JSplitPane jSplitPane;
|
|
|
|
Column referenceSequencePanel;
|
|
|
|
Column editSequencePanel;
|
|
|
|
JTextArea jTextArea;
|
|
|
|
|
|
|
|
CustomSequenceEditPane(java.util.List<String> 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 Column();
|
|
|
|
UILabel titleLabel = new UILabel(Toolkit.i18nText("Fine-Design_Sort_Reference_Sequence"));
|
|
|
|
UIScrollPane uiScrollPane = new UIScrollPane(getReferenceSequenceList());
|
|
|
|
uiScrollPane.setPreferredSize(scale(new Dimension(200, 320)));
|
|
|
|
uiScrollPane.setBorder(FineBorderFactory.createWrappedRoundBorder());
|
|
|
|
|
|
|
|
referenceSequencePanel.add(titleLabel);
|
|
|
|
referenceSequencePanel.add(uiScrollPane);
|
|
|
|
referenceSequencePanel.setSize(scale(new Dimension(200, 400)));
|
|
|
|
}
|
|
|
|
|
|
|
|
private UIList getReferenceSequenceList() {
|
|
|
|
UIList uiList = new UIList(getReferenceSequenceModel());
|
|
|
|
new CustomSequenceEditDragSource(uiList, DnDConstants.ACTION_MOVE);
|
|
|
|
FineUIStyle.setStyle(uiList, FineUIStyle.PURE_LIST);
|
|
|
|
return uiList;
|
|
|
|
}
|
|
|
|
|
|
|
|
private String[] getReferenceSequenceModel() {
|
|
|
|
List<List<String>> 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 Column();
|
|
|
|
UILabel inputLabel = new UILabel(Toolkit.i18nText("Fine-Design_Sort_Input_Sequence"));
|
|
|
|
UILabel hintLabel = new UILabel(Toolkit.i18nText("Fine-Design_Sort_Please_Interlace_Sequence_Elements"));
|
|
|
|
FineUIStyle.setStyle(hintLabel, FineUIStyle.LABEL_TIP);
|
|
|
|
|
|
|
|
JPanel titlePane = FineLayoutBuilder.createHorizontalLayout(5, inputLabel, hintLabel);
|
|
|
|
jTextArea = getTextArea();
|
|
|
|
UIScrollPane uiScrollPane = new UIScrollPane(jTextArea);
|
|
|
|
uiScrollPane.setPreferredSize(scale(new Dimension(475, 320)));
|
|
|
|
|
|
|
|
editSequencePanel.add(titlePane);
|
|
|
|
editSequencePanel.add(uiScrollPane);
|
|
|
|
editSequencePanel.setSize(scale(new Dimension(475, 320)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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<java.util.List<String>> customSequences = new ArrayList<>();
|
|
|
|
|
|
|
|
public CustomSequenceEditDropTarget(PlaceholderTextArea jPanel, java.util.List<java.util.List<String>> 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<String> 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<String> updateBean() {
|
|
|
|
return CustomSequenceSortExpression.stringToCustomSequence(jTextArea.getText(), "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|