Browse Source

Pull request #16818: feat: JSContentPane支持自定义提示功能 #REPORT-144004

Merge in DESIGN/design from ~ZHANYING/design:feature/x to feature/x

* commit '58f07b2980357f8eb1c5b3415aa02630fefa0395':
  feat: JSContentPane支持自定义提示功能 #REPORT-144004
feature/x
Zhanying-占盈 1 month ago
parent
commit
6ff640fa57
  1. 17
      designer-base/src/main/java/com/fr/design/fun/DefaultValueAdjustProvider.java
  2. 112
      designer-base/src/main/java/com/fr/design/javascript/JSContentPane.java
  3. 32
      designer-base/src/main/java/com/fr/design/javascript/JSContentWithDescriptionPane.java
  4. 23
      designer-base/src/main/java/com/fr/design/javascript/JavaScriptImplPane.java
  5. 23
      designer-base/src/main/java/com/fr/design/javascript/NewJavaScriptImplPane.java

17
designer-base/src/main/java/com/fr/design/fun/DefaultValueAdjustProvider.java

@ -6,6 +6,7 @@ import com.fr.chartx.attr.ChartProvider;
import com.fr.design.style.color.FRColorSelectorStyle;
import com.fr.general.FRFont;
import com.fr.report.cell.CellElement;
import com.fr.stable.StringUtils;
import com.fr.stable.collections.combination.Pair;
import com.fr.stable.fun.mark.Selectable;
@ -92,4 +93,20 @@ public interface DefaultValueAdjustProvider extends Selectable {
default boolean isNeedPostCombo4MobilePopupPane() {
return false;
}
/**
* JsContentPane是否支持内容提示
* @return 是否支持
*/
default boolean isNeedContentWarning4JsContentPane() {
return false;
}
/**
* 自定义匹配js内容并返回对应的提示文本
* @return <是否匹配提示文本>
*/
default Pair<Boolean, String> checkJsContent(String content) {
return new Pair<>(false, StringUtils.EMPTY);
}
}

112
designer-base/src/main/java/com/fr/design/javascript/JSContentPane.java

@ -25,12 +25,19 @@ import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.mainframe.DesignerContext;
import com.fr.general.IOUtils;
import com.fr.js.JavaScriptImpl;
import com.fr.stable.StringUtils;
import com.fr.stable.collections.combination.Pair;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.KeyStroke;
import javax.swing.SwingConstants;
import javax.swing.SwingWorker;
import javax.swing.border.EmptyBorder;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.FontMetrics;
@ -54,6 +61,13 @@ public class JSContentPane extends BasicPane {
private JSImplPopulateAction jsImplPopulateAction;
private boolean modal;
BasicDialog advancedEditorDialog ;
private JLabel warningLabel;
//用来标记当前显示状态
private boolean showWarning = false;
private static final Color WARING_LABEL_BACKGROUND = Color.decode("#FFFBE6");
private static final Color WARING_LABEL_FOREGROUND = new Color(0, 0, 0, 216);
private JPanel endBracketsPanel;
public JSContentPane(){}
public JSContentPane(String[] args) {
@ -73,14 +87,91 @@ public class JSContentPane extends BasicPane {
UILabel funNameLabel2 = new UILabel();
funNameLabel2.setText("}");
this.add(funNameLabel2, BorderLayout.SOUTH);
if (isNeedContentWarning()) {
endBracketsPanel = FRGUIPaneFactory.createBorderLayout_S_Pane();
endBracketsPanel.add(funNameLabel2, BorderLayout.NORTH);
warningLabel = initWarningLabel();
this.add(endBracketsPanel, BorderLayout.SOUTH);
} else {
this.add(funNameLabel2, BorderLayout.SOUTH);
}
}
protected JLabel initWarningLabel() {
JLabel warningLabel = new JLabel(StringUtils.EMPTY);
warningLabel.setOpaque(true);
warningLabel.setAlignmentX(LEFT_ALIGNMENT);
// 设置左右 5px 的间距
warningLabel.setBorder(new EmptyBorder(0, 5, 0, 5));
warningLabel.setPreferredSize(new Dimension(200, 20));
warningLabel.setBackground(WARING_LABEL_BACKGROUND);
warningLabel.setForeground(WARING_LABEL_FOREGROUND);
addContentListener4Warning();
return warningLabel;
}
private void addContentListener4Warning() {
contentTextArea.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void insertUpdate(DocumentEvent e) {
checkContent(contentTextArea);
}
@Override
public void removeUpdate(DocumentEvent e) {
checkContent(contentTextArea);
}
@Override
public void changedUpdate(DocumentEvent e) {
checkContent(contentTextArea);
}
});
}
private void checkContent(RSyntaxTextArea contentTextArea) {
String content = contentTextArea.getText().trim();
Pair<Boolean, String> pair = checkContent(content);
boolean matches = Boolean.TRUE.equals(pair.getFirst());
String tip = pair.getSecond() != null ? pair.getSecond() : StringUtils.EMPTY;
// 更新提示
updateWarningTip(tip);
if (matches == showWarning) {
return;
}
if (matches) {
addWarningLabel();
showWarning = true;
} else {
removeWarningLabel();
showWarning = false;
}
}
protected void updateWarningTip(String tip) {
if (!StringUtils.equals(warningLabel.getText(), tip)) {
warningLabel.setText(tip);
}
}
protected void removeWarningLabel() {
endBracketsPanel.remove(warningLabel);
endBracketsPanel.revalidate();
}
protected void addWarningLabel() {
endBracketsPanel.add(warningLabel, BorderLayout.SOUTH);
endBracketsPanel.revalidate();
}
public JSContentPane(String[] args,boolean modal) {
this(args);
this.modal = modal;
}
public void setJsImplUpdateAction(JSImplUpdateAction jsImplUpdateAction){
this.jsImplUpdateAction = jsImplUpdateAction;
}
@ -93,7 +184,6 @@ public class JSContentPane extends BasicPane {
this.javaScript = javaScript;
}
private void addNewPaneLabel(){
UILabel advancedEditorLabel = new UILabel(Toolkit.i18nText("Fine-Design_Advanced_Editor"), IconUtils.readIcon("com/fr/design/images/edit/advancedEditor.svg"), SwingConstants.LEFT);
advancedEditorLabel.setCursor(new Cursor(Cursor.HAND_CURSOR));
@ -328,4 +418,20 @@ public class JSContentPane extends BasicPane {
protected boolean needAdvancedEditor() {
return true;
}
/**
* 是否支持内容提示
* @return 是否支持
*/
protected boolean isNeedContentWarning() {
return false;
}
/**
* 自定义匹配js内容并返回对应的提示文本
* @return <是否匹配提示文本>
*/
protected Pair<Boolean, String> checkContent(String content) {
return new Pair<>(false, StringUtils.EMPTY);
}
}

32
designer-base/src/main/java/com/fr/design/javascript/JSContentWithDescriptionPane.java

@ -32,6 +32,7 @@ import javax.swing.BorderFactory;
import javax.swing.DefaultListCellRenderer;
import javax.swing.DefaultListModel;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
@ -71,7 +72,6 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.ExecutionException;
public class JSContentWithDescriptionPane extends JSContentPane implements KeyListener {
@ -95,6 +95,9 @@ public class JSContentWithDescriptionPane extends JSContentPane implements KeyLi
private JPopupMenu popupMenu;
private JPanel endBracketsPanel;
private JLabel warningLabel;
private InterfaceAndDescriptionPanel interfaceAndDescriptionPanel;
private JList helpDOCList;
@ -159,8 +162,13 @@ public class JSContentWithDescriptionPane extends JSContentPane implements KeyLi
endBracketsLabel.setText("}");
//结尾括号和复用函数按钮面板
JPanel endBracketsPanel = FRGUIPaneFactory.createBorderLayout_S_Pane();
endBracketsPanel.add(endBracketsLabel, BorderLayout.WEST);
endBracketsPanel = FRGUIPaneFactory.createBorderLayout_S_Pane();
if (isNeedContentWarning()) {
warningLabel = initWarningLabel();
endBracketsPanel.add(endBracketsLabel, BorderLayout.NORTH);
} else {
endBracketsPanel.add(endBracketsLabel, BorderLayout.WEST);
}
JPanel northPanel = FRGUIPaneFactory.createBorderLayout_S_Pane();
northPanel.add(jsParaAndSearchPane, BorderLayout.NORTH);
@ -178,6 +186,24 @@ public class JSContentWithDescriptionPane extends JSContentPane implements KeyLi
this.add(functionNameAndDescriptionPanel, BorderLayout.SOUTH);
}
protected void updateWarningTip(String tip) {
if (!StringUtils.equals(warningLabel.getText(), tip)) {
warningLabel.setText(tip);
}
}
@Override
protected void removeWarningLabel() {
endBracketsPanel.remove(warningLabel);
endBracketsPanel.revalidate();
}
@Override
protected void addWarningLabel() {
endBracketsPanel.add(warningLabel, BorderLayout.SOUTH);
endBracketsPanel.revalidate();
}
public void populate(String js) {
contentTextArea.setText(js);
ifHasBeenWriten = 1;

23
designer-base/src/main/java/com/fr/design/javascript/JavaScriptImplPane.java

@ -3,6 +3,7 @@ package com.fr.design.javascript;
import com.fr.base.Parameter;
import com.fr.design.data.tabledata.tabledatapane.OneListTableModel;
import com.fr.design.dialog.FineJOptionPane;
import com.fr.design.fun.DefaultValueAdjustProvider;
import com.fr.design.gui.frpane.ReportletParameterViewPane;
import com.fr.design.gui.itableeditorpane.ParameterTableModel;
import com.fr.design.gui.itableeditorpane.UITableEditAction;
@ -13,10 +14,12 @@ import com.fr.design.javascript.jsapi.JSImplPopulateAction;
import com.fr.design.javascript.jsapi.JSImplUpdateAction;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.scrollruler.ModLineBorder;
import com.fr.design.utils.DesignUtils;
import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.js.JavaScriptImpl;
import com.fr.stable.ParameterProvider;
import com.fr.stable.StringUtils;
import com.fr.stable.collections.combination.Pair;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
@ -84,7 +87,25 @@ public class JavaScriptImplPane extends AbstractHyperLinkPane<JavaScriptImpl> {
}
protected JSContentPane createJSContentPane(String[] defaultArgs){
JSContentPane jsContentPane= new JSContentPane(defaultArgs,modal);
JSContentPane jsContentPane= new JSContentPane(defaultArgs,modal) {
@Override
protected boolean isNeedContentWarning() {
DefaultValueAdjustProvider valueAdjust = DesignUtils.getValueAdjust();
if (valueAdjust != null) {
return valueAdjust.isNeedContentWarning4JsContentPane();
}
return super.isNeedContentWarning();
}
@Override
protected Pair<Boolean, String> checkContent(String content) {
DefaultValueAdjustProvider valueAdjust = DesignUtils.getValueAdjust();
if (valueAdjust != null) {
return valueAdjust.checkJsContent(content);
}
return super.checkContent(content);
}
};
jsContentPane.setJsImplUpdateAction(new JSImplUpdateAction() {
@Override
public void update(JavaScriptImpl javaScript) {

23
designer-base/src/main/java/com/fr/design/javascript/NewJavaScriptImplPane.java

@ -1,7 +1,10 @@
package com.fr.design.javascript;
import com.fr.design.fun.DefaultValueAdjustProvider;
import com.fr.design.utils.DesignUtils;
import com.fr.js.JavaScriptImpl;
import com.fr.stable.collections.combination.Pair;
public class NewJavaScriptImplPane extends JavaScriptImplPane {
@ -10,7 +13,25 @@ public class NewJavaScriptImplPane extends JavaScriptImplPane {
}
protected JSContentPane createJSContentPane(String[] defaultArgs){
return new JSContentWithDescriptionPane(defaultArgs);
return new JSContentWithDescriptionPane(defaultArgs) {
@Override
protected boolean isNeedContentWarning() {
DefaultValueAdjustProvider valueAdjust = DesignUtils.getValueAdjust();
if (valueAdjust != null) {
return valueAdjust.isNeedContentWarning4JsContentPane();
}
return super.isNeedContentWarning();
}
@Override
protected Pair<Boolean, String> checkContent(String content) {
DefaultValueAdjustProvider valueAdjust = DesignUtils.getValueAdjust();
if (valueAdjust != null) {
return valueAdjust.checkJsContent(content);
}
return super.checkContent(content);
}
};
}
public void populate(JavaScriptImpl javaScript) {

Loading…
Cancel
Save