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
@@ -21,12 +21,16 @@
*/
package org.diylc.core;
import org.diylc.common.PropertyWrapper;
import java.util.List;
import java.util.Map;
public interface IDynamicPropertySource {
void setComponent(IDIYComponent<?> component);
void setProperties(List<PropertyWrapper> properties);
void setComponent(IDIYComponent<?> ownerObject);
List<Object> getAvailableValues();
@@ -1,38 +0,0 @@
package org.diylc.core;
import java.util.*;
public class SwitchPositionPropertyValueSource implements IDynamicPropertySource {
private IDIYComponent<?> component;
@Override
public void setComponent(IDIYComponent<?> component) {
this.component = component;
}
@Override
public List<Object> getAvailableValues() {
if (component == null) {
throw new RuntimeException("Component not set");
}
if (!(component instanceof ISwitch sw)) {
return List.of();
}
int positionCount = sw.getPositionCount();
List<Object> res = new ArrayList<>();
res.add(null);
for (int i = 0; i < positionCount; i++) {
res.add(i);
}
return res;
}
@Override
public String getDisplayValue(Object value) {
if (value == null) {
return "";
}
return "#" + (((Integer)value) + 1);
}
}