Files
VisualSapfor/src/_VisualDVM/Visual/Windows/SapforVersionsComparisonForm.java

176 lines
7.3 KiB
Java
Raw Normal View History

2024-10-09 22:15:56 +03:00
package _VisualDVM.Visual.Windows;
2024-10-07 14:22:52 +03:00
import Common.Utils.CommonUtils;
2024-10-09 22:01:19 +03:00
import _VisualDVM.Constants;
import _VisualDVM.Current;
import Common.Visual.Controls.MenuBarButton;
import _VisualDVM.Utils;
import GlobalData.GlobalDatabase;
2023-11-02 01:08:00 +03:00
import GlobalData.Settings.SettingName;
import ProjectData.Files.ProjectFile;
import TestingSystem.SAPFOR.Json.SapforVersion_json;
import Visual_DVM_2021.Passes.PassCode_2021;
import Visual_DVM_2021.Passes.Pass_2021;
2023-11-02 01:08:00 +03:00
import javax.swing.*;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.Vector;
2023-11-02 00:01:34 +03:00
public class SapforVersionsComparisonForm extends ComparisonForm<SapforVersion_json> {
//--
protected LinkedHashMap<SapforVersionComparisonState, JButton> buttons = null;
2023-11-02 01:08:00 +03:00
//почти полный клон VersionsComparsionForm. В будущем нужен рефакторинг. Наверное.
2023-11-02 00:01:34 +03:00
Current current;
2023-11-02 01:08:00 +03:00
private final JComboBox<ProjectFile> cbFile;
protected ProjectFile file = null;
private SapforVersionsComparisonForm getMaster() {
return (SapforVersionsComparisonForm) master;
}
private SapforVersionsComparisonForm getSlave() {
return (SapforVersionsComparisonForm) slave;
}
2023-11-02 00:01:34 +03:00
public SapforVersionsComparisonForm(SapforVersionsComparisonForm slave_in, Current current_in) {
super(SapforVersion_json.class, slave_in);
current = current_in;
bApplyObject.setVisible(false);
bClose.setVisible(false);
2023-11-02 01:08:00 +03:00
cbFile = new JComboBox<>();
tools.add(Pass_2021.passes.get(
(current.equals(Current.SapforEtalonVersion) ? PassCode_2021.OpenSapforEtalonVersion : PassCode_2021.OpenSapforVersion
)).createButton(), 3);
tools.add(cbFile, 4);
2023-11-02 01:08:00 +03:00
//--
cbFile.addActionListener(e -> {
SelectFile(((cbFile.getSelectedItem() instanceof ProjectFile) ? ((ProjectFile) cbFile.getSelectedItem()) : null));
});
//--
buttons = new LinkedHashMap<>();
int i = 5;
for (SapforVersionComparisonState state : SapforVersionComparisonState.values()) {
MenuBarButton button = new MenuBarButton();
button.setIcon("/icons/" + state.toString() + ".png");
button.setToolTipText(state.getDescription());
button.addActionListener(e -> {
if (object != null) {
ProjectFile projectFile = null;
switch (state) {
case CompilationOutput:
projectFile = object.parse_out;
break;
case CompilationErrors:
projectFile = object.parse_err;
break;
case RunOutput:
projectFile = object.out;
break;
case RunErrors:
projectFile = object.err;
break;
2023-11-02 01:08:00 +03:00
}
SelectFile(projectFile);
}
});
tools.add(button, i);
buttons.put(state, button);
++i;
}
}
public void SelectFile(ProjectFile file_in) {
file = file_in;
if (isMaster()) {
if (isReady() && !getSlave().selectSameFile(file))
DoShowPass(true);
} else {
if (isReady()) {
if (getMaster().isReady()) {
boolean ExtensionsOn = ((GlobalDatabase)CommonUtils.db).settings.get(SettingName.ExtensionsOn).toBoolean();
2024-10-07 14:22:52 +03:00
String name1 = ExtensionsOn ? getMaster().file.file.getName() : CommonUtils.getFileNameWithoutExtension(getMaster().file.file);
String name2 = ExtensionsOn ? file.file.getName() : CommonUtils.getFileNameWithoutExtension(file.file);
if (((GlobalDatabase)CommonUtils.db).settings.get(SettingName.ComparsionDiffMergeOn).toBoolean()) {
if (name1.equalsIgnoreCase(name2))
master.DoComparePass(true);
} else
master.DoShowPass(true);
} else {
master.DoShowPass(true);
2023-11-02 01:08:00 +03:00
}
}
}
2023-11-02 00:01:34 +03:00
}
@Override
protected Current getCurrentObjectName() {
return current;
}
@Override
protected String getText() {
return isReady() ?
(file.file.exists() ? Utils.ReadAllText(file.file) : "файл не найден")
: "объект не назначен";
2023-11-02 01:08:00 +03:00
}
@Override
public boolean isReady() {
return super.isReady() && file != null;
2023-11-02 00:01:34 +03:00
}
@Override
protected void showObject() {
lObjectName.setText(object.toString());
2024-10-07 14:22:52 +03:00
lObjectName.setToolTipText(object.Home.getName() + " : " + CommonUtils.Brackets(object.description));
2023-11-02 01:08:00 +03:00
cbFile.removeAllItems();
2023-11-08 02:05:21 +03:00
for (ProjectFile file : object.files.values())
2023-11-02 01:08:00 +03:00
cbFile.addItem(file);
}
@Override
protected void removeObject() {
cbFile.removeAllItems();
file = null;
}
public boolean selectSameFile(ProjectFile file_in) {
2023-11-02 01:08:00 +03:00
file = null;
Vector<String> data_names = new Vector<>(Arrays.asList(
Constants.parse_out_file,
Constants.parse_err_file,
Constants.out_file,
Constants.err_file));
String file_name = file_in.file.getName();
if (data_names.contains(file_name)) {
SapforVersionComparisonState state = null;
switch (file_name) {
case Constants.parse_out_file:
state = SapforVersionComparisonState.CompilationOutput;
break;
case Constants.parse_err_file:
state = SapforVersionComparisonState.CompilationErrors;
break;
case Constants.out_file:
state = SapforVersionComparisonState.RunOutput;
break;
case Constants.err_file:
state = SapforVersionComparisonState.RunErrors;
break;
}
if (state != null) {
buttons.get(state).doClick();
}
2023-11-10 02:28:04 +03:00
return isReady();
} else {
cbFile.setSelectedIndex(-1);
for (int i = 0; i < cbFile.getItemCount(); ++i) {
ProjectFile projectFile = cbFile.getItemAt(i);
if (((GlobalDatabase)CommonUtils.db).settings.get(SettingName.ExtensionsOn).toBoolean()) {
//если учитываем расширения, ищем полное совпадение
if (projectFile.file.getName().equals(file_name)) {
cbFile.setSelectedIndex(i);
return true;
}
} else {
2024-10-07 14:22:52 +03:00
if (CommonUtils.getNameWithoutExtension(projectFile.file.getName()).equals(
CommonUtils.getNameWithoutExtension(file_name))) {
cbFile.setSelectedIndex(i);
return true;
}
2023-11-02 01:08:00 +03:00
}
}
return (cbFile.getSelectedItem() != null) && (cbFile.getSelectedItem() instanceof ProjectFile);
2023-11-02 01:08:00 +03:00
}
2023-11-02 00:01:34 +03:00
}
}