diff --git a/build.gradle b/build.gradle index 671e64fb95..e0bf79aefe 100644 --- a/build.gradle +++ b/build.gradle @@ -1,4 +1,5 @@ import org.gradle.plugins.ide.idea.model.IdeaLanguageLevel +import org.gradle.internal.os.OperatingSystem plugins { id 'java' @@ -65,11 +66,7 @@ allprojects { implementation 'com.fr.cbb:fine-universal-skeleton:' + cbbVersion implementation 'com.install4j:install4j-runtime:8.0.4' implementation 'com.fr.third:jxbrowser:6.23' - implementation 'com.fr.third:jxbrowser-mac:6.23' - implementation 'com.fr.third:jxbrowser-win64:6.23' implementation 'com.fr.third:jxbrowser-v7:7.22' - implementation 'com.fr.third:jxbrowser-mac-v7:7.22' - implementation 'com.fr.third:jxbrowser-win64-v7:7.22' implementation 'com.fr.third:jxbrowser-swing-v7:7.22' implementation 'com.fr.third.server:servlet-api:3.0' implementation 'org.swingexplorer:swexpl:2.0.1' @@ -94,4 +91,16 @@ allprojects { testImplementation 'org.powermock:powermock-api-easymock:1.7.1' testImplementation 'junit:junit:4.12' } + + if (OperatingSystem.current().isMacOsX()) { + dependencies { + implementation 'com.fr.third:jxbrowser-mac:6.23' + implementation 'com.fr.third:jxbrowser-mac-v7:7.22' + } + } else if (OperatingSystem.current().isWindows()) { + dependencies { + implementation 'com.fr.third:jxbrowser-win64:6.23' + implementation 'com.fr.third:jxbrowser-win64-v7:7.22' + } + } } diff --git a/designer-base/src/main/java/com/fr/design/DesignModelAdapter.java b/designer-base/src/main/java/com/fr/design/DesignModelAdapter.java index 013c703fb2..bd4130a853 100644 --- a/designer-base/src/main/java/com/fr/design/DesignModelAdapter.java +++ b/designer-base/src/main/java/com/fr/design/DesignModelAdapter.java @@ -276,22 +276,28 @@ public abstract class DesignModelAdapter map, Filter filter) { Iterator it = this.getBook().getTableDataNameIterator(); + List names = new ArrayList<>(); try { - // 清空下缓存 - tableDataParametersMap.clear(); + List tableDatas = new ArrayList<>(); while (it.hasNext()) { String name = it.next(); TableData tableData = this.getBook().getTableData(name); - ParameterProvider[] parameterProviders = DataOperator.getInstance().getTableDataParameters(tableData); + tableDatas.add(tableData); + names.add(name); + } + ParameterProvider[][] totalParameterProviders = DataOperator.getInstance().getTotalTableDataParameters(tableDatas); + tableDataParametersMap.clear(); + for (int i = 0; i < totalParameterProviders.length; i++) { + ParameterProvider[] parameterProviders = totalParameterProviders[i]; if (filter != null) { ParameterApplyHelper.addPara2Map(map, parameterProviders, filter, null, ParameterSource.DEFAULT_SOURCE); } else { ParameterApplyHelper.addPara2Map(map, parameterProviders, null, ParameterSource.TEMPLATE_SOURCE); } - tableDataParametersMap.put(name, parameterProviders); + tableDataParametersMap.put(names.get(i), parameterProviders); } } catch (Exception e) { - FineLoggerFactory.getLogger().error(e.getMessage(), e); + FineLoggerFactory.getLogger().error(e, e.getMessage()); } } diff --git a/designer-base/src/main/java/com/fr/design/DesignerEnvManager.java b/designer-base/src/main/java/com/fr/design/DesignerEnvManager.java index f7bff1f5b5..199834fb77 100644 --- a/designer-base/src/main/java/com/fr/design/DesignerEnvManager.java +++ b/designer-base/src/main/java/com/fr/design/DesignerEnvManager.java @@ -4,7 +4,9 @@ package com.fr.design; import com.fr.base.BaseXMLUtils; +import com.fr.base.OptimizeUtil; import com.fr.base.Utils; +import com.fr.collections.api.Callback; import com.fr.design.actions.help.alphafine.AlphaFineConfigManager; import com.fr.design.carton.SwitchForSwingChecker; import com.fr.design.constants.UIConstants; @@ -21,8 +23,8 @@ import com.fr.design.locale.impl.ProductImproveMark; import com.fr.design.login.DesignerLoginType; import com.fr.design.login.config.DesignerLoginConfigManager; import com.fr.design.mainframe.ComponentReuseNotifyUtil; -import com.fr.design.mainframe.simple.SimpleDesignerConfig; import com.fr.design.mainframe.reuse.ComponentReuseNotificationInfo; +import com.fr.design.mainframe.simple.SimpleDesignerConfig; import com.fr.design.mainframe.vcs.VcsConfigManager; import com.fr.design.notification.SnapChatConfig; import com.fr.design.os.impl.SupportOSImpl; @@ -41,6 +43,12 @@ import com.fr.general.SupportLocale; import com.fr.general.locale.LocaleCenter; import com.fr.general.locale.LocaleMark; import com.fr.general.xml.GeneralXMLTools; +import com.fr.general.xml.async.AsyncXmlElement; +import com.fr.general.xml.async.AsyncXmlReadable; +import com.fr.general.xml.async.SimpleXmlElement; +import com.fr.general.xml.async.XmlElement; +import com.fr.general.xml.async.XmlException; +import com.fr.general.xml.async.XmlInitialFactory; import com.fr.log.FineLoggerFactory; import com.fr.log.LogHandler; import com.fr.stable.CommonUtils; @@ -58,8 +66,10 @@ import com.fr.stable.xml.XMLTools; import com.fr.stable.xml.XMLWriter; import com.fr.stable.xml.XMLableReader; import com.fr.start.common.DesignerStartupConfig; +import com.fr.start.common.DesignerStartupPool; import com.fr.third.apache.logging.log4j.core.appender.FileAppender; import com.fr.third.apache.logging.log4j.core.layout.PatternLayout; +import com.fr.third.org.apache.commons.io.FileUtils; import com.fr.third.org.apache.commons.io.FilenameUtils; import com.fr.workspace.WorkContext; import com.fr.workspace.WorkContextCallback; @@ -86,12 +96,18 @@ import java.util.ListIterator; import java.util.Locale; import java.util.Map; import java.util.Map.Entry; +import java.util.concurrent.atomic.AtomicBoolean; /** * The manager of Designer GUI. + * 下面的作者日期都是随手写的,具体作者已经无法考究。 + * + * @author anonymous + * @version 11.0 + * created by anonymous on 2002/11/08 */ -public class DesignerEnvManager implements XMLReadable, XMLWriter { - +public class DesignerEnvManager implements XMLReadable, XMLWriter, AsyncXmlReadable { + private static final int MAX_SHOW_NUM = 10; private static final String VERSION_80 = "80"; private static final String VERSION_90 = "90"; @@ -104,21 +120,26 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { * 指定默认工作空间 */ public static final String DEFAULT_WORKSPACE_PATH = "fr.designer.workspace.default"; - + + public static final String LAST_EAST_REGION_LAYOUT = "LastEastRegionLayout"; + public static final String LAST_WEST_REGION_LAYOUT = "LastWestRegionLayout"; + private static DesignerEnvManager designerEnvManager; // gui. private String activationKey = null; private String logLocation = null; private Rectangle windowBounds = null; // window bounds. private String DialogCurrentDirectory = null; private String CurrentDirectoryPrefix = null; + private Map> recentOpenedFileListMap = new HashMap<>(); private List tempRecentOpenedFilePathList = new ArrayList(); + private XmlElement>> recentOpenedMapping = SimpleXmlElement.of(recentOpenedFileListMap); + private boolean showPaintToolBar = true; private int maxNumberOrPreviewRow = 200; - // name和Env的键值对 - private Map nameEnvMap = new ListMap<>(); - // marks: 当前报表服务器名字 - private String curEnvName = null; + + private XmlElement envConfig = SimpleXmlElement.of(new EnvConfiguration()); + private boolean showProjectPane = true; private boolean showDataPane = true; //p:这是当前选择的数据库连接的名字,这个在新建数据源的时候用到. @@ -181,7 +202,7 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { /** * alphafine */ - private AlphaFineConfigManager alphaFineConfigManager = AlphaFineConfigManager.getInstance(); + private XmlElement alphaFineConfigManager = SimpleXmlElement.of(AlphaFineConfigManager.getInstance()); /** * 阅后即焚的配置项 @@ -230,7 +251,7 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { private boolean propertiesUsable; - private SimpleDesignerConfig fvsDesignerConfig = SimpleDesignerConfig.getInstance("FvsDesignerConfig"); + private XmlElement fvsDesignerConfig = SimpleXmlElement.of(SimpleDesignerConfig.getInstance("FvsDesignerConfig")); /** * DesignerEnvManager. @@ -244,13 +265,10 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { designerEnvManager = new DesignerEnvManager(); //REPORT-15332有一个国际化调用比较早,需要在这边就设置好locale,由于后台GeneralContext默认是China GeneralContext.setLocale(designerEnvManager.getLanguage()); - try { - XMLTools.readFileXML(designerEnvManager, designerEnvManager.getDesignerEnvFile()); - } catch (FileNotFoundException e) { - FineLoggerFactory.getLogger().error(e.getMessage(), e); - XmlHandler.Self.handle(e); - } catch (Exception e) { - FineLoggerFactory.getLogger().error(e.getMessage(), e); + + if (!asyncInitEnvManager()) { + // 如果异步读取失败, 则恢复原来的逻辑 + compatibleInitEnvManager(); } // james:如果没有env定义,要设置一个默认的 @@ -267,13 +285,47 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { return designerEnvManager; } + + private static void compatibleInitEnvManager() { + + try { + XMLTools.readFileXML(designerEnvManager, designerEnvManager.getDesignerEnvFile()); + } catch (FileNotFoundException e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + XmlHandler.Self.handle(e); + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + } + } + + /** + * 异步初始化环境管理, 提供配置, 帮助处理预期外的问题 + * 1-当优化开启时,才走异步逻辑 + * 2-如果异步执行中出错,则返回异常 false, 否则返回 true + * + * @return 是/否 + */ + private static boolean asyncInitEnvManager() { + + AtomicBoolean noEx = new AtomicBoolean(false); + OptimizeUtil.open(DesignerEnvManager.class.getSimpleName().toLowerCase(), OptimizeUtil.Module.COMMON, () -> { + try { + designerEnvManager.initElements(designerEnvManager.getDesignerEnvFile()); + noEx.set(true); + } catch (Throwable retryEx) { + FineLoggerFactory.getLogger().debug("try async init DesignerEnvManager failed", retryEx); + } + }); + return noEx.get(); + } public ColorSelectConfigManager getColorConfigManager() { return this.configManager; } public static void checkNameEnvMap() { - if (designerEnvManager == null || designerEnvManager.nameEnvMap.size() > 0) { + + if (designerEnvManager == null || designerEnvManager.getNameEnvMap().size() > 0) { return; } String installHome = StableUtils.getInstallHome(); @@ -443,8 +495,8 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { FineLoggerFactory.getLogger().error(e.getMessage(), e); } // 清空前一个版本中的工作目录和最近打开 - nameEnvMap = new ListMap(); - curEnvName = null; + getEnvConfig().setNameEnvMap(new ListMap<>()); + getEnvConfig().setCurEnvName(null); designerEnvManager.saveXMLFile(); } @@ -606,7 +658,7 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { String installHome = StableUtils.getInstallHome(); String defaultenvPath = getDefaultenvPath(installHome); defaultenvPath = new File(defaultenvPath).getPath(); - Iterator> entryIt = nameEnvMap.entrySet().iterator(); + Iterator> entryIt = getNameEnvMap().entrySet().iterator(); while (entryIt.hasNext()) { Entry entry = entryIt.next(); DesignerWorkspaceInfo env = entry.getValue(); @@ -627,8 +679,8 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { String installHome = StableUtils.getInstallHome(); String defaultenvPath = getDefaultenvPath(installHome); defaultenvPath = new File(defaultenvPath).getPath(); - if (nameEnvMap.size() >= 0) { - Iterator> entryIt = nameEnvMap.entrySet().iterator(); + if (getNameEnvMap().size() >= 0) { + Iterator> entryIt = getNameEnvMap().entrySet().iterator(); while (entryIt.hasNext()) { Entry entry = entryIt.next(); DesignerWorkspaceInfo env = entry.getValue(); @@ -1019,21 +1071,21 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { } public SimpleDesignerConfig getFvsDesignerConfig() { - return fvsDesignerConfig; + return fvsDesignerConfig.getValue(); } /** * 返回环境名称迭代器 */ public Iterator getEnvNameIterator() { - return this.nameEnvMap.keySet().iterator(); + return this.getNameEnvMap().keySet().iterator(); } /** * 根据名称返回环境 */ public DesignerWorkspaceInfo getWorkspaceInfo(String name) { - return this.nameEnvMap.get(name); + return this.getNameEnvMap().get(name); } /** @@ -1044,7 +1096,7 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { */ public void putEnv(String name, DesignerWorkspaceInfo info) { - this.nameEnvMap.put(name, info); + this.getNameEnvMap().put(name, info); } /** @@ -1053,14 +1105,14 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { * @param name 环境的名字 */ public void removeEnv(String name) { - this.nameEnvMap.remove(name); + this.getNameEnvMap().remove(name); } /** * 清除全部环境 */ public void clearAllEnv() { - this.nameEnvMap.clear(); + this.getNameEnvMap().clear(); } /** @@ -1082,14 +1134,14 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { * 返回当前环境的名称. */ public String getCurEnvName() { - return this.curEnvName; + return getEnvConfig().getCurEnvName(); } /** * 设置当前环境的名称 */ public void setCurEnvName(String envName) { - this.curEnvName = envName; + getEnvConfig().setCurEnvName(envName); } /** @@ -1146,12 +1198,12 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { if (StringUtils.isEmpty(envName)) { return tempRecentOpenedFilePathList; } else { - if (!recentOpenedFileListMap.containsKey(envName)) { - recentOpenedFileListMap.put(envName, tempRecentOpenedFilePathList); + if (!recentOpenedMapping.getValue().containsKey(envName)) { + recentOpenedMapping.getValue().put(envName, tempRecentOpenedFilePathList); } } - return recentOpenedFileListMap.get(envName); + return recentOpenedMapping.getValue().get(envName); } /** @@ -1755,11 +1807,11 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { } public AlphaFineConfigManager getAlphaFineConfigManager() { - return alphaFineConfigManager; + return alphaFineConfigManager.getValue(); } public void setAlphaFineConfigManager(AlphaFineConfigManager alphaFineConfigManager) { - this.alphaFineConfigManager = alphaFineConfigManager; + this.alphaFineConfigManager.setValue(alphaFineConfigManager); } public boolean isImageCompress() { @@ -1801,7 +1853,101 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { public void setLayoutTemplateStyle(int layoutTemplateStyle) { this.layoutTemplateStyle = layoutTemplateStyle; } - + + @Override + public void initElements(File xmlFile) throws XmlException { + + try { + backupOldXmlFile(); + XmlInitialFactory xmlInitialFactory = XmlInitialFactory.create(xmlFile); + xmlInitialFactory + .init("XMLVersion", DesignerEnvManager.this::readXMLVersion) + .init("Attributes", DesignerEnvManager.this::readAttributes) + .init("ReportPaneAttributions", DesignerEnvManager.this::readReportPaneAttributions) + .init("RecentOpenedFilePath", (e) -> { + this.recentOpenedMapping = AsyncXmlElement.of(DesignerStartupPool.common(), () -> { + DesignerEnvManager.this.readRecentOpenFileList0(e); + return recentOpenedFileListMap; + }).callback(new Callback>>() { + @Override + public void exec(Map> stringListMap) { + checkRecentOpenedFileNum(); + } + }); + }) + .init("EnvConfigMap", (e) -> { + + final EnvConfiguration previousConfig = this.envConfig.getValue(); + this.envConfig = AsyncXmlElement.of(DesignerStartupPool.common(), () -> { + DesignerEnvManager.this.readEnvConfigMap(e, previousConfig); + return previousConfig; + }); + }) + .init("LogLocation", DesignerEnvManager.this::readLogLocation) + .init("Language", DesignerEnvManager.this::readLanguage) + .init("JettyServerPort", DesignerEnvManager.this::readJettyPort) + .init("PLengthUnit", DesignerEnvManager.this::readPageLengthUnit) + .init("RLengthUnit", DesignerEnvManager.this::readReportLengthUnit) + .init("LastOpenFilePath", DesignerEnvManager.this::readLastOpenFile) + .init("EncryptionKey", DesignerEnvManager.this::readEncrytionKey) + .init("jdkHome", (e) -> this.jdkHome = e.getElementValue()) + .init("lastBBSTime", DesignerEnvManager.this::readLastBBSTime) + .init("lastBBSNewsTime", DesignerEnvManager.this::readLastBBSNewsTime) + .init("ActivationKey", DesignerEnvManager.this::readActiveKey) + .init("status", DesignerEnvManager.this::readActiveStatus) + .init(CAS_PARAS, DesignerEnvManager.this::readHttpsParas) + .init(EnvDetectorConfig.XML_TAG, DesignerEnvManager.this::readEnvDetectorConfig) + .init(DesignerStartupConfig.XML_TAG, DesignerEnvManager.this::readStartupConfig) + .init("AlphaFineConfigManager", (e) -> { + this.alphaFineConfigManager = AsyncXmlElement.of(DesignerStartupPool.common(), () -> { + AlphaFineConfigManager config = AlphaFineConfigManager.getInstance(); + e.readXMLObject(config); + return config; + }); + }) + .init("RecentColors", DesignerEnvManager.this::readRecentColor) + .init("OpenDebug", DesignerEnvManager.this::readOpenDebug) + .init(ComponentReuseNotificationInfo.XML_TAG, DesignerEnvManager.this::readComponentReuseNotificationInfo) + .init(DesignerPushUpdateConfigManager.XML_TAG, DesignerEnvManager.this::readDesignerPushUpdateAttr) + .init(VcsConfigManager.XML_TAG, DesignerEnvManager.this::readVcsAttr) + .init(DesignerPort.XML_TAG, DesignerEnvManager.this::readDesignerPort) + .init(SnapChatConfig.XML_TAG, DesignerEnvManager.this::readSnapChatConfig) + .init(DesignerLoginConfigManager.XML_TAG, DesignerEnvManager.this::readDesignerLoginAttr) + .init(fvsDesignerConfig.getValue().getName(), (e) -> { + SimpleDesignerConfig config = this.fvsDesignerConfig.getValue(); + this.fvsDesignerConfig = AsyncXmlElement.of(() -> { + e.readXMLObject(config); + return config; + }); + }) + .init(SwitchForSwingChecker.XML_TAG, DesignerEnvManager.this::readSwitchForSwingCheckerAttr) + .init(LAST_WEST_REGION_LAYOUT, DesignerEnvManager.this::readLastWestRegionLayout) + .init(LAST_EAST_REGION_LAYOUT, DesignerEnvManager.this::readLastEastRegionLayout); + } catch (Exception e) { + throw new XmlException(e); + } + } + + /** + * 备份老的 xml 文件, 防止第一次修改存在问题 + * 但是,只备份一次。其他都走老逻辑 + */ + private void backupOldXmlFile() { + + try { + File oldFile = getEnvFile(); + String newFilePath = ProductConstants.getEnvHome() + File.separator + ProductConstants.APP_NAME + "Env_backup.xml"; + File newFile = new File(newFilePath); + if (newFile.exists()) { + return; + } + if (oldFile.exists()) { + FileUtils.copyFile(oldFile, newFile); + } + } catch (Exception ignored) { + } + } + /** * Read XML.
* The method will be invoked when read data from XML file.
@@ -1865,7 +2011,7 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { readComponentReuseNotificationInfo(reader); } else if (name.equals(DesignerPushUpdateConfigManager.XML_TAG)) { readDesignerPushUpdateAttr(reader); - } else if (name.equals(vcsConfigManager.XML_TAG)) { + } else if (name.equals(VcsConfigManager.XML_TAG)) { readVcsAttr(reader); } else if (DesignerPort.XML_TAG.equals(name)) { readDesignerPort(reader); @@ -1873,7 +2019,7 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { readSnapChatConfig(reader); } else if (name.equals(DesignerLoginConfigManager.XML_TAG)) { readDesignerLoginAttr(reader); - } else if (name.equals(fvsDesignerConfig.getName())) { + } else if (name.equals(fvsDesignerConfig.getValue().getName())) { readFvsDesignerConfig(reader); } else if (name.equals(SwitchForSwingChecker.XML_TAG)) { readSwitchForSwingCheckerAttr(reader); @@ -1893,7 +2039,10 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { } private void readAlphaFineAttr(XMLableReader reader) { - reader.readXMLObject(this.alphaFineConfigManager = AlphaFineConfigManager.getInstance()); + + AlphaFineConfigManager config = AlphaFineConfigManager.getInstance(); + reader.readXMLObject(config); + this.alphaFineConfigManager = SimpleXmlElement.of(config); } private void readEnvDetectorConfig(XMLableReader reader) { @@ -1918,9 +2067,9 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { private void readLayout(XMLableReader reader, String name) { - if ("LastEastRegionLayout".equals(name)) { + if (LAST_EAST_REGION_LAYOUT.equals(name)) { this.readLastEastRegionLayout(reader); - } else if ("LastWestRegionLayout".equals(name)) { + } else if (LAST_WEST_REGION_LAYOUT.equals(name)) { this.readLastWestRegionLayout(reader); } } @@ -2015,6 +2164,40 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { this.setPaginationLineColor(new Color(Integer.parseInt(tmpVal))); } } + + private void readEnvConfigMap(XMLableReader reader, EnvConfiguration envConfigs) { + + String currentEnv = reader.getAttrAsString("currentEnv", StringUtils.EMPTY); + envConfigs.setCurEnvName(currentEnv); + reader.readXMLObject(new XMLReadable() { + @Override + public void readXML(XMLableReader reader) { + if (reader.isAttr()) { + envConfigs.getNameEnvMap().clear(); + } else if (reader.isChildNode()) { + String tagName = reader.getTagName(); + if ("EnvConfigElement".equals(tagName)) { + final String name = reader.getAttrAsString("name", StringUtils.EMPTY); + reader.readXMLObject(new XMLReadable() { + @Override + public void readXML(XMLableReader reader) { + if (reader.isChildNode()) { + String tagName = reader.getTagName(); + if (DesignerWorkspaceType.Local.toString().equals(tagName)) { + LocalDesignerWorkspaceInfo envConfig = (LocalDesignerWorkspaceInfo) GeneralXMLTools.readXMLable(reader); + envConfigs.getNameEnvMap().put(name, envConfig); + } else if (DesignerWorkspaceType.Remote.toString().equals(tagName)) { + RemoteDesignerWorkspaceInfo envConfig = (RemoteDesignerWorkspaceInfo) GeneralXMLTools.readXMLable(reader); + envConfigs.getNameEnvMap().put(name, envConfig); + } + } + } + }); + } + } + } + }); + } private void readEnvConfigMap(XMLableReader reader) { String currentEnv = reader.getAttrAsString("currentEnv", StringUtils.EMPTY); @@ -2048,8 +2231,15 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { } }); } - + private void readRecentOpenFileList(XMLableReader reader) { + + readRecentOpenFileList0(reader); + checkRecentOpenedFileNum(); + } + + private void readRecentOpenFileList0(XMLableReader reader) { + reader.readXMLObject(new XMLReadable() { @Override public void readXML(XMLableReader reader) { @@ -2081,7 +2271,6 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { } } }); - checkRecentOpenedFileNum(); } private void readDesignerPushUpdateAttr(XMLableReader reader) { @@ -2151,7 +2340,7 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { private void writeAlphaFineAttr(XMLPrintWriter writer) { if (this.alphaFineConfigManager != null) { - this.alphaFineConfigManager.writeXML(writer); + this.alphaFineConfigManager.getValue().writeXML(writer); } } @@ -2228,10 +2417,10 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { writer.end(); writer.startTAG("EnvConfigMap"); - if (this.curEnvName != null) { - writer.attr("currentEnv", this.curEnvName); + if (this.getCurEnvName() != null) { + writer.attr("currentEnv", this.getCurEnvName()); } - for (Entry entry : nameEnvMap.entrySet()) { + for (Entry entry : getNameEnvMap().entrySet()) { writer.startTAG("EnvConfigElement").attr("name", entry.getKey()); DesignerWorkspaceInfo envConfig = entry.getValue(); GeneralXMLTools.writeXMLable(writer, envConfig, envConfig.getType().toString()); @@ -2440,11 +2629,14 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { } private void readFvsDesignerConfig(XMLableReader reader) { - reader.readXMLObject(fvsDesignerConfig); + + SimpleDesignerConfig config = fvsDesignerConfig.getValue(); + reader.readXMLObject(config); + fvsDesignerConfig = SimpleXmlElement.of(config); } private void writeFvsDesignerConfig(XMLPrintWriter writer) { - this.fvsDesignerConfig.writeXML(writer); + this.fvsDesignerConfig.getValue().writeXML(writer); } private void writeSwitchForSwingChecker(XMLPrintWriter writer) { @@ -2479,4 +2671,39 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { public SnapChatConfig getSnapChatConfig() { return snapChatConfig; } + + private EnvConfiguration getEnvConfig() { + + return envConfig.getValue(); + } + + private Map getNameEnvMap() { + + return getEnvConfig().getNameEnvMap(); + } + + private static class EnvConfiguration { + + // name和Env的键值对 + private Map nameEnvMap = new ListMap<>(); + // marks: 当前报表服务器名字 + private String curEnvName = null; + + public Map getNameEnvMap() { + return nameEnvMap; + } + + public void setNameEnvMap(Map nameEnvMap) { + this.nameEnvMap = nameEnvMap; + } + + public String getCurEnvName() { + return curEnvName; + } + + public void setCurEnvName(String curEnvName) { + this.curEnvName = curEnvName; + } + } + } diff --git a/designer-base/src/main/java/com/fr/design/actions/AllowAuthorityEditAction.java b/designer-base/src/main/java/com/fr/design/actions/AllowAuthorityEditAction.java index 1a0509d267..546a702979 100644 --- a/designer-base/src/main/java/com/fr/design/actions/AllowAuthorityEditAction.java +++ b/designer-base/src/main/java/com/fr/design/actions/AllowAuthorityEditAction.java @@ -1,9 +1,9 @@ package com.fr.design.actions; -import com.fr.base.svg.IconUtils; import com.fr.base.vcs.DesignerMode; import com.fr.design.constants.UIConstants; import com.fr.design.menu.KeySetUtils; +import com.fr.design.module.DesignModuleFactory; import com.fr.design.roleAuthority.ReportAndFSManagePane; import com.fr.design.roleAuthority.RolesAlreadyEditedPane; import com.fr.design.designer.TargetComponent; @@ -61,6 +61,8 @@ public class AllowAuthorityEditAction extends TemplateComponentAction { DesignerContext.getDesignerFrame().refreshDottedLine(); EastRegionContainerPane.getInstance().replaceConfiguredRolesPane(RolesAlreadyEditedPane.getInstance()); EastRegionContainerPane.getInstance().removeParameterPane(); + //进入时要关闭查找替换面板 + DesignModuleFactory.getReplaceOperator().close(); //画虚线 return true; diff --git a/designer-base/src/main/java/com/fr/design/actions/UpdateAction.java b/designer-base/src/main/java/com/fr/design/actions/UpdateAction.java index 048f233373..d33c04eb15 100644 --- a/designer-base/src/main/java/com/fr/design/actions/UpdateAction.java +++ b/designer-base/src/main/java/com/fr/design/actions/UpdateAction.java @@ -185,12 +185,24 @@ public abstract class UpdateAction extends ShortCut implements Action { * @param resource 图标资源路径 */ public void setSmallIcon(String resource) { + setSmallIcon(resource, true); + } + + /** + * 使用传入资源url的方式设置Icon,会自动设置_normal.svg,然后通过needDisable参数判断是否需要自动设置_disable.svg + * 因为有些地方是不需要设置灰化图标的,所以不存在灰化图标资源,这边如果一并设置,就会报错文件找不到 + * @param resource + * @param needDisable + */ + public void setSmallIcon(String resource, boolean needDisable) { if (StringUtils.equals(resource, StringUtils.EMPTY)) { this.putValue(Action.SMALL_ICON, null); return; } this.putValue(Action.SMALL_ICON, IconUtils.readIcon(resource)); - this.putValue(UpdateAction.DISABLED_ICON, IconUtils.readSVGIcon(resource, IconUtils.ICON_TYPE_DISABLED)); + if (needDisable) { + this.putValue(UpdateAction.DISABLED_ICON, IconUtils.readSVGIcon(resource, IconUtils.ICON_TYPE_DISABLED)); + } } public void setSmallIcon(Icon[] smallIcon, boolean white) { diff --git a/designer-base/src/main/java/com/fr/design/actions/core/ActionFactory.java b/designer-base/src/main/java/com/fr/design/actions/core/ActionFactory.java index 2d4554afdd..3a8137f9d0 100644 --- a/designer-base/src/main/java/com/fr/design/actions/core/ActionFactory.java +++ b/designer-base/src/main/java/com/fr/design/actions/core/ActionFactory.java @@ -6,6 +6,7 @@ import com.fr.design.file.HistoryTemplateListPane; import com.fr.design.mainframe.JTemplate; import com.fr.design.menu.MenuKeySet; import com.fr.design.selection.QuickEditor; +import com.fr.design.ui.util.UIUtil; import com.fr.log.FineLoggerFactory; import com.fr.stable.StringUtils; @@ -32,6 +33,7 @@ public class ActionFactory { private static Set> actionClasses = new CopyOnWriteArraySet<>(); private static Set> floatActionClasses = new CopyOnWriteArraySet<>(); private static Class chartCollectionClass = null; + /** * 无需每次实例化的悬浮元素编辑器 */ @@ -57,7 +59,6 @@ public class ActionFactory { private ActionFactory() { } - /** * 元素编辑器释放模板对象 */ @@ -69,7 +70,34 @@ public class ActionFactory { entry.getValue().release(); } } - + + /** + * 注册异步加载的单元格编辑器 + * 首先放到 classMap 中,当初始化成功后,则移除,并放到 cellEditor 中 + * 如果已经存在,则覆盖 + * + * @param keyClazz 作为 key 的类 + * @param editorClazz 作为 编辑器 的类 + */ + public static void registerAsyncInitCellEditorClass(Class keyClazz, Class editorClazz) { + + cellEditorClass.put(keyClazz, editorClazz); + // 这里直接用 invokeLater 放到 UI 线程中去调用。 + // 不阻塞主逻辑的启动 + UIUtil.invokeLaterIfNeeded(new Runnable() { + @Override + public void run() { + + try { + QuickEditor quickEditor = editorClazz.newInstance(); + cellEditorClass.remove(keyClazz); + cellEditor.put(keyClazz, quickEditor); + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + } + } + }); + } /** * 注册无需每次实例化的单元格元素编辑器 diff --git a/designer-base/src/main/java/com/fr/design/actions/file/CloseCurrentTemplateAction.java b/designer-base/src/main/java/com/fr/design/actions/file/CloseCurrentTemplateAction.java index 58fe5666a4..22263a871e 100644 --- a/designer-base/src/main/java/com/fr/design/actions/file/CloseCurrentTemplateAction.java +++ b/designer-base/src/main/java/com/fr/design/actions/file/CloseCurrentTemplateAction.java @@ -3,7 +3,7 @@ package com.fr.design.actions.file; import com.fr.design.actions.UpdateAction; import com.fr.design.file.HistoryTemplateListCache; import com.fr.design.file.HistoryTemplateListPane; -import com.fr.design.file.MutilTempalteTabPane; +import com.fr.design.file.MultiTemplateTabPane; import com.fr.design.mainframe.JTemplate; import com.fr.design.menu.KeySetUtils; @@ -28,9 +28,9 @@ public class CloseCurrentTemplateAction extends UpdateAction { * @param e 事件 */ public void actionPerformed(ActionEvent e) { - MutilTempalteTabPane.getInstance().setIsCloseCurrent(true); - MutilTempalteTabPane.getInstance().closeFormat(HistoryTemplateListPane.getInstance().getCurrentEditingTemplate()); - MutilTempalteTabPane.getInstance().closeSpecifiedTemplate(HistoryTemplateListPane.getInstance().getCurrentEditingTemplate()); + MultiTemplateTabPane.getInstance().setIsCloseCurrent(true); + MultiTemplateTabPane.getInstance().closeFormat(HistoryTemplateListPane.getInstance().getCurrentEditingTemplate()); + MultiTemplateTabPane.getInstance().closeSpecifiedTemplate(HistoryTemplateListPane.getInstance().getCurrentEditingTemplate()); } @Override diff --git a/designer-base/src/main/java/com/fr/design/actions/file/PreferencePane.java b/designer-base/src/main/java/com/fr/design/actions/file/PreferencePane.java index fdc0a46ae8..46485409bb 100644 --- a/designer-base/src/main/java/com/fr/design/actions/file/PreferencePane.java +++ b/designer-base/src/main/java/com/fr/design/actions/file/PreferencePane.java @@ -119,6 +119,7 @@ public class PreferencePane extends BasicPane { private static final int CACHING_DEFAULT = 5; private static final int CACHING_GAP = 5; private static final int MEMORY_TIP_LABEL_MAX_WIDTH = 230; + private static final int PREFERENCE_LABEL_MAX_WIDTH = 460; private static final int OFFSET_HEIGHT = 60; private static final String TYPE = "pressed"; @@ -423,22 +424,20 @@ public class PreferencePane extends BasicPane { private void createFunctionPane(JPanel generalPane) { JPanel topVerticalTitledBorderPane = FRGUIPaneFactory.createTopVerticalTitledBorderPane(i18nText("Fine-Design_Basic_Preference_Function")); - JPanel upper = new JPanel(FRGUIPaneFactory.createLeftZeroVgapNormalHgapLayout()); - JPanel lower = new JPanel(FRGUIPaneFactory.createLeftZeroVgapNormalHgapLayout()); - topVerticalTitledBorderPane.add(upper); - topVerticalTitledBorderPane.add(lower); + JPanel supportUndoPanel = new JPanel(FRGUIPaneFactory.createLeftZeroVgapNormalHgapLayout()); + topVerticalTitledBorderPane.add(supportUndoPanel); generalPane.add(topVerticalTitledBorderPane); //添加supportUndo选择项 supportUndoCheckBox = new UICheckBox(i18nText("Fine-Design_Basic_Preference_Support_Undo")); - upper.add(supportUndoCheckBox); + supportUndoPanel.add(supportUndoCheckBox); //添加maxUndoLimit //String[] undoTimes = {"最大撤销次数","5次","10次","15次","20次","50次"}; String[] undoTimes = {i18nText("Fine-Design_Basic_Max_Undo_Limit"), MAX_UNDO_LIMIT_5 + i18nText("Fine-Design_Basic_Time(s)"), MAX_UNDO_LIMIT_10 + i18nText("Fine-Design_Basic_Time(s)") , MAX_UNDO_LIMIT_15 + i18nText("Fine-Design_Basic_Time(s)"), MAX_UNDO_LIMIT_20 + i18nText("Fine-Design_Basic_Time(s)"), MAX_UNDO_LIMIT_50 + i18nText("Fine-Design_Basic_Time(s)")}; maxUndoLimit = new UIComboBox(undoTimes); - upper.add(maxUndoLimit); + supportUndoPanel.add(maxUndoLimit); //不支持撤销则不能选择撤销可缓存,也不能设置最大撤销次数 supportUndoCheckBox.addActionListener(new ActionListener() { @@ -452,14 +451,14 @@ public class PreferencePane extends BasicPane { //添加supportDefaultParentCalculate选择项 supportDefaultParentCalculateCheckBox = new UICheckBox( i18nText("Fine-Design_Basic_Preference_Support_Default_Parent_Calculate")); - upper.add(supportDefaultParentCalculateCheckBox); + topVerticalTitledBorderPane.add(supportDefaultParentCalculateCheckBox); //添加是否展示打开模板提示缺少插件选择项 showTemplateMissingPlugin = new UICheckBox( i18nText("Fine-Design_Basic_Preference_Show-Template-Missing-Plugin")); - upper.add(showTemplateMissingPlugin); + topVerticalTitledBorderPane.add(showTemplateMissingPlugin); startWithEmptyFile = new UICheckBox(i18nText("Fine-Design_Basic_Preference_Start_Empty_File")); - lower.add(startWithEmptyFile); + topVerticalTitledBorderPane.add(startWithEmptyFile); } private void createEditPane(JPanel generalPane) { @@ -661,7 +660,7 @@ public class PreferencePane extends BasicPane { startupPageEnabledCheckBox = new UICheckBox(Toolkit.i18nText("Fine-Design_Startup_Page_Config_Check_Text")); startupPane.add(startupPageEnabledCheckBox); - UILabel descLabel = new UILabel(Toolkit.i18nText("Fine-Design_Startup_Page_Config_Desc")); + UILabel descLabel = FRWidgetFactory.createLineWrapLabel(Toolkit.i18nText("Fine-Design_Startup_Page_Config_Desc"), PREFERENCE_LABEL_MAX_WIDTH); descLabel.setForeground(new Color(51, 51, 52, (int)Math.round(0.5 * 255))); startupPane.add(descLabel); } diff --git a/designer-base/src/main/java/com/fr/design/actions/file/RenameAction.java b/designer-base/src/main/java/com/fr/design/actions/file/RenameAction.java index e9adc880a7..c1efc4f5eb 100644 --- a/designer-base/src/main/java/com/fr/design/actions/file/RenameAction.java +++ b/designer-base/src/main/java/com/fr/design/actions/file/RenameAction.java @@ -7,7 +7,7 @@ import com.fr.design.actions.UpdateAction; import com.fr.design.dialog.FineJOptionPane; import com.fr.design.file.FileOperations; import com.fr.design.file.HistoryTemplateListCache; -import com.fr.design.file.MutilTempalteTabPane; +import com.fr.design.file.MultiTemplateTabPane; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.itextfield.UITextField; @@ -16,7 +16,6 @@ import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayoutHelper; import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.DesignerFrameFileDealerPane; -import com.fr.design.mainframe.manager.search.TemplateTreeSearchManager; import com.fr.design.mainframe.vcs.common.VcsHelper; import com.fr.design.utils.TemplateUtils; import com.fr.design.utils.gui.GUICoreUtils; @@ -89,7 +88,7 @@ public class RenameAction extends UpdateAction { } new FileRenameDialog(node); - MutilTempalteTabPane.getInstance().repaint(); + MultiTemplateTabPane.getInstance().repaint(); DesignerFrameFileDealerPane.getInstance().stateChange(); } diff --git a/designer-base/src/main/java/com/fr/design/actions/help/AboutPane.java b/designer-base/src/main/java/com/fr/design/actions/help/AboutPane.java index 6158540888..dbb7798f3b 100644 --- a/designer-base/src/main/java/com/fr/design/actions/help/AboutPane.java +++ b/designer-base/src/main/java/com/fr/design/actions/help/AboutPane.java @@ -126,8 +126,8 @@ public class AboutPane extends JPanel { if (GeneralContext.getLocale().equals(Locale.TAIWAN)) { return; } - boxCenterAlignmentPane = new BoxCenterAligmentPane("QQ: " + CloudCenter.getInstance().acquireUrlByKind("help.qq")); - contentPane.add(boxCenterAlignmentPane); + JPanel servicePlatformPane = getURLActionPane(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Service_Platform"), CloudCenter.getInstance().acquireUrlByKind("service.platform")); + contentPane.add(servicePlatformPane); } // 是否显示鸣谢面板 diff --git a/designer-base/src/main/java/com/fr/design/actions/help/alphafine/AlphaFineCloudConstants.java b/designer-base/src/main/java/com/fr/design/actions/help/alphafine/AlphaFineCloudConstants.java index 5e527d9916..9fb243d1e8 100644 --- a/designer-base/src/main/java/com/fr/design/actions/help/alphafine/AlphaFineCloudConstants.java +++ b/designer-base/src/main/java/com/fr/design/actions/help/alphafine/AlphaFineCloudConstants.java @@ -1,10 +1,14 @@ package com.fr.design.actions.help.alphafine; +import com.fr.design.i18n.Toolkit; import com.fr.general.CloudCenter; +import com.fr.json.JSONArray; + +import java.util.HashMap; +import java.util.Map; /** - * 需要从云端获取的常量单独放一起 - * 以防AlphaFineConstants被加载时,CloudCenter还没启动,导致常量获取不到。 + * 云端变量统一管理 * * @author Link * @version 11.0 @@ -12,55 +16,185 @@ import com.fr.general.CloudCenter; */ public class AlphaFineCloudConstants { - public static final String PLUGIN_SEARCH_URL = CloudCenter.getInstance().acquireUrlByKind("plugin.searchAPI"); - - public static final String SEARCH_ALL_PLUGIN_URL = CloudCenter.getInstance().acquireUrlByKind("plugin.all.searchAPI"); - - public static final String PLUGIN_URL = CloudCenter.getInstance().acquireUrlByKind("af.pluginInfo"); - - public static final String REUSE_URL = CloudCenter.getInstance().acquireUrlByKind("af.reuseInfo"); - - public static final String DOCUMENT_DOC_URL = CloudCenter.getInstance().acquireUrlByKind("af.doc_view"); - - public static final String DOCUMENT_SEARCH_URL = CloudCenter.getInstance().acquireUrlByKind("af.doc_search"); - - public static final String DOCUMENT_INFORMATION_URL = CloudCenter.getInstance().acquireUrlByKind("af.doc_info"); - - public static final String PLUGIN_IMAGE_URL = CloudCenter.getInstance().acquireUrlByKind("af.plugin_image"); - - public static final String CLOUD_SERVER_URL = CloudCenter.getInstance().acquireUrlByKind("af.record"); - - public static final String SEARCH_API = CloudCenter.getInstance().acquireUrlByKind("af.cloud_search"); - - public static final String SIMILAR_SEARCH_URL_PREFIX = CloudCenter.getInstance().acquireUrlByKind("af.similar_search"); - - public static final String COMPLEMENT_ADVICE_SEARCH_URL_PREFIX = CloudCenter.getInstance().acquireUrlByKind("af.advice_search"); - - public static final String ALPHA_HOT_SEARCH = CloudCenter.getInstance().acquireUrlByKind("af.hot_search"); - - public static final String ALPHA_GO_TO_FORUM = CloudCenter.getInstance().acquireUrlByKind("af.go_fourm"); - - public static final String ALPHA_GO_TO_WEB = CloudCenter.getInstance().acquireUrlByKind("af.go_web"); - - public static final String ALPHA_PREVIEW = CloudCenter.getInstance().acquireUrlByKind("af.preview"); - - public static final String ALPHA_CID = CloudCenter.getInstance().acquireUrlByKind("af.cid.new"); - - public static final String ALPHA_CID_USER_GROUP_INFO = CloudCenter.getInstance().acquireUrlByKind("af.cid.user.group.info"); - - private static final String QUICK_START_URL = CloudCenter.getInstance().acquireUrlByKind("af.help.quick.start"); - - private static final String REPORT_LEARNING_PATH = CloudCenter.getInstance().acquireUrlByKind("af.help.report.learning.path"); - - private static final String PARAMETER_LEARNING_PATH = CloudCenter.getInstance().acquireUrlByKind("af.help.param.learning.path"); - - private static final String FILL_LEARNING_PATH = CloudCenter.getInstance().acquireUrlByKind("af.help.fill.learning.path"); - - private static final String API_SUMMARY = CloudCenter.getInstance().acquireUrlByKind("af.help.api.summary"); - - private static final String MONTHLY_DOCUMENT = CloudCenter.getInstance().acquireUrlByKind("af.help.monthly.document"); - - private static final String DEFAULT_RECOMMEND = "[ { \"name\":\"快速入门指南\", \"link\":\"" + QUICK_START_URL + "\" }, { \"name\":\"报表应用学习路径\", \"link\":\"" + REPORT_LEARNING_PATH + "\" }, { \"name\":\"参数应用学习路径\", \"link\":\"" + PARAMETER_LEARNING_PATH + "\" }, { \"name\":\"填报学习路径\", \"link\":\"" + FILL_LEARNING_PATH + "\" }, { \"name\":\"API接口汇总\", \"link\":\"" + API_SUMMARY + "\" }, { \"name\":\"文档月刊\", \"link\":\"" + MONTHLY_DOCUMENT + "\" } ]"; - - public static final String ALPHA_HELP_RECOMMEND = CloudCenter.getInstance().acquireUrlByKind("af.recommend", DEFAULT_RECOMMEND); + private static final String PLUGIN_SEARCH_API = "plugin.searchAPI"; + private static final String PLUGIN_ALL_SEARCH_API = "plugin.all.searchAPI"; + private static final String AF_PLUGIN_INFO = "af.pluginInfo"; + private static final String AF_REUSE_INFO = "af.reuseInfo"; + private static final String AF_DOC_VIEW = "af.doc_view"; + private static final String AF_DOC_SEARCH = "af.doc_search"; + private static final String AF_DOC_INFO = "af.doc_info"; + private static final String AF_PLUGIN_IMAGE = "af.plugin_image"; + private static final String AF_RECORD = "af.record"; + private static final String AF_CLOUD_SEARCH = "af.cloud_search"; + private static final String AF_SIMILAR_SEARCH = "af.similar_search"; + private static final String AF_ADVICE_SEARCH = "af.advice_search"; + private static final String AF_HOT_SEARCH = "af.hot_search"; + private static final String AF_GO_FORUM = "af.go_fourm"; + private static final String AF_GO_WEB = "af.go_web"; + private static final String AF_PREVIEW = "af.preview"; + private static final String AF_CID_NEW = "af.cid.new"; + private static final String AF_CID_USER_GROUP_INFO = "af.cid.user.group.info"; + private static final String AF_HELP_QUICK_START = "af.help.quick.start"; + private static final String AF_HELP_REPORT_LEARNING_PATH = "af.help.report.learning.path"; + private static final String AF_HELP_PARAM_LEARNING_PATH = "af.help.param.learning.path"; + private static final String AF_HELP_FILL_LEARNING_PATH = "af.help.fill.learning.path"; + private static final String AF_HELP_API_SUMMARY = "af.help.api.summary"; + private static final String AF_HELP_MONTHLY_DOCUMENT = "af.help.monthly.document"; + private static final String AF_RECOMMEND = "af.recommend"; + + private static final String LINK_NAME = "name"; + private static final String LINK_URL = "link"; + + /** + * 获取插件搜索api + */ + public static String getPluginSearchUrl() { + return CloudCenter.getInstance().acquireUrlByKind(PLUGIN_SEARCH_API); + }; + + /** + * 帆软市场里全部插件api + */ + public static String getSearchAllPluginUrl() { + return CloudCenter.getInstance().acquireUrlByKind(PLUGIN_ALL_SEARCH_API); + } + + /** + * 获取插件信息api + */ + public static String getPluginUrl() { + return CloudCenter.getInstance().acquireUrlByKind(AF_PLUGIN_INFO); + } + + /** + * 获取组件信息api + */ + public static String getReuseUrl() { + return CloudCenter.getInstance().acquireUrlByKind(AF_REUSE_INFO); + } + + /** + * 获取帮助文档url + */ + public static String getDocumentDocUrl() { + return CloudCenter.getInstance().acquireUrlByKind(AF_DOC_VIEW); + } + + /** + * 帮助文档搜索api + */ + public static String getDocumentSearchUrl() { + return CloudCenter.getInstance().acquireUrlByKind(AF_DOC_SEARCH); + } + + /** + * 帮助文档信息api + */ + public static String getDocumentInformationUrl() { + return CloudCenter.getInstance().acquireUrlByKind(AF_DOC_INFO); + } + + /** + * 插件图片api + */ + public static String getPluginImageUrl() { + return CloudCenter.getInstance().acquireUrlByKind(AF_PLUGIN_IMAGE); + } + + /** + * 获取云端接口,用于上传alphafine搜索记录 + */ + public static String getCloudServerUrl() { + return CloudCenter.getInstance().acquireUrlByKind(AF_RECORD); + } + + /** + * 获取搜索api,输入搜索词,返回fr的相关功能 + */ + public static String getSearchApi() { + return CloudCenter.getInstance().acquireUrlByKind(AF_CLOUD_SEARCH); + } + + /** + * 获取模糊搜索api前缀,输入搜索词,返回alphaFine相关内容,插件,文档,功能等 + */ + public static String getSimilarSearchUrlPrefix() { + return CloudCenter.getInstance().acquireUrlByKind(AF_SIMILAR_SEARCH); + } + + /** + * 补全建议搜索结果 api,与AF_SIMILAR_SEARCH接口类似,但是返回的信息更全 + */ + public static String getComplementAdviceSearchUrlPrefix() { + return CloudCenter.getInstance().acquireUrlByKind(AF_ADVICE_SEARCH); + } + + /** + * 获取热门问题 + */ + public static String getAlphaHotSearch() { + return CloudCenter.getInstance().acquireUrlByKind(AF_HOT_SEARCH); + } + + /** + * 跳转论坛url + */ + public static String getAlphaGoToForum() { + return CloudCenter.getInstance().acquireUrlByKind(AF_GO_FORUM); + } + + /** + * 推荐搜索api,输入搜索词,返回猜你想搜的内容(html格式) + */ + public static String getAlphaGoToWeb() { + return CloudCenter.getInstance().acquireUrlByKind(AF_GO_WEB); + } + + /** + * 帆软智能客服页面url + */ + public static String getAlphaPreview() { + return CloudCenter.getInstance().acquireUrlByKind(AF_PREVIEW); + } + + /** + * cid系统的产品动态api + */ + public static String getAlphaCid() { + return CloudCenter.getInstance().acquireUrlByKind(AF_CID_NEW); + } + + /** + * cid系统的 用户组信息api + */ + public static String getAlphaCidUserGroupInfo() { + return CloudCenter.getInstance().acquireUrlByKind(AF_CID_USER_GROUP_INFO); + } + + private static String getDefaultRecommend() { + String[][] links = new String[][]{ + {Toolkit.i18nText("Fine-Design_Report_AlphaFine_Doc_Quick_Start"), CloudCenter.getInstance().acquireUrlByKind(AF_HELP_QUICK_START)}, + {Toolkit.i18nText("Fine-Design_Report_AlphaFine_Doc_Report_Learning"), CloudCenter.getInstance().acquireUrlByKind(AF_HELP_REPORT_LEARNING_PATH)}, + {Toolkit.i18nText("Fine-Design_Report_AlphaFine_Doc_Parameter_Learning"), CloudCenter.getInstance().acquireUrlByKind(AF_HELP_PARAM_LEARNING_PATH)}, + {Toolkit.i18nText("Fine-Design_Report_AlphaFine_Doc_Fill_Learning"), CloudCenter.getInstance().acquireUrlByKind(AF_HELP_FILL_LEARNING_PATH)}, + {Toolkit.i18nText("Fine-Design_Report_AlphaFine_Doc_Api_Summary"), CloudCenter.getInstance().acquireUrlByKind(AF_HELP_API_SUMMARY)}, + {Toolkit.i18nText("Fine-Design_Report_AlphaFine_Doc_Monthly_Document"), CloudCenter.getInstance().acquireUrlByKind(AF_HELP_MONTHLY_DOCUMENT)} + }; + JSONArray jsonArray = new JSONArray(); + for (String[] link : links) { + Map map = new HashMap<>(); + map.put(LINK_NAME, link[0]); + map.put(LINK_URL, link[1]); + jsonArray.put(map); + } + + return jsonArray.toString(); + } + + /** + * 获取默认推荐帮助文档url + */ + public static String getAlphaHelpRecommend() { + return CloudCenter.getInstance().acquireUrlByKind(AF_RECOMMEND, getDefaultRecommend()); + } } diff --git a/designer-base/src/main/java/com/fr/design/actions/help/alphafine/AlphaFineConfigManager.java b/designer-base/src/main/java/com/fr/design/actions/help/alphafine/AlphaFineConfigManager.java index c74ddaa65a..7d02c03864 100644 --- a/designer-base/src/main/java/com/fr/design/actions/help/alphafine/AlphaFineConfigManager.java +++ b/designer-base/src/main/java/com/fr/design/actions/help/alphafine/AlphaFineConfigManager.java @@ -108,6 +108,7 @@ public class AlphaFineConfigManager implements XMLable { private Map actionSearchTextCache = new HashMap<>(8); private String cacheBuildNO; + private static final String CONTAIN_TEMPLATE_SHOP = "isContainTemplateShop"; /** * key: 登录的bbs用户 @@ -151,6 +152,7 @@ public class AlphaFineConfigManager implements XMLable { this.setContainPlugin(reader.getAttrAsBoolean("isContainDocument", true)); this.setContainDocument(reader.getAttrAsBoolean("isContainDocument", true)); this.setContainRecommend(reader.getAttrAsBoolean("isContainRecommend", true)); + this.setShowTemplateShop(reader.getAttrAsBoolean(CONTAIN_TEMPLATE_SHOP, true)); this.setContainAction(reader.getAttrAsBoolean("isContainAction", true)); this.setContainTemplate(reader.getAttrAsBoolean("isContainTemplate", true)); this.setContainFileContent(reader.getAttrAsBoolean("isContainFileContent", false)); @@ -258,6 +260,7 @@ public class AlphaFineConfigManager implements XMLable { .attr("needSegmentationCheckbox", this.isNeedSegmentationCheckbox()) .attr("needIntelligentCustomerService", this.isNeedIntelligentCustomerService()) .attr("productDynamics", this.isProductDynamics()) + .attr(CONTAIN_TEMPLATE_SHOP, this.showTemplateShop) .attr("tabOrder", this.getTabOrderString()); writeActionSearchTextCacheXML(writer); writeSearchHistory(writer); @@ -484,6 +487,14 @@ public class AlphaFineConfigManager implements XMLable { this.showTemplateShop = showTemplateShop; } + /** + * 是否展示alphafine窗口,设置-搜索范围 0勾选,则不显示 + */ + public boolean needShowAlphaFineDialog() { + return hasTemplateShop() || isContainDocument() || isContainPlugin() || + isContainAction() || isProductDynamics() || isContainMyTemplate(); + } + /** * 返回tab显示顺序 */ diff --git a/designer-base/src/main/java/com/fr/design/actions/help/alphafine/component/CustomSortPane.java b/designer-base/src/main/java/com/fr/design/actions/help/alphafine/component/CustomSortPane.java index 747b8d8ce0..9e2af09379 100644 --- a/designer-base/src/main/java/com/fr/design/actions/help/alphafine/component/CustomSortPane.java +++ b/designer-base/src/main/java/com/fr/design/actions/help/alphafine/component/CustomSortPane.java @@ -85,6 +85,7 @@ public class CustomSortPane extends JPanel { top.addActionListener(e -> { SwingUtilities.invokeLater(() -> { sortItemPane.setComponentZOrder(selectedLabel, 0); + setToolbarEnable(sortItemPane.getComponentZOrder(selectedLabel), sortItemPane.getComponentCount()); CustomSortPane.this.revalidate(); CustomSortPane.this.repaint(); refreshCurrentOrder(); @@ -94,6 +95,7 @@ public class CustomSortPane extends JPanel { bottom.addActionListener(e -> { SwingUtilities.invokeLater(() -> { sortItemPane.setComponentZOrder(selectedLabel, sortItemPane.getComponentCount() - 1); + setToolbarEnable(sortItemPane.getComponentZOrder(selectedLabel), sortItemPane.getComponentCount()); CustomSortPane.this.revalidate(); CustomSortPane.this.repaint(); refreshCurrentOrder(); @@ -103,6 +105,7 @@ public class CustomSortPane extends JPanel { up.addActionListener(e -> { SwingUtilities.invokeLater(() -> { sortItemPane.setComponentZOrder(selectedLabel, sortItemPane.getComponentZOrder(selectedLabel) - 1); + setToolbarEnable(sortItemPane.getComponentZOrder(selectedLabel), sortItemPane.getComponentCount()); CustomSortPane.this.revalidate(); CustomSortPane.this.repaint(); refreshCurrentOrder(); @@ -112,6 +115,7 @@ public class CustomSortPane extends JPanel { down.addActionListener(e -> { SwingUtilities.invokeLater(() -> { sortItemPane.setComponentZOrder(selectedLabel, sortItemPane.getComponentZOrder(selectedLabel) + 1); + setToolbarEnable(sortItemPane.getComponentZOrder(selectedLabel), sortItemPane.getComponentCount()); CustomSortPane.this.revalidate(); CustomSortPane.this.repaint(); refreshCurrentOrder(); @@ -151,16 +155,43 @@ public class CustomSortPane extends JPanel { private void disableButton() { int order = sortItemPane.getComponentZOrder(selectedLabel); if (order == 0) { - top.setEnabled(false); - up.setEnabled(false); + setToolbarEnable(false, false, true, true); } else if (order == sortItemPane.getComponentCount() - 1) { - down.setEnabled(false); - bottom.setEnabled(false); + setToolbarEnable(true, true, false, false); } else { - up.setEnabled(true); - top.setEnabled(true); - down.setEnabled(true); - bottom.setEnabled(true); + setToolbarEnable(true, true, true, true); + } + } + + /** + * 设置 置顶,上移,下移,置底 按钮的状态 + * true:启用 + * false:关闭 + */ + private void setToolbarEnable(boolean top, boolean up, boolean down, boolean bottom) { + this.top.setEnabled(top); + this.up.setEnabled(up); + this.down.setEnabled(down); + this.bottom.setEnabled(bottom); + } + + /** + * 根据选项当前位置以及菜单大小设置 置顶,上移,下移,置底 按钮的状态 + */ + private void setToolbarEnable(int order, int maxOrder) { + this.top.setEnabled(true); + this.up.setEnabled(true); + this.down.setEnabled(true); + this.bottom.setEnabled(true); + // 选项处于顶端,则置灰上移和置顶按钮 + if (order == 0) { + this.top.setEnabled(false); + this.up.setEnabled(false); + } + // 选项处于底端,则置灰下移和置底按钮 + if (order == maxOrder - 1) { + this.down.setEnabled(false); + this.bottom.setEnabled(false); } } diff --git a/designer-base/src/main/java/com/fr/design/actions/help/replace/ITReplaceOperator.java b/designer-base/src/main/java/com/fr/design/actions/help/replace/ITReplaceOperator.java new file mode 100644 index 0000000000..bbaaedd651 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/actions/help/replace/ITReplaceOperator.java @@ -0,0 +1,19 @@ +package com.fr.design.actions.help.replace; + + +/** + * 定义一些底层操作 + * + * @author Destiny.Lin + * @version 11.0 + * created by Destiny.Lin on 2022-09-27 + */ +public interface ITReplaceOperator { + + + /** + * 关闭面板 + */ + void close(); + +} diff --git a/designer-base/src/main/java/com/fr/design/carton/EventDispatchThreadHangMonitor.java b/designer-base/src/main/java/com/fr/design/carton/EventDispatchThreadHangMonitor.java index f472d901a1..a7bf03b407 100644 --- a/designer-base/src/main/java/com/fr/design/carton/EventDispatchThreadHangMonitor.java +++ b/designer-base/src/main/java/com/fr/design/carton/EventDispatchThreadHangMonitor.java @@ -1,13 +1,13 @@ package com.fr.design.carton; import com.fr.concurrent.FineExecutors; +import com.fr.design.ui.util.UIUtil; import com.fr.json.JSONObject; import com.fr.log.FineLoggerFactory; import com.fr.stable.ArrayUtils; import com.fr.stable.ProductConstantsBase; import com.fr.stable.StableUtils; import com.fr.stable.StringUtils; -import com.fr.third.ibm.icu.text.SimpleDateFormat; import org.jetbrains.annotations.NotNull; import javax.swing.SwingUtilities; @@ -22,6 +22,7 @@ import java.io.IOException; import java.lang.management.ManagementFactory; import java.lang.management.ThreadInfo; import java.lang.management.ThreadMXBean; +import java.text.SimpleDateFormat; import java.util.LinkedList; import java.util.Timer; import java.util.TimerTask; @@ -314,7 +315,7 @@ public final class EventDispatchThreadHangMonitor extends EventQueue { * 将swing中默认的EventQueue换成自己的 */ public static void initMonitoring() { - Toolkit.getDefaultToolkit().getSystemEventQueue().push(INSTANCE); + UIUtil.invokeLaterIfNeeded(() -> Toolkit.getDefaultToolkit().getSystemEventQueue().push(INSTANCE)); } /** diff --git a/designer-base/src/main/java/com/fr/design/carton/FeedbackToolboxDialog.java b/designer-base/src/main/java/com/fr/design/carton/FeedbackToolboxDialog.java index c7192eb099..83d6e24ac8 100644 --- a/designer-base/src/main/java/com/fr/design/carton/FeedbackToolboxDialog.java +++ b/designer-base/src/main/java/com/fr/design/carton/FeedbackToolboxDialog.java @@ -94,8 +94,7 @@ public class FeedbackToolboxDialog extends JDialog { private JPanel createInfoPane() { JPanel northPane = FRGUIPaneFactory.createNColumnGridInnerContainer_Pane(2, 10, 10); UILabel title = new UILabel(); - //空格布局会好看一点 - title.setText(" " + Toolkit.i18nText("Fine-Design_Basic_Carton_Record_Lag_Time") + ": "); + title.setText(" " + Toolkit.i18nText("Fine-Design_Basic_Carton_Record_Lag_Time") + ": "); //判断一下当天是否有卡顿日志记录,如果有将日期设置为当天,如果没有设置为空 boolean cartonExists = SwitchForSwingChecker.isCartonExists(); if (cartonExists) { @@ -344,8 +343,8 @@ public class FeedbackToolboxDialog extends JDialog { /** * 导出卡顿日志到本地或远程服务器WEB-INF下 * - * @param sourceFile 导出的卡顿日志所在文件夹 - * @param path 文件需要导出到的路径 + * @param sourceFile 导出的卡顿日志所在文件夹 + * @param path 文件需要导出到的路径 * @param sourceFilePath 导出的卡顿日志所在文件夹的路径 */ private void exportCartonLog(File sourceFile, String path, String sourceFilePath) { diff --git a/designer-base/src/main/java/com/fr/design/constants/UIConstants.java b/designer-base/src/main/java/com/fr/design/constants/UIConstants.java index b10d3f9e52..850a6b5aac 100644 --- a/designer-base/src/main/java/com/fr/design/constants/UIConstants.java +++ b/designer-base/src/main/java/com/fr/design/constants/UIConstants.java @@ -150,6 +150,7 @@ public interface UIConstants { public static final Color LIST_ITEM_SPLIT_LINE = new Color(0xf0f0f3); public static final Color DESIGNER_LOGIN_BACKGROUND = new Color(0xf1ad14); public static final Color DESIGNER_LOGIN_BACKGROUND_ONCLICK = new Color(0xd89600); + public static final Color CHECK_BOX_TIP_FONT_COLOR = new Color(51, 51, 52, (int)Math.round(0.5 * 255)); public static final BufferedImage DRAG_BAR = IOUtils.readImage("com/fr/design/images/control/bar.png"); public static final BufferedImage DRAG_BAR_LIGHT = IOUtils.readImage("com/fr/design/images/control/bar-light.png"); diff --git a/designer-base/src/main/java/com/fr/design/data/BasicTableDataTreePane.java b/designer-base/src/main/java/com/fr/design/data/BasicTableDataTreePane.java index fa1fe545ed..b3c090d549 100644 --- a/designer-base/src/main/java/com/fr/design/data/BasicTableDataTreePane.java +++ b/designer-base/src/main/java/com/fr/design/data/BasicTableDataTreePane.java @@ -378,12 +378,8 @@ public abstract class BasicTableDataTreePane extends DockingView implements Resp protected boolean isDsNameRepeaded(String name) { allDSNames = DesignTableDataManager.getAllDSNames(tc.getBook()); - for (int i = 0; i < allDSNames.length; i++) { - if (ComparatorUtils.equals(name, allDSNames[i])) { - return true; - } - } - return false; + Set allDSNamesWithoutPermissions = DesignTableDataManager.getAllDSNamesWithoutPermissions(tc.getBook()); + return allDSNamesWithoutPermissions.contains(name); } protected KeyAdapter getTableTreeNodeListener(final UpdateAction editAction, final UpdateAction previewTableDataAction, final UpdateAction removeAction, final TableDataSourceOP op, final TableDataTree dataTree) { diff --git a/designer-base/src/main/java/com/fr/design/data/DesignTableDataManager.java b/designer-base/src/main/java/com/fr/design/data/DesignTableDataManager.java index 35a539a50c..5134e88c8b 100644 --- a/designer-base/src/main/java/com/fr/design/data/DesignTableDataManager.java +++ b/designer-base/src/main/java/com/fr/design/data/DesignTableDataManager.java @@ -48,6 +48,7 @@ import java.text.Collator; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedHashSet; @@ -295,6 +296,27 @@ public abstract class DesignTableDataManager { return list.toArray(new String[0]); } + /** + * 获取所有的数据集名称,无论模板是不是有数据集的权限 + */ + public static Set getAllDSNamesWithoutPermissions(TableDataSource source) { + Set names = new HashSet<>(); + Map resMap = new HashMap<>(); + // 模板数据集 + addTemplateData(resMap, source); + // 存储过程 + addStoreProcedureData(resMap); + for (Map.Entry entry : resMap.entrySet()) { + names.add(entry.getKey()); + } + //服务器数据集 + Map tableDatas = TableDataConfig.getInstance().getTableDatas(); + for (Map.Entry entry : tableDatas.entrySet()) { + names.add(entry.getKey()); + } + return names; + } + /** * 不根据过滤设置,返回当前模板数据集、服务器数据集、存储过程本身,是有顺序的 */ @@ -625,6 +647,8 @@ public abstract class DesignTableDataManager { // 把storeProcedure写成xml文件到out DataCoreXmlUtils.writeXMLStoreProcedure(writer, storeProcedure, null); if (storeProcedure.getDataModelList().size() > 0 && !storeProcedure.isFirstExpand()) { + // 存储过程有些特殊处理 + // 这个就简单直接获取暂存列表吧 return storeProcedure.getDataModelList().toArray(new ProcedureDataModel[0]); } ParameterProvider[] inParameters = DataOperator.getInstance().getStoreProcedureParameters(storeProcedure); @@ -633,11 +657,13 @@ public abstract class DesignTableDataManager { showParaWindow(parameterMap, inParameters); } storeProcedure.setFirstExpand(false); + } else { + ParameterProvider[] parameters = DataOperator.getInstance().getTableDataParameters(tableData); + if (parameters.length > 0) { + showParaWindow(parameterMap, parameters); + } } - // 存储过程有些特殊处理 - // 这个就简单直接获取暂存列表吧 - // TODO 参数处理? if (needLoadingBar) { MultiResultTableDataWrapper.loadingBar.start(); } @@ -657,4 +683,14 @@ public abstract class DesignTableDataManager { public static void setThreadLocal(String value) { threadLocal.set(value); } -} \ No newline at end of file + + /** + * 根据数据集名称判断是否为服务器数据集或服务器存储过程 + * + * @param tableDataName 数据集名称 + * @return + */ + public static boolean isGlobalTableData(String tableDataName) { + return globalDsCache.containsKey(tableDataName); + } +} diff --git a/designer-base/src/main/java/com/fr/design/data/StrategyConfigAttrUtils.java b/designer-base/src/main/java/com/fr/design/data/StrategyConfigAttrUtils.java index e2a75fc11b..a03ccc99dc 100644 --- a/designer-base/src/main/java/com/fr/design/data/StrategyConfigAttrUtils.java +++ b/designer-base/src/main/java/com/fr/design/data/StrategyConfigAttrUtils.java @@ -11,11 +11,11 @@ import com.fr.esd.event.DSMapping; import com.fr.esd.event.DsNameTarget; import com.fr.esd.event.StrategyEventsNotifier; import com.fr.esd.event.xml.XMLSavedHook; -import com.fr.file.FILE; import com.fr.log.FineLoggerFactory; import com.fr.stable.StringUtils; import com.fr.workspace.WorkContext; +import java.nio.file.Paths; import java.util.HashMap; import java.util.HashSet; import java.util.Map; @@ -46,7 +46,9 @@ public class StrategyConfigAttrUtils { } //新建模版此时不存在,不需要注册钩子 - if (attr.getXmlSavedHook() == null && WorkContext.getWorkResource().exist(jTemplate.getPath())) { + //不处理外部路径,保存到设计器才处理 + String path = jTemplate.getPath(); + if (attr.getXmlSavedHook() == null && !Paths.get(path).isAbsolute() && WorkContext.getWorkResource().exist(path)) { attr.setXmlSavedHook(new StrategyConfigsAttrSavedHook(jTemplate.getPath(), attr)); } return attr; diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionListPane.java b/designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionListPane.java index c38c27811f..f836757399 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionListPane.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionListPane.java @@ -21,6 +21,9 @@ import com.fr.event.EventDispatcher; import com.fr.file.ConnectionConfig; import com.fr.file.ConnectionOperator; import com.fr.general.NameObject; +import com.fr.license.database.BaseDataBaseTypePoint; +import com.fr.license.database.DBTypes; +import com.fr.license.exception.DataBaseNotSupportedException; import com.fr.log.FineLoggerFactory; import com.fr.stable.ArrayUtils; import com.fr.stable.Nameable; @@ -29,17 +32,22 @@ import com.fr.stable.core.PropertyChangeAdapter; import com.fr.transaction.Configurations; import com.fr.transaction.WorkerFacade; import com.fr.workspace.WorkContext; +import com.fr.workspace.server.database.DataBaseTypeOperator; +import org.jetbrains.annotations.NotNull; +import javax.swing.SwingWorker; import java.awt.Window; import java.sql.SQLException; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; +import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Set; import java.util.UUID; +import java.util.concurrent.ExecutionException; /** * Connection List Pane. @@ -49,6 +57,7 @@ public class ConnectionListPane extends JListControlPane implements ConnectionSh private boolean isNamePermitted = true; private final HashMap renameMap = new HashMap<>(); private final Map populatedConnectionsSnapshot = new LinkedHashMap<>(); + private static List supportedDatabaseTypes = new ArrayList<>(); public ConnectionListPane() { renameMap.clear(); @@ -62,6 +71,30 @@ public class ConnectionListPane extends JListControlPane implements ConnectionSh rename(selectedName, getEditingName()); } }); + + getSupportedTypes(); + } + + /** + * 获取本地、远程环境lic中未受限制的数据库类型信息 + */ + private static void getSupportedTypes() { + SwingWorker, Void> getSupportedTypesWorker = new SwingWorker, Void>() { + @Override + protected List doInBackground() { + return WorkContext.getCurrent().get(DataBaseTypeOperator.class).getSupportedDatabaseTypes(); + } + + @Override + protected void done() { + try { + supportedDatabaseTypes = get(); + } catch (InterruptedException | ExecutionException e) { + throw new RuntimeException(e); + } + } + }; + getSupportedTypesWorker.execute(); } @Override @@ -114,21 +147,31 @@ public class ConnectionListPane extends JListControlPane implements ConnectionSh /** * 创建菜单项 + *

+ * 方法中获取limitDatabaseType使用了远程rpc调用,可能会比较耗时 * * @return 菜单项 */ public NameableCreator[] createNameableCreators() { - NameableCreator[] creators = new NameableCreator[]{new NameObjectCreator( + NameObjectCreator jdbc = new NameObjectCreator( "JDBC", "/com/fr/design/images/data/source/jdbcTableData.png", JDBCDatabaseConnection.class, DatabaseConnectionPane.JDBC.class - ), new NameObjectCreator( + ); + NameObjectCreator jndi = new NameObjectCreator( "JNDI", "/com/fr/design/images/data/source/jdbcTableData.png", JNDIDatabaseConnection.class, DatabaseConnectionPane.JNDI.class - )}; + ); + NameableCreator[] creators; + if (WorkContext.getCurrent().get(DataBaseTypeOperator.class).limitDatabaseType()) { + // 不支持JNDI,屏蔽接口 + creators = new NameableCreator[]{jdbc}; + } else { + creators = new NameableCreator[]{jdbc, jndi}; + } Set pluginCreators = ExtraDesignClassManager.getInstance().getArray(ConnectionProvider.XML_TAG); for (ConnectionProvider provider : pluginCreators) { NameObjectCreator creator = new NameObjectCreator( @@ -209,7 +252,7 @@ public class ConnectionListPane extends JListControlPane implements ConnectionSh * @return */ private boolean needUpdate0(Connection origin, Connection connection) { - return !connection.equals(origin) || !isEmbedConnection(connection); + return !connection.equals(origin) || !isEmbedConnection(connection); } /** @@ -221,10 +264,56 @@ public class ConnectionListPane extends JListControlPane implements ConnectionSh } }); + this.validateDatabaseType(addedOrUpdatedConnections); this.validateConnections(addedOrUpdatedConnections); this.alterConnections(removedConnNames, addedOrUpdatedConnections); } + /** + * 校验是否支持所有新增和修改数据连接的数据库类型 + */ + public void validateDatabaseType(@NotNull List addedOrUpdatedConnections) { + Set notSupportedConnections = new HashSet<>(); + if (!addedOrUpdatedConnections.isEmpty()) { + for (ConnectionBean bean : addedOrUpdatedConnections) { + Connection connection = bean.getConnection(); + // 仅校验jdbc连接,其他插件数据连接不进行校验 + if (connection instanceof JDBCDatabaseConnection) { + BaseDataBaseTypePoint dataBaseTypePoint = BaseDataBaseTypePoint.getDataBaseTypePoint(connection.getDriver(), connection.feature()); + + if (connectionIsNotSupported(connection, dataBaseTypePoint)) { + notSupportedConnections.addAll(dataBaseTypePoint.getDataBaseType()); + } + } + } + } + + if (!notSupportedConnections.isEmpty()) { + throw new DataBaseNotSupportedException(notSupportedConnections, supportedDatabaseTypes); + } + } + + /** + * 校验当前数据连接是否被限制 + */ + private static boolean connectionIsNotSupported(Connection connection, BaseDataBaseTypePoint dataBaseTypePoint) { + return !validateFRDemo(connection.getDriver(), connection.feature()) && + (dataBaseTypePoint != null && !supportedDatabaseTypes.containsAll(dataBaseTypePoint.getDatabaseType())); + } + + /** + * 校验当前是否为FRDemo,不对其进行限制 + */ + private static boolean validateFRDemo(String driver, String url) { + if (DBTypes.Sqlite.getDriver().equals(driver) && url.contains(DBTypes.Sqlite.getUrlKey())) { + // 产品:对sqlite类型只允许示例连接FRDemo + String databaseName = url.substring(url.lastIndexOf("/") + 1); + return StringUtils.equals("FRDemo.db", databaseName); + } + + return false; + } + private void validateConnections(List addedOrUpdatedConnections) throws Exception { @@ -257,12 +346,21 @@ public class ConnectionListPane extends JListControlPane implements ConnectionSh } private boolean saveByOldWay(List removedConnNames, List addedOrUpdatedConnections) { + final int remaining = ConnectionConfig.getInstance().getRemainingCon(removedConnNames.size(), addedOrUpdatedConnections.size()); try { return Configurations.modify(new WorkerFacade(ConnectionConfig.class) { @Override public void run() { removedConnNames.forEach(n -> ConnectionConfig.getInstance().removeConnection(n)); - addedOrUpdatedConnections.forEach(cb -> ConnectionConfig.getInstance().addConnection(cb.getName(), cb.getConnection())); + int innerRemaining = remaining; + for (ConnectionBean cb : addedOrUpdatedConnections) { + if (innerRemaining > 0) { + ConnectionConfig.getInstance().addConnectionWithoutCheck(cb.getName(), cb.getConnection()); + innerRemaining--; + } else { + break; + } + } } }); } catch (Exception e) { diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionManagerPane.java b/designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionManagerPane.java index 33925dcd36..eadf456e09 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionManagerPane.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionManagerPane.java @@ -4,7 +4,6 @@ import com.fr.design.gui.frpane.LoadingBasicPane; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.file.ConnectionConfig; - import javax.swing.JPanel; import java.awt.BorderLayout; import java.util.HashMap; diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/preview/PreviewTableModel.java b/designer-base/src/main/java/com/fr/design/data/datapane/preview/PreviewTableModel.java index abbe3a7e08..9074a18d66 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/preview/PreviewTableModel.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/preview/PreviewTableModel.java @@ -20,12 +20,20 @@ public class PreviewTableModel extends AbstractTableModel { private static final int LEN_LIMIT = 1000; private static final String THREE_DOT = "..."; + private static final int DEFAULT_MAX_ROW_COUNT = 10000; private DataModel dataModel; private String erroMessage = null; public IntList dateIndexs = new IntList(4); + /** + * 为了兼容子类的空参构造,一般不主动使用 + */ + public PreviewTableModel() { + this(new ErrorResultSet(), DEFAULT_MAX_ROW_COUNT); + } + public PreviewTableModel(int maxRowCount) { // peter:默认必须显示错误的数据源. this(new ErrorResultSet(), maxRowCount); @@ -108,6 +116,19 @@ public class PreviewTableModel extends AbstractTableModel { } } + /** + * 根据列名获取列序号,当返回-1时代表异常,异常会被忽略,不打印日志或给出前台提示 + * @param columnName + * @return + */ + public int getColumnIndexWithExceptionIngore(String columnName) { + try { + return dataModel.getColumnIndex(columnName); + } catch (TableDataException ingore) { + return -1; + } + } + public int getRowCount() { try { return this.dataModel.getRowCount(); diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/preview/PreviewTablePane.java b/designer-base/src/main/java/com/fr/design/data/datapane/preview/PreviewTablePane.java index 5926dcb2df..ffac1388c6 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/preview/PreviewTablePane.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/preview/PreviewTablePane.java @@ -3,17 +3,23 @@ */ package com.fr.design.data.datapane.preview; -import com.fr.base.BaseUtils; import com.fr.base.TableData; +import com.fr.base.svg.IconUtils; import com.fr.data.TableDataSource; +import com.fr.data.desensitize.base.DesensitizationTableData; import com.fr.data.impl.DBTableData; import com.fr.data.impl.EmbeddedTableData; import com.fr.data.impl.NameDataModel; import com.fr.data.operator.DataOperator; import com.fr.design.DesignerEnvManager; import com.fr.design.data.DesignTableDataManager; +import com.fr.design.data.datapane.preview.desensitization.TableDataPreviewDesensitizeManager; +import com.fr.design.data.datapane.preview.desensitization.model.DesensitizedPreviewTableModel; +import com.fr.design.data.datapane.preview.desensitization.view.PreviewTableDesensitizationPane; +import com.fr.design.data.datapane.preview.desensitization.view.setting.TableDataDesensitizationSettingPane; import com.fr.design.dialog.BasicDialog; import com.fr.design.dialog.BasicPane; +import com.fr.design.dialog.DialogActionAdapter; import com.fr.design.dialog.FineJOptionPane; import com.fr.design.file.HistoryTemplateListCache; import com.fr.design.gui.frpane.UITabbedPane; @@ -25,7 +31,9 @@ import com.fr.design.gui.itextfield.UINumberField; import com.fr.design.i18n.Toolkit; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.mainframe.DesignerContext; +import com.fr.design.mainframe.JTemplate; import com.fr.design.ui.util.UIUtil; +import com.fr.esd.query.StrategicTableData; import com.fr.function.TIME; import com.fr.general.FRFont; import com.fr.general.data.DataModel; @@ -39,6 +47,7 @@ import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; +import javax.swing.SwingUtilities; import javax.swing.SwingWorker; import javax.swing.UIManager; import javax.swing.table.DefaultTableCellRenderer; @@ -49,20 +58,20 @@ import java.awt.Color; import java.awt.Component; import java.awt.Font; import java.awt.Graphics; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.sql.Timestamp; import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.Objects; import java.util.concurrent.CancellationException; /** * august: PreviewTablePane一共提供5个共有的静态方法,用来预览。 */ public class PreviewTablePane extends BasicPane { + private TableData tableData; private DataModel dataModel; private UINumberField maxPreviewNumberField; @@ -78,6 +87,54 @@ public class PreviewTablePane extends BasicPane { private static PreviewTablePane THIS; private EmbeddedTableData previewTableData; + private PreviewTableDesensitizationPane desensitizationPane; + + /** + * 用于refreshLabel的鼠标监听 + */ + private final MouseAdapter refreshLabelMouseAdapter = new MouseAdapter() { + boolean mouseEntered = false; + boolean buttonPressed = false; + + @Override + public void mouseEntered(MouseEvent e) { // 当鼠标进入时候调用. + mouseEntered = true; + if (!buttonPressed) { + refreshLabel.setBackground(java.awt.Color.WHITE); + refreshLabel.setOpaque(true); + refreshLabel.setBorder(BorderFactory.createLineBorder(java.awt.Color.GRAY)); + } + } + + @Override + public void mouseExited(MouseEvent e) { + mouseEntered = false; + refreshLabel.setOpaque(false); + refreshLabel.setBorder(BorderFactory.createEmptyBorder()); + } + + @Override + public void mousePressed(MouseEvent e) { + buttonPressed = true; + refreshLabel.setBackground(java.awt.Color.lightGray); + } + + @Override + public void mouseReleased(MouseEvent e) { + buttonPressed = false; + if (mouseEntered) { + refreshLabel.setBackground(java.awt.Color.WHITE); + try { + populate(tableData); + if (dataModel != null) { + setRowsLimitTableModel(); + } + } catch (Exception ignore) { + } + } + } + }; + public static final PreviewTablePane getInstance() { if (THIS == null) { THIS = new PreviewTablePane(); @@ -87,91 +144,181 @@ public class PreviewTablePane extends BasicPane { private PreviewTablePane() { this.setLayout(FRGUIPaneFactory.createBorderLayout()); + // northPane + this.add(initNorthPane(), BorderLayout.NORTH); + // centerPane + this.add(initCenterPane(), BorderLayout.CENTER); + // dialog + initDialog(); + // progressBar + initProgressBar(); + } - // elalke:预览行数 - JPanel previewNumberPanel = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); - this.add(previewNumberPanel, BorderLayout.NORTH); + /** + * 初始化northPane + * + * @return + */ + private JComponent initNorthPane() { + JPanel northPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); + // 预览行数面板 + northPane.add(initPreviewNumberPane(), BorderLayout.CENTER); + // 脱敏预览设置面板 + northPane.add(initDesensitizationPane(), BorderLayout.EAST); + return northPane; + } + /** + * 初始化预览行数面板 + * + * @return + */ + private JComponent initPreviewNumberPane() { + JPanel previewNumberPanel = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); + // 当前行数 JPanel currentPreviewPanel = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); - previewNumberPanel.add(currentPreviewPanel); currentPreviewPanel.add(new UILabel(Toolkit.i18nText("Fine-Design_Basic_Current_Preview_Rows") + ":")); - currentRowsField = new UINumberField(); currentPreviewPanel.add(currentRowsField); currentRowsField.setEditable(false); currentRowsField.setColumns(4); currentRowsField.setInteger(true); - + // 最大行数 JPanel maxPanel = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); - previewNumberPanel.add(maxPanel); maxPanel.add(new UILabel(Toolkit.i18nText("Fine-Design_Basic_Datasource_Maximum_Number_of_Preview_Rows") + ":")); - maxPreviewNumberField = new UINumberField(); maxPanel.add(maxPreviewNumberField); maxPreviewNumberField.setColumns(4); maxPreviewNumberField.setInteger(true); - - DesignerEnvManager designerEnvManager = DesignerEnvManager.getEnvManager(); - maxPreviewNumberField.setValue(designerEnvManager.getMaxNumberOrPreviewRow()); - - maxPreviewNumberField.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent evt) { - DesignerEnvManager designerEnvManager = DesignerEnvManager.getEnvManager(); - designerEnvManager.setMaxNumberOrPreviewRow((int) ((UINumberField) evt.getSource()).getValue()); - } + maxPreviewNumberField.setValue(DesignerEnvManager.getEnvManager().getMaxNumberOrPreviewRow()); + maxPreviewNumberField.addActionListener(event -> { + DesignerEnvManager designerEnvManager = DesignerEnvManager.getEnvManager(); + designerEnvManager.setMaxNumberOrPreviewRow((int) ((UINumberField) event.getSource()).getValue()); }); + // 刷新按钮 + initRefreshLabel(); - Icon refreshImage = BaseUtils.readIcon("/com/fr/design/images/control/refresh.png"); - refreshLabel = new UILabel(refreshImage); + previewNumberPanel.add(currentPreviewPanel); + previewNumberPanel.add(maxPanel); previewNumberPanel.add(refreshLabel); - refreshLabel.addMouseListener(new MouseAdapter() { - boolean mouseEntered = false; - boolean buttonPressed = false; - - public void mouseEntered(MouseEvent e) { // 当鼠标进入时候调用. - mouseEntered = true; - if (!buttonPressed) { - refreshLabel.setBackground(java.awt.Color.WHITE); - refreshLabel.setOpaque(true); - refreshLabel.setBorder(BorderFactory.createLineBorder(java.awt.Color.GRAY)); + return previewNumberPanel; + } + + private void initRefreshLabel() { + Icon refreshImage = IconUtils.readIcon("/com/fr/design/images/control/refresh"); + refreshLabel = new UILabel(refreshImage); + refreshLabel.addMouseListener(refreshLabelMouseAdapter); + } + + /** + * 初始化脱敏设置面板 + * + * @return + */ + private JComponent initDesensitizationPane() { + desensitizationPane = new PreviewTableDesensitizationPane(this); + return desensitizationPane; + } + + /** + * 点击脱敏配置后的操作 + */ + public void clickDesensitizationLabel() { + // 埋点记录 + recordDesensitization(); + // 判断数据集类型 + if (isGlobalTableData()) { + // 服务器数据集不允许在设计器端修改脱敏配置 + FineJOptionPane.showMessageDialog( + this, + Toolkit.i18nText("Fine-Design_Report_Cannot_Modify_Desensitization_Config_Of_ServerTableData"), + Toolkit.i18nText("Fine-Design_Basic_Alert"), + FineJOptionPane.WARNING_MESSAGE); + return; + } + TableDataDesensitizationSettingPane settingPane = new TableDataDesensitizationSettingPane((DesensitizationTableData) tableData); + settingPane.populateBean((DesensitizationTableData) tableData); + BasicDialog dialog = settingPane.showWindowWithCustomSize(SwingUtilities.getWindowAncestor(PreviewTablePane.this), new DialogActionAdapter() { + @Override + public void doOk() { + // 保存脱敏规则配置 + settingPane.updateBean(); + // 改变模板保存状态 + JTemplate editingTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); + if (Objects.nonNull(editingTemplate)) { + editingTemplate.fireTargetModified(true); } } - public void mouseExited(MouseEvent e) { - mouseEntered = false; - refreshLabel.setOpaque(false); - refreshLabel.setBorder(BorderFactory.createEmptyBorder()); - } + @Override + public void doCancel() { - public void mousePressed(MouseEvent e) { - buttonPressed = true; - refreshLabel.setBackground(java.awt.Color.lightGray); } + }, BasicDialog.DEFAULT); + dialog.setVisible(true); + // 关闭预览页面 + PreviewTablePane.this.dialog.setVisible(false); + } - public void mouseReleased(MouseEvent e) { - buttonPressed = false; - if (mouseEntered) { - refreshLabel.setBackground(java.awt.Color.WHITE); - try { - populate(tableData); - if (dataModel != null) { - setRowsLimitTableModel(); - } - } catch (Exception e1) { - } - } - } - }); + /** + * 触发数据脱敏埋点记录 + * + * @return 数据脱敏字段数量 + */ + private int recordDesensitization() { + return getCurrentTableDataDesensitizationCount(); + } + + /** + * 当前tableData是否为服务器数据集或服务器存储过程 + * + * @return + */ + public boolean isGlobalTableData() { + return this.tableData instanceof StrategicTableData && + DesignTableDataManager.isGlobalTableData(((StrategicTableData) this.tableData).getDsName()); + } + + /** + * 根据TableData设置脱敏设置的个数 + */ + private void setDesensitizationCountByTableData() { + desensitizationPane.setDesensitizationCount(isDesensitizeOpened(), getCurrentTableDataDesensitizationCount()); + desensitizationPane.dealWithTableDataType(isGlobalTableData()); + } + + /** + * 获取当前数据集中设置脱敏规则的个数 + * + * @return + */ + private int getCurrentTableDataDesensitizationCount() { + return this.tableData instanceof DesensitizationTableData ? + ((DesensitizationTableData) this.tableData).getDesensitizationConfig().getDesensitizationItems().size() : + 0; + } + /** + * 初始化centerPane + * + * @return + */ + private JComponent initCenterPane() { preveiwTable = new CopyableJTable(new TableSorter()); preveiwTable.setRowSelectionAllowed(false); preveiwTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); + return new JScrollPane(preveiwTable); + } - this.add(new JScrollPane(preveiwTable), BorderLayout.CENTER); + private void initDialog() { if (this.dialog == null) { this.dialog = this.showWindow(new JFrame()); } + } + + private void initProgressBar() { progressBar = new AutoProgressBar(this, Toolkit.i18nText("Fine-Design_Basic_Loading_Data"), "", 0, 100) { + @Override public void doMonitorCanceled() { if (getWorker() != null) { getWorker().cancel(true); @@ -182,7 +329,7 @@ public class PreviewTablePane extends BasicPane { } public AutoProgressBar getProgressBar() { - return this.progressBar; + return PreviewTablePane.progressBar; } @Override @@ -222,13 +369,19 @@ public class PreviewTablePane extends BasicPane { return this.worker; } - // elake:为预览表的columnIndex列着c色. + /** + * 为预览表的columnIndex列着色. + * + * @param columnIndex 列索引值 + * @param c 颜色 + */ private void setPreviewTableColumnColor(final int columnIndex, final Color c) { addLoadedListener(new LoadedEventListener() { @Override public void fireLoaded() { TableColumn column = preveiwTable.getColumnModel().getColumn(columnIndex); DefaultTableCellRenderer cellRenderer = new DefaultTableCellRenderer() { + @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { JComponent comp = (JComponent) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); comp.setBackground(c); @@ -249,7 +402,7 @@ public class PreviewTablePane extends BasicPane { getInstance().preveiwTable = new SortableJTable(new TableSorter()); getInstance().preveiwTable.setRowSelectionAllowed(false); getInstance().preveiwTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); - getInstance().progressBar.close(); + PreviewTablePane.progressBar.close(); getInstance().repaint(); } @@ -331,6 +484,7 @@ public class PreviewTablePane extends BasicPane { private void previewTableDataSQL() throws Exception { connectionBar = new AutoProgressBar(this, Toolkit.i18nText("Fine-Design_Basic_Utils_Now_Create_Connection"), "", 0, 100) { + @Override public void doMonitorCanceled() { getWorker().cancel(true); getDialog().setVisible(false); @@ -345,42 +499,49 @@ public class PreviewTablePane extends BasicPane { private void setPreviewTableColumnValue(final Graphics g) { for (int i = 0; i < preveiwTable.getColumnModel().getColumnCount(); i++) { TableColumn column = preveiwTable.getColumnModel().getColumn(i); - DefaultTableCellRenderer cellRenderer = new DefaultTableCellRenderer() { - public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { - JComponent comp = (JComponent) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); - Font f = table.getFont(); - - //默认在系统不支持 无法显示时 如自造的字 ,字体设置为空. - Font defaultShowFont = FRFont.getInstance("", f.getStyle(), f.getSize()); - if (value instanceof String) { - String str = (String) value; - for (int j = 0; j < str.length(); j++) { - char c = str.charAt(j); - if (!f.canDisplay(c)) { - table.setFont(defaultShowFont); - } + DefaultTableCellRenderer cellRenderer = getDefaultTableCellRenderer(); + column.setCellRenderer(cellRenderer); + } + } + + /** + * 默认表格格子渲染器 + * + * @return + */ + private DefaultTableCellRenderer getDefaultTableCellRenderer() { + return new DefaultTableCellRenderer() { + @Override + public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { + JComponent comp = (JComponent) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); + Font f = table.getFont(); + + //默认在系统不支持 无法显示时 如自造的字 ,字体设置为空. + Font defaultShowFont = FRFont.getInstance("", f.getStyle(), f.getSize()); + if (value instanceof String) { + String str = (String) value; + for (int j = 0; j < str.length(); j++) { + char c = str.charAt(j); + if (!f.canDisplay(c)) { + table.setFont(defaultShowFont); } } - return comp; } - }; - column.setCellRenderer(cellRenderer); - } + return comp; + } + }; } private void setWorker() { - worker = new SwingWorker() { - protected PreviewTableModel doInBackground() throws Exception { + worker = new SwingWorker() { + + @Override + protected TableModel doInBackground() throws Exception { connectionBar.start(); try { - if (tableData instanceof DBTableData) { - boolean status = DataOperator.getInstance().testConnection(((DBTableData) tableData).getDatabase()); - if (!status) { - throw new Exception(Toolkit.i18nText("Fine-Design_Basic_Database_Connection_Failed")); - } - } + testDBTableDataConnection(tableData); } finally { // 将close操作放到EDT线程中 UIUtil.invokeLaterIfNeeded(() -> connectionBar.close()); @@ -390,22 +551,20 @@ public class PreviewTablePane extends BasicPane { // parameterInputDialog // update之后的parameters,转成一个parameterMap,用于预览TableData PreviewTableModel previewModel = new PreviewTableModel(previewTableData.createDataModel(null), (int) maxPreviewNumberField.getValue()); - for (int i = 0; i < previewTableData.getColumnCount(); i++) { - Class cls = previewTableData.getColumnClass(i); - if (cls == Date.class || cls == TIME.class || cls == Timestamp.class) { - previewModel.dateIndexs.add(i); - } + if (TableDataPreviewDesensitizeManager.getInstance().needDesensitize(tableData)) { + // 数据集预览脱敏 + previewModel = TableDataPreviewDesensitizeManager.getInstance().desensitizeTableModel(tableData, previewModel); } + dealWithPreviewTableModelColumnClass(previewModel, previewTableData); return previewModel; } + @Override public void done() { try { - PreviewTableModel model = get(); - setModel(model); - setCurrentRows(model.getRowCount()); + TableModel model = get(); + setPreviewTableModel(model); setPreviewTableColumnValue(getParent().getGraphics()); - fireLoadedListener(); } catch (Exception e) { if (!(e instanceof CancellationException)) { FineLoggerFactory.getLogger().error(e.getMessage(), e); @@ -420,6 +579,36 @@ public class PreviewTablePane extends BasicPane { }; } + /** + * 检查DBTableData连接 + * + * @param tableData + * @throws Exception + */ + private void testDBTableDataConnection(TableData tableData) throws Exception { + if (tableData instanceof DBTableData) { + boolean status = DataOperator.getInstance().testConnection(((DBTableData) tableData).getDatabase()); + if (!status) { + throw new Exception(Toolkit.i18nText("Fine-Design_Basic_Database_Connection_Failed")); + } + } + } + + /** + * 处理预览Model的列类型 + * + * @param previewModel + * @param previewTableData + */ + private void dealWithPreviewTableModelColumnClass(PreviewTableModel previewModel, EmbeddedTableData previewTableData) { + for (int i = 0; i < previewTableData.getColumnCount(); i++) { + Class cls = previewTableData.getColumnClass(i); + if (cls == Date.class || cls == TIME.class || cls == Timestamp.class) { + previewModel.dateIndexs.add(i); + } + } + } + /** * 直接预览存储过程的一个返回数据集,没有实际值和显示值 * @@ -450,7 +639,7 @@ public class PreviewTablePane extends BasicPane { /** * 直接预览数据集的结果集 * - * @param dataModel 结果集 + * @param dataModel 结果集 * @param keyIndex * @param valueIndex */ @@ -528,9 +717,62 @@ public class PreviewTablePane extends BasicPane { } catch (Exception e) { previewModel = new PreviewTableModel((int) maxPreviewNumberField.getValue()); } - setModel(previewModel); - setCurrentRows(previewModel.getRowCount()); + setPreviewTableModel(previewModel); + + } + + /** + * 切换TableModel的展示状态 + */ + public void togglePreviewTableModelDesensitizeStatus() { + if (!isDesensitizeOpened()) { + // 未启用数据脱敏时,不需要切换 + return; + } + TableSorter tableSorter = (TableSorter) preveiwTable.getModel(); + TableModel originTableModel = tableSorter.getTableModel(); + if (originTableModel instanceof DesensitizedPreviewTableModel) { + ((DesensitizedPreviewTableModel) originTableModel).toggleNeedDesensite(); + } + } + + /** + * 刷新一下预览页面,用于切换脱敏和非脱敏时的显示 + */ + public void refreshTable() { + TableModel originTableModel = getCurrentTableModel(); + setPreviewTableModel(originTableModel); + } + + /** + * 获取当前的TableModel,已经除掉了TableSorter的包装 + * + * @return + */ + private TableModel getCurrentTableModel() { + TableSorter tableSorter = (TableSorter) preveiwTable.getModel(); + return tableSorter.getTableModel(); + } + + /** + * 设置预览TableModel + * + * @param previewTableModel + */ + private void setPreviewTableModel(TableModel previewTableModel) { + setDesensitizationCountByTableData(); + setModel(previewTableModel); + setCurrentRows(previewTableModel.getRowCount()); fireLoadedListener(); + } + /** + * 数据脱敏是否启用 + * + * @return + */ + private boolean isDesensitizeOpened() { + return tableData instanceof DesensitizationTableData && + ((DesensitizationTableData) tableData).getDesensitizationConfig().isDesensitizeOpened(); } } diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/TableDataPreviewDesensitizeManager.java b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/TableDataPreviewDesensitizeManager.java new file mode 100644 index 0000000000..abd5a4d166 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/TableDataPreviewDesensitizeManager.java @@ -0,0 +1,136 @@ +package com.fr.design.data.datapane.preview.desensitization; + + +import com.fr.base.TableData; +import com.fr.data.TableDataSource; +import com.fr.data.desensitize.TableDataDesensitizeManager; +import com.fr.data.desensitize.base.DesensitizationTableData; +import com.fr.data.desensitize.base.TableDataDesensitizationItem; +import com.fr.data.desensitize.manage.DesensitizationManager; +import com.fr.data.desensitize.util.DesentizationUtils; +import com.fr.decision.webservice.bean.user.DepartmentPostBean; +import com.fr.decision.webservice.bean.user.RoleBean; +import com.fr.decision.webservice.utils.DecisionServiceConstants; +import com.fr.decision.webservice.v10.user.CustomRoleService; +import com.fr.decision.webservice.v10.user.PositionService; +import com.fr.design.data.DesignTableDataManager; +import com.fr.design.data.datapane.preview.PreviewTableModel; +import com.fr.design.data.datapane.preview.desensitization.model.DesensitizedPreviewTableModel; +import com.fr.esd.query.StrategicTableData; +import com.fr.general.ComparatorUtils; +import com.fr.log.FineLoggerFactory; +import com.fr.stable.StringUtils; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + + +/** + * 管理所有数据集预览过程中的脱敏计算 + * + * @author Yvan + * @version 11.0 + * Created by Yvan on 2022/9/14 + */ +public class TableDataPreviewDesensitizeManager implements DesensitizationManager { + + private static final String CONNECTOR = "_"; + + private TableDataPreviewDesensitizeManager() { + } + + private static class Holder { + private static final TableDataPreviewDesensitizeManager INSTANCE = new TableDataPreviewDesensitizeManager(); + } + + /** + * 获取TableDataPreviewDesensitizeManager单例 + * + * @return + */ + public static TableDataPreviewDesensitizeManager getInstance() { + return TableDataPreviewDesensitizeManager.Holder.INSTANCE; + } + + /** + * 判断数据集预览时是否需要脱敏,这里不需要判断roleIds,因为默认有权限编辑的人一定有权限看脱敏前后字段值 + * 只需要保证此数据集存在脱敏配置就行 + * + * @param tableData + * @return + */ + public boolean needDesensitize(TableData tableData) { + return tableData instanceof DesensitizationTableData && + DesentizationUtils.isCollectionNotEmpty(((DesensitizationTableData) tableData).getDesensitizationConfig().getDesensitizationItems()); + } + + /** + * 数据集预览脱敏,使用DesensitizedPreviewTableModel对当前的预览TableModel做包装 + * + * @param model + * @return + */ + public PreviewTableModel desensitizeTableModel(TableData tableData, PreviewTableModel model) { + + Map desensitizationItemMap = new LinkedHashMap<>(); + // 获取此数据集的所有脱敏信息 + Collection desensitizationItems = ((DesensitizationTableData) tableData).getDesensitizationConfig().getDesensitizationItems(); + if (DesentizationUtils.isCollectionNotEmpty(desensitizationItems)) { + // 更新规则 + desensitizationItems = TableDataDesensitizeManager.getInstance().dealWithlatestRules(desensitizationItems); + // 对脱敏配置项集合做过滤和排序处理 + List items = desensitizationItems.stream() + .filter(item -> isAvaliableItem4Preview(item, model)) + .sorted(Comparator.comparingInt(item -> matchColumnIndex(item, model))) + .collect(Collectors.toList()); + // 然后转换成Map + for (int i = 0; i < items.size(); i++) { + desensitizationItemMap.put(i, items.get(i)); + } + } + // 包装TableModel + return new DesensitizedPreviewTableModel(model, desensitizationItemMap); + } + + /** + * 判断是否为有效的用于预览脱敏效果的DesensitizationItem + * + * @param item 脱敏配置项 + * @param model 数据集预览数据 + * @return + */ + private boolean isAvaliableItem4Preview(TableDataDesensitizationItem item, PreviewTableModel model) { + return item.getRule().isEnable() && + matchColumnIndex(item, model) >= 0; + } + + /** + * 通过TableData获取其列名,理论上一定存在缓存值 + * + * @param tableData + * @return + */ + public List getColumnNamesByTableData(TableData tableData) { + TableDataSource editingTableDataSource = DesignTableDataManager.getEditingTableDataSource(); + if (editingTableDataSource != null && tableData instanceof StrategicTableData) { + return Arrays.asList(DesignTableDataManager.getSelectedColumnNames(editingTableDataSource, ((StrategicTableData) tableData).getDsName())); + } + return Collections.EMPTY_LIST; + } + + /** + * 根据列名,从PreviewTableModel中匹配列序号,如果返回-1代表未匹配到 + * @param desensitizationItem + * @param previewModel + * @return + */ + public int matchColumnIndex(TableDataDesensitizationItem desensitizationItem, PreviewTableModel previewModel) { + return previewModel.getColumnIndexWithExceptionIngore(desensitizationItem.getColumnName()); + } +} diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/model/DesensitizedPreviewTableModel.java b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/model/DesensitizedPreviewTableModel.java new file mode 100644 index 0000000000..d8908fd14d --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/model/DesensitizedPreviewTableModel.java @@ -0,0 +1,114 @@ +package com.fr.design.data.datapane.preview.desensitization.model; + + +import com.fr.data.desensitize.base.TableDataDesensitizationItem; +import com.fr.data.desensitize.calculate.DesensitizationCalculator; +import com.fr.data.desensitize.rule.base.DesensitizationRule; +import com.fr.design.data.datapane.preview.PreviewTableModel; +import com.fr.design.data.datapane.preview.desensitization.TableDataPreviewDesensitizeManager; + +import java.util.Map; +import java.util.Objects; + +/** + * 数据集预览TableModel的脱敏实现 + * + * @author Yvan + * @version 11.0 + * Created by Yvan on 2022/9/14 + */ +public class DesensitizedPreviewTableModel extends PreviewTableModel { + + /** + * 原始数据Model + */ + private PreviewTableModel previewTableModel; + + /** + * 脱敏后新组装的TableModel中,列序号 - 脱敏信息 对应的Map + */ + private Map desensitizationItemMap; + + private boolean needDesensitize = false; + + public DesensitizedPreviewTableModel(PreviewTableModel previewTableModel, Map desensitizationItemMap) { + this.previewTableModel = previewTableModel; + this.desensitizationItemMap = desensitizationItemMap; + } + + @Override + public String getColumnName(int column) { + return needDesensitize ? + desensitizationItemMap.get(column).getColumnName() : + previewTableModel.getColumnName(column); + } + + @Override + public int getRowCount() { + return previewTableModel.getRowCount(); + } + + @Override + public int getColumnCount() { + return needDesensitize ? + getDesensitizeColumnsCount() : + previewTableModel.getColumnCount(); + } + + @Override + public Object getValueAt(int rowIndex, int columnIndex) { + return needDesensitize && Objects.nonNull(desensitizationItemMap.get(columnIndex)) ? + getDesensitizedValue(rowIndex, columnIndex) : + previewTableModel.getValueAt(rowIndex, columnIndex); + } + + /** + * 返回脱敏后的数据值 + * + * @param rowIndex + * @param columnIndex + * @return + */ + private Object getDesensitizedValue(int rowIndex, int columnIndex) { + // 先通过columnIndex找到对应原TableModel的列序号 + int originColumnIndex = TableDataPreviewDesensitizeManager.getInstance().matchColumnIndex(desensitizationItemMap.get(columnIndex), previewTableModel); + // 获取原值 + Object value = previewTableModel.getValueAt(rowIndex, originColumnIndex); + // 判空 + if (Objects.isNull(value)) { + return value; + } + // 脱敏 + String strValue = String.valueOf(value); + value = desensitizeValue(strValue, columnIndex); + return value; + } + + /** + * 计算脱敏后的value,此时columnIndex对应的脱敏信息一定不为空 + * + * @param strValue + * @param columnIndex + * @return + */ + private String desensitizeValue(String strValue, int columnIndex) { + DesensitizationRule rule = desensitizationItemMap.get(columnIndex).getRule(); + return DesensitizationCalculator.getInstance().desensitize(strValue, rule); + } + + /** + * 获取当前有效的脱敏字段个数 + * + * @return + */ + public int getDesensitizeColumnsCount() { + return desensitizationItemMap.size(); + } + + /** + * 切换脱敏状态 + */ + public void toggleNeedDesensite() { + this.needDesensitize = !needDesensitize; + } +} diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/PreviewTableDesensitizationPane.java b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/PreviewTableDesensitizationPane.java new file mode 100644 index 0000000000..01c92e333f --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/PreviewTableDesensitizationPane.java @@ -0,0 +1,133 @@ +package com.fr.design.data.datapane.preview.desensitization.view; + +import com.fr.base.svg.IconUtils; +import com.fr.design.constants.UIConstants; +import com.fr.design.data.datapane.preview.PreviewTablePane; +import com.fr.design.gui.ibutton.UIToggleButton; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.gui.itoolbar.UIToolbar; +import com.fr.design.i18n.Toolkit; +import com.fr.design.menu.SeparatorDef; +import com.fr.design.menu.ToolBarDef; + +import javax.swing.Icon; +import javax.swing.JPanel; +import java.awt.Component; +import java.awt.FlowLayout; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; + +/** + * 数据集预览-脱敏配置面板,主要展示当前脱敏开启状态、当前脱敏设定数量等 + * + * @author Yvan + * @version 11.0 + * Created by Yvan on 2022/11/14 + */ +public class PreviewTableDesensitizationPane extends JPanel { + + private static final String DATA_DESENSITIZATION_CONFIG = Toolkit.i18nText("Fine-Design_Report_Desensitization_Config"); + private static final String LEFT_BRACKET = "("; + private static final String RIGHT_BRACKET = ")"; + private static final String COUNT = Toolkit.i18nText("Fine-Design_Report_Desensitization_Count"); + + /** + * 预览面板 + */ + private PreviewTablePane previewTablePane; + + /** + * "数据脱敏设置"-标签 + */ + private UILabel desensitizationLabel; + + /** + * 脱敏效果预览按钮 + */ + private UIToggleButton previewToggle; + + + public PreviewTableDesensitizationPane(PreviewTablePane previewTablePane) { + this.previewTablePane = previewTablePane; + initComponents(); + } + + /** + * 初始化面板 + */ + private void initComponents() { + this.setLayout(new FlowLayout(FlowLayout.LEFT)); + this.add(initDesensitizationLabel()); + this.add(initToolBar()); + this.add(initPreviewButton()); + } + + /** + * 初始化Label + * + * @return + */ + private Component initDesensitizationLabel() { + // 初始化Label + desensitizationLabel = new UILabel(DATA_DESENSITIZATION_CONFIG); + desensitizationLabel.setForeground(UIConstants.NORMAL_BLUE); + desensitizationLabel.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + previewTablePane.clickDesensitizationLabel(); + } + }); + return desensitizationLabel; + } + + /** + * 初始化分隔符 + * + * @return + */ + private UIToolbar initToolBar() { + ToolBarDef toolbarDef = new ToolBarDef(); + toolbarDef.addShortCut(SeparatorDef.DEFAULT); + UIToolbar toolBar = ToolBarDef.createJToolBar(); + toolBar.setBorderPainted(false); + toolbarDef.updateToolBar(toolBar); + return toolBar; + } + + /** + * 初始化脱敏效果预览按钮 + * + * @return + */ + private UIToggleButton initPreviewButton() { + previewToggle = new UIToggleButton(new Icon[]{IconUtils.readIcon("/com/fr/design/images/m_file/preview"), IconUtils.readIcon("/com/fr/design/images/m_file/preview")}, true); + previewToggle.setToolTipText(Toolkit.i18nText("Fine-Design_Report_Desensitization_Preview")); + previewToggle.setSelected(false); + previewToggle.addActionListener(e -> { + // 切换TableModel的脱敏状态 + previewTablePane.togglePreviewTableModelDesensitizeStatus(); + // 刷新预览页面,展示 + previewTablePane.refreshTable(); + }); + return previewToggle; + } + + /** + * 设置Label的值,主要是需要动态修改配置的脱敏规则的数量 + * + * @param desensitizeOpen + * @param count + */ + public void setDesensitizationCount(boolean desensitizeOpen, int count) { + desensitizationLabel.setText(desensitizeOpen ? + DATA_DESENSITIZATION_CONFIG + LEFT_BRACKET + count + RIGHT_BRACKET + COUNT : + DATA_DESENSITIZATION_CONFIG); + } + + /** + * 服务器数据集时,Label需要置灰 + */ + public void dealWithTableDataType(boolean globalTableData) { + desensitizationLabel.setForeground(globalTableData ? UIConstants.DISABLED_ICON_COLOR : UIConstants.NORMAL_BLUE); + } +} diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/common/ChooseMark.java b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/common/ChooseMark.java new file mode 100644 index 0000000000..099e9a960a --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/common/ChooseMark.java @@ -0,0 +1,42 @@ +package com.fr.design.data.datapane.preview.desensitization.view.common; + +import com.fr.design.gui.ibutton.UIRadioButton; + +import javax.swing.AbstractCellEditor; +import javax.swing.JTable; +import javax.swing.table.TableCellEditor; +import javax.swing.table.TableCellRenderer; +import java.awt.Component; + +/** + * 标记选中的CellEditor + * + * @author Yvan + * @version 11.0 + * Created by Yvan on 2022/12/20 + */ +public class ChooseMark extends AbstractCellEditor implements TableCellEditor, TableCellRenderer { + + private final UIRadioButton selectedButton; + + public ChooseMark() { + this.selectedButton = new UIRadioButton(); + } + + @Override + public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { + selectedButton.setSelected(isSelected); + return selectedButton; + } + + @Override + public Object getCellEditorValue() { + return selectedButton.isSelected(); + } + + @Override + public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { + selectedButton.setSelected(isSelected); + return selectedButton; + } +} diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/common/DesensitizationOpenPane.java b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/common/DesensitizationOpenPane.java new file mode 100644 index 0000000000..949069aaa8 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/common/DesensitizationOpenPane.java @@ -0,0 +1,94 @@ +package com.fr.design.data.datapane.preview.desensitization.view.common; + +import com.fr.base.svg.IconUtils; +import com.fr.design.border.UITitledBorder; +import com.fr.design.constants.UIConstants; +import com.fr.design.gui.icheckbox.UICheckBox; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.i18n.Toolkit; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.layout.VerticalFlowLayout; +import com.fr.log.FineLoggerFactory; + +import javax.swing.JPanel; +import java.awt.BorderLayout; +import java.awt.Desktop; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.net.URL; + +/** + * 启用数据脱敏的面板 + * + * @author Yvan + * @version 11.0 + * Created by Yvan on 2022/10/12 + */ +public class DesensitizationOpenPane extends JPanel { + + /** + * 数据脱敏启用框 + */ + private UICheckBox desensitizeOpenCheckBox; + + /** + * 跳转帮助文档Label + */ + private UILabel hyperlinkLabel; + + /** + * 启用提示Label + */ + private UILabel tipsLabel; + + + public DesensitizationOpenPane() { + VerticalFlowLayout layout = new VerticalFlowLayout(VerticalFlowLayout.TOP); + layout.setAlignLeft(true); + this.setLayout(layout); + this.setBorder(UITitledBorder.createBorderWithTitle(Toolkit.i18nText("Fine-Design_Report_Desensitization_Config"))); + + JPanel panel = FRGUIPaneFactory.createLeftFlowZeroGapBorderPane(); + // 启用数据脱敏的勾选框 + desensitizeOpenCheckBox = new UICheckBox(Toolkit.i18nText("Fine-Design_Report_Desensitization_Opened")); + // 跳转帮助文档Label + hyperlinkLabel = new UILabel(IconUtils.readIcon("/com/fr/design/standard/tip/tips")); + hyperlinkLabel.setToolTipText(Toolkit.i18nText("Fine-Design_Report_Desensitization_Open_Tips")); + hyperlinkLabel.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent event) { + try { + URL url = new URL(Toolkit.i18nText("Fine-Design_Report_Desensitization_Help_Document_Url")); + Desktop.getDesktop().browse(url.toURI()); + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e, "open browse of table data desensitization help document failed for {}", e.getMessage()); + } + } + }); + panel.add(desensitizeOpenCheckBox); + panel.add(hyperlinkLabel); + + // 提示Label + tipsLabel = new UILabel(Toolkit.i18nText("Fine-Design_Report_Desensitization_Opened_Tooltips")); + tipsLabel.setForeground(UIConstants.CHECK_BOX_TIP_FONT_COLOR); + + this.add(panel); + this.add(tipsLabel); + } + + /** + * 数据脱敏启用状态 + * @return + */ + public boolean isDesensitizationOpened() { + return desensitizeOpenCheckBox.isSelected(); + } + + /** + * 设置数据脱敏启用状态 + * @param opened + */ + public void setDesensitizationOpened(boolean opened) { + desensitizeOpenCheckBox.setSelected(opened); + } +} diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/rule/DesensitizationRuleChoosePane.java b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/rule/DesensitizationRuleChoosePane.java new file mode 100644 index 0000000000..11e30a2e9f --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/rule/DesensitizationRuleChoosePane.java @@ -0,0 +1,364 @@ +package com.fr.design.data.datapane.preview.desensitization.view.rule; + +import com.fr.base.svg.IconUtils; +import com.fr.data.desensitize.rule.DesensitizationRuleManager; +import com.fr.data.desensitize.rule.base.DesensitizationRule; +import com.fr.data.desensitize.rule.base.DesensitizationRuleSource; +import com.fr.data.desensitize.rule.base.DesensitizationRuleStatus; +import com.fr.design.data.datapane.preview.desensitization.view.common.ChooseMark; +import com.fr.design.dialog.BasicDialog; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.gui.itableeditorpane.UITableEditAction; +import com.fr.design.gui.itableeditorpane.UITableEditorPane; +import com.fr.design.gui.itableeditorpane.UITableModelAdapter; +import com.fr.design.i18n.Toolkit; +import com.fr.stable.StringUtils; +import com.fr.stable.collections.CollectionUtils; + +import javax.swing.AbstractCellEditor; +import javax.swing.JPanel; +import javax.swing.JTable; +import javax.swing.SwingUtilities; +import javax.swing.table.TableCellEditor; +import javax.swing.table.TableCellRenderer; +import java.awt.CardLayout; +import java.awt.Color; +import java.awt.Component; +import java.awt.event.ActionEvent; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + +/** + * 脱敏规则选择页面 + * + * @author Yvan + * @version 11.0 + * Created by Yvan on 2022/9/26 + */ +public class DesensitizationRuleChoosePane extends JPanel { + + private CardLayout cardLayout; + + private UITableEditorPane serverRuleEditPane; + + private UITableEditorPane customRuleEditPane; + + private DesensitizationRuleSource currentRuleSource; + + private Map> latestRules; + + public DesensitizationRuleChoosePane(Map> latestRules) { + this.latestRules = latestRules; + this.cardLayout = new CardLayout(); + this.setLayout(cardLayout); + serverRuleEditPane = new UITableEditorPane<>(new DesensitizationRuleChooseTableModel(this, true)); + customRuleEditPane = new UITableEditorPane<>(new DesensitizationRuleChooseTableModel(this, false)); + serverRuleEditPane.setHeaderResizing(false); + customRuleEditPane.setHeaderResizing(false); + populateDesensitizationRules(); + this.add(serverRuleEditPane, DesensitizationRuleSource.SERVER.name()); + this.add(customRuleEditPane, DesensitizationRuleSource.CUSTOM.name()); + // 默认显示平台规则 + switchPaneByRuleSource(DesensitizationRuleSource.SERVER); + } + + /** + * 通过脱敏规则来源,切换显示不同的脱敏规则Table面板 + * + * @param ruleSource + */ + public void switchPaneByRuleSource(DesensitizationRuleSource ruleSource) { + this.currentRuleSource = ruleSource; + this.cardLayout.show(this, ruleSource.name()); + } + + /** + * 展示当前规则 + */ + private void populateDesensitizationRules() { + serverRuleEditPane.populate(latestRules.get(DesensitizationRuleSource.SERVER).values().toArray(new DesensitizationRule[0])); + customRuleEditPane.populate(latestRules.get(DesensitizationRuleSource.CUSTOM).values().toArray(new DesensitizationRule[0])); + } + + /** + * 获取当前选中的规则 + * + * @return + */ + public DesensitizationRule getSelectedDesensitizationRule() { + switch (currentRuleSource) { + case SERVER: + return serverRuleEditPane.getTableModel().getSelectedValue(); + case CUSTOM: + return customRuleEditPane.getTableModel().getSelectedValue(); + default: + return null; + } + } + + /** + * 规则选择Table的TableModel + */ + private class DesensitizationRuleChooseTableModel extends UITableModelAdapter { + + private Component parent; + + private boolean debugActionOnly; + + protected DesensitizationRuleChooseTableModel(Component parent, boolean debugActionOnly) { + super(new String[]{ + StringUtils.EMPTY, + Toolkit.i18nText("Fine-Design_Report_Desensitization_Rule_Name"), + Toolkit.i18nText("Fine-Design_Report_Desensitization_Rule_Description"), + Toolkit.i18nText("Fine-Design_Report_Desensitization_Rule_Status"), + }); + this.parent = parent; + this.debugActionOnly = debugActionOnly; + this.setColumnClass(new Class[]{ + ChooseMark.class, + UILabel.class, + UILabel.class, + DesensitizationRuleStatusPane.class + }); + this.setDefaultEditor(ChooseMark.class, new ChooseMark()); + this.setDefaultRenderer(ChooseMark.class, new ChooseMark()); + this.setDefaultEditor(DesensitizationRuleStatusPane.class, new DesensitizationRuleStatusPane()); + this.setDefaultRenderer(DesensitizationRuleStatusPane.class, new DesensitizationRuleStatusPane()); + this.createTable().getColumnModel().getColumn(0).setMaxWidth(20); + this.createTable().getColumnModel().getColumn(3).setMaxWidth(60); + } + + @Override + public Object getValueAt(int rowIndex, int columnIndex) { + DesensitizationRule rule = getList().get(rowIndex); + switch (columnIndex) { + case 0: + // 选中状态 + return rule.equals(getSelectedValue()); + case 1: + // 脱敏规则名称 + return rule.getRuleName(); + case 2: + // 脱敏规则描述 + return DesensitizationRule.getDescription(rule); + case 3: + // 脱敏规则状态 + DesensitizationRuleStatus ruleStatus = DesensitizationRuleManager.getInstance().getRuleStatus(rule, latestRules); + // 非正常状态需要标记为异常 + return ruleStatus == DesensitizationRuleStatus.NORMAL ? StringUtils.EMPTY : Toolkit.i18nText("Fine-Design_Report_Desensitization_Rule_Status_Abnormal"); + default: + return StringUtils.EMPTY; + } + } + + @Override + public boolean isCellEditable(int row, int col) { + return true; + } + + @Override + public UITableEditAction[] createAction() { + return debugActionOnly ? + new UITableEditAction[]{new DebugRuleAction(parent)} : + new UITableEditAction[]{new AddRuleAction(), new EditRuleAction(), new DeleteRuleAction(parent), new DebugRuleAction(parent)}; + } + + private Set getCurrentExistRuleNames(String excludeName) { + List rules = getList(); + return CollectionUtils.isEmpty(rules) ? + new LinkedHashSet<>() : + rules.stream() + .map(DesensitizationRule::getRuleName) + .filter(name -> !StringUtils.equals(name, excludeName)) + .collect(Collectors.toSet()); + } + + /** + * 规则状态展示页面 + */ + private class DesensitizationRuleStatusPane extends AbstractCellEditor implements TableCellEditor, TableCellRenderer { + + private UILabel ruleStatusLabel; + + DesensitizationRuleStatusPane() { + // 规则状态 + this.ruleStatusLabel = new UILabel(); + this.ruleStatusLabel.setForeground(Color.RED); + } + + /** + * 根据脱敏规则信息,刷新规则状态,主要用于与规则选择器的联动 + * + * @param rule + */ + public void refreshRuleStatus(DesensitizationRule rule) { + DesensitizationRuleStatus ruleStatus = DesensitizationRuleManager.getInstance().getRuleStatus(rule, latestRules); + if (ruleStatus == DesensitizationRuleStatus.NORMAL) { + // 正常规则时,重置提示Label + this.ruleStatusLabel.setText(StringUtils.EMPTY); + this.ruleStatusLabel.setToolTipText(null); + } else { + this.ruleStatusLabel.setText(Toolkit.i18nText("Fine-Design_Report_Desensitization_Rule_Status_Abnormal")); + this.ruleStatusLabel.setToolTipText(ruleStatus.getDescription()); + } + } + + @Override + public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { + refreshRuleStatus(getList().get(row)); + return ruleStatusLabel; + } + + @Override + public Object getCellEditorValue() { + return ruleStatusLabel; + } + + @Override + public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { + refreshRuleStatus(getList().get(row)); + return ruleStatusLabel; + } + } + + /** + * 添加规则 + */ + private class AddRuleAction extends AddTableRowAction { + + public AddRuleAction() { + this.setName(Toolkit.i18nText("Fine-Design_Report_Desensitization_Add")); + this.setSmallIcon("/com/fr/design/standard/add/add_black", false); + } + + @Override + public void actionPerformed(ActionEvent e) { + // 新增一条规则 + DesensitizationRuleEditPane editPane = new DesensitizationRuleEditPane(getCurrentExistRuleNames(StringUtils.EMPTY)); + BasicDialog basicDialog = editPane.showWindowWithCustomSize(SwingUtilities.getWindowAncestor(parent), new DialogActionAdapter() { + @Override + public void doOk() { + DesensitizationRule rule = editPane.updateBean(); + // 添加到Rule Manager中 + if (DesensitizationRule.valid(rule)) { + DesensitizationRuleManager.getInstance().addRule(rule); + } + // 添加到Table中 + addRow(rule); + fireTableDataChanged(); + } + + @Override + public void doCancel() { + super.doCancel(); + } + }, BasicDialog.DEFAULT); + basicDialog.setVisible(true); + } + } + + private class EditRuleAction extends UITableEditAction { + + public EditRuleAction() { + this.setName(Toolkit.i18nText("Fine-Design_Basic_Edit")); + this.setSmallIcon(IconUtils.readIcon("/com/fr/design/standard/edit/edit")); + } + + @Override + public void checkEnabled() { + setEnabled(table.getSelectedRow() != -1); + } + + @Override + public void actionPerformed(ActionEvent e) { + // 获取当前选中规则的副本 + DesensitizationRule selectedValue = null; + try { + selectedValue = (DesensitizationRule) getSelectedValue().clone(); + } catch (CloneNotSupportedException ex) { + throw new RuntimeException(ex); + } + DesensitizationRuleEditPane editPane = new DesensitizationRuleEditPane(getCurrentExistRuleNames(selectedValue.getRuleName())); + editPane.populateBean(selectedValue); + final DesensitizationRule finalRule = selectedValue; + BasicDialog basicDialog = editPane.showWindowWithCustomSize(SwingUtilities.getWindowAncestor(parent), new DialogActionAdapter() { + @Override + public void doOk() { + DesensitizationRule rule = editPane.updateBean(); + // 修改同步到RuleManager中 + if (DesensitizationRule.valid(rule)) { + DesensitizationRuleManager.getInstance().updateRule(finalRule, rule); + } + setSelectedValue(rule); + fireTableDataChanged(); + } + + @Override + public void doCancel() { + super.doCancel(); + } + }, BasicDialog.DEFAULT); + basicDialog.setVisible(true); + } + } + + private class DeleteRuleAction extends DeleteAction { + + public DeleteRuleAction(Component parent) { + super(parent); + this.setName(Toolkit.i18nText("Fine-Design_Basic_Base_Remove")); + this.setSmallIcon("/com/fr/design/images/control/remove"); + } + + @Override + public void checkEnabled() { + setEnabled(table.getSelectedRow() != -1); + } + + @Override + public void actionPerformed(ActionEvent e) { + // 获取当前选中规则 + DesensitizationRule selectedRule = getSelectedValue(); + // 删除同步到RuleManager中 + if (DesensitizationRule.valid(selectedRule)) { + DesensitizationRuleManager.getInstance().removeRule(selectedRule); + } + super.actionPerformed(e); + } + } + + private class DebugRuleAction extends UITableEditAction { + + private Component parent; + + public DebugRuleAction(Component parent) { + this.parent = parent; + this.setName(Toolkit.i18nText("Fine-Design_Report_Desensitization_Rule_Debug")); + this.setSmallIcon("/com/fr/design/standard/debug/debug"); + } + + @Override + public void checkEnabled() { + setEnabled(table.getSelectedRow() != -1 && getList().get(table.getSelectedRow()).isEnable()); + } + + @Override + public void actionPerformed(ActionEvent e) { + // 获取当前选中规则 + DesensitizationRule selectedRule = getSelectedValue(); + if (selectedRule == null) { + return; + } + DesensitizationRuleDebugPane ruleDebugPane = new DesensitizationRuleDebugPane(selectedRule); + BasicDialog ruleDebugDialog = ruleDebugPane.showWindowWithCustomSize(SwingUtilities.getWindowAncestor(parent), null, BasicDialog.DEFAULT); + ruleDebugDialog.setVisible(true); + } + } + } + + +} diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/rule/DesensitizationRuleDebugPane.java b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/rule/DesensitizationRuleDebugPane.java new file mode 100644 index 0000000000..eba6d10899 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/rule/DesensitizationRuleDebugPane.java @@ -0,0 +1,128 @@ +package com.fr.design.data.datapane.preview.desensitization.view.rule; + +import com.fr.data.desensitize.calculate.DesensitizationCalculator; +import com.fr.data.desensitize.rule.base.DesensitizationRule; +import com.fr.design.dialog.BasicPane; +import com.fr.design.dialog.FineJOptionPane; +import com.fr.design.gui.ibutton.UIButton; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.gui.itextfield.UITextField; +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.stable.StringUtils; + +import javax.swing.BorderFactory; +import javax.swing.JComponent; +import javax.swing.JPanel; +import java.awt.BorderLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; + +/** + * 脱敏规则调试页 + * + * @author Yvan + * @version 11.0 + * Created by Yvan on 2022/9/8 + */ +public class DesensitizationRuleDebugPane extends BasicPane { + + /** + * 脱敏规则 + */ + private DesensitizationRule rule; + + public DesensitizationRuleDebugPane(DesensitizationRule rule) { + this.rule = rule; + initComponent(); + } + + private void initComponent() { + this.setLayout(FRGUIPaneFactory.createBorderLayout()); + this.add(initNorthPane(), BorderLayout.NORTH); + this.add(initCenterPane(), BorderLayout.CENTER); + } + + private JPanel initNorthPane() { + JPanel northPane = FRGUIPaneFactory.createTitledBorderPane(Toolkit.i18nText("Fine-Design_Report_Desensitization_Rule_Description")); + JPanel panel = FRGUIPaneFactory.createBorderLayout_S_Pane(); + panel.setBorder(BorderFactory.createEmptyBorder(20, 10, 0, 0)); + UILabel desensitizationRule = new UILabel(Toolkit.i18nText("Fine-Design_Report_Desensitization_Rule_Algorithm")); + UILabel characterReplace = new UILabel(rule.getRuleType().getRuleTypeName()); + UILabel description = new UILabel(DesensitizationRule.getDescription(rule)); + JComponent[][] components = new JComponent[][]{ + {desensitizationRule, characterReplace}, + {new UILabel(), description} + }; + panel.add( + TableLayoutHelper.createCommonTableLayoutPane( + components, + new double[]{TableLayout.PREFERRED, TableLayout.PREFERRED}, + new double[]{TableLayout.PREFERRED, TableLayout.PREFERRED}, + 20), + BorderLayout.CENTER); + northPane.add(panel); + return northPane; + } + + private JPanel initCenterPane() { + JPanel centerPane = FRGUIPaneFactory.createTitledBorderPane(Toolkit.i18nText("Fine-Design_Report_Desensitization_Rule_Debug")); + JPanel panel = FRGUIPaneFactory.createBorderLayout_S_Pane(); + panel.setBorder(BorderFactory.createEmptyBorder(20, 10, 0, 0)); + + UILabel beforeDesensitize = new UILabel(Toolkit.i18nText("Fine-Design_Report_Desensitization_Before")); + UITextField beforeDesensitizeText = new UITextField(20); + beforeDesensitizeText.setPlaceholder(Toolkit.i18nText("Fine-Design_Report_Desensitization_Enter_Content")); + UILabel afterDesensitize = new UILabel(Toolkit.i18nText("Fine-Design_Report_Desensitization_After")); + UITextField afterDesensitizeText = new UITextField(20); + afterDesensitizeText.setEditable(false); + UIButton desensitizeButton = new UIButton(Toolkit.i18nText("Fine-Design_Report_Desensitization_Debug")); + beforeDesensitizeText.addFocusListener(new FocusListener() { + @Override + public void focusGained(FocusEvent e) { + afterDesensitizeText.setText(StringUtils.EMPTY); + } + + @Override + public void focusLost(FocusEvent e) { + + } + }); + desensitizeButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + String text = beforeDesensitizeText.getText(); + if (StringUtils.isEmpty(text)) { + FineJOptionPane.showMessageDialog(DesensitizationRuleDebugPane.this, + Toolkit.i18nText("Fine-Design_Report_Desensitization_Please_Enter_Valid_Content")); + } + String desensitizedText = DesensitizationCalculator.getInstance().desensitize(text, rule); + afterDesensitizeText.setText(desensitizedText); + } + }); + + JComponent[][] components = new JComponent[][]{ + {beforeDesensitize, beforeDesensitizeText, desensitizeButton}, + {afterDesensitize, afterDesensitizeText, new UILabel()} + }; + panel.add( + TableLayoutHelper.createCommonTableLayoutPane( + components, + new double[]{TableLayout.PREFERRED, TableLayout.PREFERRED}, + new double[]{TableLayout.PREFERRED, TableLayout.PREFERRED, TableLayout.PREFERRED}, + 20), + BorderLayout.CENTER); + + centerPane.add(panel); + return centerPane; + } + + @Override + protected String title4PopupWindow() { + return Toolkit.i18nText("Fine-Design_Report_Desensitization_Rule_Debug"); + } +} diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/rule/DesensitizationRuleEditPane.java b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/rule/DesensitizationRuleEditPane.java new file mode 100644 index 0000000000..5a0515a59e --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/rule/DesensitizationRuleEditPane.java @@ -0,0 +1,309 @@ +package com.fr.design.data.datapane.preview.desensitization.view.rule; + +import com.fr.data.desensitize.rule.base.DesensitizationCondition; +import com.fr.data.desensitize.rule.base.DesensitizationRule; +import com.fr.data.desensitize.rule.base.DesensitizationRuleSource; +import com.fr.data.desensitize.rule.base.DesensitizationRuleType; +import com.fr.design.beans.BasicBeanPane; +import com.fr.design.constants.UIConstants; +import com.fr.design.event.UIObserverListener; +import com.fr.design.gui.icombobox.UIComboBox; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.gui.itextfield.UINumberField; +import com.fr.design.gui.itextfield.UITextField; +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.stable.StringUtils; + +import javax.swing.BorderFactory; +import javax.swing.JComponent; +import javax.swing.JPanel; +import java.awt.BorderLayout; +import java.awt.CardLayout; +import java.awt.Insets; +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; +import java.util.Arrays; +import java.util.Set; + +/** + * 脱敏规则编辑页 + * + * @author Yvan + * @version 11.0 + * Created by Yvan on 2022/9/8 + */ +public class DesensitizationRuleEditPane extends BasicBeanPane { + /** + * 已经存在的规则名称,用于检测重名 + */ + private Set existRuleNames; + + private UITextField ruleNameTextField; + private UIComboBox ruleTypeComboBox; + private UINumberField retainFrontTextField; + private UINumberField retainBackTextField; + private UITextField firstSymbolTextField; + private UITextField secondSymbolTextField; + private CardLayout cardLayout; + private JPanel ruleConditionPane; + + + private DesensitizationRule rule = DesensitizationRule.createDefaultEmptyRule(); + + private final FocusListener retainFrontListener = new FocusListener() { + @Override + public void focusGained(FocusEvent e) { + } + + @Override + public void focusLost(FocusEvent e) { + rule.getCondition().setRetainFront((int) retainFrontTextField.getValue()); + } + }; + + private final FocusListener retainBackListener = new FocusListener() { + @Override + public void focusGained(FocusEvent e) { + } + + @Override + public void focusLost(FocusEvent e) { + rule.getCondition().setRetainBack((int) retainBackTextField.getValue()); + } + }; + + private final FocusListener firstSymbolListener = new FocusListener() { + @Override + public void focusGained(FocusEvent e) { + } + + @Override + public void focusLost(FocusEvent e) { + rule.getCondition().setSymbol(firstSymbolTextField.getText()); + } + }; + + private final FocusListener secondSymbolListener = new FocusListener() { + @Override + public void focusGained(FocusEvent e) { + } + + @Override + public void focusLost(FocusEvent e) { + rule.getCondition().setRetainFront(0); + rule.getCondition().setRetainBack(0); + rule.getCondition().setSymbol(secondSymbolTextField.getText()); + } + }; + + public DesensitizationRuleEditPane(Set existRuleNames) { + this.existRuleNames = existRuleNames; + initComponent(); + } + + /** + * 初始化面板 + */ + private void initComponent() { + this.setLayout(FRGUIPaneFactory.createLeftZeroVgapNormalHgapLayout()); + JPanel panel = FRGUIPaneFactory.createBorderLayout_S_Pane(); + panel.setBorder(BorderFactory.createEmptyBorder(20, 10, 0, 0)); + UILabel ruleNameLabel = new UILabel(Toolkit.i18nText("Fine-Design_Report_Desensitization_Rule_Name")); + // 规则名称输入框 + initRuleNameTextField(); + UILabel ruleTypeLabel = new UILabel(Toolkit.i18nText("Fine-Design_Report_Desensitization_Rule_Algorithm")); + // 脱敏算法Type设置 + JPanel ruleTypePane = initRuleTypePane(); + // 脱敏算法Condition设置 + JPanel ruleConditionPane = initRuleConditionPane(); + JComponent[][] components = { + {ruleNameLabel, ruleNameTextField}, + {ruleTypeLabel, ruleTypePane}, + {new UILabel(), ruleConditionPane} + }; + panel.add( + TableLayoutHelper.createGapTableLayoutPane( + components, + new double[]{TableLayout.PREFERRED, TableLayout.PREFERRED, TableLayout.FILL}, + new double[]{TableLayout.FILL, TableLayout.PREFERRED}, + 20, + 20), + BorderLayout.CENTER); + this.add(panel); + } + + /** + * 初始化规则类型面板 + * + * @return + */ + private JPanel initRuleTypePane() { + JPanel ruleTypePane = FRGUIPaneFactory.createBorderLayout_S_Pane(); + // 脱敏算法类型下拉框 + initRuleTypeComboBox(); + ruleTypePane.add(ruleTypeComboBox, BorderLayout.CENTER); + return ruleTypePane; + } + + /** + * 初始化规则条件面板 + * + * @return + */ + private JPanel initRuleConditionPane() { + JPanel panel = FRGUIPaneFactory.createBorderLayout_S_Pane(); + cardLayout = new CardLayout(); + ruleConditionPane = new JPanel(cardLayout); + // 字符替换 + JPanel characterReplacePane = FRGUIPaneFactory.createLeftFlowZeroGapBorderPane(); + UILabel retainFrontLabel = new UILabel(Toolkit.i18nText("Fine-Design_Report_Desensitization_Part_One") + StringUtils.BLANK); + retainFrontTextField = new UINumberField(5); + retainFrontTextField.addFocusListener(retainFrontListener); + + UILabel retainBackLabel = new UILabel(StringUtils.BLANK + Toolkit.i18nText("Fine-Design_Report_Desensitization_Part_Two") + StringUtils.BLANK); + retainBackTextField = new UINumberField(5); + retainBackTextField.addFocusListener(retainBackListener); + + UILabel replaceLabel = new UILabel(StringUtils.BLANK + Toolkit.i18nText("Fine-Design_Report_Desensitization_Part_Three") + StringUtils.BLANK); + firstSymbolTextField = new UITextField(10); + firstSymbolTextField.addFocusListener(firstSymbolListener); + + characterReplacePane.add(retainFrontLabel); + characterReplacePane.add(retainFrontTextField); + characterReplacePane.add(retainBackLabel); + characterReplacePane.add(retainBackTextField); + characterReplacePane.add(replaceLabel); + characterReplacePane.add(firstSymbolTextField); + // 整体替换 + JPanel characterAllReplacePane = FRGUIPaneFactory.createLeftFlowZeroGapBorderPane(); + UILabel allReplaceLabel = new UILabel(Toolkit.i18nText("Fine-Design_Report_Desensitization_All_Character_Replace_By") + StringUtils.BLANK); + secondSymbolTextField = new UITextField(10); + secondSymbolTextField.addFocusListener(secondSymbolListener); + + characterAllReplacePane.add(allReplaceLabel); + characterAllReplacePane.add(secondSymbolTextField); + + ruleConditionPane.add(characterReplacePane, DesensitizationRuleType.CHARACTER_REPLACE.getRuleTypeName()); + ruleConditionPane.add(characterAllReplacePane, DesensitizationRuleType.ALL_CHARACTERS_REPLACE.getRuleTypeName()); + // 初始化状态为字符替换 + switchRuleConditionPane(DesensitizationRuleType.CHARACTER_REPLACE); + + panel.add(ruleConditionPane, BorderLayout.CENTER); + return panel; + } + + /** + * 切换规则类型面板 + * + * @param ruleType + */ + private void switchRuleConditionPane(DesensitizationRuleType ruleType) { + this.cardLayout.show(ruleConditionPane, ruleType.getRuleTypeName()); + } + + /** + * 初始化规则类型下拉框 + */ + private void initRuleTypeComboBox() { + ruleTypeComboBox = new UIComboBox(Arrays.stream(DesensitizationRuleType.values()).map(DesensitizationRuleType::getRuleTypeName).toArray()); + ruleTypeComboBox.setSelectedIndex(0); + ruleTypeComboBox.registerChangeListener(new UIObserverListener() { + @Override + public void doChange() { + DesensitizationRuleType ruleType = DesensitizationRuleType.matchByTypeName((String) ruleTypeComboBox.getSelectedItem()); + rule.setRuleType(ruleType); + // 修改底下的conditionPane + switchRuleConditionPane(ruleType); + } + }); + } + + /** + * 初始化规则名称输入框 + */ + private void initRuleNameTextField() { + ruleNameTextField = new UITextField(20) { + @Override + public Insets getInsets() { + return new Insets(2, 4, 0, 4); + } + }; + ruleNameTextField.setPlaceholder(Toolkit.i18nText("Fine-Design_Report_Desensitization_Please_Enter_Rule_Name")); + ruleNameTextField.setBorderPainted(true); + ruleNameTextField.addFocusListener(new FocusListener() { + @Override + public void focusGained(FocusEvent e) { + ruleNameTextField.setBorder(BorderFactory.createLineBorder(UIConstants.NORMAL_BLUE)); + ruleNameTextField.repaint(); + } + + @Override + public void focusLost(FocusEvent e) { + ruleNameTextField.setBorder(BorderFactory.createLineBorder(UIConstants.TOOLBAR_BORDER_COLOR)); + rule.setRuleName(ruleNameTextField.getText()); + ruleNameTextField.repaint(); + } + }); + } + + + @Override + public void populateBean(DesensitizationRule ob) { + this.rule = ob; + this.ruleNameTextField.setText(rule.getRuleName()); + String typeName = rule.getRuleType().getRuleTypeName(); + this.ruleTypeComboBox.setSelectedItem(typeName); + switch (DesensitizationRuleType.matchByTypeName(typeName)) { + case CHARACTER_REPLACE: + this.retainFrontTextField.setValue(rule.getCondition().getRetainFront()); + this.retainBackTextField.setValue(rule.getCondition().getRetainBack()); + this.firstSymbolTextField.setText(rule.getCondition().getSymbol()); + break; + case ALL_CHARACTERS_REPLACE: + this.secondSymbolTextField.setText(rule.getCondition().getSymbol()); + break; + default: + } + + } + + @Override + public DesensitizationRule updateBean() { + rule.setRuleName(this.ruleNameTextField.getText()); + rule.setRuleSource(DesensitizationRuleSource.CUSTOM); + DesensitizationRuleType ruleType = DesensitizationRuleType.matchByTypeName(String.valueOf(this.ruleTypeComboBox.getSelectedItem())); + rule.setRuleType(ruleType); + rule.getCondition().setRetainFront((int) this.retainFrontTextField.getValue()); + rule.getCondition().setRetainBack((int) this.retainBackTextField.getValue()); + rule.getCondition().setSymbol(ruleType == DesensitizationRuleType.CHARACTER_REPLACE ? + this.firstSymbolTextField.getText() : + this.secondSymbolTextField.getText()); + rule.setEnable(true); + return rule; + } + + @Override + protected String title4PopupWindow() { + return Toolkit.i18nText("Fine-Design_Report_Desensitization_Custom_Config_Rules"); + } + + @Override + public void checkValid() throws Exception { + // 保存rule前检查下 + String checkMessage = StringUtils.EMPTY; + if (StringUtils.isEmpty(rule.getRuleName())) { + checkMessage = Toolkit.i18nText("Fine-Design_Report_Desensitization_Rule_Name_Cannot_Be_Empty"); + } else if (existRuleNames.contains(rule.getRuleName())) { + checkMessage = Toolkit.i18nText("Fine-Design_Report_Desensitization_Rule_Name_Cannot_Repeat"); + } else if (DesensitizationCondition.invalid(rule.getCondition())) { + checkMessage = Toolkit.i18nText("Fine-Design_Report_Desensitization_Rule_Wrong_Condition"); + } + if (StringUtils.isNotEmpty(checkMessage)) { + throw new Exception(checkMessage); + } + } + +} diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/rule/DesensitizationRulePane.java b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/rule/DesensitizationRulePane.java new file mode 100644 index 0000000000..ba8b00d735 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/rule/DesensitizationRulePane.java @@ -0,0 +1,89 @@ +package com.fr.design.data.datapane.preview.desensitization.view.rule; + +import com.fr.data.desensitize.rule.base.DesensitizationRule; +import com.fr.data.desensitize.rule.base.DesensitizationRuleSource; +import com.fr.design.beans.BasicBeanPane; +import com.fr.design.border.UITitledBorder; +import com.fr.design.i18n.Toolkit; +import com.fr.design.layout.FRGUIPaneFactory; + +import javax.swing.JPanel; +import java.awt.BorderLayout; +import java.util.Map; + +/** + * 脱敏规则展示页 + * + * @author Yvan + * @version 11.0 + * Created by Yvan on 2022/9/8 + */ +public class DesensitizationRulePane extends BasicBeanPane { + + /** + * 规则来源选择面板 + */ + private DesensitizationRuleSourceChoosePane ruleSourceChoosePane; + + /** + * 规则选择面板 + */ + private DesensitizationRuleChoosePane ruleChoosePane; + + /** + * 最新的所有规则 + */ + private Map> latestRules; + + /** + * 内容面板 + */ + private JPanel contentPane; + + public DesensitizationRulePane(Map> latestRules) { + this.setLayout(FRGUIPaneFactory.createBorderLayout()); + this.latestRules = latestRules; + initPane(); + } + + private void initPane() { + // 内容面板 + contentPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); + contentPane.setBorder(UITitledBorder.createBorderWithTitle(Toolkit.i18nText("Fine-Design_Report_Desensitization_Rule_Choose"))); + this.add(contentPane, BorderLayout.CENTER); + // 规则来源选择Pane + ruleSourceChoosePane = new DesensitizationRuleSourceChoosePane(this); + // 规则选择Pane + ruleChoosePane = new DesensitizationRuleChoosePane(latestRules); + contentPane.add(ruleSourceChoosePane, BorderLayout.NORTH); + contentPane.add(ruleChoosePane, BorderLayout.CENTER); + } + + /** + * 处理规则来源选择面板中改动来源的事件 + * + * @param newRuleSource + */ + public void dealWithRuleSourceChanged(DesensitizationRuleSource newRuleSource) { + ruleChoosePane.switchPaneByRuleSource(newRuleSource); + } + + + @Override + public void populateBean(DesensitizationRule ob) { + // 这边展示当前所有规则时,不依靠外界传值,初始化的时候,从规则管理中心去获取 + } + + @Override + public DesensitizationRule updateBean() { + DesensitizationRule desensitizationRule = ruleChoosePane.getSelectedDesensitizationRule(); + return DesensitizationRule.valid(desensitizationRule) ? + desensitizationRule : + DesensitizationRule.createDefaultEmptyRule(); + } + + @Override + protected String title4PopupWindow() { + return Toolkit.i18nText("Fine-Design_Report_Desensitization_Rule"); + } +} diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/rule/DesensitizationRuleSourceChoosePane.java b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/rule/DesensitizationRuleSourceChoosePane.java new file mode 100644 index 0000000000..05ace32bdd --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/rule/DesensitizationRuleSourceChoosePane.java @@ -0,0 +1,49 @@ +package com.fr.design.data.datapane.preview.desensitization.view.rule; + +import com.fr.data.desensitize.rule.base.DesensitizationRuleSource; +import com.fr.design.gui.ibutton.UIRadioButton; +import com.fr.design.i18n.Toolkit; + +import javax.swing.BorderFactory; +import javax.swing.ButtonGroup; +import javax.swing.JPanel; +import java.awt.FlowLayout; + +/** + * 脱敏规则来源选择页面 + * + * @author Yvan + * @version 11.0 + * Created by Yvan on 2022/9/26 + */ +public class DesensitizationRuleSourceChoosePane extends JPanel { + + /** + * 来源平台的按钮 + */ + private UIRadioButton serverSource; + + /** + * 来源本地的按钮 + */ + private UIRadioButton customSource; + + public DesensitizationRuleSourceChoosePane(DesensitizationRulePane desensitizationRulePane) { + this.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); + this.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0)); + + serverSource = new UIRadioButton(Toolkit.i18nText("Fine-Design_Report_Desensitization_Server_Config_Rules")); + customSource = new UIRadioButton(Toolkit.i18nText("Fine-Design_Report_Desensitization_Custom_Config_Rules")); + + ButtonGroup buttonGroup = new ButtonGroup(); + buttonGroup.add(serverSource); + buttonGroup.add(customSource); + serverSource.setSelected(true); + + serverSource.registerChangeListener(() -> desensitizationRulePane.dealWithRuleSourceChanged(DesensitizationRuleSource.SERVER)); + customSource.registerChangeListener(() -> desensitizationRulePane.dealWithRuleSourceChanged(DesensitizationRuleSource.CUSTOM)); + + this.add(serverSource); + this.add(customSource); + } +} diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/setting/TableDataDesensitizationSettingPane.java b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/setting/TableDataDesensitizationSettingPane.java new file mode 100644 index 0000000000..a37d9d0220 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/setting/TableDataDesensitizationSettingPane.java @@ -0,0 +1,98 @@ +package com.fr.design.data.datapane.preview.desensitization.view.setting; + +import com.fr.data.desensitize.base.DesensitizationTableData; +import com.fr.data.desensitize.base.TableDataDesensitizationItem; +import com.fr.design.beans.BasicBeanPane; +import com.fr.design.data.datapane.preview.desensitization.view.common.DesensitizationOpenPane; +import com.fr.design.i18n.Toolkit; +import com.fr.design.layout.FRGUIPaneFactory; + +import javax.swing.JComponent; +import java.awt.BorderLayout; +import java.util.List; + +/** + * 数据集脱敏字段设置页面 + * + * @author Yvan + * @version 11.0 + * Created by Yvan on 2022/9/8 + */ +public class TableDataDesensitizationSettingPane extends BasicBeanPane { + + /** + * 设置针对的数据集 + */ + private DesensitizationTableData tableData; + + private DesensitizationOpenPane desensitizationOpenPane; + + private TableDataDesensitizationTablePane tableDataDesensitizationTablePane; + + + public TableDataDesensitizationSettingPane(DesensitizationTableData tableData) { + this.tableData = tableData; + initComponents(); + } + + private void initComponents() { + this.setLayout(FRGUIPaneFactory.createBorderLayout()); + this.add(initNorthPane(), BorderLayout.NORTH); + this.add(initCenterPane(), BorderLayout.CENTER); + } + + /** + * 初始化启用数据脱敏面板 + * + * @return + */ + private JComponent initNorthPane() { + this.desensitizationOpenPane = new DesensitizationOpenPane(); + return desensitizationOpenPane; + } + + /** + * 初始化数据脱敏规则表面板 + * + * @return + */ + private JComponent initCenterPane() { + this.tableDataDesensitizationTablePane = new TableDataDesensitizationTablePane(tableData, this); + return tableDataDesensitizationTablePane; + } + + @Override + protected String title4PopupWindow() { + return Toolkit.i18nText("Fine-Design_Report_Desensitization_Config"); + } + + @Override + public void populateBean(DesensitizationTableData tableData) { + this.tableData = tableData; + this.desensitizationOpenPane.setDesensitizationOpened(tableData.getDesensitizationConfig().isDesensitizeOpened()); + tableDataDesensitizationTablePane.populateDesensitizationSetting(tableData); + } + + @Override + public DesensitizationTableData updateBean() { + saveDesensitizeOpened(); + saveDesensitizationBeans(tableDataDesensitizationTablePane.updateDesensitizationSetting()); + return tableData; + } + + /** + * 保存脱敏启用状态 + */ + public void saveDesensitizeOpened() { + tableData.getDesensitizationConfig().setDesensitizeOpened(this.desensitizationOpenPane.isDesensitizationOpened()); + } + + /** + * 保存脱敏规则配置信息 + * + * @param desensitizationItems + */ + public void saveDesensitizationBeans(List desensitizationItems) { + tableData.getDesensitizationConfig().setDesensitizationItems(desensitizationItems); + } +} diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/setting/TableDataDesensitizationTableModel.java b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/setting/TableDataDesensitizationTableModel.java new file mode 100644 index 0000000000..52b7e5b19b --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/setting/TableDataDesensitizationTableModel.java @@ -0,0 +1,619 @@ +package com.fr.design.data.datapane.preview.desensitization.view.setting; + +import com.fr.data.desensitize.base.DesensitizationTableData; +import com.fr.data.desensitize.base.TableDataDesensitizationItem; +import com.fr.data.desensitize.rule.DesensitizationRuleManager; +import com.fr.data.desensitize.rule.base.DesensitizationRule; +import com.fr.data.desensitize.rule.base.DesensitizationRuleSource; +import com.fr.data.desensitize.rule.base.DesensitizationRuleStatus; +import com.fr.design.data.datapane.preview.desensitization.view.rule.DesensitizationRulePane; +import com.fr.design.dialog.BasicDialog; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.design.gui.ibutton.UIButton; +import com.fr.design.gui.icombobox.UIComboBox; +import com.fr.design.gui.icombocheckbox.UIComboCheckBox; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.gui.itableeditorpane.UITableEditAction; +import com.fr.design.gui.itableeditorpane.UITableModelAdapter; +import com.fr.design.gui.itextfield.UITextField; +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.stable.StringUtils; +import org.jetbrains.annotations.Nullable; + +import javax.swing.AbstractCellEditor; +import javax.swing.JComponent; +import javax.swing.JPanel; +import javax.swing.JTable; +import javax.swing.SwingUtilities; +import javax.swing.event.CellEditorListener; +import javax.swing.event.ChangeEvent; +import javax.swing.table.TableCellEditor; +import javax.swing.table.TableCellRenderer; +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Component; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +/** + * 处理TableDataDesensitizationTablePane中TableEditPane的Model + * + * @author Yvan + * @version 11.0 + * Created by Yvan on 2022/9/23 + */ +public class TableDataDesensitizationTableModel extends UITableModelAdapter { + + private static final String APOSTROPHE = "..."; + + private static final String COMMA = ","; + + /** + * 当前数据集的所有列名 + */ + private List columnNames = new ArrayList<>(); + + /** + * key为用户组唯一标识(id拼接),value为用户组名称 + */ + private Map roleMap = new LinkedHashMap<>(); + + /** + * 当前最新的所有规则 + */ + private Map> latestRules = new LinkedHashMap<>(); + + private Component parent; + + public TableDataDesensitizationTableModel(DesensitizationTableData tableData, Component parent, List columnNames, Map roleMap, Map> latestRules) { + // table相关 + super(new String[]{ + Toolkit.i18nText("Fine-Design_Report_Desensitization_Column"), + Toolkit.i18nText("Fine-Design_Report_Desensitization_Rule"), + Toolkit.i18nText("Fine-Design_Report_Desensitization_Rule_Description"), + Toolkit.i18nText("Fine-Design_Report_Desensitization_Effected_Roles"), + Toolkit.i18nText("Fine-Design_Report_Desensitization_Rule_Status"), + }); + this.parent = parent; + this.columnNames = columnNames; + this.roleMap = roleMap; + this.latestRules = latestRules; + + initTable(); + } + + /** + * 初始化Table + */ + private void initTable() { + this.setColumnClass(new Class[]{ + // 列名选择 + ColumnNamesComboBox.class, + // 规则选择 + DesensitizationRuleChooser.class, + // 规则详情展示 + DesensitizationRuleDescriptionPane.class, + // 生效用户组选择 + EffectedRolesChooser.class, + // 规则状态 + DesensitizationRuleStatusPane.class + }); + ColumnNamesComboBox columnNamesComboBox = new ColumnNamesComboBox(); + this.setDefaultEditor(ColumnNamesComboBox.class, columnNamesComboBox); + this.setDefaultEditor(DesensitizationRuleChooser.class, new DesensitizationRuleChooser()); + this.setDefaultEditor(DesensitizationRuleDescriptionPane.class, new DesensitizationRuleDescriptionPane()); + EffectedRolesChooser effectedRolesChooser = new EffectedRolesChooser(); + this.setDefaultEditor(EffectedRolesChooser.class, effectedRolesChooser); + this.setDefaultEditor(DesensitizationRuleStatusPane.class, new DesensitizationRuleStatusPane()); + this.setDefaultRenderer(DesensitizationRuleStatusPane.class, new DesensitizationRuleStatusPane()); + + this.createTable().getColumnModel().getColumn(TableSequences.DesensitizationRuleStatus.getNum()).setMaxWidth(60); + } + + @Override + public Object getValueAt(int rowIndex, int columnIndex) { + TableDataDesensitizationItem desensitizationItem = this.getList().get(rowIndex); + TableSequences match = TableSequences.match(columnIndex); + switch (match) { + case ColumnName: + // 选中的数据集字段名称 + return desensitizationItem.getColumnName(); + case DesensitizationRule: + // 脱敏规则名称 + return desensitizationItem.getRule().getRuleName(); + case DesensitizationRuleDescription: + // 脱敏规则详情 + return DesensitizationRule.getDescription(desensitizationItem.getRule()); + case EffectedRoles: + // 生效用户组 + return matchRoleNamesByIds(desensitizationItem.getRoleIds()); + case DesensitizationRuleStatus: + // 规则状态 + return needMarkRule(desensitizationItem.getRule()) ? StringUtils.EMPTY : Toolkit.i18nText("Fine-Design_Report_Desensitization_Rule_Status_Abnormal"); + default: + return StringUtils.EMPTY; + } + } + + /** + * 通过id匹配此用户组对应的部门职位名称(或者说自定义角色名称),并拼接成字符串返回 + * + * @param roleIds + * @return + */ + private String matchRoleNamesByIds(Collection roleIds) { + StringBuilder builder = new StringBuilder(); + for (String roleId : roleIds) { + if (roleMap != null && roleMap.containsKey(roleId)) { + builder.append(roleMap.get(roleId)); + builder.append(COMMA); + } + } + return builder.length() <= 1 ? StringUtils.EMPTY : builder.substring(0, builder.length() - 1); + } + + @Override + public boolean isCellEditable(int row, int col) { + TableSequences match = TableSequences.match(col); + return match != TableSequences.DesensitizationRuleStatus; + } + + @Override + public UITableEditAction[] createAction() { + return new UITableEditAction[]{ + new AddDesensitizationAction(), + new RemoveDesensitizationAction(parent), + new RefreshTableAction(), + }; + } + + /** + * 获取当前选中的item,可能为null + * + * @return + */ + @Nullable + private TableDataDesensitizationItem getCurrentSelectBean() { + return table.getSelectedRow() == -1 ? + null : + getList().get(table.getSelectedRow()); + } + + /** + * 列名选择下拉框 + */ + private class ColumnNamesComboBox extends AbstractCellEditor implements TableCellEditor { + + private UIComboBox columnNameComboBox; + + ColumnNamesComboBox() { + columnNameComboBox = new UIComboBox(columnNames.toArray(new String[0])); + this.addCellEditorListener(new CellEditorListener() { + @Override + public void editingStopped(ChangeEvent e) { + + TableDataDesensitizationItem desensitizationItem = getCurrentSelectBean(); + if (Objects.nonNull(desensitizationItem)) { + desensitizationItem.setColumnName(columnNames.get(columnNameComboBox.getSelectedIndex())); + fireTableDataChanged(); + } + } + + @Override + public void editingCanceled(ChangeEvent e) { + + } + }); + } + + @Override + public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { + columnNameComboBox.setSelectedItem(getList().get(row).getColumnName()); + return columnNameComboBox; + } + + @Override + public Object getCellEditorValue() { + Object selectedItem = columnNameComboBox.getSelectedItem(); + return Objects.isNull(selectedItem) ? StringUtils.EMPTY : selectedItem.toString(); + } + } + + private class DesensitizationRuleChooser extends AbstractCellEditor implements TableCellEditor { + /** + * 规则选择页面 + */ + private JPanel choosePane; + /** + * 规则名称 + */ + private UITextField ruleNameTextField; + /** + * 规则选择按钮 + */ + private UIButton chooseButton; + + private ActionListener chooseRuleListener = new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + // 重新获取一下本地规则缓存 + refreshCustomRuleCache(); + DesensitizationRulePane rulePane = new DesensitizationRulePane(latestRules); + TableDataDesensitizationItem desensitizationItem = getCurrentSelectBean(); + int selectedRow = table.getSelectedRow(); + BasicDialog ruleDialog = rulePane.showWindowWithCustomSize(SwingUtilities.getWindowAncestor(parent), new DialogActionAdapter() { + @Override + public void doOk() { + DesensitizationRule rule = rulePane.updateBean(); + if (Objects.nonNull(desensitizationItem) && DesensitizationRule.valid(rule)) { + desensitizationItem.setRule(rule); + desensitizationItem.setRuleName(rule.getRuleName()); + // 刷新规则名称、描述、状态 + ruleNameTextField.setText(rule.getRuleName()); + fireTableDataChanged(); + table.getSelectionModel().setSelectionInterval(selectedRow, selectedRow); + } + } + }, BasicDialog.DEFAULT); + ruleDialog.setVisible(true); + } + }; + + DesensitizationRuleChooser() { + // 规则名称展示 + ruleNameTextField = new UITextField(); + ruleNameTextField.setEnabled(false); + // 规则选择按钮 + chooseButton = new UIButton(APOSTROPHE); + chooseButton.setToolTipText(Toolkit.i18nText("Fine-Design_Report_Desensitization_Click_To_Choose_Rule")); + chooseButton.addActionListener(chooseRuleListener); + // 规则选择页面 + Component[][] templateChooserComponent = {{ruleNameTextField, chooseButton}}; + double[] rowSize = {TableLayout.PREFERRED}; + double[] columnSize = {TableLayout.FILL, 22}; + choosePane = TableLayoutHelper.createCommonTableLayoutPane(templateChooserComponent, rowSize, columnSize, 0); + } + + @Override + public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { + ruleNameTextField.setText(getList().get(row).getRule().getRuleName()); + return choosePane; + } + + @Override + public Object getCellEditorValue() { + return ruleNameTextField.getText(); + } + } + + private class DesensitizationRuleDescriptionPane extends AbstractCellEditor implements TableCellEditor { + + private UILabel descriptionLabel; + + DesensitizationRuleDescriptionPane() { + // 规则描述 + this.descriptionLabel = new UILabel(); + } + + /** + * 根据脱敏规则信息,刷新下规则描述文字,主要用于与规则选择器的联动 + * + * @param desensitizationRule + */ + public void refreshDescription(DesensitizationRule desensitizationRule) { + this.descriptionLabel.setText(DesensitizationRule.getDescription(desensitizationRule)); + this.descriptionLabel.setToolTipText(this.descriptionLabel.getText()); + } + + @Override + public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { + refreshDescription(getList().get(row).getRule()); + return descriptionLabel; + } + + @Override + public Object getCellEditorValue() { + return this.descriptionLabel.getText(); + } + } + + /** + * 生效用户组复选框 + */ + private class EffectedRolesChooser extends AbstractCellEditor implements TableCellEditor { + + private UIComboCheckBox rolesCheckBox; + + EffectedRolesChooser() { + this.rolesCheckBox = new UIComboCheckBox(roleMap.values().toArray(), true) { + @Override + protected void setLayoutAndAddComponents() { + // 使用BorderLayout,否则默认使用的FlowLayout会让整个下拉选框使用最小Size,然后TableCell这边会出现空白 + this.setLayout(FRGUIPaneFactory.createBorderLayout()); + this.add(getEditor(), BorderLayout.CENTER); + this.add(getArrowButton(), BorderLayout.EAST); + } + + @Override + protected void setEditorToolTipText(JComponent editor, String text) { + // 选项过多时,已选中的值会做省略显示处理,此处添加一个Tooltips,显示完整值 + if (text != null) { + editor.setToolTipText(text); + } + } + }; + this.addCellEditorListener(new CellEditorListener() { + @Override + public void editingStopped(ChangeEvent e) { + TableDataDesensitizationItem desensitizationItem = getCurrentSelectBean(); + if (Objects.nonNull(desensitizationItem)) { + desensitizationItem.setRoleIds(generateRolesIdsBySelectedValues()); + fireTableDataChanged(); + } + } + + @Override + public void editingCanceled(ChangeEvent e) { + + } + }); + } + + @Override + public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { + rolesCheckBox.setSelectedValues(generateRolesCheckBoxSelectedValues(getList().get(row))); + return rolesCheckBox; + } + + /** + * 根据当前的规则配置信息,生成选中的rolesMap用来展示 + * + * @param desensitizationItem + * @return + */ + private Map generateRolesCheckBoxSelectedValues(TableDataDesensitizationItem desensitizationItem) { + Map result = new HashMap<>(roleMap.size()); + for (Map.Entry roleEntry : roleMap.entrySet()) { + String roleId = roleEntry.getKey(); + String roleName = roleEntry.getValue(); + if (desensitizationItem.getRoleIds().contains(roleId)) { + result.put(roleName, true); + } else { + result.put(roleName, false); + } + } + return result; + } + + /** + * 根据当前的RoleName选择项,生成其对应的RoleId的set存入规则配置信息 + * + * @return + */ + private Set generateRolesIdsBySelectedValues() { + Set result = new LinkedHashSet<>(); + Object[] selectedValues = rolesCheckBox.getSelectedValues(); + for (Object selectedValue : selectedValues) { + String selectedRoleName = (String) selectedValue; + if (roleMap.containsValue(selectedRoleName)) { + Optional> matchedEntry = roleMap.entrySet().stream().filter(entry -> StringUtils.equals(entry.getValue(), selectedRoleName)).findFirst(); + matchedEntry.ifPresent(stringStringEntry -> result.add(stringStringEntry.getKey())); + } + } + return result; + } + + @Override + public Object getCellEditorValue() { + return rolesCheckBox.getSelectedValues(); + } + } + + /** + * 规则状态展示页面 + */ + private class DesensitizationRuleStatusPane extends AbstractCellEditor implements TableCellEditor, TableCellRenderer { + + private UILabel ruleStatusLabel; + + DesensitizationRuleStatusPane() { + // 规则状态 + this.ruleStatusLabel = new UILabel(); + this.ruleStatusLabel.setForeground(Color.RED); + } + + /** + * 根据脱敏规则信息,刷新规则状态,主要用于与规则选择器的联动 + * + * @param currentItem + */ + public void refreshRuleStatus(TableDataDesensitizationItem currentItem) { + DesensitizationRule rule = currentItem.getRule(); + if (needMarkRule(rule)) { + // 非正常规则,根据规则状态展示不同提示文字 + DesensitizationRuleStatus ruleStatus = DesensitizationRuleManager.getInstance().getRuleStatus(rule, latestRules); + this.ruleStatusLabel.setText(Toolkit.i18nText("Fine-Design_Report_Desensitization_Rule_Status_Abnormal")); + this.ruleStatusLabel.setToolTipText(ruleStatus.getDescription()); + } else { + // 正常规则,重置提示Label + this.ruleStatusLabel.setText(StringUtils.EMPTY); + this.ruleStatusLabel.setToolTipText(null); + } + } + + @Override + public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { + refreshRuleStatus(getList().get(row)); + return ruleStatusLabel; + } + + @Override + public Object getCellEditorValue() { + return ruleStatusLabel; + } + + @Override + public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { + refreshRuleStatus(getList().get(row)); + return ruleStatusLabel; + } + } + + private class AddDesensitizationAction extends AddTableRowAction { + + public AddDesensitizationAction() { + this.setName(Toolkit.i18nText("Fine-Design_Report_Desensitization_Add")); + this.setSmallIcon("/com/fr/design/standard/add/add_black", false); + } + + @Override + public void actionPerformed(ActionEvent e) { + super.actionPerformed(e); + // 添加一条空白数据 + addRow(TableDataDesensitizationItem.createDefault()); + fireTableDataChanged(); + table.getSelectionModel().setSelectionInterval(table.getRowCount() - 1, table.getRowCount() - 1); + } + } + + private class RemoveDesensitizationAction extends DeleteAction { + + public RemoveDesensitizationAction(Component component) { + super(component); + this.setName(Toolkit.i18nText("Fine-Design_Basic_Base_Remove")); + this.setSmallIcon("/com/fr/design/standard/remove/remove_red", false); + } + + @Override + public void actionPerformed(ActionEvent e) { + super.actionPerformed(e); + } + } + + private class RefreshTableAction extends UITableEditAction { + + public RefreshTableAction() { + this.setName(Toolkit.i18nText("Fine-Design_Basic_Refresh")); + this.setSmallIcon("/com/fr/design/standard/refresh/refresh", false); + } + + @Override + public void actionPerformed(ActionEvent e) { + // 刷新TableData的规则,主要是为了自动替换掉平台中被修改的规则 + List items = getList(); + Iterator iterator = items.iterator(); + while (iterator.hasNext()) { + TableDataDesensitizationItem item = iterator.next(); + DesensitizationRuleStatus ruleStatus = DesensitizationRuleManager.getInstance().getRuleStatus(item.getRule(), latestRules); + if (ruleStatus == DesensitizationRuleStatus.REMOVED) { + // 规则被移除,则删除整条脱敏Item + iterator.remove(); + } else { + // 规则被修改、禁用等,更新一下规则 + item.setRule(DesensitizationRuleManager.getInstance().getLastedDesentizationRule(item.getRule(), latestRules)); + } + } + fireTableDataChanged(); + } + + @Override + public void checkEnabled() {} + } + + /** + * 规则表-列字段编号 + */ + private enum TableSequences { + + /** + * 数据集列名选择 + */ + ColumnName(0), + + /** + * 规则选择 + */ + DesensitizationRule(1), + + /** + * 规则描述 + */ + DesensitizationRuleDescription(2), + + /** + * 规则生效用户组 + */ + EffectedRoles(3), + + /** + * 规则状态 + */ + DesensitizationRuleStatus(4), + + /** + * 未知,用于无法匹配时的返回 + */ + Unknown(100); + + + private int num; + + TableSequences(int num) { + this.num = num; + } + + public int getNum() { + return num; + } + + /** + * 根据列序号匹配列字段 + * + * @param num + * @return + */ + public static TableSequences match(int num) { + for (TableSequences value : TableSequences.values()) { + if (value.getNum() == num) { + return value; + } + } + return Unknown; + } + } + + /** + * 是否需要对异常规则做标记,需要满足 + * 1. 规则非默认空规则 + * 2. 规则本身异常 + * + * @return + */ + private boolean needMarkRule(DesensitizationRule rule) { + return !rule.equals(DesensitizationRule.createDefaultEmptyRule()) && + DesensitizationRuleManager.getInstance().getRuleStatus(rule, latestRules) != DesensitizationRuleStatus.NORMAL; + } + + /** + * 刷新当前页面的本地规则缓存,查询最新本地规则的逻辑也是使用了缓存,因此无需考虑耗时 + */ + private void refreshCustomRuleCache() { + Map customRules = DesensitizationRuleManager.getInstance().getRulesBySource(DesensitizationRuleSource.CUSTOM); + latestRules.put(DesensitizationRuleSource.CUSTOM, customRules); + } + +} diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/setting/TableDataDesensitizationTablePane.java b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/setting/TableDataDesensitizationTablePane.java new file mode 100644 index 0000000000..6473a02d07 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/setting/TableDataDesensitizationTablePane.java @@ -0,0 +1,153 @@ +package com.fr.design.data.datapane.preview.desensitization.view.setting; + +import com.fr.base.operator.org.OrganizationOperator; +import com.fr.data.desensitize.base.DesensitizationTableData; +import com.fr.data.desensitize.base.TableDataDesensitizationItem; +import com.fr.data.desensitize.rule.DesensitizationRuleManager; +import com.fr.data.desensitize.rule.base.DesensitizationRule; +import com.fr.data.desensitize.rule.base.DesensitizationRuleSource; +import com.fr.design.data.datapane.preview.desensitization.TableDataPreviewDesensitizeManager; +import com.fr.design.data.tabledata.tabledatapane.loading.TipsPane; +import com.fr.design.gui.itableeditorpane.UITableEditorPane; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.log.FineLoggerFactory; +import com.fr.workspace.WorkContext; + +import javax.swing.JPanel; +import javax.swing.SwingWorker; +import java.awt.BorderLayout; +import java.awt.CardLayout; +import java.awt.Component; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * 脱敏字段设置页面中的Table + * + * @author Yvan + * @version 11.0 + * Created by Yvan on 2022/9/14 + */ +public class TableDataDesensitizationTablePane extends JPanel { + + /** + * 脱敏数据集 + */ + private DesensitizationTableData tableData; + + /** + * 父页面 + */ + private Component parent; + + /** + * 脱敏信息Table + */ + private UITableEditorPane editorPane; + + private static final String LOADING_PANE = "loading"; + private static final String CONTENT_PANE = "content"; + + private CardLayout card; + + private JPanel loadingPane; + + private JPanel contentPane; + + public TableDataDesensitizationTablePane(DesensitizationTableData tableData, Component parent) { + this.tableData = tableData; + this.parent = parent; + initComponent(); + } + + private void initComponent() { + + card = new CardLayout(); + this.setLayout(card); + // 初始化Loading面板 + loadingPane = new TipsPane(true); + this.add(LOADING_PANE, loadingPane); + switchTo(LOADING_PANE); + + // 在SwingWorker中初始化Content面板并切换 + initContent(); + } + + /** + * 初始化内容面板 + * 考虑到远程设计下的性能,需要限制查询数据库的次数,所以这里查一次,之后子面板内复用 + */ + private void initContent() { + final List columnNames = new ArrayList<>(); + final Map roleMap = new LinkedHashMap<>(); + final Map> latestRules = new LinkedHashMap<>(); + new SwingWorker() { + + @Override + protected Void doInBackground() throws Exception { + // 获取当前数据集的所有列名 + columnNames.addAll(TableDataPreviewDesensitizeManager.getInstance().getColumnNamesByTableData(tableData)); + // 获取当前所有用户组 + roleMap.putAll(WorkContext.getCurrent().get(OrganizationOperator.class).getAllRoles4Desensitization()); + // 获取当前最新的所有规则 + latestRules.putAll(DesensitizationRuleManager.getInstance().getAllRules()); + return null; + } + + @Override + protected void done() { + contentPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); + editorPane = new UITableEditorPane<>(new TableDataDesensitizationTableModel(tableData, parent, columnNames, roleMap, latestRules)); + editorPane.setHeaderResizing(false); + editorPane.populate(tableData.getDesensitizationConfig().getDesensitizationItems().toArray(new TableDataDesensitizationItem[0])); + contentPane.add(editorPane, BorderLayout.CENTER); + add(CONTENT_PANE, contentPane); + switchTo(CONTENT_PANE); + } + }.execute(); + } + + /** + * 切换面板 + * + * @param panelName + */ + public void switchTo(String panelName) { + try { + if (panelName != null) { + card.show(this, panelName); + } + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + } + } + + /** + * 展示此TableData中已配置的脱敏规则信息 + * + * @param tableData + */ + public void populateDesensitizationSetting(DesensitizationTableData tableData) { + this.tableData = tableData; + if (editorPane != null) { + // editorPane的初始化在SwingWorker中完成,这里做个判空 + editorPane.populate(tableData.getDesensitizationConfig().getDesensitizationItems().toArray(new TableDataDesensitizationItem[0])); + } + } + + /** + * 获取当前对TableData的配置脱敏规则信息 + */ + public List updateDesensitizationSetting() { + + return editorPane == null ? + new ArrayList<>() : + editorPane.update() + .stream() + .filter(item -> TableDataDesensitizationItem.valid(item)) + .collect(Collectors.toList()); + } +} diff --git a/designer-base/src/main/java/com/fr/design/env/LocalDesignerWorkspaceInfo.java b/designer-base/src/main/java/com/fr/design/env/LocalDesignerWorkspaceInfo.java index ec8d997c3c..d3fb4268da 100644 --- a/designer-base/src/main/java/com/fr/design/env/LocalDesignerWorkspaceInfo.java +++ b/designer-base/src/main/java/com/fr/design/env/LocalDesignerWorkspaceInfo.java @@ -1,6 +1,7 @@ package com.fr.design.env; import com.fr.general.ComparatorUtils; +import com.fr.stable.CommonUtils; import com.fr.stable.CoreConstants; import com.fr.stable.StableUtils; import com.fr.stable.StringUtils; @@ -98,11 +99,17 @@ public class LocalDesignerWorkspaceInfo implements DesignerWorkspaceInfo { @Override public boolean checkValid(){ + File file = new File(this.path); //判断不是文件夹/路径不在WEB-INF下/代码启动三种情况 if(!file.isDirectory() || !ComparatorUtils.equals(file.getName(), "WEB-INF") || this.path.startsWith(".")) { return false; } + + // 如果当前是 debug 模式,就不检测是否 mainVersion 不一致 + if (CommonUtils.isDebug()) { + return true; + } File engineLib = new File(StableUtils.pathJoin(this.path, ProjectConstants.LIB_NAME, REPORT_ENGINE_JAR)); // 非安装版本允许自由切换 diff --git a/designer-base/src/main/java/com/fr/design/extra/PluginUtils.java b/designer-base/src/main/java/com/fr/design/extra/PluginUtils.java index 521821eadf..f12f8f8446 100644 --- a/designer-base/src/main/java/com/fr/design/extra/PluginUtils.java +++ b/designer-base/src/main/java/com/fr/design/extra/PluginUtils.java @@ -10,8 +10,8 @@ import com.fr.json.JSONObject; import com.fr.log.FineLoggerFactory; import com.fr.plugin.PluginVerifyException; import com.fr.plugin.basic.version.Version; -import com.fr.plugin.basic.version.VersionIntervalType; import com.fr.plugin.basic.version.VersionIntervalFactory; +import com.fr.plugin.basic.version.VersionIntervalType; import com.fr.plugin.context.PluginContext; import com.fr.plugin.context.PluginMarker; import com.fr.plugin.error.PluginBaseErrorCode; @@ -23,7 +23,7 @@ import com.fr.stable.ProductConstants; import com.fr.stable.StableUtils; import com.fr.stable.StringUtils; -import javax.swing.*; +import javax.swing.JOptionPane; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -47,9 +47,10 @@ public class PluginUtils { public static PluginMarker createPluginMarker(String pluginInfo) { - //todo 判空 - String[] plugin = pluginInfo.split("_"); - return PluginMarker.create(plugin[0], plugin[1]); + int splitIndex = pluginInfo.lastIndexOf("_"); + String pluginID = pluginInfo.substring(0, splitIndex); + String version = pluginInfo.substring(splitIndex + 1); + return PluginMarker.create(pluginID, version); } public static JSONObject getLatestPluginInfo(String pluginID) throws Exception { diff --git a/designer-base/src/main/java/com/fr/design/file/DefaultTemplateTreeDefineProcessor.java b/designer-base/src/main/java/com/fr/design/file/DefaultTemplateTreeDefineProcessor.java index feb1e696fd..1bcfe3c622 100644 --- a/designer-base/src/main/java/com/fr/design/file/DefaultTemplateTreeDefineProcessor.java +++ b/designer-base/src/main/java/com/fr/design/file/DefaultTemplateTreeDefineProcessor.java @@ -28,6 +28,7 @@ import com.fr.stable.StableUtils; import com.fr.stable.StringUtils; import com.fr.stable.collections.CollectionUtils; import com.fr.stable.project.ProjectConstants; +import com.fr.workspace.WorkContext; import javax.swing.BorderFactory; import javax.swing.JDialog; @@ -229,7 +230,13 @@ public class DefaultTemplateTreeDefineProcessor extends AbstractTemplateTreeDefi } //确定目标目录并检查权限 FileOperations selectedOperation = DesignerFrameFileDealerPane.getInstance().getSelectedOperation(); - if (!selectedOperation.access()) { + boolean rootAuthority = true; + if (selectedOperation.getFileNode() == null && selectedOperation instanceof TemplateTreePane) { + //没有选中文件节点时,默认粘贴到根目录下,所以直接检测根目录是否有权限 + ExpandMutableTreeNode root = (ExpandMutableTreeNode) ((TemplateTreePane) selectedOperation).getTemplateFileTree().getModel().getRoot(); + rootAuthority = root.hasFullAuthority(); + } + if (!rootAuthority && !selectedOperation.access()) { FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Toolkit.i18nText("Fine-Design_Basic_Template_Permission_Denied"), Toolkit.i18nText("Fine-Design_Basic_Alert"), diff --git a/designer-base/src/main/java/com/fr/design/file/FileOperationHelper.java b/designer-base/src/main/java/com/fr/design/file/FileOperationHelper.java index 21eb34d902..a3abaf4606 100644 --- a/designer-base/src/main/java/com/fr/design/file/FileOperationHelper.java +++ b/designer-base/src/main/java/com/fr/design/file/FileOperationHelper.java @@ -127,7 +127,7 @@ public class FileOperationHelper { WARNING_MESSAGE); return StringUtils.EMPTY; } - String name = getNoRepeatedName4Paste(targetDir, sourceFile.getName()); + String name = getNoRepeatedName4Paste(targetDir, sourceFile); String targetFile = StableUtils.pathJoin(targetDir, name); if (sourceFile.isDirectory()) { copyDir(sourcePath, targetFile, withCopyVcs); @@ -177,19 +177,22 @@ public class FileOperationHelper { * 重名处理 * * @param targetDir - * @param oldName + * @param sourceFile * @return */ - private String getNoRepeatedName4Paste(String targetDir, String oldName) { + private String getNoRepeatedName4Paste(String targetDir, FileNode sourceFile) { + String oldName = sourceFile.getName(); while (isNameRepeaded(targetDir, oldName)) { - int index = oldName.lastIndexOf("."); - if (index > 0) { - String oName = oldName.substring(0, index); - oName = oName + Toolkit.i18nText("Fine-Design_Table_Data_Copy_Of_Table_Data"); - oldName = oName.concat(oldName.substring(index)); - } else { + if (sourceFile.isDirectory()) { //目录重名 oldName = oldName + Toolkit.i18nText("Fine-Design_Table_Data_Copy_Of_Table_Data"); + } else { + int index = oldName.lastIndexOf("."); + if (index > 0) { + String oName = oldName.substring(0, index); + oName = oName + Toolkit.i18nText("Fine-Design_Table_Data_Copy_Of_Table_Data"); + oldName = oName.concat(oldName.substring(index)); + } } } return oldName; diff --git a/designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java b/designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java index d7f46ea76b..86820aa227 100644 --- a/designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java +++ b/designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java @@ -75,7 +75,7 @@ public class HistoryTemplateListCache implements CallbackEvent { historyList.remove(contains(selected)); selected.getEditingFILE().closeTemplate(); FineLoggerFactory.getLogger().info(Toolkit.i18nText("Fine-Design_Basic_Template_Closed_Warn_Text", selected.getEditingFILE().getName())); - MutilTempalteTabPane.getInstance().refreshOpenedTemplate(historyList); + MultiTemplateTabPane.getInstance().refreshOpenedTemplate(historyList); } catch (Exception e) { FineLoggerFactory.getLogger().error(e.getMessage(), e); } @@ -134,10 +134,10 @@ public class HistoryTemplateListCache implements CallbackEvent { if (contains(jt) == -1) { addHistory(); } - MutilTempalteTabPane.getInstance().refreshOpenedTemplate(historyList); + MultiTemplateTabPane.getInstance().refreshOpenedTemplate(historyList); //设置tab栏为当前选中的那一栏 if (editingTemplate != null) { - MutilTempalteTabPane.getInstance().setSelectedIndex(contains(jt)); + MultiTemplateTabPane.getInstance().setSelectedIndex(contains(jt)); } } @@ -274,7 +274,7 @@ public class HistoryTemplateListCache implements CallbackEvent { historyList.set(i, new JVirtualTemplate(overTemplate.getEditingFILE())); } } - MutilTempalteTabPane.getInstance().refreshOpenedTemplate(historyList); + MultiTemplateTabPane.getInstance().refreshOpenedTemplate(historyList); } @@ -297,7 +297,7 @@ public class HistoryTemplateListCache implements CallbackEvent { int index = iterator.nextIndex(); if (size == index + 1 && index > 0) { //如果删除的是后一个Tab,则定位到前一个 - MutilTempalteTabPane.getInstance().setSelectedIndex(index - 1); + MultiTemplateTabPane.getInstance().setSelectedIndex(index - 1); } } } @@ -307,13 +307,13 @@ public class HistoryTemplateListCache implements CallbackEvent { DesignerContext.getDesignerFrame().addAndActivateJTemplate(); } - JTemplate selectedFile = MutilTempalteTabPane.getInstance().getSelectedFile(); + JTemplate selectedFile = MultiTemplateTabPane.getInstance().getSelectedFile(); if (!isCurrentEditingFile(selectedFile.getPath())) { //如果此时面板上的实时刷新的selectedIndex得到的和历史的不一样 DesignerContext.getDesignerFrame().activateJTemplate(selectedFile); } - MutilTempalteTabPane.getInstance().repaint(); + MultiTemplateTabPane.getInstance().repaint(); } @@ -474,7 +474,7 @@ public class HistoryTemplateListCache implements CallbackEvent { int index = contains(this.editingTemplate); this.editingTemplate = jt; historyList.set(index, jt); - MutilTempalteTabPane.getInstance().refreshOpenedTemplate(historyList); - MutilTempalteTabPane.getInstance().setSelectedIndex(contains(jt)); + MultiTemplateTabPane.getInstance().refreshOpenedTemplate(historyList); + MultiTemplateTabPane.getInstance().setSelectedIndex(contains(jt)); } } diff --git a/designer-base/src/main/java/com/fr/design/file/MultiTemplateTabPane.java b/designer-base/src/main/java/com/fr/design/file/MultiTemplateTabPane.java new file mode 100644 index 0000000000..646f0e517a --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/file/MultiTemplateTabPane.java @@ -0,0 +1,1243 @@ +package com.fr.design.file; + + +import com.fr.base.BaseUtils; +import com.fr.base.GraphHelper; +import com.fr.base.vcs.DesignerMode; +import com.fr.design.actions.UpdateAction; +import com.fr.design.actions.file.LocateAction; +import com.fr.design.constants.UIConstants; +import com.fr.design.dialog.FineJOptionPane; +import com.fr.design.gui.imenu.UIMenuItem; +import com.fr.design.gui.imenu.UIPopupMenu; +import com.fr.design.gui.imenu.UIScrollPopUpMenu; +import com.fr.design.i18n.DesignSizeI18nManager; +import com.fr.design.i18n.Toolkit; +import com.fr.design.mainframe.DesignerContext; +import com.fr.design.mainframe.JTemplate; +import com.fr.design.mainframe.TemplateSavingChecker; +import com.fr.design.mainframe.manager.search.TemplateTreeSearchManager; +import com.fr.design.utils.DesignUtils; +import com.fr.design.utils.TemplateUtils; +import com.fr.design.utils.gui.GUICoreUtils; +import com.fr.design.utils.gui.GUIPaintUtils; +import com.fr.design.worker.WorkerManager; +import com.fr.design.worker.save.CallbackSaveWorker; +import com.fr.file.FILE; +import com.fr.general.ComparatorUtils; +import com.fr.general.IOUtils; +import com.fr.log.FineLoggerFactory; +import com.fr.stable.Constants; +import com.fr.third.javax.annotation.Nonnull; +import com.fr.workspace.WorkContext; +import com.fr.workspace.server.lock.TplOperator; + +import javax.swing.BorderFactory; +import javax.swing.ButtonModel; +import javax.swing.Icon; +import javax.swing.ImageIcon; +import javax.swing.JComponent; +import javax.swing.JMenu; +import javax.swing.JMenuItem; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JSeparator; +import javax.swing.MenuElement; +import javax.swing.SwingConstants; +import javax.swing.SwingUtilities; +import javax.swing.plaf.basic.BasicMenuItemUI; +import java.awt.AWTEvent; +import java.awt.AlphaComposite; +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.GradientPaint; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.RenderingHints; +import java.awt.event.AWTEventListener; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.awt.event.MouseMotionListener; +import java.awt.geom.Arc2D; +import java.awt.geom.GeneralPath; +import java.awt.geom.Line2D; +import java.awt.geom.Path2D; +import java.awt.geom.RoundRectangle2D; +import java.util.List; + +import static com.fr.design.dialog.FineJOptionPane.showConfirmDialog; +import static javax.swing.JOptionPane.OK_CANCEL_OPTION; +import static javax.swing.JOptionPane.OK_OPTION; +import static javax.swing.JOptionPane.WARNING_MESSAGE; + +/** + * 改个名字,一个拼写 n 个错误 + * + * @author daisy + * @version 11.0 + *

+ * created by daisy on 2013/08/05 + **/ +public class MultiTemplateTabPane extends JComponent { + + private static Icon LIST_DOWN = BaseUtils.readIcon("/com/fr/design/images/buttonicon/list_normal.png"); + private static Icon MOUSE_OVER_LIST_DOWN = BaseUtils.readIcon("/com/fr/design/images/buttonicon/list_pressed.png"); + private static Icon MOUSE_PRESS_LIST_DOWN = BaseUtils.readIcon("/com/fr/design/images/buttonicon/list_pressed.png"); + private static Icon CLOSE = BaseUtils.readIcon("/com/fr/design/images/buttonicon/close_icon.png"); + private static Icon MOUSE_OVER_CLOSE = BaseUtils.readIcon("/com/fr/design/images/buttonicon/mouseoverclose icon.png"); + private static Icon MOUSE_PRESS_CLOSE = BaseUtils.readIcon("/com/fr/design/images/buttonicon/pressclose icon.png"); + private static final Icon WHITE_SAVING_CLOSE_ICON = new ImageIcon(IOUtils.readImage("/com/fr/design/images/file/white_saving_close.gif")); + private static final Icon GREY_SAVING_CLOSE_ICON = new ImageIcon(IOUtils.readImage("/com/fr/design/images/file/grey_saving_close.gif")); + private static final String ELLIPSIS = "..."; + private static final int GAP = 5; + private static final int SMALLGAP = 3; + private static final int LIST_BUTTON_WIDTH = 34; + private static final int HEIGHT = 26; + private static final int LIST_DOWN_HEIGHT = 25; + private static final double CORNOR_RADIUS = 0.0; + //选了30度和60度的特殊角度的x,y作为经过的两个点的坐标 + private static final double SPECIAL_LOCATION_1 = 2.5; + private static final double SPECIAL_LOCATION_2 = 4.330127; + private static final int ICON_WIDTH = 22; + + + //每个标签页的最大的长度和最小长度。这些长度均为均分 + + private static final int MAXWIDTH = 240; + private static final int MINWIDTH = 100; + + + private static MultiTemplateTabPane THIS; + //用于存放工作簿 + private java.util.List> openedTemplate; + //选中的Tab项 + private int selectedIndex = 0; + // + private int mouseOveredIndex = -1; + + //tab栏可以放下的每个tab的实际宽度 + private int realWidth = MAXWIDTH; + + + //当前标签页栏存放的所有标签页的index + private int minPaintIndex = 0; + private int maxPaintIndex = 0; + + //每个关闭图标的起始位置 + private int[] startX; + + private boolean[] isNeedToolTips; + + //记录关闭按钮的状态 + private int closeIconIndex = -1; + private boolean isCloseCurrent = false; + private Icon clodeMode = CLOSE; + private Icon listDownMode = LIST_DOWN; + private boolean isShowList = false; + + //自动新建的模板B若没有进行任何编辑,切换到其他 + // + // 模板时,模板B会自动关闭 + private JTemplate temTemplate = null; + + + public static MultiTemplateTabPane getInstance() { + if (THIS == null) { + THIS = new MultiTemplateTabPane(); + } + return THIS; + } + + + /** + * 多工作簿面板 + */ + public MultiTemplateTabPane() { + this.setLayout(new BorderLayout(0, 0)); + this.addMouseListener(new MultiTemplateTabMouseListener()); + this.addMouseMotionListener(new MultiTemplateTabMouseMotionListener()); + this.setBorder(null); + this.setForeground(new Color(58, 56, 58)); + this.setFont(DesignUtils.getDefaultGUIFont().applySize(12)); + openedTemplate = HistoryTemplateListCache.getInstance().getHistoryList(); + selectedIndex = openedTemplate.size() - 1; + AWTEventListener awt = new AWTEventListener() { + @Override + public void eventDispatched(AWTEvent event) { + if (event instanceof MouseEvent) { + MouseEvent mv = (MouseEvent) event; + if (mv.getClickCount() > 0 && !ComparatorUtils.equals(mv.getSource(), MultiTemplateTabPane.this)) { + isShowList = false; + } + } + } + + }; + java.awt.Toolkit.getDefaultToolkit().addAWTEventListener(awt, AWTEvent.MOUSE_EVENT_MASK); + addMouseListener(new MouseAdapter() { + @Override + public void mousePressed(MouseEvent e) { + if (SwingUtilities.isRightMouseButton(e)) { + int tplIndex = getTemplateIndex(e.getX()); + if (tplIndex > -1) { + UIPopupMenu menu = new UIPopupMenu(); + menu.setBorder(BorderFactory.createEmptyBorder(-3, 3, 3, 0)); + + for (CloseOption option : CloseOption.values()) { + menu.add(new UIMenuItem(new RightMenuCloseAction(option, tplIndex))); + } + menu.add(new CloseMenuItemJSeparator()); + menu.add(new UIMenuItem(new OpenInTemplateTreeAction(tplIndex))); + + int height = 0; + for (MenuElement subElement : menu.getSubElements()) { + if (subElement instanceof CloseMenuItemJSeparator) { + height += 10; + } else { + height += 25; + } + } + //根据当前i18n语言环境,动态调整popupMenu的宽度 + menu.setPreferredSize(new Dimension((int) DesignSizeI18nManager.getInstance(). + i18nDimension("com.fr.design.file.MultiTemplateTabPane.popUpMenu").getWidth(), height)); + GUICoreUtils.showPopupMenu(menu, MultiTemplateTabPane.getInstance(), e.getX(), MultiTemplateTabPane.getInstance().getY() - 1 + MultiTemplateTabPane.getInstance().getHeight()); + } + } + } + }); + } + + enum CloseOption { + Left(Toolkit.i18nText("Fine-Design_Close_templates_To_The_Left")) { + @Override + boolean shouldClose(int tplIndex, int i) { + return i < tplIndex; + } + }, + Right(Toolkit.i18nText("Fine-Design_Close_templates_To_The_Right")) { + @Override + boolean shouldClose(int tplIndex, int i) { + return i > tplIndex; + } + }, + All(Toolkit.i18nText("Fine-Design_Close_All_templates")), + Others(Toolkit.i18nText("Fine-Design_Close_Other_templates")) { + @Override + boolean shouldClose(int tplIndex, int i) { + return i != tplIndex; + } + }; + + + String optionName; + + CloseOption(String optionName) { + this.optionName = optionName; + } + + boolean shouldClose(int tplIndex, int i) { + return true; + } + } + + private static class CloseMenuItemJSeparator extends JSeparator { + @Override + public Dimension getPreferredSize() { + Dimension d = super.getPreferredSize(); + d.height = 1; + return d; + } + + @Override + public Color getForeground() { + return UIConstants.PRESSED_DARK_GRAY; + } + } + + + private class OpenInTemplateTreeAction extends LocateAction { + + int tplIndex; + + public OpenInTemplateTreeAction(int tplIndex) { + this.tplIndex = tplIndex; + this.setName(Toolkit.i18nText("Fine-Design_Open_In_Template_Tree")); + } + + @Override + public void actionPerformed(ActionEvent e) { + //处于搜索模式时,先退出搜索模式,再定位 + if (TemplateTreeSearchManager.getInstance().isInSearchMode()) { + TemplateTreeSearchManager.getInstance().outOfSearchMode(); + TemplateTreePane.getInstance().refreshDockingView(); + } + JTemplate template = openedTemplate.get(this.tplIndex); + locateTemplate(template); + } + + private void locateTemplate(JTemplate template) { + FILE currentTemplate = template.getEditingFILE(); + //模板不属于当前环境,跟预览一样先提示保存,再定位模板 + if (!currentTemplate.exists()) { + int selVal = showConfirmDialog( + DesignerContext.getDesignerFrame(), + Toolkit.i18nText("Fine-Design_Basic_Web_Preview_Message"), + Toolkit.i18nText("Fine-Design_Basic_Preview_Tool_Tips"), + OK_CANCEL_OPTION, + WARNING_MESSAGE + ); + if (OK_OPTION == selVal) { + CallbackSaveWorker worker = template.saveAs(); + worker.start(template.getRuntimeId()); + worker.addSuccessCallback(new Runnable() { + @Override + public void run() { + gotoEditingTemplateLeaf(template.getPath()); + } + }); + } + } else { + gotoEditingTemplateLeaf(template.getPath()); + } + } + } + + private class RightMenuCloseAction extends UpdateAction { + + CloseOption option; + int tplIndex = -1; + + public RightMenuCloseAction(CloseOption option, int tplIndex) { + this.option = option; + this.setName(option.optionName); + this.tplIndex = tplIndex; + } + + + @Override + public void actionPerformed(ActionEvent e) { + SaveSomeTemplatePane saveSomeTempaltePane = new SaveSomeTemplatePane(false); + if (saveSomeTempaltePane.showSavePane()) { + + JTemplate[] templates = new JTemplate[openedTemplate.size()]; + for (int i = 0; i < openedTemplate.size(); i++) { + templates[i] = openedTemplate.get(i); + } + JTemplate currentTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); + closeTemplate(templates, currentTemplate); + + if (option == CloseOption.All) { + DesignerContext.getDesignerFrame().addAndActivateJTemplate(); + } else { + DesignerContext.getDesignerFrame().activateJTemplate(currentTemplate); + } + + MultiTemplateTabPane.getInstance().repaint(); + } + } + + private void closeTemplate(JTemplate[] templates, JTemplate currentTemplate) { + for (int i = 0; i < templates.length; i++) { + if (option.shouldClose(tplIndex, i)) { + JTemplate jTemplate = templates[i]; + if (jTemplate == currentTemplate) { + currentTemplate = option == CloseOption.All ? null : templates[tplIndex]; + } + //判断关闭的模板是不是格式刷的被参照的模板 + openedTemplate.remove(jTemplate); + if (jTemplate != currentTemplate) { + MultiTemplateTabPane.getInstance().closeFormat(jTemplate); + HistoryTemplateListCache.getInstance().closeSelectedReport(jTemplate); + closeAndFreeLock(jTemplate); + } + } + } + } + + private void closeAndFreeLock(@Nonnull JTemplate template) { + FILE file = template.getEditingFILE(); + // 只有是环境内的文件,才执行释放锁 + if (file != null && file.isEnvFile()) { + // release lock + WorkContext.getCurrent().get(TplOperator.class).closeAndFreeFile(file.getPath()); + } + } + } + + public JTemplate getSelectedFile() { + if (openedTemplate.size() == selectedIndex) { + selectedIndex = Math.max(--selectedIndex, 0); + } + return openedTemplate.get(selectedIndex); + } + + + /** + * 关闭掉当前已打开文件列表中指定的文件 + * + * @param file 指定的文件 + */ + public void closeFileTemplate(FILE file) { + for (JTemplate temp : openedTemplate) { + if (ComparatorUtils.equals(file, temp.getEditingFILE())) { + closeSpecifiedTemplate(temp); + break; + } + } + + } + + @Override + public Dimension getPreferredSize() { + Dimension dimension = super.getPreferredSize(); + dimension.height = HEIGHT; + return dimension; + } + + private UIMenuItem initCloseOther() { + UIMenuItem closeOther = new UIMenuItem(Toolkit.i18nText("Fine-Design_Basic_FS_Close_Other_Templates")); + // Yvan: 英文下文本显示不全,后续发现如果将模板名设置的比较短,其它语言也会出现显示不全的问题,所以设置一下文本水平居中 + closeOther.setHorizontalAlignment(SwingConstants.CENTER); + setListDownItemPreferredSize(closeOther); + closeOther.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if (openedTemplate.size() == 1) { + return; + } + if (!TemplateSavingChecker.check()) { + return; + } + SaveSomeTemplatePane saveSomeTempaltePane = new SaveSomeTemplatePane(false); + //点击关闭其他模板,并且点击确定保存 + if (saveSomeTempaltePane.showSavePane()) { + JTemplate[] panes = new JTemplate[openedTemplate.size()]; + for (int i = 0; i < openedTemplate.size(); i++) { + panes[i] = openedTemplate.get(i); + } + for (int i = 0; i < panes.length; i++) { + if (i != selectedIndex) { + JTemplate jTemplate = panes[i]; + //判断关闭的模板是不是格式刷的被参照的模板 + openedTemplate.remove(jTemplate); + closeFormat(jTemplate); + HistoryTemplateListCache.getInstance().closeSelectedReport(jTemplate); + closeAndFreeLock(jTemplate); + } + } + JTemplate currentTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); + HistoryTemplateListCache.getInstance().removeAllHistory(); + DesignerContext.getDesignerFrame().activateJTemplate(currentTemplate); + THIS.repaint(); + } + //如果取消保存了,则不关闭其他模板 + } + }); + if (openedTemplate.size() == 1) { + closeOther.setEnabled(false); + } + return closeOther; + } + + + private UIMenuItem[] createListDownTemplate() { + UIMenuItem[] templates = new UIMenuItem[openedTemplate.size()]; + for (int i = 0; i < openedTemplate.size(); i++) { + final int index = i; + final JTemplate tem = openedTemplate.get(i); + templates[i] = new UIMenuItem(tempalteShowName(tem), tem.getIcon()); + templates[i].setUI(new UIListDownItemUI()); + setListDownItemPreferredSize(templates[i]); + if (i == selectedIndex) { + //画选中的高亮 + templates[i].setBackground(UIConstants.SHADOW_CENTER); + } + templates[i].addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + selectedIndex = index; + tem.activeNewJTemplate(); + } + }); + } + return templates; + } + + private void setListDownItemPreferredSize(UIMenuItem item) { + Dimension dimension = item.getPreferredSize(); + dimension.height = LIST_DOWN_HEIGHT; + item.setPreferredSize(dimension); + } + + + private String tempalteShowName(JTemplate template) { + String name = TemplateUtils.createLockeTemplatedName(template, template.getTemplateName()); + if (!template.isSaved() && !name.endsWith(" *")) { + name += " *"; + } + return name; + } + + /** + * 刷新打开模板 + * + * @param history 模板 + */ + public void refreshOpenedTemplate(List> history) { + openedTemplate = history; + } + + public void setTemTemplate(JTemplate auotCreate) { + temTemplate = auotCreate; + } + + + private void showListDown() { + + UIScrollPopUpMenu menu = new UIScrollPopUpMenu(); + menu.setBorder(BorderFactory.createEmptyBorder(-3, 3, 3, 0)); + menu.add(initCloseOther()); + JSeparator separator = new JSeparator() { + @Override + public Dimension getPreferredSize() { + Dimension d = super.getPreferredSize(); + d.height = 1; + return d; + } + }; + menu.add(new JPanel() { + @Override + public Dimension getPreferredSize() { + Dimension d = super.getPreferredSize(); + d.height = 1; + return d; + } + }); + separator.setForeground(UIConstants.LINE_COLOR); + menu.add(separator); + menu.add(new JPanel() { + @Override + public Dimension getPreferredSize() { + Dimension d = super.getPreferredSize(); + d.height = 1; + return d; + } + }); + UIMenuItem[] items = createListDownTemplate(); + for (int i = 0; i < items.length; i++) { + menu.add(items[i]); + } + GUICoreUtils.showPopupMenu(menu, MultiTemplateTabPane.getInstance(), MultiTemplateTabPane.getInstance().getWidth() - menu.getPreferredSize().width, getY() - 1 + getHeight()); + } + + + public void setSelectedIndex(int index) { + selectedIndex = index; + } + + + @Override + public void paintComponent(Graphics g) { + super.paintComponent(g); + double maxWidth = getWidth() - LIST_BUTTON_WIDTH * 1.0D; //最大宽度 + Graphics2D g2d = (Graphics2D) g; + paintBackgroundAndLine(g2d, maxWidth); + } + + + @Override + public void paint(Graphics g) { + //不可见时,按钮.4f透明 + AlphaComposite composite = DesignerMode.isVcsMode() + ? AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f) + : (AlphaComposite) ((Graphics2D) g).getComposite(); + ((Graphics2D) g).setComposite(composite); + super.paint(g); + } + + private void paintBackgroundAndLine(Graphics2D g2d, double maxWidth) { + paintDefaultBackground(g2d); + //最多能画的个数 + int maxTemplateNum = (int) (maxWidth) / MINWIDTH; + //计算开始画的最小模板index和最大模板index + calMinAndMaxIndex(maxTemplateNum); + calculateRealAverageWidth(maxWidth, maxTemplateNum); + int maxStringlength = calculateStringMaxLength(); + if (selectedIndex >= openedTemplate.size()) { + selectedIndex = openedTemplate.size() - 1; + } + if (selectedIndex < 0) { + selectedIndex = 0; + } + double templateStartX = 0; + startX = new int[maxPaintIndex - minPaintIndex + 1]; + isNeedToolTips = new boolean[maxPaintIndex - minPaintIndex + 1]; + + //从可以开始展示在tab面板上的tab开始画 + for (int i = minPaintIndex; i <= maxPaintIndex; i++) { + JTemplate template = openedTemplate.get(i); + Icon icon = template.getIcon(); + String name = tempalteShowName(template); + //如果tab名字的长度大于最大能显示的英文字符长度,则进行省略号处理 + if (getStringWidth(name) > maxStringlength) { + name = getEllipsisName(name, maxStringlength); + isNeedToolTips[i - minPaintIndex] = true; + } else { + isNeedToolTips[i - minPaintIndex] = false; + } + + Icon selectedIcon; + if (i == closeIconIndex) { + selectedIcon = clodeMode; + } else { + selectedIcon = CLOSE; + } + if (i == selectedIndex) { + if (template.isSaving()) { + selectedIcon = WHITE_SAVING_CLOSE_ICON; + } + startX[i - minPaintIndex] = paintSelectedTab(g2d, icon, templateStartX, name, selectedIcon); + } else { + if (template.isSaving()) { + selectedIcon = GREY_SAVING_CLOSE_ICON; + } + boolean isLeft = i < selectedIndex; + startX[i - minPaintIndex] = paintUnSelectedTab(g2d, icon, templateStartX, name, selectedIcon, isLeft, mouseOveredIndex, i); + } + templateStartX += realWidth; + } + + if (!DesignerMode.isVcsMode()) { + paintListDown(g2d, maxWidth); + } + paintUnderLine(templateStartX, maxWidth, g2d); + } + + + private void paintUnderLine(double templateStartX, double maxWidth, Graphics2D g2d) { + //画下面的那条线 + if (templateStartX < maxWidth) { + GeneralPath generalPath = new GeneralPath(Path2D.WIND_EVEN_ODD, 2); + generalPath.moveTo((float) templateStartX, (float) (getHeight() - 1.0D)); + generalPath.lineTo((float) maxWidth, (float) (getHeight() - 1.0D)); + g2d.fill(generalPath); + //TODO hzzz delete +// g2d.setPaint(UIConstants.LINE_COLOR); +// g2d.draw(new Line2D.Double((float) templateStartX, getHeight() - 1, (float) maxWidth + LIST_BUTTON_WIDTH, getHeight() - 1)); + } + } + + private void paintDefaultBackground(Graphics2D g2d) { + //画默认背景 + g2d.setPaint(new GradientPaint(1, 1, UIConstants.TEMPLATE_TAB_PANE_BACKGROUND, 1, (float) (getHeight() - 1.0D), UIConstants.TEMPLATE_TAB_PANE_BACKGROUND)); + g2d.fillRect(0, 0, getWidth(), getHeight()); + } + + + private void paintListDown(Graphics2D g2d, double maxWidth) { + int x = (int) maxWidth + (LIST_BUTTON_WIDTH - listDownMode.getIconWidth()) / 2; + int y = (getHeight() - listDownMode.getIconHeight()) / 2; + listDownMode.paintIcon(this, g2d, x, y); + } + + /** + * 判断tab文字的长度大于能装下的最大文字长度,要用省略号 + * + * @param name + * @param maxStringlength + * @return + */ + private String getEllipsisName(String name, int maxStringlength) { + + //若是名字长度大于能显示的长度,那能显示的文字的最大长度还要减去省略号的最大长度 +// int maxellipsislength = maxStringlength - ELLIPSIS.length(); + int ellipsisWidth = getStringWidth(ELLIPSIS); + int leftkeyPoint = 0; + int rightKeyPoint = name.length() - 1; + int leftStrWidth = 0; + int rightStrWidth = 0; + while (leftStrWidth + rightStrWidth + ellipsisWidth < maxStringlength) { + if (leftStrWidth <= rightStrWidth) { + leftkeyPoint++; + } else { + rightKeyPoint--; + } + leftStrWidth = getStringWidth(name.substring(0, leftkeyPoint)); + rightStrWidth = getStringWidth(name.substring(rightKeyPoint)); + + if (leftStrWidth + rightStrWidth + ellipsisWidth > maxStringlength) { + if (leftStrWidth <= rightStrWidth) { + rightKeyPoint++; + } + break; + } + } + + return name.substring(0, leftkeyPoint) + ELLIPSIS + name.substring(rightKeyPoint); + } + + private void calMinAndMaxIndex(int maxTemplateNum) { + //如果个数大于最多能容纳的个数,则多余的进行处理 + if (openedTemplate.size() > maxTemplateNum) { + //所点击列表中的标签页处在标签页栏最后一个标签页之后,则标签页栏左移至所点击标签页出现 + if (selectedIndex >= maxPaintIndex) { + minPaintIndex = selectedIndex - maxTemplateNum + 1; + maxPaintIndex = selectedIndex; + if (minPaintIndex <= 0) { + minPaintIndex = 0; + maxPaintIndex = maxTemplateNum - 1; + } + } else if (selectedIndex <= minPaintIndex) { + //所点击列表中的标签页处在标签页栏第一个标签页之前,则标签页栏右移至所点击标签页出现 + minPaintIndex = selectedIndex; + maxPaintIndex = minPaintIndex + maxTemplateNum - 1; + if (maxPaintIndex > openedTemplate.size() - 1) { + maxPaintIndex = openedTemplate.size() - 1; + } + } else { + if (selectedIndex >= openedTemplate.size() - 1) { + selectedIndex = openedTemplate.size() - 1; + maxPaintIndex = selectedIndex; + minPaintIndex = selectedIndex - maxTemplateNum + 1; + } else { + maxPaintIndex = minPaintIndex + maxTemplateNum - 1; + if (maxPaintIndex > openedTemplate.size() - 1) { + maxPaintIndex = openedTemplate.size() - 1; + } + } + } + } else { + minPaintIndex = 0; + maxPaintIndex = openedTemplate.size() - 1; + } + } + + + //个数小于最多能容纳的个数的情况下,看看宽度每个要画多少 + private void calculateRealAverageWidth(double maxwidth, int templateNum) { + + int num = openedTemplate.size() > templateNum ? templateNum : openedTemplate.size(); + realWidth = (int) (maxwidth / (num)); + if (realWidth > MAXWIDTH) { + realWidth = MAXWIDTH; + } else if (realWidth < MINWIDTH) { + //平均下来每个的宽度小于最小宽度 + realWidth = MINWIDTH; + } + } + + /** + * 计算过长度之后的每个tab的能接受的文字的英文字符数 + * + * @return + */ + private int calculateStringMaxLength() { + return realWidth - 3 * GAP - ICON_WIDTH - SMALLGAP - CLOSE.getIconWidth(); + + } + + private int getStringWidth(String str) { + return GraphHelper.getFontMetrics(this.getFont()).stringWidth(str); + } + + + /** + * 画选中的tab + * + * @param g2d + * @param sheeticon + * @param templateStartX + * @param sheetName + * @param closeIcon + * @return + */ + private int paintSelectedTab(Graphics2D g2d, Icon sheeticon, double templateStartX, String sheetName, Icon closeIcon) { + double[] x = {templateStartX, templateStartX, templateStartX + realWidth, templateStartX + realWidth, templateStartX}; + double[] y = {1, getHeight() + 1, getHeight() + 1, 1, 1}; + RoundRectangle2D.Double rect1 = new RoundRectangle2D.Double(templateStartX, 1, this.getWidth(), this.getHeight(), 7, 7); + g2d.setPaint(new GradientPaint(1, 1, UIConstants.SELECT_TAB, 1, (float) (getHeight() - 1.0D), UIConstants.SELECT_TAB)); + //选了30度和60度的特殊角度的x,y作为经过的两个点的坐标 + double specialLocation1 = 2.5; + double specialLocation2 = 4.330127; + GeneralPath generalPath = new GeneralPath(Path2D.WIND_EVEN_ODD, x.length); + generalPath.moveTo((float) x[0] + CORNOR_RADIUS, (float) y[0]); + generalPath.curveTo(((float) x[0] + CORNOR_RADIUS - specialLocation1), (y[0] + CORNOR_RADIUS - specialLocation2), ((float) x[0] + CORNOR_RADIUS - specialLocation2), (y[0] + CORNOR_RADIUS - specialLocation1), x[0], y[0] + CORNOR_RADIUS); + + for (int index = 1; index <= 2; index++) { + generalPath.lineTo((float) x[index], (float) y[index]); + } + + generalPath.lineTo((float) x[3], (float) y[3] + CORNOR_RADIUS); + generalPath.curveTo(((float) x[3] - CORNOR_RADIUS + specialLocation1), ((float) y[3] + CORNOR_RADIUS - specialLocation2), ((float) x[3] - CORNOR_RADIUS + specialLocation2), ((float) y[3] + CORNOR_RADIUS - specialLocation1), (float) x[3] - CORNOR_RADIUS, (float) y[3]); + generalPath.lineTo((float) x[0] + CORNOR_RADIUS, (float) y[0]); + + generalPath.closePath(); + g2d.fill(generalPath); + g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + g2d.setPaint(new Color(200, 201, 205)); + g2d.draw(new Arc2D.Double(x[0], y[0], CORNOR_RADIUS * 2, CORNOR_RADIUS * 2, 90, 90, 0)); + g2d.draw(new Line2D.Double(x[0], y[0] + CORNOR_RADIUS, x[1], y[1])); + g2d.draw(new Line2D.Double(x[1], y[1], x[2], y[2])); + g2d.draw(new Line2D.Double(x[2], y[2], x[3], y[3] + CORNOR_RADIUS)); + g2d.draw(new Arc2D.Double(x[3] - CORNOR_RADIUS * 2, y[3], CORNOR_RADIUS * 2, CORNOR_RADIUS * 2, 90, -90, 0)); + g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); + int sheetIconY = (getHeight() - sheeticon.getIconHeight()) / 2; + sheeticon.paintIcon(this, g2d, (int) templateStartX + GAP, sheetIconY); + // 画字符 + g2d.setPaint(getForeground()); + g2d.drawString(sheetName, (int) templateStartX + sheeticon.getIconWidth() + 2 * GAP, getHeight() - GAP * 2); + int closePosition = (int) templateStartX + realWidth - CLOSE.getIconWidth() - SMALLGAP; + int closeY = (getHeight() - closeIcon.getIconHeight()) / 2; + if (!DesignerMode.isVcsMode()) { + closeIcon.paintIcon(this, g2d, closePosition, closeY); + } + return closePosition; + + } + + /** + * 画没有选中的tab + * + * @param g2d + * @param sheeticon + * @param templateStartX + * @param sheetName + * @param closeIcon + * @param isLeft + * @return + */ + private int paintUnSelectedTab(Graphics2D g2d, Icon sheeticon, double templateStartX, String sheetName, Icon closeIcon, boolean isLeft, int mouseOveredIndex, int selfIndex) { + double[] x = {templateStartX, templateStartX, templateStartX + realWidth, templateStartX + realWidth, templateStartX}; + double[] y = {-1, getHeight() - 1, getHeight() - 1, -1, -1}; + if (selfIndex == mouseOveredIndex) { + g2d.setPaint(new GradientPaint(1, 1, UIConstants.HOVER_BLUE, 1, (float) (getHeight() - 1.0D), UIConstants.HOVER_BLUE)); + } else { + g2d.setPaint(new GradientPaint(1, 1, UIConstants.SHADOW_GREY, 1, (float) (getHeight() - 1.0D), UIConstants.SHADOW_GREY)); + } + + + GeneralPath generalPath = new GeneralPath(Path2D.WIND_EVEN_ODD, x.length); + + unSelectedClosedPath(generalPath, isLeft, x, y); + g2d.fill(generalPath); + g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + g2d.setPaint(UIConstants.TEMPLATE_TAB_PANE_BACKGROUND); + //TODO hzzz delete +// if (isLeft) { +// g2d.draw(new Arc2D.Double(x[0], y[0], CORNOR_RADIUS * 2, CORNOR_RADIUS * 2, 90, 90, 0)); +// } else { +// g2d.draw(new Arc2D.Double(x[0] - CORNOR_RADIUS * 2, y[0], CORNOR_RADIUS * 2, CORNOR_RADIUS * 2, 90, -90, 0)); +// } + +// g2d.draw(new Line2D.Double(x[0], y[0] + CORNOR_RADIUS, x[1], y[1] + 1)); +// g2d.draw(new Line2D.Double(x[1], y[1], x[2], y[2])); + g2d.draw(new Line2D.Double(x[2], y[2], x[3], y[3] + CORNOR_RADIUS)); +// if (isLeft) { +// g2d.draw(new Arc2D.Double(x[3], y[3], CORNOR_RADIUS * 2, CORNOR_RADIUS * 2, 90, 90, 0)); +// } else { +// g2d.draw(new Arc2D.Double(x[3] - CORNOR_RADIUS * 2, y[3], CORNOR_RADIUS * 2, CORNOR_RADIUS * 2, 90, -90, 0)); +// } + + g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); + int sheetIconY = (getHeight() - sheeticon.getIconHeight()) / 2; + sheeticon.paintIcon(this, g2d, (int) templateStartX + GAP, sheetIconY); + // 画字符 + g2d.setPaint(getForeground()); + g2d.drawString(sheetName, (int) templateStartX + sheeticon.getIconWidth() + 2 * GAP, getHeight() - GAP * 2); + int closeY = (getHeight() - closeIcon.getIconHeight()) / 2; + int closePosition = (int) templateStartX + realWidth - CLOSE.getIconWidth() - SMALLGAP; + if (!DesignerMode.isVcsMode()) { + closeIcon.paintIcon(this, g2d, closePosition, closeY); + } + return closePosition; + } + + + private void unSelectedClosedPath(GeneralPath generalPath, boolean isLeft, double[] x, double[] y) { + + if (isLeft) { + generalPath.moveTo((float) x[0] + CORNOR_RADIUS, (float) y[0]); + generalPath.curveTo(((float) x[0] + CORNOR_RADIUS - SPECIAL_LOCATION_1), (y[0] + CORNOR_RADIUS - SPECIAL_LOCATION_2), ((float) x[0] + CORNOR_RADIUS - SPECIAL_LOCATION_2), (y[0] + CORNOR_RADIUS - SPECIAL_LOCATION_1), x[0], y[0] + CORNOR_RADIUS); + } else { + generalPath.moveTo((float) x[0] - CORNOR_RADIUS, (float) y[0]); + generalPath.curveTo(((float) x[0] - CORNOR_RADIUS + SPECIAL_LOCATION_1), (y[0] + CORNOR_RADIUS - SPECIAL_LOCATION_2), ((float) x[0] - CORNOR_RADIUS + SPECIAL_LOCATION_2), (y[0] + CORNOR_RADIUS - SPECIAL_LOCATION_1), x[0], y[0] + CORNOR_RADIUS); + } + + for (int index = 1; index <= 2; index++) { + generalPath.lineTo((float) x[index], (float) y[index]); + } + + generalPath.lineTo((float) x[3], (float) y[3] + CORNOR_RADIUS); + + if (isLeft) { + generalPath.curveTo(((float) x[3] + CORNOR_RADIUS - SPECIAL_LOCATION_1), ((float) y[3] + CORNOR_RADIUS - SPECIAL_LOCATION_2), ((float) x[3] + CORNOR_RADIUS - SPECIAL_LOCATION_2), ((float) y[3] - CORNOR_RADIUS + SPECIAL_LOCATION_1), (float) x[3] + CORNOR_RADIUS, (float) y[3]); + generalPath.lineTo((float) x[0] + CORNOR_RADIUS, (float) y[0]); + } else { + generalPath.curveTo(((float) x[3] - CORNOR_RADIUS + SPECIAL_LOCATION_1), ((float) y[3] + CORNOR_RADIUS - SPECIAL_LOCATION_2), ((float) x[3] - CORNOR_RADIUS + SPECIAL_LOCATION_2), ((float) y[3] + CORNOR_RADIUS - SPECIAL_LOCATION_1), (float) x[3] - CORNOR_RADIUS, (float) y[3]); + generalPath.lineTo((float) x[0] - CORNOR_RADIUS, (float) y[0]); + } + + generalPath.closePath(); + } + + + public void setIsCloseCurrent(boolean isCloseCurrent) { + this.isCloseCurrent = isCloseCurrent; + + } + + /** + * 关闭模板 + * + * @param specifiedTemplate 模板 + */ + public void closeSpecifiedTemplate(JTemplate specifiedTemplate) { + if (specifiedTemplate == null) { + return; + } + + if (!specifiedTemplate.isALLSaved() && !DesignerMode.isVcsMode()) { + specifiedTemplate.stopEditing(); + int returnVal = FineJOptionPane.showConfirmDialog(DesignerContext.getDesignerFrame(), Toolkit.i18nText("Fine-Design_Basic_Utils_Would_You_Like_To_Save") + " \"" + specifiedTemplate.getEditingFILE() + "\" ?", + Toolkit.i18nText("Fine-Design_Basic_Confirm"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); + if (returnVal == JOptionPane.YES_OPTION) { + CallbackSaveWorker worker = specifiedTemplate.save(); + worker.addSuccessCallback(new Runnable() { + @Override + public void run() { + FineLoggerFactory.getLogger().info(Toolkit.i18nText("Fine-Design_Basic_Template_Already_Saved", specifiedTemplate.getEditingFILE().getName())); + closeTpl(specifiedTemplate); + } + }); + worker.start(specifiedTemplate.getRuntimeId()); + } else if (returnVal == JOptionPane.NO_OPTION) { + closeTpl(specifiedTemplate); + } + } else { + closeTpl(specifiedTemplate); + } + + } + + private void closeTpl(@Nonnull JTemplate specifiedTemplate) { + HistoryTemplateListCache.getInstance().closeSelectedReport(specifiedTemplate); + closeAndFreeLock(specifiedTemplate); + activePrevTemplateAfterClose(); + } + + private void closeAndFreeLock(@Nonnull JTemplate template) { + FILE file = template.getEditingFILE(); + // 只有是环境内的文件,才执行释放锁 + if (file != null && file.isEnvFile()) { + // release lock + TemplateResourceManager.getResource().closeTemplate(file.getPath()); + } + } + + /** + * 后台关闭当前编辑模板 + */ + public void closeCurrentTpl() { + JTemplate jTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); + this.setIsCloseCurrent(true); + this.closeFormat(jTemplate); + this.closeSpecifiedTemplate(jTemplate); + } + + /** + * 关闭模板 + * + * @param closedTemplate 模板 + */ + public void closeFormat(JTemplate closedTemplate) { + //表单不需要处理 + if (!closedTemplate.isJWorkBook()) { + return; + } + + if (DesignerContext.getFormatState() == DesignerContext.FORMAT_STATE_NULL) { + return; + } + + //是被参照的模板被关闭,则重置格式刷 + closedTemplate.doConditionCancelFormat(); + } + + /** + * 关闭掉一个模板之后激活新的待显示模板 + */ + public void activePrevTemplateAfterClose() { + if (openedTemplate.isEmpty()) { + //新建并激活模板 + DesignerContext.getDesignerFrame().addAndActivateJTemplate(); + selectedIndex = 0; + //此时刚自动新建的模板在HistoryTemplateListCache的editingTemplate + temTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); + + } else { + // 如果关闭的模板是当前选中的模板,则重新激活当前 selectIndex 的模板; + // selectIndex 没有变化,但是对应的模板已经变成了前一张模板 + if (closeIconIndex == selectedIndex || isCloseCurrent) { + // 如果当前关闭的模板在最右侧,那么预览上一个,防止数组越界 + if (selectedIndex >= maxPaintIndex) { + // selectIndex 不会 <0 因为如果关闭的是打开的最后一个模板,那么关闭之后 openedTemplate.isEmpty() = true + selectedIndex--; + } + isCloseCurrent = false; + } + // 如果关闭的模板不是当前选中的模板,那么重新获取一下当前模板的 index,激活该 index + else { + JTemplate template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); + selectedIndex = HistoryTemplateListCache.getInstance().contains(template); + } + if (selectedIndex < openedTemplate.size()) { + //如果是已后台关闭的模板,则重新打开文件 + openedTemplate.get(selectedIndex).activeOldJTemplate(); + } + + } + } + + + private boolean isOverCloseIcon(int evtX) { + boolean isOverCloseIcon = false; + for (int i = 0; i < startX.length; i++) { + if (evtX >= startX[i] && evtX <= startX[i] + CLOSE.getIconWidth()) { + isOverCloseIcon = true; + break; + } + } + return isOverCloseIcon; + } + + + private boolean isOverListDown(int evtX) { + int maxWidth = getWidth() - LIST_BUTTON_WIDTH; + return evtX >= (maxWidth + SMALLGAP) && evtX <= (getWidth() - SMALLGAP); + } + + + private int getTemplateIndex(int evtX) { + int textX = 0; + for (int i = minPaintIndex; i <= maxPaintIndex; i++) { + int textWidth = realWidth; + if (evtX >= textX && evtX < textX + textWidth) { + return i; + } + textX += textWidth; + } + return -1; + } + + + /** + * 处理自动新建的模板 在切换时的处理 + */ + public void doWithtemTemplate() { + //temtemplate保存的一定是手动新建的没有编辑或是编辑了没有保存的模板 + //没有保存,说明有编辑;已经保存在磁盘里的文件,说明有过处理,并且已经保存,此时切换都不将其自动关闭 + if (temTemplate == null || temTemplate == HistoryTemplateListCache.getInstance().getCurrentEditingTemplate()) { + return; + } + + if (!temTemplate.isSaved() || !temTemplate.getEditingFILE().isMemFile()) { + temTemplate = null; + } + + //自动新建的模板B若没有进行任何编辑(新建模板没有进行任何编辑时saved都是true):还没有存盘 + if (temTemplate != null && temTemplate.getEditingFILE().isMemFile() && temTemplate.isSaved()) { + HistoryTemplateListCache.getInstance().closeSelectedReport(temTemplate); + temTemplate = null; + setSelectedIndex(HistoryTemplateListCache.getInstance().contains(HistoryTemplateListCache.getInstance().getCurrentEditingTemplate())); + } + } + + private class UIListDownItemUI extends BasicMenuItemUI { + @Override + protected void paintBackground(Graphics g, JMenuItem menuItem, Color bgColor) { + if (menuItem.getIcon() == null) { + super.paintBackground(g, menuItem, bgColor); + return; + } + ButtonModel model = menuItem.getModel(); + Color oldColor = g.getColor(); + int menuWidth = menuItem.getWidth(); + int menuHeight = menuItem.getHeight(); + g.setColor(UIConstants.NORMAL_BACKGROUND); + g.fillRect(0, 0, menuWidth, menuHeight); + boolean itemIsSelected = menuItem instanceof JMenu && model.isSelected(); + if (menuItem.isOpaque()) { + if (model.isArmed() || itemIsSelected) { + GUIPaintUtils.fillPaint((Graphics2D) g, GAP, 0, menuWidth - GAP, menuHeight, true, Constants.NULL, UIConstants.FLESH_BLUE, UIConstants.ARC); + } else { + GUIPaintUtils.fillPaint((Graphics2D) g, GAP, 0, menuWidth - GAP, menuHeight, true, Constants.NULL, menuItem.getBackground(), UIConstants.ARC); + } + g.setColor(oldColor); + } else if (model.isArmed() || itemIsSelected) { + GUIPaintUtils.fillPaint((Graphics2D) g, GAP, 0, menuWidth - GAP, menuHeight, true, Constants.NULL, UIConstants.FLESH_BLUE, UIConstants.ARC); + g.setColor(oldColor); + } + } + } + + private class MultiTemplateTabMouseListener implements MouseListener { + + + /** + * 鼠标进入 + * + * @param e 鼠标事件 + */ + @Override + public void mouseEntered(MouseEvent e) { + // do nothing + } + + /** + * 鼠标离开 + * + * @param e 鼠标事件 + */ + @Override + public void mouseExited(MouseEvent e) { + listDownMode = LIST_DOWN; + closeIconIndex = -1; + mouseOveredIndex = -1; + MultiTemplateTabPane.this.repaint(); + } + + /** + * 鼠标释放 + * + * @param e 鼠标事件 + */ + @Override + public void mouseReleased(MouseEvent e) { + // do nothing + } + + /** + * 点击 + * + * @param e 鼠标事件 + */ + @Override + public void mouseClicked(MouseEvent e) { + // do nothing + } + + /** + * 按下 + * + * @param e 鼠标事件 + */ + @Override + public void mousePressed(MouseEvent e) { + //如果在版本管理情况下,不允许切换tab + if (DesignerMode.isVcsMode()) { + return; + } + + int evtX = e.getX(); + + //是否点击关闭按钮 如果点击了关闭按钮,则将点击的模板关闭,不需要切换,如果没有点击关闭按钮,则切换到点击的模板处 + boolean isOverCloseIcon = isOverCloseIcon(evtX); + if (isOverListDown(evtX)) { + listDownMode = isOverListDown(evtX) ? MOUSE_PRESS_LIST_DOWN : LIST_DOWN; + if (!isShowList) { + showListDown(); + } + isShowList = !isShowList; + + } else if (isOverCloseIcon) { + //关闭按钮的图标变化 + closeIconIndex = getTemplateIndex(evtX); + clodeMode = MOUSE_PRESS_CLOSE; + //关闭close图标所在的模板{ + JTemplate template = openedTemplate.get(closeIconIndex); + if (template.isOpening()) { + WorkerManager.getInstance().cancelWorker(template.getPath()); + } else if (template.isSaving()) { + boolean completed = WorkerManager.getInstance().isCompleted(template.getTarget().getTemplateID()); + if (!completed) { + FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), + Toolkit.i18nText("Fine-Design_Close_Template_Tip", template.getEditingFILE().getName())); + return; + } + } + closeFormat(template); + closeSpecifiedTemplate(template); + DesignerContext.getDesignerFrame().getContentFrame().repaint(); + isShowList = false; + } else { + //没有点击关闭和ListDown按钮,则切换到点击的模板处 + closeIconIndex = -1; + clodeMode = CLOSE; + int tempSelectedIndex = selectedIndex; + if (selectedIndex != getTemplateIndex(evtX) && getTemplateIndex(evtX) != -1) { + openedTemplate.get(selectedIndex).stopEditing(); + selectedIndex = getTemplateIndex(evtX); + //如果在权限编辑情况下,不允许切换到表单类型的工作簿 + if (DesignerMode.isAuthorityEditing() && !openedTemplate.get(selectedIndex).isJWorkBook()) { + DesignerContext.getDesignerFrame().addAndActivateJTemplate(openedTemplate.get(tempSelectedIndex)); + FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Toolkit.i18nText("Fine-Design_Basic_Form_Authority_Edited_Cannot_Be_Supported") + + "!", Toolkit.i18nText("Fine-Design_Basic_Alert"), JOptionPane.WARNING_MESSAGE); + MultiTemplateTabPane.this.repaint(); + return; + } + JTemplate evtXTemplate = openedTemplate.get(getTemplateIndex(evtX)); + evtXTemplate.activeNewJTemplate(); + } + isShowList = false; + } + MultiTemplateTabPane.this.repaint(); + + + } + + + } + + private class MultiTemplateTabMouseMotionListener implements MouseMotionListener { + /** + * 鼠标拖拽 + * + * @param e 鼠标事件 + */ + @Override + public void mouseDragged(MouseEvent e) { + // do nothing + } + + /** + * 鼠标移动 + * + * @param e 鼠标事件 + */ + @Override + public void mouseMoved(MouseEvent e) { + int evtX = e.getX(); + mouseOveredIndex = getTemplateIndex(evtX); + + //看是否需要显示toolTip + if (mouseOveredIndex != -1 && isNeedToolTips[mouseOveredIndex - minPaintIndex]) { + setToolTipText(openedTemplate.get(mouseOveredIndex).getEditingFILE().getName()); + } else { + setToolTipText(null); + } + + listDownMode = isOverListDown(evtX) ? MOUSE_OVER_LIST_DOWN : LIST_DOWN; + + boolean isOverCloseIcon = isOverCloseIcon(evtX); + clodeMode = isOverCloseIcon ? MOUSE_OVER_CLOSE : CLOSE; + closeIconIndex = isOverCloseIcon ? mouseOveredIndex : -1; + MultiTemplateTabPane.this.repaint(); + } + } + + +} diff --git a/designer-base/src/main/java/com/fr/design/file/MutilTempalteTabPane.java b/designer-base/src/main/java/com/fr/design/file/MutilTempalteTabPane.java index 480edea346..36e0b58754 100644 --- a/designer-base/src/main/java/com/fr/design/file/MutilTempalteTabPane.java +++ b/designer-base/src/main/java/com/fr/design/file/MutilTempalteTabPane.java @@ -1,1237 +1,24 @@ package com.fr.design.file; - -import com.fr.base.BaseUtils; -import com.fr.base.GraphHelper; -import com.fr.base.vcs.DesignerMode; -import com.fr.design.actions.UpdateAction; -import com.fr.design.actions.file.LocateAction; -import com.fr.design.constants.UIConstants; -import com.fr.design.dialog.FineJOptionPane; -import com.fr.design.gui.imenu.UIMenuItem; -import com.fr.design.gui.imenu.UIPopupMenu; -import com.fr.design.gui.imenu.UIScrollPopUpMenu; -import com.fr.design.i18n.Toolkit; -import com.fr.design.mainframe.DesignerContext; -import com.fr.design.mainframe.JTemplate; -import com.fr.design.mainframe.TemplateSavingChecker; -import com.fr.design.mainframe.manager.search.TemplateTreeSearchManager; -import com.fr.design.utils.DesignUtils; -import com.fr.design.utils.gui.GUICoreUtils; -import com.fr.design.utils.gui.GUIPaintUtils; -import com.fr.design.worker.WorkerManager; -import com.fr.design.utils.TemplateUtils; -import com.fr.design.worker.save.CallbackSaveWorker; -import com.fr.file.FILE; -import com.fr.general.ComparatorUtils; -import com.fr.general.IOUtils; -import com.fr.log.FineLoggerFactory; -import com.fr.stable.Constants; -import com.fr.third.javax.annotation.Nonnull; -import com.fr.workspace.WorkContext; -import com.fr.workspace.server.lock.TplOperator; - -import javax.swing.BorderFactory; -import javax.swing.ButtonModel; -import javax.swing.Icon; -import javax.swing.ImageIcon; -import javax.swing.JComponent; -import javax.swing.JMenu; -import javax.swing.JMenuItem; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JSeparator; -import javax.swing.MenuElement; -import javax.swing.SwingConstants; -import javax.swing.SwingUtilities; -import javax.swing.plaf.basic.BasicMenuItemUI; -import java.awt.AWTEvent; -import java.awt.AlphaComposite; -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Dimension; -import java.awt.GradientPaint; -import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.RenderingHints; -import java.awt.event.AWTEventListener; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; -import java.awt.event.MouseMotionListener; -import java.awt.geom.Arc2D; -import java.awt.geom.GeneralPath; -import java.awt.geom.Line2D; -import java.awt.geom.Path2D; -import java.awt.geom.RoundRectangle2D; -import java.util.List; - -import static com.fr.design.dialog.FineJOptionPane.showConfirmDialog; -import static javax.swing.JOptionPane.OK_CANCEL_OPTION; -import static javax.swing.JOptionPane.OK_OPTION; -import static javax.swing.JOptionPane.WARNING_MESSAGE; - /** - * Author : daisy - * Date: 13-8-5 - * Time: 下午6:12 + * @author shine + * @version 10.0 + * Created by shine on 2022/11/25 + * fvs plugin jartime升级到2022-12-2之后就可以删了 */ -public class MutilTempalteTabPane extends JComponent { - - private static Icon LIST_DOWN = BaseUtils.readIcon("/com/fr/design/images/buttonicon/list_normal.png"); - private static Icon MOUSE_OVER_LIST_DOWN = BaseUtils.readIcon("/com/fr/design/images/buttonicon/list_pressed.png"); - private static Icon MOUSE_PRESS_LIST_DOWN = BaseUtils.readIcon("/com/fr/design/images/buttonicon/list_pressed.png"); - private static Icon CLOSE = BaseUtils.readIcon("/com/fr/design/images/buttonicon/close_icon.png"); - private static Icon MOUSE_OVER_CLOSE = BaseUtils.readIcon("/com/fr/design/images/buttonicon/mouseoverclose icon.png"); - private static Icon MOUSE_PRESS_CLOSE = BaseUtils.readIcon("/com/fr/design/images/buttonicon/pressclose icon.png"); - private static final Icon WHITE_SAVING_CLOSE_ICON = new ImageIcon(IOUtils.readImage("/com/fr/design/images/file/white_saving_close.gif")); - private static final Icon GREY_SAVING_CLOSE_ICON = new ImageIcon(IOUtils.readImage("/com/fr/design/images/file/grey_saving_close.gif")); - private static final String ELLIPSIS = "..."; - private static final int GAP = 5; - private static final int SMALLGAP = 3; - private static final int LIST_BUTTON_WIDTH = 34; - private static final int HEIGHT = 26; - private static final int LIST_DOWN_HEIGHT = 25; - private static final double CORNOR_RADIUS = 0.0; - //选了30度和60度的特殊角度的x,y作为经过的两个点的坐标 - private static final double SPECIAL_LOCATION_1 = 2.5; - private static final double SPECIAL_LOCATION_2 = 4.330127; - private static final int ICON_WIDTH = 22; - - - //每个标签页的最大的长度和最小长度。这些长度均为均分 - - private static final int MAXWIDTH = 240; - private static final int MINWIDTH = 100; - - - private static MutilTempalteTabPane THIS; - //用于存放工作簿 - private java.util.List> openedTemplate; - //选中的Tab项 - private int selectedIndex = 0; - // - private int mouseOveredIndex = -1; - - //tab栏可以放下的每个tab的实际宽度 - private int realWidth = MAXWIDTH; - - - //当前标签页栏存放的所有标签页的index - private int minPaintIndex = 0; - private int maxPaintIndex = 0; - - //每个关闭图标的起始位置 - private int[] startX; - - private boolean[] isNeedToolTips; - - //记录关闭按钮的状态 - private int closeIconIndex = -1; - private boolean isCloseCurrent = false; - private Icon clodeMode = CLOSE; - private Icon listDownMode = LIST_DOWN; - private boolean isShowList = false; - - //自动新建的模板B若没有进行任何编辑,切换到其他 - // - // 模板时,模板B会自动关闭 - private JTemplate temTemplate = null; - +@Deprecated +public class MutilTempalteTabPane { public static MutilTempalteTabPane getInstance() { - if (THIS == null) { - THIS = new MutilTempalteTabPane(); - } - return THIS; + return new MutilTempalteTabPane(); } + public void setIsCloseCurrent(boolean b) { + MultiTemplateTabPane.getInstance().setIsCloseCurrent(b); - /** - * 多工作簿面板 - */ - public MutilTempalteTabPane() { - this.setLayout(new BorderLayout(0, 0)); - this.addMouseListener(new MultiTemplateTabMouseListener()); - this.addMouseMotionListener(new MultiTemplateTabMouseMotionListener()); - this.setBorder(null); - this.setForeground(new Color(58, 56, 58)); - this.setFont(DesignUtils.getDefaultGUIFont().applySize(12)); - openedTemplate = HistoryTemplateListCache.getInstance().getHistoryList(); - selectedIndex = openedTemplate.size() - 1; - AWTEventListener awt = new AWTEventListener() { - @Override - public void eventDispatched(AWTEvent event) { - if (event instanceof MouseEvent) { - MouseEvent mv = (MouseEvent) event; - if (mv.getClickCount() > 0 && !ComparatorUtils.equals(mv.getSource(), MutilTempalteTabPane.this)) { - isShowList = false; - } - } - } - - }; - java.awt.Toolkit.getDefaultToolkit().addAWTEventListener(awt, AWTEvent.MOUSE_EVENT_MASK); - addMouseListener(new MouseAdapter() { - @Override - public void mousePressed(MouseEvent e) { - if (SwingUtilities.isRightMouseButton(e)) { - int tplIndex = getTemplateIndex(e.getX()); - if (tplIndex > -1) { - UIPopupMenu menu = new UIPopupMenu(); - menu.setBorder(BorderFactory.createEmptyBorder(-3, 3, 3, 0)); - - for (CloseOption option : CloseOption.values()) { - menu.add(new UIMenuItem(new RightMenuCloseAction(option, tplIndex))); - } - menu.add(new CloseMenuItemJSeparator()); - menu.add(new UIMenuItem(new OpenInTemplateTreeAction(tplIndex))); - - int height = 0; - for (MenuElement subElement : menu.getSubElements()) { - if (subElement instanceof CloseMenuItemJSeparator) { - height += 10; - } else { - height += 25; - } - } - menu.setPreferredSize(new Dimension(170, height)); - GUICoreUtils.showPopupMenu(menu, MutilTempalteTabPane.getInstance(), e.getX(), MutilTempalteTabPane.getInstance().getY() - 1 + MutilTempalteTabPane.getInstance().getHeight()); - } - } - } - }); } - enum CloseOption { - Left(Toolkit.i18nText("Fine-Design_Close_templates_To_The_Left")) { - @Override - boolean shouldClose(int tplIndex, int i) { - return i < tplIndex; - } - }, - Right(Toolkit.i18nText("Fine-Design_Close_templates_To_The_Right")) { - @Override - boolean shouldClose(int tplIndex, int i) { - return i > tplIndex; - } - }, - All(Toolkit.i18nText("Fine-Design_Close_All_templates")), - Others(Toolkit.i18nText("Fine-Design_Close_Other_templates")) { - @Override - boolean shouldClose(int tplIndex, int i) { - return i != tplIndex; - } - }; - - - String optionName; - - CloseOption(String optionName) { - this.optionName = optionName; - } - - boolean shouldClose(int tplIndex, int i) { - return true; - } - } - - private static class CloseMenuItemJSeparator extends JSeparator { - @Override - public Dimension getPreferredSize() { - Dimension d = super.getPreferredSize(); - d.height = 1; - return d; - } - - @Override - public Color getForeground() { - return UIConstants.PRESSED_DARK_GRAY; - } - } - - - private class OpenInTemplateTreeAction extends LocateAction { - - int tplIndex; - - public OpenInTemplateTreeAction(int tplIndex) { - this.tplIndex = tplIndex; - this.setName(Toolkit.i18nText("Fine-Design_Open_In_Template_Tree")); - } - - @Override - public void actionPerformed(ActionEvent e) { - //处于搜索模式时,先退出搜索模式,再定位 - if (TemplateTreeSearchManager.getInstance().isInSearchMode()) { - TemplateTreeSearchManager.getInstance().outOfSearchMode(); - TemplateTreePane.getInstance().refreshDockingView(); - } - JTemplate template = openedTemplate.get(this.tplIndex); - locateTemplate(template); - } - - private void locateTemplate(JTemplate template) { - FILE currentTemplate = template.getEditingFILE(); - //模板不属于当前环境,跟预览一样先提示保存,再定位模板 - if (!currentTemplate.exists()) { - int selVal = showConfirmDialog( - DesignerContext.getDesignerFrame(), - Toolkit.i18nText("Fine-Design_Basic_Web_Preview_Message"), - Toolkit.i18nText("Fine-Design_Basic_Preview_Tool_Tips"), - OK_CANCEL_OPTION, - WARNING_MESSAGE - ); - if (OK_OPTION == selVal) { - CallbackSaveWorker worker = template.saveAs(); - worker.start(template.getRuntimeId()); - worker.addSuccessCallback(new Runnable() { - @Override - public void run() { - gotoEditingTemplateLeaf(template.getPath()); - } - }); - } - } else { - gotoEditingTemplateLeaf(template.getPath()); - } - } - } - - private class RightMenuCloseAction extends UpdateAction { - - CloseOption option; - int tplIndex = -1; - - public RightMenuCloseAction(CloseOption option, int tplIndex) { - this.option = option; - this.setName(option.optionName); - this.tplIndex = tplIndex; - } - - - @Override - public void actionPerformed(ActionEvent e) { - SaveSomeTemplatePane saveSomeTempaltePane = new SaveSomeTemplatePane(false); - if (saveSomeTempaltePane.showSavePane()) { - - JTemplate[] templates = new JTemplate[openedTemplate.size()]; - for (int i = 0; i < openedTemplate.size(); i++) { - templates[i] = openedTemplate.get(i); - } - JTemplate currentTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); - closeTemplate(templates, currentTemplate); - - if (option == CloseOption.All) { - DesignerContext.getDesignerFrame().addAndActivateJTemplate(); - } else { - DesignerContext.getDesignerFrame().activateJTemplate(currentTemplate); - } - - MutilTempalteTabPane.getInstance().repaint(); - } - } - - private void closeTemplate(JTemplate[] templates, JTemplate currentTemplate) { - for (int i = 0; i < templates.length; i++) { - if (option.shouldClose(tplIndex, i)) { - JTemplate jTemplate = templates[i]; - if (jTemplate == currentTemplate) { - currentTemplate = option == CloseOption.All ? null : templates[tplIndex]; - } - //判断关闭的模板是不是格式刷的被参照的模板 - openedTemplate.remove(jTemplate); - if (jTemplate != currentTemplate) { - MutilTempalteTabPane.getInstance().closeFormat(jTemplate); - HistoryTemplateListCache.getInstance().closeSelectedReport(jTemplate); - closeAndFreeLock(jTemplate); - } - } - } - } - - private void closeAndFreeLock(@Nonnull JTemplate template) { - FILE file = template.getEditingFILE(); - // 只有是环境内的文件,才执行释放锁 - if (file != null && file.isEnvFile()) { - // release lock - WorkContext.getCurrent().get(TplOperator.class).closeAndFreeFile(file.getPath()); - } - } - } - - public JTemplate getSelectedFile() { - if (openedTemplate.size() == selectedIndex) { - selectedIndex = Math.max(--selectedIndex, 0); - } - return openedTemplate.get(selectedIndex); - } - - - /** - * 关闭掉当前已打开文件列表中指定的文件 - * - * @param file 指定的文件 - */ - public void closeFileTemplate(FILE file) { - for (JTemplate temp : openedTemplate) { - if (ComparatorUtils.equals(file, temp.getEditingFILE())) { - closeSpecifiedTemplate(temp); - break; - } - } - - } - - @Override - public Dimension getPreferredSize() { - Dimension dimension = super.getPreferredSize(); - dimension.height = HEIGHT; - return dimension; - } - - private UIMenuItem initCloseOther() { - UIMenuItem closeOther = new UIMenuItem(Toolkit.i18nText("Fine-Design_Basic_FS_Close_Other_Templates")); - // Yvan: 英文下文本显示不全,后续发现如果将模板名设置的比较短,其它语言也会出现显示不全的问题,所以设置一下文本水平居中 - closeOther.setHorizontalAlignment(SwingConstants.CENTER); - setListDownItemPreferredSize(closeOther); - closeOther.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - if (openedTemplate.size() == 1) { - return; - } - if (!TemplateSavingChecker.check()) { - return; - } - SaveSomeTemplatePane saveSomeTempaltePane = new SaveSomeTemplatePane(false); - //点击关闭其他模板,并且点击确定保存 - if (saveSomeTempaltePane.showSavePane()) { - JTemplate[] panes = new JTemplate[openedTemplate.size()]; - for (int i = 0; i < openedTemplate.size(); i++) { - panes[i] = openedTemplate.get(i); - } - for (int i = 0; i < panes.length; i++) { - if (i != selectedIndex) { - JTemplate jTemplate = panes[i]; - //判断关闭的模板是不是格式刷的被参照的模板 - openedTemplate.remove(jTemplate); - closeFormat(jTemplate); - HistoryTemplateListCache.getInstance().closeSelectedReport(jTemplate); - closeAndFreeLock(jTemplate); - } - } - JTemplate currentTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); - HistoryTemplateListCache.getInstance().removeAllHistory(); - DesignerContext.getDesignerFrame().activateJTemplate(currentTemplate); - THIS.repaint(); - } - //如果取消保存了,则不关闭其他模板 - } - }); - if (openedTemplate.size() == 1) { - closeOther.setEnabled(false); - } - return closeOther; - } - - - private UIMenuItem[] createListDownTemplate() { - UIMenuItem[] templates = new UIMenuItem[openedTemplate.size()]; - for (int i = 0; i < openedTemplate.size(); i++) { - final int index = i; - final JTemplate tem = openedTemplate.get(i); - templates[i] = new UIMenuItem(tempalteShowName(tem), tem.getIcon()); - templates[i].setUI(new UIListDownItemUI()); - setListDownItemPreferredSize(templates[i]); - if (i == selectedIndex) { - //画选中的高亮 - templates[i].setBackground(UIConstants.SHADOW_CENTER); - } - templates[i].addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - selectedIndex = index; - tem.activeNewJTemplate(); - } - }); - } - return templates; - } - - private void setListDownItemPreferredSize(UIMenuItem item) { - Dimension dimension = item.getPreferredSize(); - dimension.height = LIST_DOWN_HEIGHT; - item.setPreferredSize(dimension); - } - - - private String tempalteShowName(JTemplate template) { - String name = TemplateUtils.createLockeTemplatedName(template, template.getTemplateName()); - if (!template.isSaved() && !name.endsWith(" *")) { - name += " *"; - } - return name; - } - - /** - * 刷新打开模板 - * - * @param history 模板 - */ - public void refreshOpenedTemplate(List> history) { - openedTemplate = history; - } - - public void setTemTemplate(JTemplate auotCreate) { - temTemplate = auotCreate; - } - - - private void showListDown() { - - UIScrollPopUpMenu menu = new UIScrollPopUpMenu(); - menu.setBorder(BorderFactory.createEmptyBorder(-3, 3, 3, 0)); - menu.add(initCloseOther()); - JSeparator separator = new JSeparator() { - @Override - public Dimension getPreferredSize() { - Dimension d = super.getPreferredSize(); - d.height = 1; - return d; - } - }; - menu.add(new JPanel() { - @Override - public Dimension getPreferredSize() { - Dimension d = super.getPreferredSize(); - d.height = 1; - return d; - } - }); - separator.setForeground(UIConstants.LINE_COLOR); - menu.add(separator); - menu.add(new JPanel() { - @Override - public Dimension getPreferredSize() { - Dimension d = super.getPreferredSize(); - d.height = 1; - return d; - } - }); - UIMenuItem[] items = createListDownTemplate(); - for (int i = 0; i < items.length; i++) { - menu.add(items[i]); - } - GUICoreUtils.showPopupMenu(menu, MutilTempalteTabPane.getInstance(), MutilTempalteTabPane.getInstance().getWidth() - menu.getPreferredSize().width, getY() - 1 + getHeight()); - } - - - public void setSelectedIndex(int index) { - selectedIndex = index; - } - - - @Override - public void paintComponent(Graphics g) { - super.paintComponent(g); - double maxWidth = getWidth() - LIST_BUTTON_WIDTH * 1.0D; //最大宽度 - Graphics2D g2d = (Graphics2D) g; - paintBackgroundAndLine(g2d, maxWidth); - } - - - @Override - public void paint(Graphics g) { - //不可见时,按钮.4f透明 - AlphaComposite composite = DesignerMode.isVcsMode() - ? AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f) - : (AlphaComposite) ((Graphics2D) g).getComposite(); - ((Graphics2D) g).setComposite(composite); - super.paint(g); - } - - private void paintBackgroundAndLine(Graphics2D g2d, double maxWidth) { - paintDefaultBackground(g2d); - //最多能画的个数 - int maxTemplateNum = (int) (maxWidth) / MINWIDTH; - //计算开始画的最小模板index和最大模板index - calMinAndMaxIndex(maxTemplateNum); - calculateRealAverageWidth(maxWidth, maxTemplateNum); - int maxStringlength = calculateStringMaxLength(); - if (selectedIndex >= openedTemplate.size()) { - selectedIndex = openedTemplate.size() - 1; - } - if (selectedIndex < 0) { - selectedIndex = 0; - } - double templateStartX = 0; - startX = new int[maxPaintIndex - minPaintIndex + 1]; - isNeedToolTips = new boolean[maxPaintIndex - minPaintIndex + 1]; - - //从可以开始展示在tab面板上的tab开始画 - for (int i = minPaintIndex; i <= maxPaintIndex; i++) { - JTemplate template = openedTemplate.get(i); - Icon icon = template.getIcon(); - String name = tempalteShowName(template); - //如果tab名字的长度大于最大能显示的英文字符长度,则进行省略号处理 - if (getStringWidth(name) > maxStringlength) { - name = getEllipsisName(name, maxStringlength); - isNeedToolTips[i - minPaintIndex] = true; - } else { - isNeedToolTips[i - minPaintIndex] = false; - } - - Icon selectedIcon; - if (i == closeIconIndex) { - selectedIcon = clodeMode; - } else { - selectedIcon = CLOSE; - } - if (i == selectedIndex) { - if (template.isSaving()) { - selectedIcon = WHITE_SAVING_CLOSE_ICON; - } - startX[i - minPaintIndex] = paintSelectedTab(g2d, icon, templateStartX, name, selectedIcon); - } else { - if (template.isSaving()) { - selectedIcon = GREY_SAVING_CLOSE_ICON; - } - boolean isLeft = i < selectedIndex; - startX[i - minPaintIndex] = paintUnSelectedTab(g2d, icon, templateStartX, name, selectedIcon, isLeft, mouseOveredIndex, i); - } - templateStartX += realWidth; - } - - if (!DesignerMode.isVcsMode()) { - paintListDown(g2d, maxWidth); - } - paintUnderLine(templateStartX, maxWidth, g2d); - } - - - private void paintUnderLine(double templateStartX, double maxWidth, Graphics2D g2d) { - //画下面的那条线 - if (templateStartX < maxWidth) { - GeneralPath generalPath = new GeneralPath(Path2D.WIND_EVEN_ODD, 2); - generalPath.moveTo((float) templateStartX, (float) (getHeight() - 1.0D)); - generalPath.lineTo((float) maxWidth, (float) (getHeight() - 1.0D)); - g2d.fill(generalPath); - //TODO hzzz delete -// g2d.setPaint(UIConstants.LINE_COLOR); -// g2d.draw(new Line2D.Double((float) templateStartX, getHeight() - 1, (float) maxWidth + LIST_BUTTON_WIDTH, getHeight() - 1)); - } - } - - private void paintDefaultBackground(Graphics2D g2d) { - //画默认背景 - g2d.setPaint(new GradientPaint(1, 1, UIConstants.TEMPLATE_TAB_PANE_BACKGROUND, 1, (float) (getHeight() - 1.0D), UIConstants.TEMPLATE_TAB_PANE_BACKGROUND)); - g2d.fillRect(0, 0, getWidth(), getHeight()); - } - - - private void paintListDown(Graphics2D g2d, double maxWidth) { - int x = (int) maxWidth + (LIST_BUTTON_WIDTH - listDownMode.getIconWidth()) / 2; - int y = (getHeight() - listDownMode.getIconHeight()) / 2; - listDownMode.paintIcon(this, g2d, x, y); - } - - /** - * 判断tab文字的长度大于能装下的最大文字长度,要用省略号 - * - * @param name - * @param maxStringlength - * @return - */ - private String getEllipsisName(String name, int maxStringlength) { - - //若是名字长度大于能显示的长度,那能显示的文字的最大长度还要减去省略号的最大长度 -// int maxellipsislength = maxStringlength - ELLIPSIS.length(); - int ellipsisWidth = getStringWidth(ELLIPSIS); - int leftkeyPoint = 0; - int rightKeyPoint = name.length() - 1; - int leftStrWidth = 0; - int rightStrWidth = 0; - while (leftStrWidth + rightStrWidth + ellipsisWidth < maxStringlength) { - if (leftStrWidth <= rightStrWidth) { - leftkeyPoint++; - } else { - rightKeyPoint--; - } - leftStrWidth = getStringWidth(name.substring(0, leftkeyPoint)); - rightStrWidth = getStringWidth(name.substring(rightKeyPoint)); - - if (leftStrWidth + rightStrWidth + ellipsisWidth > maxStringlength) { - if (leftStrWidth <= rightStrWidth) { - rightKeyPoint++; - } - break; - } - } - - return name.substring(0, leftkeyPoint) + ELLIPSIS + name.substring(rightKeyPoint); - } - - private void calMinAndMaxIndex(int maxTemplateNum) { - //如果个数大于最多能容纳的个数,则多余的进行处理 - if (openedTemplate.size() > maxTemplateNum) { - //所点击列表中的标签页处在标签页栏最后一个标签页之后,则标签页栏左移至所点击标签页出现 - if (selectedIndex >= maxPaintIndex) { - minPaintIndex = selectedIndex - maxTemplateNum + 1; - maxPaintIndex = selectedIndex; - if (minPaintIndex <= 0) { - minPaintIndex = 0; - maxPaintIndex = maxTemplateNum - 1; - } - } else if (selectedIndex <= minPaintIndex) { - //所点击列表中的标签页处在标签页栏第一个标签页之前,则标签页栏右移至所点击标签页出现 - minPaintIndex = selectedIndex; - maxPaintIndex = minPaintIndex + maxTemplateNum - 1; - if (maxPaintIndex > openedTemplate.size() - 1) { - maxPaintIndex = openedTemplate.size() - 1; - } - } else { - if (selectedIndex >= openedTemplate.size() - 1) { - selectedIndex = openedTemplate.size() - 1; - maxPaintIndex = selectedIndex; - minPaintIndex = selectedIndex - maxTemplateNum + 1; - } else { - maxPaintIndex = minPaintIndex + maxTemplateNum - 1; - if (maxPaintIndex > openedTemplate.size() - 1) { - maxPaintIndex = openedTemplate.size() - 1; - } - } - } - } else { - minPaintIndex = 0; - maxPaintIndex = openedTemplate.size() - 1; - } - } - - - //个数小于最多能容纳的个数的情况下,看看宽度每个要画多少 - private void calculateRealAverageWidth(double maxwidth, int templateNum) { - - int num = openedTemplate.size() > templateNum ? templateNum : openedTemplate.size(); - realWidth = (int) (maxwidth / (num)); - if (realWidth > MAXWIDTH) { - realWidth = MAXWIDTH; - } else if (realWidth < MINWIDTH) { - //平均下来每个的宽度小于最小宽度 - realWidth = MINWIDTH; - } - } - - /** - * 计算过长度之后的每个tab的能接受的文字的英文字符数 - * - * @return - */ - private int calculateStringMaxLength() { - return realWidth - 3 * GAP - ICON_WIDTH - SMALLGAP - CLOSE.getIconWidth(); - - } - - private int getStringWidth(String str) { - return GraphHelper.getFontMetrics(this.getFont()).stringWidth(str); - } - - - /** - * 画选中的tab - * - * @param g2d - * @param sheeticon - * @param templateStartX - * @param sheetName - * @param closeIcon - * @return - */ - private int paintSelectedTab(Graphics2D g2d, Icon sheeticon, double templateStartX, String sheetName, Icon closeIcon) { - double[] x = {templateStartX, templateStartX, templateStartX + realWidth, templateStartX + realWidth, templateStartX}; - double[] y = {1, getHeight() + 1, getHeight() + 1, 1, 1}; - RoundRectangle2D.Double rect1 = new RoundRectangle2D.Double(templateStartX, 1, this.getWidth(), this.getHeight(), 7, 7); - g2d.setPaint(new GradientPaint(1, 1, UIConstants.SELECT_TAB, 1, (float) (getHeight() - 1.0D), UIConstants.SELECT_TAB)); - //选了30度和60度的特殊角度的x,y作为经过的两个点的坐标 - double specialLocation1 = 2.5; - double specialLocation2 = 4.330127; - GeneralPath generalPath = new GeneralPath(Path2D.WIND_EVEN_ODD, x.length); - generalPath.moveTo((float) x[0] + CORNOR_RADIUS, (float) y[0]); - generalPath.curveTo(((float) x[0] + CORNOR_RADIUS - specialLocation1), (y[0] + CORNOR_RADIUS - specialLocation2), ((float) x[0] + CORNOR_RADIUS - specialLocation2), (y[0] + CORNOR_RADIUS - specialLocation1), x[0], y[0] + CORNOR_RADIUS); - - for (int index = 1; index <= 2; index++) { - generalPath.lineTo((float) x[index], (float) y[index]); - } - - generalPath.lineTo((float) x[3], (float) y[3] + CORNOR_RADIUS); - generalPath.curveTo(((float) x[3] - CORNOR_RADIUS + specialLocation1), ((float) y[3] + CORNOR_RADIUS - specialLocation2), ((float) x[3] - CORNOR_RADIUS + specialLocation2), ((float) y[3] + CORNOR_RADIUS - specialLocation1), (float) x[3] - CORNOR_RADIUS, (float) y[3]); - generalPath.lineTo((float) x[0] + CORNOR_RADIUS, (float) y[0]); - - generalPath.closePath(); - g2d.fill(generalPath); - g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - g2d.setPaint(new Color(200, 201, 205)); - g2d.draw(new Arc2D.Double(x[0], y[0], CORNOR_RADIUS * 2, CORNOR_RADIUS * 2, 90, 90, 0)); - g2d.draw(new Line2D.Double(x[0], y[0] + CORNOR_RADIUS, x[1], y[1])); - g2d.draw(new Line2D.Double(x[1], y[1], x[2], y[2])); - g2d.draw(new Line2D.Double(x[2], y[2], x[3], y[3] + CORNOR_RADIUS)); - g2d.draw(new Arc2D.Double(x[3] - CORNOR_RADIUS * 2, y[3], CORNOR_RADIUS * 2, CORNOR_RADIUS * 2, 90, -90, 0)); - g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); - int sheetIconY = (getHeight() - sheeticon.getIconHeight()) / 2; - sheeticon.paintIcon(this, g2d, (int) templateStartX + GAP, sheetIconY); - // 画字符 - g2d.setPaint(getForeground()); - g2d.drawString(sheetName, (int) templateStartX + sheeticon.getIconWidth() + 2 * GAP, getHeight() - GAP * 2); - int closePosition = (int) templateStartX + realWidth - CLOSE.getIconWidth() - SMALLGAP; - int closeY = (getHeight() - closeIcon.getIconHeight()) / 2; - if (!DesignerMode.isVcsMode()) { - closeIcon.paintIcon(this, g2d, closePosition, closeY); - } - return closePosition; - - } - - /** - * 画没有选中的tab - * - * @param g2d - * @param sheeticon - * @param templateStartX - * @param sheetName - * @param closeIcon - * @param isLeft - * @return - */ - private int paintUnSelectedTab(Graphics2D g2d, Icon sheeticon, double templateStartX, String sheetName, Icon closeIcon, boolean isLeft, int mouseOveredIndex, int selfIndex) { - double[] x = {templateStartX, templateStartX, templateStartX + realWidth, templateStartX + realWidth, templateStartX}; - double[] y = {-1, getHeight() - 1, getHeight() - 1, -1, -1}; - if (selfIndex == mouseOveredIndex) { - g2d.setPaint(new GradientPaint(1, 1, UIConstants.HOVER_BLUE, 1, (float) (getHeight() - 1.0D), UIConstants.HOVER_BLUE)); - } else { - g2d.setPaint(new GradientPaint(1, 1, UIConstants.SHADOW_GREY, 1, (float) (getHeight() - 1.0D), UIConstants.SHADOW_GREY)); - } - - - GeneralPath generalPath = new GeneralPath(Path2D.WIND_EVEN_ODD, x.length); - - unSelectedClosedPath(generalPath, isLeft, x, y); - g2d.fill(generalPath); - g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - g2d.setPaint(UIConstants.TEMPLATE_TAB_PANE_BACKGROUND); - //TODO hzzz delete -// if (isLeft) { -// g2d.draw(new Arc2D.Double(x[0], y[0], CORNOR_RADIUS * 2, CORNOR_RADIUS * 2, 90, 90, 0)); -// } else { -// g2d.draw(new Arc2D.Double(x[0] - CORNOR_RADIUS * 2, y[0], CORNOR_RADIUS * 2, CORNOR_RADIUS * 2, 90, -90, 0)); -// } - -// g2d.draw(new Line2D.Double(x[0], y[0] + CORNOR_RADIUS, x[1], y[1] + 1)); -// g2d.draw(new Line2D.Double(x[1], y[1], x[2], y[2])); - g2d.draw(new Line2D.Double(x[2], y[2], x[3], y[3] + CORNOR_RADIUS)); -// if (isLeft) { -// g2d.draw(new Arc2D.Double(x[3], y[3], CORNOR_RADIUS * 2, CORNOR_RADIUS * 2, 90, 90, 0)); -// } else { -// g2d.draw(new Arc2D.Double(x[3] - CORNOR_RADIUS * 2, y[3], CORNOR_RADIUS * 2, CORNOR_RADIUS * 2, 90, -90, 0)); -// } - - g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); - int sheetIconY = (getHeight() - sheeticon.getIconHeight()) / 2; - sheeticon.paintIcon(this, g2d, (int) templateStartX + GAP, sheetIconY); - // 画字符 - g2d.setPaint(getForeground()); - g2d.drawString(sheetName, (int) templateStartX + sheeticon.getIconWidth() + 2 * GAP, getHeight() - GAP * 2); - int closeY = (getHeight() - closeIcon.getIconHeight()) / 2; - int closePosition = (int) templateStartX + realWidth - CLOSE.getIconWidth() - SMALLGAP; - if (!DesignerMode.isVcsMode()) { - closeIcon.paintIcon(this, g2d, closePosition, closeY); - } - return closePosition; - } - - - private void unSelectedClosedPath(GeneralPath generalPath, boolean isLeft, double[] x, double[] y) { - - if (isLeft) { - generalPath.moveTo((float) x[0] + CORNOR_RADIUS, (float) y[0]); - generalPath.curveTo(((float) x[0] + CORNOR_RADIUS - SPECIAL_LOCATION_1), (y[0] + CORNOR_RADIUS - SPECIAL_LOCATION_2), ((float) x[0] + CORNOR_RADIUS - SPECIAL_LOCATION_2), (y[0] + CORNOR_RADIUS - SPECIAL_LOCATION_1), x[0], y[0] + CORNOR_RADIUS); - } else { - generalPath.moveTo((float) x[0] - CORNOR_RADIUS, (float) y[0]); - generalPath.curveTo(((float) x[0] - CORNOR_RADIUS + SPECIAL_LOCATION_1), (y[0] + CORNOR_RADIUS - SPECIAL_LOCATION_2), ((float) x[0] - CORNOR_RADIUS + SPECIAL_LOCATION_2), (y[0] + CORNOR_RADIUS - SPECIAL_LOCATION_1), x[0], y[0] + CORNOR_RADIUS); - } - - for (int index = 1; index <= 2; index++) { - generalPath.lineTo((float) x[index], (float) y[index]); - } - - generalPath.lineTo((float) x[3], (float) y[3] + CORNOR_RADIUS); - - if (isLeft) { - generalPath.curveTo(((float) x[3] + CORNOR_RADIUS - SPECIAL_LOCATION_1), ((float) y[3] + CORNOR_RADIUS - SPECIAL_LOCATION_2), ((float) x[3] + CORNOR_RADIUS - SPECIAL_LOCATION_2), ((float) y[3] - CORNOR_RADIUS + SPECIAL_LOCATION_1), (float) x[3] + CORNOR_RADIUS, (float) y[3]); - generalPath.lineTo((float) x[0] + CORNOR_RADIUS, (float) y[0]); - } else { - generalPath.curveTo(((float) x[3] - CORNOR_RADIUS + SPECIAL_LOCATION_1), ((float) y[3] + CORNOR_RADIUS - SPECIAL_LOCATION_2), ((float) x[3] - CORNOR_RADIUS + SPECIAL_LOCATION_2), ((float) y[3] + CORNOR_RADIUS - SPECIAL_LOCATION_1), (float) x[3] - CORNOR_RADIUS, (float) y[3]); - generalPath.lineTo((float) x[0] - CORNOR_RADIUS, (float) y[0]); - } - - generalPath.closePath(); - } - - - public void setIsCloseCurrent(boolean isCloseCurrent) { - this.isCloseCurrent = isCloseCurrent; - - } - - /** - * 关闭模板 - * - * @param specifiedTemplate 模板 - */ - public void closeSpecifiedTemplate(JTemplate specifiedTemplate) { - if (specifiedTemplate == null) { - return; - } - - if (!specifiedTemplate.isALLSaved() && !DesignerMode.isVcsMode()) { - specifiedTemplate.stopEditing(); - int returnVal = FineJOptionPane.showConfirmDialog(DesignerContext.getDesignerFrame(), Toolkit.i18nText("Fine-Design_Basic_Utils_Would_You_Like_To_Save") + " \"" + specifiedTemplate.getEditingFILE() + "\" ?", - Toolkit.i18nText("Fine-Design_Basic_Confirm"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); - if (returnVal == JOptionPane.YES_OPTION) { - CallbackSaveWorker worker = specifiedTemplate.save(); - worker.addSuccessCallback(new Runnable() { - @Override - public void run() { - FineLoggerFactory.getLogger().info(Toolkit.i18nText("Fine-Design_Basic_Template_Already_Saved", specifiedTemplate.getEditingFILE().getName())); - closeTpl(specifiedTemplate); - } - }); - worker.start(specifiedTemplate.getRuntimeId()); - } else if (returnVal == JOptionPane.NO_OPTION) { - closeTpl(specifiedTemplate); - } - } else { - closeTpl(specifiedTemplate); - } - - } - - private void closeTpl(@Nonnull JTemplate specifiedTemplate) { - HistoryTemplateListCache.getInstance().closeSelectedReport(specifiedTemplate); - closeAndFreeLock(specifiedTemplate); - activePrevTemplateAfterClose(); - } - - private void closeAndFreeLock(@Nonnull JTemplate template) { - FILE file = template.getEditingFILE(); - // 只有是环境内的文件,才执行释放锁 - if (file != null && file.isEnvFile()) { - // release lock - TemplateResourceManager.getResource().closeTemplate(file.getPath()); - } - } - - /** - * 后台关闭当前编辑模板 - */ - public void closeCurrentTpl(){ - JTemplate jTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); - this.setIsCloseCurrent(true); - this.closeFormat(jTemplate); - this.closeSpecifiedTemplate(jTemplate); - } - - /** - * 关闭模板 - * - * @param closedTemplate 模板 - */ - public void closeFormat(JTemplate closedTemplate) { - //表单不需要处理 - if (!closedTemplate.isJWorkBook()) { - return; - } - - if (DesignerContext.getFormatState() == DesignerContext.FORMAT_STATE_NULL) { - return; - } - - //是被参照的模板被关闭,则重置格式刷 - closedTemplate.doConditionCancelFormat(); - } - - /** - * 关闭掉一个模板之后激活新的待显示模板 - */ public void activePrevTemplateAfterClose() { - if (openedTemplate.isEmpty()) { - //新建并激活模板 - DesignerContext.getDesignerFrame().addAndActivateJTemplate(); - selectedIndex = 0; - //此时刚自动新建的模板在HistoryTemplateListCache的editingTemplate - temTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); - - } else { - // 如果关闭的模板是当前选中的模板,则重新激活当前 selectIndex 的模板; - // selectIndex 没有变化,但是对应的模板已经变成了前一张模板 - if (closeIconIndex == selectedIndex || isCloseCurrent) { - // 如果当前关闭的模板在最右侧,那么预览上一个,防止数组越界 - if (selectedIndex >= maxPaintIndex) { - // selectIndex 不会 <0 因为如果关闭的是打开的最后一个模板,那么关闭之后 openedTemplate.isEmpty() = true - selectedIndex--; - } - isCloseCurrent = false; - } - // 如果关闭的模板不是当前选中的模板,那么重新获取一下当前模板的 index,激活该 index - else { - JTemplate template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); - selectedIndex = HistoryTemplateListCache.getInstance().contains(template); - } - if (selectedIndex < openedTemplate.size()) { - //如果是已后台关闭的模板,则重新打开文件 - openedTemplate.get(selectedIndex).activeOldJTemplate(); - } - - } - } - - - private boolean isOverCloseIcon(int evtX) { - boolean isOverCloseIcon = false; - for (int i = 0; i < startX.length; i++) { - if (evtX >= startX[i] && evtX <= startX[i] + CLOSE.getIconWidth()) { - isOverCloseIcon = true; - break; - } - } - return isOverCloseIcon; - } - - - private boolean isOverListDown(int evtX) { - int maxWidth = getWidth() - LIST_BUTTON_WIDTH; - return evtX >= (maxWidth + SMALLGAP) && evtX <= (getWidth() - SMALLGAP); - } - - - private int getTemplateIndex(int evtX) { - int textX = 0; - for (int i = minPaintIndex; i <= maxPaintIndex; i++) { - int textWidth = realWidth; - if (evtX >= textX && evtX < textX + textWidth) { - return i; - } - textX += textWidth; - } - return -1; - } - - - /** - * 处理自动新建的模板 在切换时的处理 - */ - public void doWithtemTemplate() { - //temtemplate保存的一定是手动新建的没有编辑或是编辑了没有保存的模板 - //没有保存,说明有编辑;已经保存在磁盘里的文件,说明有过处理,并且已经保存,此时切换都不将其自动关闭 - if (temTemplate == null || temTemplate == HistoryTemplateListCache.getInstance().getCurrentEditingTemplate()) { - return; - } - - if (!temTemplate.isSaved() || !temTemplate.getEditingFILE().isMemFile()) { - temTemplate = null; - } - - //自动新建的模板B若没有进行任何编辑(新建模板没有进行任何编辑时saved都是true):还没有存盘 - if (temTemplate != null && temTemplate.getEditingFILE().isMemFile() && temTemplate.isSaved()) { - HistoryTemplateListCache.getInstance().closeSelectedReport(temTemplate); - temTemplate = null; - setSelectedIndex(HistoryTemplateListCache.getInstance().contains(HistoryTemplateListCache.getInstance().getCurrentEditingTemplate())); - } - } - - private class UIListDownItemUI extends BasicMenuItemUI { - @Override - protected void paintBackground(Graphics g, JMenuItem menuItem, Color bgColor) { - if (menuItem.getIcon() == null) { - super.paintBackground(g, menuItem, bgColor); - return; - } - ButtonModel model = menuItem.getModel(); - Color oldColor = g.getColor(); - int menuWidth = menuItem.getWidth(); - int menuHeight = menuItem.getHeight(); - g.setColor(UIConstants.NORMAL_BACKGROUND); - g.fillRect(0, 0, menuWidth, menuHeight); - boolean itemIsSelected = menuItem instanceof JMenu && model.isSelected(); - if (menuItem.isOpaque()) { - if (model.isArmed() || itemIsSelected) { - GUIPaintUtils.fillPaint((Graphics2D) g, GAP, 0, menuWidth - GAP, menuHeight, true, Constants.NULL, UIConstants.FLESH_BLUE, UIConstants.ARC); - } else { - GUIPaintUtils.fillPaint((Graphics2D) g, GAP, 0, menuWidth - GAP, menuHeight, true, Constants.NULL, menuItem.getBackground(), UIConstants.ARC); - } - g.setColor(oldColor); - } else if (model.isArmed() || itemIsSelected) { - GUIPaintUtils.fillPaint((Graphics2D) g, GAP, 0, menuWidth - GAP, menuHeight, true, Constants.NULL, UIConstants.FLESH_BLUE, UIConstants.ARC); - g.setColor(oldColor); - } - } - } - - private class MultiTemplateTabMouseListener implements MouseListener { - - - /** - * 鼠标进入 - * - * @param e 鼠标事件 - */ - @Override - public void mouseEntered(MouseEvent e) { - // do nothing - } - - /** - * 鼠标离开 - * - * @param e 鼠标事件 - */ - @Override - public void mouseExited(MouseEvent e) { - listDownMode = LIST_DOWN; - closeIconIndex = -1; - mouseOveredIndex = -1; - MutilTempalteTabPane.this.repaint(); - } - - /** - * 鼠标释放 - * - * @param e 鼠标事件 - */ - @Override - public void mouseReleased(MouseEvent e) { - // do nothing - } - - /** - * 点击 - * - * @param e 鼠标事件 - */ - @Override - public void mouseClicked(MouseEvent e) { - // do nothing - } - - /** - * 按下 - * - * @param e 鼠标事件 - */ - @Override - public void mousePressed(MouseEvent e) { - //如果在版本管理情况下,不允许切换tab - if (DesignerMode.isVcsMode()) { - return; - } - - int evtX = e.getX(); - - //是否点击关闭按钮 如果点击了关闭按钮,则将点击的模板关闭,不需要切换,如果没有点击关闭按钮,则切换到点击的模板处 - boolean isOverCloseIcon = isOverCloseIcon(evtX); - if (isOverListDown(evtX)) { - listDownMode = isOverListDown(evtX) ? MOUSE_PRESS_LIST_DOWN : LIST_DOWN; - if (!isShowList) { - showListDown(); - } - isShowList = !isShowList; - - } else if (isOverCloseIcon) { - //关闭按钮的图标变化 - closeIconIndex = getTemplateIndex(evtX); - clodeMode = MOUSE_PRESS_CLOSE; - //关闭close图标所在的模板{ - JTemplate template = openedTemplate.get(closeIconIndex); - if (template.isOpening()) { - WorkerManager.getInstance().cancelWorker(template.getPath()); - } else if (template.isSaving()) { - boolean completed = WorkerManager.getInstance().isCompleted(template.getTarget().getTemplateID()); - if (!completed) { - FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), - Toolkit.i18nText("Fine-Design_Close_Template_Tip", template.getEditingFILE().getName())); - return; - } - } - closeFormat(template); - closeSpecifiedTemplate(template); - DesignerContext.getDesignerFrame().getContentFrame().repaint(); - isShowList = false; - } else { - //没有点击关闭和ListDown按钮,则切换到点击的模板处 - closeIconIndex = -1; - clodeMode = CLOSE; - int tempSelectedIndex = selectedIndex; - if (selectedIndex != getTemplateIndex(evtX) && getTemplateIndex(evtX) != -1) { - openedTemplate.get(selectedIndex).stopEditing(); - selectedIndex = getTemplateIndex(evtX); - //如果在权限编辑情况下,不允许切换到表单类型的工作簿 - if (DesignerMode.isAuthorityEditing() && !openedTemplate.get(selectedIndex).isJWorkBook()) { - DesignerContext.getDesignerFrame().addAndActivateJTemplate(openedTemplate.get(tempSelectedIndex)); - FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Toolkit.i18nText("Fine-Design_Basic_Form_Authority_Edited_Cannot_Be_Supported") - + "!", Toolkit.i18nText("Fine-Design_Basic_Alert"), JOptionPane.WARNING_MESSAGE); - MutilTempalteTabPane.this.repaint(); - return; - } - JTemplate evtXTemplate = openedTemplate.get(getTemplateIndex(evtX)); - evtXTemplate.activeNewJTemplate(); - } - isShowList = false; - } - MutilTempalteTabPane.this.repaint(); - - - } - - - } - - private class MultiTemplateTabMouseMotionListener implements MouseMotionListener { - /** - * 鼠标拖拽 - * - * @param e 鼠标事件 - */ - @Override - public void mouseDragged(MouseEvent e) { - // do nothing - } - - /** - * 鼠标移动 - * - * @param e 鼠标事件 - */ - @Override - public void mouseMoved(MouseEvent e) { - int evtX = e.getX(); - mouseOveredIndex = getTemplateIndex(evtX); - - //看是否需要显示toolTip - if (mouseOveredIndex != -1 && isNeedToolTips[mouseOveredIndex - minPaintIndex]) { - setToolTipText(openedTemplate.get(mouseOveredIndex).getEditingFILE().getName()); - } else { - setToolTipText(null); - } - - listDownMode = isOverListDown(evtX) ? MOUSE_OVER_LIST_DOWN : LIST_DOWN; - - boolean isOverCloseIcon = isOverCloseIcon(evtX); - clodeMode = isOverCloseIcon ? MOUSE_OVER_CLOSE : CLOSE; - closeIconIndex = isOverCloseIcon ? mouseOveredIndex : -1; - MutilTempalteTabPane.this.repaint(); - } + MultiTemplateTabPane.getInstance().activePrevTemplateAfterClose(); } - - } diff --git a/designer-base/src/main/java/com/fr/design/file/TemplateTreePane.java b/designer-base/src/main/java/com/fr/design/file/TemplateTreePane.java index 18abbb7e28..d985595f5f 100644 --- a/designer-base/src/main/java/com/fr/design/file/TemplateTreePane.java +++ b/designer-base/src/main/java/com/fr/design/file/TemplateTreePane.java @@ -307,10 +307,11 @@ public class TemplateTreePane extends JPanel implements FileOperations { if (reportletsTree.getSelectionCount() == 0) { //没选中文件刷新根目录 reportletsTree.refresh(); + return; } reportletsTree.refreshParent(Objects.requireNonNull(reportletsTree.getSelectionPath())); DesignerFrameFileDealerPane.getInstance().refreshRightToolBarBy(null); - FineLoggerFactory.getLogger().info(Toolkit.i18nText("Fine-Design_Basic_Template_File_Tree_Refresh_Successfully") + "!"); + FineLoggerFactory.getLogger().info(Toolkit.i18nText("Fine-Design_Basic_Template_File_Tree_Refresh_Successfully")); } diff --git a/designer-base/src/main/java/com/fr/design/formula/FormulaPane.java b/designer-base/src/main/java/com/fr/design/formula/FormulaPane.java index d4737f084a..f53930602c 100644 --- a/designer-base/src/main/java/com/fr/design/formula/FormulaPane.java +++ b/designer-base/src/main/java/com/fr/design/formula/FormulaPane.java @@ -58,7 +58,7 @@ import com.fr.stable.EncodeConstants; import com.fr.stable.EssentialUtils; import com.fr.stable.ParameterProvider; import com.fr.stable.StringUtils; -import com.fr.stable.script.CRAddress; +import com.fr.parser.CRAddress; import com.fr.stable.script.ColumnRowRange; import com.fr.stable.script.Expression; import com.fr.stable.script.Node; @@ -156,6 +156,8 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula { private DefaultCompletionProvider completionProvider; private static final Map PARAM_PREFIX_MAP = new HashMap<>(); + public static final int DESCRIPTION_TEXT_AREA_ROW = 16, DESCRIPTION_TEXT_AREA_COLUMN = 27; + public FormulaPane() { initComponents(); } @@ -1194,8 +1196,7 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula { private void initDescriptionTextArea() { // Description - descriptionTextArea = new UITextArea(); - + descriptionTextArea = new UITextArea(DESCRIPTION_TEXT_AREA_ROW,DESCRIPTION_TEXT_AREA_COLUMN); descriptionTextArea.setBackground(Color.white); descriptionTextArea.setLineWrap(true); descriptionTextArea.setWrapStyleWord(true); diff --git a/designer-base/src/main/java/com/fr/design/fun/DefaultValueAdjustProvider.java b/designer-base/src/main/java/com/fr/design/fun/DefaultValueAdjustProvider.java new file mode 100644 index 0000000000..1e553735dd --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/fun/DefaultValueAdjustProvider.java @@ -0,0 +1,65 @@ +package com.fr.design.fun; + +import com.fr.base.Utils; +import com.fr.base.chart.BaseChartCollection; +import com.fr.chartx.attr.ChartProvider; +import com.fr.general.FRFont; +import com.fr.report.cell.CellElement; +import com.fr.stable.fun.mark.Selectable; + +import java.awt.Font; + +/** + * 主要用于fvs报表块内元素默认值的调整,以达到所见所得效果,后续fvs内置后删除 + */ +public interface DefaultValueAdjustProvider extends Selectable { + String MARK_STRING = "DefaultValueAdjustProvider"; + int CURRENT_LEVEL = 1; + + /** + * 调整单元格对象默认值 + * + * @param cellElement + */ + void adjustCellElement(CellElement cellElement); + + /** + * 调整富文本默认值 + * + * @param fontSize + * @return + */ + int adjustRichTextTransform(int fontSize, double transformedFontSize); + + /** + * 调整ChartCollection + * + * @param chartCollection + */ + void adjustChartCollectionStyle(BaseChartCollection chartCollection); + + /** + * 调整图表 + * + * @param chartProvider + */ + void adjustChart(ChartProvider chartProvider); + + + /** + * 转成当前分辨率下显示的font + * @param font + * @param resolution + * @return + */ + Font transformFontByResolution(FRFont font, int resolution); + + /** + * 修改设计可用字体默认列表 + * @return + */ + default String[] getAvailableFontFamilyNames4Report() { + return Utils.getAvailableFontFamilyNames4Report(); + } + +} diff --git a/designer-base/src/main/java/com/fr/design/fun/TemplateThemePaneProvider.java b/designer-base/src/main/java/com/fr/design/fun/TemplateThemePaneProvider.java new file mode 100644 index 0000000000..f05d85318c --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/fun/TemplateThemePaneProvider.java @@ -0,0 +1,35 @@ +package com.fr.design.fun; + +import com.fr.design.beans.BasicBeanPane; +import com.fr.stable.fun.mark.Mutable; + +/** + * 设计器模板主题管理-细节定制部分,支持添加tab + * + * @author Bruce.Deng + * @version 11.0 + * Created by Bruce.Deng on 2023/2/7 + */ +public interface TemplateThemePaneProvider extends Mutable { + + String XML_TAG = "TemplateThemePaneProvider"; + + int CURRENT_LEVEL = 1; + + /** + * 插入tab的位置 + * + * @param total 已插入的tab数 + * @return 插入位置,如果想放到最后,则返回-1 + */ + int getInsertPosition(int total); + + + /** + * 获取tab对象 + * + * @return tab对象 + */ + BasicBeanPane getTab(); + +} diff --git a/designer-base/src/main/java/com/fr/design/fun/impl/AbstractDefaultValueAdjustProvider.java b/designer-base/src/main/java/com/fr/design/fun/impl/AbstractDefaultValueAdjustProvider.java new file mode 100644 index 0000000000..b2fc58ba8f --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/fun/impl/AbstractDefaultValueAdjustProvider.java @@ -0,0 +1,24 @@ +package com.fr.design.fun.impl; + + +import com.fr.design.fun.DefaultValueAdjustProvider; +import com.fr.stable.fun.assist.Selector; +import com.fr.stable.fun.impl.AbstractProvider; +import com.fr.stable.fun.mark.API; + +@API(level = DefaultValueAdjustProvider.CURRENT_LEVEL) +public abstract class AbstractDefaultValueAdjustProvider extends AbstractProvider implements DefaultValueAdjustProvider { + + @Override + public int currentAPILevel() { + return CURRENT_LEVEL; + } + + public String mark4Provider() { + return this.getClass().getName(); + } + + public Selector selector() { + return Selector.ALWAYS; + } +} diff --git a/designer-base/src/main/java/com/fr/design/fun/impl/AbstractTemplateThemePaneProvider.java b/designer-base/src/main/java/com/fr/design/fun/impl/AbstractTemplateThemePaneProvider.java new file mode 100644 index 0000000000..7e8fe617dc --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/fun/impl/AbstractTemplateThemePaneProvider.java @@ -0,0 +1,26 @@ +package com.fr.design.fun.impl; + +import com.fr.design.fun.TemplateThemePaneProvider; +import com.fr.stable.fun.impl.AbstractProvider; +import com.fr.stable.fun.mark.API; + +/** + * @author Bruce.Deng + * @version 11.0 + * @see TemplateThemePaneProvider + * Created by Bruce.Deng on 2023/2/7 + */ +@API(level = TemplateThemePaneProvider.CURRENT_LEVEL) +public abstract class AbstractTemplateThemePaneProvider extends AbstractProvider implements TemplateThemePaneProvider { + + @Override + public int currentAPILevel() { + return CURRENT_LEVEL; + } + + @Override + public String mark4Provider() { + return getClass().getName(); + } + +} diff --git a/designer-base/src/main/java/com/fr/design/gui/controlpane/UIControlPane.java b/designer-base/src/main/java/com/fr/design/gui/controlpane/UIControlPane.java index f9a3ed0db3..12f904922d 100644 --- a/designer-base/src/main/java/com/fr/design/gui/controlpane/UIControlPane.java +++ b/designer-base/src/main/java/com/fr/design/gui/controlpane/UIControlPane.java @@ -31,7 +31,6 @@ import java.awt.Color; import java.awt.Cursor; import java.awt.Dimension; import java.awt.FlowLayout; -import java.awt.Font; import java.awt.Frame; import java.awt.Graphics; import java.awt.Graphics2D; @@ -241,51 +240,12 @@ public abstract class UIControlPane extends JControlPane { } private void hideDialog() { - // 检查是否有子弹窗,如果有,则不隐藏 - for (Window window : getOwnedWindows()) { - if (window.isVisible()) { - return; - } - } - // 如果有可见模态对话框,则不隐藏 - for (Window window : DesignerContext.getDesignerFrame().getOwnedWindows()) { - if (window instanceof JDialog && window.isVisible() && ((JDialog) window).isModal()) { - return; - } - } - - try { - //没有指定owner的弹出框用的是SwingUtilities.getSharedOwnerFrame() - Frame sharedOwnerFrame = Reflect.on(SwingUtilities.class).call("getSharedOwnerFrame").get(); - for (Window window : sharedOwnerFrame.getOwnedWindows()) { - if (window instanceof JDialog && window.isVisible() && ((JDialog) window).isModal()) { - // 如果有可见模态对话框,则不隐藏 - return; - } - } - } catch (Exception ignore) { - //do nothing - } - - // 要隐藏 先检查有没有非法输入 - // 非法输入检查放在最后,因为可能出现面板弹出新弹框而失去焦点的情况,比如 输入公式时,弹出公式编辑对话框 - try { - checkValid(); - } catch (Exception exp) { - // 存在非法输入 拒绝隐藏 - this.setAlwaysOnTop(true); - FineJOptionPane.showMessageDialog(this, exp.getMessage()); - this.requestFocus(); - return; - } - if (JavaFxNativeFileChooser.isShowDialogState()) { - JavaFxNativeFileChooser.setShowDialogState(false); - return; + if (needToHidePopupEditDialog()) { + saveSettings(); + setVisible(false); + PopupDialogSaveAction saveAction = OSSupportCenter.getAction(PopupDialogSaveAction.class); + saveAction.unregister(); } - saveSettings(); - setVisible(false); - PopupDialogSaveAction saveAction = OSSupportCenter.getAction(PopupDialogSaveAction.class); - saveAction.unregister(); } private void initListener() { @@ -302,6 +262,54 @@ public abstract class UIControlPane extends JControlPane { } } + /** + * 是否需要隐藏popupEditDialog + */ + protected boolean needToHidePopupEditDialog() { + // 检查是否有子弹窗,如果有,则不隐藏 + for (Window window : popupEditDialog.getOwnedWindows()) { + if (window.isVisible()) { + return false; + } + } + // 如果有可见模态对话框,则不隐藏 + for (Window window : DesignerContext.getDesignerFrame().getOwnedWindows()) { + if (window instanceof JDialog && window.isVisible() && ((JDialog) window).isModal()) { + return false; + } + } + + try { + //没有指定owner的弹出框用的是SwingUtilities.getSharedOwnerFrame() + Frame sharedOwnerFrame = Reflect.on(SwingUtilities.class).call("getSharedOwnerFrame").get(); + for (Window window : sharedOwnerFrame.getOwnedWindows()) { + if (window instanceof JDialog && window.isVisible() && ((JDialog) window).isModal()) { + // 如果有可见模态对话框,则不隐藏 + return false; + } + } + } catch (Exception ignore) { + //do nothing + } + + // 要隐藏 先检查有没有非法输入 + // 非法输入检查放在最后,因为可能出现面板弹出新弹框而失去焦点的情况,比如 输入公式时,弹出公式编辑对话框 + try { + checkValid(); + } catch (Exception exp) { + // 存在非法输入 拒绝隐藏 + popupEditDialog.setAlwaysOnTop(true); + FineJOptionPane.showMessageDialog(this, exp.getMessage()); + popupEditDialog.requestFocus(); + return false; + } + if (JavaFxNativeFileChooser.isShowDialogState()) { + JavaFxNativeFileChooser.setShowDialogState(false); + return false; + } + return true; + } + // 移动弹出编辑面板的工具条 private class PopupToolPane extends JPanel { private JDialog parentDialog; // 如果不在对话框中,值为null diff --git a/designer-base/src/main/java/com/fr/design/gui/core/WidgetOption.java b/designer-base/src/main/java/com/fr/design/gui/core/WidgetOption.java index 258f558a71..4c9db5a6a0 100644 --- a/designer-base/src/main/java/com/fr/design/gui/core/WidgetOption.java +++ b/designer-base/src/main/java/com/fr/design/gui/core/WidgetOption.java @@ -1,6 +1,7 @@ package com.fr.design.gui.core; import com.fr.base.BaseUtils; +import com.fr.base.svg.IconUtils; import com.fr.form.ui.Button; import com.fr.form.ui.CheckBox; import com.fr.form.ui.CheckBoxGroup; @@ -14,6 +15,7 @@ import com.fr.form.ui.ListEditor; import com.fr.form.ui.MultiFileEditor; import com.fr.form.ui.NumberEditor; import com.fr.form.ui.Password; +import com.fr.form.ui.PictureWidget; import com.fr.form.ui.RadioGroup; import com.fr.form.ui.TextArea; import com.fr.form.ui.TextEditor; @@ -142,7 +144,7 @@ public abstract class WidgetOption implements Serializable { */ public static WidgetOption[] getFormWidgetIntance() { return new WidgetOption[]{TEXTEDITOR, LABEL, FREEBUTTON, COMBOBOX, COMBOCHECKBOX, DATEEDITOR, - NUMBEREDITOR, TREECOMBOBOX, RADIOGROUP, CHECKBOXGROUP, TEXTAREA, PASSWORD, CHECKBOX, TREE, MULTI_FILEEDITOR}; + NUMBEREDITOR, TREECOMBOBOX, RADIOGROUP, CHECKBOXGROUP, TEXTAREA, PASSWORD, CHECKBOX, TREE, MULTI_FILEEDITOR,PICTURE}; } public static final WidgetOption DATEEDITOR = WidgetOptionFactory.createByWidgetClass(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Widget_Type_Date"), @@ -214,4 +216,7 @@ public abstract class WidgetOption implements Serializable { public static final WidgetOption IFRAMEDITOR = WidgetOptionFactory.createByWidgetClass(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Form_Iframe"), BaseUtils.readIcon("/com/fr/web/images/form/resources/iframe_16.png"), IframeEditor.class); + public static final WidgetOption PICTURE = WidgetOptionFactory.createByWidgetClass(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Widget_Type_Image"), IconUtils.readIcon("/com/fr/web/images/form/resources/picture_widget_16.png"), + PictureWidget.class); + } diff --git a/designer-base/src/main/java/com/fr/design/gui/frpane/HyperlinkGroupPaneActionProvider.java b/designer-base/src/main/java/com/fr/design/gui/frpane/HyperlinkGroupPaneActionProvider.java index 525bb5b792..be0d8e8523 100644 --- a/designer-base/src/main/java/com/fr/design/gui/frpane/HyperlinkGroupPaneActionProvider.java +++ b/designer-base/src/main/java/com/fr/design/gui/frpane/HyperlinkGroupPaneActionProvider.java @@ -8,6 +8,8 @@ import com.fr.design.designer.TargetComponent; */ public interface HyperlinkGroupPaneActionProvider { + String XML_TAG = "HyperlinkGroupPane"; + /** * 刷新面板展示 * diff --git a/designer-base/src/main/java/com/fr/design/gui/icheckbox/UICheckBox.java b/designer-base/src/main/java/com/fr/design/gui/icheckbox/UICheckBox.java index 0ddd3e22d2..8162c7ba86 100644 --- a/designer-base/src/main/java/com/fr/design/gui/icheckbox/UICheckBox.java +++ b/designer-base/src/main/java/com/fr/design/gui/icheckbox/UICheckBox.java @@ -139,6 +139,15 @@ public class UICheckBox extends JCheckBox implements UIObserver, GlobalNameObser return true; } + /** + * 获取UICheckBox的UI层,可以用于设置UI + * + * @return UICheckBoxUI + */ + public UICheckBoxUI getUICheckBoxUI(){ + return new UICheckBoxUI(); + } + private class UICheckBoxUI extends MetalCheckBoxUI { @Override public synchronized void paint(Graphics g, JComponent c) { @@ -186,9 +195,9 @@ public class UICheckBox extends JCheckBox implements UIObserver, GlobalNameObser g2d.drawRoundRect(iconRect.x, iconRect.y, iconRect.width - 1, iconRect.height - 1, UIConstants.ARC, UIConstants.ARC); } - if (model.isSelected()) { - UIConstants.YES_ICON.paintIcon(c, g, iconRect.x + 2, iconRect.y + 2); - } + if (model.isSelected()) { + UIConstants.YES_ICON.paintIcon(c, g, iconRect.x + 2, iconRect.y + 2); + } g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); // Draw the Text diff --git a/designer-base/src/main/java/com/fr/design/gui/icombocheckbox/UICheckListPopup.java b/designer-base/src/main/java/com/fr/design/gui/icombocheckbox/UICheckListPopup.java index 3eed2d799d..80e7e88bbf 100644 --- a/designer-base/src/main/java/com/fr/design/gui/icombocheckbox/UICheckListPopup.java +++ b/designer-base/src/main/java/com/fr/design/gui/icombocheckbox/UICheckListPopup.java @@ -37,6 +37,10 @@ public class UICheckListPopup extends UIPopupMenu { private Color mouseEnteredColor = UIConstants.CHECKBOX_HOVER_SELECTED; private int maxDisplayNumber = 8; private boolean supportSelectAll = true; + /** + * 每项数据都有可能因为宽度设置问题,而被省略显示,这个常量代表,是否要给每项数据添加一个值等于其原值的Tooltips + */ + private boolean labelNeedToolTips = false; public static final String COMMIT_EVENT = "commit"; private static final String SELECT_ALL = com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Choose_All"); @@ -47,9 +51,14 @@ public class UICheckListPopup extends UIPopupMenu { } public UICheckListPopup(Object[] value, boolean supportSelectAll) { + this(value, supportSelectAll, false); + } + + public UICheckListPopup(Object[] values, boolean supportSelectAll, boolean labelNeedToolTips) { super(); - values = value; + this.values = values; this.supportSelectAll = supportSelectAll; + this.labelNeedToolTips = labelNeedToolTips; initComponent(); } @@ -62,6 +71,11 @@ public class UICheckListPopup extends UIPopupMenu { addCheckboxValues(); } + public UICheckListPopup setLabelNeedToolTips(boolean labelNeedToolTips) { + this.labelNeedToolTips = labelNeedToolTips; + return this; + } + private void initComponent() { checkboxPane = new JPanel(); checkboxPane.setLayout(new GridLayout(checkBoxList.size(), 1, 0, 0)); @@ -111,6 +125,10 @@ public class UICheckListPopup extends UIPopupMenu { checkPane.setBackground(Color.WHITE); checkPane.add(temp); checkPane.add(label); + if (labelNeedToolTips) { + // 设置每项Label的tooltips为其省略前的内容 + label.setToolTipText(checkValue.toString()); + } addMouseListener(temp, label); checkBoxList.add(temp); diff --git a/designer-base/src/main/java/com/fr/design/gui/icombocheckbox/UIComboCheckBox.java b/designer-base/src/main/java/com/fr/design/gui/icombocheckbox/UIComboCheckBox.java index 4dcea229ce..ce0a9f869e 100644 --- a/designer-base/src/main/java/com/fr/design/gui/icombocheckbox/UIComboCheckBox.java +++ b/designer-base/src/main/java/com/fr/design/gui/icombocheckbox/UIComboCheckBox.java @@ -17,9 +17,6 @@ import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.event.PopupMenuEvent; import javax.swing.event.PopupMenuListener; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; @@ -32,6 +29,9 @@ import java.awt.event.FocusAdapter; import java.awt.event.FocusEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; /** * 设计器下拉复选框组件 @@ -52,7 +52,7 @@ public class UIComboCheckBox extends JComponent implements UIObserver, GlobalNam //选中的值之间显示的分隔符 private String valueSperator; private static final String DEFAULT_VALUE_SPERATOR = ","; - private static final String OMIT_TEXT = "..."; + protected static final String OMIT_TEXT = "..."; private UIObserverListener uiObserverListener; private GlobalNameListener globalNameListener = null; @@ -60,6 +60,7 @@ public class UIComboCheckBox extends JComponent implements UIObserver, GlobalNam private boolean showOmitText = true; private boolean supportSelectAll = true; + private String placeHolder = StringUtils.EMPTY; public UIComboCheckBox(Object[] value) { this(value, DEFAULT_VALUE_SPERATOR, true); @@ -112,14 +113,42 @@ public class UIComboCheckBox extends JComponent implements UIObserver, GlobalNam } private void initComponent() { - this.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0)); this.popup = new UICheckListPopup(values, supportSelectAll); this.popup.addActionListener(new PopupAction()); this.editor = createEditor(); this.arrowButton = createArrowButton(); + setLayoutAndAddComponents(); + setText(); + } + + /** + * 设置布局管理器并且添加组件 + * 默认使用FlowLayout + */ + protected void setLayoutAndAddComponents() { + this.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0)); this.add(editor); this.add(arrowButton); - setText(); + } + + public UICheckListPopup getPopup() { + return popup; + } + + public UITextField getEditor() { + return editor; + } + + public String getPlaceHolder() { + return placeHolder; + } + + public void setPlaceHolder(String placeHolder) { + this.placeHolder = placeHolder; + } + + public UIButton getArrowButton() { + return arrowButton; } private UIButton createArrowButton() { @@ -171,6 +200,9 @@ public class UIComboCheckBox extends JComponent implements UIObserver, GlobalNam @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { attributeChange(); + if (uiObserverListener != null) { + uiObserverListener.doChange(); + } } @Override @@ -270,6 +302,28 @@ public class UIComboCheckBox extends JComponent implements UIObserver, GlobalNam String text = builder.length() > 0 ? builder.substring(0, builder.length() - 1) : StringUtils.EMPTY; //计算加省略号后的文本 editor.setText(this.showOmitText ? omitEditorText(editor, text) : text); + // 添加placeHolder + setEditorPlaceHolder(editor); + // tooltips显示原值 + setEditorToolTipText(editor, text); + } + + /** + * 为为添加placeholder + * @param editor + */ + protected void setEditorPlaceHolder(UITextField editor) { + // 默认空实现 + } + + /** + * 为UITextField设置悬浮提示值 + * + * @param editor + * @param text + */ + protected void setEditorToolTipText(JComponent editor, String text) { + // 默认不做设置 } /** @@ -279,7 +333,7 @@ public class UIComboCheckBox extends JComponent implements UIObserver, GlobalNam * @param text * @return 省略后的文字 */ - private static String omitEditorText(UITextField textEditor, String text) { + protected String omitEditorText(UITextField textEditor, String text) { char[] omitChars = OMIT_TEXT.toCharArray(); //获取字体的大小 FontMetrics fontMetrics = textEditor.getFontMetrics(textEditor.getFont()); diff --git a/designer-base/src/main/java/com/fr/design/gui/iprogressbar/ProgressDialog.java b/designer-base/src/main/java/com/fr/design/gui/iprogressbar/ProgressDialog.java index 2c1e6abf56..44e697d043 100644 --- a/designer-base/src/main/java/com/fr/design/gui/iprogressbar/ProgressDialog.java +++ b/designer-base/src/main/java/com/fr/design/gui/iprogressbar/ProgressDialog.java @@ -20,6 +20,10 @@ import java.awt.Frame; /** * 加载进度弹窗 + * 使用注意点: + * 必须到使用时再初始化,不要作为属性存在 + * 因为涉及到 大小/位置 相对于 parent 的相对判断 + * 见 {@link com.fr.design.gui.iprogressbar.ProgressDialogTest} */ public class ProgressDialog extends UIDialog { protected static final FRFont font = DesignUtils diff --git a/designer-base/src/main/java/com/fr/design/gui/ispinner/UISpinner.java b/designer-base/src/main/java/com/fr/design/gui/ispinner/UISpinner.java index 4a722fc50d..a19db05060 100644 --- a/designer-base/src/main/java/com/fr/design/gui/ispinner/UISpinner.java +++ b/designer-base/src/main/java/com/fr/design/gui/ispinner/UISpinner.java @@ -312,6 +312,25 @@ public class UISpinner extends JPanel implements UIObserver, GlobalNameObserver componentInitListeners(); } + /** + * 设置最大值 + * @param maxValue 最大值 + */ + public void setMaxValue(double maxValue) { + this.maxValue = maxValue; + textField.setMaxValue(maxValue); + } + + /** + * 设置最小值 + * + * @param minValue 最小值 + */ + public void setMinValue(double minValue) { + this.minValue = minValue; + textField.setMinValue(minValue); + } + private void componentInitListeners() { preButton.addActionListener(new ActionListener() { @Override diff --git a/designer-base/src/main/java/com/fr/design/gui/itableeditorpane/UITableEditorPane.java b/designer-base/src/main/java/com/fr/design/gui/itableeditorpane/UITableEditorPane.java index 07756a56b7..aca38b28d2 100644 --- a/designer-base/src/main/java/com/fr/design/gui/itableeditorpane/UITableEditorPane.java +++ b/designer-base/src/main/java/com/fr/design/gui/itableeditorpane/UITableEditorPane.java @@ -8,10 +8,12 @@ import com.fr.design.gui.icontainer.UIScrollPane; import com.fr.design.gui.ilable.UILabel; import com.fr.design.layout.FRGUIPaneFactory; - -import javax.swing.*; +import javax.swing.JPanel; +import javax.swing.JTable; import javax.swing.event.TableModelListener; -import java.awt.*; +import java.awt.BorderLayout; +import java.awt.GridLayout; +import java.awt.Insets; import java.util.List; /** @@ -31,25 +33,25 @@ public class UITableEditorPane extends BasicPane { private String leftLabelName; private JPanel buttonPane; - public UITableEditorPane(UITableModelAdapter model) { - this.tableModel = model; - this.initComponent(model.createAction()); - } + public UITableEditorPane(UITableModelAdapter model) { + this.tableModel = model; + this.initComponent(model.createAction()); + } - public UITableEditorPane(UITableModelAdapter model, String s) { - leftLabelName = s; - this.tableModel = model; - this.initComponent(model.createAction()); - } + public UITableEditorPane(UITableModelAdapter model, String s) { + leftLabelName = s; + this.tableModel = model; + this.initComponent(model.createAction()); + } - private void initComponent(UITableEditAction[] action) { - this.setLayout(FRGUIPaneFactory.createBorderLayout()); - JPanel pane = new JPanel(new BorderLayout(4, 4)); - this.add(pane, BorderLayout.CENTER); + protected void initComponent(UITableEditAction[] action) { + this.setLayout(FRGUIPaneFactory.createBorderLayout()); + JPanel pane = new JPanel(new BorderLayout(4, 4)); + this.add(pane, BorderLayout.CENTER); - UILabel l = new UILabel(leftLabelName); - editTable = tableModel.createTable(); - editTable.getTableHeader().setBackground(UIConstants.DEFAULT_BG_RULER); + UILabel l = new UILabel(leftLabelName); + editTable = tableModel.createTable(); + editTable.getTableHeader().setBackground(UIConstants.DEFAULT_BG_RULER); UIScrollPane scrollPane = new UIScrollPane(editTable); scrollPane.setBorder(new UIRoundedBorder(UIConstants.TITLED_BORDER_COLOR, 1, UIConstants.ARC)); @@ -62,11 +64,11 @@ public class UITableEditorPane extends BasicPane { } - public UITableModelAdapter getTableModel(){ + public UITableModelAdapter getTableModel() { return tableModel; } - private void initbuttonPane(UITableEditAction[] action) { + protected void initbuttonPane(UITableEditAction[] action) { buttonPane = new JPanel(); if (action != null) { @@ -146,6 +148,14 @@ public class UITableEditorPane extends BasicPane { return buttonPane; } + public JTable getEditTable() { + return editTable; + } + + public void setEditTable(JTable editTable) { + this.editTable = editTable; + } + /** * 停止编辑 */ @@ -157,7 +167,7 @@ public class UITableEditorPane extends BasicPane { /** * 设置表头是否可以改变大小 */ - public void setHeaderResizing(boolean resizingAllowed){ + public void setHeaderResizing(boolean resizingAllowed) { editTable.getTableHeader().setResizingAllowed(resizingAllowed); } diff --git a/designer-base/src/main/java/com/fr/design/gui/itableeditorpane/UITableModelAdapter.java b/designer-base/src/main/java/com/fr/design/gui/itableeditorpane/UITableModelAdapter.java index 4506bb9a6c..87e21c75be 100644 --- a/designer-base/src/main/java/com/fr/design/gui/itableeditorpane/UITableModelAdapter.java +++ b/designer-base/src/main/java/com/fr/design/gui/itableeditorpane/UITableModelAdapter.java @@ -219,57 +219,69 @@ public abstract class UITableModelAdapter extends AbstractTableModel implemen protected class DeleteAction extends UITableEditAction { private Component component = null; + // 删除时界面显示的提示语,可自定义 + private String deleteTipText; public DeleteAction() { - this.setName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Delete")); - this.setSmallIcon(BaseUtils.readIcon("/com/fr/base/images/cell/control/remove.png")); - } - + this.setName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Delete")); + this.setDeleteTipText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Utils_Are_You_Sure_To_Remove_The_Selected_Item") + "?"); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/base/images/cell/control/remove.png")); + } + public DeleteAction(Component component){ - this.setName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Delete")); - this.setSmallIcon(BaseUtils.readIcon("/com/fr/base/images/cell/control/remove.png")); + this.setName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Delete")); + this.setDeleteTipText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Utils_Are_You_Sure_To_Remove_The_Selected_Item") + "?"); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/base/images/cell/control/remove.png")); this.component = component; } @Override public void actionPerformed(ActionEvent e) { - int[] selectedRow = table.getSelectedRows(); - if (ismultiSelected()) { - FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(),com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Multiple_Select_Warn_Text")); - return; - } - if (table.getCellEditor() != null) { - try { - table.getCellEditor().stopCellEditing(); - } catch (Exception ee) { + int[] selectedRow = table.getSelectedRows(); + if (ismultiSelected()) { + FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Multiple_Select_Warn_Text")); + return; + } + if (table.getCellEditor() != null) { + try { + table.getCellEditor().stopCellEditing(); + } catch (Exception ee) { FineLoggerFactory.getLogger().error(ee.getMessage(), ee); - } - } - if (getRowCount() < 1) { - return; - } - - if(component == null){ - component = DesignerContext.getDesignerFrame(); - } - int val = FineJOptionPane.showConfirmDialog(component, - com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Utils_Are_You_Sure_To_Remove_The_Selected_Item") + "?", com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Remove"), - JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); - if (val != JOptionPane.OK_OPTION) { - return; - } - for (int i = 0; i < selectedRow.length; i++) { - if (selectedRow[i] - i < 0) { - continue; - } - removeRow(selectedRow[i] - i); - } - fireTableDataChanged(); - int selection = selectedRow[0] > table.getRowCount() ? table.getRowCount() - 1 - : (selectedRow[0] > 1 ? selectedRow[0] - 1 : 0); - table.getSelectionModel().setSelectionInterval(selection, selection); - } + } + } + if (getRowCount() < 1) { + return; + } + + if (component == null) { + component = DesignerContext.getDesignerFrame(); + } + int val = FineJOptionPane.showConfirmDialog(component, getDeleteTipText() + , com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Remove"), + JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); + if (val != JOptionPane.OK_OPTION) { + return; + } + for (int i = 0; i < selectedRow.length; i++) { + if (selectedRow[i] - i < 0) { + continue; + } + removeRow(selectedRow[i] - i); + } + fireTableDataChanged(); + int selection = selectedRow[0] > table.getRowCount() ? table.getRowCount() - 1 + : (selectedRow[0] > 1 ? selectedRow[0] - 1 : 0); + table.getSelectionModel().setSelectionInterval(selection, selection); + } + + public String getDeleteTipText() { + return deleteTipText; + } + + public void setDeleteTipText(String deleteTipText) { + this.deleteTipText = deleteTipText; + } - private boolean ismultiSelected(){ + private boolean ismultiSelected() { int[] selectedRow = table.getSelectedRows(); return (selectedRow.length == 1 && (selectedRow[0] > table.getRowCount() - 1 || selectedRow[0] < 0)) || selectedRow.length == 0; } diff --git a/designer-base/src/main/java/com/fr/design/gui/itree/filetree/TemplateFileTree.java b/designer-base/src/main/java/com/fr/design/gui/itree/filetree/TemplateFileTree.java index 0a0d6c5d33..b87a70b5b6 100644 --- a/designer-base/src/main/java/com/fr/design/gui/itree/filetree/TemplateFileTree.java +++ b/designer-base/src/main/java/com/fr/design/gui/itree/filetree/TemplateFileTree.java @@ -144,8 +144,8 @@ public class TemplateFileTree extends EnvFileTree { Set supportTypes = createFileExtensionFilter(); return FRContext.getFileNodes().list( path, - supportTypes.toArray(new FileExtension[supportTypes.size()]) - ); + supportTypes.toArray(new FileExtension[supportTypes.size()]), false, true + ); } private Set createFileExtensionFilter() { @@ -306,8 +306,7 @@ public class TemplateFileTree extends EnvFileTree { if (interceptRefresh(root)) { return; } - - if (!TemplateTreeSearchManager.getInstance().isRefreshing()) { + if (!TemplateTreeSearchManager.getInstance().isRefreshing() || TemplateTreeSearchManager.getInstance().allFileNodes().size() != allTreeNode.size()) { currentTreeMode.clear(); calculateNode.clear(); allTreeNode = TemplateTreeSearchManager.getInstance().allFileNodes().entrySet().stream().collect( diff --git a/designer-base/src/main/java/com/fr/design/gui/style/BorderPane.java b/designer-base/src/main/java/com/fr/design/gui/style/BorderPane.java index 6d62593935..d2a302ea01 100644 --- a/designer-base/src/main/java/com/fr/design/gui/style/BorderPane.java +++ b/designer-base/src/main/java/com/fr/design/gui/style/BorderPane.java @@ -265,34 +265,31 @@ public class BorderPane extends AbstractBasicStylePane implements GlobalNameObse int lineStyle = currentLineCombo.getSelectedLineStyle(); Color lineColor = currentLineColorPane.getSelectObject(); CellBorderStyle cellBorderStyle = new CellBorderStyle(); - if (topToggleButton.isSelected()) { - cellBorderStyle.setTopColor(lineColor); + if (lineColor != null) { + if (topToggleButton.isSelected()) { + cellBorderStyle.setTopColor(lineColor); + } + if (bottomToggleButton.isSelected()) { + cellBorderStyle.setBottomColor(lineColor); + } + if (leftToggleButton.isSelected()) { + cellBorderStyle.setLeftColor(lineColor); + } + if (rightToggleButton.isSelected()) { + cellBorderStyle.setRightColor(lineColor); + } + if (verticalToggleButton.isSelected()) { + cellBorderStyle.setVerticalColor(lineColor); + } + if (horizontalToggleButton.isSelected()) { + cellBorderStyle.setHorizontalColor(lineColor); + } } cellBorderStyle.setTopStyle(topToggleButton.isSelected() ? lineStyle : Constants.LINE_NONE); - - if (bottomToggleButton.isSelected()) { - cellBorderStyle.setBottomColor(lineColor); - } cellBorderStyle.setBottomStyle(bottomToggleButton.isSelected() ? lineStyle : Constants.LINE_NONE); - - if (leftToggleButton.isSelected()) { - cellBorderStyle.setLeftColor(lineColor); - } cellBorderStyle.setLeftStyle(leftToggleButton.isSelected() ? lineStyle : Constants.LINE_NONE); - - if (rightToggleButton.isSelected()) { - cellBorderStyle.setRightColor(lineColor); - } cellBorderStyle.setRightStyle(rightToggleButton.isSelected() ? lineStyle : Constants.LINE_NONE); - - if (verticalToggleButton.isSelected()) { - cellBorderStyle.setVerticalColor(lineColor); - } cellBorderStyle.setVerticalStyle(verticalToggleButton.isSelected() ? lineStyle : Constants.LINE_NONE); - - if (horizontalToggleButton.isSelected()) { - cellBorderStyle.setHorizontalColor(lineColor); - } cellBorderStyle.setHorizontalStyle(horizontalToggleButton.isSelected() ? lineStyle : Constants.LINE_NONE); outerToggleButton.setSelected(leftToggleButton.isSelected() && bottomToggleButton.isSelected() && rightToggleButton.isSelected() && topToggleButton.isSelected()); diff --git a/designer-base/src/main/java/com/fr/design/gui/style/ComponentTitleStylePane.java b/designer-base/src/main/java/com/fr/design/gui/style/ComponentTitleStylePane.java index 33af029ad6..1f2fb91b82 100644 --- a/designer-base/src/main/java/com/fr/design/gui/style/ComponentTitleStylePane.java +++ b/designer-base/src/main/java/com/fr/design/gui/style/ComponentTitleStylePane.java @@ -12,6 +12,7 @@ import com.fr.design.gui.icombobox.UIComboBox; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayoutHelper; +import com.fr.design.utils.DesignUtils; import com.fr.design.widget.FRWidgetFactory; import com.fr.form.ui.LayoutBorderStyle; import com.fr.form.ui.WidgetTitle; @@ -90,7 +91,7 @@ public class ComponentTitleStylePane extends AbstractBorderPackerPane { textContentPane = new TinyFormulaPane(); - fontFamilyComboBox = new UIComboBox(Utils.getAvailableFontFamilyNames4Report()); + fontFamilyComboBox = new UIComboBox(DesignUtils.getAvailableFontFamilyNames4Report()); FRFont frFont = DEFAULT_TITLE_PACKER.getFrFont(); if (frFont != null) { String fontFamily = frFont.getFamily(); diff --git a/designer-base/src/main/java/com/fr/design/gui/style/FRFontPane.java b/designer-base/src/main/java/com/fr/design/gui/style/FRFontPane.java index f806ded065..8af5c08d40 100644 --- a/designer-base/src/main/java/com/fr/design/gui/style/FRFontPane.java +++ b/designer-base/src/main/java/com/fr/design/gui/style/FRFontPane.java @@ -18,6 +18,7 @@ import com.fr.design.gui.icombobox.LineComboBox; import com.fr.design.gui.icombobox.UIComboBox; import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayoutHelper; +import com.fr.design.utils.DesignUtils; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.general.ComparatorUtils; import com.fr.general.DefaultValues; @@ -246,7 +247,7 @@ public class FRFontPane extends AbstractBasicStylePane implements GlobalNameObse protected void initComponents() { fontSizeStyleComboBox = new UIComboBox(fontSizeStyles); - fontNameComboBox = new UIComboBox(Utils.getAvailableFontFamilyNames4Report()); + fontNameComboBox = new UIComboBox(DesignUtils.getAvailableFontFamilyNames4Report()); fontNameComboBox.setPreferredSize(new Dimension(144, 20)); fontSizeComboBox = new UIComboBox(getFontSizes()); fontSizeComboBox.setEditable(true); diff --git a/designer-base/src/main/java/com/fr/design/gui/style/TextFormatPaneContainer.java b/designer-base/src/main/java/com/fr/design/gui/style/TextFormatPaneContainer.java new file mode 100644 index 0000000000..bf58ab6558 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/gui/style/TextFormatPaneContainer.java @@ -0,0 +1,81 @@ +package com.fr.design.gui.style; + +import com.fr.base.Style; +import com.fr.design.gui.frpane.AbstractAttrNoScrollPane; +import com.fr.design.gui.frpane.AttributeChangeListener; + +import javax.swing.BorderFactory; +import javax.swing.JPanel; +import java.awt.BorderLayout; +import java.awt.Dimension; + +/** + * 封装格式panel,管理 AttributeChangeListener + * + * @author Leo.Qin + * @version 11.0 + * Created by Leo.Qin on 2022/10/31 + */ +public class TextFormatPaneContainer extends AbstractAttrNoScrollPane { + private TextFormatPane formatPane; + private AttributeChangeListener oldListner; + + @Override + protected JPanel createContentPane() { + formatPane = new TextFormatPane(); + return formatPane; + } + + protected void initContentPane() { + leftContentPane = createContentPane(); + if (leftContentPane != null) { + leftContentPane.setBorder(BorderFactory.createEmptyBorder()); + this.add(leftContentPane, BorderLayout.CENTER); + } + } + + @Override + public Dimension getPreferredSize() { + if (formatPane == null) { + return super.getPreferredSize(); + } + return formatPane.getPreferredSize(); + } + + /** + * 根据单元格样式填充面板设置 + * + * @param style 单元格样式 + */ + public void populateBean(Style style) { + formatPane.populateBean(style); + } + + /** + * 根据面板设置获取修改后的单元格样式 + * + * @param style 单元格当前样式 + * @return 更新后的单元格样式 + */ + public Style update(Style style) { + return formatPane.update(style); + } + + @Override + public void removeAttributeChangeListener() { + super.removeAttributeChangeListener(); + } + + @Override + public void addAttributeChangeListener(AttributeChangeListener listener) { + oldListner = listener; + super.addAttributeChangeListener(listener); + } + + /** + * 恢复使用AttributeChangeListener + */ + public void restoreAttributeChangeListener() { + super.addAttributeChangeListener(oldListner); + } +} diff --git a/designer-base/src/main/java/com/fr/design/gui/style/TranslucentBorderSpecialPane.java b/designer-base/src/main/java/com/fr/design/gui/style/TranslucentBorderSpecialPane.java index 20e47f556c..cc49820de5 100644 --- a/designer-base/src/main/java/com/fr/design/gui/style/TranslucentBorderSpecialPane.java +++ b/designer-base/src/main/java/com/fr/design/gui/style/TranslucentBorderSpecialPane.java @@ -191,7 +191,7 @@ public class TranslucentBorderSpecialPane extends AbstractBorderPackerPane imple String lastUsedBorderImageDirPath = history.getLastSelectedBorderImageDir(); File lastUsedBorderImageDir = StringUtils.isNotEmpty(lastUsedBorderImageDirPath) ? new File(lastUsedBorderImageDirPath) : null; - File inbuiltBorderImagesDir = new File(StableUtils.pathJoin(ProjectLibrary.getInstance().getLibHome(), ProjectConstants.ASSETS_NAME, "border_images")); + File inbuiltBorderImagesDir = new File(StableUtils.pathJoin(ProjectLibrary.getInstance().getLibHome(), ProjectConstants.LOCAL, ProjectConstants.BORDER_IMAGES)); if (lastUsedBorderImageDir!= null && lastUsedBorderImageDir.exists()) { imageFileChooser.setCurrentDirectory(lastUsedBorderImageDir); diff --git a/designer-base/src/main/java/com/fr/design/hyperlink/ReportletHyperlinkPane.java b/designer-base/src/main/java/com/fr/design/hyperlink/ReportletHyperlinkPane.java index 7147ef90e2..48affb7dc3 100644 --- a/designer-base/src/main/java/com/fr/design/hyperlink/ReportletHyperlinkPane.java +++ b/designer-base/src/main/java/com/fr/design/hyperlink/ReportletHyperlinkPane.java @@ -158,6 +158,14 @@ public class ReportletHyperlinkPane extends AbstractHyperLinkPane { return importedJsPane; } - - /** * 参数改变 * diff --git a/designer-base/src/main/java/com/fr/design/layout/FRGUIPaneFactory.java b/designer-base/src/main/java/com/fr/design/layout/FRGUIPaneFactory.java index ce8fdaa9d7..417533465d 100644 --- a/designer-base/src/main/java/com/fr/design/layout/FRGUIPaneFactory.java +++ b/designer-base/src/main/java/com/fr/design/layout/FRGUIPaneFactory.java @@ -607,6 +607,24 @@ public class FRGUIPaneFactory { return jp; } + /** + * 创建垂直流布局,水平填充面板 + * + * @param isAlignLeft 是否左对齐 + * @param align the alignment value + * @param hgap the horizontal gap between components + * @param vgap the vertical gap between components + * @param hfill 水平填充组件 + * @return JPanel对象 + */ + public static JPanel createVerticalFlowLayout_F_Pane(boolean isAlignLeft, int align, int hgap, int vgap, boolean hfill) { + JPanel jp = new JPanel(); + VerticalFlowLayout layout = new VerticalFlowLayout(align, hgap, vgap, hfill); + layout.setAlignLeft(isAlignLeft); + jp.setLayout(layout); + return jp; + } + /** * 创建边框面板L * diff --git a/designer-base/src/main/java/com/fr/design/layout/VerticalFlowLayout.java b/designer-base/src/main/java/com/fr/design/layout/VerticalFlowLayout.java index c857c7301b..9f91fee506 100644 --- a/designer-base/src/main/java/com/fr/design/layout/VerticalFlowLayout.java +++ b/designer-base/src/main/java/com/fr/design/layout/VerticalFlowLayout.java @@ -95,6 +95,15 @@ public class VerticalFlowLayout implements LayoutManager, java.io.Serializable { */ protected int vgap; + + /** + * true: 水平填充组件 + * + * @see #isHfill() + * @see #setHfill(boolean) + */ + protected boolean hfill; + /** * Constructs a new FlowLayout with a centered alignment and a * default 5-unit horizontal and vertical gap. @@ -135,6 +144,14 @@ public class VerticalFlowLayout implements LayoutManager, java.io.Serializable { setAlignment(align); } + public VerticalFlowLayout(int align, int hgap, int vgap, boolean fill) { + this.hgap = hgap; + this.vgap = vgap; + this.hfill = fill; + + setAlignment(align); + } + /** * Gets the alignment for this layout. * Possible values are FlowLayout.TOP, @@ -219,6 +236,31 @@ public class VerticalFlowLayout implements LayoutManager, java.io.Serializable { * @param name the name of the component * @param comp the component to be added */ + + /** + * Gets the horizontal filling of components in the + * Container.The default is false. + * + * @return the horizontal filling of components in the + * Container + * @see #setHfill(boolean) + */ + public boolean isHfill() { + return hfill; + } + + /** + * Sets the horizontal filling of components in the + * Container.The default is false. + * + * @param hfill the horizontal filling of components in the + * Container + * @see #isHfill() + */ + public void setHfill(boolean hfill) { + this.hfill = hfill; + } + @Override public void addLayoutComponent(String name, Component comp) { } @@ -379,6 +421,7 @@ public class VerticalFlowLayout implements LayoutManager, java.io.Serializable { Insets insets = target.getInsets(); int maxlen = getMaxLen4LayoutContainer(target, insets); + int maxwidth = target.getWidth() - (insets.left + insets.right); int nmembers = target.getComponentCount(); int x = getX4LayoutContainer(insets), y = getY4LayoutContainer(insets); int roww = 0, start = 0; @@ -390,6 +433,9 @@ public class VerticalFlowLayout implements LayoutManager, java.io.Serializable { Component m = target.getComponent(i); if (m.isVisible()) { Dimension d = getPreferredSize(target, m); + if (hfill) { + d.width = maxwidth; + } m.setSize(d.width, d.height); rs = dealWithDim4LayoutContainer(target, insets, d, x, y, roww, start, maxlen, i, ltr); diff --git a/designer-base/src/main/java/com/fr/design/mainframe/AbsoluteMeasureUIMode.java b/designer-base/src/main/java/com/fr/design/mainframe/AbsoluteMeasureUIMode.java new file mode 100644 index 0000000000..2085127d73 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/mainframe/AbsoluteMeasureUIMode.java @@ -0,0 +1,37 @@ +package com.fr.design.mainframe; + +import com.fr.base.AutoChangeLineProvider; +import com.fr.base.DefaultAutoChangeLine; +import com.fr.base.ScreenResolution; +import com.fr.design.fun.ReportLengthUNITProvider; +import com.fr.design.unit.UnitConvertUtil; + +public class AbsoluteMeasureUIMode implements DesignerUIMode { + + private static class AbsoluteMeasureUIModeHolder { + private static final AbsoluteMeasureUIMode absoluteMeasureUIMode = new AbsoluteMeasureUIMode(); + } + + private AbsoluteMeasureUIMode() { + + } + + public static AbsoluteMeasureUIMode getInstance() { + return AbsoluteMeasureUIModeHolder.absoluteMeasureUIMode; + } + + @Override + public ReportLengthUNITProvider parseLengthUNIT(int unitType) { + return UnitConvertUtil.parseLengthUNIT(unitType); + } + + @Override + public AutoChangeLineProvider getAutoChangeLineStrategy() { + return new DefaultAutoChangeLine(); + } + + @Override + public int getScreenResolution() { + return ScreenResolution.getScreenResolution(); + } +} \ No newline at end of file diff --git a/designer-base/src/main/java/com/fr/design/mainframe/CenterRegionContainerPane.java b/designer-base/src/main/java/com/fr/design/mainframe/CenterRegionContainerPane.java index 0e06cc87a0..b18b346525 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/CenterRegionContainerPane.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/CenterRegionContainerPane.java @@ -4,7 +4,7 @@ import com.fr.design.DesignState; import com.fr.design.base.mode.DesignModeContext; import com.fr.design.constants.UIConstants; import com.fr.design.file.HistoryTemplateListCache; -import com.fr.design.file.MutilTempalteTabPane; +import com.fr.design.file.MultiTemplateTabPane; import com.fr.design.file.NewTemplatePane; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.imenu.UIMenuHighLight; @@ -87,7 +87,7 @@ public class CenterRegionContainerPane extends JPanel { eastCenterPane.add(combineUp, BorderLayout.NORTH); templateTabPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); templateTabPane.add(newWorkBookPane = getToolBarMenuDock().getNewTemplatePane(), BorderLayout.WEST); - templateTabPane.add(MutilTempalteTabPane.getInstance(), BorderLayout.CENTER); + templateTabPane.add(MultiTemplateTabPane.getInstance(), BorderLayout.CENTER); eastCenterPane.add(templateTabPane, BorderLayout.CENTER); eastPane.add(eastCenterPane, BorderLayout.CENTER); diff --git a/designer-base/src/main/java/com/fr/design/mainframe/DesignerFrame.java b/designer-base/src/main/java/com/fr/design/mainframe/DesignerFrame.java index dfd2a20cd0..e88d0c946c 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/DesignerFrame.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/DesignerFrame.java @@ -21,7 +21,7 @@ import com.fr.design.event.TargetModifiedEvent; import com.fr.design.event.TargetModifiedListener; import com.fr.design.file.HistoryTemplateListCache; import com.fr.design.file.HistoryTemplateListPane; -import com.fr.design.file.MutilTempalteTabPane; +import com.fr.design.file.MultiTemplateTabPane; import com.fr.design.file.SaveSomeTemplatePane; import com.fr.design.file.TemplateTreePane; import com.fr.design.fun.OemProcessor; @@ -886,6 +886,54 @@ public class DesignerFrame extends JFrame implements JTemplateActionListener, Ta layeredPane.repaint(); } + /** + * 激活模板 + *

+ * activateJTemplate需要模板存在,openTemplate需要模板保存过,该方法模板保存与未保存皆可激活,模板如果关闭,并且保存过,会重新打开 + * + * @param templatePath 模板路径 template.getPath() + */ + public void openOrActiveTemplate(String templatePath) { + //没保存过的模板如果要激活就要从当前历史模板列表里面找 + String templateName = getTemplateNameFromPath(templatePath); + if (isTemplateNeverSaved(templatePath)) { + int index = HistoryTemplateListCache.getInstance().contains(templateName); + //如果历史模板列表中存在则激活 + if (index != -1) { + DesignerContext.getDesignerFrame().activateJTemplate(HistoryTemplateListCache.getInstance().getTemplate(index)); + } + } else { + DesignerContext.getDesignerFrame().openTemplate(FILEFactory.createFILE(templatePath)); + } + } + + /** + * 指定路径的模板是否保存过 + * + * @param templatePath 模板路径 template.getPath() + * @return 如果模板没保存过则返回true + */ + private boolean isTemplateNeverSaved(String templatePath) { + FILE tplFile = FILEFactory.createFILE(templatePath); + //没保存过的模板获取到的templatePath所生成的FILE文件会不存在 + return tplFile == null || !tplFile.exists() || StringUtils.isEmpty(templatePath); + } + + /** + * 根据模板路径获取模板名称 + * @param templatePath 模板路径 template.getPath() + * @return 模板名 + */ + private String getTemplateNameFromPath(String templatePath) { + FILE tplFile = FILEFactory.createFILE(templatePath); + String templateName = StringUtils.EMPTY; + if (tplFile != null) { + templateName = tplFile.getName(); + } + return templateName; + } + + /** * 当前模板 停用失败 * @@ -1062,7 +1110,7 @@ public class DesignerFrame extends JFrame implements JTemplateActionListener, Ta // 新的form不往前兼容 if (inValidDesigner(jt)) { this.addAndActivateJTemplate(); - MutilTempalteTabPane.getInstance().setTemTemplate( + MultiTemplateTabPane.getInstance().setTemTemplate( HistoryTemplateListCache.getInstance().getCurrentEditingTemplate()); } else { this.addAndActivateJTemplate(jt); @@ -1231,6 +1279,7 @@ public class DesignerFrame extends JFrame implements JTemplateActionListener, Ta /** * 判断是否正在进行服务器配置 + * * @return boolean */ public boolean isServerConfig() { @@ -1239,6 +1288,7 @@ public class DesignerFrame extends JFrame implements JTemplateActionListener, Ta /** * 设置是否正在进行服务器配置 + * * @param serverConfig */ public void setServerConfig(boolean serverConfig) { diff --git a/designer-base/src/main/java/com/fr/design/mainframe/DesignerFrameFileDealerPane.java b/designer-base/src/main/java/com/fr/design/mainframe/DesignerFrameFileDealerPane.java index 04a513d5b6..87864ffd21 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/DesignerFrameFileDealerPane.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/DesignerFrameFileDealerPane.java @@ -21,7 +21,7 @@ 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.MultiTemplateTabPane; import com.fr.design.file.TemplateTreePane; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ilable.UILabel; @@ -172,8 +172,8 @@ public class DesignerFrameFileDealerPane extends JPanel implements FileToolbarSt tooBarPane.add(new UIMenuHighLight(), BorderLayout.SOUTH); searchToolbarPane = new TemplateTreeSearchToolbarPane(toolBar); + searchToolbarPane.add(createUpToolBarPane(), BorderLayout.EAST); searchToolbarPane.setPreferredSize(new Dimension(this.getWidth(), 23)); - add(searchToolbarPane, BorderLayout.NORTH); CardLayout card; JPanel cardPane = new JPanel(card = new CardLayout()); @@ -183,7 +183,6 @@ public class DesignerFrameFileDealerPane extends JPanel implements FileToolbarSt card.show(cardPane, FILE); TemplateTreePane.getInstance().setToolbarStateChangeListener(this); - add(cardPane, BorderLayout.CENTER); stateChange(); } @@ -219,7 +218,6 @@ public class DesignerFrameFileDealerPane extends JPanel implements FileToolbarSt 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)); @@ -277,7 +275,7 @@ public class DesignerFrameFileDealerPane extends JPanel implements FileToolbarSt TableDataTreePane.getInstance(DesignModelAdapter.getCurrentModelAdapter()); HistoryTemplateListPane.getInstance().setCurrentEditingTemplate(jt); //处理自动新建的模板 - MutilTempalteTabPane.getInstance().doWithtemTemplate(); + MultiTemplateTabPane.getInstance().doWithtemTemplate(); if (DesignerMode.isAuthorityEditing()) { RolesAlreadyEditedPane.getInstance().refreshDockingView(); } @@ -461,6 +459,7 @@ public class DesignerFrameFileDealerPane extends JPanel implements FileToolbarSt public void actionPerformed(ActionEvent e) { // 交换层级 searchToolbarPane.switchPane(TemplateTreeSearchToolbarPane.SEARCH_PANE); + refreshRightToolBarByContentPaneType(); TemplateTreePane.getInstance().refreshDockingView(); TemplateTreeSearchManager.getInstance().switchToSearch(TemplateTreePane.getInstance().getTemplateFileTree()); } @@ -548,10 +547,10 @@ public class DesignerFrameFileDealerPane extends JPanel implements FileToolbarSt for (JTemplate jTemplate : HistoryTemplateListCache.getInstance().getHistoryList()) { if (ComparatorUtils.equals(jTemplate.getEditingFILE().getPath(), path)) { if (isCurrentEditing) { - MutilTempalteTabPane.getInstance().setIsCloseCurrent(true); + MultiTemplateTabPane.getInstance().setIsCloseCurrent(true); } - MutilTempalteTabPane.getInstance().closeFormat(jTemplate); - MutilTempalteTabPane.getInstance().closeSpecifiedTemplate(jTemplate); + MultiTemplateTabPane.getInstance().closeFormat(jTemplate); + MultiTemplateTabPane.getInstance().closeSpecifiedTemplate(jTemplate); return; } } @@ -595,15 +594,36 @@ public class DesignerFrameFileDealerPane extends JPanel implements FileToolbarSt } } + /** + * 搜索状态下不显示rightToolBar + */ + public void refreshRightToolBarByContentPaneType() { + if (rightToolBar != null) { + if (StringUtils.equals(TemplateTreeSearchToolbarPane.contentPaneType, TemplateTreeSearchToolbarPane.SEARCH_PANE)) { + rightToolBar.setVisible(false); + } + } + } + public void refreshRightToolBarBy(FileNode fileNode) { + refreshRightToolBarByNode(fileNode); + refreshRightToolBarByContentPaneType(); + } + + /** + * 根据当前选中节点判断是否锁定状态 + * + * @param fileNode 选中文件节点 + */ + public void refreshRightToolBarByNode(FileNode fileNode) { if (rightToolBar != null) { boolean locked = fileNode != null - && StringUtils.isNotEmpty(fileNode.getLock()) - && !ComparatorUtils.equals(fileNode.getLock(), fileNode.getUserID()); + && 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()); + && WorkContext.getCurrent().isRoot() + && WorkContext.getCurrent().get(LockInfoOperator.class).isUnLockable() + && !WorkContext.getCurrent().get(LockInfoOperator.class).isTplUnLocked(fileNode.getEnvPath()); rightToolBar.setVisible(visible); } } diff --git a/designer-base/src/main/java/com/fr/design/mainframe/DesignerUIMode.java b/designer-base/src/main/java/com/fr/design/mainframe/DesignerUIMode.java new file mode 100644 index 0000000000..801291125a --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/mainframe/DesignerUIMode.java @@ -0,0 +1,17 @@ +package com.fr.design.mainframe; + +import com.fr.base.AutoChangeLineProvider;; +import com.fr.design.fun.ReportLengthUNITProvider; + +/** + * 设计器上和展示相关配置 + */ +public interface DesignerUIMode { + + ReportLengthUNITProvider parseLengthUNIT(int unitType); + + AutoChangeLineProvider getAutoChangeLineStrategy(); + + int getScreenResolution(); + +} diff --git a/designer-base/src/main/java/com/fr/design/mainframe/DesignerUIModeConfig.java b/designer-base/src/main/java/com/fr/design/mainframe/DesignerUIModeConfig.java index 400f698185..cd99f728a2 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/DesignerUIModeConfig.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/DesignerUIModeConfig.java @@ -1,19 +1,14 @@ package com.fr.design.mainframe; import com.fr.base.AutoChangeLineProvider; -import com.fr.base.DefaultAutoChangeLine; -import com.fr.base.ScreenResolution; import com.fr.design.fun.ReportLengthUNITProvider; -import com.fr.design.unit.UnitConvertUtil; -import com.fr.form.fit.NewUIModeAutoChangeLine; import com.fr.general.ComparatorUtils; -import com.fr.stable.Constants; /** * Created by kerry on 2020-06-05 */ public class DesignerUIModeConfig { - private DesignerUIMode mode = DesignerUIMode.ABSOLUTE_MEASURE_UI_MODE; + private DesignerUIMode mode = AbsoluteMeasureUIMode.getInstance(); private static class DesignerUIModeConfigHolder { private static final DesignerUIModeConfig designerUIModeConfig = new DesignerUIModeConfig(); @@ -34,21 +29,25 @@ public class DesignerUIModeConfig { * @return boolean */ public boolean simulateWebUIMode() { - return ComparatorUtils.equals(DesignerUIMode.SIMULATE_WEB_UI_MODE, mode); + return ComparatorUtils.equals(SimulateWebUIMode.getInstance(), mode); } /** * 设置新ui模式 */ public void setSimulateWebUIMode() { - this.mode = DesignerUIMode.SIMULATE_WEB_UI_MODE; + this.mode = SimulateWebUIMode.getInstance(); + } + + public void setDesignerUIMode(DesignerUIMode mode) { + this.mode = mode; } /** * 设置老ui模式 */ public void setAbsoluteMeasureUIMode() { - this.mode = DesignerUIMode.ABSOLUTE_MEASURE_UI_MODE; + this.mode = AbsoluteMeasureUIMode.getInstance(); } /** @@ -78,50 +77,4 @@ public class DesignerUIModeConfig { return mode.getScreenResolution(); } - - private enum DesignerUIMode { - ABSOLUTE_MEASURE_UI_MODE { - @Override - protected ReportLengthUNITProvider parseLengthUNIT(int unitType) { - return UnitConvertUtil.parseLengthUNIT(unitType); - } - - @Override - public AutoChangeLineProvider getAutoChangeLineStrategy() { - return new DefaultAutoChangeLine(); - } - - @Override - protected int getScreenResolution() { - return ScreenResolution.getScreenResolution(); - } - - }, - SIMULATE_WEB_UI_MODE { - @Override - protected ReportLengthUNITProvider parseLengthUNIT(int unitType) { - return new PXReportLengthUNIT(); - } - - @Override - public AutoChangeLineProvider getAutoChangeLineStrategy() { - return new NewUIModeAutoChangeLine(); - } - - @Override - protected int getScreenResolution() { - return Constants.DEFAULT_WEBWRITE_AND_SCREEN_RESOLUTION; - } - - }; - - protected abstract ReportLengthUNITProvider parseLengthUNIT(int unitType); - - public abstract AutoChangeLineProvider getAutoChangeLineStrategy(); - - - protected abstract int getScreenResolution(); - - } - } diff --git a/designer-base/src/main/java/com/fr/design/mainframe/EastRegionContainerPane.java b/designer-base/src/main/java/com/fr/design/mainframe/EastRegionContainerPane.java index d640f84f44..d32a54ca4f 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/EastRegionContainerPane.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/EastRegionContainerPane.java @@ -354,12 +354,7 @@ public class EastRegionContainerPane extends UIEastResizableContainer { public void updateCellElementState(boolean isSelectedOneCell) { PropertyItem cellElement = propertyItemMap.get(KEY_CELL_ELEMENT); - if (isSelectedOneCell) { - enableCellElementPane(cellElement); - } else { // 如果选中多个单元格,禁用单元格元素 tab - disableCellElementPane(cellElement); - refreshRightPane(); - } + enableCellElementPane(cellElement); } // 禁用单元格元素tab diff --git a/designer-base/src/main/java/com/fr/design/mainframe/JNullTemplate.java b/designer-base/src/main/java/com/fr/design/mainframe/JNullTemplate.java index d10df810a2..656344b186 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/JNullTemplate.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/JNullTemplate.java @@ -204,4 +204,14 @@ public class JNullTemplate extends JTemplate { public int getToolBarHeight() { return 0; } + + @Override + public String getPath() { + return null; + } + + @Override + public void refreshToolArea() { + DesignerContext.getDesignerFrame().resetToolkitByPlus(this); + } } diff --git a/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java b/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java index fe0e4ee4ff..444ef577fb 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java @@ -54,6 +54,7 @@ import com.fr.design.mainframe.toolbar.VcsScene; import com.fr.design.menu.MenuDef; import com.fr.design.menu.NameSeparator; import com.fr.design.menu.ShortCut; +import com.fr.design.module.DesignModuleFactory; import com.fr.design.preview.PagePreview; import com.fr.design.ui.util.UIUtil; import com.fr.design.utils.DesignUtils; @@ -110,6 +111,7 @@ import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.FontMetrics; import java.io.ByteArrayOutputStream; +import java.nio.file.Paths; import java.util.Set; import java.util.concurrent.Callable; @@ -327,7 +329,7 @@ public abstract class JTemplate> /** * 为另存的模板创建新的模板id */ - private void generateNewTemplateIdForSaveAs() { + protected void generateNewTemplateIdForSaveAs() { generateTemplateId(); } @@ -1109,6 +1111,10 @@ public abstract class JTemplate> tplMenu.addShortCut(shortCuts4Authority()); } + //查找替换 + tplMenu.addShortCut(new NameSeparator(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Replace_Name_Separate"))); + tplMenu.addShortCut((ShortCut) DesignModuleFactory.getITReplaceAction()); + return new MenuDef[]{tplMenu}; } @@ -1615,7 +1621,7 @@ public abstract class JTemplate> return StringUtils.EMPTY; } String path = this.getEditingFILE().getPath(); - CptxMetadata metadata = CptxFileUtils.getMetadata(path); + CptxMetadata metadata = Paths.get(path).isAbsolute() ? null : CptxFileUtils.getMetadata(path); //是否是兼容模式,兼容模式下,设置了新引擎的cpt和cptx的后缀不同 if (metadata != null && metadata.isForceCpt()) { if (path.endsWith(".cptx")) { diff --git a/designer-base/src/main/java/com/fr/design/mainframe/JTemplateNameHelper.java b/designer-base/src/main/java/com/fr/design/mainframe/JTemplateNameHelper.java index 96ca5b4843..0f245d8bb4 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/JTemplateNameHelper.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/JTemplateNameHelper.java @@ -1,5 +1,6 @@ package com.fr.design.mainframe; +import com.fr.design.file.HistoryTemplateListCache; import com.fr.design.file.TemplateTreePane; import com.fr.design.gui.itree.filetree.TemplateFileTree; import com.fr.stable.StringUtils; @@ -19,8 +20,6 @@ public class JTemplateNameHelper { private static final int PREFIX_NUM = 3000; - private static short currentIndex = 0;// 此变量用于多次新建模板时,让名字不重复 - public static String newTemplateNameByIndex(String prefix) { // 用于获取左侧模板的文件名,如左侧已包含"WorkBook1.cpt, WorkBook12.cpt, WorkBook177.cpt" // 那么新建的文件名将被命名为"WorkBook178.cpt",即取最大数+1 @@ -37,13 +36,33 @@ public class JTemplateNameHelper { reportNum.add(index); } } + //把当前编辑面板的模板名也加进来判断 + addHistoryTemplateName2List(reportNum, prefix); Collections.sort(reportNum); BigInteger idx = reportNum.size() > 0 ? reportNum.get(reportNum.size() - 1).add(BigInteger.valueOf(1)) : BigInteger.valueOf(1); - idx = idx.add(BigInteger.valueOf(currentIndex)); - currentIndex++; return prefix + idx; } + /** + * 将当前打开的模板列表的模板名处理一下加进来,以便于获取左侧模板文件名与当前模板列表的最大值 + * + * @param reportNum 存储后缀的列表 + * @param prefix 前缀 + */ + private static void addHistoryTemplateName2List(List reportNum, String prefix) { + int len = HistoryTemplateListCache.getInstance().getHistoryCount(); + for (int i = 0; i < len; i++) { + JTemplate jTemplate = HistoryTemplateListCache.getInstance().get(i); + if (jTemplate != null) { + String templateName = jTemplate.getTemplateName(); + BigInteger index = getFileNameIndex(prefix, templateName); + if (index != null) { + reportNum.add(index); + } + } + } + } + /** * @return java.lang.Integer WorkBook11.cpt则返回11,如果没有找到index返回null * @Description 返回文件名中的index diff --git a/designer-base/src/main/java/com/fr/design/mainframe/SimulateWebUIMode.java b/designer-base/src/main/java/com/fr/design/mainframe/SimulateWebUIMode.java new file mode 100644 index 0000000000..a13bff759f --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/mainframe/SimulateWebUIMode.java @@ -0,0 +1,38 @@ +package com.fr.design.mainframe; + +import com.fr.base.AutoChangeLineProvider; +import com.fr.design.fun.ReportLengthUNITProvider; +import com.fr.form.fit.NewUIModeAutoChangeLine; +import com.fr.stable.Constants; + +public class SimulateWebUIMode implements DesignerUIMode { + + private static class SimulateWebUIModeHolder { + private static final SimulateWebUIMode simulateWebUIMode = new SimulateWebUIMode(); + } + + private SimulateWebUIMode() { + + } + + public static SimulateWebUIMode getInstance() { + return SimulateWebUIModeHolder.simulateWebUIMode; + } + + + @Override + public ReportLengthUNITProvider parseLengthUNIT(int unitType) { + return new PXReportLengthUNIT(); + } + + @Override + public AutoChangeLineProvider getAutoChangeLineStrategy() { + return new NewUIModeAutoChangeLine(); + } + + @Override + public int getScreenResolution() { + return Constants.DEFAULT_WEBWRITE_AND_SCREEN_RESOLUTION; + } + +} diff --git a/designer-base/src/main/java/com/fr/design/mainframe/loghandler/DesignerLogHandler.java b/designer-base/src/main/java/com/fr/design/mainframe/loghandler/DesignerLogHandler.java index 621956ce6a..b36ca47294 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/loghandler/DesignerLogHandler.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/loghandler/DesignerLogHandler.java @@ -1,6 +1,6 @@ package com.fr.design.mainframe.loghandler; -import com.finebi.cbb.base.tuple.Pair; +import com.fr.stable.collections.combination.Pair; import com.fr.base.BaseUtils; import com.fr.base.TRL; import com.fr.design.file.HistoryTemplateListCache; diff --git a/designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/control/pane/TemplateTreeSearchToolbarPane.java b/designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/control/pane/TemplateTreeSearchToolbarPane.java index bb98561bf9..e2deb13254 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/control/pane/TemplateTreeSearchToolbarPane.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/control/pane/TemplateTreeSearchToolbarPane.java @@ -39,6 +39,11 @@ public class TemplateTreeSearchToolbarPane extends JPanel implements TreeSearchS public static final String SEARCH_PANE = "searchPane"; + /** + * 判断工具栏是处于搜索栏还是非搜索栏 + */ + public static String contentPaneType = "toolbarPane"; + /** * 工具栏 */ @@ -187,6 +192,7 @@ public class TemplateTreeSearchToolbarPane extends JPanel implements TreeSearchS */ public void switchPane(String name) { cardLayout.show(contentPane, name); + contentPaneType = name; } public void setPlaceHolder(String placeHolder) { diff --git a/designer-base/src/main/java/com/fr/design/mainframe/mobile/ui/SidebarMobileBookMarkStyleCustomDefinePane.java b/designer-base/src/main/java/com/fr/design/mainframe/mobile/ui/SidebarMobileBookMarkStyleCustomDefinePane.java index ae79160bbd..0ed58fa351 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/mobile/ui/SidebarMobileBookMarkStyleCustomDefinePane.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/mobile/ui/SidebarMobileBookMarkStyleCustomDefinePane.java @@ -17,6 +17,7 @@ import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayoutHelper; import com.fr.design.style.color.ColorSelectBox; +import com.fr.design.utils.DesignUtils; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.form.ui.mobile.MobileBookMarkStyle; import com.fr.form.ui.mobile.impl.SidebarMobileBookMarkStyle; @@ -161,7 +162,7 @@ public class SidebarMobileBookMarkStyleCustomDefinePane extends BasicBeanPane { private UICheckBox autoCommitCheckBox; + private UISpinner maxDirectShowCountSpinner; + private UILabel showCountTextField; + private static final int MAX_VALUE_AUTO = 4; + private static final int MAX_VALUE = 3; + private static final int MIN_VALUE = 1; + private static final int DEFAULT_DIERTA = 1; + private static final int DEFAULT_VALUE = 4; + private static final int GAP = 2; public MobileTopParamPane() { this.init(); @@ -21,19 +37,43 @@ public class MobileTopParamPane extends BasicBeanPane { JPanel panel = FRGUIPaneFactory.createTitledBorderPane(Toolkit.i18nText("Fine-Plugin-TopParam_Setting")); panel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0)); autoCommitCheckBox = new UICheckBox(Toolkit.i18nText("Fine-Plugin-TopParam_AutoCommit"), true); - panel.add(autoCommitCheckBox); + maxDirectShowCountSpinner = new UISpinner(MIN_VALUE, MAX_VALUE_AUTO, DEFAULT_DIERTA, DEFAULT_VALUE); + showCountTextField = new UILabel(Toolkit.i18nText("Fine-Design_Mobile_Widget_Show_Count")); + Component[][] components = {{autoCommitCheckBox},{showCountTextField, maxDirectShowCountSpinner}}; + double p = TableLayout.PREFERRED; + double f = TableLayout.FILL; + double[] rowSize = {p, p}; + double[] columnSize = {p, f}; + JPanel paraPane = TableLayoutHelper.createCommonTableLayoutPane(components, rowSize, columnSize, GAP); + panel.add(paraPane); this.add(panel, BorderLayout.CENTER); + + autoCommitCheckBox.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if (!autoCommitCheckBox.isSelected()) { + maxDirectShowCountSpinner.setMaxValue(MAX_VALUE); + if (maxDirectShowCountSpinner.getValue() >= MAX_VALUE_AUTO) { + maxDirectShowCountSpinner.setValue(MAX_VALUE); + } + } else { + maxDirectShowCountSpinner.setMaxValue(MAX_VALUE_AUTO); + } + } + }); } @Override public void populateBean(MobileTopParamStyle topParamStyle) { autoCommitCheckBox.setSelected(topParamStyle.isAutoCommit()); + maxDirectShowCountSpinner.setValue(topParamStyle.getMaxDirectShowCount()); } @Override public MobileTopParamStyle updateBean() { MobileTopParamStyle topParamStyle = new MobileTopParamStyle(); topParamStyle.setAutoCommit(autoCommitCheckBox.isSelected()); + topParamStyle.setMaxDirectShowCount((int) maxDirectShowCountSpinner.getValue()); return topParamStyle; } diff --git a/designer-base/src/main/java/com/fr/design/mainframe/mobile/utils/FontConfigPane.java b/designer-base/src/main/java/com/fr/design/mainframe/mobile/utils/FontConfigPane.java index 6386e31e01..2b98479be2 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/mobile/utils/FontConfigPane.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/mobile/utils/FontConfigPane.java @@ -5,6 +5,7 @@ import com.fr.base.Utils; import com.fr.design.gui.ibutton.UIColorButton; import com.fr.design.gui.ibutton.UIToggleButton; import com.fr.design.gui.icombobox.UIComboBox; +import com.fr.design.utils.DesignUtils; import com.fr.general.FRFont; import javax.swing.*; @@ -35,7 +36,7 @@ public class FontConfigPane extends JPanel { private void init() { this.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 0)); - fontFamily = new UIComboBox(Utils.getAvailableFontFamilyNames4Report()); + fontFamily = new UIComboBox(DesignUtils.getAvailableFontFamilyNames4Report()); Vector integerList = new Vector<>(); for (int i = 1; i < 100; i++) { integerList.add(i); diff --git a/designer-base/src/main/java/com/fr/design/mainframe/platform/ServicePlatformAction.java b/designer-base/src/main/java/com/fr/design/mainframe/platform/ServicePlatformAction.java new file mode 100644 index 0000000000..c6dc9a9b66 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/mainframe/platform/ServicePlatformAction.java @@ -0,0 +1,30 @@ +package com.fr.design.mainframe.platform; + +import com.fr.design.actions.UpdateAction; +import com.fr.design.i18n.Toolkit; +import com.fr.design.utils.BrowseUtils; +import com.fr.general.CloudCenter; +import com.fr.log.FineLoggerFactory; + +import java.awt.Desktop; +import java.awt.event.ActionEvent; +import java.net.URI; + +/** + * 帮助-服务平台 + * + * @author Destiny.Lin + * @version 11.0 + * created by Destiny.Lin on 2022-12-14 + */ +public class ServicePlatformAction extends UpdateAction { + public ServicePlatformAction() { + this.setName(Toolkit.i18nText("Fine-Design_Basic_Service_Platform_Title")); + this.setSmallIcon("/com/fr/design/images/platform/platform", false); + } + + @Override + public void actionPerformed(ActionEvent e) { + BrowseUtils.browser(CloudCenter.getInstance().acquireUrlByKind("service.platform")); + } +} diff --git a/designer-base/src/main/java/com/fr/design/mainframe/theme/FormThemeProfilePane.java b/designer-base/src/main/java/com/fr/design/mainframe/theme/FormThemeProfilePane.java index 798bb73c59..eb15a657f5 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/theme/FormThemeProfilePane.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/theme/FormThemeProfilePane.java @@ -4,12 +4,14 @@ import com.fr.base.theme.FormTheme; import com.fr.base.theme.TemplateThemeConfig; import com.fr.base.theme.settings.ThemedComponentStyle; import com.fr.base.theme.settings.ThemedFormBodyStyle; +import com.fr.design.ExtraDesignClassManager; import com.fr.design.i18n.Toolkit; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.mainframe.theme.edit.ChartStyleFormEditPane; import com.fr.design.mainframe.theme.edit.ComponentStyleEditPane; import com.fr.design.mainframe.theme.edit.FormBodyStyleEditPane; import com.fr.design.mainframe.theme.preview.FormThemePreviewPane; +import com.fr.design.mainframe.theme.processor.ThemePreviewPaneProcessor; import javax.swing.JPanel; @@ -31,7 +33,11 @@ public class FormThemeProfilePane extends TemplateThemeProfilePane { } @Override - public FormThemePreviewPane createThemePreviewPane() { + public TemplateThemePreviewPane createThemePreviewPane() { + ThemePreviewPaneProcessor processor = ExtraDesignClassManager.getInstance().getSingle(ThemePreviewPaneProcessor.XML_TAG); + if (processor != null) { + return processor.createFormThemePreviewPane(); + } return new FormThemePreviewPane(); } @@ -61,6 +67,7 @@ public class FormThemeProfilePane extends TemplateThemeProfilePane { componentStyleSettingPane = new ComponentStyleEditPane(); addCustomEditorPane(i18nText("Fine-Design_Predefined_Component_Style"), componentStyleSettingPane); + refreshExtraAdvancedPane(); } @Override diff --git a/designer-base/src/main/java/com/fr/design/mainframe/theme/ReportThemeProfilePane.java b/designer-base/src/main/java/com/fr/design/mainframe/theme/ReportThemeProfilePane.java index f0f25f677f..57e6ddf5f1 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/theme/ReportThemeProfilePane.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/theme/ReportThemeProfilePane.java @@ -2,10 +2,11 @@ package com.fr.design.mainframe.theme; import com.fr.base.theme.ReportTheme; import com.fr.base.theme.TemplateThemeConfig; +import com.fr.design.ExtraDesignClassManager; import com.fr.design.i18n.Toolkit; import com.fr.design.mainframe.theme.edit.ReportBodyStyleEditPane; import com.fr.design.mainframe.theme.preview.ReportThemePreviewPane; -import javax.swing.JPanel; +import com.fr.design.mainframe.theme.processor.ThemePreviewPaneProcessor; /** * @author Starryi @@ -20,7 +21,11 @@ public class ReportThemeProfilePane extends TemplateThemeProfilePane createThemePreviewPane() { + ThemePreviewPaneProcessor processor = ExtraDesignClassManager.getInstance().getSingle(ThemePreviewPaneProcessor.XML_TAG); + if (processor != null) { + return processor.createReportThemePreviewPane(); + } return new ReportThemePreviewPane(); } @@ -44,6 +49,7 @@ public class ReportThemeProfilePane extends TemplateThemeProfilePane extends J protected ColorListPane colorListPane; protected CellStyleListEditPane cellStyleSettingPane; protected ChartStyleEditPane chartStyleSettingPane; + protected final List> extraPaneList = new ArrayList<>(); protected boolean isPopulating = false; protected UITabbedPane uiTabbedPane; @@ -171,7 +178,7 @@ public abstract class TemplateThemeEditorPane extends J uiTabbedPane = new UITabbedPane(); uiTabbedPane.setBorder(BorderFactory.createEmptyBorder(10, 5, 10, 1)); container.add(uiTabbedPane, BorderLayout.CENTER); - + initPluginListener(); return container; } @@ -192,6 +199,33 @@ public abstract class TemplateThemeEditorPane extends J }); uiTabbedPane.addTab(title, settingPane); } + + protected void refreshExtraAdvancedPane() { + extraPaneList.clear(); + Set> providers = ExtraDesignClassManager.getInstance().getArray(TemplateThemePaneProvider.XML_TAG); + for (TemplateThemePaneProvider provider : providers) { + insertShortCut(provider.getInsertPosition(extraPaneList.size()), provider.getTab()); + } + for (BasicBeanPane pane : extraPaneList) { + addCustomEditorPane(pane.getTitle(), pane); + } + } + + private void insertShortCut(int index, BasicBeanPane pane) { + int size = extraPaneList.size(); + index = Math.min(index, size); + extraPaneList.add(index, pane); + } + + private void initPluginListener() { + GeneralContext.listenPluginRunningChanged(new PluginEventListener() { + @Override + public void on(PluginEvent event) { + refreshExtraAdvancedPane(); + } + }, pluginContext -> pluginContext.getRuntime().contain(TemplateThemePaneProvider.XML_TAG)); + } + protected JPanel createCellStyleSettingPane() { JPanel container = FRGUIPaneFactory.createBorderLayout_S_Pane(); cellStyleSettingPane = new CellStyleListEditPane(); @@ -223,6 +257,9 @@ public abstract class TemplateThemeEditorPane extends J colorListPane.populate(theme.getColorScheme().getColors()); populateBean4CustomEditors(theme); + for (BasicBeanPane pane : extraPaneList) { + pane.populateBean(theme); + } isPopulating = false; } @@ -243,7 +280,9 @@ public abstract class TemplateThemeEditorPane extends J theme.setColorScheme(colorScheme); updateBean4CustomEditors(theme); - + for (BasicBeanPane pane : extraPaneList) { + pane.updateBean(theme); + } return theme; } diff --git a/designer-base/src/main/java/com/fr/design/mainframe/theme/edit/chart/ChartFontPane.java b/designer-base/src/main/java/com/fr/design/mainframe/theme/edit/chart/ChartFontPane.java index 2b19b232e3..a70870a61b 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/theme/edit/chart/ChartFontPane.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/theme/edit/chart/ChartFontPane.java @@ -13,6 +13,7 @@ import com.fr.design.gui.ilable.UILabel; import com.fr.design.i18n.Toolkit; import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayoutHelper; +import com.fr.design.utils.DesignUtils; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.general.FRFont; import com.fr.general.GeneralUtils; @@ -52,7 +53,7 @@ public class ChartFontPane extends BasicPane { } private void initState() { - fontNameComboBox = new UIComboBox(Utils.getAvailableFontFamilyNames4Report()); + fontNameComboBox = new UIComboBox(DesignUtils.getAvailableFontFamilyNames4Report()); fontSizeComboBox = new UIComboBox(FONT_SIZES); bold = new UIToggleButton(BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/bold.png")); italic = new UIToggleButton(BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/italic.png")); diff --git a/designer-base/src/main/java/com/fr/design/mainframe/theme/processor/AbstractThemePreviewPaneProcessor.java b/designer-base/src/main/java/com/fr/design/mainframe/theme/processor/AbstractThemePreviewPaneProcessor.java new file mode 100644 index 0000000000..839944d9fe --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/mainframe/theme/processor/AbstractThemePreviewPaneProcessor.java @@ -0,0 +1,23 @@ +package com.fr.design.mainframe.theme.processor; + +import com.fr.stable.fun.mark.API; + +/** + * @author Bruce.Deng + * @version 11.0 + * Created by Bruce.Deng on 2023/2/14 + */ +@API(level = ThemePreviewPaneProcessor.CURRENT_LEVEL) +public abstract class AbstractThemePreviewPaneProcessor implements ThemePreviewPaneProcessor { + + @Override + public int currentAPILevel() { + return CURRENT_LEVEL; + } + + @Override + public int layerIndex() { + return DEFAULT_LAYER_INDEX; + } + +} diff --git a/designer-base/src/main/java/com/fr/design/mainframe/theme/processor/ThemePreviewPaneProcessor.java b/designer-base/src/main/java/com/fr/design/mainframe/theme/processor/ThemePreviewPaneProcessor.java new file mode 100644 index 0000000000..93b17b8e92 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/mainframe/theme/processor/ThemePreviewPaneProcessor.java @@ -0,0 +1,35 @@ +package com.fr.design.mainframe.theme.processor; + +import com.fr.base.theme.FormTheme; +import com.fr.base.theme.ReportTheme; +import com.fr.design.mainframe.theme.TemplateThemePreviewPane; +import com.fr.stable.fun.mark.Immutable; + +/** + * 主题样式预览界面接口 + * + * @author Bruce.Deng + * @version 11.0 + * Created by Bruce.Deng on 2023/2/14 + */ +public interface ThemePreviewPaneProcessor extends Immutable { + + String XML_TAG = "ThemePreviewPaneProcessor"; + + int CURRENT_LEVEL = 1; + + /** + * 创建报表主题样式预览界面 + * + * @return 报表主题样式预览界面 + */ + TemplateThemePreviewPane createReportThemePreviewPane(); + + /** + * 创建决策报表主题样式预览界面 + * + * @return 决策报表主题样式预览界面 + */ + TemplateThemePreviewPane createFormThemePreviewPane(); + +} diff --git a/designer-base/src/main/java/com/fr/design/mainframe/theme/utils/DefaultThemedTemplateCellElementCase.java b/designer-base/src/main/java/com/fr/design/mainframe/theme/utils/DefaultThemedTemplateCellElementCase.java index 8b1abe71b4..0923c7f659 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/theme/utils/DefaultThemedTemplateCellElementCase.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/theme/utils/DefaultThemedTemplateCellElementCase.java @@ -5,7 +5,9 @@ import com.fr.base.theme.TemplateTheme; import com.fr.base.theme.settings.ThemedCellStyle; import com.fr.design.base.mode.DesignModeContext; import com.fr.design.file.HistoryTemplateListCache; +import com.fr.design.fun.DefaultValueAdjustProvider; import com.fr.design.mainframe.JTemplate; +import com.fr.design.utils.DesignUtils; import com.fr.report.cell.DefaultTemplateCellElement; /** @@ -41,6 +43,10 @@ public class DefaultThemedTemplateCellElementCase { cellElement.setStyle(DesignModeContext.isDuchampMode() ? nameStyle.getRealStyle() : nameStyle); } } + DefaultValueAdjustProvider adjustProvider = DesignUtils.getValueAdjust(); + if (adjustProvider != null) { + adjustProvider.adjustCellElement(cellElement); + } return cellElement; } } diff --git a/designer-base/src/main/java/com/fr/design/mainframe/toolbar/ToolBarMenuDock.java b/designer-base/src/main/java/com/fr/design/mainframe/toolbar/ToolBarMenuDock.java index 6a83a159b8..3c75eff39d 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/toolbar/ToolBarMenuDock.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/toolbar/ToolBarMenuDock.java @@ -56,6 +56,7 @@ import com.fr.design.gui.itoolbar.UIToolbar; import com.fr.design.locale.impl.SupportLocaleImpl; import com.fr.design.mainframe.JTemplate; import com.fr.design.mainframe.ToolBarNewTemplatePane; +import com.fr.design.mainframe.platform.ServicePlatformAction; import com.fr.design.menu.MenuDef; import com.fr.design.menu.SeparatorDef; import com.fr.design.menu.ShortCut; @@ -571,22 +572,21 @@ public abstract class ToolBarMenuDock { if (AlphaFineConfigManager.isALPHALicAvailable()) { shortCuts.add(new AlphaFineAction()); } - + shortCuts.add(new EnvDetectorAction()); - + //服务平台(仅针对中国大陆) + if (GeneralContext.getLocale().equals(Locale.CHINA)) { + shortCuts.add(new ServicePlatformAction()); + } + + shortCuts.add(SeparatorDef.DEFAULT); if (DesignerEnvManager.getEnvManager().isOpenDebug()) { OSSupportCenter.buildAction(objects -> shortCuts.add(new FineUIAction()), SupportOSImpl.FINEUI); } shortCuts.add(new AboutAction()); - try { - if (DesignModuleFactory.getITReplaceAction() != null) { - shortCuts.add((ShortCut) DesignModuleFactory.getITReplaceAction().newInstance()); - } - } catch (Exception e) { - FineLoggerFactory.getLogger().error(e.getMessage(), e); - } + return shortCuts.toArray(new ShortCut[0]); } diff --git a/designer-base/src/main/java/com/fr/design/mainframe/vcs/ui/FileVersionCellEditor.java b/designer-base/src/main/java/com/fr/design/mainframe/vcs/ui/FileVersionCellEditor.java index bf5b8ba45b..8cff3ffbb1 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/vcs/ui/FileVersionCellEditor.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/vcs/ui/FileVersionCellEditor.java @@ -1,7 +1,7 @@ package com.fr.design.mainframe.vcs.ui; import com.fr.design.file.HistoryTemplateListCache; -import com.fr.design.file.MutilTempalteTabPane; +import com.fr.design.file.MultiTemplateTabPane; import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.DesignerFrameFileDealerPane; import com.fr.design.mainframe.JTemplate; @@ -57,9 +57,9 @@ public class FileVersionCellEditor extends AbstractCellEditor implements TableCe jt.stopEditing(); //只有模板路径一致时关闭当前模板 if (ComparatorUtils.equals(fileOfVersion, jt.getPath())) { - MutilTempalteTabPane.getInstance().setIsCloseCurrent(true); - MutilTempalteTabPane.getInstance().closeFormat(jt); - MutilTempalteTabPane.getInstance().closeSpecifiedTemplate(jt); + MultiTemplateTabPane.getInstance().setIsCloseCurrent(true); + MultiTemplateTabPane.getInstance().closeFormat(jt); + MultiTemplateTabPane.getInstance().closeSpecifiedTemplate(jt); } //再打开cache中的模板 diff --git a/designer-base/src/main/java/com/fr/design/mainframe/vcs/ui/FileVersionsPanel.java b/designer-base/src/main/java/com/fr/design/mainframe/vcs/ui/FileVersionsPanel.java index 4d9b6e35e6..4dd14bce6d 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/vcs/ui/FileVersionsPanel.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/vcs/ui/FileVersionsPanel.java @@ -5,7 +5,7 @@ import com.fr.design.base.mode.DesignModeContext; import com.fr.design.base.mode.DesignerMode; import com.fr.design.dialog.BasicPane; import com.fr.design.file.HistoryTemplateListCache; -import com.fr.design.file.MutilTempalteTabPane; +import com.fr.design.file.MultiTemplateTabPane; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.icontainer.UIScrollPane; import com.fr.design.gui.ilable.UILabel; @@ -115,9 +115,9 @@ public class FileVersionsPanel extends BasicPane { // 关闭当前打开的版本 JTemplate jt = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); - MutilTempalteTabPane.getInstance().setIsCloseCurrent(true); - MutilTempalteTabPane.getInstance().closeFormat(jt); - MutilTempalteTabPane.getInstance().closeSpecifiedTemplate(jt); + MultiTemplateTabPane.getInstance().setIsCloseCurrent(true); + MultiTemplateTabPane.getInstance().closeFormat(jt); + MultiTemplateTabPane.getInstance().closeSpecifiedTemplate(jt); updateDesignerFrame(true); diff --git a/designer-base/src/main/java/com/fr/design/mainframe/widget/MobileTabFontConfPane.java b/designer-base/src/main/java/com/fr/design/mainframe/widget/MobileTabFontConfPane.java index b4d678f985..8f10d21020 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/widget/MobileTabFontConfPane.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/widget/MobileTabFontConfPane.java @@ -5,6 +5,7 @@ import com.fr.base.Utils; import com.fr.design.gui.ibutton.UIColorButton; import com.fr.design.gui.ibutton.UIToggleButton; import com.fr.design.gui.icombobox.UIComboBox; +import com.fr.design.utils.DesignUtils; import com.fr.general.FRFont; import javax.swing.Icon; @@ -38,7 +39,7 @@ public class MobileTabFontConfPane extends JPanel { private void init() { this.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 0)); - fontFamily = new UIComboBox(Utils.getAvailableFontFamilyNames4Report()); + fontFamily = new UIComboBox(DesignUtils.getAvailableFontFamilyNames4Report()); Vector integerList = new Vector(); for (int i = 1; i < 100; i++) { integerList.add(i); diff --git a/designer-base/src/main/java/com/fr/design/module/DesignModuleFactory.java b/designer-base/src/main/java/com/fr/design/module/DesignModuleFactory.java index baed29be47..cccd6f71e6 100644 --- a/designer-base/src/main/java/com/fr/design/module/DesignModuleFactory.java +++ b/designer-base/src/main/java/com/fr/design/module/DesignModuleFactory.java @@ -1,6 +1,7 @@ package com.fr.design.module; import com.fr.base.chart.BaseChartCollection; +import com.fr.design.actions.help.replace.ITReplaceOperator; import com.fr.design.gui.chart.BaseChartPropertyPane; import com.fr.design.gui.chart.MiddleChartComponent; import com.fr.design.gui.chart.MiddleChartDialog; @@ -18,6 +19,7 @@ import com.fr.log.FineLoggerFactory; import com.fr.plugin.solution.sandbox.collection.PluginSandboxCollections; import com.fr.stable.StableUtils; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.lang.reflect.Constructor; import java.awt.Dialog; @@ -50,6 +52,7 @@ public class DesignModuleFactory { private Class ITReplaceAction; private Class formParaDesigner; private Class paraPropertyPane; + private static ITReplaceOperator replaceHelper; private Class formHierarchyPaneCls; private Class widgetPropertyPane; private Class buttonDetailPaneClass; @@ -127,8 +130,37 @@ public class DesignModuleFactory { instance.ITReplaceAction = r; } - public static Class getITReplaceAction() { - return instance.ITReplaceAction; + /** + * 获取查找替换 + * + * @return ITReplaceAction + */ + @Nullable + public static Object getITReplaceAction() { + try { + if (instance.ITReplaceAction != null) { + return instance.ITReplaceAction.newInstance(); + } + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + } + return null; + } + + /** + * 注册一下查找替换面板 + * @param + */ + public static void registerReplace(ITReplaceOperator replace) { + replaceHelper = replace; + } + + /** + * 获取查找替换面板的操作类 + * @return + */ + public static ITReplaceOperator getReplaceOperator() { + return replaceHelper; } public static void registerParaPropertyPaneClass(Class p) { diff --git a/designer-base/src/main/java/com/fr/design/os/impl/SupportOSImpl.java b/designer-base/src/main/java/com/fr/design/os/impl/SupportOSImpl.java index 5751c3ecb9..d8eda915b7 100644 --- a/designer-base/src/main/java/com/fr/design/os/impl/SupportOSImpl.java +++ b/designer-base/src/main/java/com/fr/design/os/impl/SupportOSImpl.java @@ -152,7 +152,13 @@ public enum SupportOSImpl implements SupportOS { @Override public boolean support() { - return (OperatingSystem.isLinux() && Arch.getArch() == Arch.ARM) || MACOS_12_VERSION_ADAPTER.support(); + boolean javafxExist = true; + try { + Class.forName("javafx.stage.FileChooser"); + } catch (ClassNotFoundException e) { + javafxExist = false; + } + return !javafxExist || (OperatingSystem.isLinux() && Arch.getArch() == Arch.ARM) || MACOS_12_VERSION_ADAPTER.support(); } }, diff --git a/designer-base/src/main/java/com/fr/design/record/analyzer/DesignerAnalyzerActivator.java b/designer-base/src/main/java/com/fr/design/record/analyzer/DesignerAnalyzerActivator.java index 8a23e6fe0e..087a656ba6 100644 --- a/designer-base/src/main/java/com/fr/design/record/analyzer/DesignerAnalyzerActivator.java +++ b/designer-base/src/main/java/com/fr/design/record/analyzer/DesignerAnalyzerActivator.java @@ -18,6 +18,7 @@ import com.fr.event.Null; import com.fr.intelli.metrics.Compute; import com.fr.intelli.record.Focus; import com.fr.intelli.record.PerformancePoint; +import com.fr.jvm.assist.FineAssist; import com.fr.module.Activator; import com.fr.module.extension.Prepare; import com.fr.record.analyzer.AnalyzerConfiguration; @@ -57,7 +58,7 @@ public class DesignerAnalyzerActivator extends Activator implements Prepare { List backwardsConfigurations = findMutableBackwards(AnalyzerKey.KEY); if (!CollectionUtils.isEmpty(backwardsConfigurations)) { // 直接初始化,不添加默认值,防止和下面的冲突 - FineAnalyzer.initDirectly(basicFactory, backwardsConfigurations.toArray(new AnalyzerConfiguration[0])); + FineAnalyzer.initDirectly(FineAssist.findInstrumentation(), basicFactory, backwardsConfigurations.toArray(new AnalyzerConfiguration[0])); } // 等页面完全打开后,再进行 retransform, 别影响了启动速度 diff --git a/designer-base/src/main/java/com/fr/design/record/analyzer/advice/MonitorAdvice.java b/designer-base/src/main/java/com/fr/design/record/analyzer/advice/MonitorAdvice.java index b70bf44f97..a4ddfcd4e8 100644 --- a/designer-base/src/main/java/com/fr/design/record/analyzer/advice/MonitorAdvice.java +++ b/designer-base/src/main/java/com/fr/design/record/analyzer/advice/MonitorAdvice.java @@ -11,6 +11,7 @@ import com.fr.intelli.record.Measurable; import com.fr.intelli.record.MeasureObject; import com.fr.intelli.record.MeasureUnit; import com.fr.log.FineLoggerFactory; +import com.fr.log.message.AbstractMessage; import com.fr.measure.DBMeterFactory; import com.fr.stable.StringUtils; import com.fr.third.net.bytebuddy.asm.Advice; @@ -75,7 +76,7 @@ public class MonitorAdvice implements DesignerAnalyzerAdvice { List newArgs = new ArrayList<>(Arrays.asList(args)); newArgs.add(id); recordSQLDetail(id); - Object message = null; + AbstractMessage message = null; try { message = measurable.durableEntity(measureObject, newArgs.toArray()); } catch (Throwable throwable) { diff --git a/designer-base/src/main/java/com/fr/design/remote/button/IconButton.java b/designer-base/src/main/java/com/fr/design/remote/button/IconButton.java index 598ec7f057..d2d04b8d4c 100644 --- a/designer-base/src/main/java/com/fr/design/remote/button/IconButton.java +++ b/designer-base/src/main/java/com/fr/design/remote/button/IconButton.java @@ -4,6 +4,7 @@ import com.fr.base.BaseUtils; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.stable.StringUtils; +import javax.swing.Icon; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; @@ -15,14 +16,19 @@ import java.awt.Graphics2D; import java.awt.Point; public final class IconButton extends JButton { - public IconButton() { + + public IconButton(Icon icon) { super(StringUtils.EMPTY); setContentAreaFilled(false); setFocusPainted(false); - setIcon(BaseUtils.readIcon("com/fr/design/remote/images/icon_tab_close_normal.png")); + setIcon(icon); setBorder(null); } + public IconButton() { + this(BaseUtils.readIcon("com/fr/design/remote/images/icon_tab_close_normal.png")); + } + @Override protected void paintBorder(Graphics g) { } diff --git a/designer-realize/src/main/java/com/fr/design/report/SelectImagePane.java b/designer-base/src/main/java/com/fr/design/report/SelectImagePane.java similarity index 96% rename from designer-realize/src/main/java/com/fr/design/report/SelectImagePane.java rename to designer-base/src/main/java/com/fr/design/report/SelectImagePane.java index bcad15c76c..7781233aac 100644 --- a/designer-realize/src/main/java/com/fr/design/report/SelectImagePane.java +++ b/designer-base/src/main/java/com/fr/design/report/SelectImagePane.java @@ -13,22 +13,24 @@ import com.fr.report.cell.Elem; import com.fr.report.cell.cellattr.CellImage; import com.fr.report.cell.painter.CellImagePainter; import com.fr.stable.Constants; - -import javax.swing.BorderFactory; -import javax.swing.ButtonGroup; -import javax.swing.JFileChooser; -import javax.swing.JPanel; -import javax.swing.JScrollPane; import java.awt.BorderLayout; import java.awt.GridLayout; import java.awt.Image; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; +import javax.swing.BorderFactory; +import javax.swing.ButtonGroup; +import javax.swing.JFileChooser; +import javax.swing.JPanel; +import javax.swing.JScrollPane; /** - * 这个类主要用于插入图片时的设置 - */ + *

这个类主要用于插入图片时的设置

+ *

这个类原本在designer-realize包下面,现在表单也可选择图片,所以应该抽为公用的base包。包名不变,应该不影响插件使用

+ * + * @author Jimmy.Zheng created on 2022/8/11 21:22 + **/ public class SelectImagePane extends BasicPane { private ImagePreviewPane previewPane = null; @@ -39,8 +41,31 @@ public class SelectImagePane extends BasicPane { private UIRadioButton adjustRadioButton = null; private Style imageStyle = null; + ActionListener layoutActionListener = new ActionListener() { + @Override + public void actionPerformed(ActionEvent evt) { + setImageStyle(); + changeImageStyle(); + } + }; private File imageFile; + /** + * Select picture. + */ + ActionListener selectPictureActionListener = new ActionListener() { + + @Override + public void actionPerformed(ActionEvent evt) { + int returnVal = imageFileChooser + .showOpenDialog(SelectImagePane.this); + if (returnVal != JFileChooser.CANCEL_OPTION) { + File selectedFile = imageFileChooser.getSelectedFile(); + imageFile = selectedFile; + ImgChooseWrapper.getInstance(previewPane, imageFileChooser, imageStyle, null).dealWithImageFile(returnVal); + } + } + }; public SelectImagePane() { this.setLayout(FRGUIPaneFactory.createBorderLayout()); @@ -102,23 +127,6 @@ public class SelectImagePane extends BasicPane { imageFileChooser.setMultiSelectionEnabled(false); } - /** - * Select picture. - */ - ActionListener selectPictureActionListener = new ActionListener() { - - @Override - public void actionPerformed(ActionEvent evt) { - int returnVal = imageFileChooser - .showOpenDialog(SelectImagePane.this); - if (returnVal != JFileChooser.CANCEL_OPTION) { - File selectedFile = imageFileChooser.getSelectedFile(); - imageFile = selectedFile; - ImgChooseWrapper.getInstance(previewPane, imageFileChooser, imageStyle, null).dealWithImageFile(returnVal); - } - } - }; - // 调整图片样式,只有水平和垂直对齐以及拉伸。相对于背景,平铺不予考虑。 private void changeImageStyle() { previewPane.setImageStyle(this.imageStyle); @@ -137,15 +145,6 @@ public class SelectImagePane extends BasicPane { } } - ActionListener layoutActionListener = new ActionListener() { - - @Override - public void actionPerformed(ActionEvent evt) { - setImageStyle(); - changeImageStyle(); - } - }; - @Override protected String title4PopupWindow() { return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Image"); diff --git a/designer-base/src/main/java/com/fr/design/style/FontFamilyPane.java b/designer-base/src/main/java/com/fr/design/style/FontFamilyPane.java index 37076c66fb..ba496ae138 100644 --- a/designer-base/src/main/java/com/fr/design/style/FontFamilyPane.java +++ b/designer-base/src/main/java/com/fr/design/style/FontFamilyPane.java @@ -3,6 +3,7 @@ package com.fr.design.style; import com.fr.base.Utils; import com.fr.design.gui.itextfield.UITextField; import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.utils.DesignUtils; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.general.FRFont; @@ -26,7 +27,7 @@ public class FontFamilyPane extends JPanel { familyField = new UITextField(); familyField.setEditable(false); - familyList = new JList(Utils.getAvailableFontFamilyNames4Report()); + familyList = new JList(DesignUtils.getAvailableFontFamilyNames4Report()); familyList.setVisibleRowCount(4); familyList.addListSelectionListener(listener); diff --git a/designer-base/src/main/java/com/fr/design/style/color/ColorPicker.java b/designer-base/src/main/java/com/fr/design/style/color/ColorPicker.java index 2e5f56981d..067d82f9ce 100644 --- a/designer-base/src/main/java/com/fr/design/style/color/ColorPicker.java +++ b/designer-base/src/main/java/com/fr/design/style/color/ColorPicker.java @@ -67,16 +67,10 @@ public class ColorPicker extends JDialog implements ActionListener { hideCursor(); // 如果要求实时变化,确保先关闭弹窗,再截屏 - // 主要针对"图案"选项卡中的"前景"、"背景" if (this.setColorRealTime) { colorSelectable.setColor(Color.WHITE); // setColor 可以关闭弹窗 - try { - Thread.sleep(100); // 等待弹窗关闭 - } catch (InterruptedException e) { - FineLoggerFactory.getLogger().error(e.getMessage(), e); - Thread.currentThread().interrupt(); - } - colorPickerPanel.captureScreen(); + // REPORT-82110 确保关闭所有弹窗后截屏 + SwingUtilities.invokeLater(colorPickerPanel :: captureScreen); } } diff --git a/designer-base/src/main/java/com/fr/design/style/color/UIToolbarColorButton.java b/designer-base/src/main/java/com/fr/design/style/color/UIToolbarColorButton.java index 9a8640f627..8627f27a5f 100644 --- a/designer-base/src/main/java/com/fr/design/style/color/UIToolbarColorButton.java +++ b/designer-base/src/main/java/com/fr/design/style/color/UIToolbarColorButton.java @@ -153,12 +153,23 @@ public class UIToolbarColorButton extends UICombinationButton implements PopupHi popupWin = null; } + /** + * 取色器取色时隐藏弹出框,与另一个hide的区别是无需经过macOS的判断,以规避REPORT-25645的mac适配bug + */ + public void hidePopupMenu4PickColor() { + if (popupWin != null) { + popupWin.setVisible(false); + } + popupWin = null; + } + private ColorControlWindow getColorControlWindow() { //find parant. if (this.popupWin == null) { this.popupWin = new ColorControlWindow(this.isCanBeNull(), UIToolbarColorButton.this) { @Override protected void colorChanged() { + hidePopupMenu4PickColor(); UIToolbarColorButton.this.setColor(this.getColor()); } diff --git a/designer-base/src/main/java/com/fr/design/update/ui/dialog/UpdateMainDialog.java b/designer-base/src/main/java/com/fr/design/update/ui/dialog/UpdateMainDialog.java index 0dd70e03cd..033e2cb07f 100644 --- a/designer-base/src/main/java/com/fr/design/update/ui/dialog/UpdateMainDialog.java +++ b/designer-base/src/main/java/com/fr/design/update/ui/dialog/UpdateMainDialog.java @@ -118,6 +118,8 @@ public class UpdateMainDialog extends UIDialog { private ArrayList updateInfoList; + private Set titleSet; + private boolean getUpdateInfoSuccess; private UpdateInfoCachePropertyManager cacheProperty; @@ -267,6 +269,7 @@ public class UpdateMainDialog extends UIDialog { String keyword = searchUpdateInfoKeyword.getText(); if (ComparatorUtils.equals(keyword, StringUtils.EMPTY) && getUpdateInfoSuccess) { updateInfoList.clear(); + titleSet.clear(); getUpdateInfo(keyword).execute(); } } @@ -281,6 +284,7 @@ public class UpdateMainDialog extends UIDialog { public void actionPerformed(ActionEvent e) { if (getUpdateInfoSuccess) { updateInfoList.clear(); + titleSet.clear(); getUpdateInfo(searchUpdateInfoKeyword.getText()).execute(); } } @@ -388,6 +392,7 @@ public class UpdateMainDialog extends UIDialog { private SwingWorker getUpdateInfo(final String keyword) { updateInfoList = new ArrayList<>(); + titleSet = new HashSet<>(); lastUpdateCacheTime = UpdateConstants.CHANGELOG_X_START; String cacheConfigPath = getUpdateCacheConfig(); cacheProperty = new UpdateInfoCachePropertyManager(StableUtils.pathJoin(WorkContext.getCurrent().getPath(), "resources", "offlineres", cacheConfigPath)); @@ -488,7 +493,8 @@ public class UpdateMainDialog extends UIDialog { continue; } } - if (isValidLogInfo(updateInfo[UpdateInfoTable.UPDATE_TITLE_INDEX]) && curJarDate != null) { + if (isValid(updateInfo, GeneralUtils.objectToString(curJarDate))) { + titleSet.add(updateInfo[UpdateInfoTable.UPDATE_TITLE_INDEX]); updateInfoList.add(new Object[]{UPDATELOG_FORMAT.format(updateTime), updateInfo[UpdateInfoTable.UPDATE_VERSION_INDEX], updateInfo[UpdateInfoTable.UPDATE_TITLE_INDEX], updateTime.after(curJarDate)}); } } @@ -499,6 +505,11 @@ public class UpdateMainDialog extends UIDialog { } } + + private boolean isValid(String[] updateInfo, String curJarDate) { + return isValidLogInfo(updateInfo[UpdateInfoTable.UPDATE_TITLE_INDEX]) && curJarDate != null && curJarDate.compareTo(updateInfo[UpdateInfoTable.UPDATE_DATE_INDEX]) <= 0 && !titleSet.contains(updateInfo[UpdateInfoTable.UPDATE_TITLE_INDEX]); + } + private void updateCachedInfoFile(JSONArray jsonArray) throws Exception { String cacheDirPath = StableUtils.pathJoin(WorkContext.getCurrent().getPath(), "resources", "offlineres"); File cacheFileDir = new File(cacheDirPath); @@ -554,13 +565,19 @@ public class UpdateMainDialog extends UIDialog { continue; } } - if (isValidLogInfo(updateTitle)) { + Date curDate = UPDATE_INFO_TABLE_FORMAT.parse(currentNO, new ParsePosition(currentNO.indexOf("-") + 1)); + if (isValid4GenerateInfo(updateTitle, GeneralUtils.objectToString(curDate), updateTimeStr)) { + titleSet.add(updateTitle); updateInfoList.add(new Object[]{updateTimeStr, updateVersionStr, updateTitle, updateTime.after(curJarDate)}); } } return new ArrayList<>(updateInfoList); } + private boolean isValid4GenerateInfo(String updateTitle, String curDate, String updateTimeStr) { + return isValidLogInfo(updateTitle) && curDate.compareTo(updateTimeStr) <= 0 && !titleSet.contains(updateTitle); + } + private boolean containsKeyword(String str, String keyword) { return str.toUpperCase().contains(keyword.toUpperCase()); } diff --git a/designer-base/src/main/java/com/fr/design/utils/DesignUtils.java b/designer-base/src/main/java/com/fr/design/utils/DesignUtils.java index 47690bba9b..4779f91916 100644 --- a/designer-base/src/main/java/com/fr/design/utils/DesignUtils.java +++ b/designer-base/src/main/java/com/fr/design/utils/DesignUtils.java @@ -2,11 +2,13 @@ package com.fr.design.utils; import com.fr.base.FeedBackInfo; import com.fr.base.ServerConfig; +import com.fr.base.Utils; import com.fr.concurrent.NamedThreadFactory; import com.fr.design.DesignerEnvManager; import com.fr.design.ExtraDesignClassManager; import com.fr.design.deeplink.DeepLinkCore; import com.fr.design.dialog.FineJOptionPane; +import com.fr.design.fun.DefaultValueAdjustProvider; import com.fr.design.fun.DesignerEnvProcessor; import com.fr.design.gui.UILookAndFeel; import com.fr.design.i18n.Toolkit; @@ -18,11 +20,14 @@ import com.fr.general.ComparatorUtils; import com.fr.general.FRFont; import com.fr.general.GeneralContext; import com.fr.log.FineLoggerFactory; +import com.fr.plugin.injectable.PluginModule; import com.fr.stable.ArrayUtils; import com.fr.stable.CommonCodeUtils; import com.fr.stable.StableUtils; import com.fr.stable.StringUtils; +import com.fr.stable.bridge.ObjectHolder; import com.fr.stable.os.OperatingSystem; +import com.fr.stable.plugin.ExtraDesignClassManagerProvider; import com.fr.start.ServerStarter; import com.fr.start.common.DesignerStartupContext; import com.fr.start.common.DesignerStartupUtil; @@ -48,6 +53,7 @@ import java.net.URI; import java.nio.charset.StandardCharsets; import java.util.Enumeration; import java.util.Locale; +import java.util.Set; import java.util.concurrent.Callable; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -463,4 +469,29 @@ public class DesignUtils { return xmlDesignerVersion; } + public static DefaultValueAdjustProvider getValueAdjust() { + ExtraDesignClassManager extraDesignClassManager = PluginModule.getAgent(PluginModule.ExtraDesign); + if (extraDesignClassManager != null) { + Set providers = extraDesignClassManager.getArray(DefaultValueAdjustProvider.MARK_STRING); + for (DefaultValueAdjustProvider provider : providers) { + if (provider.selector().accept(new ObjectHolder())) { + return provider; + } + } + } + return null; + } + + /** + * 获取设计器可用字体 + * @return + */ + public static String[] getAvailableFontFamilyNames4Report() { + DefaultValueAdjustProvider valueAdjust = DesignUtils.getValueAdjust(); + if (valueAdjust != null) { + return valueAdjust.getAvailableFontFamilyNames4Report(); + } + return Utils.getAvailableFontFamilyNames4Report(); + } + } diff --git a/designer-base/src/main/java/com/fr/design/utils/gui/GUICoreUtils.java b/designer-base/src/main/java/com/fr/design/utils/gui/GUICoreUtils.java index ac75786314..d90f2af422 100644 --- a/designer-base/src/main/java/com/fr/design/utils/gui/GUICoreUtils.java +++ b/designer-base/src/main/java/com/fr/design/utils/gui/GUICoreUtils.java @@ -17,6 +17,7 @@ import com.fr.design.actions.UpdateAction; import com.fr.design.actions.core.ActionFactory; import com.fr.design.border.UITitledBorder; import com.fr.design.dialog.FineJOptionPane; +import com.fr.design.fun.DefaultValueAdjustProvider; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ibutton.UIToggleButton; import com.fr.design.gui.icheckbox.UICheckBox; @@ -32,6 +33,7 @@ import com.fr.design.style.color.ColorCell; import com.fr.design.style.color.ColorFactory; import com.fr.design.style.color.ColorSelectBox; import com.fr.design.style.color.ColorSelectable; +import com.fr.design.utils.DesignUtils; import com.fr.general.FRFont; import com.fr.stable.AssistUtils; import com.fr.stable.Constants; @@ -171,6 +173,10 @@ public final class GUICoreUtils { FRFont frFont = style.getFRFont(); textField.setFont(new Font(frFont.getFontName(), frFont.getStyle(), frFont.getShowSize(resolution))); + DefaultValueAdjustProvider valueAdjust = DesignUtils.getValueAdjust(); + if (valueAdjust != null) { + textField.setFont(valueAdjust.transformFontByResolution(frFont, resolution)); + } textField.setForeground(style.getFRFont().getForeground()); if (style.getBackground() instanceof ColorBackground) { diff --git a/designer-base/src/main/java/com/fr/design/versioncheck/VersionCheckUtils.java b/designer-base/src/main/java/com/fr/design/versioncheck/VersionCheckUtils.java index 55dfe60cf1..a6a2d7896a 100644 --- a/designer-base/src/main/java/com/fr/design/versioncheck/VersionCheckUtils.java +++ b/designer-base/src/main/java/com/fr/design/versioncheck/VersionCheckUtils.java @@ -70,6 +70,7 @@ public class VersionCheckUtils { private static final String GROUP = "group"; private static final String BI = "bi"; private static final String BIPREFIX = "com.finebi"; + private static final String DEVELOP_BRANCH_MARK = "#"; private static final Set pluginsNeedIgnore = new HashSet<>(); static { pluginsNeedIgnore.addAll(Arrays.asList( @@ -88,7 +89,23 @@ public class VersionCheckUtils { public static boolean versionCheck(String envName) { - return checkLocalAndRemoteJartime(envName) && checkLocalAndRemotePlugin().size() == 0; + if (needCheckConsistency(envName)) { + return checkLocalAndRemoteJartime(envName) && checkLocalAndRemotePlugin().size() == 0; + } + return true; + } + + /** + * 判断是否需要检查Jartime和插件的一致性 + * + * @param selectedEnvName 当前工作目录名称 + * @return + */ + private static boolean needCheckConsistency(String selectedEnvName) { + DesignerEnvManager envManager = DesignerEnvManager.getEnvManager(); + DesignerWorkspaceInfo selectedEnv = envManager.getWorkspaceInfo(selectedEnvName); + // 当前工作目录为远程工作目录时,需要检查 + return selectedEnv.getType() == DesignerWorkspaceType.Remote; } public static boolean versionCheck(DesignerWorkspaceInfo selectedEnv) { @@ -139,21 +156,17 @@ public class VersionCheckUtils { } public static boolean checkLocalAndRemoteJartime(DesignerWorkspaceInfo selectedEnv) { - //是否需要做服务校验 - if (needCheckBranch(selectedEnv)) { - String localBranch; - String remoteBranch = getRemoteBranch(selectedEnv); - localBranch = GeneralUtils.readFullBuildNO(); - //通过是否包含#来避免当前版本为非安装版本(主要是内部开发版本) - if (localBranch.contains("#") && ComparatorUtils.equals(localBranch, remoteBranch)) { - //说明版本一致,仅做日志记录 - FineLoggerFactory.getLogger().info("Remote Designer version consistency"); - return true; - } else { - return false; - } + String localBranch; + String remoteBranch = getRemoteBranch(selectedEnv); + localBranch = GeneralUtils.readFullBuildNO(); + // 通过是否包含"#"来避免当前版本为非安装版本(主要是内部开发版本) + if (localBranch.contains(DEVELOP_BRANCH_MARK) && ComparatorUtils.equals(localBranch, remoteBranch)) { + //说明版本一致,仅做日志记录 + FineLoggerFactory.getLogger().info("Remote Designer version consistency"); + return true; + } else { + return false; } - return true; } public static List getNoExistServiceDescription(String envName) { @@ -267,10 +280,6 @@ public class VersionCheckUtils { return df.format(jarDate); } - private static boolean needCheckBranch(DesignerWorkspaceInfo selectedEnv) { - return selectedEnv.getType() == DesignerWorkspaceType.Remote; - } - public static JSONArray checkLocalAndRemotePlugin() { JSONArray differentPlugins = new JSONArray(); JSONArray remotePlugins = FRContext.getCommonOperator().getPluginStatus(); diff --git a/designer-base/src/main/java/com/fr/design/worker/open/OpenWorker.java b/designer-base/src/main/java/com/fr/design/worker/open/OpenWorker.java index b070b7f078..d9c8568bf9 100644 --- a/designer-base/src/main/java/com/fr/design/worker/open/OpenWorker.java +++ b/designer-base/src/main/java/com/fr/design/worker/open/OpenWorker.java @@ -3,7 +3,7 @@ package com.fr.design.worker.open; import com.fr.base.chart.exception.ChartNotFoundException; import com.fr.design.dialog.FineJOptionPane; import com.fr.design.file.HistoryTemplateListCache; -import com.fr.design.file.MutilTempalteTabPane; +import com.fr.design.file.MultiTemplateTabPane; import com.fr.design.file.TemplateTreePane; import com.fr.design.i18n.Toolkit; import com.fr.design.lock.LockInfoDialog; @@ -87,7 +87,7 @@ public class OpenWorker extends SwingWorker { UIManager.getIcon("OptionPane.errorIcon")); } if (cause.getCause() instanceof TplLockedException) { - MutilTempalteTabPane.getInstance().closeCurrentTpl(); + MultiTemplateTabPane.getInstance().closeCurrentTpl(); TemplateTreePane.getInstance().getFileNode().setLock(UUID.randomUUID().toString()); LockInfoDialog.show(null); } diff --git a/designer-base/src/main/java/com/fr/env/RemoteWorkspaceURL.java b/designer-base/src/main/java/com/fr/env/RemoteWorkspaceURL.java index 4ea950e845..1dcd2220f6 100644 --- a/designer-base/src/main/java/com/fr/env/RemoteWorkspaceURL.java +++ b/designer-base/src/main/java/com/fr/env/RemoteWorkspaceURL.java @@ -1,13 +1,20 @@ package com.fr.env; +import com.fr.log.FineLoggerFactory; import com.fr.stable.AssistUtils; import com.fr.stable.FCloneable; import com.fr.stable.StringUtils; +import java.net.URI; +import java.net.URISyntaxException; +import com.fr.third.guava.base.Strings; /** * @author yaohwu */ public class RemoteWorkspaceURL implements FCloneable { + private static final String IPV6_JUDGE_SYMBOL = "["; + + private static final String IPV6_JUDGE_SYMBOL2 = "]"; public static final String SYSTEM_LOGIN_PATH = "#management/system/login"; @@ -98,6 +105,8 @@ public class RemoteWorkspaceURL implements FCloneable { parserWebAndServlet(lefts); } } + //判断一下IPV6 + this.refreshIPV6Format(); } public boolean hasDefaultHostName() { @@ -129,6 +138,27 @@ public class RemoteWorkspaceURL implements FCloneable { return this.url; } + /** + * IPV6地址格式不同,处理字符串的方式不同,需要处理的是port和host + * 形如 http://[XXXX::XXXX:XXXX:XXXX:XXXX]:8080/webroot/decision + */ + public void refreshIPV6Format() { + String url = this.url; + if (Strings.isNullOrEmpty(url)) { + return; + } + if (!url.contains(IPV6_JUDGE_SYMBOL) || !url.contains(IPV6_JUDGE_SYMBOL2)) { + return; + } + URI uri = null; + try { + uri = new URI(url); + this.host = uri.getHost(); + this.port = String.valueOf(uri.getPort()); + } catch (URISyntaxException ignored) { + + } + } public void setHttps(boolean https) { isHttps = https; diff --git a/designer-base/src/main/java/com/fr/env/detect/impl/converter/ClassConflictConvertor.java b/designer-base/src/main/java/com/fr/env/detect/impl/converter/ClassConflictConvertor.java index 57c97326e5..6cd92e4039 100644 --- a/designer-base/src/main/java/com/fr/env/detect/impl/converter/ClassConflictConvertor.java +++ b/designer-base/src/main/java/com/fr/env/detect/impl/converter/ClassConflictConvertor.java @@ -48,6 +48,7 @@ public class ClassConflictConvertor implements ThrowableConverter { private static final String JAR_URL_SUFFIX = ".jar!"; private static final String JAR_FILE_SUFFIX = ".jar"; private static final String FILE_URL_PREFIX = "file:"; + private static final String PLUGINS_DIR_NAME = "plugins"; private final Map, ClassNameConverter> throwableMap = new HashMap<>(); @@ -108,6 +109,9 @@ public class ClassConflictConvertor implements ThrowableConverter { for (URL url : urlList) { String file = url.getFile(); String decodeFileStr = URLDecoder.decode(file, EncodeConstants.ENCODING_UTF_8); + if (decodeFileStr.contains(PLUGINS_DIR_NAME)) { + continue; + } if (decodeFileStr.contains(JAR_URL_SUFFIX)) { String jarPath = decodeFileStr.substring(FILE_URL_PREFIX.length(), decodeFileStr.indexOf(JAR_URL_SUFFIX) + JAR_FILE_SUFFIX.length()); String jar = new File(jarPath).getName(); diff --git a/designer-base/src/main/java/com/fr/nx/app/designer/toolbar/TemplateTransformer.java b/designer-base/src/main/java/com/fr/nx/app/designer/toolbar/TemplateTransformer.java index 42490fe7d5..1a6e2bf1c8 100644 --- a/designer-base/src/main/java/com/fr/nx/app/designer/toolbar/TemplateTransformer.java +++ b/designer-base/src/main/java/com/fr/nx/app/designer/toolbar/TemplateTransformer.java @@ -2,7 +2,7 @@ package com.fr.nx.app.designer.toolbar; import com.fr.base.extension.FileExtension; import com.fr.design.file.HistoryTemplateListCache; -import com.fr.design.file.MutilTempalteTabPane; +import com.fr.design.file.MultiTemplateTabPane; import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.JTemplate; import com.fr.file.FILE; @@ -103,9 +103,9 @@ public enum TemplateTransformer { DesignerContext.getDesignerFrame().openTemplate(file); return; } - MutilTempalteTabPane.getInstance().setIsCloseCurrent(true); - MutilTempalteTabPane.getInstance().closeFormat(jt); - MutilTempalteTabPane.getInstance().closeSpecifiedTemplate(jt); + MultiTemplateTabPane.getInstance().setIsCloseCurrent(true); + MultiTemplateTabPane.getInstance().closeFormat(jt); + MultiTemplateTabPane.getInstance().closeSpecifiedTemplate(jt); DesignerContext.getDesignerFrame().openTemplate(file); } diff --git a/designer-base/src/main/java/com/fr/start/BaseDesigner.java b/designer-base/src/main/java/com/fr/start/BaseDesigner.java index 016c6bd6d1..44228c2a4a 100644 --- a/designer-base/src/main/java/com/fr/start/BaseDesigner.java +++ b/designer-base/src/main/java/com/fr/start/BaseDesigner.java @@ -8,7 +8,7 @@ import com.fr.design.DesignerEnvManager; import com.fr.design.ExtraDesignClassManager; import com.fr.design.constants.DesignerLaunchStatus; import com.fr.design.file.HistoryTemplateListPane; -import com.fr.design.file.MutilTempalteTabPane; +import com.fr.design.file.MultiTemplateTabPane; import com.fr.design.file.TemplateTreePane; import com.fr.design.fun.DesignerStartOpenFileProcessor; import com.fr.design.fun.impl.DesignerStartWithEmptyFile; @@ -39,6 +39,7 @@ import org.jetbrains.annotations.Nullable; import java.awt.Window; import java.lang.reflect.Method; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; /** @@ -136,7 +137,7 @@ public abstract class BaseDesigner extends ToolBarMenuDock { DesignerFrame df = DesignerContext.getDesignerFrame(); isException = openFile(df, isException, file); df.fireDesignerOpened(); - FineLoggerFactory.getLogger().debug("show designer cost {} ms", DesignerStartupContext.getRecorder().getTime()); + FineLoggerFactory.getLogger().info("Designer showed.Time used {} ms", DesignerStartupContext.getRecorder().getTime(TimeUnit.MILLISECONDS)); } catch (Exception e) { FineLoggerFactory.getLogger().error(e.getMessage(), e); if (!isException) { @@ -192,7 +193,7 @@ public abstract class BaseDesigner extends ToolBarMenuDock { } else { df.addAndActivateJTemplate(); // 如果没有模板,则需要确认一下 - MutilTempalteTabPane.getInstance().setTemTemplate(HistoryTemplateListPane.getInstance().getCurrentEditingTemplate()); + MultiTemplateTabPane.getInstance().setTemTemplate(HistoryTemplateListPane.getInstance().getCurrentEditingTemplate()); } } @@ -252,7 +253,7 @@ public abstract class BaseDesigner extends ToolBarMenuDock { private boolean createNewTemplate(DesignerFrame df) { df.addAndActivateJTemplate(); // 如果没有模板,则需要确认一下 - MutilTempalteTabPane.getInstance().setTemTemplate(HistoryTemplateListPane.getInstance().getCurrentEditingTemplate()); + MultiTemplateTabPane.getInstance().setTemTemplate(HistoryTemplateListPane.getInstance().getCurrentEditingTemplate()); return true; } diff --git a/designer-base/src/main/java/com/fr/start/common/DesignerOpenEmptyPanel.java b/designer-base/src/main/java/com/fr/start/common/DesignerOpenEmptyPanel.java index 7f4a0eeb97..b42cc4ed8f 100644 --- a/designer-base/src/main/java/com/fr/start/common/DesignerOpenEmptyPanel.java +++ b/designer-base/src/main/java/com/fr/start/common/DesignerOpenEmptyPanel.java @@ -3,7 +3,7 @@ package com.fr.start.common; import com.fr.base.svg.IconUtils; import com.fr.design.file.HistoryTemplateListCache; import com.fr.design.file.HistoryTemplateListPane; -import com.fr.design.file.MutilTempalteTabPane; +import com.fr.design.file.MultiTemplateTabPane; import com.fr.design.gui.ilable.UILabel; import com.fr.design.i18n.DesignSizeI18nManager; import com.fr.design.i18n.Toolkit; @@ -59,7 +59,7 @@ public class DesignerOpenEmptyPanel extends JPanel { HistoryTemplateListCache.getInstance().setCurrentEditingTemplate(null); df.addAndActivateJTemplate(); // 如果没有模板,则需要确认一下 - MutilTempalteTabPane.getInstance().setTemTemplate(HistoryTemplateListPane.getInstance().getCurrentEditingTemplate()); + MultiTemplateTabPane.getInstance().setTemTemplate(HistoryTemplateListPane.getInstance().getCurrentEditingTemplate()); } }); createButton.setBorder(new EmptyBorder(0, 10, 0, 10)); diff --git a/designer-base/src/main/java/com/fr/start/common/DesignerStartupPool.java b/designer-base/src/main/java/com/fr/start/common/DesignerStartupPool.java index 524c474df1..6625a5a31b 100644 --- a/designer-base/src/main/java/com/fr/start/common/DesignerStartupPool.java +++ b/designer-base/src/main/java/com/fr/start/common/DesignerStartupPool.java @@ -4,17 +4,36 @@ import com.fr.concurrent.FineExecutors; import com.fr.concurrent.NamedThreadFactory; import java.util.concurrent.Executor; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.TimeUnit; /** * created by Harrison on 2022/07/03 **/ public class DesignerStartupPool { - private static final Executor COMMON_EXECUTOR = FineExecutors.newCachedThreadPool(new NamedThreadFactory("startup-common")); + private static final int MAX_THREAD_COUNT = Runtime.getRuntime().availableProcessors() * 2; + private static final Executor COMMON_EXECUTOR = FineExecutors.newThreadPoolExecutor(MAX_THREAD_COUNT, MAX_THREAD_COUNT, 10L, TimeUnit.SECONDS, new LinkedBlockingQueue<>(), new NamedThreadFactory("startup-common")); + + private static final Executor DESIGNER_EXECUTOR = FineExecutors.newThreadPoolExecutor(MAX_THREAD_COUNT, MAX_THREAD_COUNT, 10L, TimeUnit.SECONDS, new LinkedBlockingQueue<>(), new NamedThreadFactory("startup-designer")); + + /** + * + * @return 启动通用线程池 + */ public static Executor common() { return COMMON_EXECUTOR; } + + /** + * + * @return 启动设计器线程池 + */ + public static Executor designer() { + + return DESIGNER_EXECUTOR; + } } diff --git a/designer-base/src/main/java/com/fr/startup/ui/StartupLoadingPanel.java b/designer-base/src/main/java/com/fr/startup/ui/StartupLoadingPanel.java new file mode 100644 index 0000000000..59f86fc467 --- /dev/null +++ b/designer-base/src/main/java/com/fr/startup/ui/StartupLoadingPanel.java @@ -0,0 +1,118 @@ +package com.fr.startup.ui; + +import com.fr.concurrent.FineExecutors; +import com.fr.concurrent.NamedThreadFactory; +import com.fr.design.gui.iprogressbar.ProgressDialog; +import com.fr.design.i18n.Toolkit; +import com.fr.design.ui.util.UIUtil; +import com.fr.event.Event; +import com.fr.event.EventDispatcher; +import com.fr.event.Listener; +import com.fr.module.ModuleEvent; + +import java.awt.Frame; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + +/** + * 启动加载面板 + * + * @author Harrison + * @version 11.0 + * created by Harrison on 2022/11/08 + **/ +public class StartupLoadingPanel { + + /** + * 每次更新的步伐 + */ + private static final int STEP = 1; + + /** + * 40ms更新进度 + */ + private static final int STEP_HEARTBEAT = 40; + + private final Listener MODULE_LISTENER = new Listener() { + @Override + public void on(Event event, String param) { + moduleId = param; + } + }; + + private ProgressDialog progressDialog; + private String moduleId; + private int progress; + + public StartupLoadingPanel(Frame frame) { + this.progressDialog = new ProgressDialog(frame); + this.moduleId = Toolkit.i18nText("Fine-Design_Basic_Initializing"); + + initListeners(); + } + + /** + * 隐藏 + */ + public void hide() { + this.progress = progressDialog.getProgressMaximum(); + } + + /** + * 展示 + */ + public void show() { + + final ScheduledExecutorService scheduler = FineExecutors.newScheduledThreadPool(1, + new NamedThreadFactory("StartupLoadingPanel")); + scheduler.scheduleAtFixedRate(new Runnable() { + @Override + public void run() { + UIUtil.invokeAndWaitIfNeeded(() -> { + if (isComplete()) { + scheduler.shutdown(); + progressDialog.dispose(); + resetListeners(); + return; + } + if (!progressDialog.isVisible()) { + progressDialog.setVisible(true); + String moduleId = getModuleId(); + progressDialog.updateLoadingText(moduleId); + } + progressDialog.setProgressValue(incrementProgress()); + }); + } + }, 0, STEP_HEARTBEAT, TimeUnit.MILLISECONDS); + + } + + private void initListeners() { + + EventDispatcher.listen(ModuleEvent.MajorModuleStarting, MODULE_LISTENER); + } + + private void resetListeners() { + + EventDispatcher.stopListen(MODULE_LISTENER); + } + + private boolean isComplete() { + return this.progress >= progressDialog.getProgressMaximum(); + } + + private String getModuleId() { + + return this.moduleId; + } + + private int incrementProgress() { + + if (progress != progressDialog.getProgressMaximum()) { + progress += STEP; + } + return progress; + } + + +} diff --git a/designer-base/src/main/java/com/fr/startup/ui/StartupPageWindow.java b/designer-base/src/main/java/com/fr/startup/ui/StartupPageWindow.java index 0a0cdb4aac..41cd758905 100644 --- a/designer-base/src/main/java/com/fr/startup/ui/StartupPageWindow.java +++ b/designer-base/src/main/java/com/fr/startup/ui/StartupPageWindow.java @@ -2,7 +2,6 @@ package com.fr.startup.ui; import com.fr.base.svg.IconUtils; import com.fr.design.DesignerEnvManager; -import com.fr.design.components.loading.LoadingPane; import com.fr.design.dialog.UIExpandDialog; import com.fr.design.gui.icontainer.UIScrollPane; import com.fr.design.gui.ilable.UILabel; @@ -12,12 +11,14 @@ import com.fr.design.layout.VerticalFlowLayout; import com.fr.design.ui.util.UIUtil; import com.fr.design.utils.ColorUtils; import com.fr.design.utils.ThemeUtils; +import com.fr.design.utils.gui.GUICoreUtils; import com.fr.exit.DesignerExiter; import com.fr.general.GeneralUtils; import com.fr.general.IOUtils; import com.fr.log.FineLoggerFactory; import com.fr.stable.ProductConstants; import com.fr.stable.collections.CollectionUtils; +import com.fr.stable.os.OperatingSystem; import com.fr.start.common.DesignerStartupContext; import com.fr.startup.metric.DesignerMetrics; import org.jetbrains.annotations.NotNull; @@ -25,7 +26,6 @@ import org.jetbrains.annotations.NotNull; import javax.swing.BorderFactory; import javax.swing.JComponent; import javax.swing.JFrame; -import javax.swing.JLayeredPane; import javax.swing.JPanel; import javax.swing.JSeparator; import javax.swing.ScrollPaneConstants; @@ -34,7 +34,6 @@ import javax.swing.SwingWorker; import javax.swing.border.EmptyBorder; import java.awt.BorderLayout; import java.awt.Color; -import java.awt.Component; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Font; @@ -59,9 +58,6 @@ import java.util.Map; **/ public class StartupPageWindow extends JFrame { - private static final int CONTENT_LAYER = 0; - private static final int TRANSPARENT_LAYER = 1; - private static final Color HOVER_COLOR = new Color(65, 155, 249); private static final Color SEP_COLOR = new Color(224, 224, 225); @@ -84,56 +80,51 @@ public class StartupPageWindow extends JFrame { private JPanel body; - private LoadingPane loadingPane = new LoadingPane(); - - private JLayeredPane layeredPane = new JLayeredPane() { - @Override - public void doLayout() { - for (Component comp : getComponents()) { - comp.setBounds(0, 0, getWidth(), getHeight()); - } - } - }; - public StartupPageWindow(StartupPageModel pageModel) { patchUIAction(pageModel); setLayout(new BorderLayout()); + + initCenter(pageModel); + + // Workspace-detail + setSize(SCREEN_SIZE); + setDefaultTitle(); + addDefaultListeners(); + + repaint(); + validate(); + revalidate(); + setFullScreen(); + + } + + private void initCenter(StartupPageModel pageModel) { + + initHeaderPanel(); + + initWorkspacePanel(pageModel); + + initRecentOpenPanel(pageModel); + initContentPanel(); + } + + private void initHeaderPanel() { this.body = FRGUIPaneFactory.createBorderLayout_S_Pane(); this.body.setBackground(new Color(0, 0, 0, 0)); - // Header - UILabel label = new UILabel(Toolkit.i18nText("Fine-Design_Startup_Page_Select_Workspace")); - Font font = label.getFont(); - Font titleFont = font.deriveFont(font.getStyle(), TITLE_FONT_SIZE); - label.setFont(titleFont); - JPanel headerPanel = new JPanel(); - LayoutManager centerFlowLayout = FRGUIPaneFactory.createCenterFlowLayout(); - headerPanel.setLayout(centerFlowLayout); - headerPanel.add(label); - headerPanel.setBackground(new Color(0, 0, 0, 0)); + JPanel headerPanel = createHeader(); this.body.add(headerPanel, BorderLayout.NORTH); - - // Workspace-description - this.workspacePanel = generateWorkspacePanel(pageModel); - this.body.add(workspacePanel, BorderLayout.CENTER); + } - workspacePanel.setSelectWorkspaceRunnable(new Runnable() { - @Override - public void run() { - JPanel newPanel = generateRecentOpenPanel(pageModel); - - body.remove(recentOpenPanel); - recentOpenPanel = newPanel; - body.add(recentOpenPanel, BorderLayout.SOUTH); - validate(); - repaint(); - } - }); + private void initRecentOpenPanel(StartupPageModel pageModel) { this.recentOpenPanel = generateRecentOpenPanel(pageModel); this.body.add(recentOpenPanel, BorderLayout.SOUTH); + } + + private void initContentPanel() { this.contentPane = new JPanel() { @Override protected void paintComponent(Graphics g) { @@ -144,32 +135,58 @@ public class StartupPageWindow extends JFrame { this.contentPane.setLayout(getCenterLayout(body)); this.contentPane.add(this.body, BorderLayout.CENTER); this.contentPane.setPreferredSize(this.body.getPreferredSize()); - - this.layeredPane.setName("layered-pane"); - this.layeredPane.add(this.contentPane, CONTENT_LAYER); - this.layeredPane.add(this.loadingPane, TRANSPARENT_LAYER); - this.layeredPane.moveToFront(this.contentPane); - add(this.layeredPane, BorderLayout.CENTER); + add(this.contentPane, BorderLayout.CENTER); + } + + private void initWorkspacePanel(StartupPageModel pageModel) { - // Workspace-detail - setSize(SCREEN_SIZE); - setDefaultTitle(); - addDefaultListeners(); + // Workspace-description + this.workspacePanel = generateWorkspacePanel(pageModel); + this.body.add(workspacePanel, BorderLayout.CENTER); - repaint(); - validate(); - revalidate(); + workspacePanel.setSelectWorkspaceRunnable(new Runnable() { + @Override + public void run() { + JPanel newPanel = generateRecentOpenPanel(pageModel); + + body.remove(recentOpenPanel); + recentOpenPanel = newPanel; + body.add(recentOpenPanel, BorderLayout.SOUTH); + validate(); + repaint(); + } + }); + } + + @NotNull + private static JPanel createHeader() { - setFullScreen(); - + // Header + UILabel label = new UILabel(Toolkit.i18nText("Fine-Design_Startup_Page_Select_Workspace")); + Font font = label.getFont(); + Font titleFont = font.deriveFont(font.getStyle(), TITLE_FONT_SIZE); + label.setFont(titleFont); + JPanel headerPanel = new JPanel(); + LayoutManager centerFlowLayout = FRGUIPaneFactory.createCenterFlowLayout(); + headerPanel.setLayout(centerFlowLayout); + headerPanel.add(label); + headerPanel.setBackground(new Color(0, 0, 0, 0)); + return headerPanel; } + /** + * 1-mac启动时全屏 + * 2-windows 则居中处理 + */ private void setFullScreen() { - - Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); - this.setLocation(0, 0); - this.setSize(screenSize.width, screenSize.height); + + if (OperatingSystem.isMacos()) { + this.setLocation(0, 0); + this.setSize(SCREEN_SIZE.width, SCREEN_SIZE.height); + } else { + GUICoreUtils.setWindowFullScreen(this); + } } private void addDefaultListeners() { @@ -214,44 +231,51 @@ public class StartupPageWindow extends JFrame { } private void enterWorkspace(Runnable action) { - - loadingPane.start(); - layeredPane.moveToFront(loadingPane); - SwingWorker task = new SwingWorker() { - @Override - protected Void doInBackground() throws Exception { - action.run(); - return null; - } - @Override - protected void done() { - - try { - Void result = get(); - setVisible(false); - } catch (Exception e) { - // 处理错误 - UIUtil.invokeLaterIfNeeded(() -> { - UIExpandDialog.Builder() - .owner(StartupPageWindow.this) - .title(Toolkit.i18nText("Fine-Design_Basic_Remote_Env_Try")) - .message(Toolkit.i18nText("Fine-Design_Basic_Connection_Failed")) - .messageType(UIExpandDialog.WARNING_MESSAGE) - .detail(e.getMessage()) - .expand(true) - .modal(false) - .build() - .setVisible(true); - }); - FineLoggerFactory.getLogger().error(e.getMessage(), e); - layeredPane.moveToFront(contentPane); - } finally { - loadingPane.stop(); + UIUtil.invokeAndWaitIfNeeded(() -> { + + // 必须直接初始化 + // 见 https://work.fineres.com/browse/REPORT-85293 + StartupLoadingPanel loadingPanel = new StartupLoadingPanel(this); + loadingPanel.show(); + setEnabled(false); + + SwingWorker task = new SwingWorker() { + @Override + protected Void doInBackground() throws Exception { + action.run(); + return null; } - } - }; - task.execute(); + + @Override + protected void done() { + + try { + Void result = get(); + setVisible(false); + } catch (Exception e) { + // 处理错误 + UIUtil.invokeLaterIfNeeded(() -> { + UIExpandDialog.Builder() + .owner(StartupPageWindow.this) + .title(Toolkit.i18nText("Fine-Design_Basic_Remote_Env_Try")) + .message(Toolkit.i18nText("Fine-Design_Basic_Connection_Failed")) + .messageType(UIExpandDialog.WARNING_MESSAGE) + .detail(e.getMessage()) + .expand(true) + .modal(false) + .build() + .setVisible(true); + setEnabled(true); + }); + FineLoggerFactory.getLogger().error(e.getMessage(), e); + } finally { + loadingPanel.hide(); + } + } + }; + task.execute(); + }); } private JPanel generateRecentOpenPanel(StartupPageModel pageModel) { diff --git a/designer-base/src/main/java/com/fr/startup/ui/StartupPageWorkspacePanel.java b/designer-base/src/main/java/com/fr/startup/ui/StartupPageWorkspacePanel.java index ced2aa3767..3cd6b78773 100644 --- a/designer-base/src/main/java/com/fr/startup/ui/StartupPageWorkspacePanel.java +++ b/designer-base/src/main/java/com/fr/startup/ui/StartupPageWorkspacePanel.java @@ -4,6 +4,7 @@ import com.fr.base.svg.IconUtils; import com.fr.design.components.tooltip.ModernToolTip; import com.fr.design.gui.icontainer.UIScrollPane; import com.fr.design.gui.ilable.UILabel; +import com.fr.design.gui.itextfield.FRGraphics2D; import com.fr.design.i18n.Toolkit; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.utils.ColorUtils; @@ -17,6 +18,8 @@ import javax.swing.Icon; import javax.swing.JComponent; import javax.swing.JPanel; import javax.swing.JToolTip; +import javax.swing.JViewport; +import javax.swing.RepaintManager; import javax.swing.ScrollPaneConstants; import javax.swing.border.EmptyBorder; import java.awt.BasicStroke; @@ -28,9 +31,11 @@ import java.awt.Font; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.GridLayout; +import java.awt.Image; import java.awt.RenderingHints; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; +import java.awt.image.ImageObserver; import java.util.List; import java.util.concurrent.atomic.AtomicReference; @@ -127,9 +132,15 @@ public class StartupPageWorkspacePanel extends JPanel { this.contentPanel = generateUnLimitContentPanel(this.partitions); this.add(contentPanel, BorderLayout.NORTH); } - private JComponent generateUnLimitContentPanel(List> partitions) { + JComponent panel = generateUnLimitContentPanel0(partitions); + ColorUtils.transparentBackground(panel); + return panel; + } + + private JComponent generateUnLimitContentPanel0(List> partitions) { + JPanel workspaceDescWrapper = new JPanel(); workspaceDescWrapper.setLayout(new BorderLayout(0, 0)); workspaceDescWrapper.setBorder(new EmptyBorder(0, 0, 0, 0)); @@ -142,16 +153,28 @@ public class StartupPageWorkspacePanel extends JPanel { } boolean needScroll = partitions.size() > 4; if (needScroll) { - // 滚动条 - UIScrollPane scrollPane = new UIScrollPane(workspaceDescPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); - scrollPane.setBorder(new EmptyBorder(10, 0, 0, 0)); - scrollPane.setPreferredSize(new Dimension(CONTENT_WIDTH, SCROLL_HEIGHT)); - workspaceDescWrapper.add(scrollPane, BorderLayout.CENTER); - return workspaceDescWrapper; + return generateScrollUnLimitContentPanel(workspaceDescWrapper, workspaceDescPanel); } workspaceDescWrapper.add(workspaceDescPanel, BorderLayout.CENTER); - ColorUtils.transparentBackground(workspaceDescWrapper); + return workspaceDescWrapper; + } + + @NotNull + private JPanel generateScrollUnLimitContentPanel(JPanel workspaceDescWrapper, JPanel workspaceDescPanel) { + + // 滚动条 + UIScrollPane scrollPane = new UIScrollPane(workspaceDescPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); + JViewport viewport = scrollPane.getViewport(); + JViewport scrollViewport = new TransparentScrollViewPort(); + // 动态画图 + scrollViewport.addChangeListener(e -> repaintAll()); + scrollViewport.setView(viewport.getView()); + scrollPane.setViewport(scrollViewport); + scrollPane.setBorder(new EmptyBorder(10, 0, 0, 0)); + scrollPane.setPreferredSize(new Dimension(CONTENT_WIDTH, SCROLL_HEIGHT)); + workspaceDescWrapper.add(scrollPane, BorderLayout.CENTER); + return workspaceDescWrapper; } @@ -580,4 +603,27 @@ public class StartupPageWorkspacePanel extends JPanel { this.getRootPane().repaint(); } + + /** + * 支持透明的滚动视图 + */ + private class TransparentScrollViewPort extends JViewport { + + /** + * 从而屏蔽掉 {@link RepaintManager.PaintManager#paintDoubleBuffered(JComponent, Image, Graphics, int, int, int, int)} + * + * @return 创建一个不会实际画图的 Graphics + */ + @Override + public Graphics getGraphics() { + + Graphics graphics = super.getGraphics(); + return new FRGraphics2D((Graphics2D) graphics) { + @Override + public boolean drawImage(Image img, int x, int y, ImageObserver observer) { + return true; + } + }; + } + } } diff --git a/designer-base/src/main/resources/com/fr/design/i18n/dimension_en.properties b/designer-base/src/main/resources/com/fr/design/i18n/dimension_en.properties index 7f249d1a5e..d1f8ee17b2 100644 --- a/designer-base/src/main/resources/com/fr/design/i18n/dimension_en.properties +++ b/designer-base/src/main/resources/com/fr/design/i18n/dimension_en.properties @@ -15,10 +15,12 @@ com.fr.design.report.fit.firstColumn=120*20 com.fr.design.report.fit.column=160*20 com.fr.design.lock.LockInfoDialog=500*180 com.fr.design.mainframe.ForbiddenPane.refreshButton=75*24 +com.fr.start.common.DesignerOpenEmptyPanel.createButton=120*24 com.fr.design.cell.expand.sort.pane=257*185 com.fr.design.sort.rule.item=125*20 com.fr.design.ds.column.sort.pane=250*180 com.fr.design.sort.expand.header.pane=95*10 com.fr.design.plugin.remind.PluginInvalidateRemindDialog.dialog=600*500 com.fr.design.plugin.remind.PluginInvalidateRemindDialog.centerPane=580*369 -com.fr.design.report.WatermarkSettingPane=720*600 \ No newline at end of file +com.fr.design.report.WatermarkSettingPane=720*600 +com.fr.design.file.MultiTemplateTabPane.popUpMenu=350*65 diff --git a/designer-base/src/main/resources/com/fr/design/i18n/dimension_ja_JP.properties b/designer-base/src/main/resources/com/fr/design/i18n/dimension_ja_JP.properties index ec876154ae..a5b3a03fe6 100644 --- a/designer-base/src/main/resources/com/fr/design/i18n/dimension_ja_JP.properties +++ b/designer-base/src/main/resources/com/fr/design/i18n/dimension_ja_JP.properties @@ -14,10 +14,12 @@ com.fr.design.report.fit.firstColumn=170*20 com.fr.design.report.fit.column=100*20 com.fr.design.lock.LockInfoDialog=500*180 com.fr.design.mainframe.ForbiddenPane.refreshButton=68*24 +com.fr.start.common.DesignerOpenEmptyPanel.createButton=70*24 com.fr.design.cell.expand.sort.pane=257*170 com.fr.design.sort.rule.item=125*20 com.fr.design.ds.column.sort.pane=250*165 com.fr.design.sort.expand.header.pane=95*10 com.fr.design.plugin.remind.PluginInvalidateRemindDialog.dialog=600*500 com.fr.design.plugin.remind.PluginInvalidateRemindDialog.centerPane=580*369 -com.fr.design.report.WatermarkSettingPane=720*600 \ No newline at end of file +com.fr.design.report.WatermarkSettingPane=720*600 +com.fr.design.file.MultiTemplateTabPane.popUpMenu=240*65 diff --git a/designer-base/src/main/resources/com/fr/design/i18n/dimension_ko_KR.properties b/designer-base/src/main/resources/com/fr/design/i18n/dimension_ko_KR.properties index dd8e8571b5..4e8b3f9cdb 100644 --- a/designer-base/src/main/resources/com/fr/design/i18n/dimension_ko_KR.properties +++ b/designer-base/src/main/resources/com/fr/design/i18n/dimension_ko_KR.properties @@ -14,10 +14,12 @@ com.fr.design.report.fit.firstColumn=130*20 com.fr.design.report.fit.column=100*20 com.fr.design.lock.LockInfoDialog=500*180 com.fr.design.mainframe.ForbiddenPane.refreshButton=80*24 +com.fr.start.common.DesignerOpenEmptyPanel.createButton=70*24 com.fr.design.cell.expand.sort.pane=267*165 com.fr.design.sort.rule.item=125*20 com.fr.design.ds.column.sort.pane=250*180 com.fr.design.sort.expand.header.pane=95*10 com.fr.design.plugin.remind.PluginInvalidateRemindDialog.dialog=600*500 com.fr.design.plugin.remind.PluginInvalidateRemindDialog.centerPane=580*369 -com.fr.design.report.WatermarkSettingPane=720*600 \ No newline at end of file +com.fr.design.report.WatermarkSettingPane=720*600 +com.fr.design.file.MultiTemplateTabPane.popUpMenu=240*65 diff --git a/designer-base/src/main/resources/com/fr/design/i18n/dimension_zh.properties b/designer-base/src/main/resources/com/fr/design/i18n/dimension_zh.properties index 44ea2f3bd8..d1e84b4618 100644 --- a/designer-base/src/main/resources/com/fr/design/i18n/dimension_zh.properties +++ b/designer-base/src/main/resources/com/fr/design/i18n/dimension_zh.properties @@ -22,4 +22,5 @@ com.fr.design.ds.column.sort.pane=220*150 com.fr.design.sort.expand.header.pane=108*10 com.fr.design.plugin.remind.PluginInvalidateRemindDialog.dialog=600*500 com.fr.design.plugin.remind.PluginInvalidateRemindDialog.centerPane=580*369 -com.fr.design.report.WatermarkSettingPane=720*600 \ No newline at end of file +com.fr.design.report.WatermarkSettingPane=720*600 +com.fr.design.file.MultiTemplateTabPane.popUpMenu=170*65 diff --git a/designer-base/src/main/resources/com/fr/design/i18n/dimension_zh_TW.properties b/designer-base/src/main/resources/com/fr/design/i18n/dimension_zh_TW.properties index 90d082cc9f..82f86a3a43 100644 --- a/designer-base/src/main/resources/com/fr/design/i18n/dimension_zh_TW.properties +++ b/designer-base/src/main/resources/com/fr/design/i18n/dimension_zh_TW.properties @@ -14,10 +14,12 @@ com.fr.design.report.fit.firstColumn=80*20 com.fr.design.report.fit.column=100*20 com.fr.design.lock.LockInfoDialog=400*180 com.fr.design.mainframe.ForbiddenPane.refreshButton=68*24 +com.fr.start.common.DesignerOpenEmptyPanel.createButton=70*24 com.fr.design.cell.expand.sort.pane=227*155 com.fr.design.sort.rule.item=80*20 com.fr.design.ds.column.sort.pane=220*150 com.fr.design.sort.expand.header.pane=108*10 com.fr.design.plugin.remind.PluginInvalidateRemindDialog.dialog=600*500 com.fr.design.plugin.remind.PluginInvalidateRemindDialog.centerPane=580*369 -com.fr.design.report.WatermarkSettingPane=720*600 \ No newline at end of file +com.fr.design.report.WatermarkSettingPane=720*600 +com.fr.design.file.MultiTemplateTabPane.popUpMenu=170*65 diff --git a/designer-base/src/main/resources/com/fr/design/images/buttonicon/replace_help.svg b/designer-base/src/main/resources/com/fr/design/images/buttonicon/replace_help.svg new file mode 100644 index 0000000000..fdbd5eca5e --- /dev/null +++ b/designer-base/src/main/resources/com/fr/design/images/buttonicon/replace_help.svg @@ -0,0 +1,3 @@ + + + diff --git a/designer-base/src/main/resources/com/fr/design/images/buttonicon/widget/picture_widget_16.png b/designer-base/src/main/resources/com/fr/design/images/buttonicon/widget/picture_widget_16.png new file mode 100644 index 0000000000..fbf334ad22 Binary files /dev/null and b/designer-base/src/main/resources/com/fr/design/images/buttonicon/widget/picture_widget_16.png differ diff --git a/designer-base/src/main/resources/com/fr/design/images/control/refresh_normal.svg b/designer-base/src/main/resources/com/fr/design/images/control/refresh_normal.svg new file mode 100644 index 0000000000..e83a52740e --- /dev/null +++ b/designer-base/src/main/resources/com/fr/design/images/control/refresh_normal.svg @@ -0,0 +1,7 @@ + + + icon_刷新_normal + + + + diff --git a/designer-base/src/main/resources/com/fr/design/images/form/designer/widget/picture_widget_designer_bg.png b/designer-base/src/main/resources/com/fr/design/images/form/designer/widget/picture_widget_designer_bg.png new file mode 100644 index 0000000000..9e731c557b Binary files /dev/null and b/designer-base/src/main/resources/com/fr/design/images/form/designer/widget/picture_widget_designer_bg.png differ diff --git a/designer-base/src/main/resources/com/fr/design/images/platform/platform_normal.svg b/designer-base/src/main/resources/com/fr/design/images/platform/platform_normal.svg new file mode 100644 index 0000000000..ab95e95f3c --- /dev/null +++ b/designer-base/src/main/resources/com/fr/design/images/platform/platform_normal.svg @@ -0,0 +1,3 @@ + + + diff --git a/designer-base/src/main/resources/com/fr/design/images/replace/change_normal.svg b/designer-base/src/main/resources/com/fr/design/images/replace/change_normal.svg new file mode 100644 index 0000000000..88d9e7772b --- /dev/null +++ b/designer-base/src/main/resources/com/fr/design/images/replace/change_normal.svg @@ -0,0 +1,3 @@ + + + diff --git a/designer-base/src/main/resources/com/fr/design/images/replace/replace.png b/designer-base/src/main/resources/com/fr/design/images/replace/replace.png new file mode 100644 index 0000000000..b9a41125c5 Binary files /dev/null and b/designer-base/src/main/resources/com/fr/design/images/replace/replace.png differ diff --git a/designer-base/src/main/resources/com/fr/design/images/replace/replace_normal.svg b/designer-base/src/main/resources/com/fr/design/images/replace/replace_normal.svg new file mode 100644 index 0000000000..f11cdc07b0 --- /dev/null +++ b/designer-base/src/main/resources/com/fr/design/images/replace/replace_normal.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/designer-base/src/main/resources/com/fr/design/standard/add/add_black_normal.svg b/designer-base/src/main/resources/com/fr/design/standard/add/add_black_normal.svg new file mode 100644 index 0000000000..2c63e640bc --- /dev/null +++ b/designer-base/src/main/resources/com/fr/design/standard/add/add_black_normal.svg @@ -0,0 +1,3 @@ + + + diff --git a/designer-base/src/main/resources/com/fr/design/standard/debug/debug_disabled.svg b/designer-base/src/main/resources/com/fr/design/standard/debug/debug_disabled.svg new file mode 100644 index 0000000000..520d126a0f --- /dev/null +++ b/designer-base/src/main/resources/com/fr/design/standard/debug/debug_disabled.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/designer-base/src/main/resources/com/fr/design/standard/debug/debug_normal.svg b/designer-base/src/main/resources/com/fr/design/standard/debug/debug_normal.svg new file mode 100644 index 0000000000..80abccaba9 --- /dev/null +++ b/designer-base/src/main/resources/com/fr/design/standard/debug/debug_normal.svg @@ -0,0 +1,4 @@ + + + + diff --git a/designer-base/src/main/resources/com/fr/design/standard/edit/edit_disabled.svg b/designer-base/src/main/resources/com/fr/design/standard/edit/edit_disabled.svg new file mode 100644 index 0000000000..6ac7d0b932 --- /dev/null +++ b/designer-base/src/main/resources/com/fr/design/standard/edit/edit_disabled.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/designer-base/src/main/resources/com/fr/design/standard/edit/edit_normal.svg b/designer-base/src/main/resources/com/fr/design/standard/edit/edit_normal.svg new file mode 100644 index 0000000000..3ab4c0b297 --- /dev/null +++ b/designer-base/src/main/resources/com/fr/design/standard/edit/edit_normal.svg @@ -0,0 +1,3 @@ + + + diff --git a/designer-base/src/main/resources/com/fr/design/standard/refresh/refresh_normal.svg b/designer-base/src/main/resources/com/fr/design/standard/refresh/refresh_normal.svg new file mode 100644 index 0000000000..4e3fd9c147 --- /dev/null +++ b/designer-base/src/main/resources/com/fr/design/standard/refresh/refresh_normal.svg @@ -0,0 +1,7 @@ + + + icon_刷新_normal + + + + \ No newline at end of file diff --git a/designer-base/src/main/resources/com/fr/design/standard/remove/remove_red_normal.svg b/designer-base/src/main/resources/com/fr/design/standard/remove/remove_red_normal.svg new file mode 100644 index 0000000000..74ff5ab385 --- /dev/null +++ b/designer-base/src/main/resources/com/fr/design/standard/remove/remove_red_normal.svg @@ -0,0 +1,7 @@ + + + icon_关闭_red + + + + diff --git a/designer-base/src/main/resources/com/fr/design/standard/tip/tips_normal.svg b/designer-base/src/main/resources/com/fr/design/standard/tip/tips_normal.svg new file mode 100644 index 0000000000..cfc3370a66 --- /dev/null +++ b/designer-base/src/main/resources/com/fr/design/standard/tip/tips_normal.svg @@ -0,0 +1,3 @@ + + + diff --git a/designer-base/src/test/java/com/fr/design/gui/iprogressbar/ProgressDialogTest.java b/designer-base/src/test/java/com/fr/design/gui/iprogressbar/ProgressDialogTest.java new file mode 100644 index 0000000000..336850f26b --- /dev/null +++ b/designer-base/src/test/java/com/fr/design/gui/iprogressbar/ProgressDialogTest.java @@ -0,0 +1,55 @@ +package com.fr.design.gui.iprogressbar; + +import com.fr.design.utils.DevUtils; + +import java.awt.Dimension; +import java.awt.Frame; +import java.util.function.Consumer; + +/** + * @author Harrison + * @version 11.0 + * Created by Harrison on 2022/11/23 + */ +public class ProgressDialogTest { + + public static void main(String[] args) { + + mockInitSize(); + } + + /** + * 模拟 frame 的大小未初始化好的情况 + */ + private static void mockNotInitSize() { + + DevUtils.show(new Consumer() { + @Override + public void accept(Frame frame) { + + Dimension origin = frame.getSize(); + frame.setSize(0, 0); + ProgressDialog progressDialog = new ProgressDialog(frame); + progressDialog.setVisible(true); + progressDialog.updateLoadingText("test"); + frame.setSize(origin); + } + }); + } + + /** + * 模拟 frame 的大小初始化好的情况 + */ + private static void mockInitSize() { + + DevUtils.show(new Consumer() { + @Override + public void accept(Frame frame) { + + ProgressDialog progressDialog = new ProgressDialog(frame); + progressDialog.setVisible(true); + progressDialog.updateLoadingText("test"); + } + }); + } +} \ No newline at end of file diff --git a/designer-base/src/test/java/com/fr/env/RemoteWorkspaceURLTest.java b/designer-base/src/test/java/com/fr/env/RemoteWorkspaceURLTest.java index f066ae6896..b9412a93d5 100644 --- a/designer-base/src/test/java/com/fr/env/RemoteWorkspaceURLTest.java +++ b/designer-base/src/test/java/com/fr/env/RemoteWorkspaceURLTest.java @@ -242,4 +242,14 @@ public class RemoteWorkspaceURLTest { assertEquals("servlet", b.getServlet()); //others begin } + + @Test + public void testIPV6Url() { + String trueUrl = "http://[fe80::4d83:cc10:9f6f:3303]:8080/webroot/decision"; + RemoteWorkspaceURL remoteWorkspaceURL1 = new RemoteWorkspaceURL(trueUrl); + assertEquals("[fe80::4d83:cc10:9f6f:3303]", remoteWorkspaceURL1.getHost()); + assertEquals("8080", remoteWorkspaceURL1.getPort()); + assertEquals("webroot", remoteWorkspaceURL1.getWeb()); + assertEquals("decision", remoteWorkspaceURL1.getServlet()); + } } diff --git a/designer-base/src/test/java/com/fr/env/detect/impl/converter/ClassConflictConvertorTest.java b/designer-base/src/test/java/com/fr/env/detect/impl/converter/ClassConflictConvertorTest.java index cdc789b015..20f370b7b1 100644 --- a/designer-base/src/test/java/com/fr/env/detect/impl/converter/ClassConflictConvertorTest.java +++ b/designer-base/src/test/java/com/fr/env/detect/impl/converter/ClassConflictConvertorTest.java @@ -1,5 +1,6 @@ package com.fr.env.detect.impl.converter; +import org.junit.Assert; import org.junit.Test; public class ClassConflictConvertorTest { @@ -10,14 +11,7 @@ public class ClassConflictConvertorTest { ClassNotFoundException ex1 = new ClassNotFoundException("Class 111.222.333 not found"); Iterable names = ClassConflictConvertor.Converter.CLASS.converter(ex1); - System.out.println(); - } - - @Test - public void testConverter() { - - ClassNotFoundException ex1 = new ClassNotFoundException("com.zaxxer.hikari.HikariConfig"); - ClassConflictConvertor convertor = new ClassConflictConvertor(); - convertor.convert(ex1); + String next = names.iterator().next(); + Assert.assertEquals("111.222.333", next); } } \ No newline at end of file diff --git a/designer-chart/src/main/java/com/fr/design/chart/ChartDialog.java b/designer-chart/src/main/java/com/fr/design/chart/ChartDialog.java index bce90aaaeb..183f14b768 100644 --- a/designer-chart/src/main/java/com/fr/design/chart/ChartDialog.java +++ b/designer-chart/src/main/java/com/fr/design/chart/ChartDialog.java @@ -4,9 +4,11 @@ import com.fr.base.chart.BaseChartCollection; import com.fr.chart.chartattr.ChartCollection; import com.fr.design.dialog.BasicDialog; import com.fr.design.file.HistoryTemplateListCache; +import com.fr.design.fun.DefaultValueAdjustProvider; import com.fr.design.gui.chart.MiddleChartDialog; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.i18n.Toolkit; +import com.fr.design.utils.DesignUtils; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.third.joda.time.DateTime; @@ -87,6 +89,10 @@ public class ChartDialog extends MiddleChartDialog { return new ActionListener() { public void actionPerformed(ActionEvent e) { chartTypePane.update((ChartCollection) cc, createTime); + DefaultValueAdjustProvider adjustProvider = DesignUtils.getValueAdjust(); + if (adjustProvider != null) { + adjustProvider.adjustChartCollectionStyle(cc); + } doOK(); } }; diff --git a/designer-chart/src/main/java/com/fr/design/chart/axis/ChartAlertValuePane.java b/designer-chart/src/main/java/com/fr/design/chart/axis/ChartAlertValuePane.java index d0244cebab..59250c9725 100644 --- a/designer-chart/src/main/java/com/fr/design/chart/axis/ChartAlertValuePane.java +++ b/designer-chart/src/main/java/com/fr/design/chart/axis/ChartAlertValuePane.java @@ -18,6 +18,7 @@ import com.fr.design.layout.TableLayoutHelper; import com.fr.design.style.AlphaPane; import com.fr.design.style.FRFontPane; import com.fr.design.style.color.ColorSelectBox; +import com.fr.design.utils.DesignUtils; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.general.FRFont; @@ -114,7 +115,7 @@ public class ChartAlertValuePane extends BasicBeanPane { fontNameBox.setPreferredSize(new Dimension(80,20)); fontNameBox.addItem("SimSun"); // TODO 这边字体中没有在列表内 - String[] names = Utils.getAvailableFontFamilyNames4Report(); + String[] names = DesignUtils.getAvailableFontFamilyNames4Report(); for(int i = 0; i < names.length; i++) { fontNameBox.addItem(names[i]); } diff --git a/designer-chart/src/main/java/com/fr/design/chart/series/SeriesCondition/DataLabelStylePane.java b/designer-chart/src/main/java/com/fr/design/chart/series/SeriesCondition/DataLabelStylePane.java index a2047b4e1c..c2036b7292 100644 --- a/designer-chart/src/main/java/com/fr/design/chart/series/SeriesCondition/DataLabelStylePane.java +++ b/designer-chart/src/main/java/com/fr/design/chart/series/SeriesCondition/DataLabelStylePane.java @@ -9,6 +9,7 @@ import com.fr.chart.base.TextAttr; import com.fr.design.gui.icombobox.UIComboBox; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.dialog.BasicPane; +import com.fr.design.utils.DesignUtils; import com.fr.general.FRFont; import com.fr.design.style.FRFontPane; @@ -36,7 +37,7 @@ public class DataLabelStylePane extends BasicPane { private void initPane(boolean isSurpportFontColor) { this.setLayout(FRGUIPaneFactory.createBoxFlowLayout()); - this.add(nameBox = new UIComboBox(Utils.getAvailableFontFamilyNames4Report())); + this.add(nameBox = new UIComboBox(DesignUtils.getAvailableFontFamilyNames4Report())); nameBox.setPreferredSize(new Dimension(80, 20)); String[] styles = { diff --git a/designer-chart/src/main/java/com/fr/design/chart/series/SeriesCondition/impl/ChartHyperPoplinkPane.java b/designer-chart/src/main/java/com/fr/design/chart/series/SeriesCondition/impl/ChartHyperPoplinkPane.java index 11d2e32e4d..35b0c0d5bc 100644 --- a/designer-chart/src/main/java/com/fr/design/chart/series/SeriesCondition/impl/ChartHyperPoplinkPane.java +++ b/designer-chart/src/main/java/com/fr/design/chart/series/SeriesCondition/impl/ChartHyperPoplinkPane.java @@ -8,10 +8,12 @@ import com.fr.chart.web.ChartHyperPoplink; import com.fr.chartx.attr.ChartProvider; import com.fr.design.chart.gui.ChartComponent; import com.fr.design.file.HistoryTemplateListCache; +import com.fr.design.fun.DefaultValueAdjustProvider; import com.fr.design.gui.itextfield.UITextField; import com.fr.design.hyperlink.AbstractHyperLinkPane; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.mainframe.chart.ChartHyperEditPane; +import com.fr.design.utils.DesignUtils; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.log.FineLoggerFactory; import com.fr.van.chart.config.DefaultStyleHelper4Van; @@ -67,7 +69,10 @@ public class ChartHyperPoplinkPane extends AbstractHyperLinkPane extends BasicBeanPane(columnNameList); } private void checkCardPane() { diff --git a/designer-chart/src/main/java/com/fr/design/chartx/component/correlation/AbstractCorrelationPane.java b/designer-chart/src/main/java/com/fr/design/chartx/component/correlation/AbstractCorrelationPane.java index 5c468c424a..2cb52f4542 100644 --- a/designer-chart/src/main/java/com/fr/design/chartx/component/correlation/AbstractCorrelationPane.java +++ b/designer-chart/src/main/java/com/fr/design/chartx/component/correlation/AbstractCorrelationPane.java @@ -127,4 +127,14 @@ public abstract class AbstractCorrelationPane extends BasicBeanPane { return StringUtils.EMPTY; } + /** + * 清空 “系列名使用字段名” 表格 + */ + public void clearAllBoxList() { + this.correlationPane.getTable().clear(); + this.correlationPane.validate(); + this.correlationPane.repaint(); + this.correlationPane.revalidate(); + } + } diff --git a/designer-chart/src/main/java/com/fr/design/chartx/single/DataSetPane.java b/designer-chart/src/main/java/com/fr/design/chartx/single/DataSetPane.java index 3df0d3d6d5..dab74e15a4 100644 --- a/designer-chart/src/main/java/com/fr/design/chartx/single/DataSetPane.java +++ b/designer-chart/src/main/java/com/fr/design/chartx/single/DataSetPane.java @@ -8,6 +8,7 @@ import com.fr.design.chartx.fields.AbstractDataSetFieldsPane; import com.fr.design.data.tabledata.wrapper.TableDataWrapper; import com.fr.design.i18n.Toolkit; import com.fr.design.mainframe.chart.gui.data.DatabaseTableDataPane; +import com.fr.stable.StringUtils; import javax.swing.JPanel; import java.awt.BorderLayout; @@ -75,6 +76,10 @@ public class DataSetPane extends FurtherBasicBeanPane { List columnNameList = dataWrap.calculateColumnNameList(); if (dataSetFieldsPane != null) { + // 如果属性编辑画板中选中的数据集发生改变,则清空之前的匹配项 + if (!StringUtils.equals(dataSetFieldsPane.getTableName(), dataWrap.getTableDataName())) { + dataSetFieldsPane.clearAllBoxList(); + } dataSetFieldsPane.refreshBoxListWithSelectTableData(columnNameList); dataSetFieldsPane.setTableName(dataWrap.getTableDataName()); } diff --git a/designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/data/TableDataPane.java b/designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/data/TableDataPane.java index 8863977740..82240bc6d2 100644 --- a/designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/data/TableDataPane.java +++ b/designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/data/TableDataPane.java @@ -15,6 +15,7 @@ import com.fr.design.i18n.Toolkit; import com.fr.design.mainframe.chart.gui.ChartDataPane; import com.fr.design.mainframe.chart.gui.data.table.AbstractTableDataContentPane; import com.fr.design.utils.gui.UIComponentUtils; +import com.fr.stable.StringUtils; import javax.swing.BorderFactory; import java.awt.BorderLayout; @@ -74,6 +75,10 @@ public class TableDataPane extends FurtherBasicBeanPane{ return; } if(dataContentPane != null) { + // 如果属性编辑画板中选中的数据集发生改变,则清空之前的匹配项 + if (!StringUtils.equals(dataContentPane.getTableName(), dataWrap.getTableDataName())) { + dataContentPane.clearAllBoxList(); + } dataContentPane.onSelectTableData(dataWrap); dataContentPane.setTableName(dataWrap.getTableDataName()); } diff --git a/designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/data/table/SeriesNameUseFieldNamePane.java b/designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/data/table/SeriesNameUseFieldNamePane.java index 9783c0577a..ec63cda9b9 100644 --- a/designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/data/table/SeriesNameUseFieldNamePane.java +++ b/designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/data/table/SeriesNameUseFieldNamePane.java @@ -24,8 +24,6 @@ import javax.swing.JComponent; import javax.swing.JPanel; import javax.swing.JTable; import javax.swing.event.ChangeEvent; -import java.util.ArrayList; -import java.util.List; import java.awt.BorderLayout; import java.awt.Component; import java.awt.Container; @@ -33,6 +31,8 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; +import java.util.ArrayList; +import java.util.List; /** * 属性表 数据集界面: 系列名 使用字段名. @@ -145,7 +145,7 @@ public class SeriesNameUseFieldNamePane extends FurtherBasicBeanPane { + // kuns: 默认修改500, 在地图修改系列颜色text时, 快速响应. + SwingUtilities.invokeLater(this::runChange); }, 500, TimeUnit.MILLISECONDS); } diff --git a/designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/style/series/UIColorPickerPane.java b/designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/style/series/UIColorPickerPane.java index ba617b5e78..2ae7e502e1 100644 --- a/designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/style/series/UIColorPickerPane.java +++ b/designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/style/series/UIColorPickerPane.java @@ -21,6 +21,7 @@ import com.fr.design.style.color.ColorSelectBox; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.stable.StringUtils; import com.fr.van.chart.designer.TableLayout4VanChartHelper; +import com.fr.van.chart.range.component.LegendGradientBar; import javax.swing.JComponent; import javax.swing.JFrame; @@ -102,7 +103,7 @@ public class UIColorPickerPane extends BasicPane implements UIObserver { } }); - regionNumPane = new UINumberDragPane(1, 6) { + regionNumPane = new UINumberDragPane(1, LegendGradientBar.COLOR_GRADUAL_NUM_MAX) { @Override public void userEvent(double value) { if(!UIColorPickerPane.this.moveOnColorOrTextPane){ @@ -191,7 +192,7 @@ public class UIColorPickerPane extends BasicPane implements UIObserver { } }); - regionNumPane = new UINumberDragPane(1, 6) { + regionNumPane = new UINumberDragPane(1, LegendGradientBar.COLOR_GRADUAL_NUM_MAX) { @Override public void userEvent(double value) { if(!UIColorPickerPane.this.moveOnColorOrTextPane){ diff --git a/designer-chart/src/main/java/com/fr/van/chart/config/DefaultStyleHelper4Van.java b/designer-chart/src/main/java/com/fr/van/chart/config/DefaultStyleHelper4Van.java index b3bfca329c..60f208f228 100644 --- a/designer-chart/src/main/java/com/fr/van/chart/config/DefaultStyleHelper4Van.java +++ b/designer-chart/src/main/java/com/fr/van/chart/config/DefaultStyleHelper4Van.java @@ -11,7 +11,9 @@ import com.fr.chart.chartglyph.ConditionAttr; import com.fr.chart.chartglyph.DataSheet; import com.fr.chartx.attr.ChartProvider; import com.fr.config.predefined.ColorFillStyle; +import com.fr.design.fun.DefaultValueAdjustProvider; import com.fr.design.mainframe.chart.mode.ChartEditContext; +import com.fr.design.utils.DesignUtils; import com.fr.plugin.chart.PiePlot4VanChart; import com.fr.plugin.chart.attr.axis.VanChartAlertValue; import com.fr.plugin.chart.attr.axis.VanChartAxis; @@ -54,7 +56,12 @@ public class DefaultStyleHelper4Van { dealChartColor((VanChart) chartProvider); // //主题中没有的 根据主题深浅色自动 的属性 默认自动 // ((VanChart) chart4Update).setAutoThemeCustom(); + DefaultValueAdjustProvider adjustProvider = DesignUtils.getValueAdjust(); + if (adjustProvider != null) { + adjustProvider.adjustChart(chartProvider); + } } + } public static void dealVanPlot4Custom(VanChartPlot plot, CustomPlotType customPlotType) { diff --git a/designer-chart/src/main/java/com/fr/van/chart/custom/component/VanChartHyperLinkPane.java b/designer-chart/src/main/java/com/fr/van/chart/custom/component/VanChartHyperLinkPane.java index 6e5b346a18..7b74d1576a 100644 --- a/designer-chart/src/main/java/com/fr/van/chart/custom/component/VanChartHyperLinkPane.java +++ b/designer-chart/src/main/java/com/fr/van/chart/custom/component/VanChartHyperLinkPane.java @@ -39,6 +39,8 @@ import com.fr.stable.Nameable; import com.fr.stable.bridge.StableFactory; import com.fr.van.chart.designer.component.VanChartUIListControlPane; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; @@ -186,6 +188,16 @@ public class VanChartHyperLinkPane extends VanChartUIListControlPane { } this.populate(nameObjects.toArray(new NameObject[nameObjects.size()])); + if (popupEditDialog instanceof HyperDialog) { + popupEditDialog.addWindowFocusListener(new WindowAdapter() { + @Override + public void windowLostFocus(WindowEvent e) { + if (needToHidePopupEditDialog()) { + popupEditDialog.setVisible(false); + } + } + }); + } doLayout(); } diff --git a/designer-chart/src/main/java/com/fr/van/chart/designer/style/background/VanChartAlertValuePane.java b/designer-chart/src/main/java/com/fr/van/chart/designer/style/background/VanChartAlertValuePane.java index 387d974d28..49e7f3fa99 100644 --- a/designer-chart/src/main/java/com/fr/van/chart/designer/style/background/VanChartAlertValuePane.java +++ b/designer-chart/src/main/java/com/fr/van/chart/designer/style/background/VanChartAlertValuePane.java @@ -17,6 +17,7 @@ import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayoutHelper; import com.fr.design.style.color.ColorSelectBox; +import com.fr.design.utils.DesignUtils; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.general.FRFont; import com.fr.general.GeneralUtils; @@ -99,7 +100,7 @@ public class VanChartAlertValuePane extends BasicBeanPane { alertText.setPreferredSize(new Dimension(TEXT_WD, HT)); fontSize = new UIComboBox(FRFontPane.FONT_SIZES); - fontName = new UIComboBox(Utils.getAvailableFontFamilyNames4Report()); + fontName = new UIComboBox(DesignUtils.getAvailableFontFamilyNames4Report()); fontColor = new ColorSelectBox(100); } diff --git a/designer-chart/src/main/java/com/fr/van/chart/multilayer/data/MultiPiePlotTableDataContentPane.java b/designer-chart/src/main/java/com/fr/van/chart/multilayer/data/MultiPiePlotTableDataContentPane.java index bfea7e1dc7..b32ea4b67c 100644 --- a/designer-chart/src/main/java/com/fr/van/chart/multilayer/data/MultiPiePlotTableDataContentPane.java +++ b/designer-chart/src/main/java/com/fr/van/chart/multilayer/data/MultiPiePlotTableDataContentPane.java @@ -10,6 +10,7 @@ import com.fr.design.gui.icombobox.UIComboBox; import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.ispinner.UISpinner; import com.fr.design.gui.itextfield.UITextField; +import com.fr.design.i18n.Toolkit; import com.fr.design.layout.TableLayout; import com.fr.design.mainframe.chart.gui.ChartDataPane; import com.fr.design.mainframe.chart.gui.data.CalculateComboBox; @@ -17,7 +18,6 @@ import com.fr.design.mainframe.chart.gui.data.table.AbstractTableDataContentPane import com.fr.design.mainframe.chart.gui.data.table.DataPaneHelper; import com.fr.general.ComparatorUtils; import com.fr.plugin.chart.multilayer.data.MultiPieValueDefinition; -import com.fr.design.i18n.Toolkit; import com.fr.stable.ArrayUtils; import com.fr.stable.AssistUtils; import com.fr.stable.StringUtils; @@ -235,7 +235,14 @@ public class MultiPiePlotTableDataContentPane extends AbstractTableDataContentPa @Override public void clearAllBoxList() { - + levelNumEdit.setValue(3); + nameField.setText(StringUtils.EMPTY); + clearBoxItems(value); + for (UIComboBox uiComboBox : levelNameList) { + clearBoxItems(uiComboBox); + } + clearBoxItems(calculateCombox); + refreshCenterPane(); } @Override diff --git a/designer-chart/src/main/java/com/fr/van/chart/range/component/GradualIntervalConfigPane.java b/designer-chart/src/main/java/com/fr/van/chart/range/component/GradualIntervalConfigPane.java index 1a0413ffaa..f1cdc5b62e 100644 --- a/designer-chart/src/main/java/com/fr/van/chart/range/component/GradualIntervalConfigPane.java +++ b/designer-chart/src/main/java/com/fr/van/chart/range/component/GradualIntervalConfigPane.java @@ -14,7 +14,7 @@ import javax.swing.event.ChangeListener; import java.awt.BorderLayout; import java.awt.Component; -public class GradualIntervalConfigPane extends JPanel{ +public class GradualIntervalConfigPane extends JPanel { private static final long serialVersionUID = 1614283200308877353L; //最大最小值面板 @@ -26,7 +26,7 @@ public class GradualIntervalConfigPane extends JPanel{ //渐变色编辑器 private LegendGradientBar legendGradientBar; - public GradualIntervalConfigPane(){ + public GradualIntervalConfigPane() { initComponents(); } @@ -42,10 +42,10 @@ public class GradualIntervalConfigPane extends JPanel{ } }); - numberDragPane = new UINumberDragPane(1,6) { + numberDragPane = new UINumberDragPane(1, LegendGradientBar.COLOR_GRADUAL_NUM_MAX) { @Override public void userEvent(double value) { - legendGradientBar.refreshColorSelectionBtnNum((int)value); + legendGradientBar.refreshColorSelectionBtnNum((int) value); } }; @@ -60,9 +60,9 @@ public class GradualIntervalConfigPane extends JPanel{ Component[][] components = getPaneComponents(minMaxValuePane, colorSelectBox, numberDragPane, legendGradientBar); //控件承载面板 - JPanel contentPane = TableLayout4VanChartHelper.createGapTableLayoutPane(components,row,col); + JPanel contentPane = TableLayout4VanChartHelper.createGapTableLayoutPane(components, row, col); this.setLayout(new BorderLayout()); - this.add(contentPane,BorderLayout.CENTER); + this.add(contentPane, BorderLayout.CENTER); } protected LegendGradientBar createLegendGradientBar() { @@ -81,7 +81,7 @@ public class GradualIntervalConfigPane extends JPanel{ }; } - public void populate(GradualIntervalConfig intervalConfig){ + public void populate(GradualIntervalConfig intervalConfig) { minMaxValuePane.populate(intervalConfig.getMinAndMaxValue()); colorSelectBox.setSelectObject(intervalConfig.getSubColor()); @@ -92,7 +92,7 @@ public class GradualIntervalConfigPane extends JPanel{ legendGradientBar.populate(intervalConfig); } - public void update(GradualIntervalConfig intervalConfig){ + public void update(GradualIntervalConfig intervalConfig) { minMaxValuePane.update(intervalConfig.getMinAndMaxValue()); intervalConfig.setSubColor(colorSelectBox.getSelectObject()); diff --git a/designer-chart/src/main/java/com/fr/van/chart/range/component/LegendGradientBar.java b/designer-chart/src/main/java/com/fr/van/chart/range/component/LegendGradientBar.java index 6096056a4b..c55e2a4923 100644 --- a/designer-chart/src/main/java/com/fr/van/chart/range/component/LegendGradientBar.java +++ b/designer-chart/src/main/java/com/fr/van/chart/range/component/LegendGradientBar.java @@ -44,14 +44,16 @@ public class LegendGradientBar extends JComponent implements ColorSelectable, UI private static final int REC_HEIGHT = 30; private static final int MAX_VERTICAL = 45; + //颜色选择器个数 private int colorSelectionBtnNum; //主题色 private Color subColor; - private int max = 150; + private static int max = 150; private int min = 4; + public static final int COLOR_GRADUAL_NUM_MAX = max / 5; //选中的颜色 private Color color; diff --git a/designer-chart/src/main/java/com/fr/van/chart/wordcloud/designer/style/VanChartWordCloudSeriesPane.java b/designer-chart/src/main/java/com/fr/van/chart/wordcloud/designer/style/VanChartWordCloudSeriesPane.java index 543b8139f6..29624a5867 100644 --- a/designer-chart/src/main/java/com/fr/van/chart/wordcloud/designer/style/VanChartWordCloudSeriesPane.java +++ b/designer-chart/src/main/java/com/fr/van/chart/wordcloud/designer/style/VanChartWordCloudSeriesPane.java @@ -14,6 +14,7 @@ import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayoutHelper; import com.fr.design.mainframe.backgroundpane.ImageBackgroundQuickPane; import com.fr.design.mainframe.chart.gui.ChartStylePane; +import com.fr.design.utils.DesignUtils; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.general.FRFont; import com.fr.general.IOUtils; @@ -94,7 +95,7 @@ public class VanChartWordCloudSeriesPane extends VanChartColorValueSeriesPane { double[] northC = {f, e}; double[] northR = {p, p}; - fontNameComboBox = new UIComboBox(Utils.getAvailableFontFamilyNames4Report()); + fontNameComboBox = new UIComboBox(DesignUtils.getAvailableFontFamilyNames4Report()); defineFontSize = new UIButtonGroup(new String[]{AUTO_FONT_SIZE, CUSTOM_FONT_SIZE}); Component[][] northComps = new Component[][]{ new Component[]{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Font")), fontNameComboBox}, diff --git a/designer-form/src/main/java/com/fr/design/designer/beans/models/ClipboardProvider.java b/designer-form/src/main/java/com/fr/design/designer/beans/models/ClipboardProvider.java new file mode 100644 index 0000000000..4382fc35f7 --- /dev/null +++ b/designer-form/src/main/java/com/fr/design/designer/beans/models/ClipboardProvider.java @@ -0,0 +1,18 @@ +package com.fr.design.designer.beans.models; + +public interface ClipboardProvider { + + /** + * 剪切到剪贴板 + * + * @param o 剪切对象 + */ + void cut2Clipboard(Object o); + + /** + * 复制到剪贴板 + * + * @param o 复制对象 + */ + void copy2Clipboard(Object o); +} diff --git a/designer-form/src/main/java/com/fr/design/designer/beans/models/DashboardClipboardManager.java b/designer-form/src/main/java/com/fr/design/designer/beans/models/DashboardClipboardManager.java new file mode 100644 index 0000000000..55cf2f12c7 --- /dev/null +++ b/designer-form/src/main/java/com/fr/design/designer/beans/models/DashboardClipboardManager.java @@ -0,0 +1,45 @@ +package com.fr.design.designer.beans.models; + +import java.util.ArrayList; +import java.util.List; + +/** + * 用来管理不同剪贴板,以及之间的数据同步 + */ +public class DashboardClipboardManager { + private static class Holder { + private static final DashboardClipboardManager HOLDER = new DashboardClipboardManager(); + } + + private static final List CLIPBOARD_LIST = new ArrayList<>(); + + + public void registerDashboardClipboard(ClipboardProvider clipboard) { + CLIPBOARD_LIST.add(clipboard); + } + + public void removeDashboardClipboard(ClipboardProvider clipboard) { + CLIPBOARD_LIST.remove(clipboard); + } + + public static DashboardClipboardManager getInstance() { + return Holder.HOLDER; + } + + private DashboardClipboardManager() { + } + + public void cut2Clipboard(Object o) { + for (ClipboardProvider clipboard : CLIPBOARD_LIST) { + //同步其他剪贴板 + clipboard.cut2Clipboard(o); + } + } + + public void copy2Clipboard(Object o) { + for (ClipboardProvider clipboard : CLIPBOARD_LIST) { + //同步其他剪贴板 + clipboard.copy2Clipboard(o); + } + } +} diff --git a/designer-form/src/main/java/com/fr/design/designer/beans/models/FormSelectionClipboard.java b/designer-form/src/main/java/com/fr/design/designer/beans/models/FormSelectionClipboard.java new file mode 100644 index 0000000000..a190532769 --- /dev/null +++ b/designer-form/src/main/java/com/fr/design/designer/beans/models/FormSelectionClipboard.java @@ -0,0 +1,45 @@ +package com.fr.design.designer.beans.models; + +import com.fr.design.mainframe.FormSelection; + +public class FormSelectionClipboard implements ClipboardProvider { + private static final FormSelection FRM_CLIPBOARD = new FormSelection(); + + static { + DashboardClipboardManager.getInstance().registerDashboardClipboard(FormSelectionClipboard.getInstance()); + } + + private static class Holder { + private static final FormSelectionClipboard HOLDER = new FormSelectionClipboard(); + } + + public static FormSelectionClipboard getInstance() { + return Holder.HOLDER; + } + + private FormSelectionClipboard() { + } + + + public boolean isEmpty() { + return FRM_CLIPBOARD.isEmpty(); + } + + public FormSelection getClipboard() { + return FRM_CLIPBOARD; + } + + @Override + public void cut2Clipboard(Object o) { + if (o instanceof FormSelection) { + ((FormSelection) o).cut2ClipBoard(FRM_CLIPBOARD); + } + } + + @Override + public void copy2Clipboard(Object o) { + if (o instanceof FormSelection) { + ((FormSelection) o).copy2ClipBoard(FRM_CLIPBOARD); + } + } +} diff --git a/designer-form/src/main/java/com/fr/design/designer/beans/models/SelectionModel.java b/designer-form/src/main/java/com/fr/design/designer/beans/models/SelectionModel.java index f75e08d723..807325a3b4 100644 --- a/designer-form/src/main/java/com/fr/design/designer/beans/models/SelectionModel.java +++ b/designer-form/src/main/java/com/fr/design/designer/beans/models/SelectionModel.java @@ -46,12 +46,14 @@ public class SelectionModel { //被粘贴组件在所选组件位置处往下、往右各错开20像素。执行多次粘贴时,在上一次粘贴的位置处错开20像素。 private static final int DELTA_X_Y = 20; //粘贴时候的偏移距离 private static final double OFFSET_RELATIVE = 0.80; - private static FormSelection clipboard = new FormSelection(); + private static FormSelectionClipboard formClipboard = FormSelectionClipboard.getInstance(); private FormDesigner designer; private FormSelection selection; private Rectangle hotspotBounds; private FormWidgetOptionProvider provider; + + public SelectionModel(FormDesigner designer) { this.designer = designer; selection = new FormSelection(); @@ -71,7 +73,7 @@ public class SelectionModel { * @return 是否为空 */ public static boolean isEmpty() { - return clipboard.isEmpty(); + return formClipboard.isEmpty(); } /** @@ -161,7 +163,7 @@ public class SelectionModel { if (hasSelectionComponent()) { FormSelection cutSelection = ClipboardFilter.cut(selection); if (cutSelection != null) { - cutSelection.cut2ClipBoard(clipboard); + DashboardClipboardManager.getInstance().cut2Clipboard(cutSelection); designer.getEditListenerTable().fireCreatorModified(DesignerEvent.CREATOR_CUTED); setSelectedCreator(hasSelectedParaComponent() ? designer.getParaComponent() : designer.getRootComponent()); designer.repaint(); @@ -192,7 +194,7 @@ public class SelectionModel { if (!selection.isEmpty()) { FormSelection copySelection = ClipboardFilter.copy(selection); if (copySelection != null) { - copySelection.copy2ClipBoard(clipboard); + DashboardClipboardManager.getInstance().copy2Clipboard(copySelection); } } } @@ -203,7 +205,7 @@ public class SelectionModel { * @return 否 */ public boolean pasteFromClipBoard() { - FormSelection pasteSelection = ClipboardFilter.paste(clipboard); + FormSelection pasteSelection = ClipboardFilter.paste(formClipboard.getClipboard()); if (pasteSelection != null && !pasteSelection.isEmpty()) { if (!hasSelectedPasteSource()) { //未选 @@ -240,7 +242,7 @@ public class SelectionModel { //编辑器外面还有两层容器,使用designer.getRootComponent()获取到的是编辑器中层的容器,不是编辑器表层 //当前选择的就是编辑器表层 FormSelectionUtils.paste2Container(designer, (XLayoutContainer) selection.getSelectedCreator(), - clipboard, + formClipboard.getClipboard(), DELTA_X_Y, DELTA_X_Y); } @@ -248,7 +250,7 @@ public class SelectionModel { //cpt本地组件复用,编辑器就一层,是最底层,使用designer.getRootComponent()就可以获取到 //使用selection.getSelectedCreator()也应该是可以获取到的。 FormSelectionUtils.paste2Container(designer, designer.getRootComponent(), - clipboard, + formClipboard.getClipboard(), DELTA_X_Y, DELTA_X_Y); } @@ -266,7 +268,7 @@ public class SelectionModel { if (hasSelectedPasteSource()) { selectedPaste(); } else { - FormSelectionUtils.paste2Container(designer, container, clipboard, + FormSelectionUtils.paste2Container(designer, container, formClipboard.getClipboard(), rectangle.x + rectangle.width / 2, rectangle.y + DELTA_X_Y); } @@ -281,7 +283,7 @@ public class SelectionModel { selectedPaste(); } else { FormSelectionUtils.paste2Container(designer, designer.getRootComponent(), - clipboard, + formClipboard.getClipboard(), rectangle.x + rectangle.width / 2, rectangle.y + DELTA_X_Y); } @@ -314,13 +316,13 @@ public class SelectionModel { positionX = selectionRec.x - containerRec.x + selectionRec.width / 2; positionY = (int) (selectionRec.y - containerRec.y + selectionRec.height * OFFSET_RELATIVE); } - FormSelectionUtils.paste2Container(designer, container, clipboard, positionX, positionY); + FormSelectionUtils.paste2Container(designer, container, formClipboard.getClipboard(), positionX, positionY); } else if (container != null && selection.getSelectedCreator().getParent() instanceof XWAbsoluteLayout) { //绝对布局 Rectangle rec = selection.getSelctionBounds(); - FormSelectionUtils.paste2Container(designer, container, clipboard, rec.x + DELTA_X_Y, rec.y + DELTA_X_Y); + FormSelectionUtils.paste2Container(designer, container, formClipboard.getClipboard(), rec.x + DELTA_X_Y, rec.y + DELTA_X_Y); } else if (isExtraContainer(container)) { - provider.paste2Container(clipboard); + provider.paste2Container(formClipboard.getClipboard()); } } diff --git a/designer-form/src/main/java/com/fr/design/designer/creator/XCreatorUtils.java b/designer-form/src/main/java/com/fr/design/designer/creator/XCreatorUtils.java index 5e7807698a..1ebd19ec3d 100644 --- a/designer-form/src/main/java/com/fr/design/designer/creator/XCreatorUtils.java +++ b/designer-form/src/main/java/com/fr/design/designer/creator/XCreatorUtils.java @@ -19,6 +19,7 @@ import com.fr.design.designer.creator.cardlayout.XWCardTagLayout; import com.fr.design.designer.creator.cardlayout.XWCardTitleLayout; import com.fr.design.designer.creator.cardlayout.XWTabFitLayout; import com.fr.design.file.HistoryTemplateListCache; +import com.fr.design.fit.common.TemplateTool; import com.fr.design.fun.ChartWidgetOptionProvider; import com.fr.design.fun.FormWidgetOptionProvider; import com.fr.design.fun.ParameterWidgetOptionProvider; @@ -39,6 +40,7 @@ import com.fr.form.ui.ComboCheckBox; import com.fr.form.ui.DateEditor; import com.fr.form.ui.EditorHolder; import com.fr.form.ui.ElementCaseEditor; +import com.fr.form.ui.FieldEditor; import com.fr.form.ui.FileEditor; import com.fr.form.ui.FreeButton; import com.fr.form.ui.IframeEditor; @@ -47,10 +49,12 @@ import com.fr.form.ui.MultiFileEditor; import com.fr.form.ui.NameWidget; import com.fr.form.ui.NumberEditor; import com.fr.form.ui.Password; +import com.fr.form.ui.PictureWidget; import com.fr.form.ui.Radio; import com.fr.form.ui.RadioGroup; import com.fr.form.ui.TextArea; import com.fr.form.ui.TextEditor; +import com.fr.form.ui.ToggleButton; import com.fr.form.ui.TreeComboBoxEditor; import com.fr.form.ui.TreeEditor; import com.fr.form.ui.Widget; @@ -183,6 +187,7 @@ public class XCreatorUtils { objectMap.put(CardSwitchButton.class, XCardSwitchButton.class); objectMap.put(CardAddButton.class, XCardAddButton.class); objectMap.put(WidgetErrorMarker.class, ErrorCreator.class); + objectMap.put(PictureWidget.class, XPicture.class); } private static void reInitExtra() { @@ -236,14 +241,30 @@ public class XCreatorUtils { } public static XCreator createThemedXCreator(Widget widget) { + JTemplate template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); TemplateTheme theme = template.getTemplateTheme(); if (theme instanceof FormTheme) { widget = setupTemplateTheme(widget, true, (FormTheme) theme, TemplateThemeCompatible.NONE); } + if (TemplateTool.isCurrentEditingNewJForm()){ + resetWidgetDefaultProperty(widget); + } return createXCreator(widget); } + /** + * 新表单下控件的字体默认都为9pt + * @param widget 控件 + */ + private static void resetWidgetDefaultProperty(Widget widget) { + if (widget.acceptType(FieldEditor.class)) { + ((FieldEditor) widget).setFontSize(Widget.DEFAULT_FONT_PT_SIZE); + } else if (widget.acceptType(ToggleButton.class)) { + ((ToggleButton) widget).setFontSize(Widget.DEFAULT_FONT_PT_SIZE); + } + } + /** * 创建creator * diff --git a/designer-form/src/main/java/com/fr/design/designer/creator/XElementCase.java b/designer-form/src/main/java/com/fr/design/designer/creator/XElementCase.java index 6b452bd08d..d1198d6094 100644 --- a/designer-form/src/main/java/com/fr/design/designer/creator/XElementCase.java +++ b/designer-form/src/main/java/com/fr/design/designer/creator/XElementCase.java @@ -51,7 +51,6 @@ public class XElementCase extends XBorderStyleWidgetCreator implements FormEleme public XElementCase(ElementCaseEditor widget, Dimension initSize) { super(widget, initSize); - widget.getElementCaseImage().adjustImageSize(initSize.width, initSize.height, false); } protected void initXCreatorProperties() { diff --git a/designer-form/src/main/java/com/fr/design/designer/creator/XPicture.java b/designer-form/src/main/java/com/fr/design/designer/creator/XPicture.java new file mode 100644 index 0000000000..7dd23bd4ce --- /dev/null +++ b/designer-form/src/main/java/com/fr/design/designer/creator/XPicture.java @@ -0,0 +1,74 @@ +package com.fr.design.designer.creator; + +import com.fr.design.designer.ui.ImgPanel; +import com.fr.design.i18n.Toolkit; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.mainframe.widget.editors.PictureEditor; +import com.fr.design.mainframe.widget.editors.UrlLinkEditor; +import com.fr.design.mainframe.widget.renderer.PictureRenderer; +import com.fr.design.mainframe.widget.renderer.UrlLinkRenderer; +import com.fr.form.ui.PictureWidget; +import com.fr.general.IOUtils; +import com.fr.stable.ArrayUtils; +import java.awt.Dimension; +import java.awt.Image; +import java.beans.IntrospectionException; +import javax.swing.JComponent; + +/** +* +*

图片控件的creator

+* +* @author Jimmy.Zheng created on 2022/8/11 21:16 +**/ +public class XPicture extends XWidgetCreator { + + public XPicture(PictureWidget widget, Dimension dimension) { + super(widget, dimension); + } + + @Override + protected String getIconName() { + return "picture_widget_16.png"; + } + + @Override + public CRPropertyDescriptor[] supportedDescriptor() throws IntrospectionException { + return (CRPropertyDescriptor[]) ArrayUtils.addAll(super.supportedDescriptor(), new CRPropertyDescriptor[]{ + new CRPropertyDescriptor("picUrl", toData().getClass()) + .setI18NName(Toolkit.i18nText("Fine-Design_Basic_Widget_Type_Image")) + .setEditorClass(PictureEditor.class) + .setRendererClass(PictureRenderer.class) + .putKeyValue("category", "Fine-Design_Basic_Advanced"), + new CRPropertyDescriptor("urlLink", toData().getClass()) + .setI18NName(Toolkit.i18nText("Fine-Design_Basic_Hyperlink")) + .setEditorClass(UrlLinkEditor.class) + .setRendererClass(UrlLinkRenderer.class) + .putKeyValue( + "category", "Fine-Design_Basic_Advanced")}); + } + + @Override + protected JComponent initEditor() { + PictureWidget pictureWidget = (PictureWidget) this.data; + if (this.editor == null) { + this.editor = FRGUIPaneFactory.createBorderLayout_S_Pane(); + Object value = pictureWidget.getPicUrl().getValue(); + ImgPanel imgPanel = new ImgPanel(); + if (value instanceof Image) { + imgPanel.setBackgroundImage((Image) value); + imgPanel.setImageDisplayMode(pictureWidget.getShowType()); + } else { + imgPanel.setBackgroundImage(IOUtils.readImage("com/fr/design/images/form/designer/widget/picture_widget_designer_bg.png")); + imgPanel.setImageDisplayMode(0); + } + this.editor.add(imgPanel, "Center"); + } + return this.editor; + } + + @Override + public boolean canEnterIntoParaPane() { + return false; + } +} diff --git a/designer-form/src/main/java/com/fr/design/designer/ui/ImgPanel.java b/designer-form/src/main/java/com/fr/design/designer/ui/ImgPanel.java new file mode 100644 index 0000000000..1c17c56c34 --- /dev/null +++ b/designer-form/src/main/java/com/fr/design/designer/ui/ImgPanel.java @@ -0,0 +1,113 @@ +package com.fr.design.designer.ui; + +import com.fr.general.ImageWithSuffix; +import com.fr.stable.Constants; +import java.awt.Graphics; +import java.awt.Image; +import javax.swing.JComponent; + + +/** + *

图片控件中的已选图片展示面板

+ * + * @author Jimmy.Zheng created on 2022/8/11 21:17 + **/ +public class ImgPanel extends JComponent { + private static final long serialVersionUID = 1L; + private Image backgroundImage; + private int imageDisplayMode; + private int modeIndex; + + public ImgPanel() { + this(null, 0); + } + + public ImgPanel(Image image, int modeName) { + setBackgroundImage(image); + setImageDisplayMode(modeName); + } + + public Image getBackgroundImage() { + return this.backgroundImage; + } + + public void setBackgroundImage(Image image) { + this.backgroundImage = image; + repaint(); + } + + public int getImageDisplayMode() { + return this.imageDisplayMode; + } + + public void setImageDisplayMode(int modeName) { + switch (modeName) { + case Constants.IMAGE_CENTER: + this.modeIndex = 0; + break; + case Constants.IMAGE_TILED: + this.imageDisplayMode = 0; + this.modeIndex = 1; + break; + case Constants.IMAGE_EXTEND: + this.imageDisplayMode = 2; + this.modeIndex = 2; + break; + case Constants.IMAGE_ADJUST: + this.imageDisplayMode = 4; + this.modeIndex = 3; + break; + default: + } + repaint(); + } + + @Override + protected void paintComponent(Graphics g) { + super.paintComponent(g); + + if (this.backgroundImage != null) { + if (this.backgroundImage instanceof ImageWithSuffix) { + this.backgroundImage = ((ImageWithSuffix) backgroundImage).getImage(); + } + int width = getWidth(); + int height = getHeight(); + int imageWidth = this.backgroundImage.getWidth(this); + int imageHeight = this.backgroundImage.getHeight(this); + + switch (this.modeIndex) { + case 0: + int x = (width - imageWidth) / 2; + int y = (height - imageHeight) / 2; + g.drawImage(this.backgroundImage, x, y, this); + break; + case 1: + for (int ix = 0; ix < width; ix += imageWidth) { + for (int iy = 0; iy < height; iy += imageHeight) { + g.drawImage(this.backgroundImage, ix, iy, this); + } + } + + break; + case 2: + g.drawImage(this.backgroundImage, 0, 0, width, height, this); + break; + case 3: + double sx = 1.0 * width / imageWidth; + double sy = 1.0 * height / imageHeight; + + if (sx > sy) { + sx = sy; + width = (int) (sx * imageWidth); + } else { + sy = sx; + height = (int) (sy * imageHeight); + } + int xx = (getWidth() - width) / 2; + int yy = (getHeight() - height) / 2; + g.drawImage(this.backgroundImage, xx, yy, width, height, this); + default: + } + } + } +} diff --git a/designer-form/src/main/java/com/fr/design/fit/common/TemplateTool.java b/designer-form/src/main/java/com/fr/design/fit/common/TemplateTool.java index 47512348f4..04633435be 100644 --- a/designer-form/src/main/java/com/fr/design/fit/common/TemplateTool.java +++ b/designer-form/src/main/java/com/fr/design/fit/common/TemplateTool.java @@ -1,7 +1,7 @@ package com.fr.design.fit.common; import com.fr.design.file.HistoryTemplateListCache; -import com.fr.design.file.MutilTempalteTabPane; +import com.fr.design.file.MultiTemplateTabPane; import com.fr.design.fit.NewJForm; import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.JTemplate; @@ -86,7 +86,7 @@ public class TemplateTool { JTemplate oldJTemplate = jTemplateList.get(i); if (oldJTemplate != null && ComparatorUtils.equals(oldJTemplate.getEditingFILE(), newJTemplate.getEditingFILE())) { jTemplateList.set(i, newJTemplate); - MutilTempalteTabPane.getInstance().refreshOpenedTemplate(jTemplateList); + MultiTemplateTabPane.getInstance().refreshOpenedTemplate(jTemplateList); return; } } diff --git a/designer-form/src/main/java/com/fr/design/fit/menupane/FitRadioGroup.java b/designer-form/src/main/java/com/fr/design/fit/menupane/FitRadioGroup.java index 46fb327686..70bf18fd69 100644 --- a/designer-form/src/main/java/com/fr/design/fit/menupane/FitRadioGroup.java +++ b/designer-form/src/main/java/com/fr/design/fit/menupane/FitRadioGroup.java @@ -77,4 +77,12 @@ public class FitRadioGroup extends ButtonGroup { } } + /** + * + * @return 被选中的按钮 + */ + public UIRadioButton getSelectedButton() { + return radioButtons.get(this.getSelectRadioIndex()); + } + } diff --git a/designer-form/src/main/java/com/fr/design/fun/WidgetAdvancedPaneProvider.java b/designer-form/src/main/java/com/fr/design/fun/WidgetAdvancedPaneProvider.java new file mode 100644 index 0000000000..eafa70b239 --- /dev/null +++ b/designer-form/src/main/java/com/fr/design/fun/WidgetAdvancedPaneProvider.java @@ -0,0 +1,42 @@ +package com.fr.design.fun; + +import com.fr.design.beans.BasicBeanPane; +import com.fr.design.designer.creator.XCreator; +import com.fr.stable.fun.mark.Mutable; + +/** + * 设计器控件的属性设置下“高级”设置项扩展,支持追加设置项 + * + * @author Bruce.Deng + * @version 11.0 + * Created by Bruce.Deng on 2023/2/15 + */ +public interface WidgetAdvancedPaneProvider extends Mutable { + + String XML_TAG = "WidgetAdvancedPaneProvider"; + + int CURRENT_LEVEL = 1; + + /** + * 获取插入的位置 + * + * @param total 已插入的面板数 + * @return 插入位置,如果想放到最后,则返回-1 + */ + int getInsertPosition(int total); + + /** + * 根据XCreator判断是否需要处理 + * + * @param creator + * @return true:需要处理;false:不处理 + */ + boolean accept(XCreator creator); + + /** + * 创建控件高级设置项的追加面板 + * + * @return 高级设置项追加面板 + */ + BasicBeanPane createExtraAdvancedPane(); +} diff --git a/designer-form/src/main/java/com/fr/design/fun/impl/AbstractWidgetAdvancedPaneProvider.java b/designer-form/src/main/java/com/fr/design/fun/impl/AbstractWidgetAdvancedPaneProvider.java new file mode 100644 index 0000000000..6b60eb56a8 --- /dev/null +++ b/designer-form/src/main/java/com/fr/design/fun/impl/AbstractWidgetAdvancedPaneProvider.java @@ -0,0 +1,26 @@ +package com.fr.design.fun.impl; + +import com.fr.design.fun.WidgetAdvancedPaneProvider; +import com.fr.stable.fun.impl.AbstractProvider; +import com.fr.stable.fun.mark.API; + +/** + * @author Bruce.Deng + * @version 11.0 + * @see WidgetAdvancedPaneProvider + * Created by Bruce.Deng on 2023/2/15 + */ +@API(level = WidgetAdvancedPaneProvider.CURRENT_LEVEL) +public abstract class AbstractWidgetAdvancedPaneProvider extends AbstractProvider implements WidgetAdvancedPaneProvider { + + @Override + public int currentAPILevel() { + return CURRENT_LEVEL; + } + + @Override + public String mark4Provider() { + return getClass().getName(); + } + +} diff --git a/designer-form/src/main/java/com/fr/design/gui/xpane/CardTagLayoutBorderPane.java b/designer-form/src/main/java/com/fr/design/gui/xpane/CardTagLayoutBorderPane.java index fd0507c812..4d9d104abb 100644 --- a/designer-form/src/main/java/com/fr/design/gui/xpane/CardTagLayoutBorderPane.java +++ b/designer-form/src/main/java/com/fr/design/gui/xpane/CardTagLayoutBorderPane.java @@ -12,6 +12,7 @@ import com.fr.design.gui.style.FRFontPane; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayoutHelper; +import com.fr.design.utils.DesignUtils; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.form.ui.LayoutBorderStyle; @@ -32,7 +33,7 @@ public class CardTagLayoutBorderPane extends LayoutBorderPane { protected UIScrollPane initRightBottomPane(){ this.setFontSizeComboBox(new UIComboBox(FRFontPane.FONT_SIZES)); - this.setFontNameComboBox(new UIComboBox(Utils.getAvailableFontFamilyNames4Report())); + this.setFontNameComboBox(new UIComboBox(DesignUtils.getAvailableFontFamilyNames4Report())); JPanel fontSizeTypePane = new JPanel(new BorderLayout(10,0)); fontSizeTypePane.add(this.getFontSizeComboBox(), BorderLayout.CENTER); fontSizeTypePane.add(this.getFontNameComboBox(), BorderLayout.EAST); diff --git a/designer-form/src/main/java/com/fr/design/gui/xpane/LayoutBorderPane.java b/designer-form/src/main/java/com/fr/design/gui/xpane/LayoutBorderPane.java index 7a00075d61..5294687e33 100644 --- a/designer-form/src/main/java/com/fr/design/gui/xpane/LayoutBorderPane.java +++ b/designer-form/src/main/java/com/fr/design/gui/xpane/LayoutBorderPane.java @@ -33,6 +33,7 @@ import com.fr.design.layout.TableLayoutHelper; import com.fr.design.layout.VerticalFlowLayout; import com.fr.design.mainframe.JForm; import com.fr.design.mainframe.JTemplate; +import com.fr.design.utils.DesignUtils; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.form.ui.LayoutBorderStyle; import com.fr.form.ui.WidgetTitle; @@ -437,7 +438,7 @@ public class LayoutBorderPane extends BasicPane { protected UIScrollPane initRightBottomPane(){ formulaPane = new TinyFormulaPane(); fontSizeComboBox = new UIComboBox(FRFontPane.FONT_SIZES); - fontNameComboBox = new UIComboBox(Utils.getAvailableFontFamilyNames4Report()); + fontNameComboBox = new UIComboBox(DesignUtils.getAvailableFontFamilyNames4Report()); fontNameComboBox.setPreferredSize(new Dimension(160, 30)); JPanel fontSizeTypePane = new JPanel(new BorderLayout(10,0)); fontSizeTypePane.add(fontSizeComboBox, BorderLayout.CENTER); diff --git a/designer-form/src/main/java/com/fr/design/mainframe/JForm.java b/designer-form/src/main/java/com/fr/design/mainframe/JForm.java index a142ee297c..4e9c45ce44 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/JForm.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/JForm.java @@ -6,8 +6,6 @@ import com.fr.base.Parameter; import com.fr.base.Releasable; import com.fr.base.extension.FileExtension; import com.fr.base.iofile.attr.ExtendSharableAttrMark; -import com.fr.base.theme.FineColorGather; -import com.fr.base.theme.FineColorManager; import com.fr.base.theme.FineColorSynchronizer; import com.fr.base.theme.FormTheme; import com.fr.base.theme.TemplateTheme; @@ -17,8 +15,8 @@ import com.fr.base.vcs.DesignerMode; import com.fr.design.DesignModelAdapter; import com.fr.design.DesignState; import com.fr.design.DesignerEnvManager; -import com.fr.design.actions.FormMobileAttrAction; import com.fr.design.actions.FormECParallelCalAction; +import com.fr.design.actions.FormMobileAttrAction; import com.fr.design.actions.TemplateParameterAction; import com.fr.design.actions.core.WorkBookSupportable; import com.fr.design.actions.file.export.EmbeddedFormExportExportAction; @@ -56,8 +54,8 @@ import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.mainframe.form.FormECCompositeProvider; import com.fr.design.mainframe.form.FormECDesignerProvider; import com.fr.design.mainframe.reuse.ComponentReuseNotificationInfo; -import com.fr.design.mainframe.share.collect.ComponentCollector; import com.fr.design.mainframe.share.ComponentShareUtil; +import com.fr.design.mainframe.share.collect.ComponentCollector; import com.fr.design.mainframe.template.info.JFormProcessInfo; import com.fr.design.mainframe.template.info.TemplateProcessInfo; import com.fr.design.mainframe.theme.dialog.TemplateThemeUsingDialog; @@ -71,7 +69,6 @@ import com.fr.design.parameter.ParameterPropertyPane; import com.fr.design.preview.FormPreview; import com.fr.design.preview.MobilePreview; import com.fr.design.roleAuthority.RolesAlreadyEditedPane; -import com.fr.design.ui.util.UIUtil; import com.fr.design.utils.gui.LayoutUtils; import com.fr.file.FILE; import com.fr.file.FILEChooserPane; @@ -110,7 +107,14 @@ import javax.swing.JComponent; import javax.swing.JPanel; import javax.swing.SwingConstants; import javax.swing.tree.TreePath; -import java.awt.*; +import java.awt.BorderLayout; +import java.awt.CardLayout; +import java.awt.Color; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.Insets; +import java.awt.Rectangle; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.image.BufferedImage; @@ -704,8 +708,8 @@ public class JForm extends JTemplate implements BaseJForm implements BaseJForm implements BaseJForm图片控件的图片选择、编辑器

+* +* @author Jimmy.Zheng created on 2022/8/11 21:13 +**/ +public class AccessiblePictureModelEditor extends UneditableAccessibleEditor { + protected FloatElement element = new FloatElement(); + private PictureWidget pic; + + public AccessiblePictureModelEditor(PictureWidget pic) { + super(new PictureModelWrapper()); + this.pic = pic; + } + + @Override + public FloatElement getValue() { + return (FloatElement) super.getValue(); + } + + @Override + protected void showEditorPane() { + final SelectImagePane imageEditorPane = new SelectImagePane(); + if (super.getValue() != null) { + this.element = ((FloatElement) super.getValue()); + } + this.element.setStyle(Style.getInstance().deriveImageLayout(this.pic.getShowType())); + imageEditorPane.populate(this.element); + final Object oldValue = this.element.getValue(); + final Style oldStyle = this.element.getStyle(); + final String oldname = this.element.getName(); + imageEditorPane.showWindow(DesignerContext.getDesignerFrame(), new DialogActionAdapter() { + @Override + public void doOk() { + CellImage cellImage = imageEditorPane.update(); + if ((!ComparatorUtils.equals(cellImage.getImage(), oldValue)) || (!ComparatorUtils.equals(cellImage.getStyle(), oldStyle))) { + AccessiblePictureModelEditor.this.element.setValue(cellImage.getImage()); + AccessiblePictureModelEditor.this.element.setStyle(cellImage.getStyle()); + AccessiblePictureModelEditor.this.element.setName(imageEditorPane.getSelectedImage() == null ? oldname : imageEditorPane.getSelectedImage().toString()); + AccessiblePictureModelEditor.this.setValue(AccessiblePictureModelEditor.this.element); + AccessiblePictureModelEditor.this.pic.setShowType(cellImage.getStyle().getImageLayout()); + AccessiblePictureModelEditor.this.pic.setPicUrl(element); + ImgPanel p = AccessiblePictureModelEditor.this.getCurrentImgPanel(); + p.setBackgroundImage(cellImage.getBufferImage()); + p.setImageDisplayMode(cellImage.getStyle().getImageLayout()); + AccessiblePictureModelEditor.this.fireStateChanged(); + DesignModelAdapter d = DesignModelAdapter.getCurrentModelAdapter(); + d.fireTargetModified(); + } + } + }).setVisible(true); + } + + private ImgPanel getCurrentImgPanel() { + XPicture xPicture = (XPicture) WidgetPropertyPane.getInstance().getEditingFormDesigner().getSelectionModel().getSelection().getSelectedCreator(); + JComponent editor = (JComponent) xPicture.getComponent(0); + return (ImgPanel) editor.getComponent(0); + } +} \ No newline at end of file diff --git a/designer-form/src/main/java/com/fr/design/mainframe/widget/accessibles/AccessibleUrlLinkModelEditor.java b/designer-form/src/main/java/com/fr/design/mainframe/widget/accessibles/AccessibleUrlLinkModelEditor.java new file mode 100644 index 0000000000..2dd4b54991 --- /dev/null +++ b/designer-form/src/main/java/com/fr/design/mainframe/widget/accessibles/AccessibleUrlLinkModelEditor.java @@ -0,0 +1,57 @@ +package com.fr.design.mainframe.widget.accessibles; + +import com.fr.design.DesignModelAdapter; +import com.fr.design.dialog.BasicDialog; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.design.gui.frpane.HyperlinkGroupPaneActionProvider; +import com.fr.design.gui.xpane.FormHyperlinkGroupPane; +import com.fr.design.mainframe.DesignerContext; +import com.fr.design.mainframe.widget.wrappers.UrlLinkModelWrapper; +import com.fr.js.NameJavaScriptGroup; +import com.fr.stable.bridge.StableFactory; + +/** + *

表单图片控件的链接编辑器

+ * @author Jimmy + */ +public class AccessibleUrlLinkModelEditor extends UneditableAccessibleEditor { + private FormHyperlinkGroupPane hyperlinkPane; + + public AccessibleUrlLinkModelEditor() { + super(new UrlLinkModelWrapper()); + } + /** + * 原插件使用 + *

DesignerContext.getDesignerFrame().getSelectedJTemplate().getHyperLinkPaneNoPop( + * HyperlinkGroupPaneActionImpl.getInstance()));

获取{@see this.hyperlinkPane} + * 合并插件依赖不到,换种方式 用{@see DesignerActivator将实例注册了} + */ + @Override + protected void showEditorPane() { + if (this.hyperlinkPane == null) { + HyperlinkGroupPaneActionProvider hyperlinkGroupPaneActionProvider = StableFactory.getMarkedInstanceObjectFromClass(HyperlinkGroupPaneActionProvider.XML_TAG,HyperlinkGroupPaneActionProvider.class); + this.hyperlinkPane = (FormHyperlinkGroupPane) DesignerContext.getDesignerFrame().getSelectedJTemplate().getHyperLinkPaneNoPop( + hyperlinkGroupPaneActionProvider); + } + BasicDialog dialog = this.hyperlinkPane.showWindow(DesignerContext.getDesignerFrame()); + dialog.addDialogActionListener(new DialogActionAdapter() { + @Override + public void doOk() { + super.doOk(); + NameJavaScriptGroup hyperlinks = AccessibleUrlLinkModelEditor.this.hyperlinkPane.updateJSGroup(); + AccessibleUrlLinkModelEditor.this.setValue(hyperlinks); + AccessibleUrlLinkModelEditor.this.fireStateChanged(); + DesignModelAdapter d = DesignModelAdapter.getCurrentModelAdapter(); + d.fireTargetModified(); + } + }); + this.hyperlinkPane.populate(getValue()); + + dialog.setVisible(true); + } + + @Override + public NameJavaScriptGroup getValue() { + return (NameJavaScriptGroup) super.getValue(); + } +} diff --git a/designer-form/src/main/java/com/fr/design/mainframe/widget/editors/PictureEditor.java b/designer-form/src/main/java/com/fr/design/mainframe/widget/editors/PictureEditor.java new file mode 100644 index 0000000000..c7bbff80a3 --- /dev/null +++ b/designer-form/src/main/java/com/fr/design/mainframe/widget/editors/PictureEditor.java @@ -0,0 +1,17 @@ +package com.fr.design.mainframe.widget.editors; + +import com.fr.design.mainframe.widget.accessibles.AccessiblePictureModelEditor; +import com.fr.design.mainframe.widget.accessibles.AccessiblePropertyEditor; +import com.fr.form.ui.PictureWidget; +/** +* +*

图片控件的图片选择、编辑器

+* +* @author Jimmy.Zheng created on 2022/8/11 21:15 +**/ +public class PictureEditor extends AccessiblePropertyEditor { + + public PictureEditor(Object o) { + super(new AccessiblePictureModelEditor((PictureWidget) o)); + } +} diff --git a/designer-form/src/main/java/com/fr/design/mainframe/widget/editors/UrlLinkEditor.java b/designer-form/src/main/java/com/fr/design/mainframe/widget/editors/UrlLinkEditor.java new file mode 100644 index 0000000000..195e8f5250 --- /dev/null +++ b/designer-form/src/main/java/com/fr/design/mainframe/widget/editors/UrlLinkEditor.java @@ -0,0 +1,17 @@ +package com.fr.design.mainframe.widget.editors; + +import com.fr.design.mainframe.widget.accessibles.AccessiblePropertyEditor; +import com.fr.design.mainframe.widget.accessibles.AccessibleUrlLinkModelEditor; + +/** +* +*

图片控件的链接编辑器

+* +* @author Jimmy.Zheng created on 2022/8/11 21:19 +**/ +public class UrlLinkEditor extends AccessiblePropertyEditor { + + public UrlLinkEditor() { + super(new AccessibleUrlLinkModelEditor()); + } +} \ No newline at end of file diff --git a/designer-form/src/main/java/com/fr/design/mainframe/widget/renderer/PictureRenderer.java b/designer-form/src/main/java/com/fr/design/mainframe/widget/renderer/PictureRenderer.java new file mode 100644 index 0000000000..82fcc85b43 --- /dev/null +++ b/designer-form/src/main/java/com/fr/design/mainframe/widget/renderer/PictureRenderer.java @@ -0,0 +1,15 @@ +package com.fr.design.mainframe.widget.renderer; + +import com.fr.design.mainframe.widget.wrappers.PictureModelWrapper; + +/** + *

图片控件的图片编辑器的EncoderCellRenderer

+ * + * @author Jimmy.Zheng created on 2022/8/11 21:29 + **/ +public class PictureRenderer extends EncoderCellRenderer { + + public PictureRenderer() { + super(new PictureModelWrapper()); + } +} diff --git a/designer-form/src/main/java/com/fr/design/mainframe/widget/renderer/UrlLinkRenderer.java b/designer-form/src/main/java/com/fr/design/mainframe/widget/renderer/UrlLinkRenderer.java new file mode 100644 index 0000000000..a81187d2d5 --- /dev/null +++ b/designer-form/src/main/java/com/fr/design/mainframe/widget/renderer/UrlLinkRenderer.java @@ -0,0 +1,16 @@ +package com.fr.design.mainframe.widget.renderer; + + +import com.fr.design.mainframe.widget.wrappers.UrlLinkModelWrapper; + +/** + *

图片控件的链接编辑器的EncoderCellRenderer

+ * + * @author Jimmy.Zheng created on 2022/8/11 21:29 + **/ +public class UrlLinkRenderer extends EncoderCellRenderer { + + public UrlLinkRenderer() { + super(new UrlLinkModelWrapper()); + } +} \ No newline at end of file diff --git a/designer-form/src/main/java/com/fr/design/mainframe/widget/ui/FormSingleWidgetCardPane.java b/designer-form/src/main/java/com/fr/design/mainframe/widget/ui/FormSingleWidgetCardPane.java index 81e3a53641..98c539f278 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/widget/ui/FormSingleWidgetCardPane.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/widget/ui/FormSingleWidgetCardPane.java @@ -28,9 +28,11 @@ import com.fr.design.widget.Operator; import com.fr.design.widget.ui.designer.component.WidgetAbsoluteBoundPane; import com.fr.design.widget.ui.designer.component.WidgetBoundPane; import com.fr.design.widget.ui.designer.component.WidgetCardTagBoundPane; +import com.fr.form.main.WidgetUtil; import com.fr.form.ui.ChartEditor; import com.fr.form.ui.Widget; import com.fr.form.ui.container.WScaleLayout; +import com.fr.form.ui.container.WSortLayout; import com.fr.form.ui.container.WTitleLayout; import com.fr.form.ui.widget.CRBoundsWidget; import com.fr.general.ComparatorUtils; @@ -241,7 +243,12 @@ public class FormSingleWidgetCardPane extends FormWidgetCardPane { showNameInvalidDialog(Toolkit.i18nText("Fine-Design_Form_Chart_Widget_Rename_Failure")); return; } + String oldName = widget.getWidgetName(); widgetPropertyPane.update(widget); + Widget innerWidget = WidgetUtil.getInnerWidget(widget); + if (!StringUtils.equals(oldName, innerWidget.getWidgetName())) { + innerWidget.setMobileOldWidgetName(oldName); + } // 上面一行更新了组件 这里必须重新调用getWidgetName xCreator.resetCreatorName(widget.getWidgetName()); xCreator.resetVisible(widget.isVisible()); diff --git a/designer-form/src/main/java/com/fr/design/mainframe/widget/wrappers/PictureModelWrapper.java b/designer-form/src/main/java/com/fr/design/mainframe/widget/wrappers/PictureModelWrapper.java new file mode 100644 index 0000000000..ed9fd0a4ac --- /dev/null +++ b/designer-form/src/main/java/com/fr/design/mainframe/widget/wrappers/PictureModelWrapper.java @@ -0,0 +1,34 @@ +package com.fr.design.mainframe.widget.wrappers; + +import com.fr.design.Exception.ValidationException; +import com.fr.design.designer.properties.Decoder; +import com.fr.design.designer.properties.Encoder; +import com.fr.report.cell.FloatElement; +import com.fr.stable.StringUtils; + +/** + *

图片选择器 {@link com.fr.design.mainframe.widget.accessibles.AccessiblePictureModelEditor}的 Wrapper

+ *

插件中直接移入,未作改动

+ * + * @author Jimmy.Zheng created on 2022/8/11 21:25 + **/ +public class PictureModelWrapper implements Encoder, Decoder { + + @Override + public FloatElement decode(String txt) { + return null; + } + + @Override + public void validate(String txt) throws ValidationException { + // do nothing + } + + @Override + public String encode(FloatElement v) { + if (v != null) { + return v.getName(); + } + return StringUtils.EMPTY; + } +} diff --git a/designer-form/src/main/java/com/fr/design/mainframe/widget/wrappers/UrlLinkModelWrapper.java b/designer-form/src/main/java/com/fr/design/mainframe/widget/wrappers/UrlLinkModelWrapper.java new file mode 100644 index 0000000000..a892065ad7 --- /dev/null +++ b/designer-form/src/main/java/com/fr/design/mainframe/widget/wrappers/UrlLinkModelWrapper.java @@ -0,0 +1,33 @@ +package com.fr.design.mainframe.widget.wrappers; + +import com.fr.design.Exception.ValidationException; +import com.fr.design.designer.properties.Decoder; +import com.fr.design.designer.properties.Encoder; +import com.fr.js.NameJavaScriptGroup; + +/** + *

链接选择器 {@link com.fr.design.mainframe.widget.accessibles.AccessibleUrlLinkModelEditor}的 Wrapper

+ *

插件中直接移入,未作改动

+ * + * @author Jimmy.Zheng created on 2022/8/11 21:28 + **/ +public class UrlLinkModelWrapper implements Encoder, Decoder { + + @Override + public NameJavaScriptGroup decode(String txt) { + return null; + } + + @Override + public void validate(String txt) throws ValidationException { + // do nothing + } + + @Override + public String encode(NameJavaScriptGroup v) { + if (v.size() > 0) { + return v.getNameHyperlink(0).getName(); + } + return null; + } +} \ No newline at end of file diff --git a/designer-form/src/main/java/com/fr/design/parameter/RootDesignDefinePane.java b/designer-form/src/main/java/com/fr/design/parameter/RootDesignDefinePane.java index 910b466f79..86e3f49986 100644 --- a/designer-form/src/main/java/com/fr/design/parameter/RootDesignDefinePane.java +++ b/designer-form/src/main/java/com/fr/design/parameter/RootDesignDefinePane.java @@ -2,6 +2,7 @@ package com.fr.design.parameter; import com.fr.base.BaseUtils; import com.fr.design.ExtraDesignClassManager; +import com.fr.design.beans.BasicBeanPane; import com.fr.design.data.DataCreatorUI; import com.fr.design.designer.IntervalConstants; import com.fr.design.designer.creator.CRPropertyDescriptor; @@ -13,6 +14,7 @@ import com.fr.design.file.HistoryTemplateListPane; import com.fr.design.fit.common.TemplateTool; import com.fr.design.foldablepane.UIExpandablePane; import com.fr.design.fun.ParameterExpandablePaneUIProvider; +import com.fr.design.fun.WidgetAdvancedPaneProvider; import com.fr.design.gui.ibutton.UIButtonGroup; import com.fr.design.gui.icheckbox.UICheckBox; import com.fr.design.gui.ilable.UILabel; @@ -32,6 +34,9 @@ import com.fr.design.widget.ui.designer.AbstractDataModify; import com.fr.design.widget.ui.designer.component.UIBoundSpinner; import com.fr.form.ui.container.WParameterLayout; import com.fr.general.Background; +import com.fr.general.GeneralContext; +import com.fr.plugin.observer.PluginEvent; +import com.fr.plugin.observer.PluginEventListener; import com.fr.report.stable.FormConstants; import javax.swing.BorderFactory; @@ -41,6 +46,8 @@ import javax.swing.JPanel; import java.awt.BorderLayout; import java.awt.Component; import java.awt.Rectangle; +import java.util.ArrayList; +import java.util.List; import java.util.Set; /** @@ -59,6 +66,8 @@ public class RootDesignDefinePane extends AbstractDataModify { //是否是新设计模式下决策报表 private boolean newForm; private PropertyGroupPane extraPropertyGroupPane; + protected final List> extraPaneList = new ArrayList<>(); + private JPanel backgroundPane; public RootDesignDefinePane(XCreator xCreator) { super(xCreator); @@ -134,7 +143,7 @@ public class RootDesignDefinePane extends AbstractDataModify { displayReport = new UICheckBox(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Display_Nothing_Before_Query")); UIComponentUtils.setLineWrap(displayReport); useParamsTemplate = new UICheckBox(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Use_Params_Template")); - fireAfterEditor = new UICheckBox(com.fr.design.i18n.Toolkit.i18nText("触发编辑结束事件")); + fireAfterEditor = new UICheckBox(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Trigger_Editing_End_Event")); fireAfterEditor.setEnabled(false); fireAfterEditor.setBorder(BorderFactory.createEmptyBorder(0, 30, 0, 0)); useParamsTemplate.addChangeListener(e -> { @@ -144,7 +153,6 @@ public class RootDesignDefinePane extends AbstractDataModify { fireAfterEditor.setSelected(false); } }); - background = new AccessibleBackgroundEditor(); Icon[] hAlignmentIconArray = {BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/h_left_normal.png"), BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/h_center_normal.png"), BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/h_right_normal.png"),}; @@ -152,6 +160,8 @@ public class RootDesignDefinePane extends AbstractDataModify { hAlignmentPane = new UIButtonGroup(hAlignmentIconArray, hAlignment); hAlignmentPane.setAllToolTips(new String[]{com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_StyleAlignment_Left") , com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_StyleAlignment_Center"), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_StyleAlignment_Right")}); + backgroundPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); + this.initExtraPane(); double f = TableLayout.FILL; double p = TableLayout.PREFERRED; double[] rowSize = {p, p, p, p, p, p}; @@ -159,7 +169,7 @@ public class RootDesignDefinePane extends AbstractDataModify { int[][] rowCount = {{1, 1}, {1, 1}, {1, 1}, {1, 1}, {1, 1}, {1, 1}}; Component[][] components = new Component[][]{ new Component[]{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Label_Name")), labelNameTextField}, - new Component[]{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Base_Background")), background}, + new Component[]{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Base_Background")), backgroundPane}, new Component[]{displayReport, null}, new Component[]{useParamsTemplate, null}, new Component[]{fireAfterEditor, null}, @@ -176,6 +186,54 @@ public class RootDesignDefinePane extends AbstractDataModify { return jPanel; } + private void initExtraPane() { + initPluginListener(); + refreshExtraAdvancedPane(); + } + + private void initPluginListener() { + GeneralContext.listenPluginRunningChanged(new PluginEventListener() { + @Override + public void on(PluginEvent event) { + refreshExtraAdvancedPane(); + } + }, pluginContext -> pluginContext.getRuntime().contain(WidgetAdvancedPaneProvider.XML_TAG)); + } + + private void refreshExtraAdvancedPane() { + extraPaneList.clear(); + backgroundPane.removeAll(); + Set> providers = ExtraDesignClassManager.getInstance().getArray(WidgetAdvancedPaneProvider.XML_TAG); + for (WidgetAdvancedPaneProvider provider : providers) { + if (!provider.accept(creator)) { + continue; + } + insertShortCut(provider.getInsertPosition(extraPaneList.size()), provider.createExtraAdvancedPane()); + } + if (extraPaneList.isEmpty()) { + if (background == null) { + background = new AccessibleBackgroundEditor(); + } + backgroundPane.add(background); + } else { + for (BasicBeanPane pane : extraPaneList) { + backgroundPane.add(pane); + } + } + } + + /** + * 插入配置项面板 + * + * @param index 插入的位置 + * @param pane 配置项面板 + */ + public void insertShortCut(int index, BasicBeanPane pane) { + int size = extraPaneList.size(); + index = Math.min(index, size); + extraPaneList.add(index, pane); + } + /** * @param * @Description: 获取新决策报表的AdvancePane @@ -189,7 +247,7 @@ public class RootDesignDefinePane extends AbstractDataModify { displayReport = new UICheckBox(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Display_Nothing_Before_Query")); UIComponentUtils.setLineWrap(displayReport); useParamsTemplate = new UICheckBox(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Use_Params_Template")); - fireAfterEditor = new UICheckBox(com.fr.design.i18n.Toolkit.i18nText("触发编辑结束事件")); + fireAfterEditor = new UICheckBox(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Trigger_Editing_End_Event")); fireAfterEditor.setEnabled(false); fireAfterEditor.setBorder(BorderFactory.createEmptyBorder(0, 30, 0, 0)); useParamsTemplate.addChangeListener(e -> { @@ -199,8 +257,8 @@ public class RootDesignDefinePane extends AbstractDataModify { fireAfterEditor.setSelected(false); } }); - background = new AccessibleBackgroundEditor(); - + backgroundPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); + this.initExtraPane(); double f = TableLayout.FILL; double p = TableLayout.PREFERRED; double[] rowSize = {p, p, p, p, p}; @@ -208,7 +266,7 @@ public class RootDesignDefinePane extends AbstractDataModify { int[][] rowCount = {{1, 1}, {1, 1}, {1, 1}, {1, 1}, {1, 1}}; Component[][] components = new Component[][]{ new Component[]{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Label_Name")), labelNameTextField}, - new Component[]{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Base_Background")), background}, + new Component[]{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Base_Background")), backgroundPane}, new Component[]{displayReport, null}, new Component[]{useParamsTemplate, null}, new Component[]{fireAfterEditor, null}, @@ -229,7 +287,13 @@ public class RootDesignDefinePane extends AbstractDataModify { @Override public void populateBean(WParameterLayout ob) { labelNameTextField.setText(ob.getLabelName()); - background.setValue(ob.getBackground()); + if (extraPaneList.isEmpty()) { + background.setValue(ob.getBackground()); + } else { + for (BasicBeanPane pane : extraPaneList) { + pane.populateBean(ob); + } + } displayReport.setSelected(ob.isDelayDisplayContent()); useParamsTemplate.setSelected(ob.isUseParamsTemplate()); fireAfterEditor.setEnabled(ob.isUseParamsTemplate()); @@ -277,8 +341,14 @@ public class RootDesignDefinePane extends AbstractDataModify { wParameterLayout.setParamsFireStopEdit(fireAfterEditor.isSelected()); JTemplate jTemplate = HistoryTemplateListPane.getInstance().getCurrentEditingTemplate(); jTemplate.needAddTemplateIdAttr(useParamsTemplate.isSelected()); - wParameterLayout.setBackground((Background) background.getValue()); wParameterLayout.setPosition((Integer) hAlignmentPane.getSelectedItem()); + if (extraPaneList.isEmpty()) { + wParameterLayout.setBackground((Background) background.getValue()); + } else { + for (BasicBeanPane pane : extraPaneList) { + pane.updateBean(wParameterLayout); + } + } return wParameterLayout; } @@ -299,6 +369,13 @@ public class RootDesignDefinePane extends AbstractDataModify { JTemplate jTemplate = HistoryTemplateListPane.getInstance().getCurrentEditingTemplate(); jTemplate.needAddTemplateIdAttr(useParamsTemplate.isSelected()); wParameterLayout.setBackground((Background) background.getValue()); + if (extraPaneList.isEmpty()) { + background.setValue(wParameterLayout.getBackground()); + } else { + for (BasicBeanPane pane : extraPaneList) { + pane.populateBean(wParameterLayout); + } + } //设置参数模板面板的高度 int height = (int) paraHeight.getTextField().getValue(); FormDesigner designer = TemplateTool.getCurrentEditingNewJForm().getFormDesign(); diff --git a/designer-form/src/main/java/com/fr/design/preview/DeveloperPreview.java b/designer-form/src/main/java/com/fr/design/preview/DeveloperPreview.java index 69e514b408..260ba183d4 100644 --- a/designer-form/src/main/java/com/fr/design/preview/DeveloperPreview.java +++ b/designer-form/src/main/java/com/fr/design/preview/DeveloperPreview.java @@ -1,11 +1,12 @@ package com.fr.design.preview; import com.fr.design.file.HistoryTemplateListCache; -import com.fr.design.file.MutilTempalteTabPane; +import com.fr.design.file.MultiTemplateTabPane; import com.fr.design.fun.impl.AbstractPreviewProvider; import com.fr.design.i18n.Toolkit; import com.fr.design.mainframe.JForm; import com.fr.design.mainframe.JTemplate; +import com.fr.design.module.DesignModuleFactory; import com.fr.design.worker.WorkerManager; import com.fr.design.worker.save.CallbackSaveWorker; import com.fr.general.web.ParameterConstants; @@ -47,6 +48,8 @@ public class DeveloperPreview extends AbstractPreviewProvider { @Override public void onClick(JTemplate jt) { super.onClick(jt); + //进入时要关闭查找替换面板 + DesignModuleFactory.getReplaceOperator().close(); SwingWorker worker = WorkerManager.getInstance().getWorker(jt.getRuntimeId()); if (worker instanceof CallbackSaveWorker) { CallbackSaveWorker callbackSaveWorker = (CallbackSaveWorker) worker; @@ -63,7 +66,7 @@ public class DeveloperPreview extends AbstractPreviewProvider { } private void onPreview(JTemplate jt) { - MutilTempalteTabPane.getInstance().closeCurrentTpl(); + MultiTemplateTabPane.getInstance().closeCurrentTpl(); jt.generateForBiddenTemplate(); } diff --git a/designer-form/src/main/java/com/fr/design/widget/ui/designer/FieldEditorDefinePane.java b/designer-form/src/main/java/com/fr/design/widget/ui/designer/FieldEditorDefinePane.java index 4ee699e0fe..1777a027ba 100644 --- a/designer-form/src/main/java/com/fr/design/widget/ui/designer/FieldEditorDefinePane.java +++ b/designer-form/src/main/java/com/fr/design/widget/ui/designer/FieldEditorDefinePane.java @@ -1,6 +1,7 @@ package com.fr.design.widget.ui.designer; import com.fr.design.ExtraDesignClassManager; +import com.fr.design.beans.BasicBeanPane; import com.fr.design.beans.ErrorMsgTextFieldAdapter; import com.fr.design.beans.UITextFieldAdapter; import com.fr.design.constants.LayoutConstants; @@ -12,6 +13,7 @@ import com.fr.design.designer.creator.XWFitLayout; import com.fr.design.designer.creator.XWParameterLayout; import com.fr.design.foldablepane.UIExpandablePane; import com.fr.design.fun.TextFieldAdapterProvider; +import com.fr.design.fun.WidgetAdvancedPaneProvider; import com.fr.design.gui.icheckbox.UICheckBox; import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.itextfield.UITextField; @@ -19,7 +21,10 @@ import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.TableLayoutHelper; import com.fr.design.widget.ui.designer.component.FontSizeComboPane; import com.fr.form.ui.FieldEditor; +import com.fr.general.GeneralContext; import com.fr.log.FineLoggerFactory; +import com.fr.plugin.observer.PluginEvent; +import com.fr.plugin.observer.PluginEventListener; import javax.swing.BorderFactory; import javax.swing.JPanel; @@ -27,6 +32,9 @@ import java.awt.BorderLayout; import java.awt.Component; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; public abstract class FieldEditorDefinePane extends AbstractDataModify { protected UICheckBox allowBlankCheckBox; @@ -35,7 +43,8 @@ public abstract class FieldEditorDefinePane extends Abstr protected JPanel validatePane; protected FontSizeComboPane fontSizePane; protected UITextField labelNameTextField; - + private final List> extraPaneList = new ArrayList<>(); + private JPanel extraPane; public FieldEditorDefinePane(XCreator xCreator) { super(xCreator); @@ -49,8 +58,11 @@ public abstract class FieldEditorDefinePane extends Abstr allowBlankCheckBox.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); fontSizePane = new FontSizeComboPane(); JPanel contentPane = this.setFirstContentPane(); - JPanel jPanel = FRGUIPaneFactory.createBorderLayout_S_Pane(); - jPanel.add(contentPane, BorderLayout.CENTER); + JPanel jPanel = FRGUIPaneFactory.createYBoxEmptyBorderPane(); + jPanel.add(contentPane); + extraPane = FRGUIPaneFactory.createYBoxEmptyBorderPane(); + jPanel.add(extraPane); + this.initExtraPane(); contentPane.setBorder(BorderFactory.createEmptyBorder(10, 0, 10, 0)); if (contentPane != null) { UIExpandablePane uiExpandablePane = new UIExpandablePane(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Advanced"), 280, 20, jPanel); @@ -59,12 +71,35 @@ public abstract class FieldEditorDefinePane extends Abstr this.addValidatePane(); } + private void initExtraPane() { + initPluginListener(); + refreshExtraAdvancedPane(); + } + + private void refreshExtraAdvancedPane() { + extraPaneList.clear(); + extraPane.removeAll(); + Set> providers = ExtraDesignClassManager.getInstance().getArray(WidgetAdvancedPaneProvider.XML_TAG); + for (WidgetAdvancedPaneProvider provider : providers) { + if (!provider.accept(creator)) { + continue; + } + insertShortCut(provider.getInsertPosition(extraPaneList.size()), provider.createExtraAdvancedPane()); + } + for (BasicBeanPane pane : extraPaneList) { + extraPane.add(pane); + } + } + @Override public void populateBean(T ob) { this.allowBlankCheckBox.setSelected(ob.isAllowBlank()); this.errorMsgTextField.setText(ob.getErrorMessage()); this.fontSizePane.setValue(ob.getFontSize()); this.labelNameTextField.setText(ob.getLabelName()); + for (BasicBeanPane pane : extraPaneList) { + pane.populateBean(ob); + } populateSubFieldEditorBean(ob); } @@ -78,6 +113,9 @@ public abstract class FieldEditorDefinePane extends Abstr e.setErrorMessage(this.errorMsgTextField.getText()); e.setFontSize(fontSizePane.getValue()); e.setLabelName(labelNameTextField.getText()); + for (BasicBeanPane pane : extraPaneList) { + pane.updateBean(e); + } return e; } @@ -152,4 +190,25 @@ public abstract class FieldEditorDefinePane extends Abstr return null; } + /** + * 插入配置项面板 + * + * @param index 插入的位置 + * @param pane 配置项面板 + */ + private void insertShortCut(int index, BasicBeanPane pane) { + int size = extraPaneList.size(); + index = Math.min(index, size); + extraPaneList.add(index, pane); + } + + private void initPluginListener() { + GeneralContext.listenPluginRunningChanged(new PluginEventListener() { + @Override + public void on(PluginEvent event) { + refreshExtraAdvancedPane(); + } + }, pluginContext -> pluginContext.getRuntime().contain(WidgetAdvancedPaneProvider.XML_TAG)); + } + } diff --git a/designer-form/src/main/java/com/fr/design/widget/ui/designer/LabelDefinePane.java b/designer-form/src/main/java/com/fr/design/widget/ui/designer/LabelDefinePane.java index 1c30b1a557..992ea9cfb5 100644 --- a/designer-form/src/main/java/com/fr/design/widget/ui/designer/LabelDefinePane.java +++ b/designer-form/src/main/java/com/fr/design/widget/ui/designer/LabelDefinePane.java @@ -68,7 +68,7 @@ public class LabelDefinePane extends AbstractDataModify