Files
VisualSapfor/src/Visual_DVM_2021/Passes/All/CopyProject.java
2024-10-14 11:48:44 +03:00

71 lines
2.9 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 Visual_DVM_2021.Passes.All;
import Common.Utils.Utils_;
import Common.Visual.UI_;
import _VisualDVM.Global;
import Common.Visual.Windows.Dialog.Dialog;
import _VisualDVM.Utils;
import Visual_DVM_2021.Passes.CurrentProjectPass;
import Visual_DVM_2021.Passes.PassCode;
import _VisualDVM.Visual.Windows.CopyProjectFields;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.nio.file.Paths;
public class CopyProject extends CurrentProjectPass {
protected File dstFile = null;
protected boolean migrateData = false;
@Override
public boolean hasStats() {
return true;
}
@Override
protected boolean canStart(Object... args) throws Exception {
if (super.canStart(args)) {
Dialog<Object, CopyProjectFields> dialog = new Dialog<Object, CopyProjectFields>(CopyProjectFields.class) {
@Override
public int getDefaultHeight() {
return 230;
}
@Override
public void Init(Object... params) {
fields.tfParent.setText(Global.visualiser.getWorkspace().getAbsolutePath());
}
@Override
public void validateFields() {
Utils.validateFileShortNewName(fields.tfName.getText(), Log);
if (!fields.tfParent.getText().isEmpty()) {
if (Utils_.ContainsCyrillic(fields.tfParent.getText()))
Log.Writeln_("Путь к целевой папке не может содержать кириллицу!");
} else Log.Writeln_("Путь к целевой папке не может быть пустым!");
if (Log.isEmpty()) {
dstFile = Paths.get(fields.tfParent.getText(), fields.tfName.getText()).toFile();
if (dstFile.exists())
Log.Writeln_("Файл " + dstFile.getAbsolutePath() + " уже существует!");
}
}
};
if (dialog.ShowDialog(getDescription())) {
migrateData = dialog.fields.MigrateData.isSelected();
return true;
}
}
return false;
}
@Override
public String getIconPath() {
return "/icons/Transformations/CopyProject.png";
}
@Override
protected void body() throws Exception {
FileUtils.forceMkdir(dstFile);
target.Clone(dstFile, migrateData);
}
@Override
protected void performDone() throws Exception {
if (UI_.Question("копия текущего проекта успешно создана по адресу\n" + dstFile.getAbsolutePath() + "\nОткрыть её")) {
Global.mainModule.getPass(PassCode.CloseCurrentProject).Do();
Global.mainModule.getPass(PassCode.OpenCurrentProject).Do(dstFile);
}
}
}