2024-10-07 00:58:29 +03:00
|
|
|
|
package Common.Database.Tables;
|
2024-10-14 15:19:13 +03:00
|
|
|
|
import Common.Database.Objects.DBObject;
|
2024-10-16 21:58:46 +03:00
|
|
|
|
import Common.Passes.PassCode_;
|
2024-10-08 00:39:13 +03:00
|
|
|
|
import Common.Visual.DataSetControlForm;
|
2024-10-15 15:13:57 +03:00
|
|
|
|
import Common.Visual.UI;
|
2024-10-08 22:33:49 +03:00
|
|
|
|
import Common.Visual.Windows.Dialog.DBObjectDialog;
|
|
|
|
|
|
import Common.Visual.Windows.Dialog.DialogFields;
|
2023-09-17 22:13:42 +03:00
|
|
|
|
|
|
|
|
|
|
import javax.swing.*;
|
|
|
|
|
|
import java.util.Comparator;
|
|
|
|
|
|
import java.util.LinkedHashMap;
|
|
|
|
|
|
import java.util.Vector;
|
|
|
|
|
|
public class DataSet<K, D extends DBObject> extends DataSetAnchestor {
|
|
|
|
|
|
public String Name;
|
|
|
|
|
|
public Class<K> k; //класс первичного ключа.
|
|
|
|
|
|
public Class<D> d; //класс объектов.
|
|
|
|
|
|
public LinkedHashMap<K, D> Data = new LinkedHashMap<>(); //наполнение
|
|
|
|
|
|
//-
|
2024-10-17 21:24:55 +03:00
|
|
|
|
protected DataSetControlForm ui = null;
|
2023-12-26 19:12:30 +03:00
|
|
|
|
//--
|
2023-09-17 22:13:42 +03:00
|
|
|
|
public DataSet(Class<K> k_in, Class<D> d_in) {
|
|
|
|
|
|
k = k_in;
|
|
|
|
|
|
d = d_in;
|
|
|
|
|
|
Name = d.getSimpleName();
|
|
|
|
|
|
}
|
2024-10-21 12:32:20 +03:00
|
|
|
|
public DataSetControlForm<D> getUI() {
|
2024-10-17 21:24:55 +03:00
|
|
|
|
return ui;
|
2024-10-17 17:22:33 +03:00
|
|
|
|
}
|
2024-10-17 20:04:16 +03:00
|
|
|
|
public void mountUI(JPanel mountPanel_in) {
|
|
|
|
|
|
UI.Clear(mountPanel_in);
|
2024-10-17 21:24:55 +03:00
|
|
|
|
ui = createUI(mountPanel_in);
|
2023-09-17 22:13:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
public void ClearUI() {
|
2024-10-17 21:24:55 +03:00
|
|
|
|
if ((ui != null) && ui.isShown()) {
|
|
|
|
|
|
ui.ClearSelection();
|
|
|
|
|
|
ui.Clear();
|
2023-09-17 22:13:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
public void RefreshUI() {
|
2024-10-17 21:24:55 +03:00
|
|
|
|
if (ui != null) ui.Refresh();
|
2023-09-17 22:13:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
public int getRowCountUI() {
|
2024-10-17 21:24:55 +03:00
|
|
|
|
return ui.getRowCount();
|
2023-09-17 22:13:42 +03:00
|
|
|
|
}
|
2024-10-17 20:04:16 +03:00
|
|
|
|
protected DataSetControlForm createUI(JPanel mountPanel) {
|
2023-09-17 22:13:42 +03:00
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
public D getFirstRecord() {
|
|
|
|
|
|
return Data.values().stream().findFirst().orElse(null);
|
|
|
|
|
|
}
|
|
|
|
|
|
public Vector<D> getOrderedRecords(Comparator<D> comparator) {
|
|
|
|
|
|
Vector<D> res = new Vector<>(Data.values());
|
|
|
|
|
|
res.sort(comparator);
|
|
|
|
|
|
return res;
|
|
|
|
|
|
}
|
2024-10-22 15:25:06 +03:00
|
|
|
|
//todo все это тоже в уи?
|
2023-09-17 22:13:42 +03:00
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
|
|
public DBObjectDialog<D, ? extends DialogFields> getDialog() {
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
public boolean ShowAddObjectDialog(DBObject object) {
|
2024-10-22 15:25:06 +03:00
|
|
|
|
return getDialog().ShowDialog(getUI().getSingleDescription() + ": добавление", object);
|
2023-09-17 22:13:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
public boolean ShowEditObjectDialog(DBObject object) {
|
|
|
|
|
|
DBObjectDialog dialog = getDialog();
|
|
|
|
|
|
dialog.edit = true;
|
|
|
|
|
|
dialog.SetEditLimits();
|
2024-10-22 15:25:06 +03:00
|
|
|
|
return dialog.ShowDialog(getUI().getSingleDescription() + ": редактирование", object);
|
2023-09-17 22:13:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
public boolean ViewObject(DBObject object) {
|
|
|
|
|
|
DBObjectDialog dialog = getDialog();
|
|
|
|
|
|
dialog.SetReadonly();
|
2024-10-22 15:25:06 +03:00
|
|
|
|
dialog.ShowDialog(getUI().getSingleDescription() + ": просмотр", object);
|
2023-09-17 22:13:42 +03:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
public boolean ShowDeleteObjectDialog(DBObject object) {
|
2024-10-22 15:25:06 +03:00
|
|
|
|
return UI.Warning(getUI().getSingleDescription() + " " + object.getBDialogName() + " будет удален(а)");
|
2023-09-17 22:13:42 +03:00
|
|
|
|
}
|
2024-10-16 18:58:23 +03:00
|
|
|
|
public boolean ShowDeleteObjectsDialog(int toDeleteCount) {
|
2024-10-22 15:25:06 +03:00
|
|
|
|
return UI.Warning(getUI().getPluralDescription() + " в количестве " + toDeleteCount + " будут удалены)");
|
2024-10-16 18:58:23 +03:00
|
|
|
|
}
|
2023-09-17 22:13:42 +03:00
|
|
|
|
public String QName() {
|
|
|
|
|
|
return "\"" + Name + "\"";
|
|
|
|
|
|
}
|
|
|
|
|
|
public String getPKName() {
|
|
|
|
|
|
return "";
|
|
|
|
|
|
} //получить имя ключевого поля. нужно для таблиц.
|
|
|
|
|
|
//-
|
|
|
|
|
|
public void put(Object key, D object) {
|
|
|
|
|
|
Data.put((K) key, object);
|
|
|
|
|
|
}
|
|
|
|
|
|
public D get(Object key) {
|
|
|
|
|
|
return Data.get(key);
|
|
|
|
|
|
}
|
|
|
|
|
|
public void clear() {
|
|
|
|
|
|
Data.clear();
|
|
|
|
|
|
}
|
|
|
|
|
|
public int size() {
|
|
|
|
|
|
return Data.size();
|
|
|
|
|
|
}
|
|
|
|
|
|
public boolean containsKey(Object key) {
|
|
|
|
|
|
return Data.containsKey(key);
|
|
|
|
|
|
}
|
2023-12-26 19:12:30 +03:00
|
|
|
|
public void ShowUI() {
|
2024-10-17 21:24:55 +03:00
|
|
|
|
if (ui != null) {
|
|
|
|
|
|
ui.Show();
|
2023-12-26 19:12:30 +03:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
public void ShowUI(Object key) {
|
2024-10-17 21:24:55 +03:00
|
|
|
|
if (ui != null) {
|
|
|
|
|
|
ui.Show(key);
|
2023-12-26 19:12:30 +03:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-10-17 17:22:33 +03:00
|
|
|
|
public PassCode_ getDeletePassCode() {
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
2023-09-17 22:13:42 +03:00
|
|
|
|
}
|