From 491a9cfa6ef7948fc573d24d195b4724c5e9f2b5 Mon Sep 17 00:00:00 2001 From: rusefi Date: Mon, 13 Jul 2020 22:33:11 -0400 Subject: [PATCH] RE TS plugin to have continues tune auto-upload feature #1605 --- .../src/com/rusefi/ts_plugin/PluginEntry.java | 67 +++---------------- .../src/com/rusefi/ts_plugin/UploadView.java | 49 ++++++++++++++ .../com/rusefi/ts_plugin/UploaderStatus.java | 41 ++++++++++++ 3 files changed, 101 insertions(+), 56 deletions(-) create mode 100644 java_tools/ts_plugin/src/com/rusefi/ts_plugin/UploadView.java diff --git a/java_tools/ts_plugin/src/com/rusefi/ts_plugin/PluginEntry.java b/java_tools/ts_plugin/src/com/rusefi/ts_plugin/PluginEntry.java index 220f14938d..f98e3ae2a7 100644 --- a/java_tools/ts_plugin/src/com/rusefi/ts_plugin/PluginEntry.java +++ b/java_tools/ts_plugin/src/com/rusefi/ts_plugin/PluginEntry.java @@ -1,7 +1,6 @@ package com.rusefi.ts_plugin; import com.efiAnalytics.plugin.ecu.ControllerAccess; -import com.rusefi.TsTuneReader; import com.rusefi.autoupdate.AutoupdateUtil; import com.rusefi.tools.online.Online; import com.rusefi.ts_plugin.util.ManifestHelper; @@ -17,8 +16,6 @@ import org.putgemin.VerticalFlowLayout; import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; -import java.io.File; -import java.util.Map; import java.util.function.Supplier; /** @@ -26,14 +23,13 @@ import java.util.function.Supplier; */ public class PluginEntry implements TsPluginBody { private static final String REO_URL = "https://rusefi.com/online/"; - private static final String NO_PROJECT = "Please open project"; private final AuthTokenPanel tokenPanel = new AuthTokenPanel(); private final JComponent content = new JPanel(new VerticalFlowLayout()); + + private final UploadView uploadView = new UploadView(); + private final JButton upload = new JButton("Upload Current Tune"); - private final JLabel uploadState = new JLabel(); - private final JLabel projectWarning = new JLabel(NO_PROJECT); - private final JLabel tuneInfo = new JLabel(); private final Supplier controllerAccessSupplier; private String currentConfiguration; @@ -63,16 +59,11 @@ public class PluginEntry implements TsPluginBody { } boolean isProjectActive = configurationName != null; + uploaderStatus.updateProjectStatus(configurationName, isProjectActive); + SwingUtilities.invokeLater(new Runnable() { @Override public void run() { - if (!isProjectActive) { - uploaderStatus.projectWarning = NO_PROJECT; - } else if (!new File(TsTuneReader.getTsTuneFileName(configurationName)).exists()) { - uploaderStatus.projectWarning = "Tune not found " + configurationName; - } else { - uploaderStatus.projectWarning = null; - } updateUploadEnabled(); } @@ -107,8 +98,7 @@ public class PluginEntry implements TsPluginBody { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { - uploadState.setText(array.get(0).toString()); - uploadState.setVisible(true); + uploadView.setResult(array); } }); } @@ -127,12 +117,10 @@ public class PluginEntry implements TsPluginBody { content.add(new JLabel(ManifestHelper.getBuildTimestamp())); // content.add(new JLabel("Active project: " + getConfigurationName())); - uploadState.setVisible(false); - content.add(projectWarning); - content.add(tuneInfo); + content.add(uploadView.getContent()); content.add(upload); - content.add(uploadState); + ImageIcon LOGO = AutoupdateUtil.loadIcon("/rusefi_online_color_300.png"); content.add(new JLabel(LOGO)); content.add(tokenPanel.getContent()); @@ -143,53 +131,20 @@ public class PluginEntry implements TsPluginBody { * This method is invoked every time we defect a switch between projects */ private void handleConfigurationChange(String configurationName) { - Map fileSystemValues = TuneUploder.getFileSystemValues(configurationName); - Constant engineMake = fileSystemValues.get("enginemake"); - Constant engineCode = fileSystemValues.get("enginecode"); - Constant vehicleName = fileSystemValues.get("VEHICLENAME"); - String warning = ""; - if (isEmpty(engineMake)) { - warning += " engine make"; - } - if (isEmpty(engineCode)) { - warning += " engine code"; - } - if (isEmpty(vehicleName)) { - warning += " vehicle name"; - } - if (warning.isEmpty()) { - uploaderStatus.tuneInfo = engineMake.getValue() + " " + engineCode.getValue() + " " + vehicleName.getValue(); - uploaderStatus.tuneWarning = null; - } else { - uploaderStatus.tuneInfo = null; - uploaderStatus.tuneWarning = "Please set " + warning + " on Base Settings tab
and reopen Project"; - } + uploaderStatus.readTuneState(configurationName); updateUploadEnabled(); currentConfiguration = configurationName; } - private boolean isEmpty(Constant constant) { + public static boolean isEmpty(Constant constant) { if (constant == null) return true; return isEmpty(constant.getValue()); } private void updateUploadEnabled() { - if (uploaderStatus.isTuneOk()) { - tuneInfo.setText(uploaderStatus.tuneInfo); - tuneInfo.setForeground(Color.black); - } else { - tuneInfo.setText(uploaderStatus.tuneWarning); - tuneInfo.setForeground(Color.red); - } - - if (uploaderStatus.isProjectIsOk()) { - projectWarning.setVisible(false); - } else { - projectWarning.setVisible(true); - projectWarning.setText(uploaderStatus.projectWarning); - } + uploadView.update(uploaderStatus); upload.setEnabled(uploaderStatus.isTuneOk() && uploaderStatus.isProjectIsOk()); } diff --git a/java_tools/ts_plugin/src/com/rusefi/ts_plugin/UploadView.java b/java_tools/ts_plugin/src/com/rusefi/ts_plugin/UploadView.java new file mode 100644 index 0000000000..5145511af5 --- /dev/null +++ b/java_tools/ts_plugin/src/com/rusefi/ts_plugin/UploadView.java @@ -0,0 +1,49 @@ +package com.rusefi.ts_plugin; + +import org.json.simple.JSONArray; +import org.putgemin.VerticalFlowLayout; + +import javax.swing.*; +import java.awt.*; + +public class UploadView { + private final JComponent content = new JPanel(new VerticalFlowLayout()); + + private final JLabel uploadState = new JLabel(); + private final JLabel projectWarning = new JLabel(UploaderStatus.NO_PROJECT); + private final JLabel tuneInfo = new JLabel(); + + public UploadView() { + content.add(projectWarning); + content.add(tuneInfo); + content.add(uploadState); + + uploadState.setVisible(false); + } + + public void setResult(JSONArray array) { + uploadState.setText(array.get(0).toString()); + uploadState.setVisible(true); + } + + public JComponent getContent() { + return content; + } + + public void update(UploaderStatus uploaderStatus) { + if (uploaderStatus.isTuneOk()) { + tuneInfo.setText(uploaderStatus.tuneInfo); + tuneInfo.setForeground(Color.black); + } else { + tuneInfo.setText(uploaderStatus.tuneWarning); + tuneInfo.setForeground(Color.red); + } + + if (uploaderStatus.isProjectIsOk()) { + projectWarning.setVisible(false); + } else { + projectWarning.setVisible(true); + projectWarning.setText(uploaderStatus.projectWarning); + } + } +} diff --git a/java_tools/ts_plugin/src/com/rusefi/ts_plugin/UploaderStatus.java b/java_tools/ts_plugin/src/com/rusefi/ts_plugin/UploaderStatus.java index e7762437b2..d9a062c4ed 100644 --- a/java_tools/ts_plugin/src/com/rusefi/ts_plugin/UploaderStatus.java +++ b/java_tools/ts_plugin/src/com/rusefi/ts_plugin/UploaderStatus.java @@ -1,10 +1,51 @@ package com.rusefi.ts_plugin; +import com.rusefi.TsTuneReader; +import com.rusefi.tune.xml.Constant; + +import java.io.File; +import java.util.Map; + public class UploaderStatus { + static final String NO_PROJECT = "Please open project"; public String projectWarning; public String tuneInfo; public String tuneWarning; + void updateProjectStatus(String configurationName, boolean isProjectActive) { + if (!isProjectActive) { + this.projectWarning = NO_PROJECT; + } else if (!new File(TsTuneReader.getTsTuneFileName(configurationName)).exists()) { + this.projectWarning = "Tune not found " + configurationName; + } else { + this.projectWarning = null; + } + } + + void readTuneState(String configurationName) { + Map fileSystemValues = TuneUploder.getFileSystemValues(configurationName); + Constant engineMake = fileSystemValues.get("enginemake"); + Constant engineCode = fileSystemValues.get("enginecode"); + Constant vehicleName = fileSystemValues.get("VEHICLENAME"); + String warning = ""; + if (PluginEntry.isEmpty(engineMake)) { + warning += " engine make"; + } + if (PluginEntry.isEmpty(engineCode)) { + warning += " engine code"; + } + if (PluginEntry.isEmpty(vehicleName)) { + warning += " vehicle name"; + } + if (warning.isEmpty()) { + tuneInfo = engineMake.getValue() + " " + engineCode.getValue() + " " + vehicleName.getValue(); + tuneWarning = null; + } else { + tuneInfo = null; + tuneWarning = "Please set " + warning + " on Base Settings tab
and reopen Project"; + } + } + public boolean isProjectIsOk() { return projectWarning == null; }