продолжение рефакторинга. создал предка для класса current
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package Common_old;
|
||||
import Common.CurrentAnchestor;
|
||||
import Common.Database.Objects.iDBObject;
|
||||
import _VisualDVM.Syntax.VisualiserTheme;
|
||||
import Common.Utils.TextLog;
|
||||
import GlobalData.Account.Account;
|
||||
import GlobalData.Compiler.Compiler;
|
||||
import GlobalData.Machine.Machine;
|
||||
@@ -26,15 +26,13 @@ import Visual_DVM_2021.Passes.UI.PassForm;
|
||||
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import java.io.File;
|
||||
import java.util.LinkedHashMap;
|
||||
public enum Current {
|
||||
Undefined,
|
||||
public enum Current implements CurrentAnchestor {
|
||||
//--
|
||||
DVMPackage,
|
||||
SapforPackage,
|
||||
//--
|
||||
ServerSapfor,
|
||||
SapforEtalonVersion,//самый левый пакет
|
||||
SapforEtalonVersion,
|
||||
SapforVersion,
|
||||
//--
|
||||
//--
|
||||
@@ -109,159 +107,155 @@ public enum Current {
|
||||
DVMRunTask,
|
||||
SapforSettings,
|
||||
SapforSettingsCommand,
|
||||
DVMSettings,
|
||||
;
|
||||
//-
|
||||
private static final LinkedHashMap<Current, Object> objects = new LinkedHashMap<>();
|
||||
DVMSettings;
|
||||
public static Mode mode;
|
||||
public static boolean hasUI() {
|
||||
return Current.mode.equals(Current.Mode.Normal);
|
||||
}
|
||||
public static boolean HasProject() {
|
||||
return get(Project) != null;
|
||||
return CurrentAnchestor.get(Project) != null;
|
||||
}
|
||||
public static boolean HasFile() {
|
||||
return get(File) != null;
|
||||
return CurrentAnchestor.get(File) != null;
|
||||
}
|
||||
public static boolean HasSelectedFile() {
|
||||
return get(SelectedFile) != null;
|
||||
return CurrentAnchestor.get(SelectedFile) != null;
|
||||
}
|
||||
public static boolean HasAccount() {
|
||||
return get(Account) != null;
|
||||
return CurrentAnchestor.get(Account) != null;
|
||||
}
|
||||
public static boolean HasMachine() {
|
||||
return get(Machine) != null;
|
||||
return CurrentAnchestor.get(Machine) != null;
|
||||
}
|
||||
public static boolean HasUser() {
|
||||
return get(User) != null;
|
||||
return CurrentAnchestor.get(User) != null;
|
||||
}
|
||||
public static boolean HasCompiler() {
|
||||
return get(Compiler) != null;
|
||||
return CurrentAnchestor.get(Compiler) != null;
|
||||
}
|
||||
public static boolean HasRemoteFile() {
|
||||
return get(RemoteFile) != null;
|
||||
return CurrentAnchestor.get(RemoteFile) != null;
|
||||
}
|
||||
public static boolean HasMakefile() {
|
||||
return get(Makefile) != null;
|
||||
return CurrentAnchestor.get(Makefile) != null;
|
||||
}
|
||||
public static boolean HasRunConfiguration() {
|
||||
return get(RunConfiguration) != null;
|
||||
return CurrentAnchestor.get(RunConfiguration) != null;
|
||||
}
|
||||
public static boolean HasCompilationTask() {
|
||||
return get(CompilationTask) != null;
|
||||
return CurrentAnchestor.get(CompilationTask) != null;
|
||||
}
|
||||
public static boolean HasRunTask() {
|
||||
return get(RunTask) != null;
|
||||
return CurrentAnchestor.get(RunTask) != null;
|
||||
}
|
||||
public static boolean HasPassForm() {
|
||||
return get(PassForm) != null;
|
||||
return CurrentAnchestor.get(PassForm) != null;
|
||||
}
|
||||
public static boolean HasProjectView() {
|
||||
return get(ProjectView) != null;
|
||||
return CurrentAnchestor.get(ProjectView) != null;
|
||||
}
|
||||
//для быстрого доступа на чтение. слишком много на нем завязано.
|
||||
public static SapforSettings getSapforSettings() {
|
||||
return (SapforSettings) get(SapforSettings);
|
||||
return (SapforSettings) CurrentAnchestor.get(SapforSettings);
|
||||
}
|
||||
public static boolean HasSapforSettings() {
|
||||
return get(SapforSettings) != null;
|
||||
return CurrentAnchestor.get(SapforSettings) != null;
|
||||
}
|
||||
|
||||
public static db_project_info getProject() {
|
||||
return (db_project_info) get(Project);
|
||||
return (db_project_info) CurrentAnchestor.get(Project);
|
||||
}
|
||||
public static DBProjectFile getFile() {
|
||||
return (DBProjectFile) get(File);
|
||||
return (DBProjectFile) CurrentAnchestor.get(File);
|
||||
}
|
||||
public static Repository.Component.Component getComponent() {
|
||||
return (Repository.Component.Component) get(Component);
|
||||
return (Repository.Component.Component) CurrentAnchestor.get(Component);
|
||||
}
|
||||
public static Repository.BugReport.BugReport getBugReport() {
|
||||
return (BugReport) get(BugReport);
|
||||
return (BugReport) CurrentAnchestor.get(BugReport);
|
||||
}
|
||||
public static db_project_info getRoot() {
|
||||
return (db_project_info) get(Root);
|
||||
return (db_project_info) CurrentAnchestor.get(Root);
|
||||
}
|
||||
public static boolean HasRoot() {
|
||||
return get(Root) != null;
|
||||
return CurrentAnchestor.get(Root) != null;
|
||||
}
|
||||
public static db_project_info getVersion() {
|
||||
return (db_project_info) get(Version);
|
||||
return (db_project_info) CurrentAnchestor.get(Version);
|
||||
}
|
||||
public static Account getAccount() {
|
||||
return (Account) get(Account);
|
||||
return (Account) CurrentAnchestor.get(Account);
|
||||
}
|
||||
public static boolean HasSubscriber() {
|
||||
return get(Current.Subscriber) != null;
|
||||
return CurrentAnchestor.get(Current.Subscriber) != null;
|
||||
}
|
||||
public static Repository.Subscribes.Subscriber getSubscriber() {
|
||||
return (Subscriber) get(Current.Subscriber);
|
||||
return (Subscriber) CurrentAnchestor.get(Current.Subscriber);
|
||||
}
|
||||
public static Machine getMachine() {
|
||||
return (Machine) get(Current.Machine);
|
||||
return (Machine) CurrentAnchestor.get(Current.Machine);
|
||||
}
|
||||
public static User getUser() {
|
||||
return (User) get(Current.User);
|
||||
return (User) CurrentAnchestor.get(Current.User);
|
||||
}
|
||||
public static Compiler getCompiler() {
|
||||
return (Compiler) get(Current.Compiler);
|
||||
return (Compiler) CurrentAnchestor.get(Current.Compiler);
|
||||
}
|
||||
public static CompilationTask getCompilationTask() {
|
||||
return (CompilationTask) get(Current.CompilationTask);
|
||||
return (CompilationTask) CurrentAnchestor.get(Current.CompilationTask);
|
||||
}
|
||||
public static RunTask getRunTask() {
|
||||
return (RunTask) get(Current.RunTask);
|
||||
return (RunTask) CurrentAnchestor.get(Current.RunTask);
|
||||
}
|
||||
public static RemoteFile getRemoteFile() {
|
||||
return (RemoteFile) get(Current.RemoteFile);
|
||||
return (RemoteFile) CurrentAnchestor.get(Current.RemoteFile);
|
||||
}
|
||||
public static Makefile getMakefile() {
|
||||
return (Makefile) get(Current.Makefile);
|
||||
return (Makefile) CurrentAnchestor.get(Current.Makefile);
|
||||
}
|
||||
public static Module getModule() {
|
||||
return (Module) get(Current.Module);
|
||||
return (Module) CurrentAnchestor.get(Current.Module);
|
||||
}
|
||||
public static RunConfiguration getRunConfiguration() {
|
||||
return (RunConfiguration) get(Current.RunConfiguration);
|
||||
return (RunConfiguration) CurrentAnchestor.get(Current.RunConfiguration);
|
||||
}
|
||||
public static Repository.Component.Sapfor.Sapfor getSapfor() {
|
||||
return (Repository.Component.Sapfor.Sapfor) get(Current.Sapfor);
|
||||
return (Repository.Component.Sapfor.Sapfor) CurrentAnchestor.get(Current.Sapfor);
|
||||
}
|
||||
public static boolean HasGroup() {
|
||||
return get(Current.Group) != null;
|
||||
return CurrentAnchestor.get(Current.Group) != null;
|
||||
}
|
||||
public static TestingSystem.Common.Group.Group getGroup() {
|
||||
return (TestingSystem.Common.Group.Group) get(Current.Group);
|
||||
return (TestingSystem.Common.Group.Group) CurrentAnchestor.get(Current.Group);
|
||||
}
|
||||
//--
|
||||
public static boolean HasConfiguration() {
|
||||
return get(Current.DVMConfiguration) != null;
|
||||
return CurrentAnchestor.get(Current.DVMConfiguration) != null;
|
||||
}
|
||||
public static DVMConfiguration getDVMConfiguration() {
|
||||
return (DVMConfiguration) get(Current.DVMConfiguration);
|
||||
return (DVMConfiguration) CurrentAnchestor.get(Current.DVMConfiguration);
|
||||
}
|
||||
public static SapforConfiguration getSapforConfiguration() {
|
||||
return (TestingSystem.SAPFOR.SapforConfiguration.SapforConfiguration) get(Current.SapforConfiguration);
|
||||
return (TestingSystem.SAPFOR.SapforConfiguration.SapforConfiguration) CurrentAnchestor.get(Current.SapforConfiguration);
|
||||
}
|
||||
//--
|
||||
public static Test getTest() {
|
||||
return (TestingSystem.Common.Test.Test) get(Current.Test);
|
||||
return (TestingSystem.Common.Test.Test) CurrentAnchestor.get(Current.Test);
|
||||
}
|
||||
public static boolean HasTest() {
|
||||
return get(Current.Test) != null;
|
||||
return CurrentAnchestor.get(Current.Test) != null;
|
||||
}
|
||||
public static boolean HasVersion() {
|
||||
return get(Current.Version) != null;
|
||||
return CurrentAnchestor.get(Current.Version) != null;
|
||||
}
|
||||
public static RemoteFile getComponentServerBackup() {
|
||||
return (RemoteFile) get(Current.ComponentServerBackup);
|
||||
return (RemoteFile) CurrentAnchestor.get(Current.ComponentServerBackup);
|
||||
}
|
||||
public static boolean HasComponentServerBackup() {
|
||||
return get(Current.ComponentServerBackup) != null;
|
||||
return CurrentAnchestor.get(Current.ComponentServerBackup) != null;
|
||||
}
|
||||
//-
|
||||
public static DefaultMutableTreeNode getProjectNode() {
|
||||
return (DefaultMutableTreeNode) get(Current.ProjectNode);
|
||||
return (DefaultMutableTreeNode) CurrentAnchestor.get(Current.ProjectNode);
|
||||
}
|
||||
public static DefaultMutableTreeNode getProjectCurrentParentNode() {
|
||||
DefaultMutableTreeNode node = Current.getProjectNode();
|
||||
@@ -271,116 +265,100 @@ public enum Current {
|
||||
return (node.getUserObject() instanceof DBProjectFile) ? (DefaultMutableTreeNode) node.getParent() : node;
|
||||
}
|
||||
public static File getSelectedDirectory() {
|
||||
return (File) get(Current.SelectedDirectory);
|
||||
return (File) CurrentAnchestor.get(Current.SelectedDirectory);
|
||||
}
|
||||
public static DBProjectFile getSelectedFile() {
|
||||
return (DBProjectFile) get(Current.SelectedFile);
|
||||
return (DBProjectFile) CurrentAnchestor.get(Current.SelectedFile);
|
||||
}
|
||||
//-
|
||||
public static boolean HasBugReport() {
|
||||
return get(Current.BugReport) != null;
|
||||
return CurrentAnchestor.get(Current.BugReport) != null;
|
||||
}
|
||||
public static PassForm getPassForm() {
|
||||
return (Visual_DVM_2021.Passes.UI.PassForm) get(Current.PassForm);
|
||||
return (Visual_DVM_2021.Passes.UI.PassForm) CurrentAnchestor.get(Current.PassForm);
|
||||
}
|
||||
public static VisualiserTheme getTheme() {
|
||||
return (VisualiserTheme) get(Current.Theme);
|
||||
return (VisualiserTheme) CurrentAnchestor.get(Current.Theme);
|
||||
}
|
||||
//--------------------------------------------------------------------------------
|
||||
public static ParallelRegion getParallelRegion() {
|
||||
return (ParallelRegion) get(Current.ParallelRegion);
|
||||
return (ParallelRegion) CurrentAnchestor.get(Current.ParallelRegion);
|
||||
}
|
||||
public static boolean HasParallelRegion() {
|
||||
return get(Current.ParallelRegion) != null;
|
||||
return CurrentAnchestor.get(Current.ParallelRegion) != null;
|
||||
}
|
||||
public static boolean HasFunction() {
|
||||
return get(Current.Function) != null;
|
||||
return CurrentAnchestor.get(Current.Function) != null;
|
||||
}
|
||||
public static boolean HasSelectedFunction() {
|
||||
return get(Current.SelectedFunction) != null;
|
||||
return CurrentAnchestor.get(Current.SelectedFunction) != null;
|
||||
}
|
||||
public static FuncInfo getFunction() {
|
||||
return (FuncInfo) get(Current.Function);
|
||||
return (FuncInfo) CurrentAnchestor.get(Current.Function);
|
||||
}
|
||||
public static FuncInfo getSelectionFunction() {
|
||||
return (FuncInfo) get(Current.SelectedFunction);
|
||||
return (FuncInfo) CurrentAnchestor.get(Current.SelectedFunction);
|
||||
}
|
||||
public static boolean HasScenario() {
|
||||
return get(Current.Scenario) != null;
|
||||
return CurrentAnchestor.get(Current.Scenario) != null;
|
||||
}
|
||||
public static db_project_info getPackageVersion() {
|
||||
return (db_project_info) get(Current.PackageVersion);
|
||||
return (db_project_info) CurrentAnchestor.get(Current.PackageVersion);
|
||||
}
|
||||
public static boolean HasPackageVersion() {
|
||||
return get(Current.PackageVersion) != null;
|
||||
return CurrentAnchestor.get(Current.PackageVersion) != null;
|
||||
}
|
||||
public static boolean HasSapforConfiguration() {
|
||||
return get(Current.SapforConfiguration) != null;
|
||||
return CurrentAnchestor.get(Current.SapforConfiguration) != null;
|
||||
}
|
||||
public static ProjectData.ProjectView getProjectView() {
|
||||
return (ProjectData.ProjectView) get(ProjectView);
|
||||
}
|
||||
public static boolean Check(TextLog Log, Current... names) {
|
||||
for (Current name : names)
|
||||
if (get(name) == null)
|
||||
Log.Writeln_(name.getDescription() + " не выбран(а)");
|
||||
return Log.isEmpty();
|
||||
}
|
||||
public static void CreateAll() {
|
||||
for (Current c : values())
|
||||
objects.put(c, null);
|
||||
return (ProjectData.ProjectView) CurrentAnchestor.get(ProjectView);
|
||||
}
|
||||
//-----------------------------------------
|
||||
public static Object get(Current name) {
|
||||
return objects.get(name);
|
||||
}
|
||||
public static Object set(Current name, Object object) {
|
||||
objects.replace(name, object);
|
||||
return object;
|
||||
}
|
||||
//применять только для наследников iDBObject
|
||||
public static boolean CheckID(Current name, int id) {
|
||||
return (get(name) != null) && (((iDBObject) get(name)).id == id);
|
||||
return (CurrentAnchestor.get(name) != null) && (((iDBObject) CurrentAnchestor.get(name)).id == id);
|
||||
}
|
||||
public static boolean HasSapforProfile() {
|
||||
return get(Current.SapforProfile) != null;
|
||||
return CurrentAnchestor.get(Current.SapforProfile) != null;
|
||||
}
|
||||
public static GlobalData.SapforProfile.SapforProfile getSapforProfile() {
|
||||
return (GlobalData.SapforProfile.SapforProfile) get(Current.SapforProfile);
|
||||
return (GlobalData.SapforProfile.SapforProfile) CurrentAnchestor.get(Current.SapforProfile);
|
||||
}
|
||||
//сапфоры установленные на тестовый сервер.
|
||||
public static boolean HasServerSapfor() {
|
||||
return get(Current.ServerSapfor) != null;
|
||||
return CurrentAnchestor.get(Current.ServerSapfor) != null;
|
||||
}
|
||||
public static TestingSystem.SAPFOR.ServerSapfor.ServerSapfor getServerSapfor() {
|
||||
return (TestingSystem.SAPFOR.ServerSapfor.ServerSapfor) get(Current.ServerSapfor);
|
||||
return (TestingSystem.SAPFOR.ServerSapfor.ServerSapfor) CurrentAnchestor.get(Current.ServerSapfor);
|
||||
}
|
||||
public static boolean HasSubscriberWorkspace() {
|
||||
return get(Current.SubscriberWorkspace) != null;
|
||||
return CurrentAnchestor.get(Current.SubscriberWorkspace) != null;
|
||||
}
|
||||
public static Repository.SubscriberWorkspace.SubscriberWorkspace getSubscriberWorkspace() {
|
||||
return (Repository.SubscriberWorkspace.SubscriberWorkspace) get(Current.SubscriberWorkspace);
|
||||
return (Repository.SubscriberWorkspace.SubscriberWorkspace) CurrentAnchestor.get(Current.SubscriberWorkspace);
|
||||
}
|
||||
//----->>
|
||||
public static boolean HasDVMPackage() {
|
||||
return get(Current.DVMPackage) != null;
|
||||
return CurrentAnchestor.get(Current.DVMPackage) != null;
|
||||
}
|
||||
public static TestingSystem.DVM.DVMPackage.DVMPackage getDVMPackage() {
|
||||
return (TestingSystem.DVM.DVMPackage.DVMPackage) get(Current.DVMPackage);
|
||||
return (TestingSystem.DVM.DVMPackage.DVMPackage) CurrentAnchestor.get(Current.DVMPackage);
|
||||
}
|
||||
public static boolean HasSapforPackage() {
|
||||
return get(Current.SapforPackage) != null;
|
||||
return CurrentAnchestor.get(Current.SapforPackage) != null;
|
||||
}
|
||||
public static TestingSystem.SAPFOR.SapforPackage.SapforPackage getSapforPackage() {
|
||||
return (TestingSystem.SAPFOR.SapforPackage.SapforPackage) get(Current.SapforPackage);
|
||||
return (TestingSystem.SAPFOR.SapforPackage.SapforPackage) CurrentAnchestor.get(Current.SapforPackage);
|
||||
}
|
||||
public static boolean HasDVMRunTask() {
|
||||
return get(Current.DVMRunTask) != null;
|
||||
return CurrentAnchestor.get(Current.DVMRunTask) != null;
|
||||
}
|
||||
public static TestingSystem.DVM.DVMTasks.DVMRunTask getDVMRunTask() {
|
||||
return (TestingSystem.DVM.DVMTasks.DVMRunTask) Current.get(Current.DVMRunTask);
|
||||
return (TestingSystem.DVM.DVMTasks.DVMRunTask) CurrentAnchestor.get(Current.DVMRunTask);
|
||||
}
|
||||
//--------------------------------------------
|
||||
@Override
|
||||
public String getDescription() {
|
||||
switch (this) {
|
||||
case DVMSettings:
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
package Common_old.UI.ComboBox;
|
||||
import Common_old.UI.Menus.TextComboBoxMenu;
|
||||
|
||||
import javax.swing.*;
|
||||
public class StyledTextComboBox extends JComboBox<String> {
|
||||
public StyledTextComboBox() {
|
||||
setComponentPopupMenu(new TextComboBoxMenu(this));
|
||||
}
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
package Common_old.UI;
|
||||
import Common.Utils.CommonUtils;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
//класс, представляющий собой прокручиваемую панель, на которой лежит нечто.
|
||||
public class ControlForm<C extends Component> {
|
||||
public C control = null;
|
||||
protected Class<C> control_class;
|
||||
protected JPanel content; //задник.
|
||||
public JScrollPane scroll = null;
|
||||
public ControlForm(Class<C> class_in) {
|
||||
control_class = class_in;
|
||||
setContent(new JPanel(new BorderLayout()));
|
||||
}
|
||||
//нужно будет вывестии сделать нормальные формы для деревьев а не ручное создание.
|
||||
public JPanel getContent() {
|
||||
return content;
|
||||
}
|
||||
public void setContent(JPanel content_in) {
|
||||
|
||||
content = content_in;
|
||||
}
|
||||
//-
|
||||
public void Show() {
|
||||
Clear();
|
||||
CreateControl();
|
||||
//------------------------
|
||||
scroll = new JScrollPane(control);
|
||||
scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
|
||||
scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
||||
}
|
||||
public void CreateControl() {
|
||||
try {
|
||||
control = control_class.newInstance();
|
||||
} catch (Exception e) {
|
||||
CommonUtils.MainLog.PrintException(e);
|
||||
}
|
||||
}
|
||||
public boolean isShown() {
|
||||
return control != null;
|
||||
}
|
||||
public void Clear() {
|
||||
control = null; //очищено.
|
||||
}
|
||||
public void Refresh() {
|
||||
if (control != null)
|
||||
refresh();
|
||||
}
|
||||
//-
|
||||
protected void refresh() {
|
||||
} //перерисовать контрол.
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
package Common_old.UI;
|
||||
import Common_old.Current;
|
||||
|
||||
import java.awt.*;
|
||||
public class ControlWithCurrentForm<C extends Component> extends ControlForm<C> {
|
||||
public ControlWithCurrentForm(Class<C> class_in) {
|
||||
super(class_in);
|
||||
}
|
||||
//-
|
||||
public Current CurrentName() {
|
||||
return Current.Undefined;
|
||||
}
|
||||
public void ShowCurrentObject() throws Exception {
|
||||
}
|
||||
public void ShowNoCurrentObject() throws Exception {
|
||||
}
|
||||
public void MouseAction2() throws Exception {
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package Common_old.UI;
|
||||
import Common.Database.Objects.DBObject;
|
||||
public interface DataControl {
|
||||
DBObject getRowObject(int rowIndex); //получить объект, сответствующий данной строке.
|
||||
void SelectRowByPK(Object pk);
|
||||
//выделить строку где лежит объект с данным первичным ключом.
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package Common_old.UI;
|
||||
import Common_old.Current;
|
||||
public interface DataControl_OLD {
|
||||
//todo скорее всего устареет.
|
||||
default Current getCurrent() {
|
||||
return Current.Undefined;
|
||||
}
|
||||
//-?
|
||||
default void ShowCurrentObject() throws Exception {
|
||||
}
|
||||
default void ShowNoCurrentObject() throws Exception {
|
||||
}
|
||||
}
|
||||
@@ -1,327 +0,0 @@
|
||||
package Common_old.UI;
|
||||
import Common.CommonConstants;
|
||||
import Common.Utils.CommonUtils;
|
||||
import Common.Visual.CommonUI;
|
||||
import Common_old.Current;
|
||||
import Common.Database.Objects.DBObject;
|
||||
import Common.Database.Tables.DBTable;
|
||||
import Common.Database.Tables.DataSet;
|
||||
import Common.Database.Tables.FKBehaviour;
|
||||
import _VisualDVM.Global;
|
||||
import Common_old.UI.Menus.TableMenu;
|
||||
import Common_old.UI.Tables.ColumnInfo;
|
||||
import Common_old.UI.Tables.DataTable;
|
||||
import Common_old.UI.Tables.Grid.GridAnchestor;
|
||||
import GlobalData.Grid.Grid;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.table.TableColumn;
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.Arrays;
|
||||
import java.util.Vector;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import static Common_old.UI.Tables.TableEditors.EditorSelect;
|
||||
import static Common_old.UI.Tables.TableRenderers.RendererSelect;
|
||||
public class DataSetControlForm extends ControlWithCurrentForm<DataTable> {
|
||||
protected JPanel dataPanel;
|
||||
protected DataSet dataSource;
|
||||
public JPanel getDataPanel() {
|
||||
return dataPanel;
|
||||
}
|
||||
protected int current_row_i;
|
||||
protected boolean events_on = true;
|
||||
protected String colNamesAndSizes = "";
|
||||
protected Vector<ColumnInfo> columns = new Vector<>();
|
||||
public DataSetControlForm(DataSet dataSource_in) {
|
||||
this(dataSource_in, DataTable.class);
|
||||
}
|
||||
public DataSetControlForm(DataSet dataSource_in, Class tableClass) {
|
||||
super(tableClass);
|
||||
dataSource = dataSource_in;
|
||||
//---
|
||||
dataPanel = new JPanel(new BorderLayout());
|
||||
content.add(dataPanel, BorderLayout.CENTER);
|
||||
}
|
||||
@Override
|
||||
public void Show() {
|
||||
super.Show();
|
||||
dataPanel.add(scroll);
|
||||
dataPanel.updateUI();
|
||||
}
|
||||
@Override
|
||||
public void Clear() {
|
||||
super.Clear();
|
||||
CommonUI.Clear(dataPanel);
|
||||
}
|
||||
public DataSet getDataSource() {
|
||||
return dataSource;
|
||||
}
|
||||
@Override
|
||||
public Current CurrentName() {
|
||||
return getDataSource().CurrentName();
|
||||
}
|
||||
public void SaveColumns() {
|
||||
if (Global.db != null) {
|
||||
try {
|
||||
if ((CurrentName() != Current.Undefined)) {
|
||||
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);
|
||||
Grid grid;
|
||||
if (Global.db.grids.containsKey(CurrentName())) {
|
||||
grid = Global.db.grids.get(CurrentName());
|
||||
} else {
|
||||
grid = new Grid(CurrentName());
|
||||
Global.db.Insert(grid);
|
||||
}
|
||||
grid.sizes = packed;
|
||||
Global.db.Update(grid);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
public boolean hasCheckBox() {
|
||||
return false;
|
||||
}
|
||||
private Vector<String> getHeaders() {
|
||||
return columns.stream().map(ColumnInfo::getName).collect(Collectors.toCollection(Vector::new));
|
||||
}
|
||||
protected void CreateColumnsInfo() {
|
||||
columns.clear();
|
||||
columns.add(new ColumnInfo(getDataSource().getPKName()));
|
||||
if (hasCheckBox()) {
|
||||
columns.add(new ColumnInfo("", RendererSelect, EditorSelect));
|
||||
columns.get(1).setMinWidth(25);
|
||||
columns.get(1).setMaxWidth(25);
|
||||
}
|
||||
Arrays.stream(getDataSource().getUIColumnNames()).forEach(name -> columns.add(new ColumnInfo(name)));
|
||||
AdditionalInitColumns();
|
||||
}
|
||||
protected void AdditionalInitColumns() {
|
||||
//уточнение инфы по столбцам.
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void CreateControl() {
|
||||
CreateColumnsInfo();
|
||||
GridAnchestor table_data_model = new GridAnchestor(getHeaders(), dataSource.getVisibleKeys()) {
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Object getValueAt(int rowIndex, int columnIndex) {
|
||||
Object key = data.get(rowIndex);
|
||||
if (columnIndex == 0)
|
||||
return key;
|
||||
DBObject object = getDataSource().get((key));
|
||||
if ((columnIndex == 1) && hasCheckBox())
|
||||
return object.isSelected();
|
||||
return getDataSource().getFieldAt(object, columnIndex);
|
||||
}
|
||||
@Override
|
||||
public boolean isCellEditable(int row, int col) {
|
||||
return columns.get(col).isEditable();
|
||||
}
|
||||
//------------------------------------------------------------------------------------
|
||||
@Override
|
||||
public void setValueAt(Object value, int row, int col) {
|
||||
fireTableCellUpdated(row, col);
|
||||
}
|
||||
};
|
||||
control = new DataTable(table_data_model) {
|
||||
@Override
|
||||
public TableMenu CreateMenu() {
|
||||
return new TableMenu(this);
|
||||
}
|
||||
//строго говоря эта штука нужна только для рендереров и едиторов клеток.
|
||||
@Override
|
||||
public DBObject getRowObject(int rowIndex) {
|
||||
//вот так делать НЕЛЬЗЯ. модель только для внутреннего пользования
|
||||
// Object key = table_data_model.data.get(rowIndex);
|
||||
//из таблицы можно пользоваться только getValueAt
|
||||
//иначе сортировка не будет работать.
|
||||
Object key = getValueAt(rowIndex, 0);
|
||||
return getDataSource().get(key);
|
||||
}
|
||||
//-----------------------------NEW-------------------------------------
|
||||
@Override
|
||||
public void CorrectColumnsSizes() {
|
||||
if ((Global.db != null) && CurrentName() != Current.Undefined && Global.db.grids.containsKey(CurrentName())) {
|
||||
//Undefined может оказаться в таблице, например если енум устарел. Поэтому надо проверять.
|
||||
if (!getColumnsProfile().equalsIgnoreCase(colNamesAndSizes)) {
|
||||
Grid grid = Global.db.grids.get(CurrentName());
|
||||
String[] data = grid.sizes.split("\\|");
|
||||
for (int i = 0; i < columns.size(); ++i) {
|
||||
if (i <= (data.length - 1)) {
|
||||
int width = Integer.parseInt(data[i]);
|
||||
getColumnModel().getColumn(i).setPreferredWidth(width);
|
||||
getColumnModel().getColumn(i).setWidth(width);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else
|
||||
super.CorrectColumnsSizes(); //обычный авторазмер.
|
||||
}
|
||||
public String getColumnsProfile() {
|
||||
String res = "";
|
||||
for (int i = 0; i < getColumnModel().getColumnCount(); i++) {
|
||||
if (i > 0) res += ",";
|
||||
TableColumn column = getColumnModel().getColumn(i);
|
||||
res += column.getHeaderValue();
|
||||
res += ":";
|
||||
res += column.getWidth();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
@Override
|
||||
public void Init() {
|
||||
for (int i = 0; i < columns.size(); i++) {
|
||||
ColumnInfo columnInfo = columns.get(i);
|
||||
if (columnInfo.isVisible()) {
|
||||
if (columnInfo.hasRenderer())
|
||||
getColumnModel().getColumn(i).setCellRenderer(UI.TableRenderers.get(columnInfo.getRenderer()));
|
||||
if (columnInfo.hasEditor())
|
||||
getColumnModel().getColumn(i).setCellEditor(UI.TableEditors.get(columnInfo.getEditor()));
|
||||
if (columnInfo.hasMaxWidth())
|
||||
getColumnModel().getColumn((i)).setMaxWidth(columnInfo.getMaxWidth());
|
||||
if (columnInfo.hasMinWidth())
|
||||
getColumnModel().getColumn((i)).setMinWidth(columnInfo.getMinWidth());
|
||||
} else {
|
||||
getColumnModel().getColumn(i).setMinWidth(0);
|
||||
getColumnModel().getColumn(i).setMaxWidth(0);
|
||||
}
|
||||
}
|
||||
//обновление в БД при ручном изменении размера столбиков.--------->>
|
||||
getTableHeader().addMouseListener(new MouseAdapter() {
|
||||
public void mouseReleased(MouseEvent arg0) {
|
||||
String new_colNamesAndSizes = getColumnsProfile();
|
||||
// check if changed, if yes, persist...
|
||||
if (!colNamesAndSizes.equals(new_colNamesAndSizes)) {
|
||||
colNamesAndSizes = new_colNamesAndSizes;
|
||||
SaveColumns();
|
||||
}
|
||||
}
|
||||
});
|
||||
//------------------------->>
|
||||
}
|
||||
};
|
||||
if (CurrentName() != Current.Undefined) {
|
||||
current_row_i = CommonConstants.Nan;
|
||||
ListSelectionModel selModel = control.getSelectionModel();
|
||||
selModel.addListSelectionListener(e -> {
|
||||
int row = control.getSelectedRow();
|
||||
if ((row >= 0)) {
|
||||
if (row != current_row_i) {
|
||||
current_row_i = row;
|
||||
getDataSource().setCurrent(control.getRowObject(row));
|
||||
if (events_on) {
|
||||
try {
|
||||
ShowCurrentObject();
|
||||
} catch (Exception ex) {
|
||||
CommonUtils.MainLog.PrintException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
current_row_i = CommonConstants.Nan;
|
||||
getDataSource().dropCurrent();
|
||||
if (events_on) {
|
||||
try {
|
||||
ShowNoCurrentObject();
|
||||
} catch (Exception ex) {
|
||||
CommonUtils.MainLog.PrintException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
//двойной клик мыши.------------------------------------------------------
|
||||
control.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
if ((e.getClickCount() == 2) && (dataSource.getCurrent() != null)) {
|
||||
try {
|
||||
MouseAction2();
|
||||
} catch (Exception ex) {
|
||||
CommonUtils.MainLog.PrintException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
//----------------------------------------------------------------------------
|
||||
//при переотображении таблицы скидываем текущий объект!!
|
||||
getDataSource().dropCurrent();
|
||||
try {
|
||||
ShowNoCurrentObject();
|
||||
} catch (Exception e) {
|
||||
CommonUtils.MainLog.PrintException(e);
|
||||
}
|
||||
}
|
||||
//---
|
||||
/*
|
||||
if (hasCheckBox()) {
|
||||
TableColumn column = control.getColumnModel().getColumn(1)
|
||||
column.setHeaderRenderer(new TableCellRenderer() {
|
||||
@Override
|
||||
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
|
||||
return null;
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
*/
|
||||
}
|
||||
@Override
|
||||
protected void refresh() {
|
||||
control.CorrectSizes();
|
||||
}
|
||||
public void Show(Object pk) {
|
||||
Show();
|
||||
Select(pk);
|
||||
}
|
||||
public void Select(Object pk) {
|
||||
if (isShown())
|
||||
control.SelectRowByPK(pk);
|
||||
}
|
||||
public void ClearSelection() {
|
||||
if (isShown())
|
||||
control.clearSelection(); //строка сбросится сама. благодаря сбросу события выбора
|
||||
}
|
||||
public int getRowCount() {
|
||||
return control.getRowCount();
|
||||
}
|
||||
@Override
|
||||
public void ShowCurrentObject() throws Exception {
|
||||
if (dataSource instanceof DBTable) {
|
||||
DBTable table = (DBTable) dataSource;
|
||||
for (Class dep : table.getFKDependencies().keySet()) {
|
||||
FKBehaviour behaviour = table.getFKDependencies().get(dep);
|
||||
switch (behaviour.ui) {
|
||||
case ACTIVE:
|
||||
table.getDb().tables.get(dep).ShowUI();
|
||||
break;
|
||||
case PASSIVE:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void ShowNoCurrentObject() throws Exception {
|
||||
if (dataSource instanceof DBTable) {
|
||||
DBTable table = (DBTable) dataSource;
|
||||
for (Class dep : table.getFKDependencies().keySet()) {
|
||||
FKBehaviour behaviour = table.getFKDependencies().get(dep);
|
||||
switch (behaviour.ui) {
|
||||
case ACTIVE:
|
||||
table.getDb().tables.get(dep).ClearUI();
|
||||
break;
|
||||
case PASSIVE:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
package Common_old.UI.Menus;
|
||||
import Common.CurrentAnchestor;
|
||||
import Common.Utils.CommonUtils;
|
||||
import Common_old.Current;
|
||||
import Common_old.UI.Menus_2023.StableMenuItem;
|
||||
@@ -41,7 +42,7 @@ public abstract class SelectionTreeMenu extends GraphMenu<DataTree> {
|
||||
m_select_for_current.addActionListener(new AbstractAction() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Object o = Current.get(tree.getCurrent());
|
||||
Object o = CurrentAnchestor.get(tree.getCurrent());
|
||||
if (o instanceof Selectable) {
|
||||
((Selectable) o).SelectAllChildren(true);
|
||||
}
|
||||
@@ -54,7 +55,7 @@ public abstract class SelectionTreeMenu extends GraphMenu<DataTree> {
|
||||
m_unselect_for_current.addActionListener(new AbstractAction() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Object o = Current.get(tree.getCurrent());
|
||||
Object o = CurrentAnchestor.get(tree.getCurrent());
|
||||
if (o instanceof Selectable) {
|
||||
((Selectable) o).SelectAllChildren(false);
|
||||
}
|
||||
@@ -68,7 +69,7 @@ public abstract class SelectionTreeMenu extends GraphMenu<DataTree> {
|
||||
public abstract void SelectAll(boolean select);
|
||||
@Override
|
||||
public void CheckElementsVisibility() {
|
||||
Object current = Current.get(tree.getCurrent());
|
||||
Object current = CurrentAnchestor.get(tree.getCurrent());
|
||||
if ((current != null) && (current.getClass().equals(getTargetClass()))) {
|
||||
String name = ((Selectable) current).getSelectionText();
|
||||
m_select_for_current.setText("Выбрать всё для " +
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
package Common_old.UI.Menus_2023.ProjectMenuBar;
|
||||
import Common.CurrentAnchestor;
|
||||
import Common.Utils.CommonUtils;
|
||||
import Common_old.Current;
|
||||
import Common_old.UI.Menus_2023.VisualiserMenu;
|
||||
@@ -19,7 +20,7 @@ public class ProjectViewMenu extends VisualiserMenu {
|
||||
setIcon(CommonUtils.getIcon(view.getIcon()));
|
||||
setFont(Current.getTheme().Fonts.get(VisualiserFonts.TreeItalic));
|
||||
addActionListener(e -> {
|
||||
Current.set(Current.ProjectView, view);
|
||||
CurrentAnchestor.set(Current.ProjectView, view);
|
||||
UI.getMainWindow().getProjectWindow().ShowProjectView();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package Common_old.UI.Tables;
|
||||
import Common.Database.Objects.DBObject;
|
||||
import Common_old.UI.DataControl;
|
||||
import Common.Visual.DataControl;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.CellEditorListener;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package Common_old.UI.Tables;
|
||||
import Common.Database.Objects.DBObject;
|
||||
import Common_old.UI.DataControl;
|
||||
import Common.Visual.DataControl;
|
||||
|
||||
import javax.swing.*;
|
||||
public abstract class DBObjectRenderer extends RendererCell<DBObject> {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package Common_old.UI.Tables;
|
||||
import Common.Database.Objects.DBObject;
|
||||
import Common_old.UI.DataControl;
|
||||
import Common.Visual.DataControl;
|
||||
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
public abstract class DataTable extends StyledTable implements DataControl {
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package Common_old.UI.Trees;
|
||||
import Common.CurrentAnchestor;
|
||||
import Common.Utils.CommonUtils;
|
||||
import Common_old.Current;
|
||||
import Common_old.UI.DataControl_OLD;
|
||||
import Common.Visual.DataControl_OLD;
|
||||
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import javax.swing.tree.TreePath;
|
||||
@@ -10,8 +11,8 @@ public class DataTree extends StyledTree implements DataControl_OLD {
|
||||
super(root_in);
|
||||
}
|
||||
public void ChangeCurrentObject(DefaultMutableTreeNode node) {
|
||||
if (getCurrent() != Current.Undefined)
|
||||
Current.set(getCurrent(), node.getUserObject());
|
||||
if (getCurrent() != null)
|
||||
CurrentAnchestor.set(getCurrent(), node.getUserObject());
|
||||
}
|
||||
@Override
|
||||
public void ShowCurrentObject() throws Exception {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
package Common_old.UI.Trees;
|
||||
import Common.CurrentAnchestor;
|
||||
import Common_old.Current;
|
||||
import Common.Visual.Selectable;
|
||||
|
||||
@@ -9,7 +10,7 @@ public class SelectableTree extends DataTree {
|
||||
}
|
||||
@Override
|
||||
public void LeftMouseAction1() {
|
||||
Object element = Current.get(getCurrent());
|
||||
Object element = CurrentAnchestor.get(getCurrent());
|
||||
if ((element instanceof Selectable)) {
|
||||
((Selectable) element).SwitchSelection();
|
||||
updateUI();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package Common_old.UI.Trees;
|
||||
import Common.Visual.CommonUI;
|
||||
import Common_old.UI.ControlForm;
|
||||
import Common.Visual.ControlForm;
|
||||
|
||||
import java.awt.*;
|
||||
public class TreeForm<C extends StyledTree> extends ControlForm<C> {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
package Common_old.UI;
|
||||
import Common.CurrentAnchestor;
|
||||
import Common.Utils.CommonUtils;
|
||||
import Common_old.Current;
|
||||
import Common_old.UI.Menus_2023.CredentialsBar.CredentialsBar;
|
||||
@@ -240,9 +241,8 @@ public class UI {
|
||||
//</editor-fold>
|
||||
//<editor-fold desc="Темы(всегда создавать первыми)">
|
||||
themes.put(VisualiserThemeName.Light, new LightVisualiserTheme());
|
||||
themes.put(VisualiserThemeName.Dark, new DarkVisualiserTheme());
|
||||
//по умолчанию поставить светлую тему. потому что до загрузки бд работаем с таблицей компонент.
|
||||
Current.set(Current.Theme, themes.get(VisualiserThemeName.Light));
|
||||
CurrentAnchestor.set(Current.Theme, themes.get(VisualiserThemeName.Light));
|
||||
//</editor-fold>
|
||||
//<editor-fold desc="Объекты отрисовки и редактирования деревьев и таблиц">
|
||||
TableRenderers.put(RendererDate, new DateRenderer_());
|
||||
|
||||
@@ -558,15 +558,12 @@ public class Utils {
|
||||
}
|
||||
//---
|
||||
for (int i = 1; i < letters.length; ++i) {
|
||||
if (!(CommonUtils.isEnglishLetter(letters[i]) || letters[i] == '_' || CommonUtils.isDigit(String.valueOf(letters[i])))) {
|
||||
if (!(CommonUtils.isEnglishLetter(letters[i]) || letters[i] == '_' || CommonUtils.isIntegerValue(String.valueOf(letters[i])))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public static int fromBoolean(boolean flag) {
|
||||
return flag ? 1 : 0;
|
||||
}
|
||||
public static void keepNewFiles(File directory, int count) throws Exception {
|
||||
if (count > 0) {
|
||||
File[] old_ = directory.listFiles(pathname -> pathname.isFile());
|
||||
|
||||
Reference in New Issue
Block a user