кнопки для отображения служебных файлов.
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
package Visual_DVM_2021.UI.Main;
|
||||
public enum SapforVersionComparisonState {
|
||||
//названия только для изображений.
|
||||
CompilationOutput,
|
||||
CompilationErrors,
|
||||
RunOutput,
|
||||
RunErrors;
|
||||
public String getDescription(){
|
||||
switch (this){
|
||||
case CompilationOutput:
|
||||
return "Поток вывода парсера";
|
||||
case CompilationErrors:
|
||||
return "Поток ошибок парсера";
|
||||
case RunOutput:
|
||||
return "Поток вывода преобразования";
|
||||
case RunErrors:
|
||||
return "Поток ошибок преобразования";
|
||||
default:
|
||||
return "?";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,20 @@
|
||||
package Visual_DVM_2021.UI.Main;
|
||||
import Common.Constants;
|
||||
import Common.Current;
|
||||
import Common.Global;
|
||||
import Common.UI.Menus_2023.MenuBarButton;
|
||||
import Common.Utils.Utils;
|
||||
import GlobalData.Settings.SettingName;
|
||||
import ProjectData.Files.ProjectFile;
|
||||
import SapforTestingSystem.Json.SapforVersion_json;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Vector;
|
||||
public class SapforVersionsComparisonForm extends ComparisonForm<SapforVersion_json> {
|
||||
//--
|
||||
protected LinkedHashMap<SapforVersionComparisonState, JButton> buttons = null;
|
||||
//почти полный клон VersionsComparsionForm. В будущем нужен рефакторинг. Наверное.
|
||||
Current current;
|
||||
private final JComboBox<ProjectFile> cbFile;
|
||||
@@ -27,29 +34,61 @@ public class SapforVersionsComparisonForm extends ComparisonForm<SapforVersion_j
|
||||
tools.add(cbFile, 3);
|
||||
//--
|
||||
cbFile.addActionListener(e -> {
|
||||
file = (cbFile.getSelectedItem() instanceof ProjectFile) ?
|
||||
((ProjectFile) cbFile.getSelectedItem()) : null;
|
||||
//-->>
|
||||
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);
|
||||
SelectFile(((cbFile.getSelectedItem() instanceof ProjectFile) ? ((ProjectFile) cbFile.getSelectedItem()) : null));
|
||||
});
|
||||
//--
|
||||
buttons = new LinkedHashMap<>();
|
||||
int i = 4;
|
||||
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;
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected Current getCurrentObjectName() {
|
||||
@@ -57,7 +96,9 @@ public class SapforVersionsComparisonForm extends ComparisonForm<SapforVersion_j
|
||||
}
|
||||
@Override
|
||||
protected String getText() {
|
||||
return isReady() ? Utils.ReadAllText(file.file) : "объект не назначен";
|
||||
return isReady() ?
|
||||
(file.file.exists() ? Utils.ReadAllText(file.file) : "файл не найден")
|
||||
: "объект не назначен";
|
||||
}
|
||||
@Override
|
||||
public boolean isReady() {
|
||||
@@ -78,23 +119,51 @@ public class SapforVersionsComparisonForm extends ComparisonForm<SapforVersion_j
|
||||
}
|
||||
public boolean selectSameFile(ProjectFile file_in) {
|
||||
file = null;
|
||||
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_in.file.getName())) {
|
||||
cbFile.setSelectedIndex(i);
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if (Utils.getNameWithoutExtension(projectFile.file.getName()).equals(
|
||||
Utils.getNameWithoutExtension(file_in.file.getName()))) {
|
||||
cbFile.setSelectedIndex(i);
|
||||
return true;
|
||||
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();
|
||||
}
|
||||
return true;
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
return (cbFile.getSelectedItem() != null) && (cbFile.getSelectedItem() instanceof ProjectFile);
|
||||
}
|
||||
return (cbFile.getSelectedItem() != null) && (cbFile.getSelectedItem() instanceof ProjectFile);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user