окончательное разделение таблицы и функционала видимой ее формы

This commit is contained in:
2024-10-22 15:25:06 +03:00
parent 319e6575c8
commit 38b2896e4a
102 changed files with 738 additions and 709 deletions

View File

@@ -4,8 +4,4 @@ public class FormsDBTable extends DBTable<String, DBForm> {
public FormsDBTable() {
super(String.class, DBForm.class);
}
@Override
public String getSingleDescription() {
return "параметры окна";
}
}

View File

@@ -4,10 +4,6 @@ public class PassStatsDBTable extends DBTable<String, PassStats> {
public PassStatsDBTable() {
super(String.class, PassStats.class);
}
@Override
public String getSingleDescription() {
return "статистика выполнения прохода";
}
public void IncPassStat(String passName) throws Exception {
PassStats passStats = null;
if (Data.containsKey(passName)) {

View File

@@ -1,9 +1,6 @@
package Common.Database.Tables;
import Common.Current_;
import Common.Database.Objects.DBObject;
import Common.MainModule_;
import Common.Passes.PassCode_;
import Common.Utils.TextLog;
import Common.Visual.DataSetControlForm;
import Common.Visual.UI;
import Common.Visual.Windows.Dialog.DBObjectDialog;
@@ -13,7 +10,6 @@ import javax.swing.*;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.Vector;
import java.util.stream.Collectors;
public class DataSet<K, D extends DBObject> extends DataSetAnchestor {
public String Name;
public Class<K> k; //класс первичного ключа.
@@ -46,22 +42,9 @@ public class DataSet<K, D extends DBObject> extends DataSetAnchestor {
public int getRowCountUI() {
return ui.getRowCount();
}
public void SetCurrentObjectByUI(Object pk) {
if (ui != null) {
ui.ClearSelection(); //сброс текущего объекта и всего что с ним связано.
ui.SetCurrentByPK(pk);
}
}
protected DataSetControlForm createUI(JPanel mountPanel) {
return null;
}
public void SelectAll(boolean flag) {
for (D object : Data.values()) {
if (getUI().isObjectVisible(object))
object.Select(flag);
}
RefreshUI();
}
public D getFirstRecord() {
return Data.values().stream().findFirst().orElse(null);
}
@@ -70,30 +53,31 @@ public class DataSet<K, D extends DBObject> extends DataSetAnchestor {
res.sort(comparator);
return res;
}
//todo все это тоже в уи?
@SuppressWarnings("unchecked")
public DBObjectDialog<D, ? extends DialogFields> getDialog() {
return null;
}
public boolean ShowAddObjectDialog(DBObject object) {
return getDialog().ShowDialog(getSingleDescription() + ": добавление", object);
return getDialog().ShowDialog(getUI().getSingleDescription() + ": добавление", object);
}
public boolean ShowEditObjectDialog(DBObject object) {
DBObjectDialog dialog = getDialog();
dialog.edit = true;
dialog.SetEditLimits();
return dialog.ShowDialog(getSingleDescription() + ": редактирование", object);
return dialog.ShowDialog(getUI().getSingleDescription() + ": редактирование", object);
}
public boolean ViewObject(DBObject object) {
DBObjectDialog dialog = getDialog();
dialog.SetReadonly();
dialog.ShowDialog(getSingleDescription() + ": просмотр", object);
dialog.ShowDialog(getUI().getSingleDescription() + ": просмотр", object);
return false;
}
public boolean ShowDeleteObjectDialog(DBObject object) {
return UI.Warning(getSingleDescription() + " " + object.getBDialogName() + " будет удален(а)");
return UI.Warning(getUI().getSingleDescription() + " " + object.getBDialogName() + " будет удален(а)");
}
public boolean ShowDeleteObjectsDialog(int toDeleteCount) {
return UI.Warning(getPluralDescription() + " в количестве " + toDeleteCount + " будут удалены)");
return UI.Warning(getUI().getPluralDescription() + " в количестве " + toDeleteCount + " будут удалены)");
}
public String QName() {
return "\"" + Name + "\"";
@@ -101,12 +85,6 @@ public class DataSet<K, D extends DBObject> extends DataSetAnchestor {
public String getPKName() {
return "";
} //получить имя ключевого поля. нужно для таблиц.
public String getPluralDescription() {
return "";
}
public String getSingleDescription() {
return "";
}
//-
public void put(Object key, D object) {
Data.put((K) key, object);
@@ -123,17 +101,6 @@ public class DataSet<K, D extends DBObject> extends DataSetAnchestor {
public boolean containsKey(Object key) {
return Data.containsKey(key);
}
//-
public int getSelectedCount() {
return (int) Data.values().stream().filter(d -> getUI().isObjectVisible(d) && d.isSelected()).count();
}
public Vector<D> getSelectedItems() {
return Data.values().stream().filter(d -> getUI().isObjectVisible(d) && d.isSelected()).collect(Collectors.toCollection(Vector::new));
}
public Vector<K> getSelectedKeys() {
return Data.values().stream().filter(DBObject::isSelected).map(d -> (K) d.getPK()).collect(Collectors.toCollection(Vector::new));
}
//--
public void ShowUI() {
if (ui != null) {
ui.Show();
@@ -144,53 +111,6 @@ public class DataSet<K, D extends DBObject> extends DataSetAnchestor {
ui.Show(key);
}
}
//------------------------------------------------------------------------------------
public Current_ CurrentName() {
return null;
}
public boolean CheckCurrent(TextLog log) {
return MainModule_.instance.Check(log, CurrentName());
}
public boolean CheckSelectedOrCurrent(TextLog log) {
if ((getSelectedCount() == 0) && (CurrentName() == null || (getCurrent() == null))) {
log.Writeln_(getPluralDescription() + ":");
log.Writeln_("Отсутствуют отмеченные объекты, или текущий объект!");
return false;
}
return true;
}
public void dropCurrent() {
MainModule_.instance.set(CurrentName(), null);
}
public D getCurrent() {
return (D) MainModule_.instance.get(CurrentName());
}
public void setCurrent(D o) {
MainModule_.instance.set(CurrentName(), o);
}
public Vector<D> getSelectedOrCurrent() {
Vector<D> res = new Vector<>();
if (getSelectedCount() > 0)
res = getSelectedItems();
else {
if ((CurrentName() != null) && (getCurrent() != null)) {
res.add(getCurrent());
}
}
return res;
}
public Vector<K> getSelectedOrCurrentKeys() {
Vector<K> res = new Vector<>();
if (getSelectedCount() > 0)
res = getSelectedKeys();
else {
if ((CurrentName() != null) && (getCurrent() != null)) {
res.add((K) getCurrent().getPK());
}
}
return res;
}
//-------------------------------------------------------------------------------------
public PassCode_ getDeletePassCode() {
return null;
}

View File

@@ -11,7 +11,7 @@ public abstract class AddObjectPass<D extends DBObject> extends ObjectPass<D> {
protected boolean canStart(Object... args) throws Exception {
target = d.newInstance();
return
((getOwner() == null) || (getDb().getTable(getOwner()).CheckCurrent(Log))) &&
((getOwner() == null) || (getDb().getTable(getOwner()).getUI().CheckCurrent(Log))) &&
fillObjectFields();
}
protected boolean fillObjectFields() throws Exception {

View File

@@ -10,8 +10,8 @@ public abstract class DeleteObjectPass<D extends DBObject> extends ObjectPass<D>
}
@Override
protected boolean canStart(Object... args) throws Exception {
target = (D) getTable().getCurrent();
return getTable().CheckCurrent(Log) && getTable().ShowDeleteObjectDialog(target);
target = (D) getTable().getUI().getCurrent();
return getTable().getUI().CheckCurrent(Log) && getTable().ShowDeleteObjectDialog(target);
}
//Очищаем все связанные таблицы, чтобы не допустить перерисовки во время удаления объекта.
@Override

View File

@@ -10,9 +10,9 @@ public abstract class DeleteObjectsPass<D extends DBObject> extends ObjectsPass<
}
@Override
protected boolean canStart(Object... args) throws Exception {
if (!getTable().CheckSelectedOrCurrent(Log))
if (!getTable().getUI().CheckSelectedOrCurrent(Log))
return false;
target = getTable().getSelectedOrCurrent();
target = getTable().getUI().getSelectedOrCurrent();
return getTable().ShowDeleteObjectsDialog(target.size());
}
//Очищаем все связанные таблицы, чтобы не допустить перерисовки во время удаления объекта.

View File

@@ -10,8 +10,8 @@ public abstract class EditObjectPass<D extends DBObject> extends ObjectPass<D> {
}
@Override
protected boolean canStart(Object... args) throws Exception {
target = (D) getTable().getCurrent();
return getTable().CheckCurrent(Log) && getTable().ShowEditObjectDialog(target);
target = (D) getTable().getUI().getCurrent();
return getTable().getUI().CheckCurrent(Log) && getTable().ShowEditObjectDialog(target);
}
@Override
protected void body() throws Exception {

View File

@@ -1,11 +1,13 @@
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;
import Common.Database.Tables.DataSet;
import Common.Database.Tables.FKBehaviour;
import Common.MainModule_;
import Common.Utils.TextLog;
import Common.Utils.Utils_;
import Common.Visual.Menus.DataMenuBar;
import Common.Visual.Menus.TableMenu;
@@ -72,6 +74,12 @@ public class DataSetControlForm<D extends DBObject> extends ControlForm<DataTabl
}
}
}
public String getPluralDescription() {
return "";
}
public String getSingleDescription() {
return "";
}
<M> Vector<M> getFilters(Class<M> f) {
Vector<M> res = new Vector<>();
for (DBObjectFilter_ filter_ : allFilters) {
@@ -99,8 +107,8 @@ public class DataSetControlForm<D extends DBObject> extends ControlForm<DataTabl
public void SaveColumns() {
if (MainModule_.instance.getDb() != null) {
try {
if (dataSource.CurrentName() != null) {
String tableName = dataSource.CurrentName().toString();
if (CurrentName() != null) {
String tableName = CurrentName().toString();
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;
@@ -206,10 +214,10 @@ public class DataSetControlForm<D extends DBObject> extends ControlForm<DataTabl
@Override
public void CorrectColumnsSizes() {
if ((MainModule_.instance.getDb() != null)
&& dataSource.CurrentName() != null
&& MainModule_.instance.getDb().tablesVisualData.containsKey(dataSource.CurrentName().toString())) {
&& CurrentName() != null
&& MainModule_.instance.getDb().tablesVisualData.containsKey(CurrentName().toString())) {
if (!getColumnsProfile().equalsIgnoreCase(colNamesAndSizes)) {
TableVisualData grid = MainModule_.instance.getDb().tablesVisualData.get(dataSource.CurrentName().toString());
TableVisualData grid = MainModule_.instance.getDb().tablesVisualData.get(CurrentName().toString());
String[] data = grid.sizes.split("\\|");
for (int i = 0; i < columns.size(); ++i) {
if (i <= (data.length - 1)) {
@@ -265,7 +273,7 @@ public class DataSetControlForm<D extends DBObject> extends ControlForm<DataTabl
//------------------------->>
}
};
if (dataSource.CurrentName() != null) {
if (CurrentName() != null) {
current_row_i = CommonConstants.Nan;
ListSelectionModel selModel = control.getSelectionModel();
selModel.addListSelectionListener(e -> {
@@ -273,7 +281,7 @@ public class DataSetControlForm<D extends DBObject> extends ControlForm<DataTabl
if ((row >= 0)) {
if (row != current_row_i) {
current_row_i = row;
dataSource.setCurrent((D) control.getRowObject(row));
MainModule_.instance.set(CurrentName(), control.getRowObject(row));
if (events_on) {
try {
ShowCurrentObject();
@@ -284,7 +292,7 @@ public class DataSetControlForm<D extends DBObject> extends ControlForm<DataTabl
}
} else {
current_row_i = CommonConstants.Nan;
dataSource.dropCurrent();
dropCurrent();
if (events_on) {
try {
ShowNoCurrentObject();
@@ -298,7 +306,7 @@ public class DataSetControlForm<D extends DBObject> extends ControlForm<DataTabl
control.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if ((e.getClickCount() == 2) && (dataSource.getCurrent() != null)) {
if ((e.getClickCount() == 2) && (getCurrent() != null)) {
try {
MouseAction2();
} catch (Exception ex) {
@@ -329,7 +337,7 @@ public class DataSetControlForm<D extends DBObject> extends ControlForm<DataTabl
);
//----------------------------------------------------------------------------
//при переотображении таблицы скидываем текущий объект!!
dataSource.dropCurrent();
dropCurrent();
try {
ShowNoCurrentObject();
} catch (Exception e) {
@@ -340,7 +348,7 @@ public class DataSetControlForm<D extends DBObject> extends ControlForm<DataTabl
filter.Mount(getControl());
}
protected DataMenuBar createMenuBar() {
return new DataMenuBar(dataSource.getPluralDescription());
return new DataMenuBar(getPluralDescription());
}
protected void createFilters() {
}
@@ -373,6 +381,13 @@ public class DataSetControlForm<D extends DBObject> extends ControlForm<DataTabl
public void ClearSelection() {
if (isShown()) control.clearSelection(); //строка сбросится сама. благодаря сбросу события выбора
}
public void SelectAll(boolean flag) {
for (D object : dataSource.Data.values()) {
if (isObjectVisible(object))
object.Select(flag);
}
Refresh();
}
@Override
public void Clear() {
super.Clear();
@@ -424,10 +439,10 @@ public class DataSetControlForm<D extends DBObject> extends ControlForm<DataTabl
public void SaveLastCurrent() {
savedCurrentKey = null;
savedSelectedKeys.clear();
if ((dataSource.CurrentName() != null) && (dataSource.getCurrent() != null)) {
savedCurrentKey = dataSource.getCurrent().getPK();
if ((CurrentName() != null) && (getCurrent() != null)) {
savedCurrentKey = getCurrent().getPK();
}
savedSelectedKeys = (Vector<Object>) dataSource.getSelectedKeys();
savedSelectedKeys = getSelectedKeys();
}
public void RestoreLastCurrent() {
for (Object key : savedSelectedKeys) {
@@ -438,4 +453,56 @@ public class DataSetControlForm<D extends DBObject> extends ControlForm<DataTabl
SetCurrentByPK(savedCurrentKey);
}
}
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));
}
//--
public Current_ CurrentName() {
return null;
}
public boolean CheckCurrent(TextLog log) {
return MainModule_.instance.Check(log, CurrentName());
}
public boolean CheckSelectedOrCurrent(TextLog log) {
if ((getSelectedCount() == 0) && (CurrentName() == null || (getCurrent() == null))) {
log.Writeln_(getPluralDescription() + ":");
log.Writeln_("Отсутствуют отмеченные объекты, или текущий объект!");
return false;
}
return true;
}
public void dropCurrent() {
MainModule_.instance.set(CurrentName(), null);
}
public D getCurrent() {
return (D) MainModule_.instance.get(CurrentName());
}
public Vector<D> getSelectedOrCurrent() {
Vector<D> res = new Vector<>();
if (getSelectedCount() > 0)
res = getSelectedItems();
else {
if ((CurrentName() != null) && (getCurrent() != null)) {
res.add(getCurrent());
}
}
return res;
}
public Vector<Object> getSelectedOrCurrentKeys() {
Vector<Object> res = new Vector<>();
if (getSelectedCount() > 0)
res = getSelectedKeys();
else {
if ((CurrentName() != null) && (getCurrent() != null)) {
res.add(getCurrent().getPK());
}
}
return res;
}
}

View File

@@ -46,10 +46,10 @@ public class DataMenuBar extends VisualiserMenuBar {
if (selectAllListener != null) {
selectAllButton.removeActionListener(selectAllListener);
}
selectAllButton.addActionListener(selectAllListener = e -> dataSet.SelectAll(true));
selectAllButton.addActionListener(selectAllListener = e -> dataSet.getUI().SelectAll(true));
if (unselectAllListener != null) {
unselectAllButton.removeActionListener(unselectAllListener);
}
unselectAllButton.addActionListener(unselectAllListener = e -> dataSet.SelectAll(false));
unselectAllButton.addActionListener(unselectAllListener = e -> dataSet.getUI().SelectAll(false));
}
}