2023-09-17 22:13:42 +03:00
|
|
|
|
package GlobalData.RemoteFile.UI;
|
2024-10-07 22:04:09 +03:00
|
|
|
|
import Common.Utils.CommonUtils;
|
2024-10-07 00:58:29 +03:00
|
|
|
|
import Common_old.Current;
|
|
|
|
|
|
import Common_old.UI.UI;
|
|
|
|
|
|
import Common_old.UI.Windows.Dialog.Dialog;
|
2023-09-17 22:13:42 +03:00
|
|
|
|
import GlobalData.RemoteFile.RemoteFile;
|
2024-01-08 20:37:16 +03:00
|
|
|
|
import Visual_DVM_2021.Passes.SSH.ConnectionPass;
|
2023-09-17 22:13:42 +03:00
|
|
|
|
import com.jcraft.jsch.ChannelSftp.LsEntry;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.swing.tree.DefaultMutableTreeNode;
|
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
|
import java.util.Comparator;
|
|
|
|
|
|
import java.util.Vector;
|
|
|
|
|
|
public class RemoteFileChooser extends Dialog<String, RemoteFileChooserFields> {
|
|
|
|
|
|
public DefaultMutableTreeNode root = new DefaultMutableTreeNode("нет данных");
|
|
|
|
|
|
ConnectionPass session;
|
|
|
|
|
|
RemoteFile root_file;
|
|
|
|
|
|
boolean target_is_directory = false;
|
|
|
|
|
|
public RemoteFileChooser() {
|
|
|
|
|
|
super(RemoteFileChooserFields.class);
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public boolean NeedsScroll() {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void Init(Object... params) {
|
|
|
|
|
|
session = (ConnectionPass) params[0];
|
|
|
|
|
|
target_is_directory = (boolean) params[1];
|
|
|
|
|
|
try {
|
2024-01-08 20:37:16 +03:00
|
|
|
|
Refresh(session.user.connection.sftpChannel.pwd());
|
2023-09-17 22:13:42 +03:00
|
|
|
|
} catch (Exception ex) {
|
2024-10-07 22:04:09 +03:00
|
|
|
|
CommonUtils.MainLog.PrintException(ex);
|
2023-09-17 22:13:42 +03:00
|
|
|
|
onCancel(); //закрываем окно.
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
public void ShowCurrentRemoteFile() {
|
|
|
|
|
|
fields.lCurrentFile.setText(Current.getRemoteFile().full_name);
|
|
|
|
|
|
}
|
|
|
|
|
|
public void Refresh(String path) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
Current.set(Current.RemoteFile, null);//сброс текущего файла перед любым обновлением.
|
|
|
|
|
|
fields.lCurrentFile.setText("?");
|
|
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
|
|
root_file = new RemoteFile(path, true);
|
|
|
|
|
|
root = new DefaultMutableTreeNode(root_file);
|
|
|
|
|
|
//-------------------------------------------------------
|
2024-01-08 20:37:16 +03:00
|
|
|
|
Vector<LsEntry> files = session.user.connection.sftpChannel.ls(path);
|
2023-09-17 22:13:42 +03:00
|
|
|
|
Vector<RemoteFile> directories_ = new Vector<>();
|
|
|
|
|
|
Vector<RemoteFile> files_ = new Vector<>();
|
|
|
|
|
|
//отсортировать по принадлежности.
|
|
|
|
|
|
for (LsEntry file : files) {
|
|
|
|
|
|
if (!file.getFilename().equals(".") && !file.getFilename().equals("")) {
|
|
|
|
|
|
if (file.getAttrs().isDir())
|
|
|
|
|
|
directories_.add(new RemoteFile(root_file.full_name, file.getFilename(), true));
|
|
|
|
|
|
else
|
|
|
|
|
|
files_.add(new RemoteFile(root_file.full_name, file.getFilename(), false));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//отсортировать по алфавиту
|
|
|
|
|
|
Collections.sort(directories_, Comparator.comparing(o -> o.name));
|
|
|
|
|
|
Collections.sort(files_, Comparator.comparing(o -> o.name));
|
|
|
|
|
|
for (RemoteFile f : directories_)
|
|
|
|
|
|
root.add(new DefaultMutableTreeNode(f));
|
|
|
|
|
|
for (RemoteFile f : files_)
|
|
|
|
|
|
root.add(new DefaultMutableTreeNode(f));
|
|
|
|
|
|
//просто пересоздаем дерево
|
|
|
|
|
|
fields.treeForm.Show();
|
|
|
|
|
|
fields.lCurrentFolder.setText(path);
|
|
|
|
|
|
} catch (Exception ex) {
|
2024-10-07 22:04:09 +03:00
|
|
|
|
CommonUtils.MainLog.PrintException(ex);
|
2023-09-17 22:13:42 +03:00
|
|
|
|
onCancel();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
public void goHome() {
|
|
|
|
|
|
try {
|
2024-01-08 20:37:16 +03:00
|
|
|
|
Refresh(session.user.connection.sftpChannel.getHome());
|
2023-09-17 22:13:42 +03:00
|
|
|
|
} catch (Exception ex) {
|
2024-10-07 22:04:09 +03:00
|
|
|
|
CommonUtils.MainLog.PrintException(ex);
|
2023-09-17 22:13:42 +03:00
|
|
|
|
onCancel(); //закрываем окно.
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
public void goUp() {
|
|
|
|
|
|
if (!root_file.full_name.equals("/")) {
|
|
|
|
|
|
Refresh(root_file.parent);
|
|
|
|
|
|
} else UI.Info("Корневая папка файловой системы достигнута.");
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void validateFields() {
|
|
|
|
|
|
String target_name = target_is_directory ? "папка" : "файл";
|
|
|
|
|
|
if (Current.HasRemoteFile()) {
|
|
|
|
|
|
if (target_is_directory != Current.getRemoteFile().isDirectory)
|
|
|
|
|
|
Log.Writeln("Выбранный объект - не " + target_name);
|
|
|
|
|
|
} else Log.Writeln(target_name + " не выбран(а)");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|