продолжение рефакторинга таблиц. перевод меню баров в интерфейс
This commit is contained in:
@@ -6,7 +6,6 @@ import Common.Passes.PassCode_;
|
||||
import Common.Utils.TextLog;
|
||||
import Common.Visual.DataSetControlForm;
|
||||
import Common.Visual.DataSetFilter;
|
||||
import Common.Visual.FilterInterface;
|
||||
import Common.Visual.Menus.DataMenuBar;
|
||||
import Common.Visual.Tables.ColumnFilter;
|
||||
import Common.Visual.UI;
|
||||
@@ -14,7 +13,6 @@ import Common.Visual.Windows.Dialog.DBObjectDialog;
|
||||
import Common.Visual.Windows.Dialog.DialogFields;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Vector;
|
||||
@@ -28,16 +26,9 @@ public class DataSet<K, D extends DBObject> extends DataSetAnchestor {
|
||||
public Class<D> d; //класс объектов.
|
||||
public LinkedHashMap<K, D> Data = new LinkedHashMap<>(); //наполнение
|
||||
//-
|
||||
protected DataSetControlForm ui= null;
|
||||
public DataSetControlForm getUI() {
|
||||
return ui;
|
||||
}
|
||||
public void setUI(DataSetControlForm ui_in) {
|
||||
this.ui = ui_in;
|
||||
}
|
||||
//-
|
||||
public LinkedHashMap<Integer, ColumnFilter> columnsFilters = new LinkedHashMap<>(); //текстовые фильтры столбцов
|
||||
protected FilterInterface f_ui; // отображение количества объектов
|
||||
//-
|
||||
protected DataSetControlForm ui = null;
|
||||
//--
|
||||
protected Vector<DataSetFilter<D>> filters = new Vector<>();
|
||||
//--
|
||||
@@ -46,39 +37,14 @@ public class DataSet<K, D extends DBObject> extends DataSetAnchestor {
|
||||
d = d_in;
|
||||
Name = d.getSimpleName();
|
||||
}
|
||||
public DataSetControlForm getUI() {
|
||||
return ui;
|
||||
}
|
||||
protected void createFilters() {
|
||||
}
|
||||
public boolean hasMenuBar() {
|
||||
return true;
|
||||
}
|
||||
public DataMenuBar createMenuBar() {
|
||||
return new DataMenuBar(getPluralDescription());
|
||||
}
|
||||
public void mountUI(JPanel mountPanel_in) {
|
||||
UI.Clear(mountPanel_in);
|
||||
//-->
|
||||
setUI(createUI(mountPanel_in));
|
||||
//-->
|
||||
if (hasMenuBar()) {
|
||||
try {
|
||||
DataMenuBar bar = null;
|
||||
if (!MainModule_.instance.getUI().menuBars.containsKey(getClass())) {
|
||||
bar = createMenuBar();
|
||||
if (getUI().hasCheckBox())
|
||||
bar.createSelectionButtons(this);
|
||||
MainModule_.instance.getUI().menuBars.put(getClass(), bar);
|
||||
} else {
|
||||
bar = MainModule_.instance.getUI().menuBars.get(getClass());
|
||||
}
|
||||
mountPanel_in.add(bar, BorderLayout.NORTH);
|
||||
//--
|
||||
setFilterUI(count -> MainModule_.instance.getUI().menuBars.get(getClass()).countLabel.setText(String.valueOf(count)));
|
||||
//--
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
//----
|
||||
ui = createUI(mountPanel_in);
|
||||
createFilters();
|
||||
if (!filters.isEmpty()) {
|
||||
DataMenuBar menuBar = MainModule_.instance.getUI().menuBars.get(getClass());
|
||||
@@ -86,31 +52,23 @@ public class DataSet<K, D extends DBObject> extends DataSetAnchestor {
|
||||
menuBar.addMenus(filter.menu);
|
||||
}
|
||||
}
|
||||
public DataSetControlForm getUi() {
|
||||
return getUI();
|
||||
}
|
||||
public void setFilterUI(FilterInterface ui_in) {
|
||||
f_ui = ui_in;
|
||||
}
|
||||
public void ClearUI() {
|
||||
if ((getUI() != null) && getUI().isShown()) {
|
||||
getUI().ClearSelection();
|
||||
getUI().Clear();
|
||||
if (f_ui != null)
|
||||
f_ui.ShowNoMatches();
|
||||
if ((ui != null) && ui.isShown()) {
|
||||
ui.ClearSelection();
|
||||
ui.Clear();
|
||||
}
|
||||
}
|
||||
public void RefreshUI() {
|
||||
if (getUI() != null) getUI().Refresh();
|
||||
if (ui != null) ui.Refresh();
|
||||
}
|
||||
public int getRowCountUI() {
|
||||
return getUI().getRowCount();
|
||||
return ui.getRowCount();
|
||||
}
|
||||
public void SetCurrentObjectUI(Object pk) {
|
||||
if (getUI() != null) {
|
||||
if (ui != null) {
|
||||
//todo возможно проверить, что текущий объект уже соответствует ключу, и если да, то ничего делать.
|
||||
getUI().ClearSelection(); //сброс текущего объекта и всего что с ним связано.
|
||||
getUI().Select(pk);
|
||||
ui.ClearSelection(); //сброс текущего объекта и всего что с ним связано.
|
||||
ui.Select(pk);
|
||||
}
|
||||
}
|
||||
public String[] getUIColumnNames() {
|
||||
@@ -120,7 +78,7 @@ public class DataSet<K, D extends DBObject> extends DataSetAnchestor {
|
||||
return null;
|
||||
}
|
||||
public boolean hasUI() {
|
||||
return getUI() != null;
|
||||
return ui != null;
|
||||
}
|
||||
public void SelectAll(boolean flag) {
|
||||
for (D object : Data.values()) {
|
||||
@@ -237,10 +195,8 @@ public class DataSet<K, D extends DBObject> extends DataSetAnchestor {
|
||||
for (DataSetFilter<D> filter : filters)
|
||||
filter.Drop();
|
||||
//--
|
||||
if (getUI() != null) {
|
||||
getUI().Show();
|
||||
if (f_ui != null)
|
||||
f_ui.ShowMatchesCount(getRowCountUI());
|
||||
if (ui != null) {
|
||||
ui.Show();
|
||||
}
|
||||
//--
|
||||
for (DataSetFilter<D> filter : filters)
|
||||
@@ -250,10 +206,8 @@ public class DataSet<K, D extends DBObject> extends DataSetAnchestor {
|
||||
for (DataSetFilter<D> filter : filters)
|
||||
filter.Drop();
|
||||
//--
|
||||
if (getUI() != null) {
|
||||
getUI().Show(key);
|
||||
if (f_ui != null)
|
||||
f_ui.ShowMatchesCount(getRowCountUI());
|
||||
if (ui != null) {
|
||||
ui.Show(key);
|
||||
}
|
||||
//--
|
||||
for (DataSetFilter<D> filter : filters)
|
||||
@@ -326,7 +280,7 @@ public class DataSet<K, D extends DBObject> extends DataSetAnchestor {
|
||||
if (hasUI()) {
|
||||
Object lastPk = selections.get(getClass());
|
||||
if ((CurrentName() != null) && (lastPk != null)) {
|
||||
getUI().Select(lastPk);
|
||||
ui.Select(lastPk);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,18 +5,22 @@ import javax.swing.*;
|
||||
import java.awt.*;
|
||||
//класс, представляющий собой прокручиваемую панель, на которой лежит нечто.
|
||||
public class ControlForm<C extends Component> {
|
||||
protected C control = null;
|
||||
JPanel mountPanel = null; //панель на которую монтируется UI.помимо контрола может содержать меню сверху.
|
||||
JPanel scrollPanel = null; //панель на которой лежит скролл.
|
||||
JScrollPane scroll = null; //панель прокрутки в которую встроен контрол
|
||||
protected C control = null;
|
||||
Class<C> control_class = null;
|
||||
public C getControl(){return control;}
|
||||
public ControlForm(Class<C> class_in, JPanel mountPanel_in) {
|
||||
control_class = class_in;
|
||||
mountPanel = mountPanel_in;
|
||||
mountPanel.add((scrollPanel = new JPanel(new BorderLayout())), BorderLayout.CENTER);
|
||||
}
|
||||
public JPanel getMountPanel(){return mountPanel;} //todo осталось только в projectForm, вывести
|
||||
public C getControl() {
|
||||
return control;
|
||||
}
|
||||
public JPanel getMountPanel() {
|
||||
return mountPanel;
|
||||
} //todo осталось только в projectForm, вывести
|
||||
//новое отображение предполагает полную перерисовку контрола.(?)
|
||||
public void Show() {
|
||||
Clear();
|
||||
|
||||
@@ -7,6 +7,7 @@ import Common.Database.Tables.DataSet;
|
||||
import Common.Database.Tables.FKBehaviour;
|
||||
import Common.MainModule_;
|
||||
import Common.Utils.Utils_;
|
||||
import Common.Visual.Menus.DataMenuBar;
|
||||
import Common.Visual.Menus.TableMenu;
|
||||
import Common.Visual.Tables.ColumnInfo;
|
||||
import Common.Visual.Tables.DBObjectSelectionRenderer;
|
||||
@@ -26,15 +27,35 @@ import java.util.Vector;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
public class DataSetControlForm extends ControlForm<DataTable> {
|
||||
|
||||
protected DataSet dataSource;
|
||||
protected int current_row_i;
|
||||
protected DataSet dataSource; //источник данных
|
||||
protected DataMenuBar bar = null; //верхняя панель меню
|
||||
protected int current_row_i; //индекс текущей строки.
|
||||
protected boolean events_on = true;
|
||||
protected String colNamesAndSizes = "";
|
||||
protected Vector<ColumnInfo> columns = new Vector<>();
|
||||
protected Vector<ColumnInfo> columns = new Vector<>(); //информация о столбцах и их оформлении
|
||||
FilterInterface f_ui; // отображение количества объектов ( todo слить с баром ?)
|
||||
public DataSetControlForm(DataSet dataSource_in, JPanel mountPanel_in) {
|
||||
super(DataTable.class, mountPanel_in);
|
||||
dataSource = dataSource_in;
|
||||
//--
|
||||
if (hasMenuBar()) {
|
||||
try {
|
||||
if (!MainModule_.instance.getUI().menuBars.containsKey(dataSource.getClass())) {
|
||||
bar = createMenuBar();
|
||||
if (hasCheckBox())
|
||||
bar.createSelectionButtons(dataSource);
|
||||
MainModule_.instance.getUI().menuBars.put(dataSource.getClass(), bar);
|
||||
} else {
|
||||
bar = MainModule_.instance.getUI().menuBars.get(dataSource.getClass());
|
||||
}
|
||||
mountPanel.add(bar, BorderLayout.NORTH);
|
||||
//--
|
||||
f_ui = (count -> bar.countLabel.setText(String.valueOf(count)));
|
||||
//--
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
public void SaveColumns() {
|
||||
if (MainModule_.instance.getDb() != null) {
|
||||
@@ -58,9 +79,6 @@ public class DataSetControlForm extends ControlForm<DataTable> {
|
||||
}
|
||||
}
|
||||
}
|
||||
public boolean hasCheckBox() {
|
||||
return false;
|
||||
}
|
||||
private Vector<String> getHeaders() {
|
||||
return columns.stream().map(ColumnInfo::getName).collect(Collectors.toCollection(Vector::new));
|
||||
}
|
||||
@@ -254,10 +272,18 @@ public class DataSetControlForm extends ControlForm<DataTable> {
|
||||
}
|
||||
}
|
||||
}
|
||||
protected DataMenuBar createMenuBar() {
|
||||
return new DataMenuBar(dataSource.getPluralDescription());
|
||||
}
|
||||
@Override
|
||||
protected void redrawControl() {
|
||||
control.CorrectSizes();
|
||||
}
|
||||
@Override
|
||||
public void Show() {
|
||||
super.Show();
|
||||
if (f_ui != null) f_ui.ShowMatchesCount(getRowCount());
|
||||
}
|
||||
public void Show(Object pk) {
|
||||
Show();
|
||||
Select(pk);
|
||||
@@ -267,8 +293,12 @@ public class DataSetControlForm extends ControlForm<DataTable> {
|
||||
control.SelectRowByPK(pk);
|
||||
}
|
||||
public void ClearSelection() {
|
||||
if (isShown())
|
||||
control.clearSelection(); //строка сбросится сама. благодаря сбросу события выбора
|
||||
if (isShown()) control.clearSelection(); //строка сбросится сама. благодаря сбросу события выбора
|
||||
}
|
||||
@Override
|
||||
public void Clear() {
|
||||
super.Clear();
|
||||
if (f_ui != null) f_ui.ShowNoMatches();
|
||||
}
|
||||
public int getRowCount() {
|
||||
return control.getRowCount();
|
||||
@@ -303,5 +333,13 @@ public class DataSetControlForm extends ControlForm<DataTable> {
|
||||
}
|
||||
}
|
||||
}
|
||||
public void MouseAction2() throws Exception{}
|
||||
public void MouseAction2() throws Exception {
|
||||
}
|
||||
//-
|
||||
public boolean hasCheckBox() {
|
||||
return false;
|
||||
}
|
||||
public boolean hasMenuBar() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,28 +45,28 @@ public class ColumnFilter {
|
||||
};
|
||||
popup.add(textField);
|
||||
//--
|
||||
dataSet.getUi().getControl().getColumnModel().getColumn(columnIndex).setHeaderRenderer((table, value, isSelected, hasFocus, row, column1) -> new JLabel() {
|
||||
dataSet.getUI().getControl().getColumnModel().getColumn(columnIndex).setHeaderRenderer((table, value, isSelected, hasFocus, row, column1) -> new JLabel() {
|
||||
{
|
||||
setIcon(Utils_.getIcon("/Common/icons/Filter.png"));
|
||||
setForeground(dataSet.getUi().getControl().getTableHeader().getForeground());
|
||||
setBackground(dataSet.getUi().getControl().getTableHeader().getBackground());
|
||||
setFont(dataSet.getUi().getControl().getTableHeader().getFont());
|
||||
setForeground(dataSet.getUI().getControl().getTableHeader().getForeground());
|
||||
setBackground(dataSet.getUI().getControl().getTableHeader().getBackground());
|
||||
setFont(dataSet.getUI().getControl().getTableHeader().getFont());
|
||||
setBorder(new MatteBorder(0, 0, 1, 1, Color.DARK_GRAY));
|
||||
setText("текст : " + dataSet.getColumnFilterValue(columnIndex));
|
||||
}
|
||||
});
|
||||
//--
|
||||
dataSet.getUi().getControl().getTableHeader().addMouseListener(new MouseAdapter() {
|
||||
dataSet.getUI().getControl().getTableHeader().addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent event) {
|
||||
if (event.getClickCount() == 1) {
|
||||
int columnIndex = dataSet.getUi().getControl().getTableHeader().columnAtPoint(event.getPoint());
|
||||
int columnIndex = dataSet.getUI().getControl().getTableHeader().columnAtPoint(event.getPoint());
|
||||
if (dataSet.columnsFilters.containsKey(columnIndex)) {
|
||||
Rectangle columnRectangle = dataSet.getUi().getControl().getTableHeader().getHeaderRect(columnIndex);
|
||||
Rectangle columnRectangle = dataSet.getUI().getControl().getTableHeader().getHeaderRect(columnIndex);
|
||||
Dimension d = new Dimension(columnRectangle.width - 72, columnRectangle.height - 1);
|
||||
popup.setPreferredSize(d);
|
||||
popup.setMaximumSize(d);
|
||||
popup.show(dataSet.getUi().getControl().getTableHeader(), columnRectangle.x + 72, 0);
|
||||
popup.show(dataSet.getUI().getControl().getTableHeader(), columnRectangle.x + 72, 0);
|
||||
textField.setText(dataSet.getColumnFilterValue(columnIndex).toString());
|
||||
textField.requestFocusInWindow();
|
||||
textField.selectAll();
|
||||
|
||||
@@ -5,7 +5,7 @@ import Common.Utils.Utils_;
|
||||
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import javax.swing.tree.TreePath;
|
||||
public class DataTree extends StyledTree{
|
||||
public class DataTree extends StyledTree {
|
||||
public DataTree(DefaultMutableTreeNode root_in) {
|
||||
super(root_in);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
package Common.Visual.Trees;
|
||||
import Common.Visual.ControlForm;
|
||||
import Common.Visual.UI;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
public class TreeForm<C extends StyledTree> extends ControlForm<C> {
|
||||
public TreeForm(Class<C> class_in, JPanel mountPanel_in) {
|
||||
super(class_in, mountPanel_in);
|
||||
|
||||
Reference in New Issue
Block a user