forked from fanruan/finekit
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.
112 lines
4.1 KiB
112 lines
4.1 KiB
6 years ago
|
package com.fanruan.api.design.ui.editor;
|
||
|
|
||
|
import com.fanruan.api.design.DesignKit;
|
||
|
import com.fanruan.api.design.ui.component.UIComboBox;
|
||
|
import com.fanruan.api.util.StringKit;
|
||
|
import com.fr.data.SimpleDSColumn;
|
||
|
import com.fr.design.data.DesignTableDataManager;
|
||
|
import com.fr.design.data.datapane.TableDataComboBox;
|
||
|
import com.fr.design.data.tabledata.wrapper.TableDataWrapper;
|
||
|
import com.fr.general.data.TableDataColumn;
|
||
|
|
||
|
import javax.swing.*;
|
||
|
import java.awt.*;
|
||
|
import java.awt.event.ItemEvent;
|
||
|
import java.awt.event.ItemListener;
|
||
|
import java.util.List;
|
||
|
import java.util.regex.Pattern;
|
||
|
|
||
|
/**
|
||
|
* @author richie
|
||
|
* @version 10.0
|
||
|
* Created by richie on 2019/11/4
|
||
|
* 用于编辑和展示数据集列的编辑器
|
||
|
*/
|
||
|
public class TypeColumnTableDataEditor extends BaseEditor<SimpleDSColumn> {
|
||
|
private TableDataComboBox tableDataComboBox;
|
||
|
private UIComboBox columnNameComboBox;
|
||
|
private String[] columnNames;
|
||
|
|
||
|
public TypeColumnTableDataEditor() {
|
||
|
this.setName(DesignKit.i18nText("Fine-Design_Basic_DS_Column"));
|
||
|
this.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
|
||
|
tableDataComboBox = new TableDataComboBox(DesignTableDataManager.getEditingTableDataSource());
|
||
|
columnNames = new String[0];
|
||
|
tableDataComboBox.addItemListener(new ItemListener() {
|
||
|
@Override
|
||
|
public void itemStateChanged(ItemEvent e) {
|
||
|
if (tableDataComboBox.getSelectedItem() == null) {
|
||
|
return;
|
||
|
}
|
||
|
List<String> nameList = tableDataComboBox.getSelectedItem().calculateColumnNameList();
|
||
|
columnNames = new String[nameList.size()];
|
||
|
columnNames = tableDataComboBox.getSelectedItem().calculateColumnNameList().toArray(columnNames);
|
||
|
columnNameComboBox.removeAllItems();
|
||
|
for (int i = 0; i < columnNames.length; i++) {
|
||
|
columnNameComboBox.addItem(columnNames[i]);
|
||
|
}
|
||
|
columnNameComboBox.validate();
|
||
|
}
|
||
|
});
|
||
|
columnNameComboBox = new UIComboBox();
|
||
|
tableDataComboBox.setPreferredSize(new Dimension(82, 20));
|
||
|
this.add(tableDataComboBox);
|
||
|
columnNameComboBox.setPreferredSize(new Dimension(82, 20));
|
||
|
this.add(columnNameComboBox);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public JComponent getSwingComponent() {
|
||
|
return columnNameComboBox;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public SimpleDSColumn getValue() {
|
||
|
if (this.tableDataComboBox.getSelectedItem() == null || this.columnNameComboBox.getSelectedItem() == null) {
|
||
|
return null;
|
||
|
}
|
||
|
SimpleDSColumn dsColumn = new SimpleDSColumn();
|
||
|
TableDataWrapper item = this.tableDataComboBox.getSelectedItem();
|
||
|
dsColumn.setDsName(item.getTableDataName());
|
||
|
TableDataColumn column;
|
||
|
String columnExp = (String) this.columnNameComboBox.getSelectedItem();
|
||
|
if (StringKit.isNotBlank(columnExp) && (columnExp.length() > 0 && columnExp.charAt(0) == '#') && !columnExp.endsWith("#")) {
|
||
|
String number = columnExp.substring(1);
|
||
|
Pattern pattern = Pattern.compile("[^\\d]");
|
||
|
if (pattern.matcher(number).find()) {
|
||
|
column = TableDataColumn.createColumn(columnExp);
|
||
|
} else {
|
||
|
int serialNumber = Integer.parseInt(columnExp.substring(1));
|
||
|
column = TableDataColumn.createColumn(serialNumber);
|
||
|
}
|
||
|
} else {
|
||
|
column = TableDataColumn.createColumn(columnExp);
|
||
|
}
|
||
|
dsColumn.setColumn(column);
|
||
|
return dsColumn;
|
||
|
}
|
||
|
|
||
|
public String getIconName() {
|
||
|
return "ds_column";
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public boolean accept(Object object) {
|
||
|
return object instanceof SimpleDSColumn;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void setValue(SimpleDSColumn value) {
|
||
|
if (value != null) {
|
||
|
tableDataComboBox.setSelectedTableDataByName(value.getDsName());
|
||
|
columnNameComboBox.setSelectedItem(TableDataColumn.getColumnName(value.getColumn()));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void clearData() {
|
||
|
tableDataComboBox.setSelectedItem(null);
|
||
|
columnNameComboBox.setSelectedItem(null);
|
||
|
}
|
||
|
}
|