no message
This commit is contained in:
@@ -86,7 +86,7 @@ public abstract class Database {
|
||||
public DBObject InsertS(DBObject object) throws Exception {
|
||||
DBTable table = tables.get(object.getClass());
|
||||
if (!(object instanceof iDBObject) && table.Data.containsKey(object.getPK()))
|
||||
throw new RepositoryRefuseException("Таблица " + Utils_.Brackets(table.Name) + " уже содержит объект с ключом " + Utils_.Brackets(object.getPK().toString()));
|
||||
throw new RepositoryRefuseException("Таблица " + Utils_.Brackets(table.getName()) + " уже содержит объект с ключом " + Utils_.Brackets(object.getPK().toString()));
|
||||
insert(table, object);
|
||||
table.Data.put(object.getPK(), object);
|
||||
return object;
|
||||
@@ -113,7 +113,7 @@ public abstract class Database {
|
||||
table.Data.remove(o.getPK());
|
||||
return o;
|
||||
} else
|
||||
throw new RepositoryRefuseException("Таблица " + Utils_.Brackets(table.Name) + " не содержит объект с ключом " + Utils_.Brackets(to_delete.getPK().toString()));
|
||||
throw new RepositoryRefuseException("Таблица " + Utils_.Brackets(table.getName()) + " не содержит объект с ключом " + Utils_.Brackets(to_delete.getPK().toString()));
|
||||
}
|
||||
public DBObject DeleteByPK(Class object_class, Object key) throws Exception {
|
||||
DBTable table = tables.get(object_class);
|
||||
@@ -123,7 +123,7 @@ public abstract class Database {
|
||||
table.Data.remove(key);
|
||||
return o;
|
||||
} else
|
||||
throw new RepositoryRefuseException("Таблица " + Utils_.Brackets(table.Name) + " не содержит объект с ключом " + Utils_.Brackets(key.toString()));
|
||||
throw new RepositoryRefuseException("Таблица " + Utils_.Brackets(table.getName()) + " не содержит объект с ключом " + Utils_.Brackets(key.toString()));
|
||||
}
|
||||
// не работает с автоинкрементом.
|
||||
public DBObject getObjectCopyByPK(Class table_class, Object pk) throws Exception {
|
||||
|
||||
@@ -29,7 +29,7 @@ public abstract class DBTable<K, D extends DBObject> extends DataSet<K, D> {
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder res = new StringBuilder(Name + "\n");
|
||||
StringBuilder res = new StringBuilder(getName() + "\n");
|
||||
for (DBTableColumn c : columns.values())
|
||||
res.append(c).append("\n");
|
||||
return res.toString();
|
||||
|
||||
@@ -9,18 +9,31 @@ 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;
|
||||
DataSetControlForm ui = null;
|
||||
//--
|
||||
public DataSet(Class<K> k_in, Class<D> d_in) {
|
||||
k = k_in;
|
||||
d = d_in;
|
||||
Name = d.getSimpleName();
|
||||
}
|
||||
//---
|
||||
protected DataSetControlForm createUI(JPanel mountPanel) {
|
||||
return null;
|
||||
}
|
||||
//БАЗА ДАННЫХ
|
||||
public String getName() {
|
||||
return d.getSimpleName();
|
||||
}
|
||||
public String QName() {
|
||||
return "\"" + getName() + "\"";
|
||||
}
|
||||
public String getPKName() {
|
||||
return "";
|
||||
} //получить имя ключевого поля. нужно для таблиц.
|
||||
//ИНТЕРФЕЙС
|
||||
public DataSetControlForm<D> getUI() {
|
||||
return ui;
|
||||
}
|
||||
@@ -34,15 +47,17 @@ public class DataSet<K, D extends DBObject> extends DataSetAnchestor {
|
||||
ui.Clear();
|
||||
}
|
||||
}
|
||||
public void RefreshUI() {
|
||||
if (ui != null) ui.Refresh();
|
||||
public void ShowUI() {
|
||||
if (ui != null) {
|
||||
ui.Show();
|
||||
}
|
||||
}
|
||||
public int getRowCountUI() {
|
||||
return ui.getRowCount();
|
||||
}
|
||||
protected DataSetControlForm createUI(JPanel mountPanel) {
|
||||
return null;
|
||||
public void ShowUI(Object key) {
|
||||
if (ui != null) {
|
||||
ui.Show(key);
|
||||
}
|
||||
}
|
||||
//СОДЕРЖИМОЕ
|
||||
public D getFirstRecord() {
|
||||
return Data.values().stream().findFirst().orElse(null);
|
||||
}
|
||||
@@ -51,13 +66,6 @@ public class DataSet<K, D extends DBObject> extends DataSetAnchestor {
|
||||
res.sort(comparator);
|
||||
return res;
|
||||
}
|
||||
public String QName() {
|
||||
return "\"" + Name + "\"";
|
||||
}
|
||||
public String getPKName() {
|
||||
return "";
|
||||
} //получить имя ключевого поля. нужно для таблиц.
|
||||
//-
|
||||
public void put(Object key, D object) {
|
||||
Data.put((K) key, object);
|
||||
}
|
||||
@@ -73,16 +81,6 @@ public class DataSet<K, D extends DBObject> extends DataSetAnchestor {
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ public abstract class DeleteObjectPass<D extends DBObject> extends ObjectPass<D>
|
||||
protected void performFinish() throws Exception {
|
||||
getTable().ShowUI();
|
||||
for (Class dep : getTable().getFKDependencies().keySet()) {
|
||||
getDb().getTable(dep).RefreshUI();
|
||||
getDb().getTable(dep).getUI().Refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ public abstract class DeleteObjectsPass<D extends DBObject> extends ObjectsPass<
|
||||
protected void performFinish() throws Exception {
|
||||
getTable().ShowUI();
|
||||
for (Class dep : getTable().getFKDependencies().keySet()) {
|
||||
getDb().getTable(dep).RefreshUI();
|
||||
getDb().getTable(dep).getUI().Refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,6 @@ public abstract class EditObjectPass<D extends DBObject> extends ObjectPass<D> {
|
||||
protected void showFinish() throws Exception {
|
||||
getTable().ShowUI(target.getPK());
|
||||
for (Class dep : getTable().getFKDependencies().keySet())
|
||||
getDb().getTable(dep).RefreshUI();
|
||||
getDb().getTable(dep).getUI().Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,10 +72,10 @@ public class DataSetControlForm<D extends DBObject> extends ControlForm<DataTabl
|
||||
}
|
||||
}
|
||||
}
|
||||
public String getPluralDescription() {
|
||||
protected String getPluralDescription() {
|
||||
return "";
|
||||
}
|
||||
public String getSingleDescription() {
|
||||
protected String getSingleDescription() {
|
||||
return "";
|
||||
}
|
||||
<M> Vector<M> getFilters(Class<M> f) {
|
||||
@@ -88,7 +88,7 @@ public class DataSetControlForm<D extends DBObject> extends ControlForm<DataTabl
|
||||
}
|
||||
return res;
|
||||
}
|
||||
public void AddFilter(DBObjectFilter_<D> filter_in) {
|
||||
protected void AddFilter(DBObjectFilter_<D> filter_in) {
|
||||
allFilters.add(filter_in);
|
||||
}
|
||||
public ColumnInfo getColumnInfo(int i) {
|
||||
@@ -98,11 +98,11 @@ public class DataSetControlForm<D extends DBObject> extends ControlForm<DataTabl
|
||||
protected String[] getUIColumnNames() {
|
||||
return new String[]{};
|
||||
}
|
||||
public Object getFieldAt(D object, int coulmnIndex) {
|
||||
public Object getFieldAt(D object, int columnIndex) {
|
||||
return null;
|
||||
}
|
||||
//-
|
||||
public void SaveColumns() {
|
||||
void SaveColumns() {
|
||||
if (MainModule_.instance.getDb() != null) {
|
||||
try {
|
||||
if (CurrentName() != null) {
|
||||
@@ -124,10 +124,10 @@ public class DataSetControlForm<D extends DBObject> extends ControlForm<DataTabl
|
||||
}
|
||||
}
|
||||
}
|
||||
private Vector<String> getHeaders() {
|
||||
Vector<String> getHeaders() {
|
||||
return columns.stream().map(ColumnInfo::getName).collect(Collectors.toCollection(Vector::new));
|
||||
}
|
||||
protected void CreateColumnsInfo() {
|
||||
void CreateColumnsInfo() {
|
||||
columns.clear();
|
||||
columns.add(new ColumnInfo(dataSource.getPKName()));
|
||||
if (hasCheckBox()) {
|
||||
@@ -144,9 +144,6 @@ public class DataSetControlForm<D extends DBObject> extends ControlForm<DataTabl
|
||||
protected Comparator getDefaultComparator() {
|
||||
return null;
|
||||
}
|
||||
public boolean isObjectVisible(D object) {
|
||||
return ApplyFilters(object);
|
||||
}
|
||||
Vector<Object> getVisibleKeys() {
|
||||
Comparator comparator = getDefaultComparator();
|
||||
Vector<Object> res_keys = new Vector<>();
|
||||
@@ -167,7 +164,6 @@ public class DataSetControlForm<D extends DBObject> extends ControlForm<DataTabl
|
||||
}
|
||||
return res_keys;
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
protected void createControl() {
|
||||
CreateColumnsInfo();
|
||||
@@ -350,7 +346,7 @@ public class DataSetControlForm<D extends DBObject> extends ControlForm<DataTabl
|
||||
}
|
||||
protected void createFilters() {
|
||||
}
|
||||
protected boolean ApplyFilters(D object) {
|
||||
boolean ApplyFilters(D object) {
|
||||
for (DBObjectFilter_ filterInterface : allFilters) {
|
||||
if (!filterInterface.Validate(object))
|
||||
return false;
|
||||
@@ -361,40 +357,7 @@ public class DataSetControlForm<D extends DBObject> extends ControlForm<DataTabl
|
||||
protected void redrawControl() {
|
||||
control.CorrectSizes();
|
||||
}
|
||||
@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);
|
||||
}
|
||||
public void SetCurrentByPK(Object pk) {
|
||||
if (isShown())
|
||||
control.SelectRowByPK(pk);
|
||||
}
|
||||
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();
|
||||
if (counter_ui != null) counter_ui.ShowNoMatches();
|
||||
}
|
||||
public int getRowCount() {
|
||||
return control.getRowCount();
|
||||
}
|
||||
public void ShowCurrentObject() throws Exception {
|
||||
protected void ShowCurrentObject() throws Exception {
|
||||
if (dataSource instanceof DBTable) {
|
||||
DBTable table = (DBTable) dataSource;
|
||||
for (Class dep : table.getFKDependencies().keySet()) {
|
||||
@@ -409,7 +372,7 @@ public class DataSetControlForm<D extends DBObject> extends ControlForm<DataTabl
|
||||
}
|
||||
}
|
||||
}
|
||||
public void ShowNoCurrentObject() throws Exception {
|
||||
protected void ShowNoCurrentObject() throws Exception {
|
||||
if (dataSource instanceof DBTable) {
|
||||
DBTable table = (DBTable) dataSource;
|
||||
for (Class dep : table.getFKDependencies().keySet()) {
|
||||
@@ -424,16 +387,50 @@ public class DataSetControlForm<D extends DBObject> extends ControlForm<DataTabl
|
||||
}
|
||||
}
|
||||
}
|
||||
public void MouseAction2() throws Exception {
|
||||
protected void MouseAction2() throws Exception {
|
||||
}
|
||||
//-
|
||||
public boolean hasCheckBox() {
|
||||
protected boolean hasCheckBox() {
|
||||
return false;
|
||||
}
|
||||
public boolean hasMenuBar() {
|
||||
protected boolean hasMenuBar() {
|
||||
return true;
|
||||
}
|
||||
//-found
|
||||
//-
|
||||
protected Current_ CurrentName() {
|
||||
return null;
|
||||
}
|
||||
void dropCurrent() {
|
||||
MainModule_.instance.set(CurrentName(), null);
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
protected DBObjectDialog getDialog() {
|
||||
return null;
|
||||
}
|
||||
protected boolean isObjectEditable(D object) {
|
||||
return true;
|
||||
}
|
||||
//БАЗОВЫЙ ФУНКЦИОНАЛ ФОРМЫ
|
||||
@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();
|
||||
}
|
||||
//ТЕКУЩИЕ И ВЫБРАННЫЕ ОБЪЕКТЫ
|
||||
public void SaveLastCurrent() {
|
||||
savedCurrentKey = null;
|
||||
savedSelectedKeys.clear();
|
||||
@@ -451,6 +448,9 @@ public class DataSetControlForm<D extends DBObject> extends ControlForm<DataTabl
|
||||
SetCurrentByPK(savedCurrentKey);
|
||||
}
|
||||
}
|
||||
public boolean isObjectVisible(D object) {
|
||||
return ApplyFilters(object);
|
||||
}
|
||||
public int getSelectedCount() {
|
||||
return (int) dataSource.Data.values().stream().filter(d -> isObjectVisible(d) && d.isSelected()).count();
|
||||
}
|
||||
@@ -460,10 +460,6 @@ 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 Current_ CurrentName() {
|
||||
return null;
|
||||
}
|
||||
public boolean CheckCurrent(TextLog log) {
|
||||
return MainModule_.instance.Check(log, CurrentName());
|
||||
}
|
||||
@@ -475,9 +471,6 @@ public class DataSetControlForm<D extends DBObject> extends ControlForm<DataTabl
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public void dropCurrent() {
|
||||
MainModule_.instance.set(CurrentName(), null);
|
||||
}
|
||||
public D getCurrent() {
|
||||
return (D) MainModule_.instance.get(CurrentName());
|
||||
}
|
||||
@@ -503,25 +496,36 @@ public class DataSetControlForm<D extends DBObject> extends ControlForm<DataTabl
|
||||
}
|
||||
return res;
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
public DBObjectDialog getDialog() {
|
||||
return null;
|
||||
public void SetCurrentByPK(Object pk) {
|
||||
if (isShown())
|
||||
control.SelectRowByPK(pk);
|
||||
}
|
||||
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();
|
||||
}
|
||||
//ДИАЛОГИ
|
||||
public boolean ShowAddObjectDialog(D object) {
|
||||
return getDialog().ShowDialog(getSingleDescription() + ": добавление", object);
|
||||
}
|
||||
//todo встроить развилку на возможность редактирования объекты boolean isObjectEditable(D object){return true;}
|
||||
public boolean ShowEditObjectDialog(D object) {
|
||||
DBObjectDialog dialog = getDialog();
|
||||
dialog.edit = true;
|
||||
dialog.SetEditLimits();
|
||||
return dialog.ShowDialog(getSingleDescription() + ": редактирование", object);
|
||||
}
|
||||
public boolean ViewObject(D object) {
|
||||
DBObjectDialog dialog = getDialog();
|
||||
dialog.SetReadonly();
|
||||
dialog.ShowDialog(getSingleDescription() + ": просмотр", object);
|
||||
return false;
|
||||
String title = getSingleDescription() + ": ";
|
||||
if (isObjectEditable(object)) {
|
||||
title += "редактирование";
|
||||
} else {
|
||||
title += "просмотр";
|
||||
dialog.SetReadonly();
|
||||
}
|
||||
return dialog.ShowDialog(title, object);
|
||||
}
|
||||
public boolean ShowDeleteObjectDialog(D object) {
|
||||
return UI.Warning(getSingleDescription() + " " + object.getBDialogName() + " будет удален(а)");
|
||||
|
||||
@@ -12,6 +12,7 @@ public abstract class DBObjectDialog<T extends DBObject, F extends DialogFields>
|
||||
Result = (T) params[0];
|
||||
fillFields();
|
||||
}
|
||||
//todo перенести в поля(?). тогда достаточно будет подавать класс полей.
|
||||
public void SetEditLimits() {
|
||||
//установить ограничения если объект в режиме редактирования( например нельзя менять тип машины, или почту адресата)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user