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.
139 lines
5.0 KiB
139 lines
5.0 KiB
/* |
|
* Copyright (C), 2018-2021 |
|
* Project: starter |
|
* FileName: WebBaseTableDatapane |
|
* Author: fr.open |
|
* Date: 2021/12/10 8:49 |
|
*/ |
|
package com.fr.plugin.icjb.ui; |
|
|
|
import com.fanruan.api.design.DesignKit; |
|
import com.fanruan.api.design.ui.action.UpdateAction; |
|
import com.fanruan.api.design.ui.component.UIToolbar; |
|
import com.fanruan.api.design.ui.component.table.UITableEditorPane; |
|
import com.fanruan.api.design.ui.component.table.action.UITableEditAction; |
|
import com.fanruan.api.design.ui.component.table.model.ParameterTableModel; |
|
import com.fanruan.api.design.ui.component.table.model.UITableModelAdapter; |
|
import com.fanruan.api.design.ui.toolbar.ToolBarDef; |
|
import com.fanruan.api.design.work.BaseTableDataPane; |
|
import com.fanruan.api.log.LogKit; |
|
import com.fanruan.api.util.IOKit; |
|
import com.fr.base.TableData; |
|
import com.fr.stable.ParameterProvider; |
|
|
|
import javax.swing.*; |
|
import java.awt.*; |
|
import java.awt.event.ActionEvent; |
|
import java.io.IOException; |
|
import java.net.URI; |
|
|
|
/** |
|
* <Function Description><br> |
|
* <WebBaseTableDatapane> |
|
* |
|
* @author fr.open |
|
* @since 1.0.0 |
|
*/ |
|
public abstract class WebBaseTableDataPane<T extends TableData> extends BaseTableDataPane<T> { |
|
public static final String ICON_HELP = "/com/fr/plugin/icjb/images/help.png"; |
|
public static final String ICON_PREVIEW = "/com/fr/design/images/m_file/preview.png"; |
|
public static final String ICON_REFRESH = "/com/fr/design/images/control/refresh.png"; |
|
public static final String HELP_URL = "https://help.finereport.com/index.php"; |
|
private static final String PREVIEW_BUTTON = DesignKit.i18nText("Plugin-icjb_Preview"); |
|
private static final String REFRESH_BUTTON = DesignKit.i18nText("Plugin-icjb_Refresh"); |
|
private static final String HELP_BUTTON = DesignKit.i18nText("Plugin-icjb_Help"); |
|
|
|
protected UITableEditorPane<ParameterProvider> editorPane; |
|
|
|
public WebBaseTableDataPane() { |
|
this.setLayout(new BorderLayout(4, 4)); |
|
Box box = new Box(BoxLayout.Y_AXIS); |
|
JPanel northPane = new JPanel(new BorderLayout(4, 4)); |
|
JToolBar editToolBar = createToolBar(); |
|
northPane.add(editToolBar, BorderLayout.CENTER); |
|
JToolBar editHelpBar = createHelpBar(); |
|
northPane.add(editHelpBar, BorderLayout.EAST); |
|
northPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 6, 0)); |
|
|
|
UITableModelAdapter<ParameterProvider> model = new ParameterTableModel(); |
|
editorPane = new UITableEditorPane<ParameterProvider>(model); |
|
box.add(northPane); |
|
box.add(createQueryPane()); |
|
box.add(editorPane); |
|
JPanel sqlSplitPane = new JPanel(new BorderLayout(4, 4)); |
|
sqlSplitPane.add(box, BorderLayout.CENTER); |
|
this.add(sqlSplitPane, BorderLayout.CENTER); |
|
} |
|
|
|
private JToolBar createToolBar() { |
|
ToolBarDef toolBarDef = new ToolBarDef(); |
|
toolBarDef.addShortCut(new PreviewAction()); |
|
UIToolbar editToolBar = ToolBarDef.createJToolBar(); |
|
toolBarDef.updateToolBar(editToolBar); |
|
return editToolBar; |
|
} |
|
|
|
private JToolBar createHelpBar() { |
|
ToolBarDef helpBarDef = new ToolBarDef(); |
|
helpBarDef.addShortCut(new HelpAction()); |
|
UIToolbar editHelpBar = ToolBarDef.createJToolBar(); |
|
helpBarDef.updateToolBar(editHelpBar); |
|
return editHelpBar; |
|
} |
|
|
|
@Override |
|
protected String title4PopupWindow() { |
|
return DesignKit.i18nText("Plugin-icjb_Query"); |
|
} |
|
|
|
protected abstract JComponent createQueryPane(); |
|
|
|
private void refresh() { |
|
java.util.List<ParameterProvider> existParameterList = editorPane.update(); |
|
ParameterProvider[] ps = existParameterList == null ? new ParameterProvider[0] : existParameterList.toArray(new ParameterProvider[0]); |
|
editorPane.populate(ps); |
|
} |
|
|
|
private class PreviewAction extends UpdateAction { |
|
public PreviewAction() { |
|
this.setName(PREVIEW_BUTTON); |
|
this.setMnemonic('P'); |
|
this.setSmallIcon(IOKit.readIcon(ICON_PREVIEW)); |
|
} |
|
|
|
public void actionPerformed(ActionEvent evt) { |
|
DesignKit.previewTableData(WebBaseTableDataPane.this.updateBean()); |
|
} |
|
} |
|
|
|
private class HelpAction extends UpdateAction { |
|
public HelpAction() { |
|
this.setName(HELP_BUTTON); |
|
this.setMnemonic('P'); |
|
this.setSmallIcon(IOKit.readIcon(ICON_HELP)); |
|
} |
|
|
|
public void actionPerformed(ActionEvent evt) { |
|
try { |
|
Desktop.getDesktop().browse(URI.create(HELP_URL)); |
|
} catch (IOException e1) { |
|
LogKit.error(e1.getMessage(), e1); |
|
} |
|
} |
|
} |
|
|
|
protected class RefreshAction extends UITableEditAction { |
|
public RefreshAction() { |
|
this.setName(REFRESH_BUTTON); |
|
this.setSmallIcon(IOKit.readIcon(ICON_REFRESH)); |
|
} |
|
|
|
public void actionPerformed(ActionEvent e) { |
|
refresh(); |
|
} |
|
|
|
@Override |
|
public void checkEnabled() { |
|
} |
|
} |
|
} |