2023-11-19 01:53:56 +03:00
|
|
|
|
package Common.UI.Windows.Main;
|
2023-11-10 02:22:44 +03:00
|
|
|
|
import Common.Constants;
|
2023-11-02 00:01:34 +03:00
|
|
|
|
import Common.Current;
|
2023-11-02 01:08:00 +03:00
|
|
|
|
import Common.Global;
|
2023-11-10 02:22:44 +03:00
|
|
|
|
import Common.UI.Menus_2023.MenuBarButton;
|
2023-11-02 01:08:00 +03:00
|
|
|
|
import Common.Utils.Utils;
|
|
|
|
|
|
import GlobalData.Settings.SettingName;
|
|
|
|
|
|
import ProjectData.Files.ProjectFile;
|
2023-11-19 01:53:56 +03:00
|
|
|
|
import Repository.TestingSystem.SAPFOR.Json.SapforVersion_json;
|
|
|
|
|
|
import Common.Passes.PassCode_2021;
|
|
|
|
|
|
import Common.Passes.Pass_2021;
|
2023-11-02 01:08:00 +03:00
|
|
|
|
|
|
|
|
|
|
import javax.swing.*;
|
2023-11-10 02:22:44 +03:00
|
|
|
|
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> {
|
2023-11-10 02:22:44 +03:00
|
|
|
|
//--
|
|
|
|
|
|
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<>();
|
2023-11-12 02:14:20 +03:00
|
|
|
|
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 -> {
|
2023-11-10 02:22:44 +03:00
|
|
|
|
SelectFile(((cbFile.getSelectedItem() instanceof ProjectFile) ? ((ProjectFile) cbFile.getSelectedItem()) : null));
|
|
|
|
|
|
});
|
|
|
|
|
|
//--
|
|
|
|
|
|
buttons = new LinkedHashMap<>();
|
2023-11-12 02:14:20 +03:00
|
|
|
|
int i = 5;
|
2023-11-10 02:22:44 +03:00
|
|
|
|
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
|
|
|
|
}
|
2023-11-10 02:22:44 +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 = Global.db.settings.get(SettingName.ExtensionsOn).toBoolean();
|
|
|
|
|
|
String name1 = ExtensionsOn ? getMaster().file.file.getName() : Utils.getFileNameWithoutExtension(getMaster().file.file);
|
|
|
|
|
|
String name2 = ExtensionsOn ? file.file.getName() : Utils.getFileNameWithoutExtension(file.file);
|
|
|
|
|
|
if (Global.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-10 02:22:44 +03:00
|
|
|
|
}
|
2023-11-02 00:01:34 +03:00
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
|
|
|
protected Current getCurrentObjectName() {
|
|
|
|
|
|
return current;
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
|
|
|
protected String getText() {
|
2023-11-10 02:22:44 +03:00
|
|
|
|
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());
|
|
|
|
|
|
lObjectName.setToolTipText(object.toString());
|
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;
|
|
|
|
|
|
}
|
2023-11-02 20:43:45 +03:00
|
|
|
|
public boolean selectSameFile(ProjectFile file_in) {
|
2023-11-02 01:08:00 +03:00
|
|
|
|
file = null;
|
2023-11-10 02:22:44 +03:00
|
|
|
|
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();
|
2023-11-10 02:22:44 +03:00
|
|
|
|
} else {
|
|
|
|
|
|
cbFile.setSelectedIndex(-1);
|
|
|
|
|
|
for (int i = 0; i < cbFile.getItemCount(); ++i) {
|
|
|
|
|
|
ProjectFile projectFile = cbFile.getItemAt(i);
|
|
|
|
|
|
if (Global.db.settings.get(SettingName.ExtensionsOn).toBoolean()) {
|
|
|
|
|
|
//если учитываем расширения, ищем полное совпадение
|
|
|
|
|
|
if (projectFile.file.getName().equals(file_name)) {
|
|
|
|
|
|
cbFile.setSelectedIndex(i);
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
if (Utils.getNameWithoutExtension(projectFile.file.getName()).equals(
|
|
|
|
|
|
Utils.getNameWithoutExtension(file_name))) {
|
|
|
|
|
|
cbFile.setSelectedIndex(i);
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2023-11-02 01:08:00 +03:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-11-10 02:22:44 +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
|
|
|
|
}
|
|
|
|
|
|
}
|