001package jmri.jmrit.display.swing; 002 003import javax.swing.*; 004 005import jmri.*; 006import jmri.jmrit.display.EditorPermissions.EditorPermissionEnum; 007import jmri.swing.PermissionSwing; 008 009/** 010 * Swing configurations for PermissionsSystemAdmin permissions. 011 * 012 * @author Daniel Bergqvist Copyright 2024 013 */ 014public class EditorPermissionsSwing { 015 016 public static class EditorPermissionSwing implements PermissionSwing { 017 018 @Override 019 public JLabel getLabel(Permission permission) throws IllegalArgumentException { 020 return new JLabel(permission.getName()); 021 } 022 023 @Override 024 public JComponent getComponent(Role role, Permission permission, Runnable onChange) 025 throws IllegalArgumentException { 026 JComboBox<EditorPermissionEnum> comboBox = new JComboBox<>(EditorPermissionEnum.values()); 027 PermissionValue value = role.getPermissionValue(permission); 028 if (!(value instanceof EditorPermissionEnum)) { 029 throw new IllegalArgumentException("Permission value is not a EditorPermissionEnum: " + value.getClass().getName()); 030 } 031 comboBox.setSelectedItem(value); 032 comboBox.addActionListener((evt) -> { 033 role.setPermission(permission, comboBox.getItemAt(comboBox.getSelectedIndex())); 034 onChange.run(); 035 }); 036 return comboBox; 037 } 038 039 } 040 041}