Files
VisualSapfor/src/Visual_DVM_2021/UI/Main/VersionsComparisonForm.java

111 lines
4.3 KiB
Java
Raw Normal View History

2023-09-17 22:13:42 +03:00
package Visual_DVM_2021.UI.Main;
import Common.Current;
import Common.Global;
import Common.Utils.Utils;
import GlobalData.Settings.SettingName;
import ProjectData.Files.DBProjectFile;
import ProjectData.Files.ProjectFile;
2023-09-17 22:13:42 +03:00
import ProjectData.Project.db_project_info;
import javax.swing.*;
import java.util.Vector;
public class VersionsComparisonForm extends ComparisonForm<db_project_info> {
private final JComboBox<DBProjectFile> cbFile;
protected DBProjectFile file = null;
private VersionsComparisonForm getMaster() {
return (VersionsComparisonForm) master;
}
private VersionsComparisonForm getSlave() {
return (VersionsComparisonForm) slave;
}
public VersionsComparisonForm(VersionsComparisonForm slave_in) {
super(db_project_info.class, slave_in);
cbFile = new JComboBox<>();
tools.add(cbFile, 3);
file = (cbFile.getSelectedItem() instanceof DBProjectFile) ?
((DBProjectFile) cbFile.getSelectedItem()) : null;
2023-09-17 22:13:42 +03:00
cbFile.addActionListener(e -> {
file = (cbFile.getSelectedItem() instanceof DBProjectFile) ?
((DBProjectFile) cbFile.getSelectedItem()) : null;
//-->>
if (isMaster()) {
if (isReady() && !getSlave().selectSameFile(file))
DoShowPass(true);
} else {
if (isReady()) {
if (getMaster().isReady()) {
2023-09-17 22:13:42 +03:00
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);
2023-09-17 22:13:42 +03:00
if (Global.db.settings.get(SettingName.ComparsionDiffMergeOn).toBoolean()) {
if (name1.equalsIgnoreCase(name2))
master.DoComparePass(true);
} else
master.DoShowPass(true);
} else {
master.DoShowPass(true);
2023-09-17 22:13:42 +03:00
}
}
}
});
}
@Override
protected Current getCurrentObjectName() {
return Current.Version;
}
@Override
protected String getText() {
return isReady() ? Utils.ReadAllText(file.file) : "объект не назначен";
2023-09-17 22:13:42 +03:00
}
@Override
protected void removeObject() {
cbFile.removeAllItems();
file = null;
}
@Override
public boolean isReady() {
return super.isReady() && file != null;
}
@Override
protected void showObject() {
lObjectName.setText(object.name);
lObjectName.setToolTipText(
object.getVersionTooltip()
);
cbFile.removeAllItems();
Vector<DBProjectFile> files = object.getFilesForComparsion();
for (DBProjectFile file : files)
cbFile.addItem(file);
}
public boolean selectSameFile(ProjectFile file_in) {
2023-09-17 22:13:42 +03:00
file = null;
cbFile.setSelectedIndex(-1);
for (int i = 0; i < cbFile.getItemCount(); ++i) {
ProjectFile projectFile = cbFile.getItemAt(i);
2023-09-17 22:13:42 +03:00
if (Global.db.settings.get(SettingName.ExtensionsOn).toBoolean()) {
2023-11-02 00:01:34 +03:00
//если учитываем расширения, ищем полное совпадение
if (projectFile.file.getName().equals(file_in.file.getName())) {
2023-09-17 22:13:42 +03:00
cbFile.setSelectedIndex(i);
return true;
2023-09-17 22:13:42 +03:00
}
} else {
if (Utils.getNameWithoutExtension(projectFile.file.getName()).equals(
Utils.getNameWithoutExtension(file_in.file.getName()))) {
2023-09-17 22:13:42 +03:00
cbFile.setSelectedIndex(i);
return true;
2023-09-17 22:13:42 +03:00
}
}
}
return (cbFile.getSelectedItem() != null) && (cbFile.getSelectedItem() instanceof ProjectFile);
2023-09-17 22:13:42 +03:00
}
public void CheckVersion(db_project_info version_in) {
if ((object != null) && version_in.Home.equals(object.Home)) {
RemoveObject();
}
}
@Override
protected boolean fortranWrapsOn() {
return Global.db.settings.get(SettingName.FortranWrapsOn).toBoolean();
}
}