Browse Source

REPORT-96012 移动文件夹到自己文件夹下,文件夹丢失

release/11.0
Levy.Xie 2 years ago
parent
commit
d0d89d77f0
  1. 4
      designer-base/src/main/java/com/fr/design/file/DefaultTemplateTreeDefineProcessor.java
  2. 14
      designer-base/src/main/java/com/fr/design/file/FileOperationHelper.java
  3. 23
      designer-base/src/test/java/com/fr/design/file/FileOperationHelperTest.java

4
designer-base/src/main/java/com/fr/design/file/DefaultTemplateTreeDefineProcessor.java

@ -433,8 +433,8 @@ public class DefaultTemplateTreeDefineProcessor extends AbstractTemplateTreeDefi
WARNING_MESSAGE); WARNING_MESSAGE);
return false; return false;
} }
// 检查移动源文件夹是否为目标文件夹的子文件夹 // 检查移动的源文件夹是否为目标文件夹相同文件夹或子文件夹
if (FileOperationHelper.getInstance().isSubDirectory(getFileTree().getSelectedTreeNodes(), getTargetFileNode())) { if (FileOperationHelper.getInstance().isSubDirectoryOrSame(getFileTree().getSelectedTreeNodes(), getTargetFileNode())) {
FineJOptionPane.showMessageDialog(this, FineJOptionPane.showMessageDialog(this,
Toolkit.i18nText("Fine-Design_Basic_Move_To_SubDirectory"), Toolkit.i18nText("Fine-Design_Basic_Move_To_SubDirectory"),
Toolkit.i18nText("Fine-Design_Basic_Alert"), Toolkit.i18nText("Fine-Design_Basic_Alert"),

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

@ -36,16 +36,16 @@ public class FileOperationHelper {
} }
/** /**
* 检查目标文件夹是否为多个源文件夹中任一文件夹的子文件夹 * 检查目标文件夹是否为多个源文件夹中的任一文件夹或者任一文件夹的子文件夹
* *
* @param fileNodes 需移动的源文件 * @param fileNodes 需移动的源文件
* @param targetNode 移动后的目标文件夹 * @param targetNode 移动后的目标文件夹
* @return * @return
*/ */
public boolean isSubDirectory(@NotNull ExpandMutableTreeNode[] fileNodes, @NotNull FileNode targetNode) { public boolean isSubDirectoryOrSame(@NotNull ExpandMutableTreeNode[] fileNodes, @NotNull FileNode targetNode) {
for (ExpandMutableTreeNode treeNode : fileNodes) { for (ExpandMutableTreeNode treeNode : fileNodes) {
FileNode sourceFileNode = (FileNode) treeNode.getUserObject(); FileNode sourceFileNode = (FileNode) treeNode.getUserObject();
if (isSubDirectory(sourceFileNode, targetNode)) { if (isSubDirectoryOrSame(sourceFileNode, targetNode)) {
return true; return true;
} }
} }
@ -53,17 +53,17 @@ public class FileOperationHelper {
} }
/** /**
* 检查目标文件夹是否为源文件夹的子文件夹 * 检查目标文件夹是否为源文件夹或源文件夹的子文件夹
* *
* @param sourceFileNode 需移动的源文件 * @param sourceFileNode 需移动的源文件
* @param targetNode 移动后的目标文件夹 * @param targetNode 移动后的目标文件夹
*/ */
public boolean isSubDirectory(@NotNull FileNode sourceFileNode, @NotNull FileNode targetNode) { public boolean isSubDirectoryOrSame(@NotNull FileNode sourceFileNode, @NotNull FileNode targetNode) {
if (!sourceFileNode.isDirectory() || !targetNode.isDirectory()) { if (!sourceFileNode.isDirectory() || !targetNode.isDirectory()) {
return false; return false;
} }
Path sourceDir = Paths.get(sourceFileNode.getEnvPath()); Path sourceDir = Paths.get(sourceFileNode.getEnvPath()).normalize();
Path targetDir = Paths.get(targetNode.getEnvPath()); Path targetDir = Paths.get(targetNode.getEnvPath()).normalize();
return targetDir.startsWith(sourceDir); return targetDir.startsWith(sourceDir);
} }

23
designer-base/src/test/java/com/fr/design/file/FileOperationHelperTest.java

@ -23,22 +23,27 @@ public class FileOperationHelperTest {
FileNode sourceNode5 = new FileNode("/usr/local/webroot/reportlets/demo/test", true); FileNode sourceNode5 = new FileNode("/usr/local/webroot/reportlets/demo/test", true);
FileNode sourceNode6 = new FileNode("/usr/local/webroot/reportlets/demo/test", false); FileNode sourceNode6 = new FileNode("/usr/local/webroot/reportlets/demo/test", false);
FileNode sourceNode7 = new FileNode("/usr/local/webroot/reportlets/demo/test123", true); FileNode sourceNode7 = new FileNode("/usr/local/webroot/reportlets/demo/test123", true);
FileNode sourceNode8 = new FileNode("/usr/local/webroot/reportlets/../reportlets/demo/test", true);
FileNode sourceNode9 = new FileNode("/usr/local/webroot/reportlets/../reportlets/demo/test/c", true);
FileNode targetNode = new FileNode("/usr/local/webroot/reportlets/demo/test", true); FileNode targetNode = new FileNode("/usr/local/webroot/reportlets/demo/test", true);
Assert.assertTrue(FileOperationHelper.getInstance().isSubDirectory(sourceNode1, targetNode)); Assert.assertTrue(FileOperationHelper.getInstance().isSubDirectoryOrSame(sourceNode1, targetNode));
Assert.assertTrue(FileOperationHelper.getInstance().isSubDirectory(sourceNode2, targetNode)); Assert.assertTrue(FileOperationHelper.getInstance().isSubDirectoryOrSame(sourceNode2, targetNode));
Assert.assertFalse(FileOperationHelper.getInstance().isSubDirectory(sourceNode3, targetNode)); Assert.assertFalse(FileOperationHelper.getInstance().isSubDirectoryOrSame(sourceNode3, targetNode));
Assert.assertFalse(FileOperationHelper.getInstance().isSubDirectory(sourceNode4, targetNode)); Assert.assertFalse(FileOperationHelper.getInstance().isSubDirectoryOrSame(sourceNode4, targetNode));
Assert.assertTrue(FileOperationHelper.getInstance().isSubDirectory(sourceNode5, targetNode)); Assert.assertTrue(FileOperationHelper.getInstance().isSubDirectoryOrSame(sourceNode5, targetNode));
Assert.assertFalse(FileOperationHelper.getInstance().isSubDirectory(sourceNode6, targetNode)); Assert.assertFalse(FileOperationHelper.getInstance().isSubDirectoryOrSame(sourceNode6, targetNode));
Assert.assertFalse(FileOperationHelper.getInstance().isSubDirectory(sourceNode7, targetNode)); Assert.assertFalse(FileOperationHelper.getInstance().isSubDirectoryOrSame(sourceNode7, targetNode));
Assert.assertTrue(FileOperationHelper.getInstance().isSubDirectoryOrSame(sourceNode8, targetNode));
Assert.assertFalse(FileOperationHelper.getInstance().isSubDirectoryOrSame(sourceNode9, targetNode));
ExpandMutableTreeNode treeNode1 = new ExpandMutableTreeNode(sourceNode1); ExpandMutableTreeNode treeNode1 = new ExpandMutableTreeNode(sourceNode1);
ExpandMutableTreeNode treeNode2 = new ExpandMutableTreeNode(sourceNode2); ExpandMutableTreeNode treeNode2 = new ExpandMutableTreeNode(sourceNode2);
ExpandMutableTreeNode treeNode3 = new ExpandMutableTreeNode(sourceNode3); ExpandMutableTreeNode treeNode3 = new ExpandMutableTreeNode(sourceNode3);
ExpandMutableTreeNode treeNode4 = new ExpandMutableTreeNode(sourceNode4); ExpandMutableTreeNode treeNode4 = new ExpandMutableTreeNode(sourceNode4);
Assert.assertTrue(FileOperationHelper.getInstance().isSubDirectory(new ExpandMutableTreeNode[]{treeNode1, treeNode2, treeNode3}, targetNode)); Assert.assertTrue(FileOperationHelper.getInstance().isSubDirectoryOrSame(new ExpandMutableTreeNode[]{treeNode1, treeNode2, treeNode3}, targetNode));
Assert.assertFalse(FileOperationHelper.getInstance().isSubDirectory(new ExpandMutableTreeNode[]{treeNode3, treeNode4}, targetNode)); Assert.assertFalse(FileOperationHelper.getInstance().isSubDirectoryOrSame(new ExpandMutableTreeNode[]{treeNode3, treeNode4}, targetNode));
} }
} }
Loading…
Cancel
Save