постепенное выведение старой концепции текущих объектов, касаемо табличных лучше держать их в интерфейсе таблиц, чтобы не писать описание объекта дважды и не мучиться с типом. некоторые фиксы

This commit is contained in:
2024-10-24 23:40:24 +03:00
parent f811d9b3ac
commit 36c11ac93f
153 changed files with 765 additions and 739 deletions

View File

@@ -1,6 +1,5 @@
package Common.Visual;
import Common.CommonConstants;
import Common.Current_;
import Common.Database.Objects.DBObject;
import Common.Database.Objects.Grid.TableVisualData;
import Common.Database.Tables.DBTable;
@@ -29,6 +28,7 @@ import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class DataSetControlForm<D extends DBObject> extends ControlForm<DataTable> {
protected DataSet<?, D> dataSource; //источник данных
protected D current = null; //заменить все обращения к мейн модулю.
protected DataMenuBar bar = null; //верхняя панель меню
protected int current_row_i; //индекс текущей строки.
protected boolean events_on = true;
@@ -99,15 +99,15 @@ public class DataSetControlForm<D extends DBObject> extends ControlForm<DataTabl
void SaveColumns() {
if (MainModule_.instance.getDb() != null) {
try {
if (CurrentName() != null) {
String tableName = CurrentName().toString();
if (needsCurrent()) {
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;
if (MainModule_.instance.getDb().tablesVisualData.containsKey(tableName)) {
tableVisualData = MainModule_.instance.getDb().tablesVisualData.get(tableName);
//todo метод сохрания к бд отнести, как с окнами и проходами. (?)
if (MainModule_.instance.getDb().tablesVisualData.containsKey(getCurrentName())) {
tableVisualData = MainModule_.instance.getDb().tablesVisualData.get(getCurrentName());
} else {
tableVisualData = new TableVisualData(tableName);
tableVisualData = new TableVisualData(getCurrentName());
MainModule_.instance.getDb().Insert(tableVisualData);
}
tableVisualData.sizes = packed;
@@ -202,10 +202,10 @@ public class DataSetControlForm<D extends DBObject> extends ControlForm<DataTabl
@Override
public void CorrectColumnsSizes() {
if ((MainModule_.instance.getDb() != null)
&& CurrentName() != null
&& MainModule_.instance.getDb().tablesVisualData.containsKey(CurrentName().toString())) {
&& needsCurrent()
&& MainModule_.instance.getDb().tablesVisualData.containsKey(getCurrentName())) {
if (!getColumnsProfile().equalsIgnoreCase(colNamesAndSizes)) {
TableVisualData grid = MainModule_.instance.getDb().tablesVisualData.get(CurrentName().toString());
TableVisualData grid = MainModule_.instance.getDb().tablesVisualData.get(getCurrentName());
String[] data = grid.sizes.split("\\|");
for (int i = 0; i < columns.size(); ++i) {
if (i <= (data.length - 1)) {
@@ -261,7 +261,7 @@ public class DataSetControlForm<D extends DBObject> extends ControlForm<DataTabl
//------------------------->>
}
};
if (CurrentName() != null) {
if (needsCurrent()) {
current_row_i = CommonConstants.Nan;
ListSelectionModel selModel = control.getSelectionModel();
selModel.addListSelectionListener(e -> {
@@ -269,7 +269,7 @@ public class DataSetControlForm<D extends DBObject> extends ControlForm<DataTabl
if ((row >= 0)) {
if (row != current_row_i) {
current_row_i = row;
MainModule_.instance.set(CurrentName(), control.getRowObject(row));
setCurrent((D) control.getRowObject(row));
if (events_on) {
try {
ShowCurrentObject();
@@ -390,12 +390,8 @@ public class DataSetControlForm<D extends DBObject> extends ControlForm<DataTabl
protected boolean hasMenuBar() {
return true;
}
//-
protected Current_ CurrentName() {
return null;
}
void dropCurrent() {
MainModule_.instance.set(CurrentName(), null);
public void dropCurrent() {
current = null;
}
@SuppressWarnings("unchecked")
protected DBObjectDialog getDialog() {
@@ -428,7 +424,7 @@ public class DataSetControlForm<D extends DBObject> extends ControlForm<DataTabl
public void SaveLastCurrent() {
savedCurrentKey = null;
savedSelectedKeys.clear();
if ((CurrentName() != null) && (getCurrent() != null)) {
if (needsCurrent() && (getCurrent() != null)) {
savedCurrentKey = getCurrent().getPK();
}
savedSelectedKeys = getSelectedKeys();
@@ -454,26 +450,43 @@ public class DataSetControlForm<D extends DBObject> extends ControlForm<DataTabl
public Vector<Object> getSelectedKeys() {
return dataSource.Data.values().stream().filter(DBObject::isSelected).map(d -> d.getPK()).collect(Collectors.toCollection(Vector::new));
}
public boolean CheckCurrent(TextLog log) {
return MainModule_.instance.Check(log, CurrentName());
//переименовать в CheckCurrent
public boolean Check(TextLog log) {
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);
}
public boolean CheckSelectedOrCurrent(TextLog log) {
if ((getSelectedCount() == 0) && (CurrentName() == null || (getCurrent() == null))) {
if ((getSelectedCount() == 0) && (!needsCurrent() || (getCurrent() == null))) {
log.Writeln_(dataSource.getPluralDescription() + ":");
log.Writeln_("Отсутствуют отмеченные объекты, или текущий объект!");
return false;
}
return true;
}
protected boolean needsCurrent() {
return false;
} //нужно ли отслеживать текущий объект.
protected String getCurrentName() {
return dataSource.d.getSimpleName();
}
public D getCurrent() {
return (D) MainModule_.instance.get(CurrentName());
return current;
}
public D setCurrent(D object) {
return current = object;
}
public Vector<D> getSelectedOrCurrent() {
Vector<D> res = new Vector<>();
if (getSelectedCount() > 0)
res = getSelectedItems();
else {
if ((CurrentName() != null) && (getCurrent() != null)) {
if (needsCurrent() && (getCurrent() != null)) {
res.add(getCurrent());
}
}
@@ -484,7 +497,7 @@ public class DataSetControlForm<D extends DBObject> extends ControlForm<DataTabl
if (getSelectedCount() > 0)
res = getSelectedKeys();
else {
if ((CurrentName() != null) && (getCurrent() != null)) {
if (needsCurrent() && (getCurrent() != null)) {
res.add(getCurrent().getPK());
}
}
@@ -502,7 +515,7 @@ public class DataSetControlForm<D extends DBObject> extends ControlForm<DataTabl
if (isObjectVisible(object))
object.Select(flag);
}
Refresh();
RedrawControl();
}
//ДИАЛОГИ
public boolean ShowAddObjectDialog(D object) {