2024-10-14 12:24:59 +03:00
|
|
|
|
package Common;
|
2024-10-14 12:37:30 +03:00
|
|
|
|
import Common.Database.Objects.PassStats.PassStats;
|
2024-10-13 22:08:13 +03:00
|
|
|
|
import Common.Database.Objects.iDBObject;
|
2024-10-12 00:17:51 +03:00
|
|
|
|
import Common.Database.VisualiserDatabase;
|
|
|
|
|
|
import Common.Passes.Pass;
|
|
|
|
|
|
import Common.Passes.PassCode_;
|
2024-10-13 22:08:13 +03:00
|
|
|
|
import Common.Utils.TextLog;
|
2024-10-14 16:16:41 +03:00
|
|
|
|
import Common.Visual.UIModule_;
|
2024-10-12 00:17:51 +03:00
|
|
|
|
|
2024-10-14 18:52:44 +03:00
|
|
|
|
import javax.swing.*;
|
2024-10-14 01:16:31 +03:00
|
|
|
|
import java.util.Comparator;
|
2024-10-12 00:17:51 +03:00
|
|
|
|
import java.util.LinkedHashMap;
|
2024-10-14 01:16:31 +03:00
|
|
|
|
import java.util.Vector;
|
2024-10-12 00:17:51 +03:00
|
|
|
|
//Основной объект визуализатора.
|
2024-10-14 16:16:41 +03:00
|
|
|
|
public abstract class MainModule_<D extends VisualiserDatabase, U extends UIModule_> {
|
2024-10-14 15:30:52 +03:00
|
|
|
|
public static MainModule_ instance = null; //текущий экземпляр. всегда один.
|
2024-10-14 01:31:33 +03:00
|
|
|
|
//--
|
2024-10-15 13:35:33 +03:00
|
|
|
|
D db = null;
|
|
|
|
|
|
Class<D> db_class = null;
|
|
|
|
|
|
LinkedHashMap<Current_, Object> objects = null; //Current
|
2024-10-14 01:16:31 +03:00
|
|
|
|
//--
|
2024-10-15 13:35:33 +03:00
|
|
|
|
LinkedHashMap<PassCode_, Pass> passes = null;
|
2024-10-14 01:16:31 +03:00
|
|
|
|
//--
|
2024-10-15 13:35:33 +03:00
|
|
|
|
U ui = null;
|
|
|
|
|
|
Class<U> ui_class = null;
|
|
|
|
|
|
MenuElement[] last_menu_path = null;
|
2024-10-14 16:16:41 +03:00
|
|
|
|
//--
|
|
|
|
|
|
public MainModule_(Class<D> db_class_in, Class<U> ui_class_in) throws Exception {
|
2024-10-15 13:35:33 +03:00
|
|
|
|
ui_class = ui_class_in;
|
2024-10-14 18:41:02 +03:00
|
|
|
|
db_class = db_class_in;
|
2024-10-14 15:30:52 +03:00
|
|
|
|
instance = this;
|
2024-10-12 00:17:51 +03:00
|
|
|
|
}
|
2024-10-15 13:35:33 +03:00
|
|
|
|
public void CreateAll() throws Exception {
|
|
|
|
|
|
if (ui_class != null)
|
|
|
|
|
|
ui = ui_class.newInstance();
|
2024-10-14 18:41:02 +03:00
|
|
|
|
//--
|
2024-10-14 20:17:29 +03:00
|
|
|
|
createPasses();
|
2024-10-14 18:41:02 +03:00
|
|
|
|
//-
|
|
|
|
|
|
objects = new LinkedHashMap<>();
|
|
|
|
|
|
}
|
2024-10-14 16:16:41 +03:00
|
|
|
|
//ИНТЕРФЕЙС
|
2024-10-15 13:35:33 +03:00
|
|
|
|
public boolean hasUI() {
|
|
|
|
|
|
return ui != null;
|
|
|
|
|
|
}
|
|
|
|
|
|
public U getUI() {
|
2024-10-14 18:52:44 +03:00
|
|
|
|
return ui;
|
|
|
|
|
|
}
|
2024-10-15 13:35:33 +03:00
|
|
|
|
public boolean hasLastMenuPath() {
|
|
|
|
|
|
return last_menu_path != null;
|
|
|
|
|
|
}
|
|
|
|
|
|
public MenuElement[] getLastMenuPath() {
|
|
|
|
|
|
return last_menu_path;
|
|
|
|
|
|
}
|
|
|
|
|
|
public MenuElement[] setLastMenuPath(MenuElement[] last_menu_path_in) {
|
|
|
|
|
|
return last_menu_path = last_menu_path_in;
|
|
|
|
|
|
}
|
2024-10-14 12:37:02 +03:00
|
|
|
|
//БАЗА ДАННЫХ И ТЕКУЩИЕ ОБЪЕКТЫ
|
|
|
|
|
|
public D getDb() {
|
|
|
|
|
|
return db;
|
|
|
|
|
|
}
|
2024-10-12 00:17:51 +03:00
|
|
|
|
public void ActivateDB() throws Exception {
|
|
|
|
|
|
db = db_class.newInstance();
|
|
|
|
|
|
db.Connect();
|
|
|
|
|
|
db.CreateAllTables();
|
|
|
|
|
|
db.prepareTablesStatements();
|
|
|
|
|
|
db.Synchronize();
|
|
|
|
|
|
}
|
2024-10-14 12:37:30 +03:00
|
|
|
|
public void DeactivateDB() throws Exception {
|
2024-10-12 00:17:51 +03:00
|
|
|
|
if (db != null) db.Disconnect();
|
|
|
|
|
|
}
|
2024-10-13 22:08:13 +03:00
|
|
|
|
public Object get(Current_ name) {
|
|
|
|
|
|
if (!objects.containsKey(name))
|
2024-10-14 12:37:30 +03:00
|
|
|
|
objects.put(name, null);
|
2024-10-13 22:08:13 +03:00
|
|
|
|
return objects.get(name);
|
|
|
|
|
|
}
|
|
|
|
|
|
public Object set(Current_ name, Object object) {
|
|
|
|
|
|
if (objects.containsKey(name))
|
|
|
|
|
|
objects.replace(name, object);
|
|
|
|
|
|
else objects.put(name, object);
|
|
|
|
|
|
return object;
|
|
|
|
|
|
}
|
|
|
|
|
|
public boolean Check(TextLog Log, Current_... names) {
|
|
|
|
|
|
for (Current_ name : names)
|
|
|
|
|
|
if (get(name) == null)
|
|
|
|
|
|
Log.Writeln_(name.getDescription() + " не выбран(а)");
|
|
|
|
|
|
return Log.isEmpty();
|
|
|
|
|
|
}
|
|
|
|
|
|
public boolean matchCurrentID(Current_ name, int id) {
|
|
|
|
|
|
return (get(name) != null) && (((iDBObject) get(name)).id == id);
|
|
|
|
|
|
}
|
2024-10-14 12:37:02 +03:00
|
|
|
|
//ПРОХОДЫ
|
|
|
|
|
|
public abstract Class getPassCodesEnum();
|
|
|
|
|
|
public abstract String getAllPassesClassPrefix();
|
2024-10-14 12:37:30 +03:00
|
|
|
|
private void createPasses() {
|
|
|
|
|
|
passes = new LinkedHashMap<>();
|
|
|
|
|
|
for (Object code : getPassCodesEnum().getEnumConstants()) {
|
2024-10-14 12:37:02 +03:00
|
|
|
|
try {
|
|
|
|
|
|
Class<?> clazz = Class.forName(getAllPassesClassPrefix() + code.toString());
|
|
|
|
|
|
Pass pass = ((Pass) clazz.newInstance());
|
|
|
|
|
|
passes.put((PassCode_) code, pass);
|
|
|
|
|
|
} catch (Exception ex) {
|
2024-10-14 12:37:30 +03:00
|
|
|
|
ex.printStackTrace();
|
2024-10-14 12:37:02 +03:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
public void setPassesControlsVisible(boolean flag, PassCode_... codes_in) {
|
|
|
|
|
|
for (PassCode_ code_in : codes_in)
|
|
|
|
|
|
getPass(code_in).setControlsVisible(flag);
|
|
|
|
|
|
}
|
2024-10-14 12:37:30 +03:00
|
|
|
|
public Pass getPass(PassCode_ code) {
|
2024-10-14 12:37:02 +03:00
|
|
|
|
return passes.get(code);
|
|
|
|
|
|
}
|
2024-10-14 12:37:30 +03:00
|
|
|
|
public String getPassDescription(String passName) {
|
2024-10-14 15:30:52 +03:00
|
|
|
|
return ((PassCode_) Enum.valueOf(MainModule_.instance.getPassCodesEnum(), passName)).getDescription();
|
2024-10-14 12:37:02 +03:00
|
|
|
|
}
|
2024-10-14 12:37:30 +03:00
|
|
|
|
public Vector<Pass> getFirstAccessPasses() {
|
2024-10-14 01:16:31 +03:00
|
|
|
|
Vector<PassStats> sortedStats = new Vector<>(getDb().passStats.Data.values());
|
|
|
|
|
|
sortedStats.sort(new Comparator<PassStats>() {
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public int compare(PassStats o1, PassStats o2) {
|
|
|
|
|
|
return Integer.compare(o2.Usages, o1.Usages);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2024-10-14 12:37:30 +03:00
|
|
|
|
Vector<Pass> res = new Vector<>();
|
|
|
|
|
|
for (PassStats passStats : sortedStats) {
|
2024-10-14 01:16:31 +03:00
|
|
|
|
PassCode_ passCode = (PassCode_) Enum.valueOf(getPassCodesEnum(), passStats.code);
|
|
|
|
|
|
res.add(getPass(passCode));
|
|
|
|
|
|
}
|
|
|
|
|
|
return res;
|
|
|
|
|
|
}
|
2024-10-14 12:37:02 +03:00
|
|
|
|
//---
|
2024-10-12 00:17:51 +03:00
|
|
|
|
}
|