239 lines
8.1 KiB
Java
239 lines
8.1 KiB
Java
package jnet.client.gui.serversettings;
|
|
|
|
import jnet.client.client.NettyClientManager;
|
|
import jnet.lib.Message;
|
|
|
|
import javax.swing.*;
|
|
import java.awt.*;
|
|
import java.awt.event.ActionEvent;
|
|
import java.awt.event.ActionListener;
|
|
import static jnet.client.Client.user;
|
|
import jnet.client.gui.dialog.DialogSnmpProfile;
|
|
import jnet.client.gui.dialog.DialogSnmpTemplate;
|
|
import jnet.client.gui.dialog.DialogSnmpValueMap;
|
|
import jnet.client.gui.dialog.DialogUser;
|
|
import jnet.lib.object.SnmpTemplate;
|
|
|
|
public class ServerSettingsPanel extends JTabbedPane {
|
|
|
|
public static final int TAB_DEFAULT = 0;
|
|
public static final int TAB_DEVICE_TYPE = 1;
|
|
public static final int TAB_USERS = 2;
|
|
public static final int TAB_SNMP_PROFILE = 3;
|
|
public static final int TAB_SNMP_TEMPLATE = 4;
|
|
public static final int TAB_SNMP_VALUE_MAP = 5;
|
|
public static final int TAB_LOG = 6;
|
|
|
|
private TableDeviceType tableDeviceType;
|
|
private TableUsers tableUsers;
|
|
private TableSnmpProfile tableSnmpProfile;
|
|
private TableSnmpTemplate tableSnmpTemplate;
|
|
private TabLog tabLog;
|
|
private TableValueMap tableValueMap;
|
|
|
|
public ServerSettingsPanel() {
|
|
addTab("Základní", tabZakladni());
|
|
addTab("Typy zařízení", tabZarizeni());
|
|
addTab("Uživatelé", tabUsers());
|
|
addTab("SNMP profily", tabSnmpProfile());
|
|
addTab("SNMP šablony", tabSnmpTemplate());
|
|
addTab("SNMP mapování hodnot", tabSnmpValueMap());
|
|
addTab("Log serveru", tabServerLog());
|
|
}
|
|
|
|
public void setTable(int tab) {
|
|
setSelectedIndex(tab);
|
|
}
|
|
|
|
// ------------------------------------------------------------------------
|
|
// Základní nastavení (původní styl s null layout)
|
|
// ------------------------------------------------------------------------
|
|
private Component tabZakladni() {
|
|
JPanel panel = new JPanel();
|
|
panel.setLayout(new BorderLayout());
|
|
|
|
TabSettings tabSettings = new TabSettings();
|
|
JScrollPane scrollPane = new JScrollPane(tabSettings);
|
|
scrollPane.getVerticalScrollBar().setUnitIncrement(25);
|
|
panel.add(scrollPane,BorderLayout.CENTER);
|
|
|
|
|
|
return panel;
|
|
}
|
|
|
|
// ------------------------------------------------------------------------
|
|
// Typy zařízení
|
|
// ------------------------------------------------------------------------
|
|
private JPanel tabZarizeni() {
|
|
JPanel panel = new JPanel();
|
|
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
|
|
|
|
tableDeviceType = new TableDeviceType();
|
|
JScrollPane scrollPane = new JScrollPane(tableDeviceType);
|
|
panel.add(scrollPane);
|
|
|
|
JButton button = new JButton("Přidat typ");
|
|
button.setAlignmentX(Component.CENTER_ALIGNMENT);
|
|
button.addActionListener(new ActionListener() {
|
|
@Override
|
|
public void actionPerformed(ActionEvent e) {
|
|
SwingUtilities.invokeLater(() -> new DialogUser(user, true).setVisible(true));
|
|
}
|
|
});
|
|
panel.add(button);
|
|
|
|
return panel;
|
|
}
|
|
|
|
public void refreshDeviceTypes() {
|
|
if (tableDeviceType != null) {
|
|
SwingUtilities.invokeLater(() -> tableDeviceType.refreshTable());
|
|
}
|
|
}
|
|
|
|
// ------------------------------------------------------------------------
|
|
// Uživatelé
|
|
// ------------------------------------------------------------------------
|
|
private JPanel tabUsers() {
|
|
JPanel panel = new JPanel();
|
|
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
|
|
|
|
tableUsers = new TableUsers();
|
|
panel.add(new JScrollPane(tableUsers));
|
|
|
|
JButton button = new JButton("Přidat uživatele");
|
|
button.setAlignmentX(Component.CENTER_ALIGNMENT);
|
|
button.addActionListener(new ActionListener() {
|
|
@Override
|
|
public void actionPerformed(ActionEvent e) {
|
|
SwingUtilities.invokeLater(() -> new DialogUser(null, true).setVisible(true));
|
|
}
|
|
});
|
|
panel.add(button);
|
|
|
|
return panel;
|
|
}
|
|
|
|
public void refreshUsers() {
|
|
if (tableUsers != null) {
|
|
SwingUtilities.invokeLater(() -> tableUsers.refreshTable());
|
|
}
|
|
}
|
|
|
|
// ------------------------------------------------------------------------
|
|
// SNMP profily
|
|
// ------------------------------------------------------------------------
|
|
private Component tabSnmpProfile() {
|
|
JPanel panel = new JPanel();
|
|
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
|
|
|
|
tableSnmpProfile = new TableSnmpProfile();
|
|
JScrollPane scrollPane = new JScrollPane(tableSnmpProfile);
|
|
panel.add(scrollPane);
|
|
|
|
JButton button = new JButton("Přidat profil");
|
|
button.setAlignmentX(Component.CENTER_ALIGNMENT);
|
|
button.addActionListener(new ActionListener() {
|
|
@Override
|
|
public void actionPerformed(ActionEvent e) {
|
|
SwingUtilities.invokeLater(() -> new DialogSnmpProfile(null, true).setVisible(true));
|
|
}
|
|
});
|
|
panel.add(button);
|
|
|
|
return panel;
|
|
}
|
|
|
|
public void refreshSnmpProfiles() {
|
|
if (tableUsers != null) {
|
|
SwingUtilities.invokeLater(() -> tableSnmpProfile.refreshTable());
|
|
}
|
|
}
|
|
|
|
// ------------------------------------------------------------------------
|
|
// SNMP profily
|
|
// ------------------------------------------------------------------------
|
|
private Component tabSnmpTemplate() {
|
|
JPanel panel = new JPanel();
|
|
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
|
|
|
|
tableSnmpTemplate = new TableSnmpTemplate();
|
|
JScrollPane scrollPane = new JScrollPane(tableSnmpTemplate);
|
|
panel.add(scrollPane);
|
|
|
|
JButton button = new JButton("Přidat sablonu");
|
|
button.setAlignmentX(Component.CENTER_ALIGNMENT);
|
|
button.addActionListener(new ActionListener() {
|
|
@Override
|
|
public void actionPerformed(ActionEvent e) {
|
|
SwingUtilities.invokeLater(() -> new DialogSnmpTemplate(new SnmpTemplate(), true).show());
|
|
}
|
|
});
|
|
panel.add(button);
|
|
|
|
return panel;
|
|
}
|
|
|
|
public void refreshSnmpTemplates() {
|
|
if (tableUsers != null) {
|
|
SwingUtilities.invokeLater(() -> tableSnmpTemplate.refreshTable());
|
|
}
|
|
}
|
|
|
|
// ------------------------------------------------------------------------
|
|
// server log
|
|
// ------------------------------------------------------------------------
|
|
private Component tabServerLog() {
|
|
JPanel panel = new JPanel();
|
|
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
|
|
|
|
tabLog = new TabLog();
|
|
panel.add(tabLog);
|
|
|
|
JButton button = new JButton("Obnovit");
|
|
button.setAlignmentX(Component.CENTER_ALIGNMENT);
|
|
button.addActionListener(new ActionListener() {
|
|
@Override
|
|
public void actionPerformed(ActionEvent e) {
|
|
NettyClientManager.sendMessage(Message.SERVER_LOG, null);
|
|
}
|
|
});
|
|
panel.add(button);
|
|
|
|
return panel;
|
|
}
|
|
|
|
public void putLog(String[] log) {
|
|
tabLog.putLog(log);
|
|
}
|
|
|
|
// ------------------------------------------------------------------------
|
|
// snmp mapovani hodnot
|
|
// ------------------------------------------------------------------------
|
|
private Component tabSnmpValueMap() {
|
|
JPanel panel = new JPanel();
|
|
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
|
|
|
|
tableValueMap = new TableValueMap();
|
|
panel.add(new JScrollPane(tableValueMap));
|
|
|
|
JButton button = new JButton("Přidat mapování");
|
|
button.setAlignmentX(Component.CENTER_ALIGNMENT);
|
|
button.addActionListener(new ActionListener() {
|
|
@Override
|
|
public void actionPerformed(ActionEvent e) {
|
|
new DialogSnmpValueMap(null).show();
|
|
}
|
|
});
|
|
panel.add(button);
|
|
|
|
return panel;
|
|
}
|
|
|
|
public void refreshValueMap() {
|
|
if (tableValueMap != null) {
|
|
SwingUtilities.invokeLater(() -> tableValueMap.refreshTable());
|
|
}
|
|
}
|
|
}
|