package com.fr.design.mainframe; import com.fr.base.BaseUtils; import com.fr.base.extension.FileExtension; import com.fr.base.vcs.DesignerMode; import com.fr.chartx.TwoTuple; import com.fr.design.DesignModelAdapter; import com.fr.design.DesignerEnvManager; import com.fr.design.ExtraDesignClassManager; import com.fr.design.actions.UpdateAction; import com.fr.design.actions.file.DelFileAction; import com.fr.design.actions.file.LocateAction; import com.fr.design.actions.file.RenameAction; import com.fr.design.constants.UIConstants; import com.fr.design.data.DesignTableDataManager; import com.fr.design.data.datapane.TableDataTreePane; import com.fr.design.data.datapane.management.search.TableDataTreeSearchManager; import com.fr.design.data.tabledata.ResponseDataSourceChange; import com.fr.design.dialog.FineJOptionPane; import com.fr.design.file.FileOperations; import com.fr.design.file.FileToolbarStateChangeListener; import com.fr.design.file.HistoryTemplateListCache; import com.fr.design.file.HistoryTemplateListPane; import com.fr.design.file.MutilTempalteTabPane; import com.fr.design.file.TemplateTreePane; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.imenu.UIMenuHighLight; import com.fr.design.gui.itextfield.UITextField; import com.fr.design.gui.itoolbar.UIToolbar; import com.fr.design.i18n.Toolkit; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayoutHelper; import com.fr.design.mainframe.manager.search.TemplateTreeSearchManager; import com.fr.design.mainframe.manager.search.searcher.control.pane.TemplateTreeSearchToolbarPane; import com.fr.design.mainframe.vcs.common.VcsHelper; import com.fr.design.mainframe.vcs.ui.FileVersionsPanel; import com.fr.design.menu.KeySetUtils; import com.fr.design.menu.ShortCut; import com.fr.design.menu.ToolBarDef; import com.fr.design.roleAuthority.RolesAlreadyEditedPane; import com.fr.design.ui.util.UIUtil; import com.fr.design.utils.DesignUtils; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.event.Event; import com.fr.file.filetree.FileNode; import com.fr.general.ComparatorUtils; import com.fr.general.GeneralContext; import com.fr.general.IOUtils; import com.fr.log.FineLoggerFactory; import com.fr.plugin.context.PluginContext; import com.fr.plugin.injectable.PluginModule; import com.fr.plugin.manage.PluginFilter; import com.fr.plugin.observer.PluginEvent; import com.fr.plugin.observer.PluginEventListener; import com.fr.stable.CoreConstants; import com.fr.stable.StableUtils; import com.fr.stable.StringUtils; import com.fr.stable.project.ProjectConstants; import com.fr.third.org.apache.commons.io.FilenameUtils; import com.fr.workspace.WorkContext; import com.fr.report.lock.LockInfoOperator; import javax.swing.BorderFactory; import javax.swing.JDialog; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.SwingConstants; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; import java.awt.BorderLayout; import java.awt.CardLayout; import java.awt.Color; import java.awt.Component; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; import java.util.regex.Pattern; import static javax.swing.JOptionPane.WARNING_MESSAGE; public class DesignerFrameFileDealerPane extends JPanel implements FileToolbarStateChangeListener, ResponseDataSourceChange { public static final com.fr.event.Event> TEMPLATE_RENAME = new Event>() { }; private static final String FILE = "file"; public static final String FILE_NAME_LIMIT = "^[^/\\\\:<>\\*\\|\"\\?]+$"; private static volatile DesignerFrameFileDealerPane THIS; static { GeneralContext.listenPluginRunningChanged(new PluginEventListener() { @Override public void on(PluginEvent event) { DesignUtils.refreshDesignerFrame(); } }, new PluginFilter() { @Override public boolean accept(PluginContext context) { return context.contain(PluginModule.ExtraDesign, ShortCut.TEMPLATE_TREE); } }); GeneralContext.listenPluginRunningChanged(new PluginEventListener() { @Override public void on(PluginEvent event) { UIUtil.invokeLaterIfNeeded(new Runnable() { @Override public void run() { DesignerFrameFileDealerPane.getInstance().refresh(); DesignerFrameFileDealerPane.getInstance().stateChange(); } }); } }, new PluginFilter() { @Override public boolean accept(PluginContext context) { return context.contain(PluginModule.ExtraDesign, App.MARK_STRING); } }); } private List otherToolbarStateChangeListeners = new ArrayList<>(); private FileOperations selectedOperation; private UIToolbar toolBar; private UIToolbar rightToolBar; private NewFolderAction newFolderAction = new NewFolderAction(); private RefreshTreeAction refreshTreeAction = new RefreshTreeAction(); private ShowInExplorerAction showInExplorerAction = new ShowInExplorerAction(); private RenameAction renameAction = new RenameAction(); private DelFileAction delFileAction = new DelFileAction(); private VcsAction vcsAction = new VcsAction(); //搜索 private SwitchAction switchAction = new SwitchAction(); private TemplateTreeSearchToolbarPane searchToolbarPane; //定位、收起 private LocateAction locateAction = new LocateAction(); private CollapseAllAction collapseAllAction = new CollapseAllAction(); private DesignerFrameFileDealerPane() { setLayout(new BorderLayout()); toolBar = ToolBarDef.createJToolBar(); toolBar.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, UIConstants.TOOLBAR_BORDER_COLOR)); toolBar.setBorderPainted(true); JPanel tooBarPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); JPanel parent = new JPanel(new BorderLayout()); parent.add(createUpToolBarPane(), BorderLayout.CENTER); parent.setBorder(BorderFactory.createEmptyBorder(3, 0, 4, 0)); tooBarPane.add(parent, BorderLayout.CENTER); tooBarPane.add(new UIMenuHighLight(), BorderLayout.SOUTH); searchToolbarPane = new TemplateTreeSearchToolbarPane(toolBar); searchToolbarPane.setPreferredSize(new Dimension(this.getWidth(), 23)); add(searchToolbarPane, BorderLayout.NORTH); CardLayout card; JPanel cardPane = new JPanel(card = new CardLayout()); cardPane.add(TemplateTreePane.getInstance(), FILE); selectedOperation = TemplateTreePane.getInstance(); card.show(cardPane, FILE); TemplateTreePane.getInstance().setToolbarStateChangeListener(this); add(cardPane, BorderLayout.CENTER); stateChange(); } public static DesignerFrameFileDealerPane getInstance() { if (THIS == null) { synchronized (DesignerFrameFileDealerPane.class) { if (THIS == null) { THIS = new DesignerFrameFileDealerPane(); } } } return THIS; } /** * 刷新 */ public void refresh() { selectedOperation.refresh(); } /** * 刷新根目录并退出搜索模式 */ public void refreshAndOutOfSearch() { if (TemplateTreeSearchManager.getInstance().isInSearchMode()) { TemplateTreeSearchManager.getInstance().outOfSearchMode(); } refresh(); } private JPanel createUpToolBarPane() { JPanel panel = new JPanel(new BorderLayout()); panel.add(toolBar, BorderLayout.CENTER); if (WorkContext.getCurrent().isRoot()) { rightToolBar = new UIToolbar(FlowLayout.RIGHT); rightToolBar.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, UIConstants.TOOLBAR_BORDER_COLOR)); rightToolBar.setBorderPainted(true); UILabel tipLabel = new UILabel(Toolkit.i18nText("Fine_Design_Template_Lock_Status")); tipLabel.setForeground(Color.GRAY); rightToolBar.add(tipLabel); UIButton button = new UIButton(IOUtils.readIcon("/com/fr/design/images/toolbarbtn/lock.png")); button.setRolloverIcon(IOUtils.readIcon("/com/fr/design/images/toolbarbtn/unlock.png")); button.setBorderPainted(false); button.setContentAreaFilled(false); button.set4ToolbarButton(); button.setToolTipText(Toolkit.i18nText("Fine_Design_Template_Unlock_Tip")); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int option = FineJOptionPane.showOptionDialog(DesignerContext.getDesignerFrame(), Toolkit.i18nText("Fine_Design_Template_UnLock_Tip"), Toolkit.i18nText("Fine-Design_Basic_Alert"), JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, IOUtils.readIcon("/com/fr/design/images/warnings/warning32.png"), new Object[] {Toolkit.i18nText("Fine_Design_Template_UnLock_I_Known"), Toolkit.i18nText("Fine-Design_Basic_Button_Cancel")}, null); if (option == JOptionPane.YES_OPTION) { String path = StableUtils.pathJoin(ProjectConstants.REPORTLETS_NAME, TemplateTreePane.getInstance().getTemplateFileTree().getSelectedTemplatePath()); boolean success = WorkContext.getCurrent().get(LockInfoOperator.class).unLockTpl(path); if (success) { FileNode fileNode = TemplateTreePane.getInstance().getFileNode(); refreshRightToolBarBy(fileNode); } else { FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Toolkit.i18nText("Fine-Design_Template_Unlock_Failed"), Toolkit.i18nText("Fine-Design_Basic_Alert"), JOptionPane.WARNING_MESSAGE); FineLoggerFactory.getLogger().error("Unlock {} failed", path); } TemplateTreePane.getInstance().refresh(); } } }); rightToolBar.add(button); refreshRightToolBarBy(TemplateTreePane.getInstance().getFileNode()); panel.add(rightToolBar, BorderLayout.EAST); } return panel; } public final void setCurrentEditingTemplate(JTemplate jt) { DesignModelAdapter.setCurrentModelAdapter(jt.getModel()); fireDSChanged(); if (TableDataTreeSearchManager.getInstance().isInSearchMode()) { TableDataTreeSearchManager.getInstance().outOfSearchMode(); } TableDataTreePane.getInstance(DesignModelAdapter.getCurrentModelAdapter()); HistoryTemplateListPane.getInstance().setCurrentEditingTemplate(jt); //处理自动新建的模板 MutilTempalteTabPane.getInstance().doWithtemTemplate(); if (DesignerMode.isAuthorityEditing()) { RolesAlreadyEditedPane.getInstance().refreshDockingView(); } jt.setComposite(); jt.refreshToolArea(); jt.fireJTemplateOpened(); jt.requestFocus(); jt.revert(); // 打开为空占位模板时不输出 if (!jt.isOpening()) { FineLoggerFactory.getLogger().info( "\"" + jt.getEditingFILE().getName() + "\"" + Toolkit.i18nText("Fine-Design_Basic_LOG_Has_Been_Openned") + "!"); } } /** * 刷新菜单 */ public void refreshDockingView() { ToolBarDef toolbarDef = new ToolBarDef(); toolbarDef.addShortCut(newFolderAction, refreshTreeAction); if (WorkContext.getCurrent().isLocal()) { toolbarDef.addShortCut(showInExplorerAction); } toolbarDef.addShortCut(renameAction, delFileAction); Set extraShortCuts = ExtraDesignClassManager.getInstance().getExtraShortCuts(); for (ShortCut shortCut : extraShortCuts) { toolbarDef.addShortCut(shortCut); } addVcsAction(toolbarDef); toolbarDef.addShortCut(locateAction, collapseAllAction, switchAction); toolbarDef.updateToolBar(toolBar); resetActionStatus(); refresh(); } /** * 添加VcsAction * * @param toolbarDef */ private void addVcsAction(ToolBarDef toolbarDef) { if (VcsHelper.getInstance().needInit()) { vcsAction = new VcsAction(); if (!WorkContext.getCurrent().isCluster()) { vcsAction.setName(Toolkit.i18nText("Fine-Design_Vcs_Title")); } else { vcsAction.setName(Toolkit.i18nText("Fine-Design_Vcs_NotSupportRemote")); } toolbarDef.addShortCut(vcsAction); } } private void resetActionStatus() { newFolderAction.setEnabled(false); refreshTreeAction.setEnabled(true); showInExplorerAction.setEnabled(false); renameAction.setEnabled(false); delFileAction.setEnabled(false); vcsAction.setEnabled(false); this.repaint(); } /** * 响应数据集改变 */ @Override public void fireDSChanged() { fireDSChanged(new HashMap()); } /** * 响应数据集改变 * * @param map 改变名字的数据集 */ @Override public void fireDSChanged(Map map) { DesignTableDataManager.fireDSChanged(map); } public void addToolbarStateChangeListener(FileToolbarStateChangeListener listener) { this.otherToolbarStateChangeListeners.add(listener); } public void removeToolbarStateChangeListener(FileToolbarStateChangeListener listener) { this.otherToolbarStateChangeListeners.remove(listener); } private void otherStateChange() { for (FileToolbarStateChangeListener listener : otherToolbarStateChangeListeners) { listener.stateChange(); } } private boolean isCurrentEditing(String path) { JTemplate jt = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); String editing = jt.getEditingFILE().getPath(); return ComparatorUtils.equals(editing, path); } /** * 按钮状态改变 */ @Override public void stateChange() { int selectedPathNum = TemplateTreePane.getInstance().countSelectedPath(); // 新建文件夹,重命名操作,在explorer中打开三个操作在选中单个文件夹或者文件时可用,其他情况不可用 boolean singleSelected = selectedPathNum == 1; // 打开和保存中 需要禁用相关操作 boolean enable = isEnable(); newFolderAction.setEnabled(singleSelected); renameAction.setEnabled(singleSelected && enable); showInExplorerAction.setEnabled(singleSelected); // 删除操作在至少选中一个时可用 boolean selected = selectedPathNum > 0; delFileAction.setEnabled(selected && enable); // 刷新操作始终可用 refreshTreeAction.setEnabled(true); //触发vcsAction变化 vcsAction.fireVcsActionChange(enable); // 其他状态 otherStateChange(); } public FileOperations getSelectedOperation() { return selectedOperation; } /** * 新建文件夹 */ private class NewFolderAction extends UpdateAction { public NewFolderAction() { this.setName(KeySetUtils.NEW_FOLDER.getMenuKeySetName()); this.setSmallIcon("/com/fr/design/images/FileDealerPaneIcon/new_folder"); } @Override public void actionPerformed(ActionEvent evt) { if (!selectedOperation.access()) { FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Toolkit.i18nText("Fine-Design_Basic_Template_Permission_Denied"), Toolkit.i18nText("Fine-Design_Basic_Alert"), WARNING_MESSAGE); return; } new MkdirDialog(); stateChange(); } } private class SwitchAction extends UpdateAction { public SwitchAction() { this.setName(Toolkit.i18nText("Fine-Design_Basic_Search")); this.setMnemonic('S'); this.setSmallIcon("/com/fr/design/images/data/search"); } @Override public void actionPerformed(ActionEvent e) { // 交换层级 searchToolbarPane.switchPane(TemplateTreeSearchToolbarPane.SEARCH_PANE); TemplateTreePane.getInstance().refreshDockingView(); TemplateTreeSearchManager.getInstance().switchToSearch(TemplateTreePane.getInstance().getTemplateFileTree()); } } public class CollapseAllAction extends UpdateAction { public CollapseAllAction() { this.setName(Toolkit.i18nText("Fine-Design_Basic_Collapse_All")); this.setSmallIcon("/com/fr/design/images/FileDealerPaneIcon/collapse-all.png"); } @Override public void actionPerformed(ActionEvent e) { TemplateTreePane.getInstance().refreshDockingView(); } } /** * 版本管理 */ private class VcsAction extends UpdateAction { public VcsAction() { this.setSmallIcon("/com/fr/design/images/FileDealerPaneIcon/vcs_list"); } @Override public void actionPerformed(ActionEvent e) { String path = DesignerFrameFileDealerPane.getInstance().getSelectedOperation().getFilePath(); path = StableUtils.pathJoin(ProjectConstants.REPORTLETS_NAME, path); boolean isCurrentEditing = isCurrentEditing(path); // 如果模板已经打开了,关掉,避免出现2个同名tab(1个是模板,1个是版本) closeOpenedTemplate(path, isCurrentEditing); FileVersionsPanel fileVersionTablePanel = FileVersionsPanel.getInstance(); fileVersionTablePanel.showFileVersionsPane(); stateChange(); } /** * 版本管理可用状态的监控 */ private void fireVcsActionChange(boolean enable) { if (!DesignerEnvManager.getEnvManager().getVcsConfigManager().isVcsEnable() || VcsHelper.getInstance().isUnSelectedTemplate() || WorkContext.getCurrent().isCluster()) { setEnabled(false); return; } if (WorkContext.getCurrent() != null) { boolean pathSupportVcsAction = selectedOperation.getFilePath() != null && pathSupportVcsAction(selectedOperation.getFilePath()); if (!WorkContext.getCurrent().isLocal()) { //当前环境为远程环境时 FileNode node = TemplateTreePane.getInstance().getTemplateFileTree().getSelectedFileNode(); if (pathSupportVcsAction) { if (node.getLock() != null && !ComparatorUtils.equals(node.getUserID(), node.getLock())) { setEnabled(false); } else { setEnabled(enable); } } else { setEnabled(false); } } else { //当前环境为本地环境时 setEnabled(pathSupportVcsAction && enable); } } } private boolean pathSupportVcsAction(String path) { if (FileExtension.CPT.matchExtension(path) || FileExtension.FRM.matchExtension(path)) { return true; } return false; } private void closeOpenedTemplate(String path, boolean isCurrentEditing) { for (JTemplate jTemplate : HistoryTemplateListCache.getInstance().getHistoryList()) { if (ComparatorUtils.equals(jTemplate.getEditingFILE().getPath(), path)) { if (isCurrentEditing) { MutilTempalteTabPane.getInstance().setIsCloseCurrent(true); } MutilTempalteTabPane.getInstance().closeFormat(jTemplate); MutilTempalteTabPane.getInstance().closeSpecifiedTemplate(jTemplate); return; } } } } /** * 在系统资源管理器中打开 */ private class ShowInExplorerAction extends UpdateAction { public ShowInExplorerAction() { this.setName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Show_In_Containing_Folder")); this.setSmallIcon("/com/fr/design/images/FileDealerPaneIcon/view_folder"); } @Override public void actionPerformed(ActionEvent evt) { selectedOperation.showInExplorer(); } } /* * 刷新ReportletsTree */ private class RefreshTreeAction extends UpdateAction { public RefreshTreeAction() { this.setName(Toolkit.i18nText("Fine-Design_Basic_Refresh")); this.setSmallIcon("/com/fr/design/images/FileDealerPaneIcon/refresh"); } @Override public void actionPerformed(ActionEvent evt) { selectedOperation.refresh(); stateChange(); } } public void refreshRightToolBarBy(FileNode fileNode) { if (rightToolBar != null) { boolean locked = fileNode != null && StringUtils.isNotEmpty(fileNode.getLock()) && !ComparatorUtils.equals(fileNode.getLock(), fileNode.getUserID()); boolean visible = locked && WorkContext.getCurrent().isRoot() && WorkContext.getCurrent().get(LockInfoOperator.class).isUnLockable() && !WorkContext.getCurrent().get(LockInfoOperator.class).isTplUnLocked(fileNode.getEnvPath()); rightToolBar.setVisible(visible); } } /** * 新建文件夹对话框 * 支持快捷键Enter,ESC */ private class MkdirDialog extends JDialog { private UITextField nameField; private UILabel warnLabel; private UIButton confirmButton; private MkdirDialog() { this.setLayout(new BorderLayout()); this.setModal(true); // 输入框前提示 UILabel newNameLabel = new UILabel(Toolkit.i18nText( "Fine-Design_Basic_Enter_New_Folder_Name") ); newNameLabel.setHorizontalAlignment(SwingConstants.RIGHT); newNameLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10)); // 文件名输入框 nameField = new UITextField(); nameField.getDocument().addDocumentListener(new DocumentListener() { @Override public void changedUpdate(DocumentEvent e) { validInput(); } @Override public void insertUpdate(DocumentEvent e) { validInput(); } @Override public void removeUpdate(DocumentEvent e) { validInput(); } }); nameField.selectAll(); nameField.setPreferredSize(new Dimension(180, 20)); JPanel topPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 5)); topPanel.setBorder(BorderFactory.createEmptyBorder(15, 15, 0, 15)); topPanel.add(newNameLabel); topPanel.add(nameField); // 增加enter以及esc快捷键的支持 nameField.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { dispose(); } else if (e.getKeyCode() == KeyEvent.VK_ENTER) { if (confirmButton.isEnabled()) { confirmClose(); } } } }); // 重名提示 warnLabel = new UILabel(); warnLabel.setPreferredSize(new Dimension(300, 50)); warnLabel.setHorizontalAlignment(SwingConstants.LEFT); warnLabel.setVerticalAlignment(SwingConstants.TOP); warnLabel.setForeground(Color.RED); warnLabel.setVisible(false); JPanel midPanel = new JPanel(new BorderLayout()); midPanel.setBorder(BorderFactory.createEmptyBorder(0, 15, 0, 15)); midPanel.add(warnLabel, BorderLayout.WEST); // 确认按钮 confirmButton = new UIButton(Toolkit.i18nText("Fine-Design_Basic_Confirm")); confirmButton.setPreferredSize(new Dimension(60, 25)); confirmButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { confirmClose(); } }); confirmButton.setEnabled(false); // 取消按钮 UIButton cancelButton = new UIButton(Toolkit.i18nText("Fine-Design_Basic_Cancel")); cancelButton.setPreferredSize(new Dimension(60, 25)); cancelButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dispose(); } }); JPanel bottomPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 10, 0)); bottomPanel.setBorder(BorderFactory.createEmptyBorder(10, 15, 10, 10)); bottomPanel.add(confirmButton); bottomPanel.add(cancelButton); this.add( TableLayoutHelper.createTableLayoutPane( new Component[][]{ new Component[]{topPanel}, new Component[]{midPanel}, new Component[]{bottomPanel} }, new double[]{TableLayout.FILL, TableLayout.PREFERRED, TableLayout.PREFERRED}, new double[]{TableLayout.FILL} ), BorderLayout.CENTER); this.setSize(380, 200); this.setTitle(Toolkit.i18nText("Fine-Design_Basic_Mkdir")); this.setResizable(false); this.setAlwaysOnTop(true); this.setIconImage(BaseUtils.readImage("/com/fr/base/images/oem/logo.png")); this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); GUICoreUtils.setWindowCenter(DesignerContext.getDesignerFrame(), this); this.setVisible(true); } private void confirmClose() { String userInput = nameField.getText().trim(); if (StringUtils.isEmpty(userInput)) { return; } //新建文件夹 FileNode selectedFileNode = selectedOperation.getFileNode(); String parentPath = selectedFileNode.getParent(); if (selectedFileNode.isDirectory()) { //目录的话,父目录就是所选目录 parentPath = FilenameUtils.standard(parentPath + CoreConstants.SEPARATOR + selectedFileNode.getName()); } boolean success = selectedOperation.mkdir( FilenameUtils.standard(parentPath + CoreConstants.SEPARATOR + userInput) ); selectedOperation.refresh(); this.dispose(); if (!success) { FineJOptionPane.showConfirmDialog(DesignerContext.getDesignerFrame(), Toolkit.i18nText("Fine-Design_Basic_Make_Failure"), Toolkit.i18nText("Fine-Design_Basic_Error"), JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE); } } private void validInput() { String userInput = nameField.getText().trim(); if (StringUtils.isEmpty(userInput)) { confirmButton.setEnabled(false); return; } String errorMsg = doCheck(userInput, StringUtils.EMPTY); if (StringUtils.isNotEmpty(errorMsg)) { nameField.selectAll(); // 如果检测出错,则灰掉确认按钮并提示 warnLabel.setText(errorMsg); warnLabel.setVisible(true); confirmButton.setEnabled(false); } else { warnLabel.setVisible(false); confirmButton.setEnabled(true); } } } private String doCheck (String userInput, String suffix) { String errorMsg = StringUtils.EMPTY; if (selectedOperation.duplicated(userInput, suffix)) { errorMsg = Toolkit.i18nText("Fine-Design_Basic_Folder_Name_Duplicate", userInput); } if (!Pattern.compile(FILE_NAME_LIMIT).matcher(userInput).matches()) { errorMsg = Toolkit.i18nText("Fine-Design_Basic_Template_Name_Illegal"); } return errorMsg; } private boolean isEnable() { List> templates = HistoryTemplateListCache.getInstance().getHistoryList(); for (JTemplate template : templates) { if (template.isSaving() || template.isOpening()) { FileNode node = TemplateTreePane.getInstance().getFileNode(); if (node != null && ComparatorUtils.equals(template.getEditingFILE().getPath(), node.getEnvPath())) { return false; } } } return true; } }