108 changed files with 9102 additions and 1668 deletions
@ -0,0 +1,193 @@ |
|||||||
|
package com.fr.design; |
||||||
|
|
||||||
|
import com.fr.concurrent.NamedThreadFactory; |
||||||
|
import com.fr.general.CloudCenter; |
||||||
|
import com.fr.general.CloudCenterConfig; |
||||||
|
import com.fr.general.http.HttpToolbox; |
||||||
|
import com.fr.log.FineLoggerFactory; |
||||||
|
import com.fr.stable.ProductConstants; |
||||||
|
import com.fr.stable.StableUtils; |
||||||
|
import com.fr.stable.StringUtils; |
||||||
|
import com.fr.stable.xml.XMLPrintWriter; |
||||||
|
import com.fr.stable.xml.XMLReaderHelper; |
||||||
|
import com.fr.stable.xml.XMLTools; |
||||||
|
import com.fr.stable.xml.XMLable; |
||||||
|
import com.fr.stable.xml.XMLableReader; |
||||||
|
import com.fr.third.javax.xml.stream.XMLStreamException; |
||||||
|
import com.fr.third.org.apache.commons.io.FileUtils; |
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream; |
||||||
|
import java.io.File; |
||||||
|
import java.io.FileInputStream; |
||||||
|
import java.io.FileNotFoundException; |
||||||
|
import java.io.IOException; |
||||||
|
import java.io.InputStream; |
||||||
|
import java.nio.charset.StandardCharsets; |
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.Iterator; |
||||||
|
import java.util.Map; |
||||||
|
import java.util.concurrent.ExecutorService; |
||||||
|
import java.util.concurrent.Executors; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by kerry on 2021/10/22 |
||||||
|
*/ |
||||||
|
public class DesignerCloudURLManager implements XMLable { |
||||||
|
private static final String CLOUD_URL_INFO = "cloudUrl.info"; |
||||||
|
private static final String ROOT_XML_TAG = "CloudUrlInfoList"; |
||||||
|
private static final String CHILD_XML_TAG = "CloudUrlInfo"; |
||||||
|
private final Map<String, String> urlMap = new HashMap<>(); |
||||||
|
|
||||||
|
public static DesignerCloudURLManager getInstance() { |
||||||
|
return DesignerCloudURLManager.HOLDER.singleton; |
||||||
|
} |
||||||
|
|
||||||
|
private final ExecutorService executorService = Executors.newSingleThreadExecutor(new NamedThreadFactory("TestCloudConnectThread")); |
||||||
|
|
||||||
|
private volatile boolean testResult; |
||||||
|
|
||||||
|
|
||||||
|
private static class HOLDER { |
||||||
|
private static final DesignerCloudURLManager singleton = new DesignerCloudURLManager(); |
||||||
|
} |
||||||
|
|
||||||
|
private DesignerCloudURLManager() { |
||||||
|
loadURLXMLFile(); |
||||||
|
} |
||||||
|
|
||||||
|
public String acquireUrlByKind(String key) { |
||||||
|
String url = urlMap.getOrDefault(key, StringUtils.EMPTY); |
||||||
|
if (StringUtils.isEmpty(url)) { |
||||||
|
//本地缓存中为空时,直接从云中心获取,获取完成后异步更新本地缓存文件
|
||||||
|
String latestUrl = CloudCenter.getInstance().acquireConf(key, StringUtils.EMPTY); |
||||||
|
executorService.submit(() -> { |
||||||
|
updateURLXMLFile(key, latestUrl); |
||||||
|
}); |
||||||
|
return latestUrl; |
||||||
|
} |
||||||
|
//本地缓存不为空时,直接返回对应 url,同时异步更新
|
||||||
|
executorService.submit(() -> { |
||||||
|
String latestUrl = CloudCenter.getInstance().acquireConf(key, StringUtils.EMPTY); |
||||||
|
updateURLXMLFile(key, latestUrl); |
||||||
|
}); |
||||||
|
return url; |
||||||
|
} |
||||||
|
|
||||||
|
private synchronized void updateURLXMLFile(String key, String url) { |
||||||
|
if (StringUtils.isNotEmpty(url) && (!urlMap.containsKey(key) || !url.equals(urlMap.get(key)))) { |
||||||
|
urlMap.put(key, url); |
||||||
|
saveURLXMLFile(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
public void testConnect() { |
||||||
|
executorService.submit(() -> { |
||||||
|
testResult = isOnline(); |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
public boolean isConnected() { |
||||||
|
return testResult; |
||||||
|
} |
||||||
|
|
||||||
|
public boolean isOnline() { |
||||||
|
if (CloudCenterConfig.getInstance().isOnline()) { |
||||||
|
String ping = acquireUrlByKind("ping"); |
||||||
|
if (StringUtils.isNotEmpty(ping)) { |
||||||
|
try { |
||||||
|
return StringUtils.isEmpty(HttpToolbox.get(ping)); |
||||||
|
} catch (Exception ignore) { |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 加载本地 url 管理文件 |
||||||
|
*/ |
||||||
|
private void loadURLXMLFile() { |
||||||
|
if (!getInfoFile().exists()) { |
||||||
|
return; |
||||||
|
} |
||||||
|
XMLableReader reader = null; |
||||||
|
try (InputStream in = new FileInputStream(getInfoFile())) { |
||||||
|
// XMLableReader 还是应该考虑实现 Closable 接口的,这样就能使用 try-with 语句了
|
||||||
|
reader = XMLReaderHelper.createXMLableReader(in, XMLPrintWriter.XML_ENCODER); |
||||||
|
if (reader == null) { |
||||||
|
return; |
||||||
|
} |
||||||
|
reader.readXMLObject(this); |
||||||
|
} catch (FileNotFoundException e) { |
||||||
|
// do nothing
|
||||||
|
} catch (XMLStreamException | IOException e) { |
||||||
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||||
|
} finally { |
||||||
|
try { |
||||||
|
if (reader != null) { |
||||||
|
reader.close(); |
||||||
|
} |
||||||
|
} catch (XMLStreamException e) { |
||||||
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private File getInfoFile() { |
||||||
|
|
||||||
|
File file = new File(StableUtils.pathJoin(ProductConstants.getEnvHome(), CLOUD_URL_INFO)); |
||||||
|
try { |
||||||
|
if (!file.exists()) { |
||||||
|
file.createNewFile(); |
||||||
|
} |
||||||
|
} catch (Exception ex) { |
||||||
|
FineLoggerFactory.getLogger().error(ex.getMessage(), ex); |
||||||
|
} |
||||||
|
return file; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 保存到本地 URL 管理文件中,存放在 .Finereport110 中 |
||||||
|
*/ |
||||||
|
void saveURLXMLFile() { |
||||||
|
try { |
||||||
|
ByteArrayOutputStream out = new ByteArrayOutputStream(); |
||||||
|
XMLTools.writeOutputStreamXML(this, out); |
||||||
|
out.flush(); |
||||||
|
out.close(); |
||||||
|
String fileContent = new String(out.toByteArray(), StandardCharsets.UTF_8); |
||||||
|
FileUtils.writeStringToFile(getInfoFile(), fileContent, StandardCharsets.UTF_8); |
||||||
|
} catch (Exception ex) { |
||||||
|
FineLoggerFactory.getLogger().error(ex.getMessage()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
@Override |
||||||
|
public void readXML(XMLableReader reader) { |
||||||
|
String tagName = reader.getTagName(); |
||||||
|
if (tagName.equals(CHILD_XML_TAG)) { |
||||||
|
String key = reader.getAttrAsString("key", StringUtils.EMPTY); |
||||||
|
String value = reader.getAttrAsString("url", StringUtils.EMPTY); |
||||||
|
this.urlMap.put(key, value); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void writeXML(XMLPrintWriter xmlPrintWriter) { |
||||||
|
xmlPrintWriter.startTAG(ROOT_XML_TAG); |
||||||
|
Iterator<Map.Entry<String, String>> iterable = urlMap.entrySet().iterator(); |
||||||
|
while (iterable.hasNext()) { |
||||||
|
Map.Entry<String, String> entry = iterable.next(); |
||||||
|
xmlPrintWriter.startTAG(CHILD_XML_TAG).attr("key", entry.getKey()).attr("url", entry.getValue()).end(); |
||||||
|
} |
||||||
|
xmlPrintWriter.end(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Object clone() throws CloneNotSupportedException { |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
File diff suppressed because it is too large
Load Diff
@ -1,91 +1,48 @@ |
|||||||
package com.fr.design.formula; |
package com.fr.design.formula; |
||||||
|
|
||||||
|
import com.fr.design.formula.exception.FormulaExceptionTipsProcessor; |
||||||
import com.fr.design.i18n.Toolkit; |
import com.fr.design.i18n.Toolkit; |
||||||
import com.fr.log.FineLoggerFactory; |
|
||||||
import com.fr.parser.FRLexer; |
|
||||||
import com.fr.parser.FRParser; |
import com.fr.parser.FRParser; |
||||||
import com.fr.script.checker.FunctionCheckerDispatcher; |
import com.fr.script.checker.FunctionCheckerDispatcher; |
||||||
import com.fr.script.checker.exception.ConditionCheckWrongException; |
import com.fr.script.checker.result.FormulaCheckResult; |
||||||
import com.fr.script.checker.exception.FunctionCheckWrongException; |
import com.fr.script.checker.result.FormulaCoordinates; |
||||||
import com.fr.script.rules.FunctionParameterType; |
|
||||||
import com.fr.script.rules.FunctionRule; |
|
||||||
import com.fr.stable.StringUtils; |
import com.fr.stable.StringUtils; |
||||||
import com.fr.stable.script.Expression; |
import com.fr.stable.script.Expression; |
||||||
import com.fr.stable.script.Node; |
import com.fr.stable.script.Node; |
||||||
|
import com.fr.third.antlr.TokenStreamRecognitionException; |
||||||
|
|
||||||
import java.io.StringReader; |
import java.io.StringReader; |
||||||
import java.util.List; |
|
||||||
|
|
||||||
/** |
/** |
||||||
* @author Hoky |
* @author Hoky |
||||||
* @date 2021/9/28 |
* @date 2021/9/28 |
||||||
*/ |
*/ |
||||||
public class FormulaChecker { |
public class FormulaChecker { |
||||||
private static final String VALID_FORMULA = Toolkit.i18nText("Fine-Design_Basic_FormulaD_Valid_Formula"); |
public static final String VALID_FORMULA = Toolkit.i18nText("Fine-Design_Basic_FormulaD_Valid_Formula"); |
||||||
private static final String INVALID_FORMULA = Toolkit.i18nText("Fine-Design_Basic_FormulaD_Invalid_Formula"); |
public static final String INVALID_FORMULA = Toolkit.i18nText("Fine-Design_Basic_FormulaD_Invalid_Formula"); |
||||||
public static final String COLON = ":"; |
private static FormulaExceptionTipsProcessor processor = FormulaExceptionTipsProcessor.getProcessor(); |
||||||
|
|
||||||
public static String check(String formulaText) throws FormulaCheckerException { |
public static FormulaCheckResult check(String formulaText) { |
||||||
|
if (StringUtils.isEmpty(formulaText) || formulaText.equals(Toolkit.i18nText("Fine-Design_Basic_FormulaPane_Tips"))) { |
||||||
|
return new FormulaCheckResult(true, VALID_FORMULA, FormulaCoordinates.INVALID, true); |
||||||
|
} |
||||||
|
//过滤一些空格等符号
|
||||||
StringReader in = new StringReader(formulaText); |
StringReader in = new StringReader(formulaText); |
||||||
|
//此lexer为公式校验定制
|
||||||
FRLexer lexer = new FRLexer(in); |
FRFormulaLexer lexer = new FRFormulaLexer(in); |
||||||
FRParser parser = new FRParser(lexer); |
FRParser parser = new FRParser(lexer); |
||||||
|
|
||||||
try { |
try { |
||||||
Expression expression = parser.parse(); |
Expression expression = parser.parse(); |
||||||
Node node = expression.getConditionalExpression(); |
Node node = expression.getConditionalExpression(); |
||||||
boolean valid = FunctionCheckerDispatcher.getInstance().getFunctionChecker(node).checkFunction(node); |
boolean valid = FunctionCheckerDispatcher.getInstance().getFunctionChecker(node).checkFunction(formulaText, node); |
||||||
if (valid) { |
return new FormulaCheckResult(valid, valid ? Toolkit.i18nText("Fine-Design_Basic_FormulaD_Valid_Formula") : |
||||||
return VALID_FORMULA; |
Toolkit.i18nText("Fine-Design_Basic_FormulaD_Invalid_Formula"), FormulaCoordinates.INVALID, true); |
||||||
} else { |
|
||||||
throw new FormulaCheckerException(INVALID_FORMULA); |
|
||||||
} |
|
||||||
} catch (ConditionCheckWrongException cce) { |
|
||||||
String functionName = cce.getFunctionName(); |
|
||||||
throw new FormulaCheckerException(functionName + Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Condition_Tips") + COLON); |
|
||||||
} catch (FunctionCheckWrongException ce) { |
|
||||||
List<FunctionRule> rules = ce.getRules(); |
|
||||||
String functionName = ce.getFunctionName(); |
|
||||||
StringBuilder errorMsg = new StringBuilder(functionName + com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Error_Tips") + COLON); |
|
||||||
for (int i = 0; i < rules.size(); i++) { |
|
||||||
errorMsg.append("("); |
|
||||||
if (rules.get(i).getParameterList().isEmpty()) { |
|
||||||
errorMsg.append(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Formula_No_Param")); |
|
||||||
} |
|
||||||
for (FunctionParameterType functionParameterType : rules.get(i).getParameterList()) { |
|
||||||
errorMsg.append(getTypeString(functionParameterType)).append(","); |
|
||||||
} |
|
||||||
if (",".equals(errorMsg.charAt(errorMsg.length() - 1) + "")) { |
|
||||||
errorMsg.deleteCharAt(errorMsg.length() - 1); |
|
||||||
} |
|
||||||
errorMsg.append(")"); |
|
||||||
if (i != rules.size() - 1) { |
|
||||||
errorMsg.append(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Or")); |
|
||||||
} |
|
||||||
} |
|
||||||
throw new FormulaCheckerException(errorMsg.toString()); |
|
||||||
} catch (Exception e) { |
} catch (Exception e) { |
||||||
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
if (e instanceof TokenStreamRecognitionException) { |
||||||
throw new FormulaCheckerException(INVALID_FORMULA); |
return processor.getExceptionTips(((TokenStreamRecognitionException) e).recog); |
||||||
// alex:继续往下面走,expression为null时告知不合法公式
|
|
||||||
} |
} |
||||||
|
return processor.getExceptionTips(e); |
||||||
} |
} |
||||||
|
|
||||||
private static String getTypeString(FunctionParameterType type) { |
|
||||||
switch (type) { |
|
||||||
case NUMBER: |
|
||||||
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Formula_Check_ParamType_Number"); |
|
||||||
case STRING: |
|
||||||
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Formula_Check_ParamType_String"); |
|
||||||
case ANY: |
|
||||||
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Formula_Check_ParamType_Any"); |
|
||||||
case DATE: |
|
||||||
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Formula_Check_ParamType_Date"); |
|
||||||
case BOOLEAN: |
|
||||||
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Formula_Check_ParamType_Boolean"); |
|
||||||
case ARRAY: |
|
||||||
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Formula_Check_ParamType_Array"); |
|
||||||
} |
|
||||||
return StringUtils.EMPTY; |
|
||||||
} |
} |
||||||
} |
} |
||||||
|
@ -0,0 +1,48 @@ |
|||||||
|
package com.fr.design.formula.exception; |
||||||
|
|
||||||
|
import com.fr.design.formula.FormulaChecker; |
||||||
|
import com.fr.design.formula.exception.function.FormulaCheckWrongFunction; |
||||||
|
import com.fr.design.formula.exception.function.MismatchedCharFunction; |
||||||
|
import com.fr.design.formula.exception.function.MismatchedTokenFunction; |
||||||
|
import com.fr.design.formula.exception.function.NoViableAltForCharFunction; |
||||||
|
import com.fr.design.formula.exception.function.NoViableAltFunction; |
||||||
|
import com.fr.script.checker.exception.FunctionCheckWrongException; |
||||||
|
import com.fr.script.checker.result.FormulaCheckResult; |
||||||
|
import com.fr.script.checker.result.FormulaCoordinates; |
||||||
|
import com.fr.third.antlr.MismatchedCharException; |
||||||
|
import com.fr.third.antlr.MismatchedTokenException; |
||||||
|
import com.fr.third.antlr.NoViableAltException; |
||||||
|
import com.fr.third.antlr.NoViableAltForCharException; |
||||||
|
|
||||||
|
import java.util.Map; |
||||||
|
import java.util.concurrent.ConcurrentHashMap; |
||||||
|
import java.util.function.Function; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author Hoky |
||||||
|
* @date 2021/10/26 |
||||||
|
*/ |
||||||
|
public class FormulaExceptionTipsProcessor { |
||||||
|
private static final Map<Class, Function<Exception, FormulaCheckResult>> EXCEPTION_TIPS = new ConcurrentHashMap<>(); |
||||||
|
|
||||||
|
private static final FormulaExceptionTipsProcessor PROCESSOR = new FormulaExceptionTipsProcessor(); |
||||||
|
|
||||||
|
static { |
||||||
|
EXCEPTION_TIPS.put(FunctionCheckWrongException.class, FormulaCheckWrongFunction.getFunction()); |
||||||
|
EXCEPTION_TIPS.put(MismatchedCharException.class, MismatchedCharFunction.getFunction()); |
||||||
|
EXCEPTION_TIPS.put(MismatchedTokenException.class, MismatchedTokenFunction.getFunction()); |
||||||
|
EXCEPTION_TIPS.put(NoViableAltException.class, NoViableAltFunction.getFunction()); |
||||||
|
EXCEPTION_TIPS.put(NoViableAltForCharException.class, NoViableAltForCharFunction.getFunction()); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
public FormulaCheckResult getExceptionTips(Exception e) { |
||||||
|
return EXCEPTION_TIPS.getOrDefault(e.getClass(), |
||||||
|
e1 -> new FormulaCheckResult(false, FormulaChecker.INVALID_FORMULA, FormulaCoordinates.INVALID, false)) |
||||||
|
.apply(e); |
||||||
|
} |
||||||
|
|
||||||
|
public static FormulaExceptionTipsProcessor getProcessor() { |
||||||
|
return PROCESSOR; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,14 @@ |
|||||||
|
package com.fr.design.formula.exception.function; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author Hoky |
||||||
|
* @date 2021/10/28 |
||||||
|
*/ |
||||||
|
public class FormulaCheckConstants { |
||||||
|
public static final String COLON = ":"; |
||||||
|
public static final String LEFT = "("; |
||||||
|
public static final String COMMON = ","; |
||||||
|
public static final String RIGHT = ")"; |
||||||
|
public static final String BLANK = " "; |
||||||
|
public static final String SINGLE_QUOTES = "'"; |
||||||
|
} |
@ -0,0 +1,78 @@ |
|||||||
|
package com.fr.design.formula.exception.function; |
||||||
|
|
||||||
|
import com.fr.design.i18n.Toolkit; |
||||||
|
import com.fr.script.checker.exception.FunctionCheckWrongException; |
||||||
|
import com.fr.script.checker.result.FormulaCheckResult; |
||||||
|
import com.fr.script.checker.result.FormulaCoordinates; |
||||||
|
import com.fr.script.rules.FunctionParameterType; |
||||||
|
import com.fr.script.rules.FunctionRule; |
||||||
|
import com.fr.stable.StringUtils; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
import java.util.function.Function; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author Hoky |
||||||
|
* @date 2021/10/26 |
||||||
|
*/ |
||||||
|
public class FormulaCheckWrongFunction implements Function<Exception, FormulaCheckResult> { |
||||||
|
private final static FormulaCheckWrongFunction FUNCTION = new FormulaCheckWrongFunction(); |
||||||
|
|
||||||
|
@Override |
||||||
|
public FormulaCheckResult apply(Exception e) { |
||||||
|
if (e instanceof FunctionCheckWrongException) { |
||||||
|
FunctionCheckWrongException ce = (FunctionCheckWrongException) e; |
||||||
|
List<FunctionRule> rules = ce.getRules(); |
||||||
|
String functionName = ce.getFunctionName(); |
||||||
|
StringBuilder errorMsg = new StringBuilder(functionName + Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Error_Tips") + FormulaCheckConstants.COLON); |
||||||
|
for (int i = 0; i < rules.size(); i++) { |
||||||
|
errorMsg.append(FormulaCheckConstants.LEFT); |
||||||
|
if (rules.get(i).getParameterList().isEmpty()) { |
||||||
|
errorMsg.append(Toolkit.i18nText("Fine-Design_Basic_Formula_No_Param")); |
||||||
|
} |
||||||
|
for (FunctionParameterType functionParameterType : rules.get(i).getParameterList()) { |
||||||
|
errorMsg.append(getTypeString(functionParameterType)).append(FormulaCheckConstants.COMMON); |
||||||
|
} |
||||||
|
if (FormulaCheckConstants.COMMON.equals(errorMsg.charAt(errorMsg.length() - 1) + StringUtils.EMPTY)) { |
||||||
|
errorMsg.deleteCharAt(errorMsg.length() - 1); |
||||||
|
} |
||||||
|
errorMsg.append(FormulaCheckConstants.RIGHT); |
||||||
|
if (i != rules.size() - 1) { |
||||||
|
errorMsg.append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Or")); |
||||||
|
} |
||||||
|
} |
||||||
|
return new FormulaCheckResult(false, errorMsg.toString(), new FormulaCoordinates(1, indexPosition(ce.getFormulaText(), ce.getNode().toString())), true); |
||||||
|
} |
||||||
|
return new FormulaCheckResult(false, StringUtils.EMPTY, new FormulaCoordinates(-1, -1), true); |
||||||
|
} |
||||||
|
|
||||||
|
private static String getTypeString(FunctionParameterType type) { |
||||||
|
switch (type) { |
||||||
|
case NUMBER: |
||||||
|
return Toolkit.i18nText("Fine-Design_Basic_Formula_Check_ParamType_Number"); |
||||||
|
case STRING: |
||||||
|
return Toolkit.i18nText("Fine-Design_Basic_Formula_Check_ParamType_String"); |
||||||
|
case ANY: |
||||||
|
return Toolkit.i18nText("Fine-Design_Basic_Formula_Check_ParamType_Any"); |
||||||
|
case DATE: |
||||||
|
return Toolkit.i18nText("Fine-Design_Basic_Formula_Check_ParamType_Date"); |
||||||
|
case BOOLEAN: |
||||||
|
return Toolkit.i18nText("Fine-Design_Basic_Formula_Check_ParamType_Boolean"); |
||||||
|
case ARRAY: |
||||||
|
return Toolkit.i18nText("Fine-Design_Basic_Formula_Check_ParamType_Array"); |
||||||
|
} |
||||||
|
return StringUtils.EMPTY; |
||||||
|
} |
||||||
|
|
||||||
|
public static Function<Exception, FormulaCheckResult> getFunction() { |
||||||
|
return FUNCTION; |
||||||
|
} |
||||||
|
|
||||||
|
private int indexPosition(String formulaText, String invalidFormula) { |
||||||
|
//处理一下自己FunctionCall自己拼的逗号逻辑
|
||||||
|
if (invalidFormula.contains(",")) { |
||||||
|
invalidFormula = invalidFormula.substring(0, invalidFormula.indexOf(",")); |
||||||
|
} |
||||||
|
return formulaText.indexOf(invalidFormula); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,104 @@ |
|||||||
|
package com.fr.design.formula.exception.function; |
||||||
|
|
||||||
|
import com.fr.design.formula.FormulaChecker; |
||||||
|
import com.fr.design.i18n.Toolkit; |
||||||
|
import com.fr.script.checker.result.FormulaCheckResult; |
||||||
|
import com.fr.script.checker.result.FormulaCoordinates; |
||||||
|
import com.fr.third.antlr.MismatchedCharException; |
||||||
|
|
||||||
|
import java.util.function.Function; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author Hoky |
||||||
|
* @date 2021/10/28 |
||||||
|
*/ |
||||||
|
public class MismatchedCharFunction implements Function<Exception, FormulaCheckResult> { |
||||||
|
private final static MismatchedCharFunction FUNCTION = new MismatchedCharFunction(); |
||||||
|
|
||||||
|
@Override |
||||||
|
public FormulaCheckResult apply(Exception e) { |
||||||
|
if (e instanceof MismatchedCharException) { |
||||||
|
MismatchedCharException charException = (MismatchedCharException) e; |
||||||
|
FormulaCoordinates formulaCoordinates = new FormulaCoordinates(charException.line, charException.column - 1); |
||||||
|
return new FormulaCheckResult(false, getMessage(charException), formulaCoordinates, false); |
||||||
|
} |
||||||
|
return new FormulaCheckResult(false, FormulaChecker.INVALID_FORMULA, FormulaCoordinates.INVALID, false); |
||||||
|
} |
||||||
|
|
||||||
|
public static Function<Exception, FormulaCheckResult> getFunction() { |
||||||
|
return FUNCTION; |
||||||
|
} |
||||||
|
|
||||||
|
private String getMessage(MismatchedCharException charException) { |
||||||
|
StringBuffer sb = new StringBuffer(); |
||||||
|
switch (charException.mismatchType) { |
||||||
|
case 1: |
||||||
|
sb.append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Expecting") + ": "); |
||||||
|
appendCharName(sb, charException.expecting); |
||||||
|
sb.append(FormulaCheckConstants.COMMON) |
||||||
|
.append(FormulaCheckConstants.BLANK) |
||||||
|
.append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Found")); |
||||||
|
appendCharName(sb, charException.foundChar); |
||||||
|
break; |
||||||
|
case 2: |
||||||
|
sb.append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Expecting_Anything") + ": ") |
||||||
|
.append(FormulaCheckConstants.BLANK) |
||||||
|
.append(FormulaCheckConstants.SINGLE_QUOTES); |
||||||
|
appendCharName(sb, charException.expecting); |
||||||
|
sb.append("';").append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_GotItAnyway")); |
||||||
|
break; |
||||||
|
case 3: |
||||||
|
case 4: |
||||||
|
sb.append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Expecting") + ": ").append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Token")); |
||||||
|
if (charException.mismatchType == 4) { |
||||||
|
sb.append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Not")); |
||||||
|
} |
||||||
|
|
||||||
|
sb.append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_In_Range")).append(": "); |
||||||
|
appendCharName(sb, charException.expecting); |
||||||
|
sb.append(".."); |
||||||
|
appendCharName(sb, charException.upper); |
||||||
|
sb.append(", ").append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Found")); |
||||||
|
appendCharName(sb, charException.foundChar); |
||||||
|
break; |
||||||
|
case 5: |
||||||
|
case 6: |
||||||
|
sb.append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Expecting") + ": ") |
||||||
|
.append(charException.mismatchType == 6 ? Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Not") : FormulaCheckConstants.BLANK) |
||||||
|
.append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_ONE_OF")).append(" ("); |
||||||
|
int[] elems = charException.set.toArray(); |
||||||
|
|
||||||
|
for (int i = 0; i < elems.length; ++i) { |
||||||
|
appendCharName(sb, elems[i]); |
||||||
|
} |
||||||
|
|
||||||
|
sb.append("), ").append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Found")); |
||||||
|
appendCharName(sb, charException.foundChar); |
||||||
|
break; |
||||||
|
default: |
||||||
|
sb.append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Mismatched_Char")); |
||||||
|
} |
||||||
|
|
||||||
|
return sb.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
private void appendCharName(StringBuffer sb, int c) { |
||||||
|
switch (c) { |
||||||
|
case 9: |
||||||
|
sb.append("'\\t'"); |
||||||
|
break; |
||||||
|
case 10: |
||||||
|
sb.append("'\\n'"); |
||||||
|
break; |
||||||
|
case 13: |
||||||
|
sb.append("'\\r'"); |
||||||
|
break; |
||||||
|
case 65535: |
||||||
|
sb.append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Mismatched_EOF")); |
||||||
|
break; |
||||||
|
default: |
||||||
|
sb.append((char) c); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
} |
@ -0,0 +1,140 @@ |
|||||||
|
package com.fr.design.formula.exception.function; |
||||||
|
|
||||||
|
import com.fr.design.formula.FormulaChecker; |
||||||
|
import com.fr.design.i18n.Toolkit; |
||||||
|
import com.fr.log.FineLoggerFactory; |
||||||
|
import com.fr.script.checker.result.FormulaCheckResult; |
||||||
|
import com.fr.script.checker.result.FormulaCoordinates; |
||||||
|
import com.fr.stable.StringUtils; |
||||||
|
import com.fr.third.antlr.MismatchedTokenException; |
||||||
|
|
||||||
|
import java.lang.reflect.Field; |
||||||
|
import java.util.function.Function; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author Hoky |
||||||
|
* @date 2021/10/28 |
||||||
|
*/ |
||||||
|
public class MismatchedTokenFunction implements Function<Exception, FormulaCheckResult> { |
||||||
|
private final static MismatchedTokenFunction FUNCTION = new MismatchedTokenFunction(); |
||||||
|
public static final String NULL_STRING = "null"; |
||||||
|
|
||||||
|
@Override |
||||||
|
public FormulaCheckResult apply(Exception e) { |
||||||
|
if (e instanceof MismatchedTokenException) { |
||||||
|
MismatchedTokenException charException = (MismatchedTokenException) e; |
||||||
|
FormulaCoordinates formulaCoordinates = new FormulaCoordinates(charException.line, charException.column - 1); |
||||||
|
return new FormulaCheckResult(false, getMessage(charException), formulaCoordinates, false); |
||||||
|
} |
||||||
|
return new FormulaCheckResult(false, FormulaChecker.INVALID_FORMULA, FormulaCoordinates.INVALID, false); |
||||||
|
} |
||||||
|
|
||||||
|
public static Function<Exception, FormulaCheckResult> getFunction() { |
||||||
|
return FUNCTION; |
||||||
|
} |
||||||
|
|
||||||
|
public String getMessage(MismatchedTokenException exception) { |
||||||
|
StringBuilder sb = new StringBuilder(); |
||||||
|
Object fieldValue = getFieldValue(exception, "tokenText"); |
||||||
|
String tokenText = fieldValue == null ? NULL_STRING : fieldValue.toString(); |
||||||
|
switch (exception.mismatchType) { |
||||||
|
case 1: |
||||||
|
sb.append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Expecting") + ": ") |
||||||
|
.append(tokenName(exception.expecting, exception)) |
||||||
|
.append(", ") |
||||||
|
.append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Found")) |
||||||
|
.append(FormulaCheckConstants.BLANK + FormulaCheckConstants.SINGLE_QUOTES) |
||||||
|
.append(tokenText).append("'"); |
||||||
|
break; |
||||||
|
case 2: |
||||||
|
sb.append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Expecting_Anything") + ": ") |
||||||
|
.append(tokenName(exception.expecting, exception)) |
||||||
|
.append("; ") |
||||||
|
.append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_GotItAnyway")); |
||||||
|
break; |
||||||
|
case 3: |
||||||
|
sb.append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Expecting") + ": ") |
||||||
|
.append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Token")) |
||||||
|
.append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_In_Range")) |
||||||
|
.append(": ") |
||||||
|
.append(tokenName(exception.expecting, exception)) |
||||||
|
.append("..") |
||||||
|
.append(tokenName(exception.upper, exception)) |
||||||
|
.append(", ").append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Found")) |
||||||
|
.append("'").append(tokenText).append("'"); |
||||||
|
break; |
||||||
|
case 4: |
||||||
|
sb.append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Expecting") + ": ") |
||||||
|
.append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Token")) |
||||||
|
.append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Not")) |
||||||
|
.append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_In_Range")) |
||||||
|
.append(": ") |
||||||
|
.append(tokenName(exception.expecting, exception)) |
||||||
|
.append("..") |
||||||
|
.append(tokenName(exception.upper, exception)) |
||||||
|
.append(","). |
||||||
|
append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Found")) |
||||||
|
.append(" '") |
||||||
|
.append(tokenText) |
||||||
|
.append("'"); |
||||||
|
break; |
||||||
|
case 5: |
||||||
|
case 6: |
||||||
|
sb.append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Expecting") + ": ") |
||||||
|
.append(exception.mismatchType == 6 ? Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Not") : FormulaCheckConstants.BLANK) |
||||||
|
.append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_ONE_OF")).append("("); |
||||||
|
int[] elms = exception.set.toArray(); |
||||||
|
|
||||||
|
for (int i = 0; i < elms.length; ++i) { |
||||||
|
sb.append(' '); |
||||||
|
sb.append(tokenName(elms[i], exception)); |
||||||
|
} |
||||||
|
|
||||||
|
sb.append("),") |
||||||
|
.append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Found")) |
||||||
|
.append("'") |
||||||
|
.append(tokenText) |
||||||
|
.append("'"); |
||||||
|
break; |
||||||
|
default: |
||||||
|
sb.append(Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Mismatched_Token")); |
||||||
|
} |
||||||
|
|
||||||
|
return sb.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
private String tokenName(int tokenType, MismatchedTokenException exception) { |
||||||
|
if (tokenType == 0) { |
||||||
|
return "<Set of tokens>"; |
||||||
|
} else { |
||||||
|
String[] tokenNames = (String[]) getFieldValue(exception, "tokenNames"); |
||||||
|
return tokenType >= 0 && tokenType < tokenNames.length ? translateToken(tokenNames[tokenType]) : "<" + tokenType + ">"; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private String translateToken(String token) { |
||||||
|
switch (token) { |
||||||
|
case ("RPAREN"): |
||||||
|
return ")"; |
||||||
|
case ("LPAREN"): |
||||||
|
return "("; |
||||||
|
case ("COMMA"): |
||||||
|
return ","; |
||||||
|
case ("COLON"): |
||||||
|
return ":"; |
||||||
|
default: |
||||||
|
return token; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private Object getFieldValue(Object object, String fieldName) { |
||||||
|
try { |
||||||
|
Field field = object.getClass().getDeclaredField(fieldName); |
||||||
|
field.setAccessible(true); |
||||||
|
return field.get(object); |
||||||
|
} catch (Exception e) { |
||||||
|
FineLoggerFactory.getLogger().warn(e.getMessage(), e); |
||||||
|
return StringUtils.EMPTY; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,44 @@ |
|||||||
|
package com.fr.design.formula.exception.function; |
||||||
|
|
||||||
|
import com.fr.design.formula.FormulaChecker; |
||||||
|
import com.fr.design.i18n.Toolkit; |
||||||
|
import com.fr.script.checker.result.FormulaCheckResult; |
||||||
|
import com.fr.script.checker.result.FormulaCoordinates; |
||||||
|
import com.fr.third.antlr.NoViableAltForCharException; |
||||||
|
|
||||||
|
import java.util.function.Function; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author Hoky |
||||||
|
* @date 2021/10/28 |
||||||
|
*/ |
||||||
|
public class NoViableAltForCharFunction implements Function<Exception, FormulaCheckResult> { |
||||||
|
private final static NoViableAltForCharFunction FUNCTION = new NoViableAltForCharFunction(); |
||||||
|
|
||||||
|
@Override |
||||||
|
public FormulaCheckResult apply(Exception e) { |
||||||
|
if (e instanceof NoViableAltForCharException) { |
||||||
|
NoViableAltForCharException charException = (NoViableAltForCharException) e; |
||||||
|
FormulaCoordinates formulaCoordinates = new FormulaCoordinates(charException.line, charException.column - 1); |
||||||
|
return new FormulaCheckResult(false, getMessage(charException), formulaCoordinates, false); |
||||||
|
} |
||||||
|
return new FormulaCheckResult(false, FormulaChecker.INVALID_FORMULA, FormulaCoordinates.INVALID, false); |
||||||
|
} |
||||||
|
|
||||||
|
public static Function<Exception, FormulaCheckResult> getFunction() { |
||||||
|
return FUNCTION; |
||||||
|
} |
||||||
|
|
||||||
|
public String getMessage(NoViableAltForCharException exception) { |
||||||
|
String mesg = Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Unexpected_Char") + ": "; |
||||||
|
if (exception.foundChar >= ' ' && exception.foundChar <= '~') { |
||||||
|
mesg = mesg + '\''; |
||||||
|
mesg = mesg + exception.foundChar; |
||||||
|
mesg = mesg + '\''; |
||||||
|
} else { |
||||||
|
mesg = mesg + exception.foundChar; |
||||||
|
} |
||||||
|
|
||||||
|
return mesg; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,41 @@ |
|||||||
|
package com.fr.design.formula.exception.function; |
||||||
|
|
||||||
|
import com.fr.design.formula.FormulaChecker; |
||||||
|
import com.fr.design.i18n.Toolkit; |
||||||
|
import com.fr.script.checker.result.FormulaCheckResult; |
||||||
|
import com.fr.script.checker.result.FormulaCoordinates; |
||||||
|
import com.fr.third.antlr.NoViableAltException; |
||||||
|
import com.fr.third.antlr.TreeParser; |
||||||
|
|
||||||
|
import java.util.function.Function; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author Hoky |
||||||
|
* @date 2021/10/28 |
||||||
|
*/ |
||||||
|
public class NoViableAltFunction implements Function<Exception, FormulaCheckResult> { |
||||||
|
private final static NoViableAltFunction FUNCTION = new NoViableAltFunction(); |
||||||
|
|
||||||
|
@Override |
||||||
|
public FormulaCheckResult apply(Exception e) { |
||||||
|
if (e instanceof NoViableAltException) { |
||||||
|
NoViableAltException altException = (NoViableAltException) e; |
||||||
|
FormulaCoordinates formulaCoordinates = new FormulaCoordinates(altException.line, altException.column - 1); |
||||||
|
return new FormulaCheckResult(false, getMessage(altException), formulaCoordinates, false); |
||||||
|
} |
||||||
|
return new FormulaCheckResult(false, FormulaChecker.INVALID_FORMULA, FormulaCoordinates.INVALID, false); |
||||||
|
} |
||||||
|
|
||||||
|
public static Function<Exception, FormulaCheckResult> getFunction() { |
||||||
|
return FUNCTION; |
||||||
|
} |
||||||
|
|
||||||
|
public String getMessage(NoViableAltException exception) { |
||||||
|
if (exception.token != null) { |
||||||
|
return Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Unexpected_Token") + ": " + exception.token.getText(); |
||||||
|
} else { |
||||||
|
return exception.node == TreeParser.ASTNULL ? Toolkit.i18nText("Fine-Design_Basic_Formula_Check_End_Of_Subtree") : |
||||||
|
Toolkit.i18nText("Fine-Design_Basic_Formula_Check_Unexpected_AST_Node") + ": " + exception.node.toString(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,22 @@ |
|||||||
|
package com.fr.design.gui.autocomplete; |
||||||
|
|
||||||
|
import javax.swing.Icon; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author Hoky |
||||||
|
* @date 2021/11/5 |
||||||
|
*/ |
||||||
|
public class FormulaCompletion extends BasicCompletion { |
||||||
|
private Icon icon; |
||||||
|
|
||||||
|
public FormulaCompletion(CompletionProvider provider, String replacementText, Icon icon) { |
||||||
|
super(provider, replacementText); |
||||||
|
this.icon = icon; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Icon getIcon() { |
||||||
|
return icon; |
||||||
|
} |
||||||
|
|
||||||
|
} |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,26 @@ |
|||||||
|
package com.fr.design.locale.impl; |
||||||
|
|
||||||
|
import com.fr.general.GeneralContext; |
||||||
|
import com.fr.general.locale.LocaleMark; |
||||||
|
|
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.Locale; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
public class ShowOnlineWidgetMark implements LocaleMark<Boolean> { |
||||||
|
private Map<Locale, Boolean> map = new HashMap<>(); |
||||||
|
|
||||||
|
public ShowOnlineWidgetMark() { |
||||||
|
map.put(Locale.CHINA, true); |
||||||
|
map.put(Locale.TAIWAN, true); |
||||||
|
map.put(Locale.US, false); |
||||||
|
map.put(Locale.KOREA, false); |
||||||
|
map.put(Locale.JAPAN, false); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Boolean getValue() { |
||||||
|
Boolean result = map.get(GeneralContext.getLocale()); |
||||||
|
return result == null ? false : result; |
||||||
|
} |
||||||
|
} |
@ -1,169 +0,0 @@ |
|||||||
package com.fr.design.mainframe.reuse; |
|
||||||
|
|
||||||
import com.fr.base.background.ColorBackground; |
|
||||||
import com.fr.design.dialog.UIDialog; |
|
||||||
import com.fr.design.gui.ilable.UILabel; |
|
||||||
import com.fr.design.i18n.Toolkit; |
|
||||||
import com.fr.design.layout.FRGUIPaneFactory; |
|
||||||
import com.fr.design.mainframe.PromptWindow; |
|
||||||
import com.fr.design.mainframe.share.collect.ComponentCollector; |
|
||||||
import com.fr.design.utils.gui.GUICoreUtils; |
|
||||||
import com.fr.general.IOUtils; |
|
||||||
|
|
||||||
import javax.swing.BorderFactory; |
|
||||||
import javax.swing.ImageIcon; |
|
||||||
import javax.swing.JButton; |
|
||||||
import javax.swing.JPanel; |
|
||||||
import java.awt.BorderLayout; |
|
||||||
import java.awt.Color; |
|
||||||
import java.awt.Dialog; |
|
||||||
import java.awt.Dimension; |
|
||||||
import java.awt.FlowLayout; |
|
||||||
import java.awt.Font; |
|
||||||
import java.awt.Frame; |
|
||||||
import java.awt.Graphics; |
|
||||||
import java.awt.Graphics2D; |
|
||||||
import java.awt.Image; |
|
||||||
import java.awt.RenderingHints; |
|
||||||
import java.awt.geom.RoundRectangle2D; |
|
||||||
|
|
||||||
public class ReuseGuideDialog extends UIDialog implements PromptWindow { |
|
||||||
InnerDialog innerDialog; |
|
||||||
private static final Dimension DEFAULT = new Dimension(735, 510); |
|
||||||
|
|
||||||
public ReuseGuideDialog(Frame parent) { |
|
||||||
super(parent); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void showWindow() { |
|
||||||
innerDialog = new InnerDialog(this); |
|
||||||
JPanel backGroundPane = new JPanel() { |
|
||||||
@Override |
|
||||||
protected void paintComponent(Graphics g) { |
|
||||||
Image icon = IOUtils.readImage("com/fr/base/images/share/background.png");// 003.jpg是测试图片在项目的根目录下
|
|
||||||
g.drawImage(icon, 0, 0, getSize().width, getSize().height, this);// 图片会自动缩放
|
|
||||||
} |
|
||||||
}; |
|
||||||
add(backGroundPane, BorderLayout.CENTER); |
|
||||||
initStyle(); |
|
||||||
innerDialog.showWindow(); |
|
||||||
} |
|
||||||
|
|
||||||
private void initStyle() { |
|
||||||
setSize(DEFAULT); |
|
||||||
setUndecorated(true); |
|
||||||
setBackground(new Color(0, 0, 0, 0)); |
|
||||||
GUICoreUtils.centerWindow(this); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void hideWindow() { |
|
||||||
ComponentReuseNotificationInfo.getInstance().updateLastGuidePopUpTime(); |
|
||||||
this.setVisible(false); |
|
||||||
if (innerDialog != null) { |
|
||||||
innerDialog.setVisible(false); |
|
||||||
innerDialog.dispose(); |
|
||||||
innerDialog = null; |
|
||||||
} |
|
||||||
this.dispose(); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void checkValid() { |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
class InnerDialog extends UIDialog { |
|
||||||
private final Dimension DEFAULT = new Dimension(700, 475); |
|
||||||
private static final int TITLE_FONT_SIZE = 20; |
|
||||||
|
|
||||||
public InnerDialog(Dialog dialog) { |
|
||||||
super(dialog); |
|
||||||
} |
|
||||||
|
|
||||||
public void showWindow() { |
|
||||||
add(createCenterPanel(), BorderLayout.CENTER); |
|
||||||
add(createSouthPanel(), BorderLayout.SOUTH); |
|
||||||
add(createNorthPanel(), BorderLayout.NORTH); |
|
||||||
showDialog(); |
|
||||||
} |
|
||||||
|
|
||||||
private JPanel createNorthPanel() { |
|
||||||
JPanel northPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); |
|
||||||
|
|
||||||
//右上角关闭按钮
|
|
||||||
JButton button = new JButton(new ImageIcon(IOUtils.readImage("/com/fr/base/images/share/close.png").getScaledInstance(15, 15, Image.SCALE_SMOOTH))); |
|
||||||
button.setBorder(null); |
|
||||||
button.setOpaque(false); |
|
||||||
button.addActionListener(e -> ReuseGuideDialog.this.hideWindow()); |
|
||||||
|
|
||||||
northPanel.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 15)); |
|
||||||
northPanel.setOpaque(false); |
|
||||||
northPanel.add(button); |
|
||||||
return northPanel; |
|
||||||
} |
|
||||||
|
|
||||||
private JPanel createCenterPanel() { |
|
||||||
JPanel centerPanel = new JPanel(new BorderLayout()); |
|
||||||
|
|
||||||
UILabel titleLabel = new UILabel(Toolkit.i18nText("Fine-Design_Share_Drag_And_Make_Component")); |
|
||||||
UILabel imageLabel = new UILabel(new ImageIcon(IOUtils.readImage("com/fr/design/images/dashboard/guide.png").getScaledInstance(DEFAULT.width, DEFAULT.height, Image.SCALE_SMOOTH))); |
|
||||||
titleLabel.setFont(new Font(titleLabel.getFont().getName(), Font.BOLD, TITLE_FONT_SIZE)); |
|
||||||
titleLabel.setBorder(BorderFactory.createEmptyBorder()); |
|
||||||
|
|
||||||
JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER)); |
|
||||||
panel.setOpaque(false); |
|
||||||
panel.add(titleLabel); |
|
||||||
|
|
||||||
centerPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0)); |
|
||||||
centerPanel.setOpaque(false); |
|
||||||
centerPanel.add(imageLabel, BorderLayout.CENTER); |
|
||||||
centerPanel.add(panel, BorderLayout.NORTH); |
|
||||||
return centerPanel; |
|
||||||
} |
|
||||||
|
|
||||||
private JPanel createSouthPanel() { |
|
||||||
JPanel southPanel = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
|
||||||
|
|
||||||
JButton button = new JButton(Toolkit.i18nText("Fine-Design_Share_Try_Drag")) { |
|
||||||
@Override |
|
||||||
public void paint(Graphics g) { |
|
||||||
ColorBackground buttonBackground = ColorBackground.getInstance(Color.decode("#419BF9")); |
|
||||||
Graphics2D g2d = (Graphics2D) g; |
|
||||||
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); |
|
||||||
buttonBackground.paint(g2d, new RoundRectangle2D.Double(0, 0, getWidth(), getHeight(), 8, 8)); |
|
||||||
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); |
|
||||||
super.paint(g); |
|
||||||
} |
|
||||||
}; |
|
||||||
button.setBorder(null); |
|
||||||
button.setForeground(Color.WHITE); |
|
||||||
button.setOpaque(false); |
|
||||||
button.addActionListener(e -> ReuseGuideDialog.this.hideWindow()); |
|
||||||
|
|
||||||
southPanel.setBorder(BorderFactory.createEmptyBorder(0, 290, 19, 290)); |
|
||||||
southPanel.setPreferredSize(new Dimension(DEFAULT.width, 51)); |
|
||||||
southPanel.setOpaque(false); |
|
||||||
southPanel.add(button); |
|
||||||
return southPanel; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* 显示窗口 |
|
||||||
*/ |
|
||||||
private void showDialog() { |
|
||||||
setSize(DEFAULT); |
|
||||||
setUndecorated(true); |
|
||||||
GUICoreUtils.centerWindow(this); |
|
||||||
setModalityType(ModalityType.APPLICATION_MODAL); |
|
||||||
ReuseGuideDialog.this.setVisible(true); |
|
||||||
setVisible(true); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void checkValid() { |
|
||||||
|
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,99 @@ |
|||||||
|
package com.fr.design.mainframe.share; |
||||||
|
|
||||||
|
import com.fr.design.DesignerEnvManager; |
||||||
|
import com.fr.design.file.HistoryTemplateListCache; |
||||||
|
import com.fr.design.mainframe.JTemplate; |
||||||
|
import com.fr.design.mainframe.reuse.ComponentReuseNotificationInfo; |
||||||
|
import com.fr.form.share.constants.ComponentPath; |
||||||
|
import com.fr.form.share.group.filter.ReuFilter; |
||||||
|
import com.fr.design.DesignerCloudURLManager; |
||||||
|
import com.fr.workspace.WorkContext; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by kerry on 2021/10/27 |
||||||
|
*/ |
||||||
|
public class ComponentShareUtil { |
||||||
|
private ComponentShareUtil() { |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 判断是否需要切换到在线组件库 |
||||||
|
* |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static boolean needSwitch2OnlineTab() { |
||||||
|
return DesignerCloudURLManager.getInstance().isConnected() && !hasTouched() && isCurrentTplNewCreate(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 判断是否可触达 |
||||||
|
* |
||||||
|
* @return boolean |
||||||
|
*/ |
||||||
|
public static boolean hasTouched() { |
||||||
|
String sharePath = ComponentPath.SHARE_PATH.path(); |
||||||
|
String[] components = WorkContext.getWorkResource().list(sharePath, new ReuFilter()); |
||||||
|
return components != null && components.length > 6; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 判断当前模板是否是新建模板 |
||||||
|
* |
||||||
|
* @return boolean |
||||||
|
*/ |
||||||
|
public static boolean isCurrentTplNewCreate() { |
||||||
|
JTemplate jTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); |
||||||
|
return jTemplate.isNewCreateTpl(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 判断是否在需要展示组件库界面 |
||||||
|
* |
||||||
|
* @return boolean |
||||||
|
*/ |
||||||
|
public static boolean needShowEmbedFilterPane() { |
||||||
|
return !ComponentReuseNotificationInfo.getInstance().isCompleteEmbedFilter() && !hasTouched() && isCurrentTplNewCreate(); |
||||||
|
} |
||||||
|
|
||||||
|
public static boolean needShowComponentLib() { |
||||||
|
return !ComponentReuseNotificationInfo.getInstance().isCompleteFirstShowComponentLib() && !hasTouched() && isCurrentTplNewCreate(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 判断是否需要展示首次拖拽动效 |
||||||
|
* |
||||||
|
* @return boolean |
||||||
|
*/ |
||||||
|
public static boolean needShowFirstDragAnimate() { |
||||||
|
return ComponentReuseNotificationInfo.getInstance().isFirstDrag(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 完成嵌入式筛选 |
||||||
|
*/ |
||||||
|
public static void completeEmbedFilter() { |
||||||
|
boolean changed = false; |
||||||
|
if (!ComponentReuseNotificationInfo.getInstance().isWidgetLibHasRefreshed()) { |
||||||
|
ComponentReuseNotificationInfo.getInstance().setWidgetLibHasRefreshed(true); |
||||||
|
changed = true; |
||||||
|
} |
||||||
|
if (!ComponentReuseNotificationInfo.getInstance().isCompleteEmbedFilter()) { |
||||||
|
ComponentReuseNotificationInfo.getInstance().setCompleteEmbedFilter(true); |
||||||
|
changed = true; |
||||||
|
} |
||||||
|
if (changed) { |
||||||
|
DesignerEnvManager.getEnvManager().saveXMLFile(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 记录组件库刷新 |
||||||
|
*/ |
||||||
|
public static void recordWidgetLibHasRefreshed() { |
||||||
|
if (!ComponentReuseNotificationInfo.getInstance().isWidgetLibHasRefreshed()) { |
||||||
|
ComponentReuseNotificationInfo.getInstance().setWidgetLibHasRefreshed(true); |
||||||
|
DesignerEnvManager.getEnvManager().saveXMLFile(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
After Width: | Height: | Size: 279 B |
After Width: | Height: | Size: 383 B |
@ -1,217 +0,0 @@ |
|||||||
|
|
||||||
|
|
||||||
package com.fr.design.mainframe; |
|
||||||
|
|
||||||
import com.fr.base.iofile.attr.ExtendSharableAttrMark; |
|
||||||
import com.fr.design.DesignerEnvManager; |
|
||||||
import com.fr.design.file.HistoryTemplateListCache; |
|
||||||
import com.fr.design.gui.ilable.UILabel; |
|
||||||
import com.fr.design.i18n.Toolkit; |
|
||||||
import com.fr.design.layout.FRGUIPaneFactory; |
|
||||||
import com.fr.design.mainframe.adaptve.config.TriggerPointProvider; |
|
||||||
|
|
||||||
import com.fr.design.mainframe.adaptve.config.impl.CellStyleTriggerPoint; |
|
||||||
import com.fr.design.mainframe.adaptve.config.impl.CellValueImageChangeTriggerPoint; |
|
||||||
import com.fr.design.mainframe.adaptve.config.ReuseNotifyInfo; |
|
||||||
import com.fr.design.mainframe.reuse.ComponentReuseNotificationInfo; |
|
||||||
import com.fr.design.mainframe.share.collect.ComponentCollector; |
|
||||||
import com.fr.design.mainframe.toast.DesignerToastMsgUtil; |
|
||||||
import com.fr.event.Event; |
|
||||||
import com.fr.event.EventDispatcher; |
|
||||||
import com.fr.event.Listener; |
|
||||||
import com.fr.event.Null; |
|
||||||
import com.fr.form.main.Form; |
|
||||||
import com.fr.form.main.WidgetGather; |
|
||||||
import com.fr.form.ui.AbstractBorderStyleWidget; |
|
||||||
import com.fr.form.ui.Widget; |
|
||||||
import com.fr.stable.StringUtils; |
|
||||||
|
|
||||||
import javax.swing.BorderFactory; |
|
||||||
import javax.swing.JPanel; |
|
||||||
import java.awt.BorderLayout; |
|
||||||
import java.awt.Color; |
|
||||||
import java.awt.Cursor; |
|
||||||
import java.awt.event.MouseEvent; |
|
||||||
import java.awt.event.MouseListener; |
|
||||||
import java.util.ArrayList; |
|
||||||
import java.util.HashMap; |
|
||||||
import java.util.Iterator; |
|
||||||
import java.util.List; |
|
||||||
import java.util.Map; |
|
||||||
|
|
||||||
/** |
|
||||||
* Created by kerry on 4/28/21 |
|
||||||
*/ |
|
||||||
public class ReuseTriggerPointManager { |
|
||||||
private static final long ONE_WEEK_TIME = 7 * 24 * 3600 * 1000L; |
|
||||||
|
|
||||||
private static class Holder { |
|
||||||
private static final ReuseTriggerPointManager HOLDER = new ReuseTriggerPointManager(); |
|
||||||
} |
|
||||||
|
|
||||||
public static ReuseTriggerPointManager getInstance() { |
|
||||||
return Holder.HOLDER; |
|
||||||
} |
|
||||||
|
|
||||||
private Map<JForm, ReuseNotifyInfo> map = new HashMap<>(); |
|
||||||
|
|
||||||
private List<Listener> listeners = new ArrayList<>(); |
|
||||||
|
|
||||||
private ReuseTriggerPointManager() { |
|
||||||
if (!hasNotifiedTwice()) { |
|
||||||
List<TriggerPointProvider> list = getTriggerPoints(); |
|
||||||
for (TriggerPointProvider triggerPoint : list) { |
|
||||||
Listener listener = new Listener<Null>() { |
|
||||||
@Override |
|
||||||
public void on(Event event, Null o) { |
|
||||||
triggerPoint.triggerAction(); |
|
||||||
} |
|
||||||
}; |
|
||||||
EventDispatcher.listen(triggerPoint.triggerEvent(), listener); |
|
||||||
listeners.add(listener); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private List<TriggerPointProvider> getTriggerPoints() { |
|
||||||
List<TriggerPointProvider> list = new ArrayList<>(); |
|
||||||
list.add(new CellStyleTriggerPoint()); |
|
||||||
list.add(new CellValueImageChangeTriggerPoint()); |
|
||||||
return list; |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
public boolean hasNotifiedTwice() { |
|
||||||
return ComponentReuseNotificationInfo.getInstance().getNotifiedNumber() >= 2; |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
private void reCount() { |
|
||||||
//重新计次数
|
|
||||||
Iterator<Map.Entry<JForm, ReuseNotifyInfo>> iterator = map.entrySet().iterator(); |
|
||||||
while (iterator.hasNext()) { |
|
||||||
iterator.next().getValue().reset(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private void writeTriggerInfo2xml() { |
|
||||||
int number = ComponentReuseNotificationInfo.getInstance().getNotifiedNumber() + 1; |
|
||||||
ComponentReuseNotificationInfo.getInstance().setNotifiedNumber(number); |
|
||||||
ComponentReuseNotificationInfo.getInstance().setLastNotifyTime(System.currentTimeMillis()); |
|
||||||
DesignerEnvManager.getEnvManager().saveXMLFile(); |
|
||||||
//如果已经提示过两次了
|
|
||||||
if (hasNotifiedTwice()) { |
|
||||||
for (Listener listener : listeners) { |
|
||||||
EventDispatcher.stopListen(listener); |
|
||||||
} |
|
||||||
this.map.clear(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public boolean needTrigger() { |
|
||||||
boolean result = true; |
|
||||||
if (ComponentReuseNotificationInfo.getInstance().getLastNotifyTime() > 0L) { |
|
||||||
result = System.currentTimeMillis() - ComponentReuseNotificationInfo.getInstance().getLastNotifyTime() > ONE_WEEK_TIME; |
|
||||||
} |
|
||||||
return !hasNotifiedTwice() && result; |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
public void registerJForm(JForm jForm) { |
|
||||||
if (!hasNotifiedTwice()) { |
|
||||||
this.map.put(jForm, new ReuseNotifyInfo()); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
public void removeJForm(JForm jForm) { |
|
||||||
if (!hasNotifiedTwice()) { |
|
||||||
this.map.remove(jForm); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
public ReuseNotifyInfo getReuseNotifyInfo() { |
|
||||||
JTemplate currentJTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); |
|
||||||
if (!(currentJTemplate instanceof JForm && hasUseReuseComponent((JForm) currentJTemplate)) |
|
||||||
&& !ReuseTriggerPointManager.getInstance().needTrigger()) { |
|
||||||
return null; |
|
||||||
} |
|
||||||
return map.get(currentJTemplate); |
|
||||||
} |
|
||||||
|
|
||||||
public void reuseNotify(ReuseNotifyInfo notifyInfo) { |
|
||||||
if (notifyInfo.matchCondition()) { |
|
||||||
ReuseTriggerPointManager.getInstance().reCount(); |
|
||||||
//弹出提示框
|
|
||||||
JTemplate currentJTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); |
|
||||||
DesignerToastMsgUtil.toastPrompt(createReusePrompt((JForm) currentJTemplate)); |
|
||||||
ReuseTriggerPointManager.getInstance().writeTriggerInfo2xml(); |
|
||||||
ComponentCollector.getInstance().collectPromptJumpWhenShow(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
private boolean hasUseReuseComponent(JForm jForm) { |
|
||||||
Form form = jForm.getTarget(); |
|
||||||
List<Widget> extendSharableWidgetList = new ArrayList<>(); |
|
||||||
Form.traversalWidget(form.getContainer(), new WidgetGather() { |
|
||||||
@Override |
|
||||||
public void dealWith(Widget widget) { |
|
||||||
ExtendSharableAttrMark attrMark = ((AbstractBorderStyleWidget) widget).getWidgetAttrMark(ExtendSharableAttrMark.XML_TAG); |
|
||||||
if (attrMark != null && StringUtils.isNotEmpty(attrMark.getShareId())) { |
|
||||||
extendSharableWidgetList.add(widget); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public boolean dealWithAllCards() { |
|
||||||
return true; |
|
||||||
} |
|
||||||
}, AbstractBorderStyleWidget.class); |
|
||||||
return extendSharableWidgetList.size() > 0; |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
private JPanel createReusePrompt(JForm jForm) { |
|
||||||
JPanel jPanel = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
|
||||||
jPanel.add(new UILabel(Toolkit.i18nText("Fine-Design_Component_Reuse_Try_Prompt")), BorderLayout.WEST); |
|
||||||
UILabel reuseLabel = new UILabel(Toolkit.i18nText("Fine-Design_Share_Component")); |
|
||||||
reuseLabel.addMouseListener(new MouseListener() { |
|
||||||
@Override |
|
||||||
public void mouseClicked(MouseEvent e) { |
|
||||||
jForm.tabChanged(0); |
|
||||||
FormWidgetDetailPane.getInstance().enterWidgetLib(); |
|
||||||
ComponentCollector.getInstance().collectPromptJumpWhenJump(); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void mousePressed(MouseEvent e) { |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void mouseReleased(MouseEvent e) { |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void mouseEntered(MouseEvent e) { |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void mouseExited(MouseEvent e) { |
|
||||||
|
|
||||||
} |
|
||||||
}); |
|
||||||
reuseLabel.setBorder(BorderFactory.createEmptyBorder(0, 3, 0, 0)); |
|
||||||
reuseLabel.setForeground(Color.BLUE); |
|
||||||
reuseLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
|
||||||
jPanel.add(reuseLabel, BorderLayout.CENTER); |
|
||||||
return jPanel; |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
} |
|
@ -1,30 +0,0 @@ |
|||||||
package com.fr.design.mainframe.adaptve.config; |
|
||||||
|
|
||||||
/** |
|
||||||
* Created by kerry on 5/7/21 |
|
||||||
*/ |
|
||||||
public class ReuseNotifyInfo { |
|
||||||
private static final int CELL_STYLE_MODIFY_MAX_NUMBER = 3; |
|
||||||
private static final int CELL_IMAGE_VALUE_MODIFY_MAX_NUMBER = 1; |
|
||||||
private int cellStyleModifiedNumber = 0; |
|
||||||
private int cellImageValueNumber = 0; |
|
||||||
|
|
||||||
public void addCellStyleModify() { |
|
||||||
cellStyleModifiedNumber++; |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
public void addCellImageValueModify() { |
|
||||||
cellImageValueNumber++; |
|
||||||
} |
|
||||||
|
|
||||||
public boolean matchCondition() { |
|
||||||
return cellStyleModifiedNumber >= CELL_STYLE_MODIFY_MAX_NUMBER |
|
||||||
|| cellImageValueNumber >= CELL_IMAGE_VALUE_MODIFY_MAX_NUMBER; |
|
||||||
} |
|
||||||
|
|
||||||
public void reset() { |
|
||||||
this.cellImageValueNumber = 0; |
|
||||||
this.cellStyleModifiedNumber = 0; |
|
||||||
} |
|
||||||
} |
|
@ -1,20 +0,0 @@ |
|||||||
package com.fr.design.mainframe.adaptve.config; |
|
||||||
|
|
||||||
|
|
||||||
import com.fr.event.Event; |
|
||||||
|
|
||||||
/** |
|
||||||
* Created by kerry on 4/29/21 |
|
||||||
*/ |
|
||||||
public interface TriggerPointProvider { |
|
||||||
/** |
|
||||||
* 触发后的操作 |
|
||||||
*/ |
|
||||||
void triggerAction(); |
|
||||||
|
|
||||||
/** |
|
||||||
* 触发事件 |
|
||||||
* @return |
|
||||||
*/ |
|
||||||
Event triggerEvent(); |
|
||||||
} |
|
@ -1,28 +0,0 @@ |
|||||||
package com.fr.design.mainframe.adaptve.config.impl; |
|
||||||
|
|
||||||
import com.fr.design.mainframe.DesignOperationEvent; |
|
||||||
import com.fr.design.mainframe.ReuseTriggerPointManager; |
|
||||||
import com.fr.design.mainframe.adaptve.config.ReuseNotifyInfo; |
|
||||||
import com.fr.design.mainframe.adaptve.config.TriggerPointProvider; |
|
||||||
import com.fr.event.Event; |
|
||||||
|
|
||||||
/** |
|
||||||
* Created by kerry on 5/7/21 |
|
||||||
*/ |
|
||||||
public class CellStyleTriggerPoint implements TriggerPointProvider { |
|
||||||
@Override |
|
||||||
public void triggerAction() { |
|
||||||
ReuseNotifyInfo notifyInfo = ReuseTriggerPointManager.getInstance().getReuseNotifyInfo(); |
|
||||||
if (notifyInfo == null) { |
|
||||||
return; |
|
||||||
} |
|
||||||
notifyInfo.addCellStyleModify(); |
|
||||||
ReuseTriggerPointManager.getInstance().reuseNotify(notifyInfo); |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public Event triggerEvent() { |
|
||||||
return DesignOperationEvent.CELL_STYLE_MODIFY; |
|
||||||
} |
|
||||||
} |
|
@ -1,27 +0,0 @@ |
|||||||
package com.fr.design.mainframe.adaptve.config.impl; |
|
||||||
|
|
||||||
import com.fr.design.mainframe.DesignOperationEvent; |
|
||||||
import com.fr.design.mainframe.ReuseTriggerPointManager; |
|
||||||
import com.fr.design.mainframe.adaptve.config.ReuseNotifyInfo; |
|
||||||
import com.fr.design.mainframe.adaptve.config.TriggerPointProvider; |
|
||||||
import com.fr.event.Event; |
|
||||||
|
|
||||||
/** |
|
||||||
* Created by kerry on 5/7/21 |
|
||||||
*/ |
|
||||||
public class CellValueImageChangeTriggerPoint implements TriggerPointProvider { |
|
||||||
@Override |
|
||||||
public void triggerAction() { |
|
||||||
ReuseNotifyInfo notifyInfo = ReuseTriggerPointManager.getInstance().getReuseNotifyInfo(); |
|
||||||
if (notifyInfo == null) { |
|
||||||
return; |
|
||||||
} |
|
||||||
notifyInfo.addCellImageValueModify(); |
|
||||||
ReuseTriggerPointManager.getInstance().reuseNotify(notifyInfo); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public Event triggerEvent() { |
|
||||||
return DesignOperationEvent.CELL_IMAGE_VALUE_MODIFY; |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,44 @@ |
|||||||
|
package com.fr.design.mainframe.share.Bean; |
||||||
|
|
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by kerry on 2021/11/1 |
||||||
|
*/ |
||||||
|
public class FilterTypeInfo { |
||||||
|
private String title; |
||||||
|
private String key; |
||||||
|
private final List<WidgetFilterTypeInfo> filterTypeInfos = new ArrayList<>(); |
||||||
|
|
||||||
|
public FilterTypeInfo(String title, String key){ |
||||||
|
this.title = title; |
||||||
|
this.key = key; |
||||||
|
} |
||||||
|
|
||||||
|
public String getTitle() { |
||||||
|
return title; |
||||||
|
} |
||||||
|
|
||||||
|
public void setTitle(String title) { |
||||||
|
this.title = title; |
||||||
|
} |
||||||
|
|
||||||
|
public String getKey() { |
||||||
|
return key; |
||||||
|
} |
||||||
|
|
||||||
|
public void setKey(String key) { |
||||||
|
this.key = key; |
||||||
|
} |
||||||
|
|
||||||
|
public void addFilterType(WidgetFilterTypeInfo info){ |
||||||
|
this.filterTypeInfos.add(info); |
||||||
|
} |
||||||
|
|
||||||
|
public List<WidgetFilterTypeInfo> getFilterTypeInfos(){ |
||||||
|
return filterTypeInfos; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,60 @@ |
|||||||
|
package com.fr.design.mainframe.share.Bean; |
||||||
|
|
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by kerry on 2020-10-23 |
||||||
|
*/ |
||||||
|
public class WidgetFilterInfo { |
||||||
|
private String name; |
||||||
|
private String id; |
||||||
|
private String type; |
||||||
|
private List<WidgetFilterInfo> childFilterInfo = new ArrayList<>(); |
||||||
|
|
||||||
|
public WidgetFilterInfo(String name, String id, String type) { |
||||||
|
this.name = name; |
||||||
|
this.id = id; |
||||||
|
this.type = type; |
||||||
|
} |
||||||
|
|
||||||
|
public WidgetFilterInfo() { |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
public String getName() { |
||||||
|
return name; |
||||||
|
} |
||||||
|
|
||||||
|
public void setName(String name) { |
||||||
|
this.name = name; |
||||||
|
} |
||||||
|
|
||||||
|
public String getId() { |
||||||
|
return id; |
||||||
|
} |
||||||
|
|
||||||
|
public void setId(String id) { |
||||||
|
this.id = id; |
||||||
|
} |
||||||
|
|
||||||
|
public String getType() { |
||||||
|
return type; |
||||||
|
} |
||||||
|
|
||||||
|
public void setType(String type) { |
||||||
|
this.type = type; |
||||||
|
} |
||||||
|
|
||||||
|
public void addChildFilterInfo(WidgetFilterInfo filterInfo) { |
||||||
|
this.childFilterInfo.add(filterInfo); |
||||||
|
} |
||||||
|
|
||||||
|
public List<WidgetFilterInfo> getInnerFilterInfo() { |
||||||
|
return childFilterInfo; |
||||||
|
} |
||||||
|
|
||||||
|
public boolean hasChildFilter() { |
||||||
|
return childFilterInfo.size() > 0; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,93 @@ |
|||||||
|
package com.fr.design.mainframe.share.Bean; |
||||||
|
|
||||||
|
import com.fr.design.i18n.Toolkit; |
||||||
|
import com.fr.design.mainframe.share.util.ShareFilterConstants; |
||||||
|
import com.fr.general.ComparatorUtils; |
||||||
|
import com.fr.json.JSONArray; |
||||||
|
import com.fr.json.JSONObject; |
||||||
|
|
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by kerry on 2020-10-21 |
||||||
|
*/ |
||||||
|
public class WidgetFilterTypeInfo { |
||||||
|
private static final String KEY_SPLIT_CHAR = "@"; |
||||||
|
private String title; |
||||||
|
private String key; |
||||||
|
private List<WidgetFilterInfo> filterItems = new ArrayList<>(); |
||||||
|
|
||||||
|
public String getTitle() { |
||||||
|
return title; |
||||||
|
} |
||||||
|
|
||||||
|
public void setTitle(String title) { |
||||||
|
this.title = title; |
||||||
|
} |
||||||
|
|
||||||
|
public String getKey() { |
||||||
|
return key; |
||||||
|
} |
||||||
|
|
||||||
|
public void setKey(String key) { |
||||||
|
this.key = key; |
||||||
|
} |
||||||
|
|
||||||
|
public List<WidgetFilterInfo> getFilterItems() { |
||||||
|
return filterItems; |
||||||
|
} |
||||||
|
|
||||||
|
public void addFilterItem(WidgetFilterInfo filterInfo) { |
||||||
|
this.filterItems.add(filterInfo); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
public static WidgetFilterTypeInfo parseFromJSONObject(JSONObject jsonObject) { |
||||||
|
WidgetFilterTypeInfo typeInfo = new WidgetFilterTypeInfo(); |
||||||
|
typeInfo.setTitle(jsonObject.getString("title")); |
||||||
|
typeInfo.setKey(jsonObject.getString("key")); |
||||||
|
JSONArray ja = jsonObject.getJSONArray("items"); |
||||||
|
if (ComparatorUtils.equals(typeInfo.getKey(), ShareFilterConstants.STYLE_FILTER_KEY)) { |
||||||
|
createStyleFilterType(ja, typeInfo); |
||||||
|
} else { |
||||||
|
for (int i = 0; i < ja.size(); i++) { |
||||||
|
JSONObject jo = ja.getJSONObject(i); |
||||||
|
WidgetFilterInfo info = new WidgetFilterInfo(); |
||||||
|
info.setId(jo.getString("id")); |
||||||
|
info.setName(jo.optString("name")); |
||||||
|
info.setType(parseType(typeInfo.getKey())); |
||||||
|
typeInfo.addFilterItem(info); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return typeInfo; |
||||||
|
} |
||||||
|
|
||||||
|
private static void createStyleFilterType(JSONArray ja, WidgetFilterTypeInfo typeInfo) { |
||||||
|
WidgetFilterInfo dark = new WidgetFilterInfo(); |
||||||
|
dark.setName(Toolkit.i18nText("Fine-Design_Share_Local_Filter_Dark_Style")); |
||||||
|
WidgetFilterInfo light = new WidgetFilterInfo(); |
||||||
|
light.setName(Toolkit.i18nText("Fine-Design_Share_Local_Filter_Light_Style")); |
||||||
|
typeInfo.addFilterItem(dark); |
||||||
|
typeInfo.addFilterItem(light); |
||||||
|
for (int i = 0; i < ja.size(); i++) { |
||||||
|
JSONObject jo = ja.getJSONObject(i); |
||||||
|
WidgetFilterInfo info = new WidgetFilterInfo(); |
||||||
|
info.setId(jo.getString("id")); |
||||||
|
info.setName(jo.optString("name")); |
||||||
|
info.setType(parseType(typeInfo.getKey())); |
||||||
|
if (ComparatorUtils.equals(jo.getInt("themeColor"), 0)) { |
||||||
|
dark.addChildFilterInfo(info); |
||||||
|
} else { |
||||||
|
light.addChildFilterInfo(info); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private static String parseType(String text) { |
||||||
|
return text.split(KEY_SPLIT_CHAR)[1]; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,82 @@ |
|||||||
|
package com.fr.design.mainframe.share.config; |
||||||
|
|
||||||
|
import com.fr.design.DesignerCloudURLManager; |
||||||
|
import com.fr.log.FineLoggerFactory; |
||||||
|
import com.fr.stable.ProductConstants; |
||||||
|
import com.fr.stable.StableUtils; |
||||||
|
import com.fr.stable.StringUtils; |
||||||
|
|
||||||
|
import java.io.File; |
||||||
|
import java.io.FileInputStream; |
||||||
|
import java.io.InputStream; |
||||||
|
import java.util.Properties; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by kerry on 2020-12-14 |
||||||
|
*/ |
||||||
|
public class ComponentReuseConfigManager { |
||||||
|
|
||||||
|
private static class Holder { |
||||||
|
private static final ComponentReuseConfigManager HOLDER = new ComponentReuseConfigManager(); |
||||||
|
} |
||||||
|
|
||||||
|
private static final String PROPERTIES_FILE_NAME = "reuse.properties"; |
||||||
|
private static final String MINI_SHOP_URL = "MINI_SHOP_URL"; |
||||||
|
private static final String COMPONENT_UPLOAD_URL = "COMPONENT_UPLOAD_URL"; |
||||||
|
private static final String MARKET_LOGIN_URL = "MARKET_LOGIN_URL"; |
||||||
|
private static final String UPLOAD_REU_SUPPORT = "UPLOAD_REU_SUPPORT"; |
||||||
|
|
||||||
|
public static ComponentReuseConfigManager getInstance() { |
||||||
|
return ComponentReuseConfigManager.Holder.HOLDER; |
||||||
|
} |
||||||
|
|
||||||
|
private Properties properties; |
||||||
|
|
||||||
|
private ComponentReuseConfigManager() { |
||||||
|
} |
||||||
|
|
||||||
|
private File getReusePropertyFile() { |
||||||
|
File file = new File(StableUtils.pathJoin(ProductConstants.getEnvHome(), PROPERTIES_FILE_NAME)); |
||||||
|
return file; |
||||||
|
} |
||||||
|
|
||||||
|
private String loadAttribute(String key, String defaultValue) { |
||||||
|
if (properties == null) { |
||||||
|
properties = new Properties(); |
||||||
|
File file = getReusePropertyFile(); |
||||||
|
if (!file.exists()) { |
||||||
|
return defaultValue; |
||||||
|
} |
||||||
|
try { |
||||||
|
InputStream in = new FileInputStream(file); |
||||||
|
properties.load(in); |
||||||
|
} catch (Exception e) { |
||||||
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||||
|
} |
||||||
|
} |
||||||
|
String p = properties.getProperty(key); |
||||||
|
if (StringUtils.isEmpty(p)) { |
||||||
|
p = defaultValue; |
||||||
|
} |
||||||
|
return p; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
public String getMiniShopUrl() { |
||||||
|
return loadAttribute(MINI_SHOP_URL, DesignerCloudURLManager.getInstance().acquireUrlByKind("af.reuseInfo")); |
||||||
|
} |
||||||
|
|
||||||
|
public String getComponentUploadUrl() { |
||||||
|
//云中心暂时没有上传网址,这边默认值为空,后续再添加
|
||||||
|
return loadAttribute(COMPONENT_UPLOAD_URL, StringUtils.EMPTY); |
||||||
|
} |
||||||
|
|
||||||
|
public String getMarketLoginUrl() { |
||||||
|
return loadAttribute(MARKET_LOGIN_URL, DesignerCloudURLManager.getInstance().acquireUrlByKind("market.login")); |
||||||
|
} |
||||||
|
|
||||||
|
public boolean supportUploadReu() { |
||||||
|
String uploadReuSupport = loadAttribute(UPLOAD_REU_SUPPORT, "false"); |
||||||
|
return Boolean.valueOf(uploadReuSupport); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,53 @@ |
|||||||
|
package com.fr.design.mainframe.share.ui.block; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by kerry on 2021/10/29 |
||||||
|
* 贝塞尔缓动函数实现 https://www.xuanfengge.com/easeing/easeing/
|
||||||
|
*/ |
||||||
|
public class BezierCubic { |
||||||
|
private final double px1; |
||||||
|
private final double px2; |
||||||
|
private final double px3; |
||||||
|
private final double py1; |
||||||
|
private final double py2; |
||||||
|
private final double py3; |
||||||
|
private final double epsilon; |
||||||
|
|
||||||
|
public BezierCubic(double a, double b, double c, double d) { |
||||||
|
this.px3 = 3 * a; |
||||||
|
this.px2 = 3 * (c - a) - this.px3; |
||||||
|
this.px1 = 1 - this.px3 - this.px2; |
||||||
|
this.py3 = 3 * b; |
||||||
|
this.py2 = 3 * (d - b) - this.py3; |
||||||
|
this.py1 = 1 - this.py3 - this.py2; |
||||||
|
this.epsilon = 1e-7; // 目标精度
|
||||||
|
} |
||||||
|
|
||||||
|
public double getX(double t) { |
||||||
|
return ((this.px1 * t + this.px2) * t + this.px3) * t; |
||||||
|
} |
||||||
|
|
||||||
|
public double getY(double t) { |
||||||
|
return ((this.py1 * t + this.py2) * t + this.py3) * t; |
||||||
|
} |
||||||
|
|
||||||
|
public double solve(double x) { |
||||||
|
if (x == 0 || x == 1) { // 对 0 和 1 两个特殊 t 不做计算
|
||||||
|
return this.getY(x); |
||||||
|
} |
||||||
|
double t = x; |
||||||
|
for (int i = 0; i < 8; i++) { // 进行 8 次迭代
|
||||||
|
double g = this.getX(t) - x; |
||||||
|
if (Math.abs(g) < this.epsilon) { // 检测误差到可以接受的范围
|
||||||
|
return this.getY(t); |
||||||
|
} |
||||||
|
double d = (3 * this.px1 * t + 2 * this.px2) * t + this.px3; // 对 x 求导
|
||||||
|
if (Math.abs(d) < 1e-6) { // 如果梯度过低,说明牛顿迭代法无法达到更高精度
|
||||||
|
break; |
||||||
|
} |
||||||
|
t = t - g / d; |
||||||
|
} |
||||||
|
return this.getY(t); // 对得到的近似 t 求 y
|
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,178 @@ |
|||||||
|
package com.fr.design.mainframe.share.ui.block; |
||||||
|
|
||||||
|
import com.fr.design.DesignerEnvManager; |
||||||
|
import com.fr.design.extra.Process; |
||||||
|
import com.fr.design.login.DesignerLoginHelper; |
||||||
|
import com.fr.design.login.DesignerLoginSource; |
||||||
|
import com.fr.design.mainframe.share.collect.ComponentCollector; |
||||||
|
import com.fr.design.mainframe.share.ui.online.OnlineWidgetRepoPane; |
||||||
|
import com.fr.design.mainframe.share.util.DownloadUtils; |
||||||
|
import com.fr.design.mainframe.share.util.ShareComponentUtils; |
||||||
|
import com.fr.design.ui.util.UIUtil; |
||||||
|
import com.fr.form.share.DefaultSharableWidget; |
||||||
|
import com.fr.form.share.Group; |
||||||
|
import com.fr.form.share.GroupManege; |
||||||
|
import com.fr.form.share.SharableWidgetProvider; |
||||||
|
import com.fr.form.share.group.DefaultShareGroupManager; |
||||||
|
import com.fr.log.FineLoggerFactory; |
||||||
|
import com.fr.stable.StableUtils; |
||||||
|
import com.fr.stable.StringUtils; |
||||||
|
|
||||||
|
import javax.swing.SwingWorker; |
||||||
|
import java.awt.Component; |
||||||
|
import java.awt.Container; |
||||||
|
import java.io.File; |
||||||
|
import java.io.IOException; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author Starryi |
||||||
|
* @version 1.0 |
||||||
|
* Created by Starryi on 2021/10/26 |
||||||
|
*/ |
||||||
|
public class LocalWidgetUpdater implements Process<Double> { |
||||||
|
|
||||||
|
private double processValue = -1; |
||||||
|
public LocalWidgetBlock widgetBlock; |
||||||
|
private SwingWorker<Boolean, Void> worker; |
||||||
|
|
||||||
|
public LocalWidgetUpdater(LocalWidgetBlock widgetBlock) { |
||||||
|
this.widgetBlock = widgetBlock; |
||||||
|
} |
||||||
|
|
||||||
|
private DefaultSharableWidget getWidget() { |
||||||
|
return this.widgetBlock.getWidget(); |
||||||
|
} |
||||||
|
|
||||||
|
private Group getGroup() { |
||||||
|
return this.widgetBlock.getGroup(); |
||||||
|
} |
||||||
|
|
||||||
|
public double getProcessValue() { |
||||||
|
return processValue; |
||||||
|
} |
||||||
|
public boolean isUpdating() { |
||||||
|
return 0 <= processValue && processValue <= 1; |
||||||
|
} |
||||||
|
|
||||||
|
public void updateWidget(String remoteLatestWidgetId, UpdateListener updateListener) { |
||||||
|
if (OnlineWidgetRepoPane.getInstance().isShowPackagePanel()) { |
||||||
|
ComponentCollector.getInstance().collectDownloadPktNum(); |
||||||
|
} |
||||||
|
|
||||||
|
LocalWidgetUpdater.this.process(0.0D); |
||||||
|
String userName = DesignerEnvManager.getEnvManager().getDesignerLoginUsername(); |
||||||
|
if (StringUtils.isEmpty(userName)) { |
||||||
|
DesignerLoginHelper.showLoginDialog(DesignerLoginSource.NORMAL); |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
final DefaultSharableWidget widget = getWidget(); |
||||||
|
|
||||||
|
worker = new SwingWorker<Boolean, Void>() { |
||||||
|
|
||||||
|
@Override |
||||||
|
protected Boolean doInBackground() { |
||||||
|
if (isCancelled()) { |
||||||
|
return false; |
||||||
|
} |
||||||
|
String filePath; |
||||||
|
try { |
||||||
|
filePath = DownloadUtils.download(remoteLatestWidgetId, widget.getName() + "." + widget.getId(), LocalWidgetUpdater.this); |
||||||
|
} catch (Exception e) { |
||||||
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||||
|
return false; |
||||||
|
} |
||||||
|
ShareComponentUtils.checkReadMe(); |
||||||
|
//安装
|
||||||
|
File file = new File(filePath); |
||||||
|
try { |
||||||
|
if (file.exists()) { |
||||||
|
getGroup().installUniqueIdModule(file); |
||||||
|
} |
||||||
|
} catch (IOException e) { |
||||||
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||||
|
} finally { |
||||||
|
//删掉下载组件的目录
|
||||||
|
StableUtils.deleteFile(file); |
||||||
|
} |
||||||
|
return true; |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected void done() { |
||||||
|
LocalWidgetUpdater.this.process(-1.0); |
||||||
|
boolean success = false; |
||||||
|
try { |
||||||
|
success = get(); |
||||||
|
} catch (Exception e) { |
||||||
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||||
|
} |
||||||
|
if (success) { |
||||||
|
resetWidgetOfBlock(); |
||||||
|
} |
||||||
|
if (updateListener != null) { |
||||||
|
updateListener.onUpdated(success, getGroup().getGroupName(), widget.getId()); |
||||||
|
} |
||||||
|
} |
||||||
|
}; |
||||||
|
|
||||||
|
worker.execute(); |
||||||
|
} |
||||||
|
|
||||||
|
private void resetWidgetOfBlock() { |
||||||
|
GroupManege groupManege = DefaultShareGroupManager.getInstance(); |
||||||
|
Group group = groupManege.getGroup(getGroup().getGroupName()); |
||||||
|
if (group != null) { |
||||||
|
String id = widgetBlock.getWidgetUuid(); |
||||||
|
if (StringUtils.isNotEmpty(id)) { |
||||||
|
SharableWidgetProvider localLatestWidget = group.getElCaseBindInfoById(widgetBlock.getWidgetUuid()); |
||||||
|
if (localLatestWidget instanceof DefaultSharableWidget) { |
||||||
|
widgetBlock.widget = (DefaultSharableWidget) localLatestWidget; |
||||||
|
repaintBlockAndOverlay(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void cancelUpdate() { |
||||||
|
if (worker != null && !worker.isDone()) { |
||||||
|
worker.cancel(true); |
||||||
|
worker = null; |
||||||
|
} |
||||||
|
|
||||||
|
process(-1.0); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void process(Double processValue) { |
||||||
|
this.processValue = processValue; |
||||||
|
repaintBlockAndOverlay(); |
||||||
|
} |
||||||
|
|
||||||
|
private void repaintBlockAndOverlay() { |
||||||
|
UIUtil.invokeLaterIfNeeded(new Runnable() { |
||||||
|
@Override |
||||||
|
public void run() { |
||||||
|
Container absoluteLayoutParent = getAbsoluteLayoutAncestor(widgetBlock); |
||||||
|
widgetBlock.repaint(); |
||||||
|
if (absoluteLayoutParent != null) { |
||||||
|
// 位于Block上方的遮罩层也要重绘下,否则Block的内容会绘制到遮罩层上方
|
||||||
|
absoluteLayoutParent.repaint(); |
||||||
|
} |
||||||
|
} |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
public Container getAbsoluteLayoutAncestor(Component component) { |
||||||
|
Container container = component.getParent(); |
||||||
|
while (container != null && container.getLayout() != null) { |
||||||
|
container = container.getParent(); |
||||||
|
} |
||||||
|
return container; |
||||||
|
} |
||||||
|
|
||||||
|
public interface UpdateListener { |
||||||
|
void onUpdated(boolean success, String group, String id); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,30 @@ |
|||||||
|
package com.fr.design.mainframe.share.ui.local; |
||||||
|
|
||||||
|
import javax.swing.JPanel; |
||||||
|
import java.awt.Component; |
||||||
|
import java.awt.Container; |
||||||
|
import java.awt.Dimension; |
||||||
|
import java.awt.LayoutManager2; |
||||||
|
import java.io.Serializable; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author Starryi |
||||||
|
* @version 1.0 |
||||||
|
* Created by Starryi on 2021/11/2 |
||||||
|
*/ |
||||||
|
public class FramePane extends JPanel { |
||||||
|
|
||||||
|
public FramePane() { |
||||||
|
setLayout(null); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void doLayout() { |
||||||
|
super.doLayout(); |
||||||
|
for (int i = 0; i < getComponentCount(); i++) { |
||||||
|
getComponent(i).setSize(getSize()); |
||||||
|
getComponent(i).setPreferredSize(getSize()); |
||||||
|
getComponent(i).setBounds(0, 0, getWidth(), getHeight()); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,144 @@ |
|||||||
|
package com.fr.design.mainframe.share.ui.local; |
||||||
|
|
||||||
|
import com.fr.design.mainframe.share.util.OnlineShopUtils; |
||||||
|
import com.fr.form.share.Group; |
||||||
|
import com.fr.form.share.SharableWidgetProvider; |
||||||
|
import com.fr.form.share.bean.OnlineShareWidget; |
||||||
|
import com.fr.form.share.group.DefaultShareGroupManager; |
||||||
|
import com.fr.log.FineLoggerFactory; |
||||||
|
import com.fr.plugin.basic.version.Version; |
||||||
|
import com.fr.stable.ProductConstants; |
||||||
|
import com.fr.stable.StringUtils; |
||||||
|
|
||||||
|
import javax.swing.SwingWorker; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.HashSet; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
import java.util.Set; |
||||||
|
import java.util.concurrent.ExecutionException; |
||||||
|
import java.util.concurrent.atomic.AtomicBoolean; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author Starryi |
||||||
|
* @version 1.0 |
||||||
|
* Created by Starryi on 2021/11/3 |
||||||
|
*/ |
||||||
|
public class LocalWidgetRepoUpdater { |
||||||
|
private LocalWidgetRepoUpdater() {} |
||||||
|
private static class Holder { |
||||||
|
public static LocalWidgetRepoUpdater INSTANCE = new LocalWidgetRepoUpdater(); |
||||||
|
} |
||||||
|
public static LocalWidgetRepoUpdater getInstance() { |
||||||
|
return LocalWidgetRepoUpdater.Holder.INSTANCE; |
||||||
|
} |
||||||
|
|
||||||
|
private final Map<String, OnlineShareWidget> remoteLatestWidgetsBackup = new HashMap<>(); |
||||||
|
|
||||||
|
private final AtomicBoolean isCheckingComponentUpdates = new AtomicBoolean(false); |
||||||
|
private SwingWorker<Boolean, Void> checkingComponentsUpdateWorker; |
||||||
|
|
||||||
|
private Set<String> getLocalWidgetIds() { |
||||||
|
Set<String> widgetIds = new HashSet<>(); |
||||||
|
Group[] groups = DefaultShareGroupManager.getInstance().getAllGroup(); |
||||||
|
for (Group group: groups) { |
||||||
|
SharableWidgetProvider[] widgetProviders = group.getAllBindInfoList(); |
||||||
|
for (SharableWidgetProvider provider: widgetProviders) { |
||||||
|
widgetIds.add(provider.getId()); |
||||||
|
} |
||||||
|
} |
||||||
|
return widgetIds; |
||||||
|
} |
||||||
|
|
||||||
|
public void clearUpdate() { |
||||||
|
remoteLatestWidgetsBackup.clear(); |
||||||
|
} |
||||||
|
|
||||||
|
public boolean checkUpdatable(SharableWidgetProvider provider) { |
||||||
|
return findLatestRemoteWidget(provider) != null; |
||||||
|
} |
||||||
|
|
||||||
|
public OnlineShareWidget findLatestRemoteWidget(SharableWidgetProvider provider) { |
||||||
|
OnlineShareWidget remoteLatestWidget = remoteLatestWidgetsBackup.get(provider.getId()); |
||||||
|
if (remoteLatestWidget != null && StringUtils.isNotEmpty(remoteLatestWidget.getVersion())) { |
||||||
|
Version remoteLatestVersion = Version.create(remoteLatestWidget.getVersion()); |
||||||
|
Version localVersion = Version.create(provider.getVersion()); |
||||||
|
|
||||||
|
boolean isUpdatable = remoteLatestVersion.compareTo(localVersion) > 0; |
||||||
|
if (isUpdatable) { |
||||||
|
return remoteLatestWidget; |
||||||
|
} |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
public List<SharableWidgetProvider> getUpdatableWidgetProviders() { |
||||||
|
List<SharableWidgetProvider> updatableProviders = new ArrayList<>(); |
||||||
|
|
||||||
|
Group[] groups = DefaultShareGroupManager.getInstance().getAllGroup(); |
||||||
|
for (Group group: groups) { |
||||||
|
SharableWidgetProvider[] widgetProviders = group.getAllBindInfoList(); |
||||||
|
for (SharableWidgetProvider widgetProvider: widgetProviders) { |
||||||
|
if (checkUpdatable(widgetProvider)) { |
||||||
|
updatableProviders.add(widgetProvider); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
return updatableProviders; |
||||||
|
} |
||||||
|
|
||||||
|
public void fetchComponentUpdates(FetchComponentUpdatesListener listener) { |
||||||
|
if (isCheckingComponentUpdates.get()) { |
||||||
|
if (checkingComponentsUpdateWorker != null) { |
||||||
|
checkingComponentsUpdateWorker.cancel(true); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
clearUpdate(); |
||||||
|
listener.onFetchedBefore(); |
||||||
|
checkingComponentsUpdateWorker = new SwingWorker<Boolean, Void>() { |
||||||
|
@Override |
||||||
|
protected Boolean doInBackground() { |
||||||
|
if (isCancelled()) { |
||||||
|
return false; |
||||||
|
} |
||||||
|
if (isCheckingComponentUpdates.compareAndSet(false, true)) { |
||||||
|
clearUpdate(); |
||||||
|
|
||||||
|
Set<String> widgetIds = getLocalWidgetIds(); |
||||||
|
String envVersion = ProductConstants.RELEASE_VERSION; |
||||||
|
|
||||||
|
List<OnlineShareWidget> remoteLatestWidgetList = OnlineShopUtils.getLatestReusesByDesignerVersion(widgetIds, envVersion); |
||||||
|
remoteLatestWidgetsBackup.clear(); |
||||||
|
for (OnlineShareWidget widget: remoteLatestWidgetList) { |
||||||
|
remoteLatestWidgetsBackup.put(widget.getUuid(), widget); |
||||||
|
} |
||||||
|
|
||||||
|
return true; |
||||||
|
} |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void done() { |
||||||
|
boolean success = false; |
||||||
|
try { |
||||||
|
success = get(); |
||||||
|
} catch (InterruptedException | ExecutionException e) { |
||||||
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||||
|
} finally { |
||||||
|
listener.onFetchedAfter(success, remoteLatestWidgetsBackup); |
||||||
|
isCheckingComponentUpdates.set(false); |
||||||
|
} |
||||||
|
} |
||||||
|
}; |
||||||
|
|
||||||
|
checkingComponentsUpdateWorker.execute(); |
||||||
|
} |
||||||
|
|
||||||
|
public interface FetchComponentUpdatesListener { |
||||||
|
void onFetchedBefore(); |
||||||
|
void onFetchedAfter(boolean success, Map<String, OnlineShareWidget> remoteLatestWidgets); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,248 @@ |
|||||||
|
package com.fr.design.mainframe.share.ui.online; |
||||||
|
|
||||||
|
import com.fr.design.gui.icontainer.UIScrollPane; |
||||||
|
import com.fr.design.layout.FRGUIPaneFactory; |
||||||
|
import com.fr.design.mainframe.share.AbstractWidgetSelectPane; |
||||||
|
import com.fr.design.mainframe.share.ui.base.AbstractWidgetPopupPreviewPane; |
||||||
|
import com.fr.design.mainframe.share.ui.base.LoadingPane; |
||||||
|
import com.fr.design.mainframe.share.ui.base.NoMatchPane; |
||||||
|
import com.fr.design.mainframe.share.ui.base.PagingFiledPane; |
||||||
|
import com.fr.design.mainframe.share.ui.block.OnlineWidgetBlock; |
||||||
|
import com.fr.design.mainframe.share.ui.block.PreviewWidgetBlock; |
||||||
|
import com.fr.design.mainframe.share.ui.online.resource.OnlineResourceManager; |
||||||
|
import com.fr.design.mainframe.share.ui.widgetfilter.FilterPane; |
||||||
|
import com.fr.design.mainframe.share.util.OnlineShopUtils; |
||||||
|
import com.fr.form.share.base.DataLoad; |
||||||
|
import com.fr.form.share.bean.OnlineShareWidget; |
||||||
|
import com.fr.form.share.constants.ShareComponentConstants; |
||||||
|
import com.fr.log.FineLoggerFactory; |
||||||
|
import com.fr.stable.ArrayUtils; |
||||||
|
|
||||||
|
import javax.swing.BorderFactory; |
||||||
|
import javax.swing.JPanel; |
||||||
|
import javax.swing.JScrollPane; |
||||||
|
import javax.swing.SwingWorker; |
||||||
|
import java.awt.BorderLayout; |
||||||
|
import java.awt.CardLayout; |
||||||
|
import java.awt.Container; |
||||||
|
import java.awt.Dimension; |
||||||
|
import java.awt.FlowLayout; |
||||||
|
import java.util.concurrent.ExecutionException; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by kerry on 2021/10/22 |
||||||
|
*/ |
||||||
|
public abstract class AbstractOnlineWidgetSelectPane extends AbstractWidgetSelectPane<OnlineShareWidget> { |
||||||
|
protected static final int H_GAP = 5; |
||||||
|
protected static final int V_GAP = 10; |
||||||
|
|
||||||
|
protected enum PaneStatue {NORMAL, NO_MATCH, LOADING, DISCONNECTED} |
||||||
|
|
||||||
|
private OnlineShareWidget[] sharableWidgetProviders; |
||||||
|
private PagingFiledPane pagingFiledPane; |
||||||
|
private JPanel contentPane; |
||||||
|
private UIScrollPane scrollPane; |
||||||
|
private FilterPane filterPane; |
||||||
|
private final int widgetsPerNum; |
||||||
|
private CardLayout cardLayout; |
||||||
|
|
||||||
|
public AbstractOnlineWidgetSelectPane(OnlineShareWidget[] providers, FilterPane filterPane, int widgetsPerNum) { |
||||||
|
this(providers, widgetsPerNum); |
||||||
|
this.filterPane = filterPane; |
||||||
|
} |
||||||
|
|
||||||
|
public AbstractOnlineWidgetSelectPane(final DataLoad<OnlineShareWidget> dataLoad, FilterPane filterPane, final int widgetsPerNum) { |
||||||
|
this(dataLoad, widgetsPerNum); |
||||||
|
this.filterPane = filterPane; |
||||||
|
} |
||||||
|
|
||||||
|
public AbstractOnlineWidgetSelectPane(OnlineShareWidget[] providers, int widgetsPerNum) { |
||||||
|
this.widgetsPerNum = widgetsPerNum; |
||||||
|
sharableWidgetProviders = providers; |
||||||
|
init(); |
||||||
|
initPagingPane(); |
||||||
|
switchPane(createComponents()); |
||||||
|
} |
||||||
|
|
||||||
|
public AbstractOnlineWidgetSelectPane(final DataLoad<OnlineShareWidget> dataLoad, final int widgetsPerNum) { |
||||||
|
this.widgetsPerNum = widgetsPerNum; |
||||||
|
init(); |
||||||
|
//异步获取组件信息
|
||||||
|
new SwingWorker<OnlineWidgetSelectPane.PaneStatue, Void>() { |
||||||
|
@Override |
||||||
|
protected OnlineWidgetSelectPane.PaneStatue doInBackground() { |
||||||
|
sharableWidgetProviders = dataLoad.load(); |
||||||
|
initPagingPane(); |
||||||
|
return createComponents(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected void done() { |
||||||
|
try { |
||||||
|
switchPane(get()); |
||||||
|
fireAfterDataLoad(); |
||||||
|
} catch (InterruptedException e) { |
||||||
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||||
|
Thread.currentThread().interrupt(); |
||||||
|
} catch (ExecutionException e) { |
||||||
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||||
|
} |
||||||
|
} |
||||||
|
}.execute(); |
||||||
|
} |
||||||
|
|
||||||
|
private void init() { |
||||||
|
cardLayout = new CardLayout(); |
||||||
|
this.setLayout(cardLayout); |
||||||
|
// 设置面板的边框 ,距离上、左、下、右 的距离
|
||||||
|
this.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 0)); |
||||||
|
contentPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
||||||
|
this.add(new LoadingPane(), OnlineWidgetSelectPane.PaneStatue.LOADING.name()); |
||||||
|
this.add(new NoMatchPane(), OnlineWidgetSelectPane.PaneStatue.NO_MATCH.name()); |
||||||
|
this.add(contentPane, OnlineWidgetSelectPane.PaneStatue.NORMAL.name()); |
||||||
|
switchPane(OnlineWidgetSelectPane.PaneStatue.LOADING); |
||||||
|
} |
||||||
|
|
||||||
|
public int getSharableWidgetNum() { |
||||||
|
return sharableWidgetProviders == null ? 0 : sharableWidgetProviders.length; |
||||||
|
} |
||||||
|
|
||||||
|
public OnlineShareWidget[] getSharableWidgetProviders() { |
||||||
|
return sharableWidgetProviders; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 切换需要显示的面板 |
||||||
|
*/ |
||||||
|
protected void switchPane(OnlineWidgetSelectPane.PaneStatue statue) { |
||||||
|
if (statue == OnlineWidgetSelectPane.PaneStatue.DISCONNECTED) { |
||||||
|
OnlineWidgetRepoPane.getInstance().switch2InternetErrorPane(); |
||||||
|
return; |
||||||
|
} |
||||||
|
cardLayout.show(this, statue.name()); |
||||||
|
if (statue == OnlineWidgetSelectPane.PaneStatue.NORMAL) { |
||||||
|
//异步加载组件缩略图
|
||||||
|
OnlineResourceManager.getInstance().loadImage(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
protected void fireAfterDataLoad(){ |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
private void synchronizedLoadingContent() { |
||||||
|
new SwingWorker<OnlineWidgetSelectPane.PaneStatue, Void>() { |
||||||
|
@Override |
||||||
|
protected OnlineWidgetSelectPane.PaneStatue doInBackground() { |
||||||
|
return createComponents(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected void done() { |
||||||
|
try { |
||||||
|
switchPane(get()); |
||||||
|
//加载之后设置下标记符
|
||||||
|
} catch (InterruptedException e) { |
||||||
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||||
|
Thread.currentThread().interrupt(); |
||||||
|
} catch (ExecutionException e) { |
||||||
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||||
|
} |
||||||
|
} |
||||||
|
}.execute(); |
||||||
|
} |
||||||
|
|
||||||
|
private void initPagingPane() { |
||||||
|
this.pagingFiledPane = new PagingFiledPane(sharableWidgetProviders.length, widgetsPerNum); |
||||||
|
this.pagingFiledPane.registerChangeListener(event -> { |
||||||
|
AbstractOnlineWidgetSelectPane.this.switchPane(OnlineWidgetSelectPane.PaneStatue.LOADING); |
||||||
|
synchronizedLoadingContent(); |
||||||
|
OnlineWidgetRepoPane.getInstance().completeEmbedFilter(); |
||||||
|
|
||||||
|
}); |
||||||
|
pagingFiledPane.setEnable(pagePaneEnable()); |
||||||
|
} |
||||||
|
|
||||||
|
protected OnlineWidgetSelectPane.PaneStatue createComponents() { |
||||||
|
if (ArrayUtils.isEmpty(sharableWidgetProviders)) { |
||||||
|
return OnlineWidgetSelectPane.PaneStatue.NO_MATCH; |
||||||
|
} |
||||||
|
if (!OnlineShopUtils.testConnection()) { |
||||||
|
return OnlineWidgetSelectPane.PaneStatue.DISCONNECTED; |
||||||
|
} |
||||||
|
OnlineResourceManager.getInstance().cancelLoad(this); |
||||||
|
|
||||||
|
contentPane.removeAll(); |
||||||
|
scrollPane = createScrollPane(); |
||||||
|
|
||||||
|
contentPane.add(scrollPane, BorderLayout.CENTER); |
||||||
|
contentPane.add(this.pagingFiledPane, BorderLayout.SOUTH); |
||||||
|
return OnlineWidgetSelectPane.PaneStatue.NORMAL; |
||||||
|
} |
||||||
|
|
||||||
|
protected UIScrollPane createScrollPane() { |
||||||
|
OnlineShareWidget[] showWidgets = getShowWidgets(); |
||||||
|
JPanel widgetPane = createWidgetPane(); |
||||||
|
widgetPane.setLayout(new FlowLayout(FlowLayout.LEFT, H_GAP, V_GAP)); |
||||||
|
for (OnlineShareWidget provider : showWidgets) { |
||||||
|
PreviewWidgetBlock<OnlineShareWidget> widgetButton = createWidgetBlock(provider); |
||||||
|
widgetPane.add(widgetButton); |
||||||
|
} |
||||||
|
widgetPane.setPreferredSize(new Dimension(240, getPaneHeight(showWidgets.length))); |
||||||
|
|
||||||
|
UIScrollPane scrollPane = new UIScrollPane(createContentPane(widgetPane)); |
||||||
|
setScrollPaneStyle(scrollPane); |
||||||
|
return scrollPane; |
||||||
|
} |
||||||
|
|
||||||
|
protected OnlineShareWidget[] getShowWidgets(){ |
||||||
|
return this.pagingFiledPane.getShowItems(this.sharableWidgetProviders); |
||||||
|
} |
||||||
|
|
||||||
|
protected JPanel createWidgetPane() { |
||||||
|
return new JPanel(); |
||||||
|
} |
||||||
|
|
||||||
|
protected JPanel createContentPane(JPanel widgetPane) { |
||||||
|
JPanel panel = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
||||||
|
panel.add(widgetPane, BorderLayout.CENTER); |
||||||
|
return panel; |
||||||
|
} |
||||||
|
|
||||||
|
protected boolean pagePaneEnable() { |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
protected void setScrollPaneStyle(UIScrollPane scrollPane) { |
||||||
|
scrollPane.setBorder(null); |
||||||
|
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); |
||||||
|
scrollPane.setWheelScrollingEnabled(filterPane == null || !filterPane.isShowPopup()); |
||||||
|
} |
||||||
|
|
||||||
|
protected PreviewWidgetBlock<OnlineShareWidget> createWidgetBlock(OnlineShareWidget provider) { |
||||||
|
return new OnlineWidgetBlock(provider, this); |
||||||
|
} |
||||||
|
|
||||||
|
protected int getPaneHeight(int count) { |
||||||
|
return (count + 1) / 2 * (ShareComponentConstants.SHARE_BLOCK_HEIGHT + V_GAP); |
||||||
|
} |
||||||
|
|
||||||
|
public void setWidgetPaneScrollEnable(boolean enable) { |
||||||
|
if (scrollPane != null) { |
||||||
|
scrollPane.setWheelScrollingEnabled(enable); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected AbstractWidgetPopupPreviewPane<OnlineShareWidget> createPopupPreviewPane() { |
||||||
|
return new OnlineWidgetPopupPreviewPane(); |
||||||
|
} |
||||||
|
|
||||||
|
protected Container getParentContainer() { |
||||||
|
return this.getParent(); |
||||||
|
} |
||||||
|
|
||||||
|
public void refreshShowPaneUI() { |
||||||
|
OnlineWidgetRepoPane.getInstance().refreshShowPaneUI(); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,74 @@ |
|||||||
|
package com.fr.design.mainframe.share.ui.online; |
||||||
|
|
||||||
|
|
||||||
|
import com.fr.general.ComparatorUtils; |
||||||
|
import com.fr.stable.StringUtils; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by kerry on 2021/10/22 |
||||||
|
*/ |
||||||
|
public class CarouselStateManger { |
||||||
|
|
||||||
|
public static final String RIGHT_CLICK ="RIGHT_CLICK"; |
||||||
|
public static final String DOWNLOAD_COMPONENT ="DOWNLOAD_COMPONENT"; |
||||||
|
public static final String FIRST_DRAG_ANIMATE ="FIRST_DRAG_ANIMATE"; |
||||||
|
public static final String MOUSE_HOVER ="MOUSE_HOVER"; |
||||||
|
|
||||||
|
private CarouseState state; |
||||||
|
|
||||||
|
|
||||||
|
private String suspendEvent; |
||||||
|
|
||||||
|
|
||||||
|
public static CarouselStateManger getInstance() { |
||||||
|
return CarouselStateManger.HOLDER.singleton; |
||||||
|
} |
||||||
|
|
||||||
|
private static class HOLDER { |
||||||
|
private static CarouselStateManger singleton = new CarouselStateManger(); |
||||||
|
} |
||||||
|
|
||||||
|
private CarouselStateManger() { |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
public void start() { |
||||||
|
this.state = CarouseState.RUNNING; |
||||||
|
} |
||||||
|
|
||||||
|
public void start(String startEvent) { |
||||||
|
if (!this.stopped() && ComparatorUtils.equals(this.suspendEvent, startEvent)){ |
||||||
|
this.state = CarouseState.RUNNING; |
||||||
|
this.suspendEvent = StringUtils.EMPTY; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public boolean running() { |
||||||
|
return this.state == CarouseState.RUNNING; |
||||||
|
} |
||||||
|
|
||||||
|
public void suspend(String externalSuspendEvent) { |
||||||
|
if (!this.stopped()) { |
||||||
|
this.state = CarouseState.SUSPEND; |
||||||
|
this.suspendEvent = externalSuspendEvent; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public boolean isSuspend() { |
||||||
|
return this.state == CarouseState.SUSPEND; |
||||||
|
} |
||||||
|
|
||||||
|
public void stop() { |
||||||
|
this.state = CarouseState.STOP; |
||||||
|
} |
||||||
|
|
||||||
|
public boolean stopped() { |
||||||
|
return this.state == CarouseState.STOP; |
||||||
|
} |
||||||
|
|
||||||
|
enum CarouseState { |
||||||
|
RUNNING, |
||||||
|
SUSPEND, |
||||||
|
STOP |
||||||
|
} |
||||||
|
} |
@ -1,53 +0,0 @@ |
|||||||
package com.fr.design.mainframe.share.ui.online; |
|
||||||
|
|
||||||
import javax.swing.SwingWorker; |
|
||||||
import java.util.ArrayList; |
|
||||||
import java.util.List; |
|
||||||
|
|
||||||
/** |
|
||||||
* Created by kerry on 2020-12-10 |
|
||||||
*/ |
|
||||||
public class OnlineResourceManager { |
|
||||||
private static class HOLDER { |
|
||||||
private static final OnlineResourceManager singleton = new OnlineResourceManager(); |
|
||||||
} |
|
||||||
|
|
||||||
private OnlineResourceManager(){ |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
public static OnlineResourceManager getInstance() { |
|
||||||
return HOLDER.singleton; |
|
||||||
} |
|
||||||
|
|
||||||
private SwingWorker<Boolean,Void> swingWorker; |
|
||||||
|
|
||||||
private final List<ResourceLoader> loaderList = new ArrayList<>(); |
|
||||||
|
|
||||||
public void cancelLoad() { |
|
||||||
if (swingWorker != null) { |
|
||||||
swingWorker.cancel(true); |
|
||||||
} |
|
||||||
this.loaderList.clear(); |
|
||||||
} |
|
||||||
|
|
||||||
public void addLoader(ResourceLoader loader) { |
|
||||||
this.loaderList.add(loader); |
|
||||||
} |
|
||||||
|
|
||||||
public void loadImage() { |
|
||||||
swingWorker = new SwingWorker<Boolean, Void>() { |
|
||||||
@Override |
|
||||||
protected Boolean doInBackground() { |
|
||||||
for (ResourceLoader loader : loaderList) { |
|
||||||
loader.load(); |
|
||||||
} |
|
||||||
return true; |
|
||||||
} |
|
||||||
}; |
|
||||||
swingWorker.execute(); |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
} |
|
@ -1,231 +1,29 @@ |
|||||||
package com.fr.design.mainframe.share.ui.online; |
package com.fr.design.mainframe.share.ui.online; |
||||||
|
|
||||||
import com.fr.design.gui.icontainer.UIScrollPane; |
|
||||||
import com.fr.design.layout.FRGUIPaneFactory; |
|
||||||
import com.fr.design.mainframe.share.AbstractWidgetSelectPane; |
|
||||||
import com.fr.design.mainframe.share.ui.base.AbstractWidgetPopupPreviewPane; |
|
||||||
import com.fr.design.mainframe.share.ui.base.LoadingPane; |
|
||||||
import com.fr.design.mainframe.share.ui.base.NoMatchPane; |
|
||||||
import com.fr.design.mainframe.share.ui.base.PagingFiledPane; |
|
||||||
import com.fr.design.mainframe.share.ui.block.OnlineWidgetBlock; |
|
||||||
import com.fr.design.mainframe.share.ui.block.PreviewWidgetBlock; |
|
||||||
import com.fr.design.mainframe.share.ui.widgetfilter.FilterPane; |
import com.fr.design.mainframe.share.ui.widgetfilter.FilterPane; |
||||||
import com.fr.form.share.base.DataLoad; |
import com.fr.form.share.base.DataLoad; |
||||||
import com.fr.form.share.bean.OnlineShareWidget; |
import com.fr.form.share.bean.OnlineShareWidget; |
||||||
import com.fr.form.share.constants.ShareComponentConstants; |
|
||||||
import com.fr.form.share.utils.ShareUtils; |
|
||||||
import com.fr.log.FineLoggerFactory; |
|
||||||
import com.fr.stable.ArrayUtils; |
|
||||||
|
|
||||||
import javax.swing.BorderFactory; |
|
||||||
import javax.swing.JPanel; |
|
||||||
import javax.swing.JScrollPane; |
|
||||||
import javax.swing.SwingWorker; |
|
||||||
import java.awt.BorderLayout; |
|
||||||
import java.awt.CardLayout; |
|
||||||
import java.awt.Container; |
|
||||||
import java.awt.Dimension; |
|
||||||
import java.awt.FlowLayout; |
|
||||||
import java.util.concurrent.ExecutionException; |
|
||||||
|
|
||||||
/** |
/** |
||||||
* Created by kerry on 2020-10-19 |
* Created by kerry on 2020-10-19 |
||||||
*/ |
*/ |
||||||
public class OnlineWidgetSelectPane extends AbstractWidgetSelectPane<OnlineShareWidget> { |
public class OnlineWidgetSelectPane extends AbstractOnlineWidgetSelectPane { |
||||||
protected static final int H_GAP = 5; |
|
||||||
protected static final int V_GAP = 10; |
|
||||||
|
|
||||||
enum PaneStatue {NORMAL, NO_MATCH, LOADING, DISCONNECTED} |
|
||||||
|
|
||||||
private OnlineShareWidget[] sharableWidgetProviders; |
|
||||||
private PagingFiledPane pagingFiledPane; |
|
||||||
private JPanel contentPane; |
|
||||||
private UIScrollPane scrollPane; |
|
||||||
private FilterPane filterPane; |
|
||||||
private final int widgetsPerNum; |
|
||||||
private CardLayout cardLayout; |
|
||||||
|
|
||||||
public OnlineWidgetSelectPane(OnlineShareWidget[] providers, FilterPane filterPane, int widgetsPerNum) { |
public OnlineWidgetSelectPane(OnlineShareWidget[] providers, FilterPane filterPane, int widgetsPerNum) { |
||||||
this(providers, widgetsPerNum); |
super(providers, filterPane, widgetsPerNum); |
||||||
this.filterPane = filterPane; |
|
||||||
} |
} |
||||||
|
|
||||||
public OnlineWidgetSelectPane(final DataLoad<OnlineShareWidget> dataLoad, FilterPane filterPane, final int widgetsPerNum) { |
public OnlineWidgetSelectPane(final DataLoad<OnlineShareWidget> dataLoad, FilterPane filterPane, final int widgetsPerNum) { |
||||||
this(dataLoad, widgetsPerNum); |
super(dataLoad, filterPane, widgetsPerNum); |
||||||
this.filterPane = filterPane; |
|
||||||
} |
} |
||||||
|
|
||||||
public OnlineWidgetSelectPane(OnlineShareWidget[] providers, int widgetsPerNum) { |
public OnlineWidgetSelectPane(OnlineShareWidget[] providers, int widgetsPerNum) { |
||||||
this.widgetsPerNum = widgetsPerNum; |
super(providers, widgetsPerNum); |
||||||
sharableWidgetProviders = providers; |
|
||||||
init(); |
|
||||||
initPagingPane(); |
|
||||||
switchPane(createComponents()); |
|
||||||
} |
} |
||||||
|
|
||||||
public OnlineWidgetSelectPane(final DataLoad<OnlineShareWidget> dataLoad, final int widgetsPerNum) { |
public OnlineWidgetSelectPane(final DataLoad<OnlineShareWidget> dataLoad, final int widgetsPerNum) { |
||||||
this.widgetsPerNum = widgetsPerNum; |
super(dataLoad, widgetsPerNum); |
||||||
init(); |
|
||||||
//异步获取组件信息
|
|
||||||
new SwingWorker<PaneStatue, Void>() { |
|
||||||
@Override |
|
||||||
protected PaneStatue doInBackground() { |
|
||||||
sharableWidgetProviders = dataLoad.load(); |
|
||||||
initPagingPane(); |
|
||||||
return createComponents(); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected void done() { |
|
||||||
try { |
|
||||||
switchPane(get()); |
|
||||||
} catch (InterruptedException e) { |
|
||||||
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
|
||||||
Thread.currentThread().interrupt(); |
|
||||||
} catch (ExecutionException e) { |
|
||||||
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
|
||||||
} |
|
||||||
} |
|
||||||
}.execute(); |
|
||||||
} |
|
||||||
|
|
||||||
private void init() { |
|
||||||
cardLayout = new CardLayout(); |
|
||||||
this.setLayout(cardLayout); |
|
||||||
// 设置面板的边框 ,距离上、左、下、右 的距离
|
|
||||||
this.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 0)); |
|
||||||
contentPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
|
||||||
this.add(new LoadingPane(), PaneStatue.LOADING.name()); |
|
||||||
this.add(new NoMatchPane(), PaneStatue.NO_MATCH.name()); |
|
||||||
this.add(contentPane, PaneStatue.NORMAL.name()); |
|
||||||
switchPane(PaneStatue.LOADING); |
|
||||||
} |
|
||||||
|
|
||||||
public int getSharableWidgetNum() { |
|
||||||
return sharableWidgetProviders == null ? 0 : sharableWidgetProviders.length; |
|
||||||
} |
} |
||||||
|
|
||||||
public OnlineShareWidget[] getSharableWidgetProviders() { |
|
||||||
return sharableWidgetProviders; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* 切换需要显示的面板 |
|
||||||
*/ |
|
||||||
private void switchPane(PaneStatue statue) { |
|
||||||
if (statue == PaneStatue.DISCONNECTED) { |
|
||||||
OnlineWidgetRepoPane.getInstance().switch2InternetErrorPane(); |
|
||||||
return; |
|
||||||
} |
|
||||||
cardLayout.show(this, statue.name()); |
|
||||||
if (statue == PaneStatue.NORMAL) { |
|
||||||
//异步加载组件缩略图
|
|
||||||
OnlineResourceManager.getInstance().loadImage(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private void synchronizedLoadingContent() { |
|
||||||
new SwingWorker<PaneStatue, Void>() { |
|
||||||
@Override |
|
||||||
protected PaneStatue doInBackground() { |
|
||||||
return createComponents(); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected void done() { |
|
||||||
try { |
|
||||||
switchPane(get()); |
|
||||||
} catch (InterruptedException e) { |
|
||||||
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
|
||||||
Thread.currentThread().interrupt(); |
|
||||||
} catch (ExecutionException e) { |
|
||||||
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
|
||||||
} |
|
||||||
} |
|
||||||
}.execute(); |
|
||||||
} |
|
||||||
|
|
||||||
private void initPagingPane() { |
|
||||||
this.pagingFiledPane = new PagingFiledPane(sharableWidgetProviders.length, widgetsPerNum); |
|
||||||
this.pagingFiledPane.registerChangeListener(event -> { |
|
||||||
OnlineWidgetSelectPane.this.switchPane(PaneStatue.LOADING); |
|
||||||
synchronizedLoadingContent(); |
|
||||||
}); |
|
||||||
pagingFiledPane.setEnable(pagePaneEnable()); |
|
||||||
} |
|
||||||
|
|
||||||
private PaneStatue createComponents() { |
|
||||||
if (ArrayUtils.isEmpty(sharableWidgetProviders)) { |
|
||||||
return PaneStatue.NO_MATCH; |
|
||||||
} |
|
||||||
if (!ShareUtils.testConnection()) { |
|
||||||
return PaneStatue.DISCONNECTED; |
|
||||||
} |
|
||||||
OnlineResourceManager.getInstance().cancelLoad(); |
|
||||||
|
|
||||||
contentPane.removeAll(); |
|
||||||
scrollPane = createScrollPane(); |
|
||||||
|
|
||||||
contentPane.add(scrollPane, BorderLayout.CENTER); |
|
||||||
contentPane.add(this.pagingFiledPane, BorderLayout.SOUTH); |
|
||||||
return PaneStatue.NORMAL; |
|
||||||
} |
|
||||||
|
|
||||||
private UIScrollPane createScrollPane() { |
|
||||||
OnlineShareWidget[] showWidgets = this.pagingFiledPane.getShowItems(this.sharableWidgetProviders); |
|
||||||
JPanel widgetPane = createWidgetPane(); |
|
||||||
widgetPane.setLayout(new FlowLayout(FlowLayout.LEFT, H_GAP, V_GAP)); |
|
||||||
for (OnlineShareWidget provider : showWidgets) { |
|
||||||
PreviewWidgetBlock<OnlineShareWidget> widgetButton = createWidgetBlock(provider); |
|
||||||
widgetPane.add(widgetButton); |
|
||||||
} |
|
||||||
widgetPane.setPreferredSize(new Dimension(240, getPaneHeight(showWidgets.length))); |
|
||||||
|
|
||||||
UIScrollPane scrollPane = new UIScrollPane(createContentPane(widgetPane)); |
|
||||||
setScrollPaneStyle(scrollPane); |
|
||||||
return scrollPane; |
|
||||||
} |
|
||||||
|
|
||||||
protected JPanel createWidgetPane() { |
|
||||||
return new JPanel(); |
|
||||||
} |
|
||||||
|
|
||||||
protected JPanel createContentPane(JPanel widgetPane) { |
|
||||||
JPanel panel = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
|
||||||
panel.add(widgetPane, BorderLayout.CENTER); |
|
||||||
return panel; |
|
||||||
} |
|
||||||
|
|
||||||
protected boolean pagePaneEnable() { |
|
||||||
return true; |
|
||||||
} |
|
||||||
|
|
||||||
protected void setScrollPaneStyle(UIScrollPane scrollPane) { |
|
||||||
scrollPane.setBorder(null); |
|
||||||
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); |
|
||||||
scrollPane.setWheelScrollingEnabled(filterPane == null || !filterPane.isShowPopup()); |
|
||||||
} |
|
||||||
|
|
||||||
protected PreviewWidgetBlock<OnlineShareWidget> createWidgetBlock(OnlineShareWidget provider) { |
|
||||||
return new OnlineWidgetBlock(provider, this); |
|
||||||
} |
|
||||||
|
|
||||||
protected int getPaneHeight(int count) { |
|
||||||
return (count + 1) / 2 * (ShareComponentConstants.SHARE_BLOCK_HEIGHT + V_GAP); |
|
||||||
} |
|
||||||
|
|
||||||
public void setWidgetPaneScrollEnable(boolean enable) { |
|
||||||
if (scrollPane != null) { |
|
||||||
scrollPane.setWheelScrollingEnabled(enable); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected AbstractWidgetPopupPreviewPane<OnlineShareWidget> createPopupPreviewPane() { |
|
||||||
return new OnlineWidgetPopupPreviewPane(); |
|
||||||
} |
|
||||||
|
|
||||||
protected Container getParentContainer() { |
|
||||||
return this.getParent(); |
|
||||||
} |
|
||||||
} |
} |
||||||
|
@ -0,0 +1,41 @@ |
|||||||
|
package com.fr.design.mainframe.share.ui.online; |
||||||
|
|
||||||
|
import com.fr.general.IOUtils; |
||||||
|
|
||||||
|
import javax.swing.JPanel; |
||||||
|
import java.awt.Dimension; |
||||||
|
import java.awt.Graphics; |
||||||
|
import java.awt.Image; |
||||||
|
import java.awt.Toolkit; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by kerry on 2021/11/19 |
||||||
|
*/ |
||||||
|
public class PreviewImagePane extends JPanel { |
||||||
|
private static final Image DEFAULT_IMAGE = IOUtils.readImage("com/fr/base/images/share/component_error.png"); |
||||||
|
private static final int PREVIEW_IMAGE_WIDTH = OnlineWidgetPopupPreviewPane.POPUP_WIDTH - 20; |
||||||
|
private static final int STANDARD_DPI = 128; |
||||||
|
|
||||||
|
private Image previewImage; |
||||||
|
|
||||||
|
public void setPreviewImage(Image previewImage) { |
||||||
|
this.previewImage = previewImage; |
||||||
|
if (this.previewImage == null) { |
||||||
|
this.previewImage = DEFAULT_IMAGE; |
||||||
|
} |
||||||
|
|
||||||
|
int dpi = Toolkit.getDefaultToolkit().getScreenResolution(); |
||||||
|
int imageWidth = this.previewImage.getWidth(null); |
||||||
|
int imageHeight = this.previewImage.getHeight(null); |
||||||
|
|
||||||
|
double imageAspectRatio = (double) imageWidth / imageHeight; |
||||||
|
int width = (PREVIEW_IMAGE_WIDTH * dpi) / STANDARD_DPI; |
||||||
|
int height = (int) (width / imageAspectRatio); |
||||||
|
setPreferredSize(new Dimension(width, height)); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void paint(Graphics g) { |
||||||
|
g.drawImage(this.previewImage, 0, 0, getWidth(), getHeight(), null); |
||||||
|
} |
||||||
|
} |
@ -1,13 +0,0 @@ |
|||||||
package com.fr.design.mainframe.share.ui.online; |
|
||||||
|
|
||||||
/** |
|
||||||
* Created by kerry on 2020-12-10 |
|
||||||
* todo 后面看看能不能和DataLoad合并起来 |
|
||||||
*/ |
|
||||||
public interface ResourceLoader { |
|
||||||
/** |
|
||||||
* 加载资源文件 |
|
||||||
*/ |
|
||||||
void load(); |
|
||||||
|
|
||||||
} |
|
@ -0,0 +1,46 @@ |
|||||||
|
package com.fr.design.mainframe.share.ui.online.embed; |
||||||
|
|
||||||
|
import com.fr.design.gui.ilable.UILabel; |
||||||
|
import com.fr.design.layout.FRGUIPaneFactory; |
||||||
|
import com.fr.design.mainframe.DesignerContext; |
||||||
|
import com.fr.general.IOUtils; |
||||||
|
|
||||||
|
import javax.swing.BorderFactory; |
||||||
|
import javax.swing.Icon; |
||||||
|
import javax.swing.ImageIcon; |
||||||
|
import javax.swing.JDialog; |
||||||
|
import javax.swing.JPanel; |
||||||
|
import java.awt.BorderLayout; |
||||||
|
import java.awt.Container; |
||||||
|
import java.awt.Graphics; |
||||||
|
import java.awt.Image; |
||||||
|
import java.awt.Point; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by kerry on 2021/10/22 |
||||||
|
*/ |
||||||
|
public class AnimatePopupDialog extends JDialog { |
||||||
|
private static final Icon DRAG_HAND = IOUtils.readIcon("/com/fr/design/form/images/drag_hand.png"); |
||||||
|
|
||||||
|
public AnimatePopupDialog(Image image, Point initialPosition) { |
||||||
|
super(DesignerContext.getDesignerFrame()); |
||||||
|
Container container = getContentPane(); |
||||||
|
setUndecorated(true); |
||||||
|
JPanel jPanel = new JPanel() { |
||||||
|
@Override |
||||||
|
public void paint(Graphics g) { |
||||||
|
super.paint(g); |
||||||
|
DRAG_HAND.paintIcon(this, g, (this.getWidth() - 20) / 2, (this.getHeight() - 20) / 2); |
||||||
|
} |
||||||
|
}; |
||||||
|
jPanel.setLayout(FRGUIPaneFactory.createBorderLayout()); |
||||||
|
jPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); |
||||||
|
jPanel.add(new UILabel(new ImageIcon(image)), BorderLayout.CENTER); |
||||||
|
container.add(jPanel, BorderLayout.CENTER); |
||||||
|
setSize(123, 70); |
||||||
|
this.setLocation(initialPosition); |
||||||
|
this.setVisible(true); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,201 @@ |
|||||||
|
package com.fr.design.mainframe.share.ui.online.embed; |
||||||
|
|
||||||
|
import com.fr.concurrent.NamedThreadFactory; |
||||||
|
import com.fr.design.dialog.FineJOptionPane; |
||||||
|
import com.fr.design.gui.ibutton.UIButton; |
||||||
|
import com.fr.design.gui.ibutton.UIButtonUI; |
||||||
|
import com.fr.design.gui.ilable.UILabel; |
||||||
|
import com.fr.design.i18n.Toolkit; |
||||||
|
import com.fr.design.layout.FRGUIPaneFactory; |
||||||
|
import com.fr.design.mainframe.DesignerContext; |
||||||
|
import com.fr.design.mainframe.share.collect.ComponentCollector; |
||||||
|
import com.fr.design.mainframe.share.ui.widgetfilter.FilterConfigPane; |
||||||
|
import com.fr.design.mainframe.share.util.OnlineShopUtils; |
||||||
|
import com.fr.design.ui.util.UIUtil; |
||||||
|
import com.fr.design.mainframe.share.Bean.WidgetFilterInfo; |
||||||
|
import com.fr.module.ModuleContext; |
||||||
|
import com.fr.stable.StringUtils; |
||||||
|
|
||||||
|
import javax.swing.BorderFactory; |
||||||
|
import javax.swing.JPanel; |
||||||
|
import javax.swing.UIManager; |
||||||
|
import java.awt.AlphaComposite; |
||||||
|
import java.awt.BorderLayout; |
||||||
|
import java.awt.Color; |
||||||
|
import java.awt.Dimension; |
||||||
|
import java.awt.FontMetrics; |
||||||
|
import java.awt.Graphics; |
||||||
|
import java.awt.Graphics2D; |
||||||
|
import java.awt.Image; |
||||||
|
import java.awt.Point; |
||||||
|
import java.awt.event.ActionEvent; |
||||||
|
import java.awt.event.ActionListener; |
||||||
|
import java.awt.event.MouseAdapter; |
||||||
|
import java.awt.image.BufferedImage; |
||||||
|
import java.util.List; |
||||||
|
import java.util.concurrent.ScheduledExecutorService; |
||||||
|
import java.util.concurrent.TimeUnit; |
||||||
|
|
||||||
|
import static javax.swing.JOptionPane.WARNING_MESSAGE; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by kerry on 2021/10/21 |
||||||
|
*/ |
||||||
|
public class EmbedPane extends JPanel { |
||||||
|
private static final String EMBED_PANE_TIMER = "EMBED_PANE_TIMER"; |
||||||
|
private static final Color BORDER_COLOR = Color.decode("#D9DADD"); |
||||||
|
private static final Color SEARCH_BUTTON_COLOR = Color.decode("#419BF9"); |
||||||
|
private static final float DELTA_ALPHA = 0.13F; |
||||||
|
private Image image; |
||||||
|
private float alpha = 1.0F; |
||||||
|
|
||||||
|
public EmbedPane(OnlineEmbedFilterShowPane showPane) { |
||||||
|
this.addMouseListener(new MouseAdapter() { |
||||||
|
}); |
||||||
|
this.setLayout(FRGUIPaneFactory.createBorderLayout()); |
||||||
|
this.setBorder(BorderFactory.createLineBorder(BORDER_COLOR)); |
||||||
|
this.add(initCenterPane(showPane), BorderLayout.CENTER); |
||||||
|
} |
||||||
|
|
||||||
|
private JPanel initCenterPane(OnlineEmbedFilterShowPane showPane) { |
||||||
|
JPanel jPanel = new JPanel(FRGUIPaneFactory.createBorderLayout()); |
||||||
|
jPanel.setBackground(Color.WHITE); |
||||||
|
jPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 0)); |
||||||
|
|
||||||
|
FilterConfigPane filterConfigPane = new FilterConfigPane(OnlineShopUtils.getEmbPaneShowFilterTypeInfos(), false) { |
||||||
|
@Override |
||||||
|
public String assembleFilter() { |
||||||
|
return OnlineShopUtils.assembleFilter(getFilterList()); |
||||||
|
} |
||||||
|
}; |
||||||
|
UIButton searchBtn = initSearchBtn(filterConfigPane, showPane); |
||||||
|
filterConfigPane.setBorder(null); |
||||||
|
JPanel tipPane = getFilterTipPane(); |
||||||
|
tipPane.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5)); |
||||||
|
jPanel.add(tipPane, BorderLayout.NORTH); |
||||||
|
jPanel.add(filterConfigPane, BorderLayout.CENTER); |
||||||
|
JPanel southPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
||||||
|
southPane.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 8)); |
||||||
|
southPane.setBackground(Color.WHITE); |
||||||
|
southPane.add(searchBtn, BorderLayout.CENTER); |
||||||
|
southPane.setPreferredSize(new Dimension(212, 24)); |
||||||
|
jPanel.add(southPane, BorderLayout.SOUTH); |
||||||
|
|
||||||
|
return jPanel; |
||||||
|
} |
||||||
|
|
||||||
|
private JPanel getFilterTipPane() { |
||||||
|
String remark = Toolkit.i18nText("Fine-Design_Share_Online_Embed_Filter_Tip"); |
||||||
|
UILabel label = new UILabel(); |
||||||
|
label.setSize(new Dimension(229, 30)); |
||||||
|
|
||||||
|
//用THML标签进行拼接,以实现自动换行
|
||||||
|
StringBuilder builder = new StringBuilder("<html>"); |
||||||
|
char[] chars = remark.toCharArray(); |
||||||
|
//获取字体计算大小
|
||||||
|
FontMetrics fontMetrics = label.getFontMetrics(label.getFont()); |
||||||
|
int start = 0; |
||||||
|
int len = 0; |
||||||
|
while (start + len < remark.length()) { |
||||||
|
while (true) { |
||||||
|
len++; |
||||||
|
if (start + len > remark.length()) |
||||||
|
break; |
||||||
|
if (fontMetrics.charsWidth(chars, start, len) |
||||||
|
> label.getWidth()) { |
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
builder.append(chars, start, len - 1).append("<br/>"); |
||||||
|
start = start + len - 1; |
||||||
|
len = 0; |
||||||
|
} |
||||||
|
//拼接剩余部分
|
||||||
|
builder.append(chars, start, remark.length() - start); |
||||||
|
builder.append("</html>"); |
||||||
|
|
||||||
|
JPanel jPanel = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
||||||
|
label.setText(builder.toString()); |
||||||
|
jPanel.add(label); |
||||||
|
|
||||||
|
return jPanel; |
||||||
|
} |
||||||
|
|
||||||
|
private UIButton initSearchBtn(FilterConfigPane filterConfigPane, OnlineEmbedFilterShowPane showPane) { |
||||||
|
UIButton searchBtn = new UIButton(Toolkit.i18nText("Fine-Design_Share_Online_Query_Recommend_Component")); |
||||||
|
searchBtn.setUI(new UIButtonUI() { |
||||||
|
@Override |
||||||
|
protected void paintBorder(Graphics g, UIButton b) { |
||||||
|
Color oldColor = g.getColor(); |
||||||
|
g.setColor(SEARCH_BUTTON_COLOR); |
||||||
|
g.drawRoundRect(2, 2, b.getWidth() - 4, b.getHeight() - 4, 2, 2); |
||||||
|
g.setColor(oldColor); |
||||||
|
} |
||||||
|
}); |
||||||
|
searchBtn.setForeground(SEARCH_BUTTON_COLOR); |
||||||
|
searchBtn.addActionListener(new ActionListener() { |
||||||
|
@Override |
||||||
|
public void actionPerformed(ActionEvent e) { |
||||||
|
String filterStr = filterConfigPane.assembleFilter(); |
||||||
|
if (StringUtils.isEmpty(filterStr)) { |
||||||
|
FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), |
||||||
|
Toolkit.i18nText("Fine-Design_Share_Online_Embed_Filter_Warning_Tip"), |
||||||
|
Toolkit.i18nText("Fine-Design_Basic_Message"), WARNING_MESSAGE, |
||||||
|
UIManager.getIcon("OptionPane.warningIcon")); |
||||||
|
ComponentCollector.getInstance().collectEmbededFilterReact(2); |
||||||
|
return; |
||||||
|
} |
||||||
|
showPane.filterStateChanged(filterStr); |
||||||
|
animateHide(showPane, filterConfigPane.getFilterList()); |
||||||
|
ComponentCollector.getInstance().collectEmbededFilterReact(1); |
||||||
|
} |
||||||
|
}); |
||||||
|
return searchBtn; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
public void animateHide(OnlineEmbedFilterShowPane showPane, List<WidgetFilterInfo> selectedFilters) { |
||||||
|
//先生成图片
|
||||||
|
image = new BufferedImage(this.getWidth(), this.getHeight(), BufferedImage.TYPE_INT_ARGB); |
||||||
|
this.paint(image.getGraphics()); |
||||||
|
ScheduledExecutorService service = createToastScheduleExecutorService(); |
||||||
|
this.removeAll(); |
||||||
|
service.scheduleAtFixedRate(() -> { |
||||||
|
Dimension dimension = EmbedPane.this.getSize(); |
||||||
|
Point point = EmbedPane.this.getLocation(); |
||||||
|
if (dimension.width <= 0 || dimension.height <= 0) { |
||||||
|
EmbedPane.this.setVisible(false); |
||||||
|
service.shutdown(); |
||||||
|
try { |
||||||
|
showPane.animate(selectedFilters); |
||||||
|
} catch (InterruptedException e) { |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
UIUtil.invokeAndWaitIfNeeded(() -> { |
||||||
|
Dimension newDimension = new Dimension(dimension.width - 25, dimension.height - 30); |
||||||
|
EmbedPane.this.setSize(newDimension); |
||||||
|
EmbedPane.this.setLocation(point.x + 25, 0); |
||||||
|
alpha -= DELTA_ALPHA; |
||||||
|
}); |
||||||
|
|
||||||
|
}, 0, 60, TimeUnit.MILLISECONDS); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void paint(Graphics g) { |
||||||
|
AlphaComposite composite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, Math.max(0, alpha)); |
||||||
|
((Graphics2D) g).setComposite(composite); |
||||||
|
super.paint(g); |
||||||
|
if (image != null) { |
||||||
|
g.drawImage(image, 0, 0, EmbedPane.this.getWidth(), EmbedPane.this.getHeight(), null); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
private ScheduledExecutorService createToastScheduleExecutorService() { |
||||||
|
return ModuleContext.getExecutor().newSingleThreadScheduledExecutor(new NamedThreadFactory(EMBED_PANE_TIMER)); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,44 @@ |
|||||||
|
package com.fr.design.mainframe.share.ui.online.embed; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Created by kerry on 2021/10/29 |
||||||
|
*/ |
||||||
|
public class FirstDragAnimateStateManager { |
||||||
|
|
||||||
|
public static FirstDragAnimateStateManager getInstance() { |
||||||
|
return FirstDragAnimateStateManager.HOLDER.singleton; |
||||||
|
} |
||||||
|
|
||||||
|
private static class HOLDER { |
||||||
|
private static final FirstDragAnimateStateManager singleton = new FirstDragAnimateStateManager(); |
||||||
|
} |
||||||
|
|
||||||
|
private FirstDragAnimateStateManager() { |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
private STATE state; |
||||||
|
|
||||||
|
public void startAnimate() { |
||||||
|
this.state = STATE.ANIMATING; |
||||||
|
} |
||||||
|
|
||||||
|
public boolean animating() { |
||||||
|
return this.state == STATE.ANIMATING; |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
public void stopAnimate() { |
||||||
|
this.state = STATE.STOP; |
||||||
|
} |
||||||
|
|
||||||
|
public boolean isStop() { |
||||||
|
return this.state == STATE.STOP; |
||||||
|
} |
||||||
|
|
||||||
|
enum STATE { |
||||||
|
ANIMATING, |
||||||
|
STOP |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,210 @@ |
|||||||
|
package com.fr.design.mainframe.share.ui.online.embed; |
||||||
|
|
||||||
|
import com.fr.concurrent.NamedThreadFactory; |
||||||
|
import com.fr.design.gui.icontainer.UIScrollPane; |
||||||
|
import com.fr.design.mainframe.share.ui.online.AbstractOnlineWidgetSelectPane; |
||||||
|
import com.fr.design.mainframe.share.ui.online.CarouselStateManger; |
||||||
|
import com.fr.design.mainframe.share.ui.widgetfilter.FilterPane; |
||||||
|
import com.fr.form.share.base.DataLoad; |
||||||
|
import com.fr.form.share.bean.OnlineShareWidget; |
||||||
|
import com.fr.form.share.constants.ShareComponentConstants; |
||||||
|
import com.fr.form.share.exception.NetWorkFailedException; |
||||||
|
import com.fr.general.http.HttpClient; |
||||||
|
import com.fr.log.FineLoggerFactory; |
||||||
|
import com.fr.module.ModuleContext; |
||||||
|
import com.fr.stable.EncodeConstants; |
||||||
|
import com.fr.third.springframework.web.util.UriUtils; |
||||||
|
|
||||||
|
import javax.imageio.ImageIO; |
||||||
|
import javax.swing.JPanel; |
||||||
|
import java.awt.AWTEvent; |
||||||
|
import java.awt.Dimension; |
||||||
|
import java.awt.FlowLayout; |
||||||
|
import java.awt.Image; |
||||||
|
import java.awt.Point; |
||||||
|
import java.awt.Rectangle; |
||||||
|
import java.awt.event.AWTEventListener; |
||||||
|
import java.awt.event.MouseEvent; |
||||||
|
import java.io.IOException; |
||||||
|
import java.io.UnsupportedEncodingException; |
||||||
|
import java.net.HttpURLConnection; |
||||||
|
import java.util.concurrent.CountDownLatch; |
||||||
|
import java.util.concurrent.ScheduledExecutorService; |
||||||
|
import java.util.concurrent.TimeUnit; |
||||||
|
import java.util.concurrent.atomic.AtomicInteger; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by kerry on 2021/10/22 |
||||||
|
*/ |
||||||
|
public class OnlineEmbedFilterSelectPane extends AbstractOnlineWidgetSelectPane { |
||||||
|
private static final String CAROUSEL_PREVIEW = "carousel_preview"; |
||||||
|
private static final int CAROUSE_IMAGE_LOAD_TIMEOUT = 2000; |
||||||
|
private OnlineShareWidget[] showWidgets; |
||||||
|
private static final int NOT_CAROUSE_WIDGET_NUM = 30; |
||||||
|
|
||||||
|
private PreviewDialog previewDialog; |
||||||
|
private JPanel widgetPane; |
||||||
|
private final CountDownLatch countDownLatch = new CountDownLatch(1); |
||||||
|
|
||||||
|
private final AWTEventListener awtEventListener; |
||||||
|
|
||||||
|
public OnlineEmbedFilterSelectPane(final DataLoad<OnlineShareWidget> dataLoad, FilterPane filterPane, int widgetsPerNum) { |
||||||
|
super(dataLoad, filterPane, widgetsPerNum); |
||||||
|
awtEventListener = event -> { |
||||||
|
if (event instanceof MouseEvent) { |
||||||
|
if (((MouseEvent) event).getClickCount() > 0) { |
||||||
|
try { |
||||||
|
Point selectPanePoint = OnlineEmbedFilterSelectPane.this.getLocationOnScreen(); |
||||||
|
Dimension selectPaneDimension = OnlineEmbedFilterSelectPane.this.getSize(); |
||||||
|
Rectangle selectPaneRec = new Rectangle(selectPanePoint.x, selectPanePoint.y, selectPaneDimension.width, selectPaneDimension.height); |
||||||
|
if (CarouselStateManger.getInstance().running() && |
||||||
|
!selectPaneRec.contains(((MouseEvent) event).getLocationOnScreen())) { |
||||||
|
CarouselStateManger.getInstance().stop(); |
||||||
|
} |
||||||
|
} catch (Exception e) { |
||||||
|
//忽略
|
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
}; |
||||||
|
|
||||||
|
java.awt.Toolkit.getDefaultToolkit().addAWTEventListener(awtEventListener, AWTEvent.MOUSE_EVENT_MASK); |
||||||
|
} |
||||||
|
|
||||||
|
protected UIScrollPane createScrollPane() { |
||||||
|
showWidgets = getShowWidgets(); |
||||||
|
widgetPane = createWidgetPane(); |
||||||
|
widgetPane.setLayout(new FlowLayout(FlowLayout.LEFT, H_GAP, V_GAP)); |
||||||
|
|
||||||
|
previewDialog = new PreviewDialog(); |
||||||
|
|
||||||
|
widgetPane.setPreferredSize(new Dimension(240, getPaneHeight(showWidgets.length))); |
||||||
|
UIScrollPane scrollPane = new UIScrollPane(createContentPane(widgetPane)); |
||||||
|
setScrollPaneStyle(scrollPane); |
||||||
|
return scrollPane; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
protected void fireAfterDataLoad() { |
||||||
|
super.fireAfterDataLoad(); |
||||||
|
countDownLatch.countDown(); |
||||||
|
} |
||||||
|
|
||||||
|
public void animate() throws InterruptedException { |
||||||
|
countDownLatch.await(); |
||||||
|
AtomicInteger integer = new AtomicInteger(showWidgets.length - 1); |
||||||
|
showCurrentLoadBlock(integer, widgetPane); |
||||||
|
this.repaint(); |
||||||
|
CarouselStateManger.getInstance().start(); |
||||||
|
previewDialog.setVisible(true); |
||||||
|
} |
||||||
|
|
||||||
|
private Image getPreviewImage(String url) throws NetWorkFailedException { |
||||||
|
try { |
||||||
|
url = UriUtils.encodePath(url, EncodeConstants.ENCODING_UTF_8); |
||||||
|
} catch (UnsupportedEncodingException e) { |
||||||
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||||
|
return ShareComponentConstants.DEFAULT_COVER; |
||||||
|
} |
||||||
|
HttpClient httpClient = new HttpClient(url); |
||||||
|
httpClient.setTimeout(CAROUSE_IMAGE_LOAD_TIMEOUT); |
||||||
|
httpClient.asGet(); |
||||||
|
int responseCode = httpClient.getResponseCode(); |
||||||
|
if (responseCode != HttpURLConnection.HTTP_OK) { |
||||||
|
throw new NetWorkFailedException(); |
||||||
|
} |
||||||
|
try { |
||||||
|
return ImageIO.read(httpClient.getResponseStream()); |
||||||
|
} catch (IOException e) { |
||||||
|
throw new NetWorkFailedException(); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
private void showCurrentLoadBlock(AtomicInteger integer, JPanel widgetPane) { |
||||||
|
ScheduledExecutorService service = createToastScheduleExecutorService(); |
||||||
|
OnlineShareWidget shareWidget = showWidgets[integer.get()]; |
||||||
|
widgetPane.add(createWidgetBlock(shareWidget), 0); |
||||||
|
this.doLayout(); |
||||||
|
this.validate(); |
||||||
|
this.repaint(); |
||||||
|
try { |
||||||
|
previewDialog.setImage(getPreviewImage(shareWidget.getPicPath()), widgetPane.getLocationOnScreen()); |
||||||
|
} catch (NetWorkFailedException e) { |
||||||
|
this.stopCarouse(integer, false); |
||||||
|
this.switchPane(PaneStatue.DISCONNECTED); |
||||||
|
return; |
||||||
|
} |
||||||
|
//展示弹出框
|
||||||
|
service.schedule(new Runnable() { |
||||||
|
@Override |
||||||
|
public void run() { |
||||||
|
if (CarouselStateManger.getInstance().stopped()) { |
||||||
|
stopCarouse(integer); |
||||||
|
return; |
||||||
|
} |
||||||
|
if (integer.get() == NOT_CAROUSE_WIDGET_NUM) { |
||||||
|
CarouselStateManger.getInstance().stop(); |
||||||
|
stopCarouse(integer); |
||||||
|
previewDialog.setVisible(false); |
||||||
|
return; |
||||||
|
} |
||||||
|
integer.decrementAndGet(); |
||||||
|
if (!CarouselStateManger.getInstance().isSuspend()) { |
||||||
|
showCurrentLoadBlock(integer, widgetPane); |
||||||
|
} else { |
||||||
|
previewDialog.setVisible(false); |
||||||
|
pollingCarouselState(integer, widgetPane); |
||||||
|
} |
||||||
|
} |
||||||
|
}, 500, TimeUnit.MILLISECONDS); |
||||||
|
} |
||||||
|
|
||||||
|
private void pollingCarouselState(AtomicInteger integer, JPanel widgetPane) { |
||||||
|
ScheduledExecutorService service = createToastScheduleExecutorService(); |
||||||
|
service.scheduleAtFixedRate(new Runnable() { |
||||||
|
@Override |
||||||
|
public void run() { |
||||||
|
if (CarouselStateManger.getInstance().stopped()) { |
||||||
|
stopCarouse(integer); |
||||||
|
return; |
||||||
|
} |
||||||
|
if (!CarouselStateManger.getInstance().isSuspend()) { |
||||||
|
previewDialog.setVisible(true); |
||||||
|
showCurrentLoadBlock(integer, widgetPane); |
||||||
|
service.shutdown(); |
||||||
|
} |
||||||
|
} |
||||||
|
}, 0, 500, TimeUnit.MILLISECONDS); |
||||||
|
} |
||||||
|
|
||||||
|
private void stopCarouse(AtomicInteger integer) { |
||||||
|
this.stopCarouse(integer, true); |
||||||
|
} |
||||||
|
|
||||||
|
private void stopCarouse(AtomicInteger integer, boolean showExtra) { |
||||||
|
previewDialog.setVisible(false); |
||||||
|
if (showExtra) { |
||||||
|
loadRestShowWidgets(integer.get() - 1); |
||||||
|
} |
||||||
|
java.awt.Toolkit.getDefaultToolkit().removeAWTEventListener(awtEventListener); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
private void loadRestShowWidgets(int startIndex) { |
||||||
|
for (int i = startIndex; i >= 0; i--) { |
||||||
|
OnlineShareWidget shareWidget = showWidgets[i]; |
||||||
|
widgetPane.add(createWidgetBlock(shareWidget)); |
||||||
|
} |
||||||
|
this.doLayout(); |
||||||
|
this.validate(); |
||||||
|
this.repaint(); |
||||||
|
} |
||||||
|
|
||||||
|
private ScheduledExecutorService createToastScheduleExecutorService() { |
||||||
|
return ModuleContext.getExecutor().newSingleThreadScheduledExecutor(new NamedThreadFactory(CAROUSEL_PREVIEW)); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,62 @@ |
|||||||
|
package com.fr.design.mainframe.share.ui.online.embed; |
||||||
|
|
||||||
|
import com.fr.design.layout.FRGUIPaneFactory; |
||||||
|
import com.fr.design.mainframe.share.ComponentShareUtil; |
||||||
|
import com.fr.design.mainframe.share.ui.online.OnlineWidgetShowPane; |
||||||
|
import com.fr.design.mainframe.share.Bean.WidgetFilterInfo; |
||||||
|
import javax.swing.JPanel; |
||||||
|
import java.awt.BorderLayout; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by kerry on 2021/10/22 |
||||||
|
*/ |
||||||
|
public class OnlineEmbedFilterShowPane extends JPanel { |
||||||
|
private final OnlineWidgetShowPane onlineWidgetShowPane; |
||||||
|
private final EmbedPane embedPane; |
||||||
|
|
||||||
|
private OnlineEmbedFilterSelectPane selectPane; |
||||||
|
|
||||||
|
public OnlineEmbedFilterShowPane(OnlineWidgetShowPane onlineWidgetShowPane) { |
||||||
|
this.setLayout(FRGUIPaneFactory.createBorderLayout()); |
||||||
|
embedPane = new EmbedPane(this); |
||||||
|
embedPane.setLocation(10, 0); |
||||||
|
embedPane.setSize(228, embedPane.getPreferredSize().height); |
||||||
|
this.add(embedPane, BorderLayout.NORTH); |
||||||
|
this.onlineWidgetShowPane = onlineWidgetShowPane; |
||||||
|
this.onlineWidgetShowPane.setToolBarPaneVisible(false); |
||||||
|
this.add(onlineWidgetShowPane, BorderLayout.CENTER); |
||||||
|
} |
||||||
|
|
||||||
|
public void filterStateChanged(String filterStr) { |
||||||
|
this.removeAll(); |
||||||
|
this.add(embedPane); |
||||||
|
this.add(onlineWidgetShowPane, BorderLayout.CENTER); |
||||||
|
this.validate(); |
||||||
|
this.doLayout(); |
||||||
|
this.repaint(); |
||||||
|
onlineWidgetShowPane.setToolBarPaneVisible(true); |
||||||
|
selectPane = onlineWidgetShowPane.animate(filterStr); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
public void animate(List<WidgetFilterInfo> selectedFilters) throws InterruptedException { |
||||||
|
onlineWidgetShowPane.setFilterItems(selectedFilters); |
||||||
|
selectPane.animate(); |
||||||
|
} |
||||||
|
|
||||||
|
public void refreshUI(){ |
||||||
|
if (embedPane != null) { |
||||||
|
this.repaint(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void completeEmbedFilter(){ |
||||||
|
if (embedPane!= null && embedPane.isShowing()){ |
||||||
|
this.remove(embedPane); |
||||||
|
ComponentShareUtil.completeEmbedFilter(); |
||||||
|
this.doLayout(); |
||||||
|
this.repaint(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,37 @@ |
|||||||
|
package com.fr.design.mainframe.share.ui.online.embed; |
||||||
|
|
||||||
|
import com.fr.design.mainframe.DesignerContext; |
||||||
|
import com.fr.design.mainframe.share.ui.online.PreviewImagePane; |
||||||
|
|
||||||
|
import javax.swing.JDialog; |
||||||
|
import java.awt.Dimension; |
||||||
|
import java.awt.Image; |
||||||
|
import java.awt.Point; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Created by kerry on 2021/10/22 |
||||||
|
*/ |
||||||
|
public class PreviewDialog extends JDialog { |
||||||
|
private static final int OFFSET_Y = 9; |
||||||
|
|
||||||
|
public PreviewDialog() { |
||||||
|
super(DesignerContext.getDesignerFrame()); |
||||||
|
setUndecorated(true); |
||||||
|
this.setVisible(false); |
||||||
|
} |
||||||
|
|
||||||
|
public void setImage(Image image, Point point) { |
||||||
|
this.getContentPane().removeAll(); |
||||||
|
PreviewImagePane previewImagePane = new PreviewImagePane(); |
||||||
|
previewImagePane.setPreviewImage(image); |
||||||
|
Dimension dimension = previewImagePane.getPreferredSize(); |
||||||
|
this.getContentPane().add(previewImagePane); |
||||||
|
setSize(new Dimension(dimension.width, dimension.height)); |
||||||
|
this.setLocation(point.x - dimension.width, point.y + OFFSET_Y); |
||||||
|
this.doLayout(); |
||||||
|
this.validate(); |
||||||
|
this.repaint(); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,70 @@ |
|||||||
|
package com.fr.design.mainframe.share.ui.online.resource; |
||||||
|
|
||||||
|
import javax.swing.SwingWorker; |
||||||
|
import java.util.concurrent.ArrayBlockingQueue; |
||||||
|
import java.util.concurrent.BlockingQueue; |
||||||
|
import java.util.function.Predicate; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by kerry on 2020-12-10 |
||||||
|
*/ |
||||||
|
public class OnlineResourceManager { |
||||||
|
private static class HOLDER { |
||||||
|
private static final OnlineResourceManager singleton = new OnlineResourceManager(); |
||||||
|
} |
||||||
|
|
||||||
|
private OnlineResourceManager() { |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
public static OnlineResourceManager getInstance() { |
||||||
|
return HOLDER.singleton; |
||||||
|
} |
||||||
|
|
||||||
|
private SwingWorker<Boolean, Void> swingWorker; |
||||||
|
|
||||||
|
|
||||||
|
private final BlockingQueue<ResourceLoader> loaderBlockingQueue = new ArrayBlockingQueue<ResourceLoader>(100); |
||||||
|
|
||||||
|
public void cancelLoad(Object key) { |
||||||
|
if (swingWorker != null) { |
||||||
|
swingWorker.cancel(true); |
||||||
|
} |
||||||
|
loaderBlockingQueue.removeIf(new Predicate<ResourceLoader>() { |
||||||
|
@Override |
||||||
|
public boolean test(ResourceLoader resourceLoader) { |
||||||
|
return resourceLoader.checkValid(key); |
||||||
|
} |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
public void addLoader(ResourceLoader loader) { |
||||||
|
try { |
||||||
|
this.loaderBlockingQueue.put(loader); |
||||||
|
} catch (InterruptedException e) { |
||||||
|
e.printStackTrace(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void loadImage() { |
||||||
|
swingWorker = new SwingWorker<Boolean, Void>() { |
||||||
|
@Override |
||||||
|
protected Boolean doInBackground() { |
||||||
|
while (!swingWorker.isCancelled()) { |
||||||
|
ResourceLoader loader = null; |
||||||
|
try { |
||||||
|
loader = loaderBlockingQueue.take(); |
||||||
|
} catch (InterruptedException e) { |
||||||
|
|
||||||
|
} |
||||||
|
loader.load(); |
||||||
|
} |
||||||
|
return true; |
||||||
|
} |
||||||
|
}; |
||||||
|
swingWorker.execute(); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,20 @@ |
|||||||
|
package com.fr.design.mainframe.share.ui.online.resource; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by kerry on 2020-12-10 |
||||||
|
* todo 后面看看能不能和DataLoad合并起来 |
||||||
|
*/ |
||||||
|
public interface ResourceLoader { |
||||||
|
/** |
||||||
|
* 加载资源文件 |
||||||
|
*/ |
||||||
|
void load(); |
||||||
|
|
||||||
|
/** |
||||||
|
* 检查resource是否属于某分类 |
||||||
|
* @param key 分类标识 |
||||||
|
* @return boolean |
||||||
|
*/ |
||||||
|
boolean checkValid(Object key); |
||||||
|
|
||||||
|
} |
@ -0,0 +1,285 @@ |
|||||||
|
package com.fr.design.mainframe.share.ui.widgetfilter; |
||||||
|
|
||||||
|
import com.fr.design.gui.icheckbox.UICheckBox; |
||||||
|
import com.fr.design.gui.ilable.UILabel; |
||||||
|
import com.fr.design.layout.FRGUIPaneFactory; |
||||||
|
import com.fr.design.layout.VerticalFlowLayout; |
||||||
|
import com.fr.design.mainframe.share.Bean.FilterTypeInfo; |
||||||
|
import com.fr.design.mainframe.share.Bean.WidgetFilterInfo; |
||||||
|
import com.fr.design.mainframe.share.Bean.WidgetFilterTypeInfo; |
||||||
|
import com.fr.general.ComparatorUtils; |
||||||
|
import com.fr.stable.StringUtils; |
||||||
|
import com.fr.third.javax.annotation.Nullable; |
||||||
|
|
||||||
|
import javax.swing.BorderFactory; |
||||||
|
import javax.swing.JPanel; |
||||||
|
import javax.swing.event.ChangeEvent; |
||||||
|
import java.awt.BorderLayout; |
||||||
|
import java.awt.Color; |
||||||
|
import java.awt.Dimension; |
||||||
|
import java.awt.FlowLayout; |
||||||
|
import java.awt.Font; |
||||||
|
import java.awt.event.ItemEvent; |
||||||
|
import java.awt.event.ItemListener; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by kerry on 2021/11/1 |
||||||
|
*/ |
||||||
|
public abstract class FilterConfigPane extends JPanel { |
||||||
|
private static final Color BORDER_COLOR = Color.decode("#D9DADD"); |
||||||
|
private static final String FILTER_ALL_ID = "0"; |
||||||
|
|
||||||
|
public static final int CONTENT_WIDTH = 225; |
||||||
|
|
||||||
|
private final List<WidgetFilterInfo> filterList = new ArrayList<>(); |
||||||
|
private final List<FilterCheckBox> checkBoxList = new ArrayList<>(); |
||||||
|
private boolean reset = false; |
||||||
|
private boolean showChildNode; |
||||||
|
|
||||||
|
|
||||||
|
public FilterConfigPane(List<FilterTypeInfo> widgetFilterCategories, boolean showChildNode) { |
||||||
|
this.showChildNode = showChildNode; |
||||||
|
initPane(widgetFilterCategories); |
||||||
|
} |
||||||
|
|
||||||
|
public FilterConfigPane(List<FilterTypeInfo> widgetFilterCategories) { |
||||||
|
this(widgetFilterCategories, true); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
private void initPane(List<FilterTypeInfo> widgetFilterCategories) { |
||||||
|
this.setBackground(Color.WHITE); |
||||||
|
this.setBorder(BorderFactory.createLineBorder(BORDER_COLOR)); |
||||||
|
this.setForeground(Color.decode("#FFFFFF")); |
||||||
|
this.setLayout(new BorderLayout()); |
||||||
|
this.add(createVerticalFlowPane(widgetFilterCategories), BorderLayout.CENTER); |
||||||
|
} |
||||||
|
|
||||||
|
public boolean hasFilter() { |
||||||
|
return filterList.size() > 0; |
||||||
|
} |
||||||
|
|
||||||
|
public List<WidgetFilterInfo> getFilterList() { |
||||||
|
return filterList; |
||||||
|
} |
||||||
|
|
||||||
|
private JPanel createVerticalFlowPane(List<FilterTypeInfo> widgetFilterCategories) { |
||||||
|
JPanel verticalFlowPane = new JPanel(); |
||||||
|
verticalFlowPane.setBackground(Color.WHITE); |
||||||
|
VerticalFlowLayout layout = new VerticalFlowLayout(FlowLayout.LEADING, 0, 10); |
||||||
|
layout.setAlignLeft(true); |
||||||
|
verticalFlowPane.setLayout(layout); |
||||||
|
|
||||||
|
verticalFlowPane.setBackground(Color.WHITE); |
||||||
|
verticalFlowPane.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5)); |
||||||
|
|
||||||
|
for (FilterTypeInfo filterTypeInfo : widgetFilterCategories) { |
||||||
|
verticalFlowPane.add(createCategoryPane(filterTypeInfo)); |
||||||
|
} |
||||||
|
|
||||||
|
return verticalFlowPane; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
private JPanel createTypeFilterPane(WidgetFilterTypeInfo widgetFilterTypeInfo) { |
||||||
|
JPanel jPanel = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
||||||
|
jPanel.setBackground(Color.WHITE); |
||||||
|
UILabel titleLabel = new UILabel(widgetFilterTypeInfo.getTitle() + ":"); |
||||||
|
titleLabel.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5)); |
||||||
|
titleLabel.setFont(new Font(titleLabel.getFont().getName(), Font.BOLD, titleLabel.getFont().getSize())); |
||||||
|
jPanel.add(titleLabel, BorderLayout.NORTH); |
||||||
|
jPanel.add(createCategoryDetailPane(widgetFilterTypeInfo), BorderLayout.CENTER); |
||||||
|
return jPanel; |
||||||
|
} |
||||||
|
|
||||||
|
private JPanel createCategoryPane(FilterTypeInfo filterTypeInfo) { |
||||||
|
JPanel jPanel = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
||||||
|
jPanel.setBackground(Color.WHITE); |
||||||
|
UILabel titleLabel = new UILabel(filterTypeInfo.getTitle()); |
||||||
|
titleLabel.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5)); |
||||||
|
titleLabel.setPreferredSize(new Dimension(CONTENT_WIDTH - 2, 20)); |
||||||
|
titleLabel.setOpaque(true); |
||||||
|
titleLabel.setBackground(Color.decode("#EDEDEE")); |
||||||
|
jPanel.add(titleLabel, BorderLayout.NORTH); |
||||||
|
jPanel.add(createCategoryDetailPane(filterTypeInfo.getFilterTypeInfos()), BorderLayout.CENTER); |
||||||
|
return jPanel; |
||||||
|
} |
||||||
|
|
||||||
|
private JPanel createCategoryDetailPane(List<WidgetFilterTypeInfo> filterTypeInfoList) { |
||||||
|
|
||||||
|
if (filterTypeInfoList.size() == 1) { |
||||||
|
return createCategoryDetailPane(filterTypeInfoList.get(0)); |
||||||
|
} |
||||||
|
|
||||||
|
JPanel contentPane = FRGUIPaneFactory.createVerticalFlowLayout_Pane(true, FlowLayout.LEADING, 0, 10); |
||||||
|
contentPane.setBackground(Color.WHITE); |
||||||
|
for (WidgetFilterTypeInfo info : filterTypeInfoList) { |
||||||
|
contentPane.add(createTypeFilterPane(info)); |
||||||
|
} |
||||||
|
return contentPane; |
||||||
|
} |
||||||
|
|
||||||
|
private JPanel createCategoryDetailPane(WidgetFilterTypeInfo filterTypeInfo) { |
||||||
|
JPanel contentPane = FRGUIPaneFactory.createNColumnGridInnerContainer_S_Pane(2); |
||||||
|
contentPane.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 0)); |
||||||
|
contentPane.setBackground(Color.WHITE); |
||||||
|
contentPane.setPreferredSize(new Dimension(CONTENT_WIDTH, calculateDetailPaneHeight(filterTypeInfo))); |
||||||
|
for (final WidgetFilterInfo filterInfo : filterTypeInfo.getFilterItems()) { |
||||||
|
if (ComparatorUtils.equals(FILTER_ALL_ID, filterInfo.getId())) { |
||||||
|
continue; |
||||||
|
} |
||||||
|
FilterCheckBox checkBox = createCheckBox(filterInfo); |
||||||
|
contentPane.add(checkBox); |
||||||
|
if (showChildNode && filterInfo.hasChildFilter()) { |
||||||
|
alignmentFilling(contentPane); |
||||||
|
createChildPane(filterInfo.getInnerFilterInfo(), contentPane, checkBox); |
||||||
|
alignmentFilling(contentPane); |
||||||
|
} |
||||||
|
} |
||||||
|
return contentPane; |
||||||
|
} |
||||||
|
|
||||||
|
private void alignmentFilling(JPanel contentPane) { |
||||||
|
if (contentPane.getComponentCount() % 2 == 1) { |
||||||
|
contentPane.add(new UILabel("")); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private FilterCheckBox createCheckBox(WidgetFilterInfo filterInfo) { |
||||||
|
final FilterCheckBox checkBox = new FilterCheckBox(filterInfo.getName(), filterInfo); |
||||||
|
checkBox.setBackground(Color.WHITE); |
||||||
|
checkBox.addItemListener(new ItemListener() { |
||||||
|
@Override |
||||||
|
public void itemStateChanged(ItemEvent e) { |
||||||
|
if (checkBox.isSelected() && (!checkBox.getFilterInfo().hasChildFilter() || !showChildNode)) { |
||||||
|
filterList.add(filterInfo); |
||||||
|
} else if (filterList.contains(filterInfo)) { |
||||||
|
filterList.remove(filterInfo); |
||||||
|
} |
||||||
|
if (reset) { |
||||||
|
return; |
||||||
|
} |
||||||
|
fireSelectedChanged(new ChangeEvent(assembleFilter())); |
||||||
|
} |
||||||
|
}); |
||||||
|
checkBoxList.add(checkBox); |
||||||
|
return checkBox; |
||||||
|
} |
||||||
|
|
||||||
|
private void createChildPane(List<WidgetFilterInfo> childFilterInfo, JPanel contentPane, FilterCheckBox parentCheckBox) { |
||||||
|
List<FilterCheckBox> childCheckboxList = new ArrayList<>(); |
||||||
|
for (WidgetFilterInfo filterInfo : childFilterInfo) { |
||||||
|
JPanel jPanel = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
||||||
|
jPanel.setBackground(Color.WHITE); |
||||||
|
jPanel.setBorder(BorderFactory.createEmptyBorder(0, 16, 0, 0)); |
||||||
|
FilterCheckBox checkBox = createCheckBox(filterInfo); |
||||||
|
checkBox.addItemListener(e -> { |
||||||
|
if (this.reset) { |
||||||
|
return; |
||||||
|
} |
||||||
|
this.reset = true; |
||||||
|
parentCheckBox.setSelected(allChildSelected(childCheckboxList)); |
||||||
|
this.reset = false; |
||||||
|
}); |
||||||
|
childCheckboxList.add(checkBox); |
||||||
|
jPanel.add(checkBox, BorderLayout.CENTER); |
||||||
|
contentPane.add(jPanel); |
||||||
|
} |
||||||
|
parentCheckBox.addItemListener(e -> { |
||||||
|
if (this.reset) { |
||||||
|
return; |
||||||
|
} |
||||||
|
this.reset = true; |
||||||
|
for (FilterCheckBox checkBox : childCheckboxList) { |
||||||
|
checkBox.setSelected(parentCheckBox.isSelected()); |
||||||
|
} |
||||||
|
this.reset = false; |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
private boolean allChildSelected(List<FilterCheckBox> childCheckboxList) { |
||||||
|
boolean flag = true; |
||||||
|
for (FilterCheckBox checkBox : childCheckboxList) { |
||||||
|
flag &= checkBox.isSelected(); |
||||||
|
} |
||||||
|
return flag; |
||||||
|
} |
||||||
|
|
||||||
|
private int calculateDetailPaneHeight(WidgetFilterTypeInfo filterTypeInfo) { |
||||||
|
int displayCount = 0; |
||||||
|
for (final WidgetFilterInfo filterInfo : filterTypeInfo.getFilterItems()) { |
||||||
|
if (!ComparatorUtils.equals(FILTER_ALL_ID, filterInfo.getId())) { |
||||||
|
displayCount++; |
||||||
|
} |
||||||
|
if (filterInfo.getInnerFilterInfo().size() > 0 && showChildNode) { |
||||||
|
displayCount += (1 + filterInfo.getInnerFilterInfo().size()); |
||||||
|
} |
||||||
|
} |
||||||
|
return ((displayCount + 1) / 2) * 27; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
public abstract String assembleFilter(); |
||||||
|
|
||||||
|
public void setFilters(List<WidgetFilterInfo> selectedFilters) { |
||||||
|
reset = true; |
||||||
|
filterList.clear(); |
||||||
|
setFilterList(selectedFilters); |
||||||
|
reset = false; |
||||||
|
} |
||||||
|
|
||||||
|
private void setFilterList(List<WidgetFilterInfo> selectedFilters){ |
||||||
|
for (FilterCheckBox checkBox : checkBoxList) { |
||||||
|
String filterName = checkBox.getFilterInfo().getName(); |
||||||
|
WidgetFilterInfo selectFilterInfo = getSelectFilterInfoByName(selectedFilters, filterName); |
||||||
|
if (selectFilterInfo == null) { |
||||||
|
continue; |
||||||
|
} |
||||||
|
checkBox.setSelected(true); |
||||||
|
if (selectFilterInfo.hasChildFilter()) { |
||||||
|
setFilterList(selectFilterInfo.getInnerFilterInfo()); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Nullable |
||||||
|
private WidgetFilterInfo getSelectFilterInfoByName(List<WidgetFilterInfo> selectedFilters, String name) { |
||||||
|
for (WidgetFilterInfo filterInfo : selectedFilters) { |
||||||
|
if (ComparatorUtils.equals(filterInfo.getName(), name)) { |
||||||
|
return filterInfo; |
||||||
|
} |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
public void reset() { |
||||||
|
reset = true; |
||||||
|
for (FilterCheckBox checkBox : checkBoxList) { |
||||||
|
checkBox.setSelected(false); |
||||||
|
} |
||||||
|
filterList.clear(); |
||||||
|
fireSelectedChanged(new ChangeEvent(StringUtils.EMPTY)); |
||||||
|
reset = false; |
||||||
|
} |
||||||
|
|
||||||
|
protected void fireSelectedChanged(ChangeEvent changeEvent) { |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
private class FilterCheckBox extends UICheckBox { |
||||||
|
private WidgetFilterInfo filterInfo; |
||||||
|
|
||||||
|
public FilterCheckBox(String string, WidgetFilterInfo filterInfo) { |
||||||
|
super(string); |
||||||
|
this.filterInfo = filterInfo; |
||||||
|
} |
||||||
|
|
||||||
|
public WidgetFilterInfo getFilterInfo() { |
||||||
|
return this.filterInfo; |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -1,203 +1,33 @@ |
|||||||
package com.fr.design.mainframe.share.ui.widgetfilter; |
package com.fr.design.mainframe.share.ui.widgetfilter; |
||||||
|
|
||||||
import com.fr.design.gui.icheckbox.UICheckBox; |
import com.fr.design.mainframe.share.Bean.FilterTypeInfo; |
||||||
import com.fr.design.gui.ilable.UILabel; |
import com.fr.design.mainframe.share.Bean.WidgetFilterInfo; |
||||||
import com.fr.design.i18n.Toolkit; |
|
||||||
import com.fr.design.layout.FRGUIPaneFactory; |
|
||||||
import com.fr.design.layout.VerticalFlowLayout; |
|
||||||
import com.fr.form.share.bean.WidgetFilterInfo; |
|
||||||
import com.fr.form.share.bean.WidgetFilterTypeInfo; |
|
||||||
import com.fr.general.ComparatorUtils; |
|
||||||
import com.fr.stable.StringUtils; |
|
||||||
|
|
||||||
import javax.swing.BorderFactory; |
|
||||||
import javax.swing.JPanel; |
|
||||||
import javax.swing.event.ChangeEvent; |
import javax.swing.event.ChangeEvent; |
||||||
import java.awt.BorderLayout; |
|
||||||
import java.awt.Color; |
|
||||||
import java.awt.Dimension; |
|
||||||
import java.awt.FlowLayout; |
|
||||||
import java.awt.Font; |
|
||||||
import java.awt.event.ItemEvent; |
|
||||||
import java.awt.event.ItemListener; |
|
||||||
import java.util.ArrayList; |
|
||||||
import java.util.List; |
import java.util.List; |
||||||
|
|
||||||
/** |
/** |
||||||
* @Author: Yuan.Wang |
* @Author: Yuan.Wang |
||||||
* @Date: 2020/11/11 |
* @Date: 2020/11/11 |
||||||
*/ |
*/ |
||||||
public abstract class FilterPopupPane extends JPanel { |
public abstract class FilterPopupPane extends FilterConfigPane { |
||||||
private static final Color BORDER_COLOR = Color.decode("#D9DADD"); |
|
||||||
private static final String FILTER_ALL_ID = "0"; |
|
||||||
|
|
||||||
public static final int CONTENT_WIDTH = 225; |
private final FilterPane filterPane; |
||||||
|
|
||||||
FilterPane filterPane; |
|
||||||
private List<WidgetFilterInfo> filterList = new ArrayList<>(); |
|
||||||
private final List<UICheckBox> checkBoxList = new ArrayList<>(); |
|
||||||
private boolean reset = false; |
|
||||||
|
|
||||||
|
public FilterPopupPane(FilterPane filterPane, List<FilterTypeInfo> widgetFilterCategories) { |
||||||
public FilterPopupPane(FilterPane filterPane, List<WidgetFilterTypeInfo> widgetFilterCategories) { |
super(widgetFilterCategories); |
||||||
this.filterPane = filterPane; |
this.filterPane = filterPane; |
||||||
initPane(widgetFilterCategories); |
|
||||||
} |
|
||||||
|
|
||||||
private void initPane(List<WidgetFilterTypeInfo> widgetFilterCategories) { |
|
||||||
this.setBackground(Color.WHITE); |
|
||||||
this.setBorder(BorderFactory.createLineBorder(BORDER_COLOR)); |
|
||||||
this.setForeground(Color.decode("#FFFFFF")); |
|
||||||
this.setLayout(new BorderLayout()); |
|
||||||
this.add(createVerticalFlowPane(widgetFilterCategories), BorderLayout.CENTER); |
|
||||||
} |
|
||||||
|
|
||||||
public boolean hasFilter() { |
|
||||||
return filterList.size() > 0; |
|
||||||
} |
|
||||||
|
|
||||||
protected List<WidgetFilterInfo> getFilterList() { |
|
||||||
return filterList; |
|
||||||
} |
|
||||||
|
|
||||||
private JPanel createVerticalFlowPane(List<WidgetFilterTypeInfo> widgetFilterCategories) { |
|
||||||
|
|
||||||
List<WidgetFilterTypeInfo> topWidgetTypeFilter = new ArrayList<>(); |
|
||||||
List<WidgetFilterTypeInfo> widgetTypeFilter = new ArrayList<>(); |
|
||||||
List<WidgetFilterTypeInfo> otherWidgetTypeFilter = new ArrayList<>(); |
|
||||||
|
|
||||||
for (WidgetFilterTypeInfo info : widgetFilterCategories) { |
|
||||||
if (ComparatorUtils.equals(FilterPane.CHART_FILTER_KEY, info.getKey()) |
|
||||||
|| ComparatorUtils.equals(FilterPane.REPORT_FILTER_KEY, info.getKey())) { |
|
||||||
widgetTypeFilter.add(info); |
|
||||||
} else if (ComparatorUtils.equals(FilterPane.SOURCE_FILTER_KEY, info.getKey())) { |
|
||||||
topWidgetTypeFilter.add(info); |
|
||||||
} else { |
|
||||||
otherWidgetTypeFilter.add(info); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
JPanel verticalFlowPane = new JPanel(); |
|
||||||
verticalFlowPane.setBackground(Color.WHITE); |
|
||||||
VerticalFlowLayout layout = new VerticalFlowLayout(FlowLayout.LEADING, 0, 10); |
|
||||||
layout.setAlignLeft(true); |
|
||||||
verticalFlowPane.setLayout(layout); |
|
||||||
|
|
||||||
verticalFlowPane.setBackground(Color.WHITE); |
|
||||||
verticalFlowPane.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5)); |
|
||||||
|
|
||||||
for (WidgetFilterTypeInfo info : topWidgetTypeFilter) { |
|
||||||
verticalFlowPane.add(createOtherCategoryPane(info)); |
|
||||||
} |
|
||||||
if (widgetTypeFilter.size() > 0) { |
|
||||||
verticalFlowPane.add(createWidgetTypeFilterPane(widgetTypeFilter)); |
|
||||||
} |
|
||||||
for (WidgetFilterTypeInfo info : otherWidgetTypeFilter) { |
|
||||||
verticalFlowPane.add(createOtherCategoryPane(info)); |
|
||||||
} |
|
||||||
return verticalFlowPane; |
|
||||||
} |
|
||||||
|
|
||||||
private JPanel createWidgetTypeFilterPane(List<WidgetFilterTypeInfo> widgetTypeFilter) { |
|
||||||
JPanel jPanel = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
|
||||||
jPanel.setBackground(Color.WHITE); |
|
||||||
UILabel titleLabel = new UILabel(Toolkit.i18nText("Fine-Design_Basic_Type")); |
|
||||||
titleLabel.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5)); |
|
||||||
titleLabel.setPreferredSize(new Dimension(CONTENT_WIDTH - 2, 20)); |
|
||||||
titleLabel.setOpaque(true); |
|
||||||
titleLabel.setBackground(Color.decode("#EDEDEE")); |
|
||||||
jPanel.add(titleLabel, BorderLayout.NORTH); |
|
||||||
|
|
||||||
JPanel contentPane = FRGUIPaneFactory.createVerticalFlowLayout_Pane(true, FlowLayout.LEADING, 0, 10); |
|
||||||
contentPane.setBackground(Color.WHITE); |
|
||||||
for (WidgetFilterTypeInfo info : widgetTypeFilter) { |
|
||||||
contentPane.add(createTypeFilterPane(info)); |
|
||||||
} |
|
||||||
jPanel.add(contentPane, BorderLayout.CENTER); |
|
||||||
return jPanel; |
|
||||||
} |
|
||||||
|
|
||||||
private JPanel createTypeFilterPane(WidgetFilterTypeInfo widgetFilterTypeInfo) { |
|
||||||
JPanel jPanel = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
|
||||||
jPanel.setBackground(Color.WHITE); |
|
||||||
UILabel titleLabel = new UILabel(widgetFilterTypeInfo.getTitle() + ":"); |
|
||||||
titleLabel.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5)); |
|
||||||
titleLabel.setFont(new Font(titleLabel.getFont().getName(), Font.BOLD, titleLabel.getFont().getSize())); |
|
||||||
jPanel.add(titleLabel, BorderLayout.NORTH); |
|
||||||
jPanel.add(createCategoryDetailPane(widgetFilterTypeInfo), BorderLayout.CENTER); |
|
||||||
return jPanel; |
|
||||||
} |
|
||||||
|
|
||||||
private JPanel createOtherCategoryPane(WidgetFilterTypeInfo filterTypeInfo) { |
|
||||||
JPanel jPanel = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
|
||||||
jPanel.setBackground(Color.WHITE); |
|
||||||
UILabel titleLabel = new UILabel(filterTypeInfo.getTitle()); |
|
||||||
titleLabel.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5)); |
|
||||||
titleLabel.setPreferredSize(new Dimension(CONTENT_WIDTH - 2, 20)); |
|
||||||
titleLabel.setOpaque(true); |
|
||||||
titleLabel.setBackground(Color.decode("#EDEDEE")); |
|
||||||
jPanel.add(titleLabel, BorderLayout.NORTH); |
|
||||||
jPanel.add(createCategoryDetailPane(filterTypeInfo), BorderLayout.CENTER); |
|
||||||
return jPanel; |
|
||||||
} |
} |
||||||
|
|
||||||
private JPanel createCategoryDetailPane(WidgetFilterTypeInfo filterTypeInfo) { |
public void setFilters(List<WidgetFilterInfo> selectedFilters) { |
||||||
JPanel contentPane = FRGUIPaneFactory.createNColumnGridInnerContainer_S_Pane(2); |
super.setFilters(selectedFilters); |
||||||
contentPane.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 0)); |
filterPane.changeFilterButtonStatus(hasFilter()); |
||||||
contentPane.setBackground(Color.WHITE); |
|
||||||
int displayCount = 0; |
|
||||||
for (final WidgetFilterInfo filterInfo : filterTypeInfo.getFilterItems()) { |
|
||||||
if (!ComparatorUtils.equals(FILTER_ALL_ID, filterInfo.getId())) { |
|
||||||
displayCount++; |
|
||||||
} |
|
||||||
} |
|
||||||
int contentPaneHeight = ((displayCount + 1) / 2) * 27; |
|
||||||
contentPane.setPreferredSize(new Dimension(CONTENT_WIDTH, contentPaneHeight)); |
|
||||||
for (final WidgetFilterInfo filterInfo : filterTypeInfo.getFilterItems()) { |
|
||||||
if (ComparatorUtils.equals(FILTER_ALL_ID, filterInfo.getId())) { |
|
||||||
continue; |
|
||||||
} |
|
||||||
final UICheckBox checkBox = new UICheckBox(filterInfo.getName()); |
|
||||||
checkBox.setBackground(Color.WHITE); |
|
||||||
|
|
||||||
checkBox.addItemListener(new ItemListener() { |
|
||||||
@Override |
|
||||||
public void itemStateChanged(ItemEvent e) { |
|
||||||
if (reset) { |
|
||||||
return; |
|
||||||
} |
|
||||||
if (checkBox.isSelected()) { |
|
||||||
filterList.add(filterInfo); |
|
||||||
} else if (filterList.contains(filterInfo)) { |
|
||||||
filterList.remove(filterInfo); |
|
||||||
} |
|
||||||
checkFilterButtonStatus(); |
|
||||||
filterPane.fireChangeListener(new ChangeEvent(assembleFilter())); |
|
||||||
} |
|
||||||
}); |
|
||||||
|
|
||||||
|
|
||||||
checkBoxList.add(checkBox); |
|
||||||
contentPane.add(checkBox); |
|
||||||
} |
|
||||||
return contentPane; |
|
||||||
} |
} |
||||||
|
|
||||||
protected abstract String assembleFilter(); |
|
||||||
|
|
||||||
private void checkFilterButtonStatus() { |
protected void fireSelectedChanged(ChangeEvent changeEvent){ |
||||||
filterPane.changeFilterButtonStatus(hasFilter()); |
filterPane.changeFilterButtonStatus(hasFilter()); |
||||||
|
filterPane.fireChangeListener(changeEvent); |
||||||
} |
} |
||||||
|
|
||||||
public void reset() { |
|
||||||
reset = true; |
|
||||||
for (UICheckBox checkBox : checkBoxList) { |
|
||||||
checkBox.setSelected(false); |
|
||||||
} |
|
||||||
filterList.clear(); |
|
||||||
checkFilterButtonStatus(); |
|
||||||
filterPane.fireChangeListener(new ChangeEvent(StringUtils.EMPTY)); |
|
||||||
reset = false; |
|
||||||
} |
|
||||||
|
|
||||||
} |
} |
||||||
|
@ -0,0 +1,349 @@ |
|||||||
|
package com.fr.design.mainframe.share.util; |
||||||
|
|
||||||
|
import com.fr.design.DesignerCloudURLManager; |
||||||
|
import com.fr.design.i18n.Toolkit; |
||||||
|
import com.fr.design.mainframe.share.Bean.FilterTypeInfo; |
||||||
|
import com.fr.form.share.bean.OnlineShareWidget; |
||||||
|
import com.fr.form.share.bean.SortParameter; |
||||||
|
import com.fr.design.mainframe.share.Bean.WidgetFilterInfo; |
||||||
|
import com.fr.design.mainframe.share.Bean.WidgetFilterTypeInfo; |
||||||
|
import com.fr.design.mainframe.share.config.ComponentReuseConfigManager; |
||||||
|
import com.fr.general.ComparatorUtils; |
||||||
|
import com.fr.general.http.HttpClient; |
||||||
|
import com.fr.general.http.HttpToolbox; |
||||||
|
import com.fr.json.JSONArray; |
||||||
|
import com.fr.json.JSONObject; |
||||||
|
import com.fr.log.FineLoggerFactory; |
||||||
|
import com.fr.stable.StableUtils; |
||||||
|
import com.fr.stable.StringUtils; |
||||||
|
|
||||||
|
import java.io.IOException; |
||||||
|
import java.net.HttpURLConnection; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.Comparator; |
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.Iterator; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
import java.util.Set; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by kerry on 2021/11/3 |
||||||
|
*/ |
||||||
|
public class OnlineShopUtils { |
||||||
|
|
||||||
|
private static final String CHART = "chart"; |
||||||
|
private static final String REPORT = "report"; |
||||||
|
private static final String CID_PREFIX = "cid"; |
||||||
|
private static final String CHART_IDS = "123457"; |
||||||
|
|
||||||
|
private OnlineShopUtils() { |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
public static String getReuInfoPath() { |
||||||
|
return ComponentReuseConfigManager.getInstance().getMiniShopUrl(); |
||||||
|
} |
||||||
|
|
||||||
|
private static String getWidgetReusePath() { |
||||||
|
return StableUtils.pathJoin(getReuInfoPath(), "all/detail/"); |
||||||
|
} |
||||||
|
|
||||||
|
private static String getPackageChildrenPath() { |
||||||
|
return StableUtils.pathJoin(getReuInfoPath(), "children/"); |
||||||
|
} |
||||||
|
|
||||||
|
private static String getWidgetFilterPath() { |
||||||
|
return StableUtils.pathJoin(getReuInfoPath(), "/all/filter/"); |
||||||
|
} |
||||||
|
|
||||||
|
private static String getGetCompositeSortParaPath() { |
||||||
|
return StableUtils.pathJoin(getReuInfoPath(), "sort_parameter"); |
||||||
|
} |
||||||
|
|
||||||
|
private static String getLatestReusesPath() { |
||||||
|
return StableUtils.pathJoin(getReuInfoPath(), "prompt/update/"); |
||||||
|
} |
||||||
|
|
||||||
|
private static String getTestConnectionUrl() { |
||||||
|
return DesignerCloudURLManager.getInstance().acquireUrlByKind("ping"); |
||||||
|
} |
||||||
|
|
||||||
|
public static List<FilterTypeInfo> getShowFilterTypeInfos() { |
||||||
|
List<FilterTypeInfo> filterTypeInfos = new ArrayList<>(); |
||||||
|
List<WidgetFilterTypeInfo> widgetFilterTypeInfos = getWidgetFilterTypeInfos(); |
||||||
|
FilterTypeInfo widgetTypeInfo = |
||||||
|
new FilterTypeInfo(Toolkit.i18nText("Fine-Design_Share_Filter_Widget_Type"), ShareFilterConstants.WIDGET_TYPE_FILTER_KEY); |
||||||
|
for (WidgetFilterTypeInfo info : widgetFilterTypeInfos) { |
||||||
|
if (ComparatorUtils.equals(ShareFilterConstants.CHART_FILTER_KEY, info.getKey()) |
||||||
|
|| ComparatorUtils.equals(ShareFilterConstants.REPORT_FILTER_KEY, info.getKey())) { |
||||||
|
widgetTypeInfo.addFilterType(info); |
||||||
|
if (!filterTypeInfos.contains(widgetTypeInfo)) { |
||||||
|
filterTypeInfos.add(widgetTypeInfo); |
||||||
|
} |
||||||
|
} else { |
||||||
|
FilterTypeInfo typeInfo = new FilterTypeInfo(info.getTitle(), info.getKey()); |
||||||
|
typeInfo.addFilterType(info); |
||||||
|
filterTypeInfos.add(typeInfo); |
||||||
|
} |
||||||
|
} |
||||||
|
filterTypeInfos.sort(Comparator.comparingInt(o -> OnlineFilterType.parse(o.getKey()).ordinal())); |
||||||
|
return filterTypeInfos; |
||||||
|
} |
||||||
|
|
||||||
|
enum OnlineFilterType { |
||||||
|
SHOW_DEVICE(ShareFilterConstants.SHOW_TERMINAL_FILTER_KEY), |
||||||
|
STYLE(ShareFilterConstants.STYLE_FILTER_KEY), |
||||||
|
WIDGET_TYPE(ShareFilterConstants.WIDGET_TYPE_FILTER_KEY), |
||||||
|
FEE(ShareFilterConstants.FEE_FILTER_KEY), |
||||||
|
VERSION(ShareFilterConstants.VERSION_FILTER_KEY); |
||||||
|
private String flag; |
||||||
|
|
||||||
|
private OnlineFilterType(String flag) { |
||||||
|
this.flag = flag; |
||||||
|
} |
||||||
|
|
||||||
|
public static OnlineFilterType parse(String flag) { |
||||||
|
for (OnlineFilterType filterType : values()) { |
||||||
|
if (ComparatorUtils.equals(filterType.flag, flag)) { |
||||||
|
return filterType; |
||||||
|
} |
||||||
|
} |
||||||
|
return SHOW_DEVICE; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public static List<FilterTypeInfo> getEmbPaneShowFilterTypeInfos() { |
||||||
|
List<FilterTypeInfo> filterTypeInfos = new ArrayList<>(); |
||||||
|
List<WidgetFilterTypeInfo> widgetFilterTypeInfos = getWidgetFilterTypeInfos(); |
||||||
|
WidgetFilterTypeInfo widgetTypeFilterInfo = new WidgetFilterTypeInfo(); |
||||||
|
widgetTypeFilterInfo.setTitle(Toolkit.i18nText("Fine-Design_Share_Filter_Widget_Type")); |
||||||
|
FilterTypeInfo widgetType = new FilterTypeInfo(widgetTypeFilterInfo.getTitle(), ShareFilterConstants.WIDGET_TYPE_FILTER_KEY); |
||||||
|
widgetType.addFilterType(widgetTypeFilterInfo); |
||||||
|
WidgetFilterInfo reportCard = new WidgetFilterInfo(); |
||||||
|
reportCard.setName(Toolkit.i18nText("Fine-Design_Share_Online_Filter_Indicator_Card")); |
||||||
|
WidgetFilterInfo chartType = new WidgetFilterInfo(); |
||||||
|
chartType.setName(Toolkit.i18nText("Fine-Design_Share_Online_Filter_Chart")); |
||||||
|
WidgetFilterInfo otherType = new WidgetFilterInfo(); |
||||||
|
otherType.setName(Toolkit.i18nText("Fine-Design_Share_Online_Filter_Other_Type")); |
||||||
|
widgetTypeFilterInfo.addFilterItem(reportCard); |
||||||
|
widgetTypeFilterInfo.addFilterItem(chartType); |
||||||
|
widgetTypeFilterInfo.addFilterItem(otherType); |
||||||
|
for (WidgetFilterTypeInfo info : widgetFilterTypeInfos) { |
||||||
|
if (ComparatorUtils.equals(ShareFilterConstants.SHOW_TERMINAL_FILTER_KEY, info.getKey())) { |
||||||
|
FilterTypeInfo showTerminalInfo = new FilterTypeInfo(info.getTitle(), info.getKey()); |
||||||
|
showTerminalInfo.addFilterType(info); |
||||||
|
filterTypeInfos.add(showTerminalInfo); |
||||||
|
|
||||||
|
} else if (ComparatorUtils.equals(ShareFilterConstants.STYLE_FILTER_KEY, info.getKey())) { |
||||||
|
FilterTypeInfo styleTypeInfo = new FilterTypeInfo(info.getTitle(), info.getKey()); |
||||||
|
styleTypeInfo.addFilterType(info); |
||||||
|
filterTypeInfos.add(styleTypeInfo); |
||||||
|
} else if (ComparatorUtils.equals(ShareFilterConstants.REPORT_FILTER_KEY, info.getKey())) { |
||||||
|
for (WidgetFilterInfo filterInfo : info.getFilterItems()) { |
||||||
|
if (ComparatorUtils.equals(filterInfo.getId(), "1")) { |
||||||
|
reportCard.addChildFilterInfo(filterInfo); |
||||||
|
} else { |
||||||
|
otherType.addChildFilterInfo(filterInfo); |
||||||
|
} |
||||||
|
} |
||||||
|
} else if (ComparatorUtils.equals(ShareFilterConstants.CHART_FILTER_KEY, info.getKey())) { |
||||||
|
for (WidgetFilterInfo filterInfo : info.getFilterItems()) { |
||||||
|
if (filterInfo.getId() != null && CHART_IDS.contains(filterInfo.getId())) { |
||||||
|
chartType.addChildFilterInfo(filterInfo); |
||||||
|
} else { |
||||||
|
otherType.addChildFilterInfo(filterInfo); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
filterTypeInfos.add(widgetType); |
||||||
|
return filterTypeInfos; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
public static Map<String, SortParameter> getCompositeSortPara() { |
||||||
|
Map<String, SortParameter> para = new HashMap<>(); |
||||||
|
try { |
||||||
|
JSONArray resultArr = getResultAttrFromUrl(getGetCompositeSortParaPath()); |
||||||
|
int size = resultArr.size(); |
||||||
|
for (int i = 0; i < size; i++) { |
||||||
|
JSONObject jo = resultArr.getJSONObject(i); |
||||||
|
SortParameter sortParameter = SortParameter.parseFromJSONObject(jo); |
||||||
|
para.put(sortParameter.getParameter(), sortParameter); |
||||||
|
} |
||||||
|
} catch (Exception e) { |
||||||
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||||
|
} |
||||||
|
return para; |
||||||
|
} |
||||||
|
|
||||||
|
public static String assembleFilter(List<WidgetFilterInfo> filterInfos) { |
||||||
|
List<WidgetFilterInfo> allFilterInfos = getAllFilterInfoList(filterInfos); |
||||||
|
List<String> cidList = new ArrayList<>(); |
||||||
|
Map<String, String> queryParaMap = new HashMap<>(); |
||||||
|
for (WidgetFilterInfo filterInfo : allFilterInfos) { |
||||||
|
if (ComparatorUtils.equals(CHART, filterInfo.getType()) |
||||||
|
|| ComparatorUtils.equals(REPORT, filterInfo.getType())) { |
||||||
|
cidList.add(filterInfo.getType() + "-" + filterInfo.getId()); |
||||||
|
continue; |
||||||
|
} |
||||||
|
String queryValue = queryParaMap.get(filterInfo.getType()); |
||||||
|
if (StringUtils.isNotEmpty(queryValue)) { |
||||||
|
queryValue += "," + filterInfo.getId(); |
||||||
|
} else { |
||||||
|
queryValue = filterInfo.getId(); |
||||||
|
} |
||||||
|
queryParaMap.put(filterInfo.getType(), queryValue); |
||||||
|
} |
||||||
|
StringBuffer sb; |
||||||
|
List<String> queryCondition = new ArrayList<>(); |
||||||
|
if (!cidList.isEmpty()) { |
||||||
|
sb = new StringBuffer(); |
||||||
|
sb.append(CID_PREFIX).append("=").append(StringUtils.join(",", cidList.toArray(new String[cidList.size()]))); |
||||||
|
queryCondition.add(sb.toString()); |
||||||
|
} |
||||||
|
|
||||||
|
Iterator<Map.Entry<String, String>> iterator = queryParaMap.entrySet().iterator(); |
||||||
|
while (iterator.hasNext()) { |
||||||
|
Map.Entry<String, String> entry = iterator.next(); |
||||||
|
sb = new StringBuffer(); |
||||||
|
sb.append(entry.getKey()).append("=").append(entry.getValue()); |
||||||
|
queryCondition.add(sb.toString()); |
||||||
|
} |
||||||
|
return StringUtils.join("&", queryCondition.toArray(new String[queryCondition.size()])); |
||||||
|
} |
||||||
|
|
||||||
|
private static List<WidgetFilterInfo> getAllFilterInfoList(List<WidgetFilterInfo> filterInfos) { |
||||||
|
List<WidgetFilterInfo> allFilterList = new ArrayList<>(); |
||||||
|
for (WidgetFilterInfo filterInfo : filterInfos) { |
||||||
|
if (filterInfo.hasChildFilter()) { |
||||||
|
allFilterList.addAll(filterInfo.getInnerFilterInfo()); |
||||||
|
} else { |
||||||
|
allFilterList.add(filterInfo); |
||||||
|
} |
||||||
|
} |
||||||
|
return allFilterList; |
||||||
|
} |
||||||
|
|
||||||
|
public static boolean testConnection() { |
||||||
|
HttpClient httpClient = new HttpClient(getTestConnectionUrl()); |
||||||
|
httpClient.asGet(); |
||||||
|
int responseCode = httpClient.getResponseCode(); |
||||||
|
return responseCode == HttpURLConnection.HTTP_OK; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
public static List<OnlineShareWidget>[] getAllSharableWidgetsFromShop() throws Exception { |
||||||
|
List<OnlineShareWidget>[] sharableWidgetsArray = new List[]{new ArrayList<>(), new ArrayList<>()}; |
||||||
|
JSONArray resultArr = getResultAttrFromUrl(getWidgetReusePath()); |
||||||
|
int size = resultArr.size(); |
||||||
|
for (int i = 0; i < size; i++) { |
||||||
|
JSONObject jo = resultArr.getJSONObject(i); |
||||||
|
OnlineShareWidget temp = OnlineShareWidget.parseFromJSONObject(jo); |
||||||
|
if (temp.isWidgetPackage()) { |
||||||
|
sharableWidgetsArray[1].add(temp); |
||||||
|
} else { |
||||||
|
sharableWidgetsArray[0].add(temp); |
||||||
|
} |
||||||
|
} |
||||||
|
return sharableWidgetsArray; |
||||||
|
} |
||||||
|
|
||||||
|
public static OnlineShareWidget[] getPackageWidgets(OnlineShareWidget widgetPackage) { |
||||||
|
String plistUrl = getPackageChildrenPath() + widgetPackage.getId(); |
||||||
|
OnlineShareWidget[] widgets = getOnlineShareWidgets(plistUrl); |
||||||
|
for (OnlineShareWidget widget : widgets) { |
||||||
|
widget.setParentPackage(widgetPackage); |
||||||
|
} |
||||||
|
return widgets; |
||||||
|
} |
||||||
|
|
||||||
|
public static List<WidgetFilterTypeInfo> getWidgetFilterTypeInfos() { |
||||||
|
List<WidgetFilterTypeInfo> result = new ArrayList<>(); |
||||||
|
try { |
||||||
|
JSONArray resultArr = getResultAttrFromUrl(getWidgetFilterPath()); |
||||||
|
int size = resultArr.size(); |
||||||
|
for (int i = 0; i < size; i++) { |
||||||
|
JSONObject jo = resultArr.getJSONObject(i); |
||||||
|
result.add(WidgetFilterTypeInfo.parseFromJSONObject(jo)); |
||||||
|
} |
||||||
|
} catch (Exception e) { |
||||||
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||||
|
} |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
private static OnlineShareWidget[] getOnlineShareWidgets(String url) { |
||||||
|
if (StringUtils.isNotBlank(url)) { |
||||||
|
try { |
||||||
|
JSONArray resultArr = getResultAttrFromUrl(url); |
||||||
|
int size = resultArr.size(); |
||||||
|
List<OnlineShareWidget> onlineShareWidgets = new ArrayList<>(); |
||||||
|
for (int i = 0; i < size; i++) { |
||||||
|
JSONObject jo = resultArr.getJSONObject(i); |
||||||
|
OnlineShareWidget widget = OnlineShareWidget.parseFromJSONObject(jo); |
||||||
|
if (!widget.isWidgetPackage()) { |
||||||
|
onlineShareWidgets.add(widget); |
||||||
|
} |
||||||
|
} |
||||||
|
return onlineShareWidgets.toArray(new OnlineShareWidget[onlineShareWidgets.size()]); |
||||||
|
} catch (Exception e) { |
||||||
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||||
|
} |
||||||
|
} |
||||||
|
return new OnlineShareWidget[]{}; |
||||||
|
} |
||||||
|
|
||||||
|
public static OnlineShareWidget[] getFilterWidgets(String filterStr) { |
||||||
|
|
||||||
|
String plistUrl = getWidgetReusePath() + "?" + filterStr; |
||||||
|
return getOnlineShareWidgets(plistUrl); |
||||||
|
} |
||||||
|
|
||||||
|
public static List<OnlineShareWidget> getLatestReusesByDesignerVersion(Set<String> reuseIds, String designerVersion) { |
||||||
|
List<OnlineShareWidget> result = new ArrayList<>(); |
||||||
|
try { |
||||||
|
JSONObject params = JSONObject.create(); |
||||||
|
StringBuilder reuseIdsStr = new StringBuilder(); |
||||||
|
for (String id: reuseIds) { |
||||||
|
reuseIdsStr.append(id).append(","); |
||||||
|
} |
||||||
|
params.put("reuseIds", reuseIdsStr.toString()); |
||||||
|
params.put("designerVersion", designerVersion); |
||||||
|
JSONArray resultArr = postResultAttrFormUrl(getLatestReusesPath(), params); |
||||||
|
int size = resultArr.size(); |
||||||
|
for (int i = 0; i < size; i++) { |
||||||
|
JSONObject jo = resultArr.getJSONObject(i); |
||||||
|
result.add(OnlineShareWidget.parseFromJSONObject(jo)); |
||||||
|
} |
||||||
|
} catch (Exception e) { |
||||||
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||||
|
} |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
private static JSONArray getResultAttrFromUrl(String url) { |
||||||
|
HttpClient httpClient = new HttpClient(url); |
||||||
|
httpClient.asGet(); |
||||||
|
String responseText = httpClient.getResponseText(); |
||||||
|
JSONObject resultJSONObject = new JSONObject(responseText); |
||||||
|
return resultJSONObject.getJSONArray("result"); |
||||||
|
} |
||||||
|
|
||||||
|
private static JSONArray postResultAttrFormUrl(String url, JSONObject params) { |
||||||
|
JSONArray result = JSONArray.create(); |
||||||
|
try { |
||||||
|
String responseText = HttpToolbox.post(url, params.toMap()); |
||||||
|
if (StringUtils.isNotEmpty(responseText)) { |
||||||
|
JSONObject resultJSONObject = new JSONObject(responseText); |
||||||
|
result = resultJSONObject.getJSONArray("result"); |
||||||
|
} |
||||||
|
} catch (IOException e) { |
||||||
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||||
|
} |
||||||
|
|
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,17 @@ |
|||||||
|
package com.fr.design.mainframe.share.util; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by kerry on 2021/11/3 |
||||||
|
*/ |
||||||
|
public class ShareFilterConstants { |
||||||
|
public static final String CHART_FILTER_KEY = "3@chart"; |
||||||
|
public static final String REPORT_FILTER_KEY = "4@report"; |
||||||
|
public static final String SHOW_TERMINAL_FILTER_KEY = "4@displayDevice"; |
||||||
|
public static final String STYLE_FILTER_KEY = "5@style"; |
||||||
|
public static final String FEE_FILTER_KEY = "2@fee"; |
||||||
|
public static final String VERSION_FILTER_KEY = "6@version"; |
||||||
|
public static final String WIDGET_TYPE_FILTER_KEY = "1@widgetType"; |
||||||
|
public static final String SOURCE_TYPE_FILTER_KEY = "2@source"; |
||||||
|
|
||||||
|
public static final String ALL_STYLE_THEME = "0"; |
||||||
|
} |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue