Рефакторинг кода панели быстрого доступа.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package Common.Database;
|
||||
import Common.Database.SQLITE.SQLiteDatabase;
|
||||
import Common.Database.Objects.DBForm.FormsDBTable;
|
||||
import Visual_DVM_2021.PassStats.PassStatsDBTable;
|
||||
import _VisualDVM.GlobalData.Grid.TablesVisualDatasDBTable;
|
||||
import _VisualDVM.GlobalData.Splitter.SplittersDBTable;
|
||||
import Visual_DVM_2021.Passes.PassCode;
|
||||
@@ -10,6 +11,7 @@ public class VisualiserDatabase extends SQLiteDatabase {
|
||||
public FormsDBTable forms;
|
||||
public TablesVisualDatasDBTable tablesVisualData;
|
||||
public SplittersDBTable splitters;
|
||||
public PassStatsDBTable passStats;
|
||||
public VisualiserDatabase(File file_in) {
|
||||
super(file_in);
|
||||
}
|
||||
@@ -18,6 +20,7 @@ public class VisualiserDatabase extends SQLiteDatabase {
|
||||
addTable(forms = new FormsDBTable());
|
||||
addTable(tablesVisualData = new TablesVisualDatasDBTable());
|
||||
addTable(splitters = new SplittersDBTable());
|
||||
addTable(passStats = new PassStatsDBTable());
|
||||
}
|
||||
@Override
|
||||
public PassCode getSynchronizePassCode() {
|
||||
|
||||
@@ -20,10 +20,6 @@ import java.util.Stack;
|
||||
import java.util.Vector;
|
||||
import java.util.concurrent.Semaphore;
|
||||
public class Pass<T> {
|
||||
public static Vector<Pass> FAPasses = new Vector<>();
|
||||
//</editor-fold>
|
||||
//-
|
||||
public PassStats stats = null;
|
||||
public int callsCount = 0; //число вызовов прохода за текущий сеанс визуализатора.
|
||||
public T target; //главный аргумент.
|
||||
public PassState state = PassState.Inactive; //текущее состояние прохода.
|
||||
@@ -39,23 +35,10 @@ public class Pass<T> {
|
||||
private JButton tabButton = null;
|
||||
private Exception last_error; //последнее пойманное исключение выполнения.
|
||||
//->>
|
||||
public static Throwable getCauseRec(Throwable ex) {
|
||||
public Throwable getCauseRec(Throwable ex) {
|
||||
Throwable cause = ex.getCause();
|
||||
return (cause == null) ? ex : getCauseRec(cause);
|
||||
}
|
||||
public static void setPassesControlsVisible(boolean flag, PassCode... codes_in) {
|
||||
for (PassCode code_in : codes_in)
|
||||
Global.mainModule.getPass(code_in).setControlsVisible(flag);
|
||||
}
|
||||
//важно. вызывать только если есть интерфейс. passstats делать частью общей бд.пусть будут.
|
||||
public static void CheckAllStats() throws Exception {
|
||||
for (Pass pass : FAPasses) {
|
||||
if (!(Global.mainModule.getDb()).passStats.Data.containsKey(pass.code().toString()))
|
||||
Global.mainModule.getDb().Insert(pass.stats = new PassStats(pass.code().toString()));
|
||||
else pass.stats = (Global.mainModule.getDb()).passStats.Data.get(pass.code().toString());
|
||||
}
|
||||
FAPasses.sort(new SortPassesByStats());
|
||||
}
|
||||
//<editor-fold desc="Интерфейс">
|
||||
//https://www.delftstack.com/ru/howto/java/java-resize-image/
|
||||
public String getIconPath() {
|
||||
@@ -110,15 +93,12 @@ public class Pass<T> {
|
||||
}
|
||||
public void UpdateStatsIfNeed() {
|
||||
if (hasStats()) {
|
||||
stats.Inc();
|
||||
try {
|
||||
Global.mainModule.getDb().Update(stats);
|
||||
FAPasses.sort(new SortPassesByStats());
|
||||
if (Global.mainModule.HasProject())
|
||||
UI.fastAccessMenuBar.Refresh();
|
||||
Global.mainModule.getDb().passStats.IncPassStat(code());
|
||||
} catch (Exception ex) {
|
||||
Utils_.MainLog.PrintException(ex);
|
||||
}
|
||||
UI.fastAccessMenuBar.Refresh();
|
||||
}
|
||||
}
|
||||
public PassCode code() {
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
package Common.Passes;
|
||||
import Common.Passes.Pass;
|
||||
|
||||
import java.util.Comparator;
|
||||
public class SortPassesByStats implements Comparator<Common.Passes.Pass> {
|
||||
public int compare(Common.Passes.Pass p1, Pass p2) {
|
||||
return p2.stats.Usages - p1.stats.Usages;
|
||||
}
|
||||
}
|
||||
@@ -6,14 +6,22 @@ import Common.Passes.Pass;
|
||||
import Common.Passes.PassCode_;
|
||||
import Common.Utils.TextLog;
|
||||
import Common.Utils.Utils_;
|
||||
import Common.Utils.Vector_;
|
||||
import Visual_DVM_2021.PassStats.PassStats;
|
||||
import Visual_DVM_2021.Passes.PassCode;
|
||||
import _VisualDVM.Global;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Vector;
|
||||
//Основной объект визуализатора.
|
||||
public abstract class MainModule_<D extends VisualiserDatabase> {
|
||||
D db;
|
||||
Class<D> db_class;
|
||||
//--
|
||||
LinkedHashMap<PassCode_, Pass> passes;
|
||||
LinkedHashMap<Current_, Object> objects;
|
||||
LinkedHashMap<Current_, Object> objects; //Current
|
||||
//--
|
||||
public D getDb() {
|
||||
return db;
|
||||
}
|
||||
@@ -25,15 +33,14 @@ public abstract class MainModule_<D extends VisualiserDatabase> {
|
||||
Class<?> clazz = Class.forName("Visual_DVM_2021.Passes.All." + code.toString());
|
||||
Pass pass = ((Pass) clazz.newInstance());
|
||||
passes.put((PassCode_) code, pass);
|
||||
//--
|
||||
if (pass.hasStats())
|
||||
Pass.FAPasses.add(pass);
|
||||
//--
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
System.out.println("Passes created!");
|
||||
}
|
||||
public void setPassesControlsVisible(boolean flag, PassCode_... codes_in) {
|
||||
for (PassCode_ code_in : codes_in)
|
||||
getPass(code_in).setControlsVisible(flag);
|
||||
}
|
||||
public MainModule_(Class<D> db_class_in) {
|
||||
objects = new LinkedHashMap<>();
|
||||
@@ -45,7 +52,7 @@ public abstract class MainModule_<D extends VisualiserDatabase> {
|
||||
}
|
||||
//---
|
||||
}
|
||||
public abstract Class<? extends PassCode_> getPassCodesEnum();
|
||||
public abstract Class getPassCodesEnum();
|
||||
public void ActivateDB() throws Exception {
|
||||
db = db_class.newInstance();
|
||||
db.Connect();
|
||||
@@ -81,4 +88,20 @@ public abstract class MainModule_<D extends VisualiserDatabase> {
|
||||
public Pass getPass(PassCode_ code){
|
||||
return passes.get(code);
|
||||
}
|
||||
public Vector<Pass> getFirstAccessPasses(){
|
||||
Vector<PassStats> sortedStats = new Vector<>(getDb().passStats.Data.values());
|
||||
System.out.println("sorted passes size= "+sortedStats.size());
|
||||
sortedStats.sort(new Comparator<PassStats>() {
|
||||
@Override
|
||||
public int compare(PassStats o1, PassStats o2) {
|
||||
return Integer.compare(o2.Usages, o1.Usages);
|
||||
}
|
||||
});
|
||||
Vector<Pass> res= new Vector<>();
|
||||
for (PassStats passStats: sortedStats){
|
||||
PassCode_ passCode = (PassCode_) Enum.valueOf(getPassCodesEnum(), passStats.code);
|
||||
res.add(getPass(passCode));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ public class PassStats extends DBObject {
|
||||
public void Inc() {
|
||||
Usages++;
|
||||
}
|
||||
public void Drop() {
|
||||
public void Reset() {
|
||||
Usages = 0;
|
||||
}
|
||||
public boolean HasUsages() {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package Visual_DVM_2021.PassStats;
|
||||
import Common.Database.Tables.DBTable;
|
||||
import Visual_DVM_2021.Passes.PassCode;
|
||||
import Common.Passes.PassCode_;
|
||||
|
||||
import java.util.Vector;
|
||||
public class PassStatsDBTable extends DBTable<String, PassStats> {
|
||||
public PassStatsDBTable() {
|
||||
super(String.class, PassStats.class);
|
||||
@@ -9,4 +11,18 @@ public class PassStatsDBTable extends DBTable<String, PassStats> {
|
||||
public String getSingleDescription() {
|
||||
return "статистика выполнения прохода";
|
||||
}
|
||||
public void IncPassStat(PassCode_ code) throws Exception {
|
||||
String code_s = code.toString();
|
||||
PassStats passStats = null;
|
||||
if (Data.containsKey(code_s)) {
|
||||
passStats = Data.get(code_s);
|
||||
passStats.Inc();
|
||||
getDb().Update(passStats);
|
||||
} else {
|
||||
passStats = new PassStats(code_s);
|
||||
passStats.Inc();
|
||||
getDb().Insert(passStats);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package Visual_DVM_2021.Passes.All;
|
||||
import Common.Utils.Utils_;
|
||||
import Visual_DVM_2021.PassStats.PassStats;
|
||||
import _VisualDVM.Global;
|
||||
import _VisualDVM.Visual.UI;
|
||||
import Common.Passes.Pass;
|
||||
@@ -10,10 +11,7 @@ public class DropFastAccess extends Pass {
|
||||
}
|
||||
@Override
|
||||
protected void body() throws Exception {
|
||||
for (Pass pass : Pass.FAPasses) {
|
||||
pass.stats.Drop();
|
||||
Global.mainModule.getDb().Update(pass.stats);
|
||||
}
|
||||
Global.mainModule.getDb().DeleteAll(PassStats.class);
|
||||
}
|
||||
@Override
|
||||
protected void showDone() throws Exception {
|
||||
|
||||
@@ -301,7 +301,6 @@ public class Global {
|
||||
//--
|
||||
if (mainModule.getDb().settings.get(SettingName.AutoTestsLoad).toBoolean())
|
||||
Global.mainModule.getPass(PassCode.SynchronizeTests).Do();
|
||||
Pass.CheckAllStats();
|
||||
Global.mainModule.getSapfor().refreshPid(); //без сапфора сюда это все равно не дойдет.
|
||||
UI.CreateMenus();
|
||||
UI.CreateWindows();
|
||||
|
||||
@@ -51,7 +51,6 @@ public class GlobalDatabase extends VisualiserDatabase {
|
||||
public SettingsDBTable settings;
|
||||
public LastProjectsDBTable lastProjects;
|
||||
public AccountsDBTable accounts;
|
||||
public PassStatsDBTable passStats;
|
||||
//-
|
||||
public SapforProfilesDBTable sapforProfiles = null;
|
||||
//---------
|
||||
@@ -76,7 +75,6 @@ public class GlobalDatabase extends VisualiserDatabase {
|
||||
addTable(settings = new SettingsDBTable());
|
||||
addTable(lastProjects = new LastProjectsDBTable());
|
||||
addTable(accounts = new AccountsDBTable());
|
||||
addTable(passStats = new PassStatsDBTable());
|
||||
addTable(dvmParameters = new DVMParameterDBTable());
|
||||
addTable(sapforProfiles = new SapforProfilesDBTable());
|
||||
addTable(sapforProfilesSettings = new SapforProfileSettingsDBTable());
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
package _VisualDVM;
|
||||
import Common.Passes.Pass;
|
||||
import Common.Passes.PassCode_;
|
||||
import Common.Utils.Vector_;
|
||||
import MainModule_.MainModule_;
|
||||
import Visual_DVM_2021.Passes.PassCode;
|
||||
@@ -42,28 +40,13 @@ import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import java.io.File;
|
||||
import java.util.Vector;
|
||||
public class MainModule extends MainModule_<GlobalDatabase> {
|
||||
Vector<PassCode> accountRoleDependentPasses = new Vector_<>(
|
||||
PassCode.AddSubscriber,
|
||||
PassCode.EditSubscriber,
|
||||
PassCode.DeleteSubscriber,
|
||||
PassCode.DeleteSubscriberWorkspace,
|
||||
//--
|
||||
PassCode.DownloadAllBugReportsArchives,
|
||||
//--
|
||||
PassCode.CompileServerSapfor,
|
||||
PassCode.DeleteServerSapfor,
|
||||
//
|
||||
PassCode.ShutdownComponentsServer,
|
||||
PassCode.StartComponentsServer,
|
||||
PassCode.PublishComponentsServer,
|
||||
//
|
||||
PassCode.ShutdownTestingServer,
|
||||
PassCode.StartTestingServer,
|
||||
PassCode.PublishTestingServer
|
||||
);
|
||||
public MainModule() {
|
||||
super(GlobalDatabase.class);
|
||||
}
|
||||
@Override
|
||||
public Class getPassCodesEnum() {
|
||||
return PassCode.class;
|
||||
}
|
||||
//--
|
||||
public boolean HasProject() {
|
||||
return get(Current.Project) != null;
|
||||
@@ -315,19 +298,35 @@ public class MainModule extends MainModule_<GlobalDatabase> {
|
||||
set(Current.Array, null);
|
||||
set(Current.DBArray, null);
|
||||
}
|
||||
@Override
|
||||
public Class getPassCodesEnum() {
|
||||
return PassCode.class;
|
||||
}
|
||||
public void SetUserAccess() {
|
||||
//--
|
||||
Vector<PassCode> accountRoleDependentPasses = new Vector_<>(
|
||||
PassCode.AddSubscriber,
|
||||
PassCode.EditSubscriber,
|
||||
PassCode.DeleteSubscriber,
|
||||
PassCode.DeleteSubscriberWorkspace,
|
||||
//--
|
||||
PassCode.DownloadAllBugReportsArchives,
|
||||
//--
|
||||
PassCode.CompileServerSapfor,
|
||||
PassCode.DeleteServerSapfor,
|
||||
//
|
||||
PassCode.ShutdownComponentsServer,
|
||||
PassCode.StartComponentsServer,
|
||||
PassCode.PublishComponentsServer,
|
||||
//
|
||||
PassCode.ShutdownTestingServer,
|
||||
PassCode.StartTestingServer,
|
||||
PassCode.PublishTestingServer
|
||||
);
|
||||
public void SetUserPassesAccess() {
|
||||
for (PassCode code: accountRoleDependentPasses)
|
||||
getPass(code).setControlsVisible(false);
|
||||
}
|
||||
public void SetDeveloperAccess() {
|
||||
SetUserAccess();
|
||||
public void SetDeveloperPassesAccess() {
|
||||
SetUserPassesAccess();
|
||||
getPass(PassCode.DownloadAllBugReportsArchives).setControlsVisible(true);
|
||||
}
|
||||
public void SetAdminAccess(){
|
||||
public void SetAdminPassesAccess(){
|
||||
for (PassCode code: accountRoleDependentPasses)
|
||||
getPass(code).setControlsVisible(true);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package _VisualDVM.Visual.Menus.FastAccessMenuBar;
|
||||
import Common.Passes.PassCode_;
|
||||
import Common.Utils.Utils_;
|
||||
import Common.Visual.UI_;
|
||||
import Visual_DVM_2021.PassStats.PassStats;
|
||||
import _VisualDVM.Global;
|
||||
import _VisualDVM.Visual.Menus.VisualiserMenuBar;
|
||||
import _VisualDVM.GlobalData.GlobalDatabase;
|
||||
@@ -12,7 +14,6 @@ import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.LinkedHashMap;
|
||||
public class FastAccessMenuBar extends VisualiserMenuBar {
|
||||
LinkedHashMap<PassCode, JButton> passesButtons = new LinkedHashMap<>();
|
||||
public FastAccessMenuBar() {
|
||||
Refresh();
|
||||
}
|
||||
@@ -21,13 +22,7 @@ public class FastAccessMenuBar extends VisualiserMenuBar {
|
||||
//если задавать PreffredSize 0, скролл НЕ РАБОТАЕТ. Магия!
|
||||
}
|
||||
public void showPass(Pass pass) {
|
||||
JButton button = null;
|
||||
if (passesButtons.containsKey(pass.code()))
|
||||
button = passesButtons.get((pass.code()));
|
||||
else {
|
||||
button = pass.createButton();
|
||||
passesButtons.put(pass.code(), button);
|
||||
}
|
||||
JButton button = pass.createButton();
|
||||
add(button);
|
||||
Dimension d = button.getPreferredSize();
|
||||
button.setPreferredSize(new Dimension(d.width, 30));
|
||||
@@ -35,14 +30,12 @@ public class FastAccessMenuBar extends VisualiserMenuBar {
|
||||
repaint();
|
||||
}
|
||||
public void Refresh() {
|
||||
UI_.Clear(this);
|
||||
Drop();
|
||||
int i = 1;
|
||||
for (Pass pass : Pass.FAPasses) {
|
||||
if (pass.stats.HasUsages()) {
|
||||
showPass(pass);
|
||||
++i;
|
||||
if (i > ((Global.mainModule.getDb()).settings.get(SettingName.FastAccessPassesCount).toInt32())) break;
|
||||
}
|
||||
for (Pass pass: Global.mainModule.getFirstAccessPasses()){
|
||||
showPass(pass);
|
||||
++i;
|
||||
if (i > ((Global.mainModule.getDb()).settings.get(SettingName.FastAccessPassesCount).toInt32())) break;
|
||||
}
|
||||
}
|
||||
public void Drop(){
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package _VisualDVM.Visual.Windows;
|
||||
import Common.Utils.Utils_;
|
||||
import Common.Visual.UI_;
|
||||
import _VisualDVM.Current;
|
||||
import _VisualDVM.GlobalData.GlobalDatabase;
|
||||
import _VisualDVM.Global;
|
||||
import _VisualDVM.Visual.Editor.BaseEditor;
|
||||
import _VisualDVM.Visual.Editor.Viewer;
|
||||
@@ -374,20 +372,20 @@ public class CallbackForm implements FormWithSplitters, CallbackWindow {
|
||||
@Override
|
||||
public void setUserRights() {
|
||||
LockMyOnly();
|
||||
Global.mainModule.SetUserAccess();
|
||||
Global.mainModule.SetUserPassesAccess();
|
||||
UI.testingBar.showServerAdminLabel(false);
|
||||
adminLabel.setVisible(false);
|
||||
}
|
||||
private void setDeveloperRights() {
|
||||
UnlockMyOnly();
|
||||
Global.mainModule.SetDeveloperAccess();
|
||||
Global.mainModule.SetDeveloperPassesAccess();
|
||||
UI.testingBar.showServerAdminLabel(false);
|
||||
adminLabel.setVisible(false);
|
||||
}
|
||||
@Override
|
||||
public void setAdminRights() {
|
||||
UnlockMyOnly();
|
||||
Global.mainModule.SetAdminAccess();
|
||||
Global.mainModule.SetAdminPassesAccess();
|
||||
//--
|
||||
UI.testingBar.showServerAdminLabel(true);
|
||||
adminLabel.setVisible(true);
|
||||
@@ -438,13 +436,13 @@ public class CallbackForm implements FormWithSplitters, CallbackWindow {
|
||||
Global.componentsServer.db.subscribers.ClearUI();
|
||||
}
|
||||
private void ShowDraft() {
|
||||
Pass.setPassesControlsVisible(true,
|
||||
Global.mainModule.setPassesControlsVisible(true,
|
||||
PassCode.PublishBugReport,
|
||||
PassCode.SaveBugReportRecipients,
|
||||
PassCode.SaveBugReportExecutor,
|
||||
PassCode.DeleteBugReport
|
||||
);
|
||||
Pass.setPassesControlsVisible(false,
|
||||
Global.mainModule.setPassesControlsVisible(false,
|
||||
PassCode.AppendBugReportDescription,
|
||||
PassCode.AppendBugReportComment,
|
||||
PassCode.SaveBugReportDescription,
|
||||
@@ -456,12 +454,12 @@ public class CallbackForm implements FormWithSplitters, CallbackWindow {
|
||||
);
|
||||
}
|
||||
private void ShowUserExecutor() {
|
||||
Pass.setPassesControlsVisible(true,
|
||||
Global.mainModule.setPassesControlsVisible(true,
|
||||
PassCode.AppendBugReportComment,
|
||||
PassCode.UpdateBugReportProgress,
|
||||
PassCode.OpenBugReportTestProject
|
||||
);
|
||||
Pass.setPassesControlsVisible(false,
|
||||
Global.mainModule.setPassesControlsVisible(false,
|
||||
PassCode.PublishBugReport,
|
||||
PassCode.SaveBugReportRecipients,
|
||||
PassCode.SaveBugReportExecutor,
|
||||
@@ -474,7 +472,7 @@ public class CallbackForm implements FormWithSplitters, CallbackWindow {
|
||||
);
|
||||
}
|
||||
private void ShowSender() {
|
||||
Pass.setPassesControlsVisible(true,
|
||||
Global.mainModule.setPassesControlsVisible(true,
|
||||
PassCode.AppendBugReportComment,
|
||||
PassCode.UpdateBugReportProgress,
|
||||
PassCode.OpenBugReportTestProject,
|
||||
@@ -487,12 +485,12 @@ public class CallbackForm implements FormWithSplitters, CallbackWindow {
|
||||
PassCode.CloseBugReport,
|
||||
PassCode.DeleteBugReport
|
||||
);
|
||||
Pass.setPassesControlsVisible(false,
|
||||
Global.mainModule.setPassesControlsVisible(false,
|
||||
PassCode.PublishBugReport
|
||||
);
|
||||
}
|
||||
private void ShowUser() {
|
||||
Pass.setPassesControlsVisible(false,
|
||||
Global.mainModule.setPassesControlsVisible(false,
|
||||
PassCode.PublishBugReport,
|
||||
PassCode.SaveBugReportRecipients,
|
||||
PassCode.SaveBugReportExecutor,
|
||||
@@ -529,7 +527,7 @@ public class CallbackForm implements FormWithSplitters, CallbackWindow {
|
||||
target.sapfor_settings
|
||||
)
|
||||
);
|
||||
Pass.setPassesControlsVisible(true, PassCode.ApplyBugReportSettings);
|
||||
Global.mainModule.setPassesControlsVisible(true, PassCode.ApplyBugReportSettings);
|
||||
//
|
||||
if (target.state.equals(BugReportState.draft)) {
|
||||
ShowDraft();
|
||||
@@ -564,7 +562,7 @@ public class CallbackForm implements FormWithSplitters, CallbackWindow {
|
||||
BugReportCommentAddition.setText("");
|
||||
BugReportSettings.setText("");
|
||||
//-
|
||||
Pass.setPassesControlsVisible(false, PassCode.SaveBugReportExecutor,
|
||||
Global.mainModule.setPassesControlsVisible(false, PassCode.SaveBugReportExecutor,
|
||||
PassCode.SaveBugReportRecipients,
|
||||
PassCode.AppendBugReportDescription,
|
||||
PassCode.SaveBugReportDescription,
|
||||
|
||||
Reference in New Issue
Block a user