use of jmri.jmrix.swing.SystemConnectionAction in project JMRI by JMRI.
the class AbstractActionModelFactory method getDialogMessage.
private JPanel getDialogMessage(JList<String> actions, JComboBox<String> connections) {
// NOI18N
JLabel connectionsLabel = new JLabel(Bundle.getMessage("AbstractActionModelFactory.getDialogMessage.connectionsLabel", JLabel.LEADING));
actions.getSelectionModel().addListSelectionListener((ListSelectionEvent e) -> {
if (!e.getValueIsAdjusting()) {
connections.removeAllItems();
connections.setEnabled(false);
connectionsLabel.setEnabled(false);
String name = actions.getSelectedValue();
if (name != null) {
String className = StartupActionModelUtil.getDefault().getClassName(name);
if (className != null && StartupActionModelUtil.getDefault().isSystemConnectionAction(className)) {
try {
Action action = (Action) Class.forName(className).newInstance();
if (SystemConnectionAction.class.isAssignableFrom(action.getClass())) {
((SystemConnectionAction) action).getSystemConnectionMemoClasses().stream().forEach((clazz) -> {
InstanceManager.getList(SystemConnectionMemo.class).stream().forEach((memo) -> {
if (clazz.isAssignableFrom(memo.getClass())) {
connections.addItem(memo.getUserName());
connections.setEnabled(true);
connectionsLabel.setEnabled(true);
}
});
});
}
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) {
log.error("Unable to create Action", ex);
}
}
}
}
});
connections.setEnabled(false);
connectionsLabel.setEnabled(false);
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
panel.add(new JLabel(this.getEditModelMessage(), JLabel.LEADING));
panel.add(new JScrollPane(actions));
panel.add(connectionsLabel);
panel.add(connections);
return panel;
}
use of jmri.jmrix.swing.SystemConnectionAction in project JMRI by JMRI.
the class AbstractActionModel method performAction.
@Override
public void performAction() throws JmriException {
log.debug("Invoke Action from {}", className);
try {
Action action = (Action) Class.forName(className).newInstance();
if (SystemConnectionAction.class.isAssignableFrom(action.getClass())) {
SystemConnectionMemo memo = ConnectionNameFromSystemName.getSystemConnectionMemoFromSystemPrefix(this.getSystemPrefix());
if (memo != null) {
((SystemConnectionAction) action).setSystemConnectionMemo(memo);
} else {
log.warn("Connection \"{}\" does not exist and cannot be assigned to action {}\nThis warning can be silenced by configuring the connection associated with the startup action.", this.getSystemPrefix(), className);
}
}
this.performAction(action);
} catch (ClassNotFoundException ex) {
log.error("Could not find specified class: {}", className);
} catch (IllegalAccessException ex) {
log.error("Unexpected access exception for class: {}", className, ex);
throw new JmriException(ex);
} catch (InstantiationException ex) {
log.error("Could not instantiate specified class: {}", className, ex);
throw new JmriException(ex);
} catch (Exception ex) {
log.error("Error while performing startup action for class: {}", className, ex);
throw new JmriException(ex);
}
}
Aggregations