рефакторинг сохранения форм. не было единого интерфейса
This commit is contained in:
@@ -2,6 +2,7 @@ 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;
|
||||
@@ -14,7 +15,6 @@ import Common.Visual.Tables.DBObjectSelector;
|
||||
import Common.Visual.Tables.DataTable;
|
||||
import Common.Visual.Tables.Grid.GridAnchestor;
|
||||
import _VisualDVM.Global;
|
||||
import _VisualDVM.GlobalData.Grid.TableVisualData;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.table.TableColumn;
|
||||
|
||||
10
src/Common/Visual/FormWithSplitters.java
Normal file
10
src/Common/Visual/FormWithSplitters.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package Common.Visual;
|
||||
import Common.MainModule_;
|
||||
public interface FormWithSplitters {
|
||||
default void LoadSplitters() {
|
||||
MainModule_.instance.getDb().splitters.Load(this);
|
||||
}
|
||||
default void SaveSplitters() {
|
||||
MainModule_.instance.getDb().splitters.Save(this);
|
||||
}
|
||||
}
|
||||
42
src/Common/Visual/SavedForm.java
Normal file
42
src/Common/Visual/SavedForm.java
Normal file
@@ -0,0 +1,42 @@
|
||||
package Common.Visual;
|
||||
import Common.Database.Objects.DBForm.DBForm;
|
||||
import Common.MainModule_;
|
||||
|
||||
import java.awt.*;
|
||||
public interface SavedForm {
|
||||
default String getFormKey() {
|
||||
return null;
|
||||
}
|
||||
int getDefaultWidth();
|
||||
int getDefaultHeight();
|
||||
default void LoadWindowParameters() {
|
||||
if (this instanceof Window) {
|
||||
Window window = (Window) this;
|
||||
if ((getFormKey() != null) && MainModule_.instance.getDb().forms.Data.containsKey(getFormKey())) {
|
||||
DBForm dbForm = MainModule_.instance.getDb().forms.Data.get(getFormKey());
|
||||
dbForm.Apply(window);
|
||||
return;
|
||||
} else {
|
||||
window.setSize(getDefaultWidth(), getDefaultHeight());
|
||||
}
|
||||
}
|
||||
}
|
||||
default void SaveWindowParameters() {
|
||||
if ((this instanceof Window) && (getFormKey() != null)) {
|
||||
Window window = (Window) this;
|
||||
DBForm dbForm = null;
|
||||
try {
|
||||
if (MainModule_.instance.getDb().forms.containsKey(getFormKey())) {
|
||||
dbForm = MainModule_.instance.getDb().forms.get(getFormKey());
|
||||
dbForm.Fill(window);
|
||||
MainModule_.instance.getDb().Update(dbForm);
|
||||
} else {
|
||||
dbForm = new DBForm(getFormKey(), window);
|
||||
MainModule_.instance.getDb().Insert(dbForm);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@ public class StyledTree extends JTree implements ThemeElement {
|
||||
setFont(MainModule_.instance.getUI().getTheme().Fonts.get(VisualiserFonts.TreePlain));
|
||||
setToggleClickCount(0); //отключение сворачивание разворачивания по двойному клику
|
||||
//--
|
||||
if (getRendererClass()!=null)
|
||||
if (getRendererClass() != null)
|
||||
setCellRenderer(MainModule_.instance.getUI().getTreeRenderer(getRendererClass()));
|
||||
//--
|
||||
getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
|
||||
|
||||
@@ -8,7 +8,7 @@ import javax.swing.text.DefaultFormatter;
|
||||
import java.awt.*;
|
||||
public class UI {
|
||||
public static boolean isActive() {
|
||||
return (MainModule_.instance!=null)&&MainModule_.instance.hasUI();
|
||||
return (MainModule_.instance != null) && MainModule_.instance.hasUI();
|
||||
}
|
||||
//---
|
||||
public static void Clear(Container container) {
|
||||
|
||||
@@ -13,7 +13,6 @@ import javax.swing.tree.TreeCellRenderer;
|
||||
import java.awt.*;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Stack;
|
||||
|
||||
public class UIModule_ {
|
||||
public LinkedHashMap<Class<? extends DataSet>, DataMenuBar> menuBars = new LinkedHashMap<>();
|
||||
public Stack<Component> windowsStack = new Stack<>();
|
||||
@@ -92,45 +91,42 @@ public class UIModule_ {
|
||||
public TableCellRenderer getTableRenderer(Class key) {
|
||||
TableCellRenderer res = null;
|
||||
if (tableRenderers.containsKey(key))
|
||||
res= tableRenderers.get(key);
|
||||
res = tableRenderers.get(key);
|
||||
else {
|
||||
try {
|
||||
res = (TableCellRenderer) key.newInstance();
|
||||
}
|
||||
catch (Exception ex){
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
tableRenderers.put(key,res);
|
||||
tableRenderers.put(key, res);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
public TableCellEditor getTableEditor(Class key) {
|
||||
TableCellEditor res = null;
|
||||
if (tableEditors.containsKey(key))
|
||||
res= tableEditors.get(key);
|
||||
res = tableEditors.get(key);
|
||||
else {
|
||||
try {
|
||||
res = (TableCellEditor) key.newInstance();
|
||||
}
|
||||
catch (Exception ex){
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
tableEditors.put(key,res);
|
||||
tableEditors.put(key, res);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
public TreeCellRenderer getTreeRenderer(Class key) {
|
||||
TreeCellRenderer res = null;
|
||||
if (treeRenderers.containsKey(key))
|
||||
res= treeRenderers.get(key);
|
||||
res = treeRenderers.get(key);
|
||||
else {
|
||||
try {
|
||||
res = (TreeCellRenderer) key.newInstance();
|
||||
}
|
||||
catch (Exception ex){
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
treeRenderers.put(key,res);
|
||||
treeRenderers.put(key, res);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
package Common.Visual.Windows;
|
||||
import Common.Database.Objects.DBForm.DBForm;
|
||||
import Common.Utils.Utils_;
|
||||
import Common.Visual.SavedForm;
|
||||
import Common.Visual.Themes.ThemeElement;
|
||||
import _VisualDVM.Global;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
public abstract class Form extends JFrame implements ThemeElement {
|
||||
private DBForm dbInfo = null;
|
||||
public abstract class Form extends JFrame implements ThemeElement, SavedForm {
|
||||
public Form() {
|
||||
if (getIconPath() != null) setIconImage(Utils_.getIcon(getIconPath()).getImage());
|
||||
SetListener();
|
||||
@@ -27,9 +25,6 @@ public abstract class Form extends JFrame implements ThemeElement {
|
||||
public String getUTitleText() {
|
||||
return "";
|
||||
}
|
||||
protected String getFormKey() {
|
||||
return null;
|
||||
}
|
||||
protected void SetListener() {
|
||||
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
|
||||
addWindowListener(new WindowAdapter() {
|
||||
@@ -39,9 +34,11 @@ public abstract class Form extends JFrame implements ThemeElement {
|
||||
}
|
||||
});
|
||||
}
|
||||
@Override
|
||||
public int getDefaultWidth() {
|
||||
return 800;
|
||||
}
|
||||
@Override
|
||||
public int getDefaultHeight() {
|
||||
return 450;
|
||||
}
|
||||
@@ -72,25 +69,6 @@ public abstract class Form extends JFrame implements ThemeElement {
|
||||
}
|
||||
public void AfterClose() {
|
||||
}
|
||||
public void LoadWindowParameters() throws Exception {
|
||||
if (getFormKey() != null)
|
||||
if (Global.mainModule.getDb().forms.Data.containsKey(getFormKey())) {
|
||||
dbInfo = Global.mainModule.getDb().forms.Data.get(getFormKey());
|
||||
dbInfo.Apply(this);
|
||||
return;
|
||||
}
|
||||
setSize(getDefaultWidth(), getDefaultHeight());
|
||||
setLocationRelativeTo(getRelative());
|
||||
}
|
||||
public void SaveWindowParameters() throws Exception {
|
||||
if (getFormKey() != null) {
|
||||
if (dbInfo != null) {
|
||||
dbInfo.Init(this);
|
||||
Global.mainModule.getDb().Update(dbInfo);
|
||||
} else
|
||||
Global.mainModule.getDb().Insert(new DBForm(getFormKey(), this));
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void applyTheme() {
|
||||
//todo -> применение темы.
|
||||
|
||||
Reference in New Issue
Block a user