Browse Source

代码规范及右键增加定位模板功能

release/11.0
roger 2 years ago
parent
commit
400df5f266
  1. 4
      designer-base/src/main/java/com/fr/design/actions/file/LocateAction.java
  2. 3
      designer-base/src/main/java/com/fr/design/actions/file/RenameAction.java
  3. 32
      designer-base/src/main/java/com/fr/design/file/DefaultTemplateTreeDefineProcessor.java
  4. 4
      designer-base/src/main/java/com/fr/design/file/FileOperationHelper.java
  5. 30
      designer-base/src/main/java/com/fr/design/file/TemplateTreePane.java

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

@ -8,6 +8,7 @@ import com.fr.design.gui.itree.refreshabletree.ExpandMutableTreeNode;
import com.fr.design.gui.itree.refreshabletree.RefreshableJTree;
import com.fr.design.i18n.Toolkit;
import com.fr.design.mainframe.JTemplate;
import com.fr.design.mainframe.manager.search.TemplateTreeSearchManager;
import com.fr.file.filetree.FileNode;
import com.fr.general.ComparatorUtils;
import com.fr.stable.CoreConstants;
@ -49,6 +50,9 @@ public class LocateAction extends UpdateAction {
if (locatedPath == null) {
return;
}
if (TemplateTreeSearchManager.getInstance().isInSearchMode()) {
TemplateTreeSearchManager.getInstance().outOfSearchMode();
}
DefaultTreeModel model = (DefaultTreeModel) getTemplateFileTree().getModel();
ExpandMutableTreeNode treeNode = (ExpandMutableTreeNode) model.getRoot();

3
designer-base/src/main/java/com/fr/design/actions/file/RenameAction.java

@ -294,11 +294,8 @@ public class RenameAction extends UpdateAction {
VcsHelper.getInstance().moveVcs(path, newPath.replaceFirst(ProjectConstants.REPORTLETS_NAME, StringUtils.EMPTY));
}
DesignerContext.getDesignerFrame().setTitle();
if (TemplateTreeSearchManager.getInstance().isInSearchMode()) {
TemplateTreeSearchManager.getInstance().outOfSearchMode();
LocateAction.gotoEditingTemplateLeaf(newPath);
}
}
private void validInput() {

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

@ -59,6 +59,7 @@ public class DefaultTemplateTreeDefineProcessor extends AbstractTemplateTreeDefi
private PasteAction pasteAction;
private DelFileAction delFileAction;
private MoveAction moveAction;
private LocateAction locateAction;
public static DefaultTemplateTreeDefineProcessor getInstance() {
return DefaultTemplateTreeDefineProcessor.HOLDER.singleton;
@ -78,6 +79,7 @@ public class DefaultTemplateTreeDefineProcessor extends AbstractTemplateTreeDefi
pasteAction = new PasteAction();
delFileAction = new DelFileAction();
moveAction = new MoveAction();
locateAction = new OpenInTemplateTreeAction();
//右键菜单
popupMenu = new UIPopupMenu();
popupMenu.add(renameAction.createMenuItem());
@ -87,6 +89,7 @@ public class DefaultTemplateTreeDefineProcessor extends AbstractTemplateTreeDefi
popupMenu.add(delFileAction.createMenuItem());
popupMenu.addSeparator();
popupMenu.add(moveAction.createMenuItem());
popupMenu.add(locateAction.createMenuItem());
}
@Override
@ -103,6 +106,7 @@ public class DefaultTemplateTreeDefineProcessor extends AbstractTemplateTreeDefi
pasteAction.setEnabled(false);
delFileAction.setEnabled(false);
moveAction.setEnabled(false);
locateAction.setEnabled(false);
int length = getFileTree().getSelectionCount();
if (length == 0) {
//没有选中文件时,只能黏贴
@ -114,6 +118,10 @@ public class DefaultTemplateTreeDefineProcessor extends AbstractTemplateTreeDefi
if (length == 1) {
//选中一个时可以,可以重命名、黏贴
renameAction.setEnabled(true);
if (TemplateTreeSearchManager.getInstance().isInSearchMode()) {
//搜索模式开启定位当前模板
locateAction.setEnabled(true);
}
if (!CollectionUtils.isEmpty(TemplateTreeClipboard.getInstance().takeFromClip())) {
pasteAction.setEnabled(true);
}
@ -158,6 +166,22 @@ public class DefaultTemplateTreeDefineProcessor extends AbstractTemplateTreeDefi
}
}
private class OpenInTemplateTreeAction extends LocateAction {
public OpenInTemplateTreeAction() {
this.setName(Toolkit.i18nText("Fine-Design_Basic_Locate_Node"));
}
@Override
public void actionPerformed(ActionEvent e) {
FileNode fileNode = getFileTree().getSelectedFileNode();
if (fileNode == null) {
return;
}
gotoEditingTemplateLeaf(fileNode.getEnvPath());
}
}
/**
* 黏贴功能
*/
@ -256,10 +280,6 @@ public class DefaultTemplateTreeDefineProcessor extends AbstractTemplateTreeDefi
JOptionPane.ERROR_MESSAGE);
}
// 粘贴时如果正在搜索,跳回原树
if (TemplateTreeSearchManager.getInstance().isInSearchMode()) {
TemplateTreeSearchManager.getInstance().outOfSearchMode();
}
DesignerFrameFileDealerPane.getInstance().getSelectedOperation().refreshParent();
LocateAction.gotoEditingTemplateLeaf(targetFile);
}
@ -402,10 +422,6 @@ public class DefaultTemplateTreeDefineProcessor extends AbstractTemplateTreeDefi
ToastMsgDialog dialog = DesignerToastMsgUtil.createPromptDialog(Toolkit.i18nText("Fine-Design_Basic_Template_Moved_Success"));
dialog.setVisible(true);
// 移动时如果正在搜索,跳回原树
if (TemplateTreeSearchManager.getInstance().isInSearchMode()) {
TemplateTreeSearchManager.getInstance().outOfSearchMode();
}
DesignerFrameFileDealerPane.getInstance().getSelectedOperation().refresh();
LocateAction.gotoEditingTemplateLeaf(targetFile);
}

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

@ -131,14 +131,16 @@ public class FileOperationHelper {
if (ArrayUtils.isEmpty(fileNodes)) {
//空目录:相当于新建一个目录
DesignerFrameFileDealerPane.getInstance().getSelectedOperation().mkdir(targetDir);
return;
}
for (FileNode fileNode : fileNodes) {
if (fileNode.isDirectory()) {
copyDir(StableUtils.pathJoin(fileNode.getParent(), fileNode.getName()), StableUtils.pathJoin(targetDir, fileNode.getName()), withCopyVcs);
}
} else {
copyFile(StableUtils.pathJoin(sourceDir, fileNode.getName()), StableUtils.pathJoin(targetDir, fileNode.getName()), withCopyVcs);
}
}
}
private void copyFile(String sourcePath, String targetPath, boolean withCopyVcs) {
//检查源文件是不是还存在

30
designer-base/src/main/java/com/fr/design/file/TemplateTreePane.java

@ -513,27 +513,31 @@ public class TemplateTreePane extends JPanel implements FileOperations {
if (treePath == null) {
return false;
}
DefaultMutableTreeNode currentTreeNode = (DefaultMutableTreeNode) treePath.getLastPathComponent();
Enumeration children;
//现在可以在目录下创建目录,重命名时是基于所选节点的父目录的子目录进行校验,目录下新建子目录时,基于所选目录的子目录进行校验
if (reportletsTree.getSelectedFileNode().isDirectory() && baseOnSelf) {
children = currentTreeNode.children();
} else {
TreeNode parentTreeNode = currentTreeNode.getParent();
children = parentTreeNode.children();
}
boolean result = false;
Enumeration children = getChild(treePath, baseOnSelf);
while (children.hasMoreElements()) {
DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) children.nextElement();
Object object = childNode.getUserObject();
if (object instanceof FileNode) {
if (ComparatorUtils.equals(((FileNode) object).getName(), newName + suffix)) {
return true;
result = true;
}
} else {
return false;
}
}
return false;
return result;
}
private Enumeration getChild(TreePath treePath, boolean baseOnSelf) {
DefaultMutableTreeNode currentTreeNode = (DefaultMutableTreeNode) treePath.getLastPathComponent();
Enumeration children;
//现在可以在目录下创建目录,重命名时是基于所选节点的父目录的子目录进行校验,目录下新建子目录时,基于所选目录的子目录进行校验
if (reportletsTree.getSelectedFileNode().isDirectory() && baseOnSelf) {
children = currentTreeNode.children();
} else {
TreeNode parentTreeNode = currentTreeNode.getParent();
children = parentTreeNode.children();
}
return children;
}
}

Loading…
Cancel
Save