upravy tabulek
parent
dd27642d6b
commit
d32d51f4ae
|
|
@ -1,8 +1,6 @@
|
|||
package jnet.client.gui.serversettings;
|
||||
|
||||
import jnet.client.Client;
|
||||
import jnet.client.gui.dialog.AddDeviceTypeDialog;
|
||||
import jnet.client.gui.dialog.UserDialog;
|
||||
import jnet.client.client.NettyClientManager;
|
||||
import jnet.lib.LogFile;
|
||||
import jnet.lib.Message;
|
||||
|
|
@ -11,8 +9,10 @@ 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.DialogUser;
|
||||
import jnet.lib.object.SnmpTemplate;
|
||||
|
||||
public class ServerSettingsPanel extends JTabbedPane {
|
||||
|
|
@ -156,7 +156,7 @@ public class ServerSettingsPanel extends JTabbedPane {
|
|||
button.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
SwingUtilities.invokeLater(() -> new AddDeviceTypeDialog().setVisible(true));
|
||||
SwingUtilities.invokeLater(() -> new DialogUser(user, true).setVisible(true));
|
||||
}
|
||||
});
|
||||
panel.add(button);
|
||||
|
|
@ -185,7 +185,7 @@ public class ServerSettingsPanel extends JTabbedPane {
|
|||
button.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
SwingUtilities.invokeLater(() -> new UserDialog(null, true).setVisible(true));
|
||||
SwingUtilities.invokeLater(() -> new DialogUser(null, true).setVisible(true));
|
||||
}
|
||||
});
|
||||
panel.add(button);
|
||||
|
|
|
|||
|
|
@ -10,29 +10,39 @@ import javax.swing.table.DefaultTableCellRenderer;
|
|||
import javax.swing.table.DefaultTableModel;
|
||||
import javax.swing.table.TableColumn;
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Base64;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import jnet.client.client.NettyClientManager;
|
||||
import jnet.client.gui.dialog.DialogSnmpProfile;
|
||||
import jnet.lib.LogFile;
|
||||
import jnet.lib.Message;
|
||||
import jnet.lib.object.SnmpProfile;
|
||||
|
||||
public class TableDeviceType extends JTable {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(TableDeviceType.class.getName());
|
||||
private static final ConcurrentHashMap<String, ImageIcon> iconCache = new ConcurrentHashMap<>();
|
||||
private JPopupMenu popupMenu;
|
||||
|
||||
private static final String[] COLUMN_NAMES = {"Ikona", "Název zařízení"};
|
||||
|
||||
private static final String[] COLUMN_NAMES = {"ID", "Ikona", "Název zařízení"};
|
||||
|
||||
private DefaultTableModel model;
|
||||
|
||||
public TableDeviceType() {
|
||||
initTable();
|
||||
initPopupMenu();
|
||||
addMouseListener(new TableMouseAdapter());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getColumnClass(int column) {
|
||||
return column == 0 ? ImageIcon.class : String.class;
|
||||
return column == 1 ? ImageIcon.class : String.class;
|
||||
}
|
||||
|
||||
private void initTable() {
|
||||
|
|
@ -46,6 +56,11 @@ public class TableDeviceType extends JTable {
|
|||
setModel(model);
|
||||
setDefaultRenderer(String.class, new CenteredRenderer());
|
||||
setRowHeight(50);
|
||||
|
||||
// Skryjeme sloupec ID (index 0)
|
||||
getColumnModel().getColumn(0).setMinWidth(0);
|
||||
getColumnModel().getColumn(0).setMaxWidth(0);
|
||||
getColumnModel().getColumn(0).setPreferredWidth(0);
|
||||
|
||||
loadData();
|
||||
|
||||
|
|
@ -60,7 +75,90 @@ public class TableDeviceType extends JTable {
|
|||
model.setRowCount(0);
|
||||
|
||||
for (ObjectType obj : Client.objectType) {
|
||||
model.addRow(new Object[]{getIcon(obj), obj.getName()});
|
||||
model.addRow(new Object[]{obj.getId(), getIcon(obj), obj.getName()});
|
||||
}
|
||||
}
|
||||
|
||||
// -------- Získání vybraného zarizeni --------
|
||||
private ObjectType getSelectedDeviceType() {
|
||||
int viewRow = getSelectedRow();
|
||||
if (viewRow == -1) return null;
|
||||
int modelRow = convertRowIndexToModel(viewRow);
|
||||
int id = (int) model.getValueAt(modelRow, 0);
|
||||
return Client.objectType.stream()
|
||||
.filter(st -> st.getId() == id)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
// -------- Kontextové menu --------
|
||||
private void initPopupMenu() {
|
||||
popupMenu = new JPopupMenu();
|
||||
|
||||
// JMenuItem editItem = new JMenuItem("Upravit");
|
||||
// editItem.addActionListener(e -> {
|
||||
// ObjectType st = getSelectedDeviceType();
|
||||
// if (st != null) {
|
||||
// // Zde zavolejte metodu pro otevření editace
|
||||
// new DialogSnmpProfile(st, false).show();
|
||||
// }
|
||||
// });
|
||||
// popupMenu.add(editItem);
|
||||
|
||||
JMenuItem deleteItem = new JMenuItem("Smazat");
|
||||
deleteItem.addActionListener(e -> {
|
||||
ObjectType st = getSelectedDeviceType();
|
||||
if (st != null) {
|
||||
// Zde zavolejte metodu pro smazání
|
||||
int option = JOptionPane.showConfirmDialog(
|
||||
null,
|
||||
"Smazat object " + st.getName() + " ?",
|
||||
"Potvrzení akce",
|
||||
JOptionPane.YES_NO_OPTION
|
||||
);
|
||||
|
||||
if (option == JOptionPane.YES_OPTION) {
|
||||
NettyClientManager.sendMessage(Message.DEVICE_TYPE_DELETE, st.getId());
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
popupMenu.add(deleteItem);
|
||||
}
|
||||
|
||||
// -------- Myší listener --------
|
||||
private class TableMouseAdapter extends MouseAdapter {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) {
|
||||
ObjectType st = getSelectedDeviceType();
|
||||
if (st != null) {
|
||||
// Dvojklik = editace
|
||||
// new DialogSnmpProfile(st, false).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
showPopup(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
showPopup(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void showPopup(MouseEvent e) {
|
||||
int row = rowAtPoint(e.getPoint());
|
||||
if (row >= 0 && row < getRowCount()) {
|
||||
setRowSelectionInterval(row, row);
|
||||
}
|
||||
popupMenu.show(TableDeviceType.this, e.getX(), e.getY());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -80,7 +178,7 @@ public class TableDeviceType extends JTable {
|
|||
}
|
||||
return null;
|
||||
} catch (IOException e) {
|
||||
LOG.log(Level.WARNING, "Failed to decode image for: " + obj.getName(), e);
|
||||
LogFile.printErr("Failed to decode image for: " + obj.getName() + " "+ e.getMessage());
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,12 +1,7 @@
|
|||
package jnet.client.gui.serversettings;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.io.IOException;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPopupMenu;
|
||||
|
|
@ -14,20 +9,22 @@ import javax.swing.JTable;
|
|||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
import jnet.client.Client;
|
||||
import jnet.client.client.NettyClientManager;
|
||||
import jnet.client.gui.dialog.DialogSnmpProfile;
|
||||
import jnet.lib.LogFile;
|
||||
import jnet.lib.Message;
|
||||
import jnet.lib.ResourceLoader;
|
||||
import jnet.lib.object.SnmpProfile;
|
||||
import org.snmp4j.mp.SnmpConstants;
|
||||
|
||||
public class TableSnmpProfile extends JTable {
|
||||
|
||||
private DefaultTableModel model;
|
||||
private static final String[] COLUMN_NAMES = {"#", "Název", "Verze", "Community Read", "Port"};
|
||||
private JPopupMenu popupMenu;
|
||||
private static final String[] COLUMN_NAMES = {"ID", "Název", "Verze", "Community Read", "Port"};
|
||||
|
||||
public TableSnmpProfile() {
|
||||
initTable();
|
||||
initPopupMenu();
|
||||
addMouseListener(new TableMouseAdapter());
|
||||
}
|
||||
|
||||
private void initTable() {
|
||||
|
|
@ -42,61 +39,96 @@ public class TableSnmpProfile extends JTable {
|
|||
setModel(model);
|
||||
setRowHeight(25);
|
||||
|
||||
// Skryjeme sloupec ID (index 0)
|
||||
getColumnModel().getColumn(0).setMinWidth(0);
|
||||
getColumnModel().getColumn(0).setMaxWidth(0);
|
||||
getColumnModel().getColumn(0).setPreferredWidth(0);
|
||||
|
||||
loadData();
|
||||
|
||||
// Dvojklik pro editaci
|
||||
addMouseListener(new MouseAdapter() {
|
||||
private void zobrazMenu(MouseEvent e, int id) {
|
||||
try {
|
||||
JPopupMenu menu = new JPopupMenu();
|
||||
JMenuItem delete = new JMenuItem("Smazat", new ImageIcon(ImageIO.read(ResourceLoader.getFile("/img/trash.png"))));
|
||||
delete.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
int option = JOptionPane.showConfirmDialog(
|
||||
}
|
||||
|
||||
// -------- Získání vybraného profilu --------
|
||||
private SnmpProfile getSelectedSnmpProfile() {
|
||||
int viewRow = getSelectedRow();
|
||||
if (viewRow == -1) return null;
|
||||
int modelRow = convertRowIndexToModel(viewRow);
|
||||
int id = (int) model.getValueAt(modelRow, 0);
|
||||
return Client.snmpProfile.stream()
|
||||
.filter(st -> st.getId() == id)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
// -------- Kontextové menu --------
|
||||
private void initPopupMenu() {
|
||||
popupMenu = new JPopupMenu();
|
||||
|
||||
JMenuItem editItem = new JMenuItem("Upravit");
|
||||
editItem.addActionListener(e -> {
|
||||
SnmpProfile st = getSelectedSnmpProfile();
|
||||
if (st != null) {
|
||||
// Zde zavolejte metodu pro otevření editace
|
||||
new DialogSnmpProfile(st, false).show();
|
||||
}
|
||||
});
|
||||
popupMenu.add(editItem);
|
||||
|
||||
JMenuItem deleteItem = new JMenuItem("Smazat");
|
||||
deleteItem.addActionListener(e -> {
|
||||
SnmpProfile st = getSelectedSnmpProfile();
|
||||
if (st != null) {
|
||||
// Zde zavolejte metodu pro smazání
|
||||
int option = JOptionPane.showConfirmDialog(
|
||||
null,
|
||||
"Smazat profil ID " + id + " ?",
|
||||
"Smazat profil " + st.getName() + " ?",
|
||||
"Potvrzení akce",
|
||||
JOptionPane.YES_NO_OPTION
|
||||
);
|
||||
|
||||
if (option == JOptionPane.YES_OPTION) {
|
||||
Client.sendMessage(new Message(Message.SNMP_PROFILE_DELETE, id));
|
||||
NettyClientManager.sendMessage(Message.SNMP_PROFILE_DELETE, st.getId());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
menu.add(delete);
|
||||
menu.show(e.getComponent(), e.getX(), e.getY());
|
||||
} catch (IOException ex) {
|
||||
LogFile.printErr("Load icon error: " + ex.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
popupMenu.add(deleteItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
int row = getSelectedRow();
|
||||
int id = (int) getValueAt(row, 0);
|
||||
|
||||
// Ověříme, zda bylo kliknuto pravým tlačítkem (BUTTON3)
|
||||
if (e.getButton() == MouseEvent.BUTTON3) {
|
||||
zobrazMenu(e, id);
|
||||
} else if (e.getClickCount() == 2) {
|
||||
if (row != -1) {
|
||||
Client.snmpProfile.stream()
|
||||
.filter(u -> u.getId() == id)
|
||||
.findFirst()
|
||||
.ifPresent(profile -> {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
new DialogSnmpProfile(profile).show();
|
||||
});
|
||||
});
|
||||
}
|
||||
// -------- Myší listener --------
|
||||
private class TableMouseAdapter extends MouseAdapter {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) {
|
||||
SnmpProfile st = getSelectedSnmpProfile();
|
||||
if (st != null) {
|
||||
// Dvojklik = editace
|
||||
new DialogSnmpProfile(st, false).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
showPopup(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
showPopup(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void showPopup(MouseEvent e) {
|
||||
int row = rowAtPoint(e.getPoint());
|
||||
if (row >= 0 && row < getRowCount()) {
|
||||
setRowSelectionInterval(row, row);
|
||||
}
|
||||
popupMenu.show(TableSnmpProfile.this, e.getX(), e.getY());
|
||||
}
|
||||
}
|
||||
|
||||
private void loadData() {
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import java.awt.event.MouseAdapter;
|
|||
import java.awt.event.MouseEvent;
|
||||
import java.util.List;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPopupMenu;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.RowSorter;
|
||||
|
|
@ -45,7 +46,7 @@ public class TableSnmpTemplate extends JTable {
|
|||
getColumnModel().getColumn(0).setMinWidth(0);
|
||||
getColumnModel().getColumn(0).setMaxWidth(0);
|
||||
getColumnModel().getColumn(0).setPreferredWidth(0);
|
||||
|
||||
|
||||
loadData();
|
||||
}
|
||||
|
||||
|
|
@ -106,7 +107,17 @@ public class TableSnmpTemplate extends JTable {
|
|||
SnmpTemplate st = getSelectedSnmpTemplate();
|
||||
if (st != null) {
|
||||
// Zde zavolejte metodu pro smazání
|
||||
NettyClientManager.sendMessage(Message.SNMP_TEMPLATE_DELETE, st.getId());
|
||||
int option = JOptionPane.showConfirmDialog(
|
||||
null,
|
||||
"Smazat šablonu " + st.getName() + " ?",
|
||||
"Potvrzení akce",
|
||||
JOptionPane.YES_NO_OPTION
|
||||
);
|
||||
|
||||
if (option == JOptionPane.YES_OPTION) {
|
||||
NettyClientManager.sendMessage(Message.SNMP_TEMPLATE_DELETE, st.getId());
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
popupMenu.add(deleteItem);
|
||||
|
|
|
|||
|
|
@ -10,16 +10,23 @@ import javax.swing.*;
|
|||
import javax.swing.table.DefaultTableCellRenderer;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import jnet.client.client.NettyClientManager;
|
||||
import jnet.client.gui.dialog.DialogSnmpTemplate;
|
||||
import jnet.lib.LogFile;
|
||||
import jnet.lib.Message;
|
||||
import jnet.lib.object.SnmpTemplate;
|
||||
|
||||
public class TableUsers extends JTable {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(TableUsers.class.getName());
|
||||
|
||||
private static final ImageIcon ICON_YES;
|
||||
private static final ImageIcon ICON_NO;
|
||||
|
||||
private JPopupMenu popupMenu;
|
||||
|
||||
static {
|
||||
ImageIcon yes = null, no = null;
|
||||
|
|
@ -27,7 +34,7 @@ public class TableUsers extends JTable {
|
|||
yes = new ImageIcon(ImageIO.read(ResourceLoader.getFile("img/yes.png")));
|
||||
no = new ImageIcon(ImageIO.read(ResourceLoader.getFile("img/no.png")));
|
||||
} catch (IOException e) {
|
||||
LOG.log(Level.SEVERE, "Failed to load yes/no icons", e);
|
||||
LogFile.printErr("Failed to load yes/no icons " + e.getMessage());
|
||||
}
|
||||
ICON_YES = yes;
|
||||
ICON_NO = no;
|
||||
|
|
@ -43,9 +50,12 @@ public class TableUsers extends JTable {
|
|||
|
||||
public TableUsers() {
|
||||
initTable();
|
||||
initPopupMenu();
|
||||
addMouseListener(new TableMouseAdapter());
|
||||
}
|
||||
|
||||
private void initTable() {
|
||||
|
||||
model = new DefaultTableModel(COLUMN_NAMES, 0) {
|
||||
@Override
|
||||
public boolean isCellEditable(int row, int column) {
|
||||
|
|
@ -60,6 +70,11 @@ public class TableUsers extends JTable {
|
|||
|
||||
setModel(model);
|
||||
setRowHeight(25);
|
||||
|
||||
// Skryjeme sloupec ID (index 0)
|
||||
getColumnModel().getColumn(0).setMinWidth(0);
|
||||
getColumnModel().getColumn(0).setMaxWidth(0);
|
||||
getColumnModel().getColumn(0).setPreferredWidth(0);
|
||||
|
||||
loadData();
|
||||
|
||||
|
|
@ -111,6 +126,89 @@ public class TableUsers extends JTable {
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
// -------- Získání vybrané šablony --------
|
||||
private User getSelectedUser() {
|
||||
int viewRow = getSelectedRow();
|
||||
if (viewRow == -1) return null;
|
||||
int modelRow = convertRowIndexToModel(viewRow);
|
||||
int id = (int) model.getValueAt(modelRow, 0);
|
||||
return Client.users.stream()
|
||||
.filter(st -> st.getId() == id)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
// -------- Kontextové menu --------
|
||||
private void initPopupMenu() {
|
||||
popupMenu = new JPopupMenu();
|
||||
|
||||
JMenuItem editItem = new JMenuItem("Upravit");
|
||||
editItem.addActionListener(e -> {
|
||||
User st = getSelectedUser();
|
||||
if (st != null) {
|
||||
// Zde zavolejte metodu pro otevření editace
|
||||
new DialogUser(st, false).show();
|
||||
}
|
||||
});
|
||||
popupMenu.add(editItem);
|
||||
|
||||
JMenuItem deleteItem = new JMenuItem("Smazat");
|
||||
deleteItem.addActionListener(e -> {
|
||||
User st = getSelectedUser();
|
||||
if (st != null) {
|
||||
// Zde zavolejte metodu pro smazání
|
||||
int option = JOptionPane.showConfirmDialog(
|
||||
null,
|
||||
"Smazat uživatele " + st.getUsername() + " ?",
|
||||
"Potvrzení akce",
|
||||
JOptionPane.YES_NO_OPTION
|
||||
);
|
||||
|
||||
if (option == JOptionPane.YES_OPTION) {
|
||||
NettyClientManager.sendMessage(Message.SNMP_TEMPLATE_DELETE, st.getId());
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
popupMenu.add(deleteItem);
|
||||
}
|
||||
|
||||
// -------- Myší listener --------
|
||||
private class TableMouseAdapter extends MouseAdapter {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) {
|
||||
User st = getSelectedUser();
|
||||
if (st != null) {
|
||||
// Dvojklik = editace
|
||||
new DialogUser(st, false).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
showPopup(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
showPopup(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void showPopup(MouseEvent e) {
|
||||
int row = rowAtPoint(e.getPoint());
|
||||
if (row >= 0 && row < getRowCount()) {
|
||||
setRowSelectionInterval(row, row);
|
||||
}
|
||||
popupMenu.show(TableUsers.this, e.getX(), e.getY());
|
||||
}
|
||||
}
|
||||
|
||||
public void refreshTable() {
|
||||
SwingUtilities.invokeLater(this::loadData);
|
||||
|
|
|
|||
Loading…
Reference in New Issue