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.gui.itree.refreshabletree.RefreshableJTree;
import com.fr.design.i18n.Toolkit; import com.fr.design.i18n.Toolkit;
import com.fr.design.mainframe.JTemplate; import com.fr.design.mainframe.JTemplate;
import com.fr.design.mainframe.manager.search.TemplateTreeSearchManager;
import com.fr.file.filetree.FileNode; import com.fr.file.filetree.FileNode;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
import com.fr.stable.CoreConstants; import com.fr.stable.CoreConstants;
@ -49,6 +50,9 @@ public class LocateAction extends UpdateAction {
if (locatedPath == null) { if (locatedPath == null) {
return; return;
} }
if (TemplateTreeSearchManager.getInstance().isInSearchMode()) {
TemplateTreeSearchManager.getInstance().outOfSearchMode();
}
DefaultTreeModel model = (DefaultTreeModel) getTemplateFileTree().getModel(); DefaultTreeModel model = (DefaultTreeModel) getTemplateFileTree().getModel();
ExpandMutableTreeNode treeNode = (ExpandMutableTreeNode) model.getRoot(); 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)); VcsHelper.getInstance().moveVcs(path, newPath.replaceFirst(ProjectConstants.REPORTLETS_NAME, StringUtils.EMPTY));
} }
DesignerContext.getDesignerFrame().setTitle(); DesignerContext.getDesignerFrame().setTitle();
if (TemplateTreeSearchManager.getInstance().isInSearchMode()) {
TemplateTreeSearchManager.getInstance().outOfSearchMode();
LocateAction.gotoEditingTemplateLeaf(newPath); LocateAction.gotoEditingTemplateLeaf(newPath);
} }
}
private void validInput() { 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 PasteAction pasteAction;
private DelFileAction delFileAction; private DelFileAction delFileAction;
private MoveAction moveAction; private MoveAction moveAction;
private LocateAction locateAction;
public static DefaultTemplateTreeDefineProcessor getInstance() { public static DefaultTemplateTreeDefineProcessor getInstance() {
return DefaultTemplateTreeDefineProcessor.HOLDER.singleton; return DefaultTemplateTreeDefineProcessor.HOLDER.singleton;
@ -78,6 +79,7 @@ public class DefaultTemplateTreeDefineProcessor extends AbstractTemplateTreeDefi
pasteAction = new PasteAction(); pasteAction = new PasteAction();
delFileAction = new DelFileAction(); delFileAction = new DelFileAction();
moveAction = new MoveAction(); moveAction = new MoveAction();
locateAction = new OpenInTemplateTreeAction();
//右键菜单 //右键菜单
popupMenu = new UIPopupMenu(); popupMenu = new UIPopupMenu();
popupMenu.add(renameAction.createMenuItem()); popupMenu.add(renameAction.createMenuItem());
@ -87,6 +89,7 @@ public class DefaultTemplateTreeDefineProcessor extends AbstractTemplateTreeDefi
popupMenu.add(delFileAction.createMenuItem()); popupMenu.add(delFileAction.createMenuItem());
popupMenu.addSeparator(); popupMenu.addSeparator();
popupMenu.add(moveAction.createMenuItem()); popupMenu.add(moveAction.createMenuItem());
popupMenu.add(locateAction.createMenuItem());
} }
@Override @Override
@ -103,6 +106,7 @@ public class DefaultTemplateTreeDefineProcessor extends AbstractTemplateTreeDefi
pasteAction.setEnabled(false); pasteAction.setEnabled(false);
delFileAction.setEnabled(false); delFileAction.setEnabled(false);
moveAction.setEnabled(false); moveAction.setEnabled(false);
locateAction.setEnabled(false);
int length = getFileTree().getSelectionCount(); int length = getFileTree().getSelectionCount();
if (length == 0) { if (length == 0) {
//没有选中文件时,只能黏贴 //没有选中文件时,只能黏贴
@ -114,6 +118,10 @@ public class DefaultTemplateTreeDefineProcessor extends AbstractTemplateTreeDefi
if (length == 1) { if (length == 1) {
//选中一个时可以,可以重命名、黏贴 //选中一个时可以,可以重命名、黏贴
renameAction.setEnabled(true); renameAction.setEnabled(true);
if (TemplateTreeSearchManager.getInstance().isInSearchMode()) {
//搜索模式开启定位当前模板
locateAction.setEnabled(true);
}
if (!CollectionUtils.isEmpty(TemplateTreeClipboard.getInstance().takeFromClip())) { if (!CollectionUtils.isEmpty(TemplateTreeClipboard.getInstance().takeFromClip())) {
pasteAction.setEnabled(true); 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); JOptionPane.ERROR_MESSAGE);
} }
// 粘贴时如果正在搜索,跳回原树
if (TemplateTreeSearchManager.getInstance().isInSearchMode()) {
TemplateTreeSearchManager.getInstance().outOfSearchMode();
}
DesignerFrameFileDealerPane.getInstance().getSelectedOperation().refreshParent(); DesignerFrameFileDealerPane.getInstance().getSelectedOperation().refreshParent();
LocateAction.gotoEditingTemplateLeaf(targetFile); LocateAction.gotoEditingTemplateLeaf(targetFile);
} }
@ -402,10 +422,6 @@ public class DefaultTemplateTreeDefineProcessor extends AbstractTemplateTreeDefi
ToastMsgDialog dialog = DesignerToastMsgUtil.createPromptDialog(Toolkit.i18nText("Fine-Design_Basic_Template_Moved_Success")); ToastMsgDialog dialog = DesignerToastMsgUtil.createPromptDialog(Toolkit.i18nText("Fine-Design_Basic_Template_Moved_Success"));
dialog.setVisible(true); dialog.setVisible(true);
// 移动时如果正在搜索,跳回原树
if (TemplateTreeSearchManager.getInstance().isInSearchMode()) {
TemplateTreeSearchManager.getInstance().outOfSearchMode();
}
DesignerFrameFileDealerPane.getInstance().getSelectedOperation().refresh(); DesignerFrameFileDealerPane.getInstance().getSelectedOperation().refresh();
LocateAction.gotoEditingTemplateLeaf(targetFile); 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)) { if (ArrayUtils.isEmpty(fileNodes)) {
//空目录:相当于新建一个目录 //空目录:相当于新建一个目录
DesignerFrameFileDealerPane.getInstance().getSelectedOperation().mkdir(targetDir); DesignerFrameFileDealerPane.getInstance().getSelectedOperation().mkdir(targetDir);
return;
} }
for (FileNode fileNode : fileNodes) { for (FileNode fileNode : fileNodes) {
if (fileNode.isDirectory()) { if (fileNode.isDirectory()) {
copyDir(StableUtils.pathJoin(fileNode.getParent(), fileNode.getName()), StableUtils.pathJoin(targetDir, fileNode.getName()), withCopyVcs); 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); copyFile(StableUtils.pathJoin(sourceDir, fileNode.getName()), StableUtils.pathJoin(targetDir, fileNode.getName()), withCopyVcs);
} }
} }
}
private void copyFile(String sourcePath, String targetPath, boolean 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) { if (treePath == null) {
return false; return false;
} }
DefaultMutableTreeNode currentTreeNode = (DefaultMutableTreeNode) treePath.getLastPathComponent(); boolean result = false;
Enumeration children; Enumeration children = getChild(treePath, baseOnSelf);
//现在可以在目录下创建目录,重命名时是基于所选节点的父目录的子目录进行校验,目录下新建子目录时,基于所选目录的子目录进行校验
if (reportletsTree.getSelectedFileNode().isDirectory() && baseOnSelf) {
children = currentTreeNode.children();
} else {
TreeNode parentTreeNode = currentTreeNode.getParent();
children = parentTreeNode.children();
}
while (children.hasMoreElements()) { while (children.hasMoreElements()) {
DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) children.nextElement(); DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) children.nextElement();
Object object = childNode.getUserObject(); Object object = childNode.getUserObject();
if (object instanceof FileNode) { if (object instanceof FileNode) {
if (ComparatorUtils.equals(((FileNode) object).getName(), newName + suffix)) { 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