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.
299 lines
11 KiB
299 lines
11 KiB
package com.fr.design.webattr; |
|
|
|
import com.fine.theme.utils.FineUIUtils; |
|
import com.fr.base.ConfigManager; |
|
import com.fr.config.Configuration; |
|
import com.fr.design.constants.LayoutConstants; |
|
import com.fr.design.dialog.BasicDialog; |
|
import com.fr.design.dialog.DialogActionAdapter; |
|
import com.fr.design.gui.core.WidgetOption; |
|
import com.fr.design.gui.ibutton.UIButton; |
|
import com.fr.design.gui.ibutton.UIRadioButton; |
|
import com.fr.design.gui.icheckbox.UICheckBox; |
|
import com.fr.design.gui.ilable.UILabel; |
|
import com.fr.design.gui.itextfield.UITextField; |
|
import com.fr.design.layout.FRGUIPaneFactory; |
|
import com.fr.form.event.Listener; |
|
|
|
import com.fr.general.ComparatorUtils; |
|
import com.fr.report.web.Location; |
|
import com.fr.report.web.ToolBarManager; |
|
import com.fr.report.web.WebContent; |
|
import com.fr.report.web.WebPage; |
|
import com.fr.stable.StringUtils; |
|
import com.fr.transaction.Configurations; |
|
import com.fr.transaction.Worker; |
|
import com.fr.web.attr.ReportWebAttr; |
|
import com.fr.design.i18n.Toolkit; |
|
|
|
import java.awt.BorderLayout; |
|
import java.awt.event.ActionEvent; |
|
import java.awt.event.ActionListener; |
|
import java.awt.event.InputMethodEvent; |
|
import java.awt.event.InputMethodListener; |
|
import java.awt.event.KeyAdapter; |
|
import java.awt.event.KeyEvent; |
|
import java.awt.event.KeyListener; |
|
import java.util.ArrayList; |
|
import java.util.List; |
|
import java.util.regex.Matcher; |
|
import java.util.regex.Pattern; |
|
import javax.swing.ButtonGroup; |
|
import javax.swing.JPanel; |
|
import javax.swing.SwingUtilities; |
|
|
|
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.flex; |
|
import static com.fine.swing.ui.layout.Layouts.row; |
|
import static com.fine.swing.ui.layout.Layouts.fix; |
|
import static com.fine.theme.utils.FineUIUtils.wrapBoldLabelWithUnderline; |
|
|
|
public class PageToolBarPane extends AbstractEditToolBarPane { |
|
|
|
private UIRadioButton centerRadioButton = new UIRadioButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Center_Display")); |
|
private UIRadioButton leftRadioButton = new UIRadioButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Left_Display")); |
|
|
|
private UICheckBox isUseToolBarCheckBox = new UICheckBox(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Use_ToolBar")); |
|
private UICheckBox isShowAsImageBox; |
|
private UICheckBox isAutoScaleBox; |
|
private UICheckBox isTDHeavyBox; |
|
private EventPane eventPane; |
|
|
|
private UIButton editToolBarButton = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Edit")); |
|
|
|
private UICheckBox isPageFixedRowBox; |
|
private UITextField pageFixedRowCountTextField; |
|
private static final Pattern ROW_COUNT = Pattern.compile("^[1-9][\\d]*$|^0"); |
|
|
|
//固定行数分页,每页最多500行,最少1行数据 |
|
private static final int MAX_ROW_COUNT = 500; |
|
private static final int MIN_ROW_COUNT = 1; |
|
|
|
public PageToolBarPane() { |
|
this.setLayout(FRGUIPaneFactory.createBorderLayout()); |
|
|
|
ButtonGroup buttonGroup = new ButtonGroup(); |
|
leftRadioButton.setSelected(true); |
|
buttonGroup.add(centerRadioButton); |
|
buttonGroup.add(leftRadioButton); |
|
|
|
isShowAsImageBox = new UICheckBox(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Is_Paint_Page")); |
|
isAutoScaleBox = new UICheckBox(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_IS_Auto_Scale")); |
|
isTDHeavyBox = new UICheckBox(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_IS_TD_HEAVY_EXPORT"), false); |
|
isPageFixedRowBox = new UICheckBox(Toolkit.i18nText("Fine-Design_Report_Page_Fixed_Row")); |
|
isPageFixedRowBox.addActionListener(new ActionListener() { |
|
@Override |
|
public void actionPerformed(ActionEvent e) { |
|
pageFixedRowCountTextField.setEnabled(isPageFixedRowBox.isSelected()); |
|
} |
|
}); |
|
editToolBarButton.addActionListener(editBtnListener); |
|
isUseToolBarCheckBox.setSelected(true); |
|
isUseToolBarCheckBox.addActionListener(new ActionListener() { |
|
@Override |
|
public void actionPerformed(ActionEvent e) { |
|
editToolBarButton.setEnabled(isUseToolBarCheckBox.isSelected()); |
|
} |
|
}); |
|
|
|
pageFixedRowCountTextField = new UITextField(); |
|
pageFixedRowCountTextField.setText("30"); |
|
pageFixedRowCountTextField.setToolTipText(Toolkit.i18nText("Fine-Design_Report_Page_Fixed_Row_Count_Tip")); |
|
pageFixedRowCountTextField.addKeyListener(rowCountKeyListener); |
|
pageFixedRowCountTextField.addInputMethodListener(rowCountInputMethodListener); |
|
|
|
JPanel northPanel = column(LayoutConstants.VERTICAL_GAP, |
|
//报表显示位置:居中展示-左展示 |
|
row(cell(new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Show_Location"))).weight(0.2), |
|
row(cell(centerRadioButton), fix(12), cell(leftRadioButton), flex()).weight(0.8) |
|
), |
|
//页面:以图片方式显示-iframe嵌入时自动缩放-重方式输出格子 |
|
row(cell(new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_PageSetup_Page"))).weight(0.2), |
|
row(cell(isShowAsImageBox), fix(12), cell(isAutoScaleBox), fix(12), cell(isTDHeavyBox),flex()).weight(0.8) |
|
), |
|
//分页设置:按行分页-每页显示行数 |
|
row(cell(new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Paging_Settings"))).weight(0.2), |
|
row(cell(isPageFixedRowBox), fix(20), cell(new UILabel(Toolkit.i18nText("Fine-Design_Report_Rows_Per_Page"))), |
|
fix(10), cell(pageFixedRowCountTextField),flex()).weight(0.8) |
|
), |
|
//提示 |
|
cell(FineUIUtils.createAutoWrapTipLabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Page_Fixed_Row_Tip"))), |
|
//使用工具栏-编辑 |
|
row(LayoutConstants.HORIZONTAL_GAP, cell(isUseToolBarCheckBox), cell(editToolBarButton)) |
|
).getComponent(); |
|
|
|
//事件编辑 |
|
JPanel eventPanel = new JPanel(new BorderLayout()); |
|
eventPane = new EventPane(new WebPage().supportedEvents()); |
|
UILabel label = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Editing_Listeners")); |
|
wrapBoldLabelWithUnderline(label); |
|
eventPanel.add(column(LayoutConstants.VGAP_SMALL, cell(label), cell(eventPane).weight(1)).getComponent()); |
|
|
|
this.add(column(LayoutConstants.VERTICAL_GAP, |
|
cell(northPanel), |
|
cell(eventPanel).weight(1) |
|
).getComponent()); |
|
|
|
//wei : 默认没config.xml的情况下,就有默认工具栏 |
|
ToolBarManager toolBarManager = ToolBarManager.createDefaultToolBar(); |
|
toolBarManager.setToolBarLocation(Location.createTopEmbedLocation()); |
|
this.toolBarManagers = new ToolBarManager[]{toolBarManager}; |
|
} |
|
|
|
@Override |
|
protected WidgetOption[] getToolBarInstance() { |
|
return ReportWebWidgetConstants.getPageToolBarInstance(); |
|
} |
|
|
|
@Override |
|
public void setEnabled(boolean isEnabled) { |
|
super.setEnabled(isEnabled); |
|
this.centerRadioButton.setEnabled(isEnabled); |
|
this.eventPane.setEnabled(isEnabled); |
|
this.isTDHeavyBox.setEnabled(isEnabled); |
|
this.isAutoScaleBox.setEnabled(isEnabled); |
|
this.isShowAsImageBox.setEnabled(isEnabled); |
|
this.leftRadioButton.setEnabled(isEnabled); |
|
this.isUseToolBarCheckBox.setEnabled(isEnabled); |
|
this.editToolBarButton.setEnabled(isEnabled && isUseToolBarCheckBox.isSelected()); |
|
this.isPageFixedRowBox.setEnabled(isEnabled); |
|
this.pageFixedRowCountTextField.setEditable(isEnabled); |
|
} |
|
|
|
@Override |
|
protected String title4PopupWindow() { |
|
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_WEB_Pagination_Setting"); |
|
} |
|
|
|
@Override |
|
public void populateBean(WebContent webContent) { |
|
if (webContent == null) { |
|
webContent = new WebPage(); |
|
} |
|
WebPage webPage = (WebPage)webContent; |
|
if (webPage.isViewAtCenter()) { |
|
centerRadioButton.setSelected(true); |
|
} else { |
|
leftRadioButton.setSelected(true); |
|
} |
|
|
|
isShowAsImageBox.setSelected(webPage.isShowAsImage()); |
|
isAutoScaleBox.setSelected(webPage.isAutoScaleWhenEmbeddedInIframe()); |
|
isTDHeavyBox.setSelected(webPage.isTDHeavy()); |
|
if (webPage.isUseToolBar()) { |
|
this.toolBarManagers = webPage.getToolBarManagers(); |
|
this.isUseToolBarCheckBox.setSelected(true); |
|
} else { |
|
this.isUseToolBarCheckBox.setSelected(false); |
|
editToolBarButton.setEnabled(false); |
|
} |
|
|
|
if (webPage.getListenerSize() != 0) { |
|
List<Listener> list = new ArrayList<Listener>(); |
|
for (int i = 0; i < webPage.getListenerSize(); i++) { |
|
list.add(webPage.getListener(i)); |
|
} |
|
eventPane.populate(list); |
|
} |
|
isPageFixedRowBox.setSelected(webPage.isPageFixedRow()); |
|
pageFixedRowCountTextField.setText(webPage.getPageFixedRowCount().toString()); |
|
pageFixedRowCountTextField.setEnabled(webPage.isPageFixedRow()); |
|
} |
|
|
|
@Override |
|
public WebPage updateBean() { |
|
WebPage webPage = new WebPage(); |
|
if (isUseToolBarCheckBox.isSelected()) { |
|
webPage.setToolBarManagers(toolBarManagers); |
|
}else { |
|
webPage.setToolBarManagers(new ToolBarManager[0]); |
|
} |
|
for (int i = 0; i < eventPane.update().size(); i++) { |
|
Listener listener = eventPane.update().get(i); |
|
webPage.addListener(listener); |
|
} |
|
webPage.setViewAtCenter(centerRadioButton.isSelected()); |
|
webPage.setShowAsImage(isShowAsImageBox.isSelected()); |
|
webPage.setAutoScaleWhenEmbeddedInIframe(isAutoScaleBox.isSelected()); |
|
webPage.setTDHeavy(isTDHeavyBox.isSelected()); |
|
webPage.setPageFixedRow(isPageFixedRowBox.isSelected()); |
|
if (!ComparatorUtils.equals(pageFixedRowCountTextField.getText(), StringUtils.EMPTY)) { |
|
webPage.setPageFixedRowCount(Integer.parseInt(pageFixedRowCountTextField.getText())); |
|
} |
|
return webPage; |
|
} |
|
|
|
/** |
|
* 编辑服务器工具栏窗格 |
|
*/ |
|
@Override |
|
public void editServerToolBarPane() { |
|
final PageToolBarPane serverPageToolBarPane = new PageToolBarPane(); |
|
ReportWebAttr reportWebAttr = ((ReportWebAttr) ConfigManager.getProviderInstance().getGlobalAttribute(ReportWebAttr.class)); |
|
if (reportWebAttr != null) { |
|
serverPageToolBarPane.populateBean(reportWebAttr.getWebPage()); |
|
} |
|
BasicDialog serverPageDialog = serverPageToolBarPane.showWindow(SwingUtilities.getWindowAncestor(PageToolBarPane.this)); |
|
serverPageDialog.addDialogActionListener(new DialogActionAdapter() { |
|
|
|
@Override |
|
public void doOk() { |
|
Configurations.update(new Worker() { |
|
@Override |
|
public void run() { |
|
ReportWebAttr reportWebAttr = ((ReportWebAttr)ConfigManager.getProviderInstance().getGlobalAttribute(ReportWebAttr.class)); |
|
reportWebAttr.setWebPage(serverPageToolBarPane.updateBean()); |
|
} |
|
|
|
@Override |
|
public Class<? extends Configuration>[] targets() { |
|
return new Class[]{ReportWebAttr.class}; |
|
} |
|
}); |
|
|
|
} |
|
}); |
|
serverPageDialog.setVisible(true); |
|
} |
|
|
|
InputMethodListener rowCountInputMethodListener = new InputMethodListener() { |
|
@Override |
|
public void inputMethodTextChanged(InputMethodEvent event) { |
|
if (null == event.getText()) { |
|
return; |
|
} |
|
char ch = event.getText().current(); |
|
if (!(ch >= '0' && ch <= '9')) { |
|
event.consume(); |
|
} |
|
} |
|
|
|
@Override |
|
public void caretPositionChanged(InputMethodEvent event) { |
|
|
|
} |
|
}; |
|
|
|
KeyListener rowCountKeyListener = new KeyAdapter() { |
|
@Override |
|
public void keyReleased(KeyEvent e) { |
|
String rowCount = pageFixedRowCountTextField.getText(); |
|
pageFixedRowCountTextField.setText(convert2ValidRowCount(rowCount)); |
|
} |
|
}; |
|
|
|
private String convert2ValidRowCount(String rowCount) { |
|
Matcher matcher = ROW_COUNT.matcher(rowCount); |
|
if (matcher.find()) { |
|
int count = Integer.parseInt(matcher.group()); |
|
if (count > MAX_ROW_COUNT) { |
|
count = MAX_ROW_COUNT; |
|
} else if (count < MIN_ROW_COUNT) { |
|
count = MIN_ROW_COUNT; |
|
} |
|
return String.valueOf(count); |
|
} |
|
return StringUtils.EMPTY; |
|
} |
|
}
|
|
|