202 lines
7.0 KiB
Java
202 lines
7.0 KiB
Java
package jnet.client.gui.dialog.object;
|
|
|
|
import java.awt.BorderLayout;
|
|
import java.awt.event.ActionEvent;
|
|
import java.awt.event.ActionListener;
|
|
import java.util.List;
|
|
import javax.swing.JButton;
|
|
import javax.swing.JFrame;
|
|
import javax.swing.JPanel;
|
|
import javax.swing.JTabbedPane;
|
|
import jnet.client.Client;
|
|
import jnet.client.network.NettyClient;
|
|
import jnet.lib.Message;
|
|
import jnet.lib.Status;
|
|
import jnet.lib.object.MapObject;
|
|
import jnet.lib.snmp.DeviceInfo;
|
|
import jnet.lib.snmp.Interface;
|
|
|
|
public class ObjectDialog extends JFrame {
|
|
|
|
private MapObject obj;
|
|
private int mapId;
|
|
private Boolean newObject;
|
|
|
|
private TabInfo tabInfo;
|
|
private TabSettings tabSettings;
|
|
private TabServices tabServices;
|
|
private TabEvents tabEvents;
|
|
|
|
public ObjectDialog(MapObject obj) {
|
|
this.obj = obj;
|
|
this.mapId = obj.getMap();
|
|
this.newObject = false;
|
|
|
|
// identifikator okna
|
|
this.setName("object_detail_" + obj.getId());
|
|
init();
|
|
}
|
|
|
|
public ObjectDialog(MapObject obj, boolean newObject) {
|
|
this.obj = new MapObject();
|
|
this.mapId = obj.getMap();
|
|
this.newObject = newObject;
|
|
init();
|
|
}
|
|
|
|
private void init() {
|
|
|
|
if (newObject) {
|
|
setTitle("Nový objekt");
|
|
} else {
|
|
setTitle(obj.getName());
|
|
}
|
|
|
|
setSize(600, 520);
|
|
setLocationRelativeTo(null);
|
|
setVisible(true);
|
|
setAlwaysOnTop(false);
|
|
setResizable(false);
|
|
|
|
setLayout(new BorderLayout());
|
|
|
|
JTabbedPane tabbedPane = new JTabbedPane();
|
|
|
|
// JScrollPane tabNastaveni = new JScrollPane(tabNastaveni(),
|
|
// JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
|
|
tabInfo = new TabInfo(this.getName(), obj);
|
|
tabSettings = new TabSettings(obj, newObject);
|
|
tabServices = new TabServices(obj, newObject);
|
|
tabEvents = new TabEvents(obj);
|
|
|
|
tabbedPane.addTab("Informace", tabInfo);
|
|
tabbedPane.addTab("Nastaveni", tabSettings);
|
|
tabbedPane.addTab("Služby", tabServices);
|
|
tabbedPane.addTab("Události", tabEvents);
|
|
//tabbedPane.addTab("Sondy", tabSondy());
|
|
|
|
// 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
|
|
}
|
|
|
|
add(tabbedPane, BorderLayout.CENTER);
|
|
|
|
JPanel pane = new JPanel();
|
|
JButton save = new JButton("Ulozit");
|
|
save.addActionListener(new ActionListener() {
|
|
public void actionPerformed(ActionEvent e) {
|
|
// kontrola chyb
|
|
String nazev = tabSettings.getName();
|
|
if (nazev == null) {
|
|
return;
|
|
}
|
|
String ip = tabSettings.getIp();
|
|
if (ip == null) {
|
|
return;
|
|
}
|
|
// ulozeni do objektu
|
|
obj.setMap(mapId);
|
|
obj.setName(nazev);
|
|
obj.setIp(ip);
|
|
obj.setUser(tabSettings.getUser());
|
|
obj.setPassword(new String(tabSettings.getPassword()));
|
|
obj.setObjectType(Client.objectType.get(tabSettings.getObjType()).getId());
|
|
obj.setSnmpProfile(Client.snmpProfile.get(tabSettings.getSnmpProfile()).getId());
|
|
obj.setActive(tabSettings.isActive());
|
|
obj.setDescription(tabSettings.getDesc());
|
|
obj.setLocation(tabSettings.getLoc());
|
|
|
|
obj.setWinbox(tabServices.isWinbox());
|
|
String winboxPort = tabServices.getWinboxPort();
|
|
if (winboxPort == null) {
|
|
return;
|
|
}
|
|
obj.setWinboxPort(winboxPort);
|
|
obj.setSsh(tabServices.isSsh());
|
|
String sshPort = tabServices.getSshPort();
|
|
if (sshPort == null) {
|
|
return;
|
|
}
|
|
obj.setSshPort(sshPort);
|
|
obj.setWeb(tabServices.isWeb());
|
|
String webPort = tabServices.getWebPort();
|
|
if (webPort == null) {
|
|
return;
|
|
}
|
|
obj.setWebPort(webPort);
|
|
obj.setWebVerze(tabServices.getWebVersion());
|
|
obj.setTelnet(tabServices.isTelnet());
|
|
String telnetPort = tabServices.getTelnetPort();
|
|
if (telnetPort == null) {
|
|
return;
|
|
}
|
|
obj.setTelnetPort(telnetPort);
|
|
obj.setSms(tabServices.isSms());
|
|
String smsPort = tabServices.getSmsPort();
|
|
if (smsPort == null) {
|
|
return;
|
|
}
|
|
obj.setSmsPort(smsPort);
|
|
obj.setSmsVerze(tabServices.getSmsVersion());
|
|
|
|
if (!obj.isActive() || newObject) {
|
|
obj.setStatus(Status.NA);
|
|
}
|
|
// ArrayList<SnmpProbe> probe = new ArrayList<>();
|
|
// if (!newObject) {
|
|
// probe.addAll(obj.getSnmpProbe());
|
|
// }
|
|
// obj.setSnmpProbe(probe);
|
|
|
|
if (newObject) {
|
|
NettyClient.send(Message.ADD_OBJECT, obj);
|
|
} else {
|
|
NettyClient.send(Message.UPDATE_OBJECT, obj);
|
|
}
|
|
|
|
// zavreni dialogu
|
|
dispose();
|
|
}
|
|
});
|
|
pane.add(save);
|
|
|
|
JButton cancel = new JButton("Zrusit");
|
|
cancel.addActionListener(new ActionListener() {
|
|
public void actionPerformed(ActionEvent e) {
|
|
dispose();
|
|
}
|
|
});
|
|
pane.add(cancel);
|
|
|
|
add(pane, BorderLayout.PAGE_END);
|
|
}
|
|
|
|
private String getStatus(int status) {
|
|
switch (status) {
|
|
case Status.OK: // online
|
|
return "online";
|
|
case Status.WARNING: // warning
|
|
return "varování";
|
|
case Status.OFFLINE: // offline
|
|
return "offline";
|
|
default: // other
|
|
return "n/a";
|
|
}
|
|
}
|
|
|
|
public void setDeviceInfo(DeviceInfo di){
|
|
this.tabInfo.setName(di.getSysName());
|
|
this.tabInfo.setDesc(di.getSysDescr());
|
|
this.tabInfo.setUptime(di.getSysUptime());
|
|
this.tabInfo.setVendor(di.getSysObjectID());
|
|
}
|
|
|
|
public void setDeviceInterface(List<Interface> iface){
|
|
this.tabInfo.setInterface(iface);
|
|
}
|
|
|
|
}
|