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.
408 lines
18 KiB
408 lines
18 KiB
package com.fr.design.carton; |
|
|
|
import com.fr.decision.webservice.v10.log.download.utils.LogZipUtils; |
|
import com.fr.design.DesignerEnvManager; |
|
import com.fr.design.constants.UIConstants; |
|
import com.fr.design.dialog.FineJOptionPane; |
|
import com.fr.design.env.DesignerWorkspaceInfo; |
|
import com.fr.design.gui.date.UIDatePicker; |
|
import com.fr.design.gui.ibutton.UIButton; |
|
import com.fr.design.gui.icheckbox.UICheckBox; |
|
import com.fr.design.gui.ilable.UILabel; |
|
import com.fr.design.i18n.Toolkit; |
|
import com.fr.design.layout.FRGUIPaneFactory; |
|
import com.fr.design.mainframe.DesignerContext; |
|
import com.fr.design.utils.gui.GUICoreUtils; |
|
import com.fr.env.detect.ui.EnvDetectorDialog; |
|
import com.fr.file.FILE; |
|
import com.fr.file.FILEChooserPane; |
|
import com.fr.file.FILEFactory; |
|
import com.fr.file.filter.ChooseFileFilter; |
|
import com.fr.general.GeneralUtils; |
|
import com.fr.log.FineLoggerFactory; |
|
import com.fr.stable.StableUtils; |
|
import com.fr.stable.StringUtils; |
|
import org.jetbrains.annotations.Nullable; |
|
import com.fr.workspace.WorkContext; |
|
|
|
|
|
import javax.swing.BorderFactory; |
|
import javax.swing.JDialog; |
|
import javax.swing.JOptionPane; |
|
import javax.swing.JPanel; |
|
import javax.swing.UIManager; |
|
import javax.swing.filechooser.FileSystemView; |
|
import java.awt.BorderLayout; |
|
import java.awt.Color; |
|
import java.awt.Component; |
|
import java.awt.Cursor; |
|
import java.awt.Dimension; |
|
import java.awt.FlowLayout; |
|
import java.awt.Frame; |
|
import java.awt.event.MouseAdapter; |
|
import java.awt.event.MouseEvent; |
|
import java.awt.event.WindowEvent; |
|
import java.io.ByteArrayOutputStream; |
|
import java.io.File; |
|
import java.io.FileInputStream; |
|
import java.text.ParseException; |
|
import java.util.List; |
|
import java.util.Objects; |
|
|
|
import static com.fr.design.carton.CartonConstants.JOURNAL_FILE_PATH; |
|
|
|
|
|
public class FeedbackToolboxDialog extends JDialog { |
|
private UIDatePicker uiDatePicker; |
|
private JPanel generalSettingPanel = null; |
|
private UICheckBox easyCheckerButton = null; |
|
private UICheckBox timerCheckerButton = null; |
|
private UIButton uploadButton = null; |
|
private UILabel exportLogLabel = null; |
|
private final Color backgroundColor = new Color(240, 240, 243, 1); |
|
private final Color lineColor = new Color(192, 192, 192, 120); |
|
private JPanel body = null; |
|
private static final String WORK_SPACE_PATH = "reportlets"; |
|
private static final int BUFFER_SIZE = 2 * 1024; |
|
|
|
public FeedbackToolboxDialog(Frame owner) { |
|
super(owner, Toolkit.i18nText("Fine-Design_Basic_Carton_Feedback_ToolBox")); |
|
setResizable(false); |
|
this.setLayout(FRGUIPaneFactory.createBorderLayout()); |
|
createBodyPanel(); |
|
add(body); |
|
setSize(body.getPreferredSize()); |
|
setSwitches(!StringUtils.isEmpty(GeneralUtils.objectToString(uiDatePicker.getSelectedItem()))); |
|
repaint(); |
|
GUICoreUtils.centerWindow(this); |
|
} |
|
|
|
public void createBodyPanel() { |
|
JPanel body = FRGUIPaneFactory.createBorderLayout_L_Pane(); |
|
body.setBackground(backgroundColor); |
|
JPanel titlePane = createTitlePane(); |
|
JPanel tailPane = createTailPane(); |
|
JPanel midPane = createMidPane(); |
|
JPanel infoPane = createInfoPane(); |
|
body.add(titlePane, BorderLayout.NORTH); |
|
body.add(tailPane, BorderLayout.SOUTH); |
|
body.add(midPane, BorderLayout.CENTER); |
|
midPane.add(infoPane, BorderLayout.NORTH); |
|
Dimension dimension = new Dimension(662, 556); |
|
body.setPreferredSize(dimension); |
|
this.body = body; |
|
} |
|
|
|
private JPanel createInfoPane() { |
|
JPanel northPane = FRGUIPaneFactory.createNColumnGridInnerContainer_Pane(2, 10, 10); |
|
UILabel title = new UILabel(); |
|
title.setText(" " + Toolkit.i18nText("Fine-Design_Basic_Carton_Record_Lag_Time") + ": "); |
|
//判断一下当天是否有卡顿日志记录,如果有将日期设置为当天,如果没有设置为空 |
|
boolean cartonExists = SwitchForSwingChecker.isCartonExists(); |
|
if (cartonExists) { |
|
this.uiDatePicker = new UIDatePicker(UIDatePicker.STYLE_CN_DATE1, this); |
|
} else { |
|
this.uiDatePicker = new UIDatePicker(UIDatePicker.STYLE_CN_DATE1, null, this); |
|
} |
|
Dimension dimension = new Dimension(160, 100); |
|
uiDatePicker.setPreferredSize(dimension); |
|
northPane.add(GUICoreUtils.createFlowPane(new Component[]{title, uiDatePicker}, FlowLayout.LEFT)); |
|
exportLogLabel = new UILabel(); |
|
exportLogLabel.setText(Toolkit.i18nText("Fine-Design_Basic_Carton_Export_Carton_Log")); |
|
exportLogLabel.setForeground(UIConstants.FLESH_BLUE); |
|
exportLogLabel.addMouseListener(new MouseAdapter() { |
|
@Override |
|
public void mouseClicked(MouseEvent e) { |
|
if (exportLogLabel.isEnabled()) { |
|
exportLogFile(); |
|
} |
|
} |
|
|
|
@Override |
|
public void mouseEntered(MouseEvent evt) { |
|
Object source = evt.getSource(); |
|
if (source instanceof UILabel) { |
|
((UILabel) source).setCursor(new Cursor(Cursor.HAND_CURSOR)); |
|
} |
|
} |
|
}); |
|
|
|
northPane.add(GUICoreUtils.createFlowPane(exportLogLabel, FlowLayout.RIGHT)); |
|
return northPane; |
|
} |
|
|
|
private void exportLogFile() { |
|
String selectDate = GeneralUtils.objectToString(uiDatePicker.getSelectedItem()); |
|
FILEChooserPane fileChooserPane = FILEChooserPane.getInstance(); |
|
StringBuilder fileName = new StringBuilder(); |
|
fileName.append(selectDate).append(Toolkit.i18nText("Fine-Design_Basic_Carton_Carton_Log")); |
|
fileChooserPane.setFileNameTextField(fileName.toString(), " "); |
|
fileChooserPane.removeAllFilter(); |
|
fileChooserPane.addChooseFILEFilter(new ChooseFileFilter("zip", Toolkit.i18nText("Fine-Design_Basic_Carton_Compile_File"))); |
|
//默认选择桌面 |
|
FILE desktop = FILEFactory.createFILE(FILEFactory.FILE_PREFIX + FileSystemView.getFileSystemView().getHomeDirectory().getPath()); |
|
fileChooserPane.setCurrentDirectory(desktop); |
|
int chooseResult = fileChooserPane.showSaveDialog(DesignerContext.getDesignerFrame()); |
|
if (chooseResult == 0) { |
|
FILE selectedFile = fileChooserPane.getSelectedFILE(); |
|
String path = selectedFile.getPath(); |
|
//selectDate 2002-03-09例子 |
|
String[] split = selectDate.split("-"); |
|
int month = Integer.parseInt(split[1]); |
|
String sourceFilePath = StableUtils.pathJoin(JOURNAL_FILE_PATH, split[0], "month-" + month, selectDate); |
|
File sourceFile = new File(sourceFilePath); |
|
if (sourceFile.exists()) { |
|
exportCartonLog(sourceFile, path, sourceFilePath); |
|
} |
|
fileChooserPane.removeAllFilter(); |
|
} |
|
} |
|
|
|
private JPanel createTailPane() { |
|
JPanel tailPanel = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
|
tailPanel.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, lineColor)); |
|
JPanel actionsPanel = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
|
actionsPanel.setLayout(FRGUIPaneFactory.createM_BorderLayout()); |
|
{ |
|
uploadButton = new UIButton(Toolkit.i18nText("Fine-Design_Basic_Carton_Upload_Carton_Log")); |
|
uploadButton.addActionListener((e) -> { |
|
try { |
|
List<CartonUploadMessage> list = SwitchForSwingChecker.uploadJournalLog(uiDatePicker.getSelectedDate()); |
|
if (list.isEmpty()) { |
|
FineJOptionPane.showMessageDialog(null, Toolkit.i18nText("Fine_Design_Basic_Upload_Fail"), UIManager.getString("OptionPane.messageDialogTitle"), JOptionPane.ERROR_MESSAGE); |
|
} else { |
|
FineJOptionPane.showMessageDialog(null, Toolkit.i18nText("Fine-Design_Basic_Upload_Success")); |
|
} |
|
} catch (ParseException parseException) { |
|
FineLoggerFactory.getLogger().error("parse error", parseException); |
|
} |
|
|
|
}); |
|
actionsPanel.add(uploadButton, BorderLayout.WEST); |
|
|
|
UIButton cancelButton = new UIButton(Toolkit.i18nText("Fine-Design_Basic_Cancel")); |
|
cancelButton.addActionListener((e) -> { |
|
setVisible(false); |
|
EnvDetectorDialog envDetectorDialog = new EnvDetectorDialog(DesignerContext.getDesignerFrame()); |
|
envDetectorDialog.setVisible(true); |
|
dispose(); |
|
}); |
|
actionsPanel.add(cancelButton, BorderLayout.EAST); |
|
} |
|
UIButton currencySetButton = new UIButton(Toolkit.i18nText("Fine-Design_Basic_Carton_General_Settings")); |
|
currencySetButton.addActionListener((e -> { |
|
createGeneralSettingPanel(); |
|
this.remove(body); |
|
this.add(generalSettingPanel); |
|
setSize(generalSettingPanel.getPreferredSize()); |
|
repaint(); |
|
setVisible(true); |
|
})); |
|
tailPanel.add(actionsPanel, BorderLayout.EAST); |
|
tailPanel.add(currencySetButton, BorderLayout.WEST); |
|
return tailPanel; |
|
} |
|
|
|
private JPanel createTitlePane() { |
|
JPanel titlePane = FRGUIPaneFactory.createBorderLayout_M_Pane(); |
|
titlePane.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, lineColor)); |
|
UILabel uiLabel = new UILabel(Toolkit.i18nText("Fine-Design_Basic_Carton_Carton_Journal_Record")); |
|
uiLabel.setForeground(UIConstants.FLESH_BLUE); |
|
titlePane.add(uiLabel, BorderLayout.WEST); |
|
return titlePane; |
|
} |
|
|
|
private JPanel createMidPane() { |
|
JPanel midPanel = FRGUIPaneFactory.createBorderLayout_L_Pane(); |
|
return midPanel; |
|
} |
|
|
|
/** |
|
* 下面是通用设置的面板 |
|
*/ |
|
private void createGeneralSettingPanel() { |
|
JPanel generalSettingPanel = FRGUIPaneFactory.createBorderLayout_L_Pane(); |
|
JPanel tailPaneInGeneralSettings = createTailPaneInGeneralSettings(); |
|
generalSettingPanel.add(tailPaneInGeneralSettings, BorderLayout.SOUTH); |
|
|
|
JPanel titlePaneInGeneralSettings = createTitlePaneInGeneralSettings(); |
|
generalSettingPanel.add(titlePaneInGeneralSettings, BorderLayout.NORTH); |
|
|
|
JPanel midPanel = FRGUIPaneFactory.createBorderLayout_L_Pane(); |
|
generalSettingPanel.add(midPanel, BorderLayout.CENTER); |
|
|
|
JPanel infoPane = createInfoPanelInGeneralSettings(); |
|
midPanel.add(infoPane, BorderLayout.NORTH); |
|
|
|
Dimension dimension = new Dimension(662, 556); |
|
generalSettingPanel.setPreferredSize(dimension); |
|
generalSettingPanel.setBackground(backgroundColor); |
|
this.generalSettingPanel = generalSettingPanel; |
|
} |
|
|
|
private JPanel createTitlePaneInGeneralSettings() { |
|
JPanel titlePane = FRGUIPaneFactory.createBorderLayout_L_Pane(); |
|
titlePane.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, lineColor)); |
|
UILabel uiLabel = new UILabel(Toolkit.i18nText("Fine-Design_Basic_Carton_Carton_Journal_Record") + "/"); |
|
uiLabel.addMouseListener(new MouseAdapter() { |
|
@Override |
|
public void mouseClicked(MouseEvent e) { |
|
createBodyPanel(); |
|
remove(generalSettingPanel); |
|
add(body); |
|
setPreferredSize(body.getPreferredSize()); |
|
setSwitches(!StringUtils.isEmpty(GeneralUtils.objectToString(uiDatePicker.getSelectedItem()))); |
|
repaint(); |
|
setVisible(true); |
|
} |
|
|
|
@Override |
|
public void mouseEntered(MouseEvent evt) { |
|
Object source = evt.getSource(); |
|
if (source instanceof UILabel) { |
|
((UILabel) source).setCursor(new Cursor(Cursor.HAND_CURSOR)); |
|
} |
|
} |
|
}); |
|
UILabel uiCurrentLabel = new UILabel(Toolkit.i18nText("Fine-Design_Basic_Carton_General_Settings")); |
|
uiCurrentLabel.setForeground(UIConstants.FLESH_BLUE); |
|
titlePane.add(GUICoreUtils.createFlowPane(new Component[]{uiLabel, uiCurrentLabel}, FlowLayout.LEFT)); |
|
return titlePane; |
|
} |
|
|
|
private JPanel createTailPaneInGeneralSettings() { |
|
JPanel tailPanel = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
|
tailPanel.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, lineColor)); |
|
JPanel actionsPanel = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
|
actionsPanel.setLayout(FRGUIPaneFactory.createM_BorderLayout()); |
|
{ |
|
UIButton confirmButton = new UIButton(Toolkit.i18nText("Fine-Design_Basic_Save")); |
|
confirmButton.addActionListener((e) -> { |
|
if (easyCheckerButton.isSelected()) { |
|
SwitchForSwingChecker.startEasyChecker(); |
|
} else { |
|
SwitchForSwingChecker.stopEasyChecker(); |
|
} |
|
if (timerCheckerButton.isSelected()) { |
|
SwitchForSwingChecker.startTimerChecker(); |
|
} else { |
|
SwitchForSwingChecker.stopTimerChecker(); |
|
} |
|
createBodyPanel(); |
|
remove(generalSettingPanel); |
|
add(body); |
|
setPreferredSize(body.getPreferredSize()); |
|
setSwitches(!StringUtils.isEmpty(GeneralUtils.objectToString(uiDatePicker.getSelectedItem()))); |
|
repaint(); |
|
setVisible(true); |
|
}); |
|
actionsPanel.add(confirmButton, BorderLayout.WEST); |
|
|
|
UIButton cancelButton = new UIButton(Toolkit.i18nText("Fine-Design_Basic_Cancel")); |
|
cancelButton.addActionListener((e) -> { |
|
createBodyPanel(); |
|
remove(generalSettingPanel); |
|
add(body); |
|
setPreferredSize(body.getPreferredSize()); |
|
repaint(); |
|
setVisible(true); |
|
|
|
}); |
|
actionsPanel.add(cancelButton, BorderLayout.EAST); |
|
} |
|
tailPanel.add(actionsPanel, BorderLayout.EAST); |
|
return tailPanel; |
|
} |
|
|
|
private JPanel createInfoPanelInGeneralSettings() { |
|
JPanel infoPane = FRGUIPaneFactory.createNColumnGridInnerContainer_S_Pane(1); |
|
easyCheckerButton = new UICheckBox(Toolkit.i18nText("Fine-Design_Basic_Carton_Operation_Time_Consuming_Detection")); |
|
timerCheckerButton = new UICheckBox(Toolkit.i18nText("Fine-Design_Basic_Carton_Carton_Operation_Class_Capture")); |
|
easyCheckerButton.setSelected(SwitchForSwingChecker.isEasyChecker()); |
|
timerCheckerButton.setSelected(SwitchForSwingChecker.isCheckerTimerSwitch()); |
|
infoPane.add(GUICoreUtils.createFlowPane(easyCheckerButton, FlowLayout.LEFT)); |
|
infoPane.add(GUICoreUtils.createFlowPane(timerCheckerButton, FlowLayout.LEFT)); |
|
return infoPane; |
|
} |
|
|
|
@Override |
|
protected void processWindowEvent(WindowEvent e) { |
|
super.processWindowEvent(e); |
|
if (e.getID() == WindowEvent.WINDOW_CLOSING) { |
|
EnvDetectorDialog envDetectorDialog = new EnvDetectorDialog(DesignerContext.getDesignerFrame()); |
|
envDetectorDialog.setVisible(true); |
|
} |
|
} |
|
|
|
/** |
|
* 上传和导出卡顿日志的可用化处理,如果没有选择日期就不可用 |
|
*/ |
|
public void setSwitches(boolean flag) { |
|
uploadButton.setEnabled(flag); |
|
exportLogLabel.setEnabled(flag); |
|
} |
|
|
|
/** |
|
* 导出卡顿日志到本地或远程服务器WEB-INF下 |
|
* |
|
* @param sourceFile 导出的卡顿日志所在文件夹 |
|
* @param path 文件需要导出到的路径 |
|
* @param sourceFilePath 导出的卡顿日志所在文件夹的路径 |
|
*/ |
|
private void exportCartonLog(File sourceFile, String path, String sourceFilePath) { |
|
File[] files = sourceFile.listFiles(); |
|
if (!Objects.isNull(files)) { |
|
try { |
|
if (path.startsWith(WORK_SPACE_PATH)) { |
|
if (WorkContext.getCurrent().isLocal()) { |
|
String curEnvName = DesignerEnvManager.getEnvManager().getCurEnvName(); |
|
DesignerWorkspaceInfo workspaceInfo = DesignerEnvManager.getEnvManager().getWorkspaceInfo(curEnvName); |
|
String workspaceInfoPath = workspaceInfo.getPath(); |
|
path = StableUtils.pathJoin(workspaceInfoPath, path); |
|
LogZipUtils.compress(files, path, false); |
|
} else { |
|
String sourceFilePathZip = sourceFilePath + ".zip"; |
|
LogZipUtils.compress(files, sourceFilePathZip, false); |
|
byte[] bytesByFile = getBytesByFile(sourceFilePathZip); |
|
WorkContext.getWorkResource().write(path, bytesByFile); |
|
LogZipUtils.delDir(sourceFilePathZip); |
|
} |
|
} else { |
|
LogZipUtils.compress(files, path, false); |
|
} |
|
FineJOptionPane.showMessageDialog(this, Toolkit.i18nText("Fine-Design_Report_Exported_Successfully")); |
|
} catch (Exception exception) { |
|
FineJOptionPane.showMessageDialog(this, Toolkit.i18nText("Fine-Design_Report_Export_Failed"), UIManager.getString("OptionPane.messageDialogTitle"), JOptionPane.ERROR_MESSAGE); |
|
FineLoggerFactory.getLogger().error("export file fail", exception); |
|
} |
|
} |
|
} |
|
|
|
/** |
|
* 根据文件地址将文件转换成byte[] |
|
* |
|
* @param pathStr 本地文件目录 |
|
* @return 本地文件转成的byte[] |
|
*/ |
|
@Nullable |
|
private static byte[] getBytesByFile(String pathStr) { |
|
File file = new File(pathStr); |
|
try { |
|
FileInputStream fis = new FileInputStream(file); |
|
ByteArrayOutputStream bos = new ByteArrayOutputStream(BUFFER_SIZE); |
|
byte[] b = new byte[BUFFER_SIZE]; |
|
int n; |
|
while ((n = fis.read(b)) != -1) { |
|
bos.write(b, 0, n); |
|
} |
|
fis.close(); |
|
byte[] data = bos.toByteArray(); |
|
bos.close(); |
|
return data; |
|
} catch (Exception e) { |
|
FineLoggerFactory.getLogger().error("reading local file fail", e); |
|
} |
|
return null; |
|
} |
|
|
|
}
|
|
|