продолжение рефакторинга таблиц. перевод меню баров в интерфейс
This commit is contained in:
@@ -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