окончательное разделение таблицы и функционала видимой ее формы
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
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;
|
||||
import Common.Database.Tables.DataSet;
|
||||
import Common.Database.Tables.FKBehaviour;
|
||||
import Common.MainModule_;
|
||||
import Common.Utils.TextLog;
|
||||
import Common.Utils.Utils_;
|
||||
import Common.Visual.Menus.DataMenuBar;
|
||||
import Common.Visual.Menus.TableMenu;
|
||||
@@ -72,6 +74,12 @@ public class DataSetControlForm<D extends DBObject> extends ControlForm<DataTabl
|
||||
}
|
||||
}
|
||||
}
|
||||
public String getPluralDescription() {
|
||||
return "";
|
||||
}
|
||||
public String getSingleDescription() {
|
||||
return "";
|
||||
}
|
||||
<M> Vector<M> getFilters(Class<M> f) {
|
||||
Vector<M> res = new Vector<>();
|
||||
for (DBObjectFilter_ filter_ : allFilters) {
|
||||
@@ -99,8 +107,8 @@ public class DataSetControlForm<D extends DBObject> extends ControlForm<DataTabl
|
||||
public void SaveColumns() {
|
||||
if (MainModule_.instance.getDb() != null) {
|
||||
try {
|
||||
if (dataSource.CurrentName() != null) {
|
||||
String tableName = dataSource.CurrentName().toString();
|
||||
if (CurrentName() != null) {
|
||||
String tableName = CurrentName().toString();
|
||||
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;
|
||||
@@ -206,10 +214,10 @@ public class DataSetControlForm<D extends DBObject> extends ControlForm<DataTabl
|
||||
@Override
|
||||
public void CorrectColumnsSizes() {
|
||||
if ((MainModule_.instance.getDb() != null)
|
||||
&& dataSource.CurrentName() != null
|
||||
&& MainModule_.instance.getDb().tablesVisualData.containsKey(dataSource.CurrentName().toString())) {
|
||||
&& CurrentName() != null
|
||||
&& MainModule_.instance.getDb().tablesVisualData.containsKey(CurrentName().toString())) {
|
||||
if (!getColumnsProfile().equalsIgnoreCase(colNamesAndSizes)) {
|
||||
TableVisualData grid = MainModule_.instance.getDb().tablesVisualData.get(dataSource.CurrentName().toString());
|
||||
TableVisualData grid = MainModule_.instance.getDb().tablesVisualData.get(CurrentName().toString());
|
||||
String[] data = grid.sizes.split("\\|");
|
||||
for (int i = 0; i < columns.size(); ++i) {
|
||||
if (i <= (data.length - 1)) {
|
||||
@@ -265,7 +273,7 @@ public class DataSetControlForm<D extends DBObject> extends ControlForm<DataTabl
|
||||
//------------------------->>
|
||||
}
|
||||
};
|
||||
if (dataSource.CurrentName() != null) {
|
||||
if (CurrentName() != null) {
|
||||
current_row_i = CommonConstants.Nan;
|
||||
ListSelectionModel selModel = control.getSelectionModel();
|
||||
selModel.addListSelectionListener(e -> {
|
||||
@@ -273,7 +281,7 @@ public class DataSetControlForm<D extends DBObject> extends ControlForm<DataTabl
|
||||
if ((row >= 0)) {
|
||||
if (row != current_row_i) {
|
||||
current_row_i = row;
|
||||
dataSource.setCurrent((D) control.getRowObject(row));
|
||||
MainModule_.instance.set(CurrentName(), control.getRowObject(row));
|
||||
if (events_on) {
|
||||
try {
|
||||
ShowCurrentObject();
|
||||
@@ -284,7 +292,7 @@ public class DataSetControlForm<D extends DBObject> extends ControlForm<DataTabl
|
||||
}
|
||||
} else {
|
||||
current_row_i = CommonConstants.Nan;
|
||||
dataSource.dropCurrent();
|
||||
dropCurrent();
|
||||
if (events_on) {
|
||||
try {
|
||||
ShowNoCurrentObject();
|
||||
@@ -298,7 +306,7 @@ public class DataSetControlForm<D extends DBObject> extends ControlForm<DataTabl
|
||||
control.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
if ((e.getClickCount() == 2) && (dataSource.getCurrent() != null)) {
|
||||
if ((e.getClickCount() == 2) && (getCurrent() != null)) {
|
||||
try {
|
||||
MouseAction2();
|
||||
} catch (Exception ex) {
|
||||
@@ -329,7 +337,7 @@ public class DataSetControlForm<D extends DBObject> extends ControlForm<DataTabl
|
||||
);
|
||||
//----------------------------------------------------------------------------
|
||||
//при переотображении таблицы скидываем текущий объект!!
|
||||
dataSource.dropCurrent();
|
||||
dropCurrent();
|
||||
try {
|
||||
ShowNoCurrentObject();
|
||||
} catch (Exception e) {
|
||||
@@ -340,7 +348,7 @@ public class DataSetControlForm<D extends DBObject> extends ControlForm<DataTabl
|
||||
filter.Mount(getControl());
|
||||
}
|
||||
protected DataMenuBar createMenuBar() {
|
||||
return new DataMenuBar(dataSource.getPluralDescription());
|
||||
return new DataMenuBar(getPluralDescription());
|
||||
}
|
||||
protected void createFilters() {
|
||||
}
|
||||
@@ -373,6 +381,13 @@ public class DataSetControlForm<D extends DBObject> extends ControlForm<DataTabl
|
||||
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();
|
||||
@@ -424,10 +439,10 @@ public class DataSetControlForm<D extends DBObject> extends ControlForm<DataTabl
|
||||
public void SaveLastCurrent() {
|
||||
savedCurrentKey = null;
|
||||
savedSelectedKeys.clear();
|
||||
if ((dataSource.CurrentName() != null) && (dataSource.getCurrent() != null)) {
|
||||
savedCurrentKey = dataSource.getCurrent().getPK();
|
||||
if ((CurrentName() != null) && (getCurrent() != null)) {
|
||||
savedCurrentKey = getCurrent().getPK();
|
||||
}
|
||||
savedSelectedKeys = (Vector<Object>) dataSource.getSelectedKeys();
|
||||
savedSelectedKeys = getSelectedKeys();
|
||||
}
|
||||
public void RestoreLastCurrent() {
|
||||
for (Object key : savedSelectedKeys) {
|
||||
@@ -438,4 +453,56 @@ public class DataSetControlForm<D extends DBObject> extends ControlForm<DataTabl
|
||||
SetCurrentByPK(savedCurrentKey);
|
||||
}
|
||||
}
|
||||
public int getSelectedCount() {
|
||||
return (int) dataSource.Data.values().stream().filter(d -> isObjectVisible(d) && d.isSelected()).count();
|
||||
}
|
||||
public Vector<D> getSelectedItems() {
|
||||
return dataSource.Data.values().stream().filter(d -> isObjectVisible(d) && d.isSelected()).collect(Collectors.toCollection(Vector::new));
|
||||
}
|
||||
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());
|
||||
}
|
||||
public boolean CheckSelectedOrCurrent(TextLog log) {
|
||||
if ((getSelectedCount() == 0) && (CurrentName() == null || (getCurrent() == null))) {
|
||||
log.Writeln_(getPluralDescription() + ":");
|
||||
log.Writeln_("Отсутствуют отмеченные объекты, или текущий объект!");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public void dropCurrent() {
|
||||
MainModule_.instance.set(CurrentName(), null);
|
||||
}
|
||||
public D getCurrent() {
|
||||
return (D) MainModule_.instance.get(CurrentName());
|
||||
}
|
||||
public Vector<D> getSelectedOrCurrent() {
|
||||
Vector<D> res = new Vector<>();
|
||||
if (getSelectedCount() > 0)
|
||||
res = getSelectedItems();
|
||||
else {
|
||||
if ((CurrentName() != null) && (getCurrent() != null)) {
|
||||
res.add(getCurrent());
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
public Vector<Object> getSelectedOrCurrentKeys() {
|
||||
Vector<Object> res = new Vector<>();
|
||||
if (getSelectedCount() > 0)
|
||||
res = getSelectedKeys();
|
||||
else {
|
||||
if ((CurrentName() != null) && (getCurrent() != null)) {
|
||||
res.add(getCurrent().getPK());
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user