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.
78 lines
2.2 KiB
78 lines
2.2 KiB
6 years ago
|
package com.fanruan.api.design.ui.editor;
|
||
|
|
||
|
import com.fanruan.api.design.DesignKit;
|
||
|
import com.fanruan.api.util.ArrayKit;
|
||
|
import com.fanruan.api.util.StringKit;
|
||
|
import com.fr.design.gui.icombobox.UIComboBoxRenderer;
|
||
|
|
||
|
import javax.swing.*;
|
||
|
import java.awt.*;
|
||
|
|
||
|
/**
|
||
|
* @author richie
|
||
|
* @version 10.0
|
||
|
* Created by richie on 2019/11/1
|
||
|
* 列编辑器,里面是数据集的列名
|
||
|
*/
|
||
|
public class TypeColumnNameEditor extends TypeColumnIndexEditor {
|
||
|
|
||
|
private String[] columnNames;
|
||
|
|
||
|
public TypeColumnNameEditor() {
|
||
|
this(ArrayKit.EMPTY_STRING_ARRAY);
|
||
|
}
|
||
|
|
||
|
public TypeColumnNameEditor(String[] columnNames) {
|
||
|
this(columnNames, DesignKit.i18nText("Fine-Design_Basic_Column_Name"));
|
||
|
}
|
||
|
|
||
|
public TypeColumnNameEditor(final String[] columnNames, String name) {
|
||
|
super(columnNames.length, name);
|
||
|
this.columnNames = columnNames;
|
||
|
valueColumnIndexComboBox.setRenderer(new UIComboBoxRenderer() {
|
||
|
@Override
|
||
|
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
|
||
|
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
|
||
|
|
||
|
if (value == null) {
|
||
|
this.setText("");
|
||
|
} else {
|
||
|
this.setText(columnNames[((Integer) value).intValue() - 1]);
|
||
|
}
|
||
|
|
||
|
return this;
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void setValue(Object value) {
|
||
|
for (int i = 0; i < columnNames.length; i++) {
|
||
|
if (columnNames[i].equalsIgnoreCase(String.valueOf(value))) {
|
||
|
super.setValue(i + 1);
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
super.reset();
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public boolean accept(Object object) {
|
||
|
return object instanceof String;
|
||
|
}
|
||
|
|
||
|
public String getColumnName() {
|
||
|
int index = this.getValue() - 1;
|
||
|
return getColumnNameAtIndex(index);
|
||
|
}
|
||
|
|
||
|
public String getColumnNameAtIndex(int index) {
|
||
|
return index >= 0 && columnNames.length > index ? columnNames[index] : StringKit.EMPTY;
|
||
|
}
|
||
|
|
||
|
public String getIconName() {
|
||
|
return "ds_column_name";
|
||
|
}
|
||
|
|
||
|
}
|