JSD-9311 企业微信标签用户数据集
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.

141 lines
5.0 KiB

/*
* Copyright (C), 2018-2021
* Project: starter
* FileName: WebBaseTableDatapane
* Author: Louis
* Date: 2021/12/10 8:49
*/
package com.fr.plugin.icak.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;
import static com.fr.plugin.icak.Constants.*;
/**
* <Function Description><br>
* <WebBaseTableDatapane>
*
* @author Louis
* @since 1.0.0
*/
public abstract class WebBaseTableDataPane<T extends TableData> extends BaseTableDataPane<T> {
private static final String PREVIEW_BUTTON = DesignKit.i18nText("Plugin-icak_Preview");
private static final String REFRESH_BUTTON = DesignKit.i18nText("Plugin-icak_Refresh");
private static final String HELP_BUTTON = DesignKit.i18nText("Plugin-icak_Help");
protected WebConnectionChosePane chosePane;
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);
chosePane = new WebConnectionChosePane();
chosePane.setPreferredSize(new Dimension(200, 200));
sqlSplitPane.add(chosePane, BorderLayout.WEST);
this.add(sqlSplitPane, BorderLayout.CENTER);
}
private JToolBar createToolBar() {
ToolBarDef toolBarDef = new ToolBarDef();
toolBarDef.addShortCut(new WebBaseTableDataPane.PreviewAction());
UIToolbar editToolBar = ToolBarDef.createJToolBar();
toolBarDef.updateToolBar(editToolBar);
return editToolBar;
}
private JToolBar createHelpBar() {
ToolBarDef helpBarDef = new ToolBarDef();
helpBarDef.addShortCut(new WebBaseTableDataPane.HelpAction());
UIToolbar editHelpBar = ToolBarDef.createJToolBar();
helpBarDef.updateToolBar(editHelpBar);
return editHelpBar;
}
@Override
protected String title4PopupWindow() {
return DesignKit.i18nText("Plugin-icak_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() {
}
}
}