Files
VisualSapfor/src/_VisualDVM/Visual/Windows/VersionsComparisonForm.java
2024-10-12 00:17:51 +03:00

113 lines
4.5 KiB
Java

package _VisualDVM.Visual.Windows;
import Common.Utils.Utils_;
import _VisualDVM.Current;
import _VisualDVM.Global;
import _VisualDVM.Utils;
import _VisualDVM.GlobalData.GlobalDatabase;
import _VisualDVM.GlobalData.Settings.SettingName;
import _VisualDVM.ProjectData.Files.DBProjectFile;
import _VisualDVM.ProjectData.Files.ProjectFile;
import _VisualDVM.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;
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()) {
boolean ExtensionsOn = (Global.mainModule.getDb()).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.mainModule.getDb()).settings.get(SettingName.ComparsionDiffMergeOn).toBoolean()) {
if (name1.equalsIgnoreCase(name2))
master.DoComparePass(true);
} else
master.DoShowPass(true);
} else {
master.DoShowPass(true);
}
}
}
});
}
@Override
protected Current getCurrentObjectName() {
return Current.Version;
}
@Override
protected String getText() {
return isReady() ? Utils.ReadAllText(file.file) : "объект не назначен";
}
@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) {
file = null;
cbFile.setSelectedIndex(-1);
for (int i = 0; i < cbFile.getItemCount(); ++i) {
ProjectFile projectFile = cbFile.getItemAt(i);
if ((Global.mainModule.getDb()).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;
}
}
}
return (cbFile.getSelectedItem() != null) && (cbFile.getSelectedItem() instanceof ProjectFile);
}
public void CheckVersion(db_project_info version_in) {
if ((object != null) && version_in.Home.equals(object.Home)) {
RemoveObject();
}
}
@Override
protected boolean fortranWrapsOn() {
return (Global.mainModule.getDb()).settings.get(SettingName.FortranWrapsOn).toBoolean();
}
}