The Sample program demonstrates the main functionality of the OTX-Runtime API. It can be used as a reference for the expected runtime behavior of the API and the source code below is like a reference guide about the proper programming of the API.
Code snippet of the OTX-Runtime API Sample Program.
1 package OpenTestSystem.Otx.Runtime.Api.Sample;
14 import javafx.application.HostServices;
15 import javafx.application.Platform;
16 import javafx.beans.property.SimpleStringProperty;
17 import javafx.beans.value.ObservableValue;
18 import javafx.collections.FXCollections;
19 import javafx.collections.ObservableList;
20 import javafx.event.ActionEvent;
21 import javafx.fxml.FXML;
22 import javafx.fxml.FXMLLoader;
23 import javafx.scene.Node;
24 import javafx.scene.Scene;
25 import javafx.scene.control.Button;
26 import javafx.scene.control.Label;
27 import javafx.scene.control.TextField;
28 import javafx.scene.control.*;
29 import javafx.scene.control.cell.PropertyValueFactory;
30 import javafx.scene.control.cell.TextFieldTableCell;
31 import javafx.scene.image.Image;
32 import javafx.scene.image.ImageView;
33 import javafx.scene.input.Clipboard;
34 import javafx.scene.input.ClipboardContent;
35 import javafx.scene.input.MouseEvent;
36 import javafx.stage.*;
38 import javax.crypto.BadPaddingException;
39 import javax.crypto.IllegalBlockSizeException;
40 import javax.crypto.NoSuchPaddingException;
41 import javax.swing.plaf.synth.SynthTextAreaUI;
43 import java.awt.event.ComponentAdapter;
44 import java.awt.event.ComponentEvent;
45 import java.awt.event.WindowEvent;
46 import java.awt.event.WindowListener;
48 import java.io.IOException;
50 import java.nio.file.Files;
51 import java.nio.file.Path;
52 import java.nio.file.Paths;
53 import java.security.InvalidAlgorithmParameterException;
54 import java.security.InvalidKeyException;
55 import java.security.NoSuchAlgorithmException;
56 import java.time.LocalDateTime;
57 import java.time.format.DateTimeFormatter;
58 import java.util.List;
60 import java.util.stream.Collectors;
62 public class SampleForm {
64 static HostServices hostServices;
66 private static final String PROJECT_ICON =
"/ODFProject.bmp";
67 private static final String DOCUMENT_ICON =
"/DocumentOTX16.bmp";
68 private static final String PROCEDURE_ICON =
"/Procedure.bmp";
69 private static final String PACKAGE_ICON =
"/Procedure.bmp";
71 private static final String SOCKET_COMMUNICATION =
"SOCKET";
72 private static final String DEFAULT_RUNTIME_PORT =
"0";
73 private static final String DEFAULT_DIAG_MANAGER_PORT =
"8888";
75 private static final String PIPE_COMMUNICATION =
"PIPE";
76 private static final String DEFAULT_RUNTIME_PIPE_NAME =
"Emotive";
77 private static final String DEFAULT_DIAG_MANAGER_PIPE_NAME =
"DiagManager";
79 private static final String PTX_EXTENSION =
"ptx";
80 private static final String PPX_EXTENSION =
"ppx";
82 private static final int DEFAULT_POLLING_TIME = 500;
83 private static final int DEFAULT_BATTERY_VOLTAGE_THRESHOLD = 6000;
85 private static final int DEFAULT_TRACE_FILE_MAX_COUNT = 10;
86 private static final int DEFAULT_TRACE_FILE_MAX_SIZE = 100;
88 private static final String password =
"<]mjkQL~B6Uh;^,LWJ+Tdz=(W#WA/8ZGYWg259Ht]`9gG;";
89 private static final List<FileChooser.ExtensionFilter> EXTENSION_FILTERS =
90 new LinkedList<FileChooser.ExtensionFilter>() {{
91 add(
new FileChooser.ExtensionFilter(
"All supported formats",
"*." + PTX_EXTENSION,
"*." + PPX_EXTENSION));
92 add(
new FileChooser.ExtensionFilter(
"PTX files",
"*." + PTX_EXTENSION));
93 add(
new FileChooser.ExtensionFilter(
"PPX files",
"*." + PPX_EXTENSION));
94 add(
new FileChooser.ExtensionFilter(
"All files",
"*.*"));
97 private static final String MAIN_PROCEDURE_NAME =
"main";
99 private static final String STYLE_SHEET =
"/sample_style.css";
101 private static final String MAIN_FXML =
"/SampleForm.fxml";
102 private static final String SAMPLE_TITLE = String.format(
103 "emotive OTX-Runtime API for Java - Reference Application - Version %s",
104 SampleConstants.VERSION
106 private static final int SAMPLE_WIDTH = 1060;
107 private static final int SAMPLE_HEIGHT = 736;
108 private static final String ICON_PATH =
"/Sample.png";
110 private static final int VALUE_STRING_MAX_LENGTH = 1024;
117 private int cyclic = 1;
119 private IRuntimeManager runtimeManager =
null;
120 private IProject project =
null;
121 private IPlayerProject playerProject =
null;
122 private IProcedure procedureWillExecute =
null;
123 private final List<IRuntimeContext> runtimeContexts =
new ArrayList<>();
125 private CustomTreeItem startupNode =
null;
127 private final String PROCESS_64_BIT =
"amd64";
129 private final DefaultCustomScreenImplementation customScreenImplementation =
new DefaultCustomScreenImplementation();
130 private final ContextVariableImplementation contextVariableImplementation =
new ContextVariableImplementation();
131 private final StateVariableImplementation stateVariableImplementation =
new StateVariableImplementation();
132 private final DefaultMeasureImplementation measureImplementation =
new DefaultMeasureImplementation();
133 private final DefaultExternalServiceProviderImplementation serviceProviderImplementation =
new DefaultExternalServiceProviderImplementation();
135 private final LoggingOutputImpl loggingOutputImpl =
new LoggingOutputImpl(this::PrintText);
136 private final BasicScreenOutputImpl basicScreenOutputImpl =
new BasicScreenOutputImpl(this::PrintText);
137 private final CustomScreenOutputImpl customScreenOutputImpl =
new CustomScreenOutputImpl(this::PrintText);
138 private final ContextVariableOutputImpl contextVariableOutputImpl =
new ContextVariableOutputImpl(this::PrintText);
139 private final StateVariableOutputImpl stateVariableOutputImpl =
new StateVariableOutputImpl(this::PrintText);
140 private final MeasureOutputImpl measureOutputImpl =
new MeasureOutputImpl(this::PrintText);
141 private final I18nOutputImpl i18nOutput =
new I18nOutputImpl(this::PrintText);
142 private final SqlOutputImpl sqlOutput =
new SqlOutputImpl(this::PrintText);
143 private final ExternalServiceProviderOutputImpl serviceProviderOutputImpl =
new ExternalServiceProviderOutputImpl(this::PrintText);
145 private String lastOpenedDirectory =
"";
147 HmiWindow hmiWindow =
null;
148 KeyDownListener keyDownListener = args -> PrintText(args.ToString());
150 private int lineNumber = 0;
152 private static int defaultPollingTime = 500;
153 private static int defaultBatteryVoltageThreshold = 6000;
154 private boolean useConnectionState =
false;
155 private Boolean KL15State =
false;
156 private ExpectedState expectedConnectionState = ExpectedState.None;
157 private final Object lock =
new Object();
158 private final Object printTextLock =
new Object();
159 private final Object eventListenerLock =
new Object();
160 private final Object tableParameterLock =
new Object();
162 private boolean cyclicExecuteAsyncIsProcessing =
false;
164 private SaveSettingUtil userSetting = SaveSettingUtil.Instance();
166 private Map<IRuntimeContext, Stage> dicMessageDialog;
168 private String runtimePort = DEFAULT_RUNTIME_PORT;
169 private String diagPort = DEFAULT_DIAG_MANAGER_PORT;
170 private String runtimePipeName = DEFAULT_RUNTIME_PIPE_NAME;
171 private String diagPipeName = DEFAULT_DIAG_MANAGER_PIPE_NAME;
175 private Button buttonExecuteMain;
177 private Button btnExecuteProcedureSelected;
179 private Button buttonCopyRow;
181 private Button buttonStop;
183 private Button buttonPause;
185 private Button buttonContinue;
187 private Button buttonHMI;
189 private Button buttonStartStopWebServer;
191 private Button btnNewInstance;
193 private TreeView<String> treeViewOtxProject;
195 private TextField txtPassword;
197 private TextField textTracePath;
199 private TextField txtFilePath;
201 private TextField txtTraceFileMaxCount;
203 private TextField txtTraceFileMaxSize;
205 private TextField textRuntimeCommunication;
207 private TextField textDiagCommunication;
209 private ListView<String> listViewOutputText;
211 private Label labelOutputOverflow;
213 private TableView<CustomTableItem> tableParameter;
215 private TableColumn<CustomTableItem, String> columnProcedureParamName;
217 private TableColumn<CustomTableItem, String> columnProcedureParamDataType;
219 private TableColumn<CustomTableItem, Object> columnProcedureParamValue;
221 private TableView<CustomTableItem> tableContextVariables;
223 private TableColumn<CustomTableItem, String> columnContextVariableName;
225 private TableColumn<CustomTableItem, String> columnContextVariableDataType;
227 private TableColumn<CustomTableItem, Object> columnContextVariableValue;
229 private TableView<CustomTableItem> tableStateVariables;
231 private TableColumn<CustomTableItem, String> columnStateVariableName;
233 private TableColumn<CustomTableItem, String> columnStateVariableDataType;
235 private TableColumn<CustomTableItem, Object> columnStateVariableValue;
237 private TableView<Map.Entry<String, String>> tableProjectSetting;
239 private TableColumn<Map.Entry<String, String>, String> columnSettingName;
241 private TableColumn<Map.Entry<String, String>, String> columnSettingValue;
243 private ComboBox<String> comboBoxCommunicationType;
245 private Label labelIpcPortPipe;
247 private ComboBox<String> comboBoxTraceLevel;
249 private CheckBox checkBoxAsynchron;
251 private CheckBox checkBoxCyclic;
253 private CheckBox checkBoxCyclicReload;
255 private RadioButton radioButtonOutputWindow;
257 private RadioButton radioButtonDefaultImplementation;
259 private RadioButton radioButtonNoCustomImplementation;
261 private Button btnBrowseFile;
263 private TextField textRuntimeName;
265 private CheckBox checkBoxUseConnectionState;
267 private Label labelExpectedState;
269 private CheckBox checkBoxIgnition;
271 private Label labelBatteryState;
273 private Label labelIgnitionState;
275 private Button buttonCheckBatteryIgnition;
277 private Label labelPollingTime;
279 private Label labelVoltageThreshold;
281 private TextField textBoxPollingTime;
283 private TextField textBoxBatteryVoltageThreshold;
285 private Label labelTimeout;
287 private TextField textBoxTimeout;
289 private TextField txtProfilingMaxFileSize;
291 private CheckBox checkBoxProfiling;
294 java.util.Timer webServerTimer =
new java.util.Timer();
297 String licenseKey =
null;
299 licenseKey = (
new RijndaelCrypt(password)).DecryptStringAES(SaveSettingUtil.Instance().GetPropertyValue(
"LicenseKey",
""));
300 }
catch (InvalidAlgorithmParameterException | IllegalBlockSizeException | BadPaddingException |
301 InvalidKeyException | NoSuchAlgorithmException | NoSuchPaddingException e) {
302 throw new RuntimeException(e);
304 if (LicenseUtil.checkLicenseKeyFormat(licenseKey)) {
305 LicenseManager.SetLicenseKey(licenseKey);
307 Alert noLicenseAlert =
new Alert(Alert.AlertType.WARNING,
"There is an invalid license key format. Please set your new key in license box.");
308 noLicenseAlert.setHeaderText(
"Invalid license key format");
309 noLicenseAlert.showAndWait();
313 public SampleForm() {
316 public void SetStage(Stage stage) {
319 if (this.stage.getTitle() ==
null) {
320 this.stage.setTitle(GetTitle(
false));
323 this.stage.setOnHidden(event -> {
324 if (webServerTimer !=
null) {
325 webServerTimer.cancel();
329 InitializeComponent();
330 InitializeRuntimeManagerFirstTime();
332 TimerTask task =
new TimerTask() {
336 UpdateWebServerButton();
342 webServerTimer.schedule(task, 1000, 1000);
345 private void InitializeComponent() {
346 CustomTreeItem mainRoot =
new CustomTreeItem(
null);
347 treeViewOtxProject.setRoot(mainRoot);
348 treeViewOtxProject.setShowRoot(
false);
349 treeViewOtxProject.getSelectionModel().selectedItemProperty().addListener(this::TreeView_SelectItemListener);
351 columnSettingName.setCellValueFactory(p ->
new SimpleStringProperty(p.getValue().getKey()));
352 columnSettingValue.setCellValueFactory(p ->
new SimpleStringProperty(p.getValue().getValue()));
354 columnProcedureParamName.setCellValueFactory(
new PropertyValueFactory<>(
"name"));
355 columnProcedureParamDataType.setCellValueFactory(
new PropertyValueFactory<>(
"dataType"));
356 columnProcedureParamValue.setCellValueFactory(
new PropertyValueFactory<>(
"value"));
358 columnContextVariableName.setCellValueFactory(
new PropertyValueFactory<>(
"name"));
359 columnContextVariableDataType.setCellValueFactory(
new PropertyValueFactory<>(
"dataType"));
360 columnContextVariableValue.setCellValueFactory(
new PropertyValueFactory<>(
"value"));
362 columnStateVariableName.setCellValueFactory(
new PropertyValueFactory<>(
"name"));
363 columnStateVariableDataType.setCellValueFactory(
new PropertyValueFactory<>(
"dataType"));
364 columnStateVariableValue.setCellValueFactory(
new PropertyValueFactory<>(
"value"));
365 SetCellFactoryForValueColumn();
367 ObservableList<String> communicationTypes = FXCollections.observableArrayList(SOCKET_COMMUNICATION, PIPE_COMMUNICATION);
368 comboBoxCommunicationType.setItems(communicationTypes);
369 comboBoxCommunicationType.setVisibleRowCount(2);
371 comboBoxCommunicationType.setValue(SOCKET_COMMUNICATION);
372 comboBoxCommunicationType.selectionModelProperty().addListener((observable, oldValue, newValue) -> {
373 comboBoxCommunicateType_Action();
375 textRuntimeCommunication.setText(DEFAULT_RUNTIME_PORT);
376 textDiagCommunication.setText(DEFAULT_DIAG_MANAGER_PORT);
378 textTracePath.textProperty().addListener((observable, oldValue, newValue) -> UpdateTraceFolder());
379 txtTraceFileMaxCount.textProperty().addListener((observable, oldValue, newValue) -> UpdateTraceFileMaxCount());
380 txtTraceFileMaxSize.textProperty().addListener((observable, oldValue, newValue) -> UpdateTraceFileMaxSize());
382 List<String> traceLevels =
new ArrayList<>();
383 for (TraceLevels traceLevel :
TraceLevels.values()) {
384 traceLevels.add(traceLevel.name());
387 comboBoxTraceLevel.setItems(FXCollections.observableArrayList(traceLevels));
388 comboBoxTraceLevel.setVisibleRowCount(7);
390 buttonCopyRow.setDisable(
true);
392 listViewOutputText.setItems(FXCollections.observableList(
new ArrayList<>()));
393 listViewOutputText.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
395 AddCheckBoxUseConnectionStateListener();
397 this.textBoxPollingTime.setText(String.valueOf(defaultPollingTime));
398 this.textBoxBatteryVoltageThreshold.setText(String.valueOf(defaultBatteryVoltageThreshold));
400 this.checkBoxCyclic.selectedProperty().addListener(observable -> {
401 checkBoxCyclic_Check();
404 AddListenerForCustomImplRadioButtons();
405 AddProfilingListener();
408 private void AddProfilingListener()
410 this.checkBoxProfiling.selectedProperty().addListener(observable -> {
411 checkBoxProfiling_Check();
414 txtProfilingMaxFileSize.textProperty().addListener((observable, oldValue, newValue) -> txtProfilingMaxFileSize_Action());
417 private void AddCheckBoxUseConnectionStateListener() {
418 this.checkBoxUseConnectionState.selectedProperty().addListener(observable -> {
419 checkBoxUseConnectionState_Check();
422 this.checkBoxIgnition.selectedProperty().addListener(observable -> {
423 checkBoxIgnition_Check();
426 this.checkBoxIgnition.indeterminateProperty().addListener(observable -> {
427 checkBoxIgnition_Check();
431 private void AddListenerForCustomImplRadioButtons() {
432 radioButtonDefaultImplementation.selectedProperty().addListener((observable, oldValue, newValue) -> {
434 CheckCustomImplRadioButtonGroup();
436 radioButtonNoCustomImplementation.selectedProperty().addListener((observable, oldValue, newValue) -> {
438 CheckCustomImplRadioButtonGroup();
440 radioButtonOutputWindow.selectedProperty().addListener((observable, oldValue, newValue) -> {
442 CheckCustomImplRadioButtonGroup();
446 private void InitializeRuntimeManagerFirstTime() {
447 PrintText(
"Application started");
448 if (runtimeManager !=
null)
453 txtTraceFileMaxCount.setText(Integer.toString(RuntimeConfig.GetInstance().GetTraceFileMaxCount()));
454 txtTraceFileMaxSize.setText(Integer.toString(RuntimeConfig.GetInstance().GetTraceFileMaxSize()));
455 checkBoxProfiling.setSelected(RuntimeConfig.GetInstance().GetProfiling());
456 txtProfilingMaxFileSize.setText(Integer.toString(RuntimeConfig.GetInstance().GetProfilingMaxFileSize()));
457 SetRuntimeManagerEvents();
458 CheckCustomImplRadioButtonGroup();
460 PrintText(
"Initialization finished");
461 }
catch (Exception e) {
462 if (runtimeManager ==
null) {
463 PrintText(
"Failed to create RuntimeManager.");
471 private void SaveSetting() {
472 HashMap<String, Object> properties =
new HashMap<>();
473 properties.put(SampleConstants.PTX_PPX_DIRECTORY, txtFilePath.getText());
474 properties.put(SampleConstants.TRACE_FILE_MAX_COUNT, txtTraceFileMaxCount.getText());
475 properties.put(SampleConstants.TRACE_FILE_MAX_SIZE, txtTraceFileMaxSize.getText());
476 properties.put(SampleConstants.TRACE_LEVEL, RuntimeConfig.GetInstance().GetTraceLevel());
477 properties.put(SampleConstants.TRACE_DIRECTORY, RuntimeConfig.GetInstance().GetTraceFolder());
478 properties.put(SampleConstants.RUNTIME_CONTEXT_NAME, textRuntimeName.getText());
480 properties.put(SampleConstants.ASYNCHRON, checkBoxAsynchron.isSelected());
481 properties.put(SampleConstants.CYCLIC, checkBoxCyclic.isSelected());
482 properties.put(SampleConstants.CYCLIC_RELOAD, checkBoxCyclicReload.isSelected());
483 properties.put(SampleConstants.CUSTOM_IMPL_TYPE, GetCustomImplType());
485 properties.put(SampleConstants.WINDOW_HEIGHT, stage.getScene().getWindow().getHeight());
486 properties.put(SampleConstants.WINDOW_WIDTH, stage.getScene().getWindow().getWidth());
487 properties.put(SampleConstants.WINDOW_LOCATION_X, stage.getScene().getWindow().getX());
488 properties.put(SampleConstants.WINDOW_LOCATION_Y, stage.getScene().getWindow().getY());
490 properties.put(SampleConstants.TIME_OUT, GetTimeout());
491 properties.put(SampleConstants.CONNECTION_STATE,
this.useConnectionState);
492 SaveKL15State(properties);
493 properties.put(SampleConstants.POLLING_TIME,
494 this.textBoxPollingTime.getText());
495 properties.put(SampleConstants.VOLTAGE_THRESHOLD,
496 this.textBoxBatteryVoltageThreshold.getText());
498 properties.put(SampleConstants.PROFILING, checkBoxProfiling.isSelected());
499 properties.put(SampleConstants.PROFILING_MAX_FILE_SIZE, txtProfilingMaxFileSize.getText());
500 SaveSocketPortOrPipeName(properties);
502 userSetting.SetPropertyValues(properties);
505 private void SaveKL15State(HashMap<String, Object> properties) {
508 if (this.KL15State ==
null) {
510 }
else if (this.KL15State ==
true) {
516 properties.put(SampleConstants.KL15_STATE, kl15IntValue);
519 private void SaveSocketPortOrPipeName(HashMap<String, Object> properties) {
521 if (comboBoxCommunicationType.getValue().equals(SOCKET_COMMUNICATION)) {
523 String runtimePort = textRuntimeCommunication.getText().trim();
524 properties.put(SampleConstants.RUNTIME_PORT, runtimePort);
526 String diagPort = textDiagCommunication.getText().trim();
527 properties.put(SampleConstants.DIAG_MANAGER_PORT, diagPort);
529 properties.put(SampleConstants.IPC_TYPE, SOCKET_COMMUNICATION);
531 }
else if (comboBoxCommunicationType.getValue().equals(PIPE_COMMUNICATION)) {
533 String runtimePipeName = textRuntimeCommunication.getText().trim();
534 properties.put(SampleConstants.RUNTIME_PIPE_NAME, runtimePipeName);
536 String diagPipeName = textDiagCommunication.getText().trim();
537 properties.put(SampleConstants.DIAG_PIPE_NAME, diagPipeName);
539 properties.put(SampleConstants.IPC_TYPE, PIPE_COMMUNICATION);
543 private void LoadSetting() {
546 LoadDefaultPortAndPipeName();
548 LoadPtxPpxDirectoryPath();
549 LoadTraceFileMaxCountAndSize();
552 LoadRuntimeContextName();
556 LoadCyclicReloadOption();
557 LoadCustomImplType();
559 LoadSampleLocation();
563 LoadConnectionState();
566 LoadVoltageThreshold();
568 this.EnableConnectionState();
572 private void LoadTraceFileMaxCountAndSize() {
573 String traceFileMaxCount = userSetting.GetPropertyValue(SampleConstants.TRACE_FILE_MAX_COUNT,
574 Integer.toString(DEFAULT_TRACE_FILE_MAX_COUNT));
575 String traceFileMaxSize = userSetting.GetPropertyValue(SampleConstants.TRACE_FILE_MAX_SIZE,
576 Integer.toString(DEFAULT_TRACE_FILE_MAX_SIZE));
578 txtTraceFileMaxCount.setText(traceFileMaxCount);
579 txtTraceFileMaxSize.setText(traceFileMaxSize);
582 private void LoadDefaultPortAndPipeName() {
583 String runtimePortSavedValue = userSetting.GetPropertyValue(SampleConstants.RUNTIME_PORT, DEFAULT_RUNTIME_PORT);
584 runtimePort = CheckValidPortString(runtimePortSavedValue.trim()) ? runtimePortSavedValue.trim() : DEFAULT_RUNTIME_PORT;
586 String diagPortSavedValue = userSetting.GetPropertyValue(SampleConstants.DIAG_MANAGER_PORT, DEFAULT_DIAG_MANAGER_PORT);
587 diagPort = CheckValidPortString(diagPortSavedValue.trim()) ? diagPortSavedValue.trim() : DEFAULT_DIAG_MANAGER_PORT;
589 String runtimePipeNameSavedValue = userSetting.GetPropertyValue(SampleConstants.RUNTIME_PIPE_NAME, DEFAULT_RUNTIME_PIPE_NAME);
590 runtimePipeName = runtimePipeNameSavedValue.trim().equals(
"") ? DEFAULT_RUNTIME_PIPE_NAME : runtimePipeNameSavedValue.trim();
592 String diagPipeNameSavedValue = userSetting.GetPropertyValue(SampleConstants.DIAG_PIPE_NAME, DEFAULT_DIAG_MANAGER_PIPE_NAME);
593 diagPipeName = diagPipeNameSavedValue.trim().equals(
"") ? DEFAULT_DIAG_MANAGER_PIPE_NAME : diagPipeNameSavedValue.trim();
596 String icpType = userSetting.GetPropertyValue(SampleConstants.IPC_TYPE, SOCKET_COMMUNICATION);
598 if (icpType.equals(SOCKET_COMMUNICATION)) {
599 textRuntimeCommunication.setText(runtimePort);
600 textDiagCommunication.setText(diagPort);
601 comboBoxCommunicationType.setValue(SOCKET_COMMUNICATION);
603 textRuntimeCommunication.setText(runtimePipeName);
604 textDiagCommunication.setText(diagPipeName);
605 comboBoxCommunicationType.setValue(PIPE_COMMUNICATION);
608 InitializeRuntimeManagerByIpcTypeTextBox();
611 private void LoadPtxPpxDirectoryPath() {
612 txtFilePath.setText(userSetting.GetPropertyValue(SampleConstants.PTX_PPX_DIRECTORY,
""));
615 private void LoadTraceLevel() {
617 String traceLevelStringValue = userSetting.GetPropertyValue(
618 SampleConstants.TRACE_LEVEL,
619 RuntimeConfig.GetInstance().GetTraceLevel().toString()
622 comboBoxTraceLevel.setValue(traceLevelStringValue);
626 private void LoadTraceFolder() {
628 String traceDirectory = userSetting.GetPropertyValue(
629 SampleConstants.TRACE_DIRECTORY,
630 RuntimeConfig.GetInstance().GetTraceFolder()
633 textTracePath.setText(traceDirectory);
637 private void LoadRuntimeContextName() {
638 textRuntimeName.setText(userSetting.GetPropertyValue(SampleConstants.RUNTIME_CONTEXT_NAME,
""));
641 private void LoadAsyncOption() {
643 boolean asynchronValue = Boolean.parseBoolean(userSetting.GetPropertyValue(
644 SampleConstants.ASYNCHRON,
"true"));
645 checkBoxAsynchron.setSelected(asynchronValue);
648 private void LoadCyclicOption() {
649 boolean cyclicValue = Boolean.parseBoolean(userSetting.GetPropertyValue(
650 SampleConstants.CYCLIC,
"true"));
652 checkBoxCyclic.setSelected(cyclicValue);
655 private void LoadCyclicReloadOption() {
657 if (checkBoxCyclicReload.isDisable())
660 boolean cyclicReloadValue = Boolean.parseBoolean(userSetting.GetPropertyValue(
661 SampleConstants.CYCLIC_RELOAD,
"true"));
663 checkBoxCyclicReload.setSelected(cyclicReloadValue);
667 private void LoadCustomImplType() {
668 SampleConstants.CustomImplType customImplType = SampleConstants.CustomImplType.valueOf(
669 userSetting.GetPropertyValue(
670 SampleConstants.CUSTOM_IMPL_TYPE,
671 SampleConstants.CustomImplType.DefaultCustomImpl.toString()).trim());
673 LoadCustomImplType(customImplType);
676 private void LoadCustomImplType(SampleConstants.CustomImplType customImplType) {
678 switch (customImplType) {
680 radioButtonOutputWindow.setSelected(
true);
683 radioButtonNoCustomImplementation.setSelected(
true);
686 radioButtonDefaultImplementation.setSelected(
true);
691 private void LoadSampleSize() {
695 double sampleHeight = Double.parseDouble(
696 userSetting.GetPropertyValue(
697 SampleConstants.WINDOW_HEIGHT,
698 Integer.toString(SAMPLE_HEIGHT)
701 double sampleWidth = Double.parseDouble(
702 userSetting.GetPropertyValue(
703 SampleConstants.WINDOW_WIDTH,
704 Integer.toString(SAMPLE_WIDTH)
707 stage.setHeight(sampleHeight);
708 stage.setWidth(sampleWidth);
712 private void LoadSampleLocation() {
717 double coordinateX = Double.parseDouble(
718 userSetting.GetPropertyValue(
719 SampleConstants.WINDOW_LOCATION_X,
"0"
722 double coordinateY = Double.parseDouble(
723 userSetting.GetPropertyValue(
724 SampleConstants.WINDOW_LOCATION_Y,
"0"
727 Point location =
new Point((
int) coordinateX, (
int) coordinateY);
728 if (CheckFormIsInBound(location)) {
729 stage.setX(coordinateX);
730 stage.setY(coordinateY);
734 stage.centerOnScreen();
737 private boolean CheckFormIsInBound(Point point) {
738 GraphicsDevice[] screenDevices = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
740 for (GraphicsDevice screen : screenDevices) {
741 if (screen.getDefaultConfiguration().getBounds().contains(point))
748 private void LoadTimeOut() {
749 textBoxTimeout.setText(userSetting.GetPropertyValue(
750 SampleConstants.TIME_OUT,
"0"
754 private void LoadConnectionState() {
755 this.useConnectionState = Boolean.parseBoolean(userSetting.GetPropertyValue(
756 SampleConstants.CONNECTION_STATE,
"false"
759 this.checkBoxUseConnectionState.setSelected(this.useConnectionState);
762 private void LoadKL15State() {
763 if (checkBoxIgnition.isDisable() ==
true)
766 int kl15StateIntValue;
768 kl15StateIntValue = Integer.parseInt(userSetting.GetPropertyValue(
769 SampleConstants.KL15_STATE,
771 }
catch (Exception ex) {
772 kl15StateIntValue = 0;
775 if (kl15StateIntValue != -1) {
776 this.KL15State = kl15StateIntValue == 1;
777 this.checkBoxIgnition.setSelected(KL15State);
780 this.KL15State =
null;
781 this.checkBoxIgnition.setIndeterminate(
true);
787 private void LoadPollingTime() {
791 pollingTime = Integer.parseInt(userSetting.GetPropertyValue(
792 SampleConstants.POLLING_TIME, Integer.toString(DEFAULT_POLLING_TIME)
794 }
catch (Exception ex) {
795 pollingTime = DEFAULT_POLLING_TIME;
798 this.textBoxPollingTime.setText(Integer.toString(pollingTime));
801 private void LoadVoltageThreshold() {
803 int batteryVoltageThreshold;
805 batteryVoltageThreshold = Integer.parseInt(userSetting.GetPropertyValue(
806 SampleConstants.VOLTAGE_THRESHOLD, Integer.toString(DEFAULT_BATTERY_VOLTAGE_THRESHOLD)
808 }
catch (Exception ex) {
809 batteryVoltageThreshold = DEFAULT_BATTERY_VOLTAGE_THRESHOLD;
813 this.textBoxBatteryVoltageThreshold.setText(Integer.toString(batteryVoltageThreshold));
816 private void LoadProfiling()
818 checkBoxProfiling.setSelected(Boolean.parseBoolean(userSetting.GetPropertyValue(
819 SampleConstants.PROFILING,
"false")));
820 txtProfilingMaxFileSize.setText(userSetting.GetPropertyValue(
821 SampleConstants.PROFILING_MAX_FILE_SIZE,
"50"));
826 private void SetCellFactoryForValueColumn() {
828 this.columnProcedureParamValue.setCellFactory(column ->
new CustomTableCell(this::PrintText));
830 this.columnContextVariableValue.setCellFactory(column ->
new CustomTableCell(this::PrintText));
832 this.columnStateVariableValue.setCellFactory(column ->
new CustomTableCell(this::PrintText));
834 this.columnSettingValue.setCellFactory(TextFieldTableCell.forTableColumn());
835 this.columnSettingValue.setOnEditCommit(e -> e.getTableView()
848 private void btnNewInstance_Action() {
850 OpenNewSampleForm(
true);
851 }
catch (Exception e) {
852 PrintText(
"Exception" + e.getMessage());
857 private void btnNewInstanceNewThreadAction() {
858 Thread newSampleThread =
new Thread(() -> {
860 OpenNewSampleForm(
false);
861 }
catch (IOException e) {
862 PrintText(
"Exception: " + e.getMessage());
865 newSampleThread.setName(
"New Sample Instance");
866 newSampleThread.setDaemon(
true);
867 newSampleThread.start();
870 private synchronized void OpenNewSampleForm(
boolean isChild)
throws IOException {
871 FXMLLoader loader =
new FXMLLoader(getClass().getResource(MAIN_FXML));
873 Scene scene =
new Scene(loader.load(), SAMPLE_WIDTH, SAMPLE_HEIGHT);
874 scene.getStylesheets().add(STYLE_SHEET);
876 long threadID = Thread.currentThread().getId();
878 Platform.runLater(() -> {
879 Stage stage =
new Stage();
880 stage.getIcons().add(
new Image(this.getClass().getResourceAsStream(ICON_PATH)));
881 stage.setScene(scene);
883 String title = GetTitle(isChild);
884 stage.setTitle(title);
886 SampleForm controller = loader.getController();
887 controller.SetStage(stage);
893 private String GetTitle(
boolean isChild) {
894 return String.format(
895 "emotive OTX-Runtime API for Java - Reference Application - Version %s - %s Bit - %s - Thread-ID %o%s",
896 SampleConstants.VERSION,
897 Is64Bit() ?
"64" :
"32",
898 isChild ?
"Child Instance" :
"Main Instance",
899 Thread.currentThread().getId(),
900 IsAdmin() ?
" - Administrator" :
""
904 private boolean Is64Bit() {
906 String osArchitecture = System.getProperty(
"os.arch");
907 return osArchitecture.equals(PROCESS_64_BIT);
908 }
catch (Exception ex) {
913 private boolean IsAdmin() {
915 String command =
"reg query \"HKU\\S-1-5-19\"";
916 Process p = Runtime.getRuntime().exec(command);
918 int exitValue = p.exitValue();
920 return 0 == exitValue;
922 }
catch (Exception e) {
930 void portTextField_KeyReleased() {
931 if (comboBoxCommunicationType.getValue().trim().equals(PIPE_COMMUNICATION)) {
932 textRuntimeCommunication.setStyle(
null);
933 textDiagCommunication.setStyle(
null);
935 CreateRuntimeManagerAndSetConfig();
939 boolean isValidRuntimePort = CheckValidPortString(textRuntimeCommunication.getText());
940 boolean isValidDiagPort = CheckValidPortString(textDiagCommunication.getText());
942 if (!isValidRuntimePort) {
943 textRuntimeCommunication.setStyle(
"-fx-text-box-border: #B22222; -fx-focus-color: #B22222;");
945 textRuntimeCommunication.setStyle(
null);
948 if (!isValidDiagPort) {
949 textDiagCommunication.setStyle(
"-fx-text-box-border: #B22222; -fx-focus-color: #B22222;");
951 textDiagCommunication.setStyle(
null);
954 if (isValidRuntimePort && isValidDiagPort)
955 CreateRuntimeManagerAndSetConfig();
958 private boolean CheckValidPortString(String port) {
960 if (port.trim().isEmpty())
964 Integer.parseInt(port);
966 }
catch (NumberFormatException nfe) {
972 private void checkBoxCyclic_Check() {
973 checkBoxCyclicReload.setDisable(!checkBoxCyclic.isSelected());
974 checkBoxCyclicReload.setSelected(
false);
977 private void SetExpectedState() {
978 if (this.useConnectionState) {
979 if (this.KL15State ==
null) {
980 this.expectedConnectionState = ExpectedState.BatteryOn;
981 }
else if (this.KL15State) {
982 this.expectedConnectionState = ExpectedState.IgnitionOn;
984 this.expectedConnectionState = ExpectedState.IgnitionOff;
987 this.expectedConnectionState = ExpectedState.None;
992 private void checkBoxUseConnectionState_Check() {
993 this.useConnectionState = this.checkBoxUseConnectionState.isSelected();
994 this.EnableConnectionState();
995 this.SetExpectedState();
999 private void checkBoxProfiling_Check() {
1000 RuntimeConfig.GetInstance().SetProfiling(checkBoxProfiling.isSelected());
1004 private void txtProfilingMaxFileSize_Action() {
1006 RuntimeConfig.GetInstance().SetProfilingMaxFileSize(Integer.parseInt(txtProfilingMaxFileSize.getText()));
1007 }
catch (java.lang.Exception ex) {
1008 PrintText(
"Exception: " + ex.getMessage());
1011 PrintText(
"ProfilingMaxFileSize is " + Integer.toString(RuntimeConfig.GetInstance().GetProfilingMaxFileSize()));
1014 private void EnableConnectionState() {
1015 this.labelExpectedState.setDisable(!this.useConnectionState);
1016 this.labelBatteryState.setDisable(!this.useConnectionState);
1017 this.checkBoxIgnition.setDisable(!this.useConnectionState);
1018 this.labelPollingTime.setDisable(!this.useConnectionState);
1019 this.textBoxPollingTime.setDisable(!this.useConnectionState);
1020 this.labelVoltageThreshold.setDisable(!this.useConnectionState);
1021 this.textBoxBatteryVoltageThreshold.setDisable(!this.useConnectionState);
1022 this.buttonCheckBatteryIgnition.setDisable(!this.useConnectionState);
1026 private void checkBoxIgnition_Check() {
1027 if (checkBoxIgnition.isIndeterminate()) {
1028 this.KL15State =
null;
1029 }
else if (!this.checkBoxIgnition.isSelected()) {
1030 this.KL15State =
false;
1032 this.KL15State =
true;
1035 this.SetExpectedState();
1038 private void SetIconStateChanged(Label button, String imagePath) {
1039 URL imageUrl = getClass().getResource(imagePath);
1042 image =
new Image(imageUrl.openStream());
1043 Node node = button.getGraphic();
1044 ImageView imageView = (ImageView) node;
1045 imageView.setImage(image);
1046 }
catch (Exception e) {
1047 e.printStackTrace();
1051 private void CheckBatteryIgnitionState(IRuntimeManager runtimeManager) {
1052 if (this.useConnectionState) {
1053 runtimeManager.GetDiagConnectionState().SetPollingTime(Integer.parseInt(
this.textBoxPollingTime.getText()));
1054 runtimeManager.GetDiagConnectionState().SetBatteryVoltageThreshold(Integer.parseInt(
this.textBoxBatteryVoltageThreshold.getText()));
1056 ClampState batteryState = runtimeManager.GetDiagConnectionState().GetBatteryState();
1057 ClampState ignitionState = runtimeManager.GetDiagConnectionState().GetIgnitionState();
1059 SetBatteryIgnitionState(batteryState, ignitionState);
1061 PrintText(
"Check DiagConnection State - BatteryState = " + batteryState.toString() +
", IgnitionState = " + ignitionState.toString());
1065 private void SetBatteryIgnitionState(ClampState batteryState, ClampState ignitionState) {
1066 switch (batteryState) {
1068 this.SetIconStateChanged(this.labelBatteryState,
"/IconBatteryNotAvailable16.png");
1071 this.SetIconStateChanged(this.labelBatteryState,
"/IconBatteryOff16.png");
1074 this.SetIconStateChanged(this.labelBatteryState,
"/IconBatteryOn16.png");
1078 switch (ignitionState) {
1080 this.SetIconStateChanged(this.labelIgnitionState,
"/IconIgnitionNotAvailable16.png");
1083 this.SetIconStateChanged(this.labelIgnitionState,
"/IconIgnitionOff16.png");
1086 this.SetIconStateChanged(this.labelIgnitionState,
"/IconIgnitionOn16.png");
1091 private void ShowConnectionStateMessage(IRuntimeContext runtimeContext) {
1092 if (runtimeContext !=
null) {
1093 switch (this.expectedConnectionState) {
1095 this.PrintText(
"----------------------------------------------------------------------------------------------------------------------------------------------");
1096 this.PrintText(
"-- Not expected connection state: Either it is not possible to communicate with the VCI or the battery is not connected. Please connect it! --");
1097 this.PrintText(
"----------------------------------------------------------------------------------------------------------------------------------------------");
1100 this.PrintText(
"------------------------------------------------------------------------------------");
1101 this.PrintText(
"-- Not expected connection state: The ignition must be OFF. Please switch it OFF! --");
1102 this.PrintText(
"------------------------------------------------------------------------------------");
1105 this.PrintText(
"----------------------------------------------------------------------------------");
1106 this.PrintText(
"-- Not expected connection state: The ignition must be ON. Please switch it ON! --");
1107 this.PrintText(
"----------------------------------------------------------------------------------");
1116 void textBoxPollingTime_Action() {
1118 Integer.parseInt(this.textBoxPollingTime.getText());
1119 }
catch (NumberFormatException nfe) {
1120 this.textBoxPollingTime.setText(String.valueOf(defaultPollingTime));
1125 void textBoxBatteryVoltageThreshold_Action() {
1127 Integer.parseInt(this.textBoxBatteryVoltageThreshold.getText());
1128 }
catch (NumberFormatException nfe) {
1129 this.textBoxBatteryVoltageThreshold.setText(String.valueOf(defaultBatteryVoltageThreshold));
1134 private void buttonClearOutput_Click(MouseEvent event) {
1135 this.listViewOutputText.setItems(FXCollections.observableList(
new ArrayList<>()));
1136 buttonCopyRow.setDisable(
true);
1137 labelOutputOverflow.setVisible(
false);
1142 private void buttonCopyRow_Click(MouseEvent event) {
1143 String copyText =
"";
1144 copyText = this.listViewOutputText.getSelectionModel().getSelectedItem();
1146 if (copyText.isEmpty()) {
1150 final Clipboard clipboard = Clipboard.getSystemClipboard();
1151 final ClipboardContent content =
new ClipboardContent();
1152 content.putString(copyText);
1153 clipboard.setContent(content);
1157 private void comboBoxCommunicateType_Action() {
1158 final String communicationType = comboBoxCommunicationType.getValue().trim();
1160 switch (communicationType) {
1161 case SOCKET_COMMUNICATION:
1162 labelIpcPortPipe.setText(SampleConstants.LABEL_IPC_PORT_TEXT);
1164 textRuntimeCommunication.setText(runtimePort);
1165 textDiagCommunication.setText(diagPort);
1167 case PIPE_COMMUNICATION:
1168 labelIpcPortPipe.setText(SampleConstants.LABEL_IPC_PIPE_TEXT);
1170 textRuntimeCommunication.setText(runtimePipeName);
1171 textDiagCommunication.setText(diagPipeName);
1175 CreateRuntimeManagerAndSetConfig();
1179 private void btnBrowseFile_Click(ActionEvent event) {
1181 File file = OpenBrowseFileWindow();
1184 String filePath = file.toPath().toAbsolutePath().normalize().toString();
1185 txtFilePath.clear();
1186 txtFilePath.appendText(filePath);
1187 textRuntimeName.clear();
1192 private File OpenBrowseFileWindow() {
1193 FileChooser fileChooser =
new FileChooser();
1194 fileChooser.getExtensionFilters().addAll(EXTENSION_FILTERS);
1196 if (lastOpenedDirectory !=
null && !lastOpenedDirectory.trim().isEmpty())
1197 fileChooser.setInitialDirectory(
new File(lastOpenedDirectory));
1199 File file = fileChooser.showOpenDialog(stage);
1204 private void btnBrowseTraceFolder_Action(ActionEvent event) {
1206 File directory = OpenBrowseDirectoryWindow();
1208 if (directory !=
null) {
1209 String directoryPath = directory.toPath().toAbsolutePath().normalize().toString();
1210 textTracePath.clear();
1211 textTracePath.appendText(directoryPath);
1216 private File OpenBrowseDirectoryWindow() {
1217 DirectoryChooser directoryChooser =
new DirectoryChooser();
1219 Path existedDirectoryPath = Paths.get(textTracePath.getText());
1221 if (Files.exists(existedDirectoryPath))
1222 directoryChooser.setInitialDirectory(
new File(existedDirectoryPath.toString()));
1224 return directoryChooser.showDialog(stage);
1228 private void btnReload_Action(ActionEvent event) {
1230 textRuntimeName.clear();
1234 private void btnOpenFile_Action(ActionEvent event) {
1235 String tracePath = textTracePath.getText();
1236 if (hostServices !=
null
1237 && !tracePath.isEmpty())
1238 hostServices.showDocument(Paths.get(tracePath).toAbsolutePath().toString());
1241 private void TreeView_SelectItemListener(
1242 ObservableValue observable,
1246 tableParameter.getItems().clear();
1247 tableContextVariables.getItems().clear();
1248 tableStateVariables.getItems().clear();
1250 if (newValue ==
null)
1253 CustomTreeItem node = (CustomTreeItem) newValue;
1255 if (node.getItem() instanceof IProcedure) {
1256 ResetContextVariableCaches();
1257 IProcedure procedure = (IProcedure) node.getItem();
1258 UpdateTable(procedure);
1259 this.btnExecuteProcedureSelected.setDisable(
false);
1263 private void ResetContextVariableCaches() {
1264 contextVariableImplementation.ClearCaches();
1266 contextVariableOutputImpl.ClearCaches();
1270 private void contextVariableColumnValue_OnCommit(TableColumn.CellEditEvent event) {
1271 Object value =
event.getNewValue();
1272 CustomTableItem contextTableItem = tableContextVariables.getItems().get(event.getTablePosition().getRow());
1275 contextTableItem.setValue(value);
1278 String fullNameContextVariable = ((IContextVariable) contextTableItem.getModel()).GetDocument().GetFullName() +
1279 '.' + ((IContextVariable) contextTableItem.getModel()).GetName();
1280 this.contextVariableImplementation.SetContextVariableValue(fullNameContextVariable, value);
1281 this.contextVariableOutputImpl.SetContextVariable(fullNameContextVariable, value);
1283 }
catch (Exception e) {
1284 PrintText(
"Exception: " + e.getMessage());
1289 private void buttonReadSetting_Click(MouseEvent event) {
1290 if (this.playerProject !=
null)
1291 ReadSettings(this.playerProject.GetSettings());
1292 else if (this.project !=
null) {
1293 ReadSettings(this.project.GetSettings());
1297 private void ReadSettings(Map<String, String> settings) {
1299 tableProjectSetting.getItems().clear();
1301 ObservableList<Map.Entry<String, String>> items = FXCollections.observableArrayList(settings.entrySet());
1302 tableProjectSetting.setItems(items);
1304 PrintText(
"Finish Reading Settings");
1308 private void buttonWriteSetting_Click(MouseEvent event) {
1312 private void WriteSettings() {
1313 if (project ==
null && playerProject ==
null)
1316 int selectedSettingPosition = 0;
1318 if (tableProjectSetting.getSelectionModel().getSelectedItems() !=
null)
1319 selectedSettingPosition = tableProjectSetting.getSelectionModel().getFocusedIndex();
1322 Map<String, String> newSetting = tableProjectSetting.getItems().stream()
1323 .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
1325 if (playerProject !=
null) {
1326 playerProject.SetSettings(newSetting);
1327 ReadSettings(playerProject.GetSettings());
1329 project.SetSettings(newSetting);
1330 ReadSettings(project.GetSettings());
1332 tableProjectSetting.getSelectionModel().select(selectedSettingPosition);
1334 PrintText(
"Finish Writing Setting!");
1335 }
catch (Exception ex) {
1336 PrintText(
"Exception when Writing settings: " + ex.getMessage());
1341 private void buttonStop_Click(MouseEvent event) {
1342 checkBoxCyclic.setSelected(
false);
1343 checkBoxCyclic_Check();
1344 if (runtimeManager !=
null) {
1345 runtimeManager.StopAll();
1350 private void buttonHmi_Click(MouseEvent event) {
1351 buttonHMI.setDisable(
true);
1352 hmiWindow =
new HmiWindow();
1353 hmiWindow.addWindowListener(
new HmiWindowListener());
1355 hmiWindow.addComponentListener(
new HmiComponentAdapter());
1358 hmiWindow.setVisible(
true);
1359 hmiWindow.setBounds(100, 100, 700, 500);
1360 if (customScreenImplementation !=
null) {
1361 customScreenImplementation.SetHmiScreenHandle(hmiWindow.GetHandle());
1365 private void SetIconStateChanged(Button button, String imagePath) {
1366 URL imageUrl = getClass().getResource(imagePath);
1369 image =
new Image(imageUrl.openStream());
1370 Node node = button.getGraphic();
1371 ImageView imageView = (ImageView) node;
1372 imageView.setImage(image);
1373 }
catch (Exception e) {
1374 e.printStackTrace();
1378 int isStartWebSever = -1;
1380 private void UpdateWebServerButton() {
1381 if (customScreenImplementation ==
null) {
1382 this.buttonStartStopWebServer.setDisable(
true);
1386 this.buttonStartStopWebServer.setDisable(
false);
1387 if (DefaultCustomScreenImplementation.IsStartedHtmlWebserver())
1389 if (isStartWebSever == 1) {
1393 this.SetIconStateChanged(this.buttonStartStopWebServer,
"/StopWebServer.png");
1394 Platform.runLater(() -> {
1395 this.buttonStartStopWebServer.setText(
"Stop WebServer");
1397 isStartWebSever = 1;
1399 if (isStartWebSever == 0) {
1403 this.SetIconStateChanged(this.buttonStartStopWebServer,
"/StartWebServer.png");
1404 Platform.runLater(() -> {
1405 this.buttonStartStopWebServer.setText(
"Start WebServer");
1407 isStartWebSever = 0;
1412 private void buttonStartStopWebServer_Click(MouseEvent event) {
1413 if (customScreenImplementation ==
null) {
1417 if (!DefaultCustomScreenImplementation.IsStartedHtmlWebserver()) {
1418 customScreenImplementation.StartHtmlWebServer();
1420 customScreenImplementation.StopHtmlWebServer();
1425 private void comboBoxTraceLevel_Action(ActionEvent actionEvent) {
1429 private class HmiWindowListener
implements WindowListener {
1431 public void windowOpened(WindowEvent e) {
1436 public void windowClosing(WindowEvent e) {
1437 if (customScreenImplementation !=
null) {
1438 customScreenImplementation.SetHmiScreenHandle(0);
1439 customScreenImplementation.CloseAllChildScreens(hmiWindow.GetHandle());
1441 buttonHMI.setDisable(
false);
1445 public void windowClosed(WindowEvent e) {
1450 public void windowIconified(WindowEvent e) {
1455 public void windowDeiconified(WindowEvent e) {
1460 public void windowActivated(WindowEvent e) {
1465 public void windowDeactivated(WindowEvent e) {
1470 private class HmiComponentAdapter
extends ComponentAdapter {
1472 public void componentResized(ComponentEvent e) {
1473 super.componentResized(e);
1474 customScreenImplementation.RefreshHmiScreen();
1479 private void buttonExecuteMain_Click(MouseEvent event) {
1481 if (this.project !=
null) {
1482 this.procedureWillExecute = project.GetMainProcedure();
1483 this.ExecuteProcedure();
1486 PrintText(
"There is no project has been loaded. Please reload the project");
1489 }
catch (Exception ex) {
1490 PrintText(
"Exception: " + ex.getMessage());
1495 private void btnExecuteProcedureSelected_Click(MouseEvent event) {
1497 CustomTreeItem node = (CustomTreeItem) treeViewOtxProject.getSelectionModel().getSelectedItem();
1500 !(node.getItem() instanceof IProcedure)) {
1501 PrintText(
"Please select a procedure");
1503 this.procedureWillExecute = (IProcedure) node.getItem();
1506 }
catch (Exception ex) {
1507 PrintText(
"Exception: " + ex.getMessage());
1513 private void CreateRuntimeManagerAndSetConfig() {
1515 InitializeRuntimeManagerByIpcTypeTextBox();
1517 if (this.runtimeManager !=
null) {
1519 UpdateTraceFolder();
1520 UpdateTraceFileMaxCount();
1521 UpdateTraceFileMaxSize();
1522 SetRuntimeManagerEvents();
1523 CheckCustomImplRadioButtonGroup();
1527 private void SetRuntimeManagerEvents() {
1528 runtimeManager.AddProcedureStartedListener(this::ProcedureStarted);
1529 runtimeManager.AddProcedureFinishedListener(this::ProcedureFinished);
1530 runtimeManager.AddProcedureAbortedListener(this::ProcedureAborted);
1531 runtimeManager.AddProcedureStoppedListener(this::ProcedureStopped);
1532 runtimeManager.AddProcedurePausedListener(this::ProcedurePaused);
1533 runtimeManager.AddProcedurePendingListener(this::ProcedurePending);
1534 runtimeManager.AddDiagConnectionStateChangedListener(this::DiagConnectionStateChanged);
1535 runtimeManager.AddProcedureContinuedListener(this::ProcedureContinued);
1536 runtimeManager.AddProcedureTimeoutListener(this::ProcedureTimeout);
1537 runtimeManager.AddInOutParameterValueChangedListener(this::InOutParameterValueChanged);
1539 PrintText(
"Initialization of runtime events finished");
1542 private void InitializeRuntimeManagerByIpcTypeTextBox() {
1543 String ipcType = comboBoxCommunicationType.getValue().trim();
1544 String statusInitializeRuntimeManager;
1547 if (ipcType.equals(SOCKET_COMMUNICATION)) {
1549 int rtPort = Integer.parseInt(textRuntimeCommunication.getText());
1550 if (textDiagCommunication.getText().trim().isEmpty()) {
1551 this.runtimeManager = RuntimeManagerFactory.CreateSocketRuntimeManager(rtPort);
1553 int diagPort = Integer.parseInt(textDiagCommunication.getText());
1554 this.runtimeManager = RuntimeManagerFactory.CreateSocketRuntimeManager(rtPort, diagPort);
1557 PrintText(
"Socket Runtime Manager (MinBinVersion: " + RuntimeConfig.GetInstance().GetMinBinVersion() +
") created");
1559 }
else if (ipcType.equals(PIPE_COMMUNICATION)) {
1560 String rtPipeName = textRuntimeCommunication.getText().trim();
1561 String diagPipeName = textDiagCommunication.getText().trim();
1562 if (diagPipeName.isEmpty()) {
1563 this.runtimeManager = RuntimeManagerFactory.CreatePipeRuntimeManager(rtPipeName);
1565 this.runtimeManager = RuntimeManagerFactory.CreatePipeRuntimeManager(rtPipeName, diagPipeName);
1568 PrintText(
"Pipe Runtime Manager (MinBinVersion: " + RuntimeConfig.GetInstance().GetMinBinVersion() +
") created");
1571 statusInitializeRuntimeManager = String.format(
1572 "Created %s Runtime Manager (MinBinVersion: %s)"
1573 , this.comboBoxCommunicationType.getValue()
1574 , RuntimeConfig.GetInstance().GetMinBinVersion()
1576 PrintText(statusInitializeRuntimeManager);
1577 }
catch (Exception ex) {
1578 PrintText(ex.getMessage());
1579 PrintText(
"No new Runtime Manager will be created");
1580 this.runtimeManager =
null;
1584 private void UpdateTraceLevel() {
1585 TraceLevels traceLevel =
TraceLevels.values()[comboBoxTraceLevel.getSelectionModel().getSelectedIndex()];
1586 RuntimeConfig.GetInstance().SetTraceLevel(traceLevel);
1589 private void UpdateTraceFolder() {
1590 RuntimeConfig.GetInstance().SetTraceFolder(textTracePath.getText());
1591 PrintText(
"Set TraceFolder to: " + textTracePath.getText());
1594 private void ProcedurePending(IRuntimeContext runtimeContext) {
1595 this.PrintText(String.format(
"ProcedurePending(%s) ExecutionState(%s)", runtimeContext.GetProcedure().GetFullName(), runtimeContext.GetExecutionState().toString()));
1596 this.UpdateExecutionState(runtimeContext);
1597 this.ShowConnectionStateMessage(runtimeContext);
1600 private void UpdateTraceFileMaxCount() {
1602 int traceFileMaxCount = Integer.parseInt(txtTraceFileMaxCount.getText());
1603 RuntimeConfig.GetInstance().SetTraceFileMaxCount(traceFileMaxCount);
1604 }
catch (java.lang.Exception e) {
1605 PrintText(e.getMessage());
1608 PrintText(
"TraceFileMaxCount is " + Integer.toString(RuntimeConfig.GetInstance().GetTraceFileMaxCount()));
1611 private void UpdateTraceFileMaxSize() {
1613 int traceFileMaxSize = Integer.parseInt(txtTraceFileMaxSize.getText());
1614 RuntimeConfig.GetInstance().SetTraceFileMaxSize(traceFileMaxSize);
1615 }
catch (java.lang.Exception e) {
1616 PrintText(e.getMessage());
1619 PrintText(
"TraceFileMaxSize is " + Integer.toString(RuntimeConfig.GetInstance().GetTraceFileMaxSize()));
1622 public void ProcedureStarted(IRuntimeContext runtimeContext) {
1623 synchronized (eventListenerLock) {
1624 this.PrintText(String.format(
"ProcedureStarted(%s) ExecutionState(%s)", runtimeContext.GetProcedure().GetFullName(), runtimeContext.GetExecutionState().toString()));
1626 String procedureName = runtimeContext.GetProcedure().GetFullName();
1628 this.PrintText(procedureName +
" - Started");
1629 this.UpdateExecutionState(runtimeContext);
1630 DisableExecutionButtons();
1631 this.buttonStop.setDisable(
false);
1632 AddRuntimeContext(runtimeContext);
1633 this.buttonPause.setDisable(IsPauseDisabled());
1638 private void DisableExecutionButtons() {
1639 if (!checkBoxAsynchron.isSelected()) {
1640 this.buttonExecuteMain.setDisable(
true);
1641 this.btnExecuteProcedureSelected.setDisable(
true);
1645 private void ProcedurePaused(IRuntimeContext runtimeContext, ExecutionStateChangeReason reason) {
1646 this.buttonPause.setDisable(IsPauseDisabled());
1647 this.buttonContinue.setDisable(reason == ExecutionStateChangeReason.Explicit ? IsContinueDisabled() :
true);
1648 this.PrintText(String.format(
"ProcedurePaused(%s) ExecutionState(%s) ExecutionStateChangeReason(%s)", runtimeContext.GetProcedure().GetFullName(), runtimeContext.GetExecutionState().toString(), reason.toString()));
1649 this.UpdateExecutionState(runtimeContext);
1650 if (reason == ExecutionStateChangeReason.UnexpectedDiagConnectionState) {
1651 this.ShowConnectionStateMessage(runtimeContext);
1655 private void ProcedureContinued(IRuntimeContext runtimeContext) {
1656 this.buttonPause.setDisable(IsPauseDisabled());
1657 this.buttonContinue.setDisable(IsContinueDisabled());
1658 this.PrintText(String.format(
"ProcedureContinued(%s) ExecutionState(%s)", runtimeContext.GetProcedure().GetFullName(), runtimeContext.GetExecutionState().toString()));
1659 this.UpdateExecutionState(runtimeContext);
1663 public void ProcedureAborted(IRuntimeContext runtimeContext) {
1664 synchronized (eventListenerLock) {
1665 String procedureName = runtimeContext.GetProcedure().GetFullName();
1667 if (runtimeContext.HasRuntimeException()) {
1668 PrintText(
"Runtime exception: " + runtimeContext.GetRuntimeException().getMessage());
1671 if (runtimeContext.HasOtxException()) {
1672 PrintText(
"Otx exception: " + runtimeContext.GetOtxException().getMessage());
1675 this.PrintText(String.format(
"ProcedureAborted(%s) ExecutionState(%s)", runtimeContext.GetProcedure().GetFullName(), runtimeContext.GetExecutionState().toString()));
1677 EnableExecutionButton();
1679 cyclicExecuteAsyncIsProcessing =
false;
1680 RemoveRuntimeContext(runtimeContext);
1681 this.buttonPause.setDisable(IsPauseDisabled());
1682 this.buttonContinue.setDisable(IsContinueDisabled());
1683 this.UpdateExecutionState(runtimeContext);
1687 private void UpdateExecutionState(IRuntimeContext context) {
1688 if (context !=
null) {
1689 switch (context.GetExecutionState()) {
1692 UpdateExecutionStateButtons(
true);
1702 UpdateExecutionStateButtons(
false);
1703 this.SetIconStateChanged(this.labelBatteryState,
"/IconBattery16.png");
1704 this.SetIconStateChanged(this.labelIgnitionState,
"/IconIgnition16.png");
1713 private void buttonCheckBatteryIgnition_Click(ActionEvent event) {
1714 CheckBatteryIgnitionState(this.runtimeManager);
1717 private void UpdateExecutionStateButtons(
boolean wasExecuted) {
1718 if (this.useConnectionState) {
1719 this.labelTimeout.setDisable(wasExecuted);
1720 this.textBoxTimeout.setDisable(wasExecuted);
1721 this.checkBoxUseConnectionState.setDisable(wasExecuted);
1722 this.labelExpectedState.setDisable(wasExecuted);
1723 this.checkBoxIgnition.setDisable(wasExecuted);
1724 this.labelPollingTime.setDisable(wasExecuted);
1725 this.textBoxPollingTime.setDisable(wasExecuted);
1726 this.labelVoltageThreshold.setDisable(wasExecuted);
1727 this.textBoxBatteryVoltageThreshold.setDisable(wasExecuted);
1728 this.buttonCheckBatteryIgnition.setDisable(wasExecuted);
1732 if (!checkBoxAsynchron.isSelected()) {
1733 this.buttonExecuteMain.setDisable(
true);
1734 this.btnExecuteProcedureSelected.setDisable(
true);
1737 this.buttonStop.setDisable(
false);
1739 EnableExecutionButton();
1741 this.buttonStop.setDisable(
true);
1745 private void DiagConnectionStateChanged(ClampState batteryState, ClampState ignitionState) {
1746 this.PrintText(String.format(
"Event DiagConnectionStateChanged occurred - BatteryState = %s, IgnitionState = %s", batteryState.toString(), ignitionState.toString()));
1747 SetBatteryIgnitionState(batteryState, ignitionState);
1750 public void FireAlertSound() {
1751 final Runnable runnable = (Runnable) Toolkit.getDefaultToolkit().getDesktopProperty(
"win.sound.default");
1753 if (runnable !=
null) {
1758 public void ProcedureFinished(IRuntimeContext runtimeContext) {
1759 synchronized (eventListenerLock) {
1760 String procedureName = runtimeContext.GetProcedure().GetFullName();
1761 String parameterOutput;
1763 for (IProcedureParameter procedureParameter :
1764 runtimeContext.GetProcedure().GetParameters()) {
1766 parameterOutput =
"Parameter Changed - " +
1767 procedureParameter.GetName() +
"(" + procedureParameter.GetDataType() +
") = ";
1769 if (procedureParameter.GetValue() !=
null) {
1770 parameterOutput += ShortenedValueString(procedureParameter);
1772 parameterOutput +=
"null";
1775 this.PrintText(parameterOutput);
1778 UpdateTableParameters(runtimeContext.GetProcedure());
1779 this.PrintText(String.format(
"ProcedureFinished(%s) ExecutionState(%s)", runtimeContext.GetProcedure().GetFullName(), runtimeContext.GetExecutionState().toString()));
1781 if (!this.checkBoxCyclic.isSelected()) {
1783 EnableExecutionButton();
1786 this.UpdateExecutionState(runtimeContext);
1787 cyclicExecuteAsyncIsProcessing =
false;
1789 RemoveRuntimeContext(runtimeContext);
1790 this.buttonPause.setDisable(IsPauseDisabled());
1791 this.buttonContinue.setDisable(IsContinueDisabled());
1796 public void ProcedureStopped(IRuntimeContext runtimeContext) {
1797 synchronized (eventListenerLock) {
1798 this.PrintText(String.format(
"ProcedureStopped(%s) ExecutionState(%s)", runtimeContext.GetProcedure().GetFullName(), runtimeContext.GetExecutionState().toString()));
1800 this.buttonExecuteMain.setDisable(
false);
1801 this.btnExecuteProcedureSelected.setDisable(
false);
1802 RemoveRuntimeContext(runtimeContext);
1803 this.buttonPause.setDisable(IsPauseDisabled());
1804 this.buttonContinue.setDisable(IsContinueDisabled());
1806 EnableExecutionButton();
1807 cyclicExecuteAsyncIsProcessing =
false;
1808 this.UpdateExecutionState(runtimeContext);
1812 private void ProcedureTimeout(IRuntimeContext runtimeContext) {
1813 this.PrintText(String.format(
"ProcedureTimeout(%s) ExecutionState(%s)", runtimeContext.GetProcedure().GetFullName(), runtimeContext.GetExecutionState().toString()));
1815 this.buttonExecuteMain.setDisable(
false);
1816 EnableExecutionButton();
1817 RemoveRuntimeContext(runtimeContext);
1818 this.buttonPause.setDisable(IsPauseDisabled());
1819 this.buttonContinue.setDisable(IsContinueDisabled());
1820 cyclicExecuteAsyncIsProcessing =
false;
1822 this.UpdateExecutionState(runtimeContext);
1825 private void EnableExecutionButton() {
1826 if (project !=
null && project.GetMainProcedure() !=
null) {
1827 this.buttonExecuteMain.setDisable(
false);
1830 this.btnExecuteProcedureSelected.setDisable(
false);
1833 private void InOutParameterValueChanged(IRuntimeContext iRuntimeContext, IProcedureInOutParameter parameter) {
1836 String message =
"Parameter '"
1837 + parameter.GetName()
1838 +
"' new value = " + ShortenedValueString(parameter);
1840 UpdateTableParameters(parameter);
1841 }
catch (Exception ex) {
1842 PrintText(ex.getMessage());
1847 }
catch (InterruptedException ignored) {
1853 private String ShortenedValueString(IProcedureParameter parameter) {
1855 String valueStr = ValueConverter.Value2String(parameter.GetValue());
1856 if (valueStr.length() > VALUE_STRING_MAX_LENGTH)
1857 return valueStr.substring(0, VALUE_STRING_MAX_LENGTH) +
"...";
1860 catch (Exception ex)
1867 private String ShortenedValueString(Object value) {
1868 if (value ==
null) {
1872 String valueStr = ValueConverter.Value2String(value);
1873 if (valueStr.length() > VALUE_STRING_MAX_LENGTH)
1874 return valueStr.substring(0, VALUE_STRING_MAX_LENGTH) +
"...";
1878 private void CheckCustomImplRadioButtonGroup() {
1879 if (radioButtonDefaultImplementation.isSelected()) {
1880 if (this.project !=
null) {
1881 customScreenImplementation.RemoveKeyDownListener(keyDownListener);
1882 customScreenImplementation.AddKeyDownListener(keyDownListener);
1885 stateVariableImplementation.AddStateVariableValueChangedHandler(this::StateVariableValueChange);
1886 contextVariableImplementation.AddContextVariableReadHandler(this::ContextVariableRead);
1888 runtimeManager.SetCustomImplementation(customScreenImplementation);
1889 runtimeManager.SetCustomImplementation(contextVariableImplementation);
1890 runtimeManager.SetCustomImplementation(stateVariableImplementation);
1891 runtimeManager.SetCustomImplementation(measureImplementation);
1892 runtimeManager.SetCustomImplementation(serviceProviderImplementation);
1893 }
else if (radioButtonOutputWindow.isSelected()) {
1895 runtimeManager.SetCustomImplementation(loggingOutputImpl);
1896 runtimeManager.SetCustomImplementation(basicScreenOutputImpl);
1897 runtimeManager.SetCustomImplementation(customScreenOutputImpl);
1898 runtimeManager.SetCustomImplementation(contextVariableOutputImpl);
1899 runtimeManager.SetCustomImplementation(stateVariableOutputImpl);
1900 runtimeManager.SetCustomImplementation(measureOutputImpl);
1901 runtimeManager.SetCustomImplementation(i18nOutput);
1902 runtimeManager.SetCustomImplementation(sqlOutput);
1903 runtimeManager.SetCustomImplementation(serviceProviderOutputImpl);
1905 runtimeManager.SetCustomImplementation((ILoggingImplementation)
null);
1906 runtimeManager.SetCustomImplementation((IBasicScreenImplementation)
null);
1907 runtimeManager.SetCustomImplementation((ICustomScreenImplementation)
null);
1908 runtimeManager.SetCustomImplementation((IContextVariableImplementation)
null);
1909 runtimeManager.SetCustomImplementation((IStateVariableImplementation)
null);
1910 runtimeManager.SetCustomImplementation((IMeasureImplementation)
null);
1911 runtimeManager.SetCustomImplementation((Ii18nImplementation)
null);
1912 runtimeManager.SetCustomImplementation((ISqlImplementation)
null);
1913 runtimeManager.SetCustomImplementation((IExternalServiceProviderImplementation)
null);
1916 PrintText(
"Set up custom implementation finished");
1919 private SampleConstants.CustomImplType GetCustomImplType() {
1921 if (radioButtonOutputWindow.isSelected())
1922 return SampleConstants.CustomImplType.OutputImpl;
1924 if (radioButtonNoCustomImplementation.isSelected())
1925 return SampleConstants.CustomImplType.NoCustom;
1927 return SampleConstants.CustomImplType.DefaultCustomImpl;
1930 private void ExecuteProcedure() {
1933 if (runtimeManager !=
null && procedureWillExecute !=
null) {
1934 buttonStop.setDisable(
false);
1936 CheckBatteryIgnitionState(this.runtimeManager);
1938 if (checkBoxCyclic.isSelected()) {
1940 }
else if (checkBoxAsynchron.isSelected()) {
1941 runtimeManager.ExecuteAsync(textRuntimeName.getText().trim(), procedureWillExecute,
this.expectedConnectionState, GetTimeout());
1946 }
catch (Exception ex) {
1947 PrintText(
"Execute failed: " + ex.getMessage());
1948 UpdateButtonStateAfterThrowException();
1952 private void UpdateButtonStateAfterThrowException() {
1953 this.buttonExecuteMain.setDisable(checkBoxCyclic.isSelected());
1954 this.btnExecuteProcedureSelected.setDisable(checkBoxCyclic.isSelected());
1956 UpdateExecutionStateButtons(
false);
1957 this.buttonPause.setDisable(IsPauseDisabled());
1958 this.buttonContinue.setDisable(IsContinueDisabled());
1960 this.SetIconStateChanged(this.labelBatteryState,
"/IconBattery16.png");
1961 this.SetIconStateChanged(this.labelIgnitionState,
"/IconIgnition16.png");
1964 private void ExecuteNotAsync() {
1966 Thread thread =
new Thread(() -> {
1968 runtimeManager.Execute(textRuntimeName.getText().trim(), procedureWillExecute,
this.expectedConnectionState, GetTimeout());
1969 }
catch (Exception ex) {
1970 PrintText(
"Execute failed: " + ex.getMessage());
1971 this.UpdateButtonStateAfterThrowException();
1974 thread.setName(
"Execute");
1975 thread.setDaemon(
true);
1979 private void ExecuteCyclic() {
1982 Thread thread =
new Thread(() -> {
1985 }
catch (Exception e) {
1986 e.printStackTrace();
1987 PrintText(
"ExecuteCyclic failed: " + e.getMessage());
1990 thread.setName(
"ExecuteCyclic");
1991 thread.setDaemon(
true);
1995 private void DoCyclic() throws InterruptedException {
1997 cyclicExecuteAsyncIsProcessing =
true;
1998 CheckBatteryIgnitionState(this.runtimeManager);
1999 if (this.checkBoxAsynchron.isSelected()) {
2000 IRuntimeContext runtimeContext = runtimeManager.ExecuteAsync(textRuntimeName.getText().trim(), procedureWillExecute,
this.expectedConnectionState, GetTimeout());
2005 IRuntimeContext runtimeContext = runtimeManager.Execute(
2006 textRuntimeName.getText().trim()
2007 , procedureWillExecute
2008 ,
this.expectedConnectionState, GetTimeout()
2013 if (this.checkBoxCyclicReload.isSelected()) {
2014 while (cyclicExecuteAsyncIsProcessing) {
2017 this.LoadContextFile();
2020 Platform.runLater(() -> {
2021 if (this.checkBoxCyclic.isSelected()) {
2022 this.checkBoxCyclic.setText(
"Cyclic (" + cyclic +
")");
2024 this.checkBoxCyclic.setText(
"Cyclic");
2028 }
while (checkBoxCyclic.isSelected());
2031 private void UpdateTable(IProcedure procedure) {
2033 if (procedure ==
null || procedure.GetParameters() ==
null) {
2036 UpdateTableParameters(procedure);
2037 IDocument document = procedure.GetDocument();
2039 if (document !=
null) {
2040 ArrayList<String> addedDocuments =
new ArrayList<String>();
2041 UpdateTableContextVariables(document,
false, addedDocuments);
2042 addedDocuments.clear();
2043 UpdateTableStateVariables(document,
false, addedDocuments);
2047 private void UpdateTableParameters(IProcedure procedure) {
2048 for (IProcedureParameter param : procedure.GetParameters()) {
2049 UpdateTableParameters(param);
2053 private void UpdateTableParameters(IProcedureParameter param) {
2055 if (param ==
null) {
2059 boolean updateParam =
false;
2062 ObservableList<CustomTableItem> items = tableParameter.getItems();
2063 for (CustomTableItem row : items) {
2066 if (param.GetName().equals(row.getName())) {
2068 synchronized (tableParameterLock) {
2069 row.setModel(param);
2079 CustomTableItem newRow =
new CustomTableItem(param);
2083 tableParameter.refresh();
2086 private void UpdateTableContextVariables(IDocument document, Boolean withPrefix, ArrayList<String> addedDocuments) {
2087 if (addedDocuments.contains(document.GetFullName())) {
2091 addedDocuments.add(document.GetFullName());
2093 for (IContextVariable context : document.GetContextVariables()) {
2094 if (context ==
null) {
2098 boolean updateContext =
false;
2101 for (
int i = 0; i < tableContextVariables.getItems().size(); i++) {
2103 CustomTableItem row = tableContextVariables.getItems().get(i);
2104 String nameContext = withPrefix ? document.GetFullName() : document.GetName();
2105 if (nameContext.equals(row.getName()) && row.getValue() !=
null) {
2106 if (this.radioButtonDefaultImplementation.isSelected()) {
2107 Object value = this.contextVariableImplementation.GetValue(
2112 row.setValue(value);
2114 row.setModel(context);
2117 updateContext =
true;
2122 if (!updateContext) {
2124 CustomTableItem newRow =
new CustomTableItem(context, withPrefix);
2125 if (this.radioButtonDefaultImplementation.isSelected()) {
2126 Object value = context.GetInitValue();
2127 newRow.setValue(value);
2129 tableContextVariables.getItems().add(newRow);
2134 for (IDocument importDoc : document.GetImports()) {
2135 UpdateTableContextVariables(importDoc,
true, addedDocuments);
2137 }
catch (Exception e) {
2138 PrintText(
"Exception" + e.getMessage());
2142 public void ContextVariableRead(IContextVariable contextVariable, Object value) {
2144 contextVariable.GetMappingName().isEmpty()
2147 " [MappedTo: " + contextVariable.GetMappingName() + (contextVariable.GetMappingIndex() > -1
2148 ? (
"[" + contextVariable.GetMappingIndex() +
"]")
2152 String outputLog =
"ContextVariableRead(" +
2153 contextVariable.GetDataType() +
" " +
2154 contextVariable.GetDocument().GetFullName() +
"." +
2155 contextVariable.GetName() + mappingStr +
" = " +
2156 ShortenedValueString(value) +
")";
2158 PrintText(outputLog);
2161 public void StateVariableValueChange(IStateVariable stateVariable, Object value) {
2163 stateVariable.GetMappingName().isEmpty()
2166 " [MappedTo: " + stateVariable.GetMappingName() + (stateVariable.GetMappingIndex() > -1
2167 ? (
"[" + stateVariable.GetMappingIndex() +
"]")
2171 String outputLog =
"StateVariableChanged(" +
2172 stateVariable.GetDataType() +
" " +
2173 stateVariable.GetDocument().GetFullName() +
"." +
2174 stateVariable.GetName() + mappingStr +
" = " +
2175 ShortenedValueString(value) +
")";
2177 PrintText(outputLog);
2178 UpdateTableStateVariables(stateVariable);
2181 private void UpdateTableStateVariables(IDocument document, Boolean withPrefix, ArrayList<String> addedDocuments) {
2182 if (addedDocuments.contains(document.GetFullName())) {
2186 addedDocuments.add(document.GetFullName());
2188 for (IStateVariable state : document.GetStateVariables()) {
2189 if (state ==
null) {
2192 CustomTableItem newRow =
new CustomTableItem(state, withPrefix);
2193 tableStateVariables.getItems().add(newRow);
2197 for (IDocument importDoc : document.GetImports()) {
2198 UpdateTableStateVariables(importDoc,
true, addedDocuments);
2200 }
catch (Exception e) {
2201 PrintText(
"Exception" + e.getMessage());
2205 private void UpdateTableStateVariables(IStateVariable state) {
2206 if (state ==
null) {
2211 for (
int i = 0; i < tableStateVariables.getItems().size(); i++) {
2213 CustomTableItem row = tableStateVariables.getItems().get(i);
2215 if (state == row.getModel() && row.getValue() !=
null) {
2216 if (radioButtonDefaultImplementation.isSelected()) {
2217 Object value = this.stateVariableImplementation.GetValue(state);
2218 row.setValue(value);
2220 row.setModel(state);
2227 private void LoadContextFile() {
2229 if (txtFilePath.getText().isEmpty())
2233 Path filePath = Paths.get(txtFilePath.getText());
2234 if (Files.notExists(filePath)) {
2235 PrintText(
"File is not exist!");
2240 this.project =
null;
2241 this.playerProject =
null;
2242 String fileExtension = FileUtil.GetExtension(filePath);
2243 if (fileExtension.contains(PTX_EXTENSION)) {
2244 this.project = LoadPtx();
2246 if (this.project !=
null) {
2247 ClearCustomImplementationsCaches();
2249 PrintText(
"Load project " + project.GetName() +
" successfully");
2252 SaveDirectoryOnSuccessLoad(filePath.getParent());
2253 ReadSettings(this.project.GetSettings());
2255 }
else if (fileExtension.contains(PPX_EXTENSION)) {
2256 this.playerProject = LoadPpx();
2258 if (this.playerProject !=
null) {
2259 ClearCustomImplementationsCaches();
2261 PrintText(
"Load player " + playerProject.GetName() +
" successfully");
2263 for (IProject project :
2264 playerProject.GetProjects()) {
2265 this.project = project;
2269 SaveDirectoryOnSuccessLoad(filePath.getParent());
2270 ReadSettings(this.playerProject.GetSettings());
2274 PrintText(
"Could not find supported file.");
2277 }
catch (Exception e) {
2282 private void PrintException(Exception e) {
2286 if (this.runtimeManager ==
null) {
2287 PrintText(
"RuntimeManager is not created, please check or set your license.");
2288 PrintText(
"Load project fail: RuntimeManager is not created.");
2292 if (e.getMessage().contains(
"The file cannot be decrypted")) {
2293 PrintText(
"The file cannot be decrypted. Either the password is wrong or the file has a wrong format or is corrupt. Please check the password or the file!");
2297 PrintText(e.getMessage());
2300 private void ClearSamepleGUI() {
2301 this.treeViewOtxProject.getRoot().getChildren().clear();
2302 this.tableProjectSetting.getItems().clear();
2305 private void ClearCustomImplementationsCaches() {
2306 this.contextVariableImplementation.ClearCaches();
2308 this.contextVariableOutputImpl.ClearCaches();
2310 this.stateVariableImplementation.ClearCaches();
2315 private void SaveDirectoryOnSuccessLoad(Path directoryToSave) {
2316 if (directoryToSave.toString().equals(lastOpenedDirectory))
2319 lastOpenedDirectory = directoryToSave.toString().intern();
2322 private void LoadPackage() {
2324 IPackage[] packages = project.GetPackages();
2326 if (packages ==
null) {
2327 IDocument document = project.GetStartupDocument();
2328 this.treeViewOtxProject.getRoot().getChildren().add(CreateDocumentNode(document));
2330 StringBuilder stringBuilder =
new StringBuilder();
2331 stringBuilder.append(project.GetName());
2333 if (!project.GetVersion().isEmpty()) {
2334 stringBuilder.append(
" (")
2335 .append(project.GetVersion())
2339 Node rootImage =
new ImageView(
new Image(getClass().getResourceAsStream(PROJECT_ICON)));
2340 CustomTreeItem projectRoot =
new CustomTreeItem(project);
2341 projectRoot.setValue(stringBuilder.toString());
2342 projectRoot.setGraphic(rootImage);
2344 for (IPackage item : packages) {
2345 projectRoot.getChildren().add(CreatePackageNode(item));
2348 projectRoot.setExpanded(
true);
2349 this.treeViewOtxProject.getRoot().getChildren().add(projectRoot);
2352 this.treeViewOtxProject.getSelectionModel().select(startupNode);
2356 private CustomTreeItem CreateDocumentNode(IDocument document) {
2357 CustomTreeItem documentNode =
new CustomTreeItem(document);
2358 String value = document.GetName();
2360 if (document.IsStartup()) {
2361 value +=
" (Start up)";
2363 documentNode.setValue(value);
2365 for (IProcedure procedure : document.GetProcedures()) {
2366 CustomTreeItem procedureNode = CreateProcedureNode(procedure);
2367 documentNode.getChildren().add(procedureNode);
2369 if (document.IsStartup() && procedure.GetName().equals(MAIN_PROCEDURE_NAME)) {
2370 startupNode = procedureNode;
2371 buttonExecuteMain.setDisable(
false);
2372 }
else if (startupNode ==
null) {
2373 startupNode = procedureNode;
2377 final Node documentImage =
new ImageView(
new Image(getClass().getResourceAsStream(DOCUMENT_ICON)));
2378 documentNode.setGraphic(documentImage);
2379 documentNode.setExpanded(
true);
2380 return documentNode;
2383 private CustomTreeItem CreateProcedureNode(IProcedure procedure) {
2384 CustomTreeItem procedureNode =
new CustomTreeItem(procedure);
2385 procedureNode.setValue(procedure.GetName());
2387 Node procedureImage =
new ImageView(
new Image(getClass().getResourceAsStream(PROCEDURE_ICON)));
2388 procedureNode.setGraphic(procedureImage);
2389 procedureNode.setExpanded(
true);
2391 if (checkBoxCyclicReload.isSelected() &&
2392 procedureWillExecute !=
null &&
2393 procedureWillExecute.GetFullName().equals(procedure.GetFullName())) {
2394 procedureWillExecute = procedure;
2397 return procedureNode;
2400 private CustomTreeItem CreatePackageNode(IPackage item) {
2401 CustomTreeItem packageNode =
new CustomTreeItem(item);
2402 packageNode.setValue(item.GetName());
2404 for (IDocument doc : item.GetDocuments()) {
2405 packageNode.getChildren().add(CreateDocumentNode(doc));
2408 for (IPackage pac : item.GetPackages()) {
2409 packageNode.getChildren().add(CreatePackageNode(pac));
2412 final Node packageImage =
new ImageView(
new Image(getClass().getResourceAsStream(PACKAGE_ICON)));
2413 packageNode.setGraphic(packageImage);
2414 packageNode.setExpanded(
true);
2418 private void PrintText(String context) {
2420 DateTimeFormatter dtf = DateTimeFormatter.ofPattern(
"HH:mm:ss.SSS");
2421 LocalDateTime now = LocalDateTime.now();
2423 synchronized (printTextLock) {
2424 String itemWillInsert = lineNumber +
" " + dtf.format(now) +
" " + context;
2426 Platform.runLater(() -> {
2427 if (lineNumber > 10000) {
2428 listViewOutputText.setItems(FXCollections.observableList(
new ArrayList<>()));
2429 buttonCopyRow.setDisable(
true);
2430 labelOutputOverflow.setVisible(
false);
2434 List<String> items = listViewOutputText.getItems();
2435 items.add(itemWillInsert +
"\n");
2436 listViewOutputText.scrollTo(items.size());
2439 if (lineNumber + 1 >= 7500) {
2440 labelOutputOverflow.setVisible(
true);
2445 this.buttonCopyRow.setDisable(
false);
2449 private IProject LoadPtx() throws IOException {
2450 IProject project =
null;
2452 if (runtimeManager.IsProtected(txtFilePath.getText())) {
2453 project = runtimeManager.LoadPtx(txtFilePath.getText(), txtPassword.getText().trim());
2455 project = runtimeManager.LoadPtx(txtFilePath.getText());
2461 private IPlayerProject LoadPpx() {
2462 IPlayerProject playerProject =
null;
2464 if (runtimeManager.IsProtected(txtFilePath.getText())) {
2465 playerProject = runtimeManager.LoadPpx(txtFilePath.getText(), txtPassword.getText().trim());
2467 playerProject = runtimeManager.LoadPpx(txtFilePath.getText());
2470 return playerProject;
2474 private void buttonPause_Click(MouseEvent event) {
2475 synchronized (runtimeContexts) {
2476 for (IRuntimeContext runtimeContext : runtimeContexts) {
2477 if (runtimeContext.GetExecutionState() == ExecutionState.Running) {
2478 runtimeContext.Pause();
2485 private void buttonContinue_Click(MouseEvent event) {
2486 synchronized (runtimeContexts) {
2487 for (IRuntimeContext runtimeContext : runtimeContexts) {
2488 if (runtimeContext.GetExecutionState() == ExecutionState.Paused) {
2489 runtimeContext.Continue();
2495 private void AddRuntimeContext(IRuntimeContext context) {
2496 synchronized (runtimeContexts) {
2497 runtimeContexts.add(context);
2501 private void RemoveRuntimeContext(IRuntimeContext context) {
2502 synchronized (runtimeContexts) {
2503 runtimeContexts.remove(context);
2507 private boolean IsPauseDisabled() {
2508 return !IsAnyRuntimeContextExecutionStateIs(ExecutionState.Running);
2511 private boolean IsContinueDisabled() {
2512 return !IsAnyRuntimeContextExecutionStateIs(ExecutionState.Paused);
2515 private boolean IsAnyRuntimeContextExecutionStateIs(
final ExecutionState executionState) {
2516 synchronized (runtimeContexts) {
2517 return runtimeContexts.stream()
2520 runtimeContext.GetExecutionState() == executionState
2526 void textBoxTimeout_Action() {
2530 private Long GetTimeout() {
2533 timeout = Long.parseLong(this.textBoxTimeout.getText());
2536 this.textBoxTimeout.setText(
"0");
2538 }
catch (NumberFormatException nfe) {
2539 this.textBoxTimeout.setText(
"0");
2545 private Stage CreateLicenseStage() throws IOException {
2546 FXMLLoader fxmlLoader =
new FXMLLoader(getClass().getResource(
"/LicenseForm.fxml"));
2547 Stage licenseInputFormStage = fxmlLoader.load();
2549 LicenseFormController licenseFormController = fxmlLoader.getController();
2550 licenseFormController.setReloadRuntimeManager(this::ReloadRuntimeMangerAfterSetLicense);
2552 licenseInputFormStage.getIcons().add(
new Image(
"/Key10.png"));
2553 licenseInputFormStage.initModality(Modality.APPLICATION_MODAL);
2554 licenseInputFormStage.setTitle(
"License");
2555 licenseInputFormStage.setResizable(
false);
2557 return licenseInputFormStage;
2560 public void ReloadRuntimeMangerAfterSetLicense() throws InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException, NoSuchAlgorithmException, InvalidKeyException, NoSuchPaddingException {
2561 CreateRuntimeManagerAndSetConfig();
2564 public void buttonLicense_Click() throws IOException {
2565 Stage licenseInputFormStage = this.CreateLicenseStage();
2566 licenseInputFormStage.showAndWait();
Converts OTX Value to String and vice versa.
Definition: ValueConverter.java:17
Class to manage the OTX-Runtime API licenses.
Definition: LicenseManager.java:9
Definition: RijndaelCrypt.java:19
Contains Projects.
Definition: IPlayerProject.java:10
Contains Packages and settings.
Definition: IProject.java:15
Package containing all interfaces for custom implementations.
Definition: ConfirmationTypes.java:1
Package contains all supported data types.
Definition: BlackBox.java:1
Package containing all objects related to licensing.
Definition: IpcLicenseCheckerBase.java:1
Package for browsing at OTX data structure.
Definition: IContextVariable.java:1
Package containing main entries: IProject and IPlayerProject.
Definition: IPlayerProject.java:1
Package containing the programming interface for browsing and execution of OTX procedures in own appl...
Definition: ApiConstants.java:1
Package containing all objects for browsing and execution of OTX procedures.
Definition: opentestsystem.otx.runtime2.api/src/main/java/opentestsystem/otx/runtime/package-info.java:4
Package containing all objects which are standardized according to ISO 13209 (OTX)
Package containing all objects related to testing inside automotive industry.