Browse Source

REPORT-96012 移动文件夹到自己文件夹下,文件夹丢失 优化代码

newui
Levy.Xie 2 years ago
parent
commit
3e2dfd6f53
  1. 21
      designer-base/src/main/java/com/fr/design/file/FileOperationHelper.java

21
designer-base/src/main/java/com/fr/design/file/FileOperationHelper.java

@ -18,6 +18,8 @@ import com.fr.workspace.WorkContext;
import com.fr.workspace.resource.ResourceIOException; import com.fr.workspace.resource.ResourceIOException;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
import static javax.swing.JOptionPane.WARNING_MESSAGE; import static javax.swing.JOptionPane.WARNING_MESSAGE;
@ -27,8 +29,6 @@ import static javax.swing.JOptionPane.WARNING_MESSAGE;
*/ */
public class FileOperationHelper { public class FileOperationHelper {
private static final char DIR_SEPARATOR = '/';
private static final FileOperationHelper INSTANCE = new FileOperationHelper(); private static final FileOperationHelper INSTANCE = new FileOperationHelper();
public static FileOperationHelper getInstance() { public static FileOperationHelper getInstance() {
@ -36,10 +36,10 @@ public class FileOperationHelper {
} }
/** /**
* 检查多个目标文件夹是否含有源文件夹的子文件夹 * 检查目标文件夹是否为多个源文件夹中任一文件夹的子文件夹
* *
* @param fileNodes * @param fileNodes 需移动的源文件
* @param targetNode * @param targetNode 移动后的目标文件夹
* @return * @return
*/ */
public boolean isSubDirectory(@NotNull ExpandMutableTreeNode[] fileNodes, @NotNull FileNode targetNode) { public boolean isSubDirectory(@NotNull ExpandMutableTreeNode[] fileNodes, @NotNull FileNode targetNode) {
@ -55,17 +55,16 @@ public class FileOperationHelper {
/** /**
* 检查目标文件夹是否为源文件夹的子文件夹 * 检查目标文件夹是否为源文件夹的子文件夹
* *
* @param sourceFileNode * @param sourceFileNode 需移动的源文件
* @param targetNode * @param targetNode 移动后的目标文件夹
*/ */
public boolean isSubDirectory(@NotNull FileNode sourceFileNode, @NotNull FileNode targetNode) { public boolean isSubDirectory(@NotNull FileNode sourceFileNode, @NotNull FileNode targetNode) {
if (!sourceFileNode.isDirectory() || !targetNode.isDirectory()) { if (!sourceFileNode.isDirectory() || !targetNode.isDirectory()) {
return false; return false;
} }
String sourceDir = sourceFileNode.getEnvPath(); Path sourceDir = Paths.get(sourceFileNode.getEnvPath());
String targetDir = targetNode.getEnvPath(); Path targetDir = Paths.get(targetNode.getEnvPath());
return StringUtils.equals(targetDir, sourceDir) || return targetDir.startsWith(sourceDir);
(targetDir.startsWith(sourceDir) && targetDir.charAt(sourceDir.length()) == DIR_SEPARATOR);
} }
public String moveFile(FileNode sourceFileNode, String targetDir) { public String moveFile(FileNode sourceFileNode, String targetDir) {

Loading…
Cancel
Save