pridáno tlačítko na SNMP test a refres infa o objektu
parent
4b7d0e3e8f
commit
1e7bc533b0
|
|
@ -19,6 +19,7 @@ import jnet.lib.object.SnmpProfile;
|
|||
import jnet.lib.object.User;
|
||||
import jnet.lib.snmp.DeviceInfo;
|
||||
import jnet.lib.snmp.Interface;
|
||||
import jnet.lib.snmp.SNMPTester;
|
||||
|
||||
public class ClientMessageParser {
|
||||
|
||||
|
|
@ -50,6 +51,7 @@ public class ClientMessageParser {
|
|||
handlers.put(Message.SERVER_CONFIG, ClientMessageParser::handleServerConfig);
|
||||
handlers.put(Message.SNMP_OBJECT_INFO, ClientMessageParser::handleSnmpObjectInfo);
|
||||
handlers.put(Message.SNMP_OBJECT_INTERFACE, ClientMessageParser::handleSnmpObjectInterface);
|
||||
handlers.put(Message.SNMP_TEST, ClientMessageParser::handleSnmpTest);
|
||||
}
|
||||
|
||||
public static void parse(Message msg) {
|
||||
|
|
@ -228,4 +230,11 @@ public class ClientMessageParser {
|
|||
List<Interface> iface = (List<Interface>) msg_obj[1];
|
||||
UIUpdater.updateObjectInterface(frame, iface);
|
||||
}
|
||||
|
||||
private static void handleSnmpTest(Message msg) {
|
||||
Object[] msg_obj = (Object[]) msg.getMsg();
|
||||
String frame = (String) msg_obj[0];
|
||||
boolean result = (boolean) msg_obj[1];
|
||||
UIUpdater.showResultSnmpTest(frame, result);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,4 +56,15 @@ public class UIUpdater {
|
|||
}
|
||||
}
|
||||
|
||||
public static void showResultSnmpTest(String frameName, boolean result) {
|
||||
for (Window w : JFrame.getWindows()) {
|
||||
if (w instanceof JFrame && frameName.equals(w.getName())) {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
((ObjectDialog) w).showResultSnmpTest(result);
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,23 @@
|
|||
package jnet.client.gui.dialog.object;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Dialog;
|
||||
import java.awt.Frame;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.List;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JProgressBar;
|
||||
import javax.swing.JTabbedPane;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
import jnet.client.Client;
|
||||
import jnet.client.network.NettyClient;
|
||||
import jnet.lib.Message;
|
||||
|
|
@ -27,6 +37,10 @@ public class ObjectDialog extends JFrame {
|
|||
private TabServices tabServices;
|
||||
private TabEvents tabEvents;
|
||||
|
||||
private JButton snmpTest = new JButton("Test SNMP");
|
||||
private JButton btnRefresh = new JButton("Obnovit");
|
||||
private JDialog progress;
|
||||
|
||||
public ObjectDialog(MapObject obj) {
|
||||
this.obj = obj;
|
||||
this.mapId = obj.getMap();
|
||||
|
|
@ -75,13 +89,35 @@ public class ObjectDialog extends JFrame {
|
|||
tabbedPane.addTab("Události", tabEvents);
|
||||
//tabbedPane.addTab("Sondy", tabSondy());
|
||||
|
||||
// Přidání listeneru na změnu tabu
|
||||
tabbedPane.addChangeListener(new ChangeListener() {
|
||||
@Override
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
int selectedIndex = tabbedPane.getSelectedIndex();
|
||||
if (selectedIndex == 1) { // pokud je zobrazena zalozka nastaveni zobrazit tlačítko test snmp
|
||||
snmpTest.setVisible(true);
|
||||
} else {
|
||||
snmpTest.setVisible(false);
|
||||
}
|
||||
if (selectedIndex == 0) { // pokud je zobrazena karta info zobrazit tlačítko refresh
|
||||
btnRefresh.setVisible(true);
|
||||
} else {
|
||||
btnRefresh.setVisible(false);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// pokud se jedna o novy objekt
|
||||
if (newObject) {
|
||||
tabbedPane.setSelectedIndex(1); // prepne na kartu nastaveni
|
||||
tabbedPane.setEnabledAt(0, false); // vypne kartu informace
|
||||
tabbedPane.setEnabledAt(3, false); // vypne kartu udalosti
|
||||
} else {
|
||||
// pokud se nejsedna o novy objekt odeslat snmp pozadavek na ziskani informaci o zarizeni
|
||||
snmpRequest();
|
||||
}
|
||||
|
||||
|
||||
add(tabbedPane, BorderLayout.CENTER);
|
||||
|
||||
JPanel pane = new JPanel();
|
||||
|
|
@ -156,14 +192,11 @@ public class ObjectDialog extends JFrame {
|
|||
} else {
|
||||
NettyClient.send(Message.UPDATE_OBJECT, obj);
|
||||
}
|
||||
|
||||
// zavreni dialogu
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
pane.add(save);
|
||||
|
||||
JButton cancel = new JButton("Zrusit");
|
||||
JButton cancel = new JButton("Zavřít");
|
||||
cancel.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
dispose();
|
||||
|
|
@ -171,6 +204,27 @@ public class ObjectDialog extends JFrame {
|
|||
});
|
||||
pane.add(cancel);
|
||||
|
||||
// tlačítko snmp test na zalozce nastaveni
|
||||
snmpTest.setVisible(false);
|
||||
snmpTest.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Object[] o = {getName(), obj};
|
||||
NettyClient.send(Message.SNMP_TEST, o);
|
||||
progress = showProgress();
|
||||
}
|
||||
});
|
||||
pane.add(snmpTest);
|
||||
|
||||
// tlačítko obnovit na info zalozce
|
||||
btnRefresh.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
snmpRequest();
|
||||
}
|
||||
});
|
||||
pane.add(btnRefresh);
|
||||
|
||||
add(pane, BorderLayout.PAGE_END);
|
||||
}
|
||||
|
||||
|
|
@ -198,4 +252,41 @@ public class ObjectDialog extends JFrame {
|
|||
this.tabInfo.setInterface(iface);
|
||||
}
|
||||
|
||||
public void showResultSnmpTest(boolean result) {
|
||||
progress.dispose();
|
||||
if (result) {
|
||||
JOptionPane.showMessageDialog(null, "SNMP funkční", "SNMP test", JOptionPane.INFORMATION_MESSAGE);
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(null, "SNMP nefunkční", "SNMP test", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private JDialog showProgress(){
|
||||
JDialog dialog = new JDialog((Frame) null, "Testování", true);
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
dialog.setSize(200, 100);
|
||||
dialog.setLayout(new BorderLayout());
|
||||
|
||||
JLabel label = new JLabel("Prosím, čekejte...", SwingConstants.CENTER);
|
||||
JProgressBar progressBar = new JProgressBar();
|
||||
progressBar.setIndeterminate(true); // Animace nekonečného načítání
|
||||
|
||||
dialog.add(label, BorderLayout.NORTH);
|
||||
dialog.add(progressBar, BorderLayout.CENTER);
|
||||
|
||||
dialog.setLocationRelativeTo(null);
|
||||
dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
|
||||
dialog.setVisible(true);
|
||||
});
|
||||
return dialog;
|
||||
}
|
||||
|
||||
private void snmpRequest() {
|
||||
Object[] data = {getName(), this.obj};
|
||||
NettyClient.send(Message.SNMP_OBJECT_INFO, data);
|
||||
NettyClient.send(Message.SNMP_OBJECT_INTERFACE, data);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,8 +27,7 @@ public class TabInfo extends JPanel {
|
|||
this.frameName = frameName;
|
||||
init();
|
||||
|
||||
// odeslani SNMP dotazu na server
|
||||
snmpRequest();
|
||||
|
||||
}
|
||||
|
||||
private void init() {
|
||||
|
|
@ -92,12 +91,6 @@ public class TabInfo extends JPanel {
|
|||
|
||||
}
|
||||
|
||||
private void snmpRequest() {
|
||||
Object[] data = {frameName, this.obj};
|
||||
NettyClient.send(Message.SNMP_OBJECT_INFO, data);
|
||||
NettyClient.send(Message.SNMP_OBJECT_INTERFACE, data);
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name.setText(name);
|
||||
}
|
||||
|
|
@ -115,6 +108,7 @@ public class TabInfo extends JPanel {
|
|||
}
|
||||
|
||||
public void setInterface(List<Interface> iface) {
|
||||
tableModel.setRowCount(0);
|
||||
for (Interface i : iface) {
|
||||
Object[] d = {
|
||||
i.getDescription(),
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@ import javax.swing.JPasswordField;
|
|||
import javax.swing.JTextArea;
|
||||
import javax.swing.JTextField;
|
||||
import jnet.client.Client;
|
||||
import jnet.client.network.NettyClient;
|
||||
import jnet.lib.Message;
|
||||
import jnet.lib.object.MapObject;
|
||||
import jnet.lib.object.ObjectType;
|
||||
import jnet.lib.object.SnmpProfile;
|
||||
|
|
@ -113,17 +115,7 @@ public class TabSettings extends JPanel {
|
|||
disableCheBox.setBounds(110, 180, 160, 25);
|
||||
this.add(disableCheBox);
|
||||
|
||||
JButton snmpTest = new JButton("Test SNMP");
|
||||
snmpTest.setBounds(390, 180, 160, 25);
|
||||
snmpTest.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
/* TODO idealne at test provede server (ten bude osesilat informace o snmp pozadavky!!!!
|
||||
|
||||
*/
|
||||
}
|
||||
});
|
||||
this.add(snmpTest);
|
||||
|
||||
JLabel locLabel = new JLabel("Umístění");
|
||||
locLabel.setBounds(20, 230, 80, 25);
|
||||
|
|
|
|||
Loading…
Reference in New Issue