2024-10-08 00:39:13 +03:00
|
|
|
|
package Common.Visual;
|
2024-10-07 14:22:52 +03:00
|
|
|
|
import Common.CommonConstants;
|
2024-10-07 00:58:29 +03:00
|
|
|
|
import Common.Database.Objects.DBObject;
|
2024-10-15 23:01:36 +03:00
|
|
|
|
import Common.Database.Objects.Grid.TableVisualData;
|
2024-10-07 00:58:29 +03:00
|
|
|
|
import Common.Database.Tables.DBTable;
|
|
|
|
|
|
import Common.Database.Tables.DataSet;
|
|
|
|
|
|
import Common.Database.Tables.FKBehaviour;
|
2024-10-15 13:35:33 +03:00
|
|
|
|
import Common.MainModule_;
|
2024-10-28 13:14:42 +03:00
|
|
|
|
import Common.Passes.PassCode_;
|
2024-10-22 15:25:06 +03:00
|
|
|
|
import Common.Utils.TextLog;
|
2024-10-14 15:19:13 +03:00
|
|
|
|
import Common.Utils.Utils_;
|
2024-10-17 21:24:55 +03:00
|
|
|
|
import Common.Visual.Menus.DataMenuBar;
|
2024-10-09 20:35:18 +03:00
|
|
|
|
import Common.Visual.Menus.TableMenu;
|
2024-10-17 22:18:10 +03:00
|
|
|
|
import Common.Visual.Tables.*;
|
2024-10-09 20:35:18 +03:00
|
|
|
|
import Common.Visual.Tables.Grid.GridAnchestor;
|
2024-10-22 16:44:13 +03:00
|
|
|
|
import Common.Visual.Windows.Dialog.DBObjectDialog;
|
2023-09-17 22:13:42 +03:00
|
|
|
|
|
|
|
|
|
|
import javax.swing.*;
|
|
|
|
|
|
import javax.swing.table.TableColumn;
|
|
|
|
|
|
import java.awt.*;
|
2024-10-16 21:58:46 +03:00
|
|
|
|
import java.awt.event.KeyAdapter;
|
|
|
|
|
|
import java.awt.event.KeyEvent;
|
2023-09-17 22:13:42 +03:00
|
|
|
|
import java.awt.event.MouseAdapter;
|
|
|
|
|
|
import java.awt.event.MouseEvent;
|
2024-10-26 14:34:55 +03:00
|
|
|
|
import java.util.Collections;
|
2024-10-20 16:19:43 +03:00
|
|
|
|
import java.util.Comparator;
|
2023-09-17 22:13:42 +03:00
|
|
|
|
import java.util.Vector;
|
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import java.util.stream.IntStream;
|
2024-10-26 15:14:23 +03:00
|
|
|
|
public abstract class DataSetControlForm<D extends DBObject> extends ControlForm<DataTable> {
|
2024-10-20 20:51:23 +03:00
|
|
|
|
protected DataSet<?, D> dataSource; //источник данных
|
2024-10-24 23:40:24 +03:00
|
|
|
|
protected D current = null; //заменить все обращения к мейн модулю.
|
2024-10-17 21:24:55 +03:00
|
|
|
|
protected DataMenuBar bar = null; //верхняя панель меню
|
|
|
|
|
|
protected int current_row_i; //индекс текущей строки.
|
2023-09-17 22:13:42 +03:00
|
|
|
|
protected boolean events_on = true;
|
|
|
|
|
|
protected String colNamesAndSizes = "";
|
2024-10-21 15:12:41 +03:00
|
|
|
|
protected Vector<DBObjectFilter_<D>> allFilters = new Vector<>();
|
2024-10-26 14:34:55 +03:00
|
|
|
|
Vector<ColumnInfo<D>> columns = new Vector<>(); //информация о столбцах и их оформлении
|
2024-10-22 01:35:30 +03:00
|
|
|
|
MatchesCounter counter_ui = null;
|
2024-10-17 23:27:47 +03:00
|
|
|
|
//--
|
|
|
|
|
|
Object savedCurrentKey = null;
|
|
|
|
|
|
Vector<Object> savedSelectedKeys = new Vector<>();
|
|
|
|
|
|
//--
|
2024-10-20 17:44:30 +03:00
|
|
|
|
public DataSetControlForm(DataSet<?, D> dataSource_in, JPanel mountPanel_in) {
|
2024-10-17 20:04:16 +03:00
|
|
|
|
super(DataTable.class, mountPanel_in);
|
2023-09-17 22:13:42 +03:00
|
|
|
|
dataSource = dataSource_in;
|
2024-10-26 14:34:55 +03:00
|
|
|
|
//--
|
|
|
|
|
|
columns.clear();
|
|
|
|
|
|
columns.add(createPKColumn());
|
|
|
|
|
|
if (hasCheckBox())
|
|
|
|
|
|
columns.add(createCheckBoxColummn());
|
2024-10-26 15:14:23 +03:00
|
|
|
|
createColumns();
|
2024-10-26 14:34:55 +03:00
|
|
|
|
//--
|
2024-10-20 12:09:59 +03:00
|
|
|
|
createFilters();
|
2024-10-21 13:54:52 +03:00
|
|
|
|
//--
|
2024-10-17 21:24:55 +03:00
|
|
|
|
if (hasMenuBar()) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
if (!MainModule_.instance.getUI().menuBars.containsKey(dataSource.getClass())) {
|
|
|
|
|
|
bar = createMenuBar();
|
|
|
|
|
|
if (hasCheckBox())
|
|
|
|
|
|
bar.createSelectionButtons(dataSource);
|
|
|
|
|
|
MainModule_.instance.getUI().menuBars.put(dataSource.getClass(), bar);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
bar = MainModule_.instance.getUI().menuBars.get(dataSource.getClass());
|
|
|
|
|
|
}
|
|
|
|
|
|
mountPanel.add(bar, BorderLayout.NORTH);
|
|
|
|
|
|
//--
|
2024-10-22 01:35:30 +03:00
|
|
|
|
counter_ui = (count -> bar.countLabel.setText(String.valueOf(count)));
|
|
|
|
|
|
//--фильтры всегда в конец бара.
|
|
|
|
|
|
bar.add(new JSeparator());
|
|
|
|
|
|
for (FilterFlag filter : getFilters(FilterFlag.class)) {
|
|
|
|
|
|
bar.add(filter.getControl());
|
|
|
|
|
|
}
|
2024-10-21 13:54:52 +03:00
|
|
|
|
for (JMenu filter : getFilters(DataSetFiltersMenu.class)) {
|
|
|
|
|
|
bar.addMenus(filter);
|
2024-10-17 21:49:18 +03:00
|
|
|
|
}
|
2024-10-22 01:35:30 +03:00
|
|
|
|
//------------------------
|
2024-10-17 21:24:55 +03:00
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-10-22 13:00:11 +03:00
|
|
|
|
}
|
2024-10-26 15:14:23 +03:00
|
|
|
|
protected boolean isPKVisible() {
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2024-10-26 14:34:55 +03:00
|
|
|
|
protected ColumnInfo<D> createPKColumn() {
|
|
|
|
|
|
return new ColumnInfo<D>(dataSource.getPKName()) {
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public Object getFieldAt(D object) {
|
|
|
|
|
|
return object.getPK();
|
|
|
|
|
|
}
|
2024-10-26 15:14:23 +03:00
|
|
|
|
@Override
|
|
|
|
|
|
public boolean isVisible() {
|
|
|
|
|
|
return isPKVisible();
|
|
|
|
|
|
}
|
2024-10-26 14:34:55 +03:00
|
|
|
|
};
|
|
|
|
|
|
}
|
2024-10-26 15:14:23 +03:00
|
|
|
|
protected boolean hasCheckBox() {
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2024-10-26 14:34:55 +03:00
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
2024-10-22 13:00:11 +03:00
|
|
|
|
<M> Vector<M> getFilters(Class<M> f) {
|
|
|
|
|
|
Vector<M> res = new Vector<>();
|
|
|
|
|
|
for (DBObjectFilter_ filter_ : allFilters) {
|
|
|
|
|
|
//либо М, либо наследует от М
|
|
|
|
|
|
if (filter_.getClass().equals(f) || filter_.getClass().getSuperclass().equals(f)) {
|
|
|
|
|
|
res.add((M) filter_);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return res;
|
|
|
|
|
|
}
|
2024-10-26 15:14:23 +03:00
|
|
|
|
protected final void AddFilters(DBObjectFilter_<D>... new_filters) {
|
2024-10-26 14:42:31 +03:00
|
|
|
|
Collections.addAll(allFilters, new_filters);
|
2023-09-17 22:13:42 +03:00
|
|
|
|
}
|
2024-10-26 14:34:55 +03:00
|
|
|
|
protected final void AddColumns(ColumnInfo<D>... new_columns) {
|
|
|
|
|
|
Collections.addAll(columns, new_columns);
|
|
|
|
|
|
}
|
|
|
|
|
|
public ColumnInfo<D> getColumnInfo(int i) {
|
2024-10-20 17:44:30 +03:00
|
|
|
|
return columns.get(i);
|
|
|
|
|
|
}
|
2024-10-20 22:19:25 +03:00
|
|
|
|
//--
|
2024-10-22 17:27:41 +03:00
|
|
|
|
void SaveColumns() {
|
2024-10-16 00:40:45 +03:00
|
|
|
|
if (MainModule_.instance.getDb() != null) {
|
2023-09-17 22:13:42 +03:00
|
|
|
|
try {
|
2024-10-24 23:40:24 +03:00
|
|
|
|
if (needsCurrent()) {
|
2023-09-17 22:13:42 +03:00
|
|
|
|
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);
|
2024-10-08 00:39:13 +03:00
|
|
|
|
TableVisualData tableVisualData;
|
2024-10-24 23:40:24 +03:00
|
|
|
|
if (MainModule_.instance.getDb().tablesVisualData.containsKey(getCurrentName())) {
|
|
|
|
|
|
tableVisualData = MainModule_.instance.getDb().tablesVisualData.get(getCurrentName());
|
2023-09-17 22:13:42 +03:00
|
|
|
|
} else {
|
2024-10-24 23:40:24 +03:00
|
|
|
|
tableVisualData = new TableVisualData(getCurrentName());
|
2024-10-16 00:40:45 +03:00
|
|
|
|
MainModule_.instance.getDb().Insert(tableVisualData);
|
2023-09-17 22:13:42 +03:00
|
|
|
|
}
|
2024-10-08 00:39:13 +03:00
|
|
|
|
tableVisualData.sizes = packed;
|
2024-10-16 00:40:45 +03:00
|
|
|
|
MainModule_.instance.getDb().Update(tableVisualData);
|
2023-09-17 22:13:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-10-22 17:27:41 +03:00
|
|
|
|
Vector<String> getHeaders() {
|
2023-09-17 22:13:42 +03:00
|
|
|
|
return columns.stream().map(ColumnInfo::getName).collect(Collectors.toCollection(Vector::new));
|
|
|
|
|
|
}
|
2024-10-25 12:53:27 +03:00
|
|
|
|
protected Comparator<D> getDefaultComparator() {
|
2024-10-20 17:54:09 +03:00
|
|
|
|
return null;
|
|
|
|
|
|
}
|
2024-10-20 16:19:43 +03:00
|
|
|
|
Vector<Object> getVisibleKeys() {
|
2024-10-20 17:54:09 +03:00
|
|
|
|
Comparator comparator = getDefaultComparator();
|
|
|
|
|
|
Vector<Object> res_keys = new Vector<>();
|
2024-10-20 16:19:43 +03:00
|
|
|
|
if (comparator == null) {
|
2024-10-20 21:59:39 +03:00
|
|
|
|
for (D object : dataSource.Data.values()) {
|
2024-10-20 20:51:23 +03:00
|
|
|
|
if (isObjectVisible(object))
|
|
|
|
|
|
res_keys.add(object.getPK());
|
|
|
|
|
|
}
|
2024-10-20 16:19:43 +03:00
|
|
|
|
} else {
|
2024-10-20 17:54:09 +03:00
|
|
|
|
Vector<D> raw = new Vector<>();
|
2024-10-20 20:51:23 +03:00
|
|
|
|
for (D object : dataSource.Data.values()) {
|
|
|
|
|
|
if (isObjectVisible(object))
|
|
|
|
|
|
raw.add(object);
|
2024-10-20 16:19:43 +03:00
|
|
|
|
}
|
|
|
|
|
|
raw.sort(comparator);
|
2024-10-20 17:54:09 +03:00
|
|
|
|
for (D object : raw)
|
|
|
|
|
|
res_keys.add(object.getPK());
|
2024-10-20 16:19:43 +03:00
|
|
|
|
}
|
2024-10-20 17:54:09 +03:00
|
|
|
|
return res_keys;
|
2024-10-20 16:19:43 +03:00
|
|
|
|
}
|
2023-09-17 22:13:42 +03:00
|
|
|
|
@Override
|
2024-10-17 20:04:16 +03:00
|
|
|
|
protected void createControl() {
|
2024-10-20 16:19:43 +03:00
|
|
|
|
GridAnchestor table_data_model = new GridAnchestor(getHeaders(), getVisibleKeys()) {
|
2023-09-17 22:13:42 +03:00
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public Object getValueAt(int rowIndex, int columnIndex) {
|
|
|
|
|
|
Object key = data.get(rowIndex);
|
2024-10-20 21:59:39 +03:00
|
|
|
|
D object = dataSource.get((key));
|
2024-10-26 14:34:55 +03:00
|
|
|
|
return columns.get(columnIndex).getFieldAt(object);
|
2023-09-17 22:13:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public boolean isCellEditable(int row, int col) {
|
|
|
|
|
|
return columns.get(col).isEditable();
|
|
|
|
|
|
}
|
|
|
|
|
|
//------------------------------------------------------------------------------------
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void setValueAt(Object value, int row, int col) {
|
|
|
|
|
|
fireTableCellUpdated(row, col);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
control = new DataTable(table_data_model) {
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public TableMenu CreateMenu() {
|
|
|
|
|
|
return new TableMenu(this);
|
|
|
|
|
|
}
|
|
|
|
|
|
//строго говоря эта штука нужна только для рендереров и едиторов клеток.
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public DBObject getRowObject(int rowIndex) {
|
|
|
|
|
|
//вот так делать НЕЛЬЗЯ. модель только для внутреннего пользования
|
|
|
|
|
|
// Object key = table_data_model.data.get(rowIndex);
|
|
|
|
|
|
//из таблицы можно пользоваться только getValueAt
|
|
|
|
|
|
//иначе сортировка не будет работать.
|
|
|
|
|
|
Object key = getValueAt(rowIndex, 0);
|
2024-10-17 17:37:59 +03:00
|
|
|
|
return dataSource.get(key);
|
2023-09-17 22:13:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
//-----------------------------NEW-------------------------------------
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void CorrectColumnsSizes() {
|
2024-10-16 00:40:45 +03:00
|
|
|
|
if ((MainModule_.instance.getDb() != null)
|
2024-10-24 23:40:24 +03:00
|
|
|
|
&& needsCurrent()
|
|
|
|
|
|
&& MainModule_.instance.getDb().tablesVisualData.containsKey(getCurrentName())) {
|
2023-09-17 22:13:42 +03:00
|
|
|
|
if (!getColumnsProfile().equalsIgnoreCase(colNamesAndSizes)) {
|
2024-10-24 23:40:24 +03:00
|
|
|
|
TableVisualData grid = MainModule_.instance.getDb().tablesVisualData.get(getCurrentName());
|
2023-09-17 22:13:42 +03:00
|
|
|
|
String[] data = grid.sizes.split("\\|");
|
|
|
|
|
|
for (int i = 0; i < columns.size(); ++i) {
|
|
|
|
|
|
if (i <= (data.length - 1)) {
|
|
|
|
|
|
int width = Integer.parseInt(data[i]);
|
|
|
|
|
|
getColumnModel().getColumn(i).setPreferredWidth(width);
|
|
|
|
|
|
getColumnModel().getColumn(i).setWidth(width);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
} else
|
|
|
|
|
|
super.CorrectColumnsSizes(); //обычный авторазмер.
|
|
|
|
|
|
}
|
|
|
|
|
|
public String getColumnsProfile() {
|
|
|
|
|
|
String res = "";
|
|
|
|
|
|
for (int i = 0; i < getColumnModel().getColumnCount(); i++) {
|
|
|
|
|
|
if (i > 0) res += ",";
|
|
|
|
|
|
TableColumn column = getColumnModel().getColumn(i);
|
|
|
|
|
|
res += column.getHeaderValue();
|
|
|
|
|
|
res += ":";
|
|
|
|
|
|
res += column.getWidth();
|
|
|
|
|
|
}
|
|
|
|
|
|
return res;
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void Init() {
|
|
|
|
|
|
for (int i = 0; i < columns.size(); i++) {
|
|
|
|
|
|
ColumnInfo columnInfo = columns.get(i);
|
|
|
|
|
|
if (columnInfo.isVisible()) {
|
|
|
|
|
|
if (columnInfo.hasRenderer())
|
2024-10-15 15:13:57 +03:00
|
|
|
|
getColumnModel().getColumn(i).setCellRenderer(MainModule_.instance.getUI().getTableRenderer(columnInfo.getRendererClass()));
|
2023-09-17 22:13:42 +03:00
|
|
|
|
if (columnInfo.hasEditor())
|
2024-10-15 15:13:57 +03:00
|
|
|
|
getColumnModel().getColumn(i).setCellEditor(MainModule_.instance.getUI().getTableEditor(columnInfo.getEditorClass()));
|
2023-09-17 22:13:42 +03:00
|
|
|
|
if (columnInfo.hasMaxWidth())
|
|
|
|
|
|
getColumnModel().getColumn((i)).setMaxWidth(columnInfo.getMaxWidth());
|
|
|
|
|
|
if (columnInfo.hasMinWidth())
|
|
|
|
|
|
getColumnModel().getColumn((i)).setMinWidth(columnInfo.getMinWidth());
|
|
|
|
|
|
} else {
|
|
|
|
|
|
getColumnModel().getColumn(i).setMinWidth(0);
|
|
|
|
|
|
getColumnModel().getColumn(i).setMaxWidth(0);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//обновление в БД при ручном изменении размера столбиков.--------->>
|
|
|
|
|
|
getTableHeader().addMouseListener(new MouseAdapter() {
|
|
|
|
|
|
public void mouseReleased(MouseEvent arg0) {
|
|
|
|
|
|
String new_colNamesAndSizes = getColumnsProfile();
|
|
|
|
|
|
// check if changed, if yes, persist...
|
|
|
|
|
|
if (!colNamesAndSizes.equals(new_colNamesAndSizes)) {
|
|
|
|
|
|
colNamesAndSizes = new_colNamesAndSizes;
|
|
|
|
|
|
SaveColumns();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
//------------------------->>
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
2024-10-24 23:40:24 +03:00
|
|
|
|
if (needsCurrent()) {
|
2024-10-07 14:22:52 +03:00
|
|
|
|
current_row_i = CommonConstants.Nan;
|
2023-09-17 22:13:42 +03:00
|
|
|
|
ListSelectionModel selModel = control.getSelectionModel();
|
|
|
|
|
|
selModel.addListSelectionListener(e -> {
|
|
|
|
|
|
int row = control.getSelectedRow();
|
|
|
|
|
|
if ((row >= 0)) {
|
|
|
|
|
|
if (row != current_row_i) {
|
|
|
|
|
|
current_row_i = row;
|
2024-10-24 23:40:24 +03:00
|
|
|
|
setCurrent((D) control.getRowObject(row));
|
2023-09-17 22:13:42 +03:00
|
|
|
|
if (events_on) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
ShowCurrentObject();
|
|
|
|
|
|
} catch (Exception ex) {
|
2024-10-11 00:00:30 +03:00
|
|
|
|
Utils_.MainLog.PrintException(ex);
|
2023-09-17 22:13:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
2024-10-07 14:22:52 +03:00
|
|
|
|
current_row_i = CommonConstants.Nan;
|
2024-10-22 15:25:06 +03:00
|
|
|
|
dropCurrent();
|
2023-09-17 22:13:42 +03:00
|
|
|
|
if (events_on) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
ShowNoCurrentObject();
|
|
|
|
|
|
} catch (Exception ex) {
|
2024-10-11 00:00:30 +03:00
|
|
|
|
Utils_.MainLog.PrintException(ex);
|
2023-09-17 22:13:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
//двойной клик мыши.------------------------------------------------------
|
|
|
|
|
|
control.addMouseListener(new MouseAdapter() {
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void mouseClicked(MouseEvent e) {
|
2024-10-22 15:25:06 +03:00
|
|
|
|
if ((e.getClickCount() == 2) && (getCurrent() != null)) {
|
2023-09-17 22:13:42 +03:00
|
|
|
|
try {
|
|
|
|
|
|
MouseAction2();
|
|
|
|
|
|
} catch (Exception ex) {
|
2024-10-11 00:00:30 +03:00
|
|
|
|
Utils_.MainLog.PrintException(ex);
|
2023-09-17 22:13:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2024-10-16 21:58:46 +03:00
|
|
|
|
control.addKeyListener(new KeyAdapter() {
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void keyPressed(KeyEvent e) {
|
|
|
|
|
|
switch (e.getKeyCode()) {
|
|
|
|
|
|
case KeyEvent.VK_DELETE:
|
2024-10-28 13:14:42 +03:00
|
|
|
|
if (getDeletePassCode() != null) {
|
|
|
|
|
|
MainModule_.instance.getPass(getDeletePassCode()).Do();
|
2024-10-16 21:58:46 +03:00
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
case KeyEvent.VK_ENTER:
|
|
|
|
|
|
try {
|
|
|
|
|
|
MouseAction2();
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
|
Utils_.MainLog.PrintException(ex);
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
);
|
2023-09-17 22:13:42 +03:00
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
//при переотображении таблицы скидываем текущий объект!!
|
2024-10-22 15:25:06 +03:00
|
|
|
|
dropCurrent();
|
2023-09-17 22:13:42 +03:00
|
|
|
|
try {
|
|
|
|
|
|
ShowNoCurrentObject();
|
|
|
|
|
|
} catch (Exception e) {
|
2024-10-11 00:00:30 +03:00
|
|
|
|
Utils_.MainLog.PrintException(e);
|
2023-09-17 22:13:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-10-21 13:54:52 +03:00
|
|
|
|
for (HeaderTextFilter filter : getFilters(HeaderTextFilter.class))
|
2024-10-20 12:09:59 +03:00
|
|
|
|
filter.Mount(getControl());
|
2023-09-17 22:13:42 +03:00
|
|
|
|
}
|
2024-10-17 21:24:55 +03:00
|
|
|
|
protected DataMenuBar createMenuBar() {
|
2024-10-22 19:17:01 +03:00
|
|
|
|
return new DataMenuBar(dataSource.getPluralDescription());
|
2024-10-17 21:24:55 +03:00
|
|
|
|
}
|
2024-10-17 22:18:10 +03:00
|
|
|
|
protected void createFilters() {
|
|
|
|
|
|
}
|
2024-10-26 15:14:23 +03:00
|
|
|
|
protected abstract void createColumns();
|
2024-10-22 17:27:41 +03:00
|
|
|
|
boolean ApplyFilters(D object) {
|
2024-10-22 13:00:11 +03:00
|
|
|
|
for (DBObjectFilter_ filterInterface : allFilters) {
|
2024-10-22 13:06:47 +03:00
|
|
|
|
if (!filterInterface.Validate(object))
|
2024-10-20 22:19:25 +03:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2023-09-17 22:13:42 +03:00
|
|
|
|
@Override
|
2024-10-17 20:04:16 +03:00
|
|
|
|
protected void redrawControl() {
|
2023-09-17 22:13:42 +03:00
|
|
|
|
control.CorrectSizes();
|
|
|
|
|
|
}
|
2024-10-22 17:27:41 +03:00
|
|
|
|
protected void ShowCurrentObject() throws Exception {
|
2023-09-17 22:13:42 +03:00
|
|
|
|
if (dataSource instanceof DBTable) {
|
|
|
|
|
|
DBTable table = (DBTable) dataSource;
|
|
|
|
|
|
for (Class dep : table.getFKDependencies().keySet()) {
|
|
|
|
|
|
FKBehaviour behaviour = table.getFKDependencies().get(dep);
|
|
|
|
|
|
switch (behaviour.ui) {
|
|
|
|
|
|
case ACTIVE:
|
2024-10-17 17:22:33 +03:00
|
|
|
|
table.getDb().getTable(dep).ShowUI();
|
2023-09-17 22:13:42 +03:00
|
|
|
|
break;
|
|
|
|
|
|
case PASSIVE:
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-10-22 17:27:41 +03:00
|
|
|
|
protected void ShowNoCurrentObject() throws Exception {
|
2023-09-17 22:13:42 +03:00
|
|
|
|
if (dataSource instanceof DBTable) {
|
|
|
|
|
|
DBTable table = (DBTable) dataSource;
|
|
|
|
|
|
for (Class dep : table.getFKDependencies().keySet()) {
|
|
|
|
|
|
FKBehaviour behaviour = table.getFKDependencies().get(dep);
|
|
|
|
|
|
switch (behaviour.ui) {
|
|
|
|
|
|
case ACTIVE:
|
2024-10-17 17:22:33 +03:00
|
|
|
|
table.getDb().getTable(dep).ClearUI();
|
2023-09-17 22:13:42 +03:00
|
|
|
|
break;
|
|
|
|
|
|
case PASSIVE:
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-10-22 17:27:41 +03:00
|
|
|
|
protected void MouseAction2() throws Exception {
|
2024-10-17 21:24:55 +03:00
|
|
|
|
}
|
|
|
|
|
|
//-
|
2024-10-22 17:27:41 +03:00
|
|
|
|
protected boolean hasMenuBar() {
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2024-10-24 23:40:24 +03:00
|
|
|
|
public void dropCurrent() {
|
|
|
|
|
|
current = null;
|
2024-10-22 17:27:41 +03:00
|
|
|
|
}
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
|
|
protected DBObjectDialog getDialog() {
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
protected boolean isObjectEditable(D object) {
|
2024-10-17 21:24:55 +03:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2024-10-22 17:27:41 +03:00
|
|
|
|
//БАЗОВЫЙ ФУНКЦИОНАЛ ФОРМЫ
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void Show() {
|
|
|
|
|
|
for (DBObjectFilter_ filter_ : allFilters) filter_.DropMatchesCount();
|
|
|
|
|
|
super.Show();
|
|
|
|
|
|
if (counter_ui != null) counter_ui.ShowMatchesCount(getRowCount());
|
|
|
|
|
|
for (DBObjectFilter_ filter_ : allFilters) filter_.ShowMatchesCount();
|
|
|
|
|
|
}
|
|
|
|
|
|
public void Show(Object pk) {
|
|
|
|
|
|
Show();
|
|
|
|
|
|
SetCurrentByPK(pk);
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void Clear() {
|
|
|
|
|
|
super.Clear();
|
|
|
|
|
|
if (counter_ui != null) counter_ui.ShowNoMatches();
|
|
|
|
|
|
}
|
|
|
|
|
|
public int getRowCount() {
|
|
|
|
|
|
return control.getRowCount();
|
|
|
|
|
|
}
|
|
|
|
|
|
//ТЕКУЩИЕ И ВЫБРАННЫЕ ОБЪЕКТЫ
|
2024-10-17 23:27:47 +03:00
|
|
|
|
public void SaveLastCurrent() {
|
|
|
|
|
|
savedCurrentKey = null;
|
|
|
|
|
|
savedSelectedKeys.clear();
|
2024-10-24 23:40:24 +03:00
|
|
|
|
if (needsCurrent() && (getCurrent() != null)) {
|
2024-10-22 15:25:06 +03:00
|
|
|
|
savedCurrentKey = getCurrent().getPK();
|
2024-10-17 23:27:47 +03:00
|
|
|
|
}
|
2024-10-22 15:25:06 +03:00
|
|
|
|
savedSelectedKeys = getSelectedKeys();
|
2024-10-17 23:27:47 +03:00
|
|
|
|
}
|
|
|
|
|
|
public void RestoreLastCurrent() {
|
2024-10-20 12:09:59 +03:00
|
|
|
|
for (Object key : savedSelectedKeys) {
|
2024-10-17 23:27:47 +03:00
|
|
|
|
if (dataSource.containsKey(key))
|
|
|
|
|
|
dataSource.get(key).Select(true);
|
|
|
|
|
|
}
|
2024-10-20 12:09:59 +03:00
|
|
|
|
if ((savedCurrentKey != null) && (dataSource.containsKey(savedCurrentKey))) {
|
2024-10-17 23:27:47 +03:00
|
|
|
|
SetCurrentByPK(savedCurrentKey);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-10-22 17:27:41 +03:00
|
|
|
|
public boolean isObjectVisible(D object) {
|
|
|
|
|
|
return ApplyFilters(object);
|
|
|
|
|
|
}
|
2024-10-22 15:25:06 +03:00
|
|
|
|
public int getSelectedCount() {
|
|
|
|
|
|
return (int) dataSource.Data.values().stream().filter(d -> isObjectVisible(d) && d.isSelected()).count();
|
|
|
|
|
|
}
|
|
|
|
|
|
public Vector<D> getSelectedItems() {
|
|
|
|
|
|
return dataSource.Data.values().stream().filter(d -> isObjectVisible(d) && d.isSelected()).collect(Collectors.toCollection(Vector::new));
|
|
|
|
|
|
}
|
|
|
|
|
|
public Vector<Object> getSelectedKeys() {
|
|
|
|
|
|
return dataSource.Data.values().stream().filter(DBObject::isSelected).map(d -> d.getPK()).collect(Collectors.toCollection(Vector::new));
|
|
|
|
|
|
}
|
2024-10-25 00:50:19 +03:00
|
|
|
|
public boolean CheckCurrent(TextLog log) {
|
2024-10-24 23:40:24 +03:00
|
|
|
|
if (current == null) {
|
|
|
|
|
|
log.Writeln_(dataSource.getSingleDescription() + " не выбран(а)");
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
public boolean matchCurrentID(int id_in) {
|
|
|
|
|
|
return (current != null) && (((int) current.getPK()) == id_in);
|
2024-10-22 15:25:06 +03:00
|
|
|
|
}
|
|
|
|
|
|
public boolean CheckSelectedOrCurrent(TextLog log) {
|
2024-10-24 23:40:24 +03:00
|
|
|
|
if ((getSelectedCount() == 0) && (!needsCurrent() || (getCurrent() == null))) {
|
2024-10-22 19:17:01 +03:00
|
|
|
|
log.Writeln_(dataSource.getPluralDescription() + ":");
|
2024-10-22 15:25:06 +03:00
|
|
|
|
log.Writeln_("Отсутствуют отмеченные объекты, или текущий объект!");
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2024-10-24 23:40:24 +03:00
|
|
|
|
protected boolean needsCurrent() {
|
2024-10-25 02:08:23 +03:00
|
|
|
|
return true;
|
2024-10-24 23:40:24 +03:00
|
|
|
|
} //нужно ли отслеживать текущий объект.
|
|
|
|
|
|
protected String getCurrentName() {
|
|
|
|
|
|
return dataSource.d.getSimpleName();
|
|
|
|
|
|
}
|
2024-10-22 15:25:06 +03:00
|
|
|
|
public D getCurrent() {
|
2024-10-24 23:40:24 +03:00
|
|
|
|
return current;
|
|
|
|
|
|
}
|
|
|
|
|
|
public D setCurrent(D object) {
|
|
|
|
|
|
return current = object;
|
2024-10-22 15:25:06 +03:00
|
|
|
|
}
|
|
|
|
|
|
public Vector<D> getSelectedOrCurrent() {
|
|
|
|
|
|
Vector<D> res = new Vector<>();
|
|
|
|
|
|
if (getSelectedCount() > 0)
|
|
|
|
|
|
res = getSelectedItems();
|
|
|
|
|
|
else {
|
2024-10-24 23:40:24 +03:00
|
|
|
|
if (needsCurrent() && (getCurrent() != null)) {
|
2024-10-22 15:25:06 +03:00
|
|
|
|
res.add(getCurrent());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return res;
|
|
|
|
|
|
}
|
|
|
|
|
|
public Vector<Object> getSelectedOrCurrentKeys() {
|
|
|
|
|
|
Vector<Object> res = new Vector<>();
|
|
|
|
|
|
if (getSelectedCount() > 0)
|
|
|
|
|
|
res = getSelectedKeys();
|
|
|
|
|
|
else {
|
2024-10-24 23:40:24 +03:00
|
|
|
|
if (needsCurrent() && (getCurrent() != null)) {
|
2024-10-22 15:25:06 +03:00
|
|
|
|
res.add(getCurrent().getPK());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return res;
|
|
|
|
|
|
}
|
2024-10-22 17:27:41 +03:00
|
|
|
|
public void SetCurrentByPK(Object pk) {
|
|
|
|
|
|
if (isShown())
|
|
|
|
|
|
control.SelectRowByPK(pk);
|
|
|
|
|
|
}
|
|
|
|
|
|
public void ClearSelection() {
|
|
|
|
|
|
if (isShown()) control.clearSelection(); //строка сбросится сама. благодаря сбросу события выбора
|
2024-10-22 16:44:13 +03:00
|
|
|
|
}
|
2024-10-22 17:27:41 +03:00
|
|
|
|
public void SelectAll(boolean flag) {
|
|
|
|
|
|
for (D object : dataSource.Data.values()) {
|
|
|
|
|
|
if (isObjectVisible(object))
|
|
|
|
|
|
object.Select(flag);
|
|
|
|
|
|
}
|
2024-10-24 23:40:24 +03:00
|
|
|
|
RedrawControl();
|
2024-10-22 17:27:41 +03:00
|
|
|
|
}
|
|
|
|
|
|
//ДИАЛОГИ
|
2024-10-22 16:44:13 +03:00
|
|
|
|
public boolean ShowAddObjectDialog(D object) {
|
2024-10-22 19:17:01 +03:00
|
|
|
|
return getDialog().ShowDialog(dataSource.getSingleDescription() + ": добавление", object);
|
2024-10-22 16:44:13 +03:00
|
|
|
|
}
|
|
|
|
|
|
public boolean ShowEditObjectDialog(D object) {
|
|
|
|
|
|
DBObjectDialog dialog = getDialog();
|
|
|
|
|
|
dialog.edit = true;
|
|
|
|
|
|
dialog.SetEditLimits();
|
2024-10-22 19:17:01 +03:00
|
|
|
|
String title = dataSource.getSingleDescription() + ": ";
|
2024-10-22 17:27:41 +03:00
|
|
|
|
if (isObjectEditable(object)) {
|
|
|
|
|
|
title += "редактирование";
|
|
|
|
|
|
} else {
|
|
|
|
|
|
title += "просмотр";
|
|
|
|
|
|
dialog.SetReadonly();
|
|
|
|
|
|
}
|
|
|
|
|
|
return dialog.ShowDialog(title, object);
|
2024-10-22 16:44:13 +03:00
|
|
|
|
}
|
|
|
|
|
|
public boolean ShowDeleteObjectDialog(D object) {
|
2024-10-22 19:17:01 +03:00
|
|
|
|
return UI.Warning(dataSource.getSingleDescription() + " " + object.getBDialogName() + " будет удален(а)");
|
2024-10-22 16:44:13 +03:00
|
|
|
|
}
|
|
|
|
|
|
public boolean ShowDeleteObjectsDialog(int toDeleteCount) {
|
2024-10-22 19:17:01 +03:00
|
|
|
|
return UI.Warning(dataSource.getPluralDescription() + " в количестве " + toDeleteCount + " будут удалены)");
|
2024-10-22 16:44:13 +03:00
|
|
|
|
}
|
2024-10-28 13:14:42 +03:00
|
|
|
|
public PassCode_ getDeletePassCode() {
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
2024-11-17 16:24:47 +03:00
|
|
|
|
public Object getCurrentPK(Object nanValue){
|
|
|
|
|
|
return current==null? nanValue: current.getPK();
|
|
|
|
|
|
}
|
2023-09-17 22:13:42 +03:00
|
|
|
|
}
|