帆软报表设计器源代码。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

288 lines
10 KiB

package com.fr.design.webattr;
import com.fine.theme.utils.FineUIStyle;
import com.formdev.flatlaf.util.ScaledEmptyBorder;
import com.fr.design.constants.LayoutConstants;
import com.fr.design.dialog.BasicPane;
import com.fr.design.dialog.FineJOptionPane;
import com.fr.design.gui.frpane.EditingStringListPane;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.ibutton.UIRadioButton;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.itextfield.UITextField;
import com.fr.design.i18n.DesignSizeI18nManager;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.widget.FRWidgetFactory;
import com.fr.file.FILE;
import com.fr.file.FILEChooserPane;
import com.fr.file.filter.ChooseFileFilter;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.CoreConstants;
import com.fr.stable.StringUtils;
import com.fr.stable.project.ProjectConstants;
import com.fr.web.attr.ReportWebAttr;
import javax.swing.ButtonGroup;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;
import static com.fine.swing.ui.layout.Layouts.cell;
import static com.fine.swing.ui.layout.Layouts.column;
import static com.fine.swing.ui.layout.Layouts.row;
import static com.fine.swing.ui.layout.Layouts.fix;
public class WebJsPane extends BasicPane {
private UITextField localText;
private UITextField urlText;
private UIRadioButton localFileRadioButton;
private UIRadioButton urlFileRadioButton;
private EditingStringListPane editingPane;
UIButton chooseFile;
UIButton testConnection;
UILabel info1;
UILabel info2;
public WebJsPane() {
this.setLayout(new BorderLayout());
localFileRadioButton = new UIRadioButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Disk_File"), true);
urlFileRadioButton = new UIRadioButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Url_Location"), false);
ButtonGroup bg = new ButtonGroup();
bg.add(localFileRadioButton);
bg.add(urlFileRadioButton);
localFileRadioButton.addActionListener(radioActionListener);
urlFileRadioButton.addActionListener(radioActionListener);
urlFileRadioButton.setForeground(new Color(143, 142, 139));
localFileRadioButton.setForeground(Color.black);
localText = new UITextField();
localText.setEditable(false);
urlText = new UITextField();
localText.setPreferredSize(DesignSizeI18nManager.getInstance().i18nDimension("com.fr.design.web.pane.text.field"));
urlText.setPreferredSize(DesignSizeI18nManager.getInstance().i18nDimension("com.fr.design.web.pane.text.field"));
urlText.addKeyListener(urlTextListener);
urlText.setEnabled(false);
chooseFile = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Selection"));
chooseFile.addActionListener(chooseFileListener);
testConnection = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Test_URL"));
testConnection.setEnabled(false);
testConnection.addActionListener(testConnectionListener);// 测试连接按钮
//ember:中英文两个按钮大小比较的结果不确定,做下判断
if(testConnection.getPreferredSize().width > chooseFile.getPreferredSize().width) {
chooseFile.setPreferredSize(testConnection.getPreferredSize());
} else {
testConnection.setPreferredSize(chooseFile.getPreferredSize());
}
createNorthPane();
createEditingPane();
}
private void createNorthPane() {
info1 = FRWidgetFactory.createLineWrapLabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_JS_WARNING1", ProjectConstants.WEBAPP_NAME, ProjectConstants.WEBAPP_NAME));
FineUIStyle.setStyle(info1, FineUIStyle.LABEL_WARNING_TIP);
info2 = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_JS_WARNING2", ProjectConstants.WEBAPP_NAME));
FineUIStyle.setStyle(info2, FineUIStyle.LABEL_WARNING_TIP);
JPanel outNorth = column(LayoutConstants.VERTICAL_GAP,
row(cell(localFileRadioButton), fix(LayoutConstants.HORIZONTAL_GAP), cell(localText).weight(1), fix(LayoutConstants.HGAP_LARGE), cell(chooseFile)),
cell(info1),
row(cell(urlFileRadioButton), fix(LayoutConstants.HORIZONTAL_GAP), cell(urlText).weight(1), fix(LayoutConstants.HGAP_LARGE), cell(testConnection)),
cell(info2)
).getComponent();
JPanel workPanel = new JPanel(new BorderLayout());
workPanel.add(outNorth);
this.add(workPanel, BorderLayout.NORTH);
}
private void createEditingPane() {
editingPane = new EditingStringListPane() {
@Override
protected String getAddOrEditString() {
if (localFileRadioButton.isSelected()) {
return localText.getText();
} else {
String url = urlText.getText();
if (url.matches("^[a-zA-z]+://.+js")) {
return url;
} else {
FineJOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor(WebJsPane.this), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Add_JS_warning"));
return "";
}
}
}
@Override
protected void selectedChanged(String selected) {
if (selected == null) {
localFileRadioButton.doClick();
localText.setText("");
return;
}
if (selected.matches("^[a-zA-z]+://.+js")) {
urlFileRadioButton.doClick();
urlText.setText(selected);
} else {
localFileRadioButton.doClick();
localText.setText(selected);
}
checkEnableState();
}
};
JPanel workPanel = new JPanel(new BorderLayout());
editingPane.setBorder(new ScaledEmptyBorder(10,0,0,0));
workPanel.add(editingPane);
this.add(editingPane, BorderLayout.CENTER);
}
@Override
protected String title4PopupWindow() {
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_ReportServerP_Import_JavaScript");
}
private ActionListener chooseFileListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
FILEChooserPane fileChooser = FILEChooserPane.getInstanceWithDesignatePath(ProjectConstants.RESOURCES_NAME ,
new ChooseFileFilter("js", "javascript" + com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_File")), ProjectConstants.RESOURCES_NAME);
if (fileChooser.showOpenDialog(DesignerContext.getDesignerFrame()) == FILEChooserPane.OK_OPTION) {
final FILE file = fileChooser.getSelectedFILE();
if (file == null) {// 选择的文件不能是 null
return;
}
String fileName = file.getName();
String fileType = fileName.substring(fileName.lastIndexOf(CoreConstants.DOT) + 1);
if (!"js".equalsIgnoreCase(fileType)) {
return;
}
localText.setText(file.getPath());
editingPane.setAddEnabled(true);
}
fileChooser.removeFILEFilter(new ChooseFileFilter("js"));
}
};
private ActionListener testConnectionListener = new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String uri = urlText.getText();
if (!uri.matches("^[a-zA-z]+://.+js")) {
FineJOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor(WebJsPane.this), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Add_JS_warning"));
return;
}
InputStream in = null;
try {
URL url = new URL(urlText.getText());
URLConnection connection = url.openConnection();
in = connection.getInputStream();
} catch (Throwable e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
if (in == null) {
FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(),
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Database_Connection_Failed"),
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Failed"),
JOptionPane.ERROR_MESSAGE);
} else {
FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Datasource_Connection_Successfully"));
try {
in.close();
} catch (IOException e) {
in = null;
}
}
}
};
private ActionListener radioActionListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (localFileRadioButton.isSelected()) {
localRadioSelectAction();
urlFileRadioButton.setForeground(new Color(143, 142, 139));
localFileRadioButton.setForeground(Color.black);
info1.setText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_JS_WARNING1", ProjectConstants.WEBAPP_NAME, ProjectConstants.WEBAPP_NAME));
info2.setText(" ");
} else if (urlFileRadioButton.isSelected()) {
urlRadioSelectAction();
localFileRadioButton.setForeground(new Color(143, 142, 139));
urlFileRadioButton.setForeground(Color.black);
info2.setText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_JS_WARNING2", ProjectConstants.WEBAPP_NAME));
info1.setText(" ");
}
if (StringUtils.isEmpty(urlText.getText()) && StringUtils.isEmpty(localText.getText())) {
editingPane.setAddEnabled(false);
}
}
};
private KeyListener urlTextListener = new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
String url = urlText.getText();
if (url != null && url.matches("^[a-zA-z]+://.+js")) {
editingPane.setAddEnabled(true);
}
}
};
private void localRadioSelectAction() {
localFileRadioButton.setSelected(true);
chooseFile.setEnabled(true);
localText.setEnabled(true);
urlText.setText("");
urlText.setEnabled(false);
testConnection.setEnabled(false);
}
private void urlRadioSelectAction() {
urlFileRadioButton.setSelected(true);
testConnection.setEnabled(true);
urlText.setEnabled(true);
localText.setText("");
localText.setEnabled(false);
chooseFile.setEnabled(false);
}
public void populate(ReportWebAttr reportWebAttr) {
if (reportWebAttr == null) {
editingPane.populateBean(new ArrayList<String>());
return;
}
List<String> list = new ArrayList<String>();
for (int i = 0; i < reportWebAttr.getJSImportCount(); i++) {
if (StringUtils.isNotBlank(reportWebAttr.getJSImport(i))) {
list.add(reportWebAttr.getJSImport(i));
}
}
editingPane.populateBean(list);
}
public void update(ReportWebAttr reportWebAttr) {
List<String> valueList = editingPane.updateBean();
reportWebAttr.clearJSImportList();
for (int i = 0; i < valueList.size(); i++) {
String a = valueList.get(i);
reportWebAttr.addJSImport(a);
}
}
}