Files
VisualSapfor/src/_VisualDVM/Passes/All/PickCompilerEnvironments.java
2024-10-25 00:50:19 +03:00

100 lines
4.8 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package _VisualDVM.Passes.All;
import Common.CommonConstants;
import Common.Passes.Pass;
import Common.Visual.Windows.Dialog.Dialog;
import _VisualDVM.Global;
import _VisualDVM.GlobalData.Compiler.Compiler;
import _VisualDVM.GlobalData.Compiler.CompilerType;
import _VisualDVM.GlobalData.CompilerEnvironment.CompilerEnvironment;
import _VisualDVM.GlobalData.CompilerEnvironment.UI.CompilerEnvironmentsFields;
import _VisualDVM.GlobalData.EnvironmentValue.EnvironmentValue;
import _VisualDVM.GlobalData.RunConfiguration.RunConfiguration;
import _VisualDVM.Passes.PassCode;
import javax.swing.*;
import java.util.LinkedHashMap;
public class PickCompilerEnvironments extends Pass<String> {
Compiler compiler = null;
RunConfiguration configuration = null;
@Override
public String getIconPath() {
return "/icons/Menu/Regions.png";
}
@Override
public String getButtonText() {
return "";
}
//-
@Override
protected boolean canStart(Object... args) throws Exception {
if (Global.mainModule.getDb().runConfigurations.getUI().CheckCurrent(Log)) {
configuration = Global.mainModule.getDb().runConfigurations.getUI().getCurrent();
if (configuration.compiler_id == CommonConstants.Nan) {
Log.Writeln_("Отсутвует DVM компилятор, связанный с текущей конфигурацией запуска.\n" +
"Если конфигурация содержит вызов DVM компилятора, но была создана на версии 801 и ниже,\n" +
"войдите в окно её редактирования,нажмите ОК, а затем повторите попытку.");
return false;
}
//-
compiler = configuration.getCompiler();
if (!compiler.type.equals(CompilerType.dvm)) {
Log.Writeln_("Выбор переменных окружения возможен только для DVM компилятора,");
return false;
}
//-
if (!(compiler.helpLoaded || Global.mainModule.getPass(PassCode.ShowCompilerHelp).Do(compiler, false)))
return false;
//-
Dialog<String, CompilerEnvironmentsFields> dialog =
new Dialog<String, CompilerEnvironmentsFields>(CompilerEnvironmentsFields.class) {
@Override
public void InitFields() {
compiler.environments.mountUI((JPanel) fields.getContent());
compiler.environments.ShowUI();
}
@Override
public boolean NeedsScroll() {
return false;
}
@Override
public void validateFields() {
for (CompilerEnvironment compilerEnv : compiler.environments.Data.values()) {
if (compilerEnv.isSelected() && compilerEnv.value.isEmpty())
Log.Writeln_("Отмеченная переменная " + compilerEnv.name + " предполагает непустое значение.");
}
}
};
return dialog.ShowDialog("Назначение переменных окружения конфигурации запуска");
}
return false;
}
@Override
protected void body() throws Exception {
LinkedHashMap<String, String> envValues = configuration.getEnvMap();
for (CompilerEnvironment compilerEnv : compiler.environments.Data.values()) {
if (compilerEnv.isSelected()) {
EnvironmentValue confEnv;
if (!envValues.containsKey(compilerEnv.name)) {
confEnv = new EnvironmentValue();
confEnv.machine_id = configuration.machine_id;
confEnv.run_configuration_id = configuration.id;
confEnv.name = compilerEnv.name;
confEnv.value = compilerEnv.value;
Global.mainModule.getDb().Insert(confEnv);
} else {
confEnv = (Global.mainModule.getDb()).environmentValues.getEnvByName(compilerEnv.name);
if (confEnv != null) {
confEnv.name = compilerEnv.name;
confEnv.value = compilerEnv.value;
Global.mainModule.getDb().Update(confEnv);
}
}
}
}
}
@Override
protected void showDone() throws Exception {
(Global.mainModule.getDb()).environmentValues.ShowUI();
}
}