2024-10-14 12:14:01 +03:00
|
|
|
package _VisualDVM.Passes.All;
|
2024-10-14 15:19:13 +03:00
|
|
|
import Common.Visual.Controls.PassMenuItem;
|
2024-10-08 23:45:06 +03:00
|
|
|
import Common.Visual.Windows.Dialog.VFileChooser;
|
2024-10-14 15:19:13 +03:00
|
|
|
import _VisualDVM.Global;
|
2024-10-14 12:14:01 +03:00
|
|
|
import _VisualDVM.Passes.CurrentComponentPass;
|
2023-09-17 22:13:42 +03:00
|
|
|
|
|
|
|
|
import javax.swing.*;
|
|
|
|
|
import javax.swing.filechooser.FileFilter;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.nio.file.Files;
|
|
|
|
|
import java.nio.file.StandardCopyOption;
|
|
|
|
|
public class ResurrectComponent extends CurrentComponentPass {
|
2024-10-14 15:19:13 +03:00
|
|
|
File file;
|
|
|
|
|
VFileChooser fileChooser;
|
2023-09-17 22:13:42 +03:00
|
|
|
@Override
|
|
|
|
|
public JMenuItem createMenuItem() {
|
|
|
|
|
if (menuItem == null)
|
|
|
|
|
menuItem = new PassMenuItem(this);
|
|
|
|
|
return menuItem;
|
|
|
|
|
}
|
|
|
|
|
@Override
|
|
|
|
|
public String getButtonText() {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
@Override
|
|
|
|
|
protected boolean canStart(Object... args) throws Exception {
|
|
|
|
|
if (super.canStart(args)) {
|
|
|
|
|
//тут таргет меняется, поэтому меняется и условие выбора файлов.
|
|
|
|
|
fileChooser = new VFileChooser(
|
|
|
|
|
"Выбор версии компонента для восстановления",
|
|
|
|
|
new FileFilter() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean accept(File f) {
|
|
|
|
|
return f.isFile() &&
|
|
|
|
|
f.getName().startsWith(target.getComponentType().toString());
|
|
|
|
|
}
|
|
|
|
|
@Override
|
|
|
|
|
public String getDescription() {
|
|
|
|
|
return target.getComponentType().toString() + "*";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
fileChooser.SetCurrentDirectory(Global.BackUpsDirectory);
|
|
|
|
|
return (file = fileChooser.ShowDialog()) != null;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
@Override
|
|
|
|
|
protected void body() throws Exception {
|
|
|
|
|
Files.copy(file.toPath(), target.getNewFile().toPath(), StandardCopyOption.REPLACE_EXISTING);
|
|
|
|
|
target.Update();
|
|
|
|
|
}
|
|
|
|
|
@Override
|
|
|
|
|
protected void performDone() throws Exception {
|
|
|
|
|
target.InitialVersionCheck();
|
|
|
|
|
if (target.CanBeUpdated())
|
|
|
|
|
target.CheckIfNeedsUpdateOrPublish();
|
|
|
|
|
}
|
|
|
|
|
@Override
|
|
|
|
|
protected void showDone() throws Exception {
|
2024-10-22 20:16:57 +03:00
|
|
|
Global.components.RefreshUpdatesStatus();
|
2023-09-17 22:13:42 +03:00
|
|
|
}
|
|
|
|
|
}
|