промежуточный. частичный рефакторинг с прицелом на библиотечную часть
This commit is contained in:
8
src/Common/Visual/CommonUI.java
Normal file
8
src/Common/Visual/CommonUI.java
Normal file
@@ -0,0 +1,8 @@
|
||||
package Common.Visual;
|
||||
import Common_old.UI.Menus_2023.DataMenuBar;
|
||||
import Common.Database.Tables.DataSet;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
public class CommonUI {
|
||||
public static LinkedHashMap<Class<? extends DataSet>, DataMenuBar> menuBars = new LinkedHashMap<>();
|
||||
}
|
||||
62
src/Common/Visual/DBObjectFilter.java
Normal file
62
src/Common/Visual/DBObjectFilter.java
Normal file
@@ -0,0 +1,62 @@
|
||||
package Common.Visual;
|
||||
import Common_old.UI.Menus_2023.StableMenuItem;
|
||||
import Common_old.Utils.Utils;
|
||||
import Common.Database.Objects.DBObject;
|
||||
import Common.Database.Tables.DataSet;
|
||||
|
||||
import javax.swing.*;
|
||||
//одиночный фильтр, пункт фильтрационного меню.
|
||||
public abstract class DBObjectFilter<D extends DBObject> {
|
||||
public JMenuItem menuItem; //пункт меню фильтра. ( возможно потом сделать и кнопку)
|
||||
//--
|
||||
String description;
|
||||
boolean active = true; //включен ли фильтр
|
||||
int count = 0;
|
||||
//--
|
||||
static String getNotActiveIconPath() {
|
||||
return "/Common/icons/NotPick.png";
|
||||
}
|
||||
static String getActiveIconPath() {
|
||||
return "/Common/icons/Pick.png";
|
||||
}
|
||||
void Mark() {
|
||||
menuItem.setIcon(Utils.getIcon(active ? getActiveIconPath() : getNotActiveIconPath()));
|
||||
}
|
||||
//-------
|
||||
public boolean Validate(D object) {
|
||||
boolean valid = validate(object);
|
||||
if (valid)
|
||||
count++;
|
||||
return valid & active;
|
||||
}
|
||||
public DBObjectFilter(DataSet dataSet, String description_in, boolean active_in) {
|
||||
menuItem = new StableMenuItem((description = description_in) + " (0)");
|
||||
active = active_in;
|
||||
menuItem.addActionListener(e -> {
|
||||
active = !active;
|
||||
Mark();
|
||||
dataSet.ShowUI();
|
||||
});
|
||||
Mark();
|
||||
}
|
||||
public DBObjectFilter(DataSet dataSet, String description_in) {
|
||||
this(dataSet, description_in, true);
|
||||
}
|
||||
public void setActive(boolean flag) {
|
||||
active = flag;
|
||||
Mark();
|
||||
}
|
||||
//--
|
||||
protected abstract boolean validate(D object);
|
||||
//--
|
||||
public void Drop() {
|
||||
count = 0;
|
||||
}
|
||||
public void Refresh() {
|
||||
menuItem.setText(description + " " + Utils.RBrackets(count));
|
||||
}
|
||||
public boolean isActive() {
|
||||
return active;
|
||||
}
|
||||
//--
|
||||
}
|
||||
80
src/Common/Visual/DataSetFilter.java
Normal file
80
src/Common/Visual/DataSetFilter.java
Normal file
@@ -0,0 +1,80 @@
|
||||
package Common.Visual;
|
||||
import Common_old.UI.Menus_2023.StableMenuItem;
|
||||
import Common_old.UI.Menus_2023.VisualiserMenu;
|
||||
import Common.Database.Objects.DBObject;
|
||||
import Common.Database.Tables.DataSet;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.Vector;
|
||||
public abstract class DataSetFilter<D extends DBObject> {
|
||||
public VisualiserMenu menu;
|
||||
//--
|
||||
protected DataSet<?, D> dataSet;
|
||||
protected Vector<DBObjectFilter<D>> field_filters;
|
||||
public DataSetFilter(String name, DataSet dataSet_in) {
|
||||
dataSet = dataSet_in;
|
||||
menu = new VisualiserMenu(name, "/icons/Filter.png", true);
|
||||
field_filters = new Vector<>();
|
||||
fill();
|
||||
//-
|
||||
for (DBObjectFilter<D> filter : field_filters)
|
||||
menu.add(filter.menuItem);
|
||||
menu.addSeparator();
|
||||
menu.add(new StableMenuItem("Выбрать всё", "/icons/SelectAll.png") {
|
||||
{
|
||||
addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
selectAll(true);
|
||||
dataSet.ShowUI();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
menu.add(new StableMenuItem("Отменить всё", "/icons/UnselectAll.png") {
|
||||
{
|
||||
addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
selectAll(false);
|
||||
dataSet.ShowUI();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
void selectAll(boolean flag) {
|
||||
for (DBObjectFilter filter : field_filters)
|
||||
filter.setActive(flag);
|
||||
}
|
||||
public abstract void fill();
|
||||
public void Drop() {
|
||||
for (DBObjectFilter<D> filter : field_filters)
|
||||
filter.Drop();
|
||||
}
|
||||
public void Refresh() {
|
||||
for (DBObjectFilter<D> filter : field_filters)
|
||||
filter.Refresh();
|
||||
}
|
||||
public boolean isActive() {
|
||||
for (DBObjectFilter<D> filter : field_filters) {
|
||||
if (filter.isActive())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public boolean Validate(D object) {
|
||||
if (!isActive()) {
|
||||
//считаем без учета результатов
|
||||
for (DBObjectFilter<D> filter : field_filters)
|
||||
filter.Validate(object);
|
||||
return true;
|
||||
}
|
||||
boolean res = false;
|
||||
for (DBObjectFilter<D> filter : field_filters)
|
||||
if (filter.Validate(object))
|
||||
res |= true;
|
||||
return res;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user