рефакторинг массовых удалений объектов

This commit is contained in:
2024-10-16 18:58:23 +03:00
parent cf660d26ea
commit 788bd67201
21 changed files with 170 additions and 53 deletions

View File

@@ -151,6 +151,9 @@ public class DataSet<K, D extends DBObject> extends DataSetAnchestor {
public boolean ShowDeleteObjectDialog(DBObject object) {
return UI.Warning(getSingleDescription() + " " + object.getBDialogName() + " будет удален(а)");
}
public boolean ShowDeleteObjectsDialog(int toDeleteCount) {
return UI.Warning(getPluralDescription() + " в количестве " + toDeleteCount + " будут удалены)");
}
public String QName() {
return "\"" + Name + "\"";
}
@@ -205,13 +208,13 @@ public class DataSet<K, D extends DBObject> extends DataSetAnchestor {
protected Comparator<D> getComparator() {
return null;
}
public int getCheckedCount() {
public int getSelectedCount() {
return (int) Data.values().stream().filter(d -> d.isVisible() && d.isSelected()).count();
}
public Vector<D> getCheckedItems() {
public Vector<D> getSelectedItems() {
return Data.values().stream().filter(d -> d.isVisible() && d.isSelected()).collect(Collectors.toCollection(Vector::new));
}
public Vector<K> getCheckedKeys() {
public Vector<K> getSelectedKeys() {
return Data.values().stream().filter(DBObject::isSelected).map(d -> (K) d.getPK()).collect(Collectors.toCollection(Vector::new));
}
//--
@@ -262,6 +265,14 @@ public class DataSet<K, D extends DBObject> extends DataSetAnchestor {
public boolean CheckCurrent(TextLog log) {
return MainModule_.instance.Check(log, CurrentName());
}
public boolean CheckSelectedOrCurrent(TextLog log) {
if ((getSelectedCount() == 0) && (CurrentName()==null || (getCurrent()==null))) {
log.Writeln_(getPluralDescription() + ":");
log.Writeln_("Отсутствуют отмеченные объекты, или текущий объект!");
return false;
}
return true;
}
public boolean hasCurrent() {
return MainModule_.instance.get(CurrentName()) != null;
}
@@ -274,15 +285,24 @@ public class DataSet<K, D extends DBObject> extends DataSetAnchestor {
public void setCurrent(D o) {
MainModule_.instance.set(CurrentName(), o);
}
public Vector<D> getCheckedOrCurrent() {
public Vector<D> getSelectedOrCurrent() {
Vector<D> res = new Vector<>();
if (getCheckedCount() > 0)
res = getCheckedItems();
if (getSelectedCount() > 0)
res = getSelectedItems();
else {
if (CurrentName() != null) {
if (getCurrent() != null) {
res.add(getCurrent());
}
if ((CurrentName() != null) && (getCurrent() != null)) {
res.add(getCurrent());
}
}
return res;
}
public Vector<K> getSelectedOrCurrentKeys(){
Vector<K> res = new Vector<>();
if (getSelectedCount() > 0)
res = getSelectedKeys();
else {
if ((CurrentName() != null) && (getCurrent() != null)) {
res.add((K) getCurrent().getPK());
}
}
return res;