1 package com.jsql.view.swing.panel.address;
2
3 import com.jsql.model.bean.util.Interaction;
4 import com.jsql.model.bean.util.Request;
5 import com.jsql.util.I18nUtil;
6 import com.jsql.util.LogLevelUtil;
7 import com.jsql.view.swing.manager.util.StateButton;
8 import com.jsql.view.swing.panel.PanelAddressBar;
9 import com.jsql.view.swing.util.MediatorHelper;
10 import org.apache.logging.log4j.LogManager;
11 import org.apache.logging.log4j.Logger;
12
13 import javax.swing.*;
14 import java.awt.event.ActionEvent;
15 import java.awt.event.ActionListener;
16
17 public class ActionStart implements ActionListener {
18
19
20
21
22 private static final Logger LOGGER = LogManager.getRootLogger();
23
24 protected final PanelAddressBar panelAddressBar;
25
26 public ActionStart(PanelAddressBar panelAddressBar) {
27 this.panelAddressBar = panelAddressBar;
28 }
29
30 @Override
31 public void actionPerformed(ActionEvent e) {
32
33 if (this.panelAddressBar.getAddressMenuBar().getButtonInUrl().getState() == StateButton.STARTABLE) {
34 this.startInjection();
35 } else if (this.panelAddressBar.getAddressMenuBar().getButtonInUrl().getState() == StateButton.STOPPABLE) {
36 this.stopInjection();
37 }
38 }
39
40 protected void startInjection() {
41
42 int option = JOptionPane.OK_OPTION;
43
44
45 if (MediatorHelper.model().shouldErasePreviousInjection()) {
46
47
48
49 try {
50 option = JOptionPane.showConfirmDialog(
51 null,
52 I18nUtil.valueByKey("DIALOG_NEW_INJECTION_TEXT"),
53 I18nUtil.valueByKey("DIALOG_NEW_INJECTION_TITLE"),
54 JOptionPane.OK_CANCEL_OPTION
55 );
56 } catch (IllegalArgumentException | ClassCastException e) {
57 LOGGER.log(LogLevelUtil.CONSOLE_JAVA, e, e);
58 }
59 }
60
61
62 if (option == JOptionPane.OK_OPTION) {
63
64 this.panelAddressBar.getAddressMenuBar().getButtonInUrl().setToolTipText(I18nUtil.valueByKey("BUTTON_STOP_TOOLTIP"));
65 this.panelAddressBar.getAddressMenuBar().getButtonInUrl().setInjectionRunning();
66 this.panelAddressBar.getAddressMenuBar().getLoader().setVisible(true);
67
68
69 var requests = new Request();
70 requests.setMessage(Interaction.RESET_INTERFACE);
71 MediatorHelper.model().sendToViews(requests);
72
73 MediatorHelper.model().getMediatorUtils().getParameterUtil().controlInput(
74 this.panelAddressBar.getTextFieldAddress().getText().trim(),
75 this.panelAddressBar.getTextFieldRequest().getText().trim(),
76 this.panelAddressBar.getTextFieldHeader().getText().trim(),
77 this.panelAddressBar.getMethodInjection(),
78 this.panelAddressBar.getRequestPanel().getTypeRequest(),
79 false
80 );
81 }
82 }
83
84 private void stopInjection() {
85
86 this.panelAddressBar.getAddressMenuBar().getLoader().setVisible(false);
87 this.panelAddressBar.getAddressMenuBar().getButtonInUrl().setInjectionStopping();
88 this.panelAddressBar.getAddressMenuBar().getButtonInUrl().setToolTipText(I18nUtil.valueByKey("BUTTON_STOPPING_TOOLTIP"));
89
90 MediatorHelper.model().setIsStoppedByUser(true);
91 }
92 }