fixed dynamic loading

This commit is contained in:
Bane Stojkovic
2025-03-16 20:37:10 +01:00
parent 473630a5e8
commit f925093c80
6 changed files with 104 additions and 66 deletions
@@ -71,29 +71,35 @@ public class DynamicValueEditor extends JComboBox<Object> {
public Component getListCellRendererComponent(JList<?> list, Object value, int index,
boolean isSelected, boolean cellHasFocus) {
// TODO Auto-generated method stub
return super.getListCellRendererComponent(list, value == null ? null : LangUtil.translate(dynamicPropertySource.getDisplayValue(value)),
return super.getListCellRendererComponent(list, LangUtil.translate(dynamicPropertySource.getDisplayValue(value)),
index, isSelected, cellHasFocus);
}
});
setSelectedItem(property.getValue());
// Create a shared refresh action
final Runnable refreshAction = () -> {
if (getModel() instanceof DynamicComboBoxModel model) {
model.refreshValues();
}
};
addPopupMenuListener(new PopupMenuListener() {
@Override
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
// Schedule the update just after the popup becomes visible
SwingUtilities.invokeLater(() -> {
if (getModel() instanceof DynamicComboBoxModel model) {
model.refreshValues();
}
});
refreshAction.run();
}
@Override
public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {}
public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
}
@Override
public void popupMenuCanceled(PopupMenuEvent e) {}
public void popupMenuCanceled(PopupMenuEvent e) {
}
});
addItemListener(new ItemListener() {
@@ -76,6 +76,13 @@ public class PropertyEditorDialog extends ButtonDialog {
this.properties = properties;
this.defaultedProperties = new HashSet<PropertyWrapper>();
// update dynamic property sources
// TODO consider better way to do this
properties.stream()
.map(x -> x.getDynamicPropertySource())
.filter(x -> x != null)
.forEach(source -> source.setProperties(properties));
setMinimumSize(new Dimension(240, 40));
layoutGui();