118 lines
3.7 KiB
Java
118 lines
3.7 KiB
Java
package Common.Database.Tables;
|
||
import Common.Database.Objects.DBObject;
|
||
import Common.Passes.PassCode_;
|
||
import Common.Visual.DataSetControlForm;
|
||
import Common.Visual.UI;
|
||
import Common.Visual.Windows.Dialog.DBObjectDialog;
|
||
import Common.Visual.Windows.Dialog.DialogFields;
|
||
|
||
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<>(); //наполнение
|
||
//-
|
||
protected DataSetControlForm ui = null;
|
||
//--
|
||
public DataSet(Class<K> k_in, Class<D> d_in) {
|
||
k = k_in;
|
||
d = d_in;
|
||
Name = d.getSimpleName();
|
||
}
|
||
public DataSetControlForm<D> getUI() {
|
||
return ui;
|
||
}
|
||
public void mountUI(JPanel mountPanel_in) {
|
||
UI.Clear(mountPanel_in);
|
||
ui = createUI(mountPanel_in);
|
||
}
|
||
public void ClearUI() {
|
||
if ((ui != null) && ui.isShown()) {
|
||
ui.ClearSelection();
|
||
ui.Clear();
|
||
}
|
||
}
|
||
public void RefreshUI() {
|
||
if (ui != null) ui.Refresh();
|
||
}
|
||
public int getRowCountUI() {
|
||
return ui.getRowCount();
|
||
}
|
||
protected DataSetControlForm createUI(JPanel mountPanel) {
|
||
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;
|
||
}
|
||
//todo все это тоже в уи?
|
||
@SuppressWarnings("unchecked")
|
||
public DBObjectDialog<D, ? extends DialogFields> getDialog() {
|
||
return null;
|
||
}
|
||
public boolean ShowAddObjectDialog(DBObject object) {
|
||
return getDialog().ShowDialog(getUI().getSingleDescription() + ": добавление", object);
|
||
}
|
||
public boolean ShowEditObjectDialog(DBObject object) {
|
||
DBObjectDialog dialog = getDialog();
|
||
dialog.edit = true;
|
||
dialog.SetEditLimits();
|
||
return dialog.ShowDialog(getUI().getSingleDescription() + ": редактирование", object);
|
||
}
|
||
public boolean ViewObject(DBObject object) {
|
||
DBObjectDialog dialog = getDialog();
|
||
dialog.SetReadonly();
|
||
dialog.ShowDialog(getUI().getSingleDescription() + ": просмотр", object);
|
||
return false;
|
||
}
|
||
public boolean ShowDeleteObjectDialog(DBObject object) {
|
||
return UI.Warning(getUI().getSingleDescription() + " " + object.getBDialogName() + " будет удален(а)");
|
||
}
|
||
public boolean ShowDeleteObjectsDialog(int toDeleteCount) {
|
||
return UI.Warning(getUI().getPluralDescription() + " в количестве " + toDeleteCount + " будут удалены)");
|
||
}
|
||
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);
|
||
}
|
||
public void ShowUI() {
|
||
if (ui != null) {
|
||
ui.Show();
|
||
}
|
||
}
|
||
public void ShowUI(Object key) {
|
||
if (ui != null) {
|
||
ui.Show(key);
|
||
}
|
||
}
|
||
public PassCode_ getDeletePassCode() {
|
||
return null;
|
||
}
|
||
}
|