постепенное выведение старой концепции текущих объектов, касаемо табличных лучше держать их в интерфейсе таблиц, чтобы не писать описание объекта дважды и не мучиться с типом. некоторые фиксы
This commit is contained in:
@@ -4,6 +4,7 @@ import Common.Database.Objects.DBObject;
|
||||
import Common.Database.Tables.DBTable;
|
||||
import Common.Database.Tables.DBTableColumn;
|
||||
import Common.Passes.PassException;
|
||||
import Common.Utils.TextLog;
|
||||
import Common.Utils.Utils_;
|
||||
import Common.Visual.UI;
|
||||
import javafx.util.Pair;
|
||||
@@ -255,4 +256,14 @@ public abstract class SQLiteDatabase extends Database {
|
||||
}
|
||||
//--
|
||||
//https://stackoverflow.com/questions/8558099/sqlite-query-with-byte-where-clause
|
||||
//получение "текущих" объектов. скорее временная мера.
|
||||
public boolean Check(TextLog log, Class... tablesClasses) {
|
||||
for (Class tableClass : tablesClasses) {
|
||||
getTable(tableClass).getUI().Check(log);
|
||||
}
|
||||
return log.isEmpty();
|
||||
}
|
||||
public boolean matchCurrentID(Class tableClass, int id_in) {
|
||||
return getTable(tableClass).getUI().matchCurrentID(id_in);
|
||||
}
|
||||
}
|
||||
@@ -64,6 +64,10 @@ public class DataSet<K, D extends DBObject> extends DataSetAnchestor {
|
||||
ui.Show(key);
|
||||
}
|
||||
}
|
||||
public void RefreshUI(){
|
||||
if ((ui != null) && ui.isShown())
|
||||
ui.RedrawControl();
|
||||
}
|
||||
//СОДЕРЖИМОЕ
|
||||
public D getFirstRecord() {
|
||||
return Data.values().stream().findFirst().orElse(null);
|
||||
|
||||
@@ -5,6 +5,7 @@ import Common.Database.Objects.PassStats.PassStatsDBTable;
|
||||
import Common.Database.Objects.Splitter.SplittersDBTable;
|
||||
import Common.Database.SQLITE.SQLiteDatabase;
|
||||
import Common.Passes.PassCode_;
|
||||
import Common.Utils.TextLog;
|
||||
|
||||
import java.io.File;
|
||||
public class VisualiserDatabase extends SQLiteDatabase {
|
||||
@@ -26,4 +27,5 @@ public class VisualiserDatabase extends SQLiteDatabase {
|
||||
public PassCode_ getSynchronizePassCode() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ public abstract class MainModule_<D extends VisualiserDatabase, U extends UIModu
|
||||
//--
|
||||
D db = null;
|
||||
Class<D> db_class = null;
|
||||
LinkedHashMap<Current_, Object> objects = null; //Current
|
||||
LinkedHashMap<Current_, Object> objects = null; //Current/ большинство выведено
|
||||
//--
|
||||
LinkedHashMap<PassCode_, Pass> passes = null;
|
||||
//--
|
||||
@@ -87,9 +87,11 @@ public abstract class MainModule_<D extends VisualiserDatabase, U extends UIModu
|
||||
Log.Writeln_(name.getDescription() + " не выбран(а)");
|
||||
return Log.isEmpty();
|
||||
}
|
||||
/*
|
||||
public boolean matchCurrentID(Current_ name, int id) {
|
||||
return (get(name) != null) && (((iDBObject) get(name)).id == id);
|
||||
}
|
||||
*/
|
||||
//ПРОХОДЫ
|
||||
public abstract Class getPassCodesEnum();
|
||||
public abstract String getAllPassesClassPrefix();
|
||||
|
||||
@@ -4,9 +4,12 @@ public abstract class AddObjectPass<D extends DBObject> extends ObjectPass<D> {
|
||||
public AddObjectPass(Class<D> d_in) {
|
||||
super(d_in);
|
||||
}
|
||||
public Class<? extends DBObject> getOwner() {
|
||||
protected Class<? extends DBObject> getOwnerClass() {
|
||||
return null;
|
||||
}
|
||||
protected DBObject getOwner() {
|
||||
return getDb().getTable(getOwnerClass()).getUI().getCurrent();
|
||||
}
|
||||
@Override
|
||||
public String getDescription_() {
|
||||
return "добавление";
|
||||
@@ -14,9 +17,7 @@ public abstract class AddObjectPass<D extends DBObject> extends ObjectPass<D> {
|
||||
@Override
|
||||
protected boolean canStart(Object... args) throws Exception {
|
||||
target = d.newInstance();
|
||||
return
|
||||
((getOwner() == null) || (getDb().getTable(getOwner()).getUI().CheckCurrent(Log))) &&
|
||||
fillObjectFields();
|
||||
return ((getOwnerClass() == null) || (getDb().getTable(getOwnerClass()).getUI().Check(Log))) && fillObjectFields();
|
||||
}
|
||||
protected boolean fillObjectFields() throws Exception {
|
||||
return getTable().getUI().ShowAddObjectDialog(target);
|
||||
|
||||
@@ -15,7 +15,7 @@ public abstract class DeleteObjectPass<D extends DBObject> extends ObjectPass<D>
|
||||
@Override
|
||||
protected boolean canStart(Object... args) throws Exception {
|
||||
target = (D) getTable().getUI().getCurrent();
|
||||
return getTable().getUI().CheckCurrent(Log) && getTable().getUI().ShowDeleteObjectDialog(target);
|
||||
return getTable().getUI().Check(Log) && getTable().getUI().ShowDeleteObjectDialog(target);
|
||||
}
|
||||
//Очищаем все связанные таблицы, чтобы не допустить перерисовки во время удаления объекта.
|
||||
@Override
|
||||
|
||||
@@ -14,7 +14,7 @@ public abstract class EditObjectPass<D extends DBObject> extends ObjectPass<D> {
|
||||
@Override
|
||||
protected boolean canStart(Object... args) throws Exception {
|
||||
target = (D) getTable().getUI().getCurrent();
|
||||
return getTable().getUI().CheckCurrent(Log) && getTable().getUI().ShowEditObjectDialog(target);
|
||||
return getTable().getUI().Check(Log) && getTable().getUI().ShowEditObjectDialog(target);
|
||||
}
|
||||
@Override
|
||||
protected void body() throws Exception {
|
||||
@@ -23,7 +23,8 @@ public abstract class EditObjectPass<D extends DBObject> extends ObjectPass<D> {
|
||||
@Override
|
||||
protected void showFinish() throws Exception {
|
||||
getTable().ShowUI(target.getPK());
|
||||
for (Class dep : getTable().getFKDependencies().keySet())
|
||||
getDb().getTable(dep).getUI().Refresh();
|
||||
for (Class dep : getTable().getFKDependencies().keySet()) {
|
||||
getDb().getTable(dep).RefreshUI();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ public class ControlForm<C extends Component> {
|
||||
UI.Clear(scrollPanel);
|
||||
control = null; //очищено.
|
||||
}
|
||||
public void Refresh() {
|
||||
public void RedrawControl() {
|
||||
if (control != null)
|
||||
redrawControl();
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user