рефакторинг форм таблиц и заполнения информации о столбцах
This commit is contained in:
@@ -21,7 +21,7 @@ import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Vector;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -33,8 +33,8 @@ public class DataSetControlForm<D extends DBObject> extends ControlForm<DataTabl
|
||||
protected int current_row_i; //индекс текущей строки.
|
||||
protected boolean events_on = true;
|
||||
protected String colNamesAndSizes = "";
|
||||
protected Vector<ColumnInfo> columns = new Vector<>(); //информация о столбцах и их оформлении
|
||||
protected Vector<DBObjectFilter_<D>> allFilters = new Vector<>();
|
||||
Vector<ColumnInfo<D>> columns = new Vector<>(); //информация о столбцах и их оформлении
|
||||
MatchesCounter counter_ui = null;
|
||||
//--
|
||||
Object savedCurrentKey = null;
|
||||
@@ -43,6 +43,12 @@ public class DataSetControlForm<D extends DBObject> extends ControlForm<DataTabl
|
||||
public DataSetControlForm(DataSet<?, D> dataSource_in, JPanel mountPanel_in) {
|
||||
super(DataTable.class, mountPanel_in);
|
||||
dataSource = dataSource_in;
|
||||
//--
|
||||
columns.clear();
|
||||
columns.add(createPKColumn());
|
||||
if (hasCheckBox())
|
||||
columns.add(createCheckBoxColummn());
|
||||
//--
|
||||
createFilters();
|
||||
//--
|
||||
if (hasMenuBar()) {
|
||||
@@ -72,6 +78,38 @@ public class DataSetControlForm<D extends DBObject> extends ControlForm<DataTabl
|
||||
}
|
||||
}
|
||||
}
|
||||
protected ColumnInfo<D> createPKColumn() {
|
||||
return new ColumnInfo<D>(dataSource.getPKName()) {
|
||||
@Override
|
||||
public Object getFieldAt(D object) {
|
||||
return object.getPK();
|
||||
}
|
||||
};
|
||||
}
|
||||
protected ColumnInfo<D> createCheckBoxColummn() {
|
||||
return new ColumnInfo<D>("") {
|
||||
@Override
|
||||
public Object getFieldAt(D object) {
|
||||
return object.isSelected();
|
||||
}
|
||||
@Override
|
||||
public int getMinWidth() {
|
||||
return 25;
|
||||
}
|
||||
@Override
|
||||
public int getMaxWidth() {
|
||||
return 25;
|
||||
}
|
||||
@Override
|
||||
public Class getRendererClass() {
|
||||
return DBObjectSelectionRenderer.class;
|
||||
}
|
||||
@Override
|
||||
public Class getEditorClass() {
|
||||
return DBObjectSelector.class;
|
||||
}
|
||||
};
|
||||
}
|
||||
<M> Vector<M> getFilters(Class<M> f) {
|
||||
Vector<M> res = new Vector<>();
|
||||
for (DBObjectFilter_ filter_ : allFilters) {
|
||||
@@ -85,17 +123,13 @@ public class DataSetControlForm<D extends DBObject> extends ControlForm<DataTabl
|
||||
protected void AddFilter(DBObjectFilter_<D> filter_in) {
|
||||
allFilters.add(filter_in);
|
||||
}
|
||||
public ColumnInfo getColumnInfo(int i) {
|
||||
protected final void AddColumns(ColumnInfo<D>... new_columns) {
|
||||
Collections.addAll(columns, new_columns);
|
||||
}
|
||||
public ColumnInfo<D> getColumnInfo(int i) {
|
||||
return columns.get(i);
|
||||
}
|
||||
//--
|
||||
protected String[] getUIColumnNames() {
|
||||
return new String[]{};
|
||||
}
|
||||
public Object getFieldAt(D object, int columnIndex) {
|
||||
return null;
|
||||
}
|
||||
//-
|
||||
void SaveColumns() {
|
||||
if (MainModule_.instance.getDb() != null) {
|
||||
try {
|
||||
@@ -103,7 +137,6 @@ public class DataSetControlForm<D extends DBObject> extends ControlForm<DataTabl
|
||||
Vector<String> widths = IntStream.range(0, columns.size()).mapToObj(i -> String.valueOf(control.getColumnModel().getColumn(i).getWidth())).collect(Collectors.toCollection(Vector::new));
|
||||
String packed = String.join("|", widths);
|
||||
TableVisualData tableVisualData;
|
||||
//todo метод сохрания к бд отнести, как с окнами и проходами. (?)
|
||||
if (MainModule_.instance.getDb().tablesVisualData.containsKey(getCurrentName())) {
|
||||
tableVisualData = MainModule_.instance.getDb().tablesVisualData.get(getCurrentName());
|
||||
} else {
|
||||
@@ -121,20 +154,6 @@ public class DataSetControlForm<D extends DBObject> extends ControlForm<DataTabl
|
||||
Vector<String> getHeaders() {
|
||||
return columns.stream().map(ColumnInfo::getName).collect(Collectors.toCollection(Vector::new));
|
||||
}
|
||||
void CreateColumnsInfo() {
|
||||
columns.clear();
|
||||
columns.add(new ColumnInfo(dataSource.getPKName()));
|
||||
if (hasCheckBox()) {
|
||||
columns.add(new ColumnInfo("", DBObjectSelectionRenderer.class, DBObjectSelector.class));
|
||||
columns.get(1).setMinWidth(25);
|
||||
columns.get(1).setMaxWidth(25);
|
||||
}
|
||||
Arrays.stream(getUIColumnNames()).forEach(name -> columns.add(new ColumnInfo(name)));
|
||||
AdditionalInitColumns();
|
||||
}
|
||||
protected void AdditionalInitColumns() {
|
||||
//уточнение инфы по столбцам.
|
||||
}
|
||||
protected Comparator<D> getDefaultComparator() {
|
||||
return null;
|
||||
}
|
||||
@@ -160,18 +179,13 @@ public class DataSetControlForm<D extends DBObject> extends ControlForm<DataTabl
|
||||
}
|
||||
@Override
|
||||
protected void createControl() {
|
||||
CreateColumnsInfo();
|
||||
GridAnchestor table_data_model = new GridAnchestor(getHeaders(), getVisibleKeys()) {
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Object getValueAt(int rowIndex, int columnIndex) {
|
||||
Object key = data.get(rowIndex);
|
||||
if (columnIndex == 0)
|
||||
return key;
|
||||
D object = dataSource.get((key));
|
||||
if ((columnIndex == 1) && hasCheckBox())
|
||||
return object.isSelected();
|
||||
return getFieldAt(object, columnIndex);
|
||||
return columns.get(columnIndex).getFieldAt(object);
|
||||
}
|
||||
@Override
|
||||
public boolean isCellEditable(int row, int col) {
|
||||
|
||||
Reference in New Issue
Block a user