Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2023 BSI Business Systems Integration AG
* Copyright (c) 2010, 2026 BSI Business Systems Integration AG
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand All @@ -15,6 +15,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -144,14 +145,18 @@ protected void initConfig() {

@Override
public void addField(IFormField f) {
CompositeFieldUtility.addField(f, this, getFieldsInternal());
List<IFormField> writableFields = new LinkedList<>(getFieldsInternal());
CompositeFieldUtility.addField(f, this, writableFields);
propertySupport.setPropertyNoFire(PROP_FIELDS, writableFields);
addChildFieldPropertyChangeListener(f);
handleFieldsChanged();
}

@Override
public void removeField(IFormField f) {
CompositeFieldUtility.removeField(f, this, getFieldsInternal());
List<IFormField> writableFields = new LinkedList<>(getFieldsInternal());
CompositeFieldUtility.removeField(f, this, writableFields);
propertySupport.setPropertyNoFire(PROP_FIELDS, writableFields);
removeChildFieldPropertyChangeListener(f);
handleFieldsChanged();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2023 BSI Business Systems Integration AG
* Copyright (c) 2010, 2026 BSI Business Systems Integration AG
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand All @@ -16,9 +16,11 @@
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.ConcurrentModificationException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -238,23 +240,40 @@ public <T> boolean setPropertyListAlwaysFire(String name, List<T> newValue) {

private <T> boolean setPropertyList(String name, List<T> newValue, boolean alwaysFire) {
Object oldValue = m_props.get(name);
newValue = optimizeList(newValue);
boolean propChanged = setPropertyNoFire(name, newValue);
if (propChanged || alwaysFire) {
Object eventOldValue = null;
if (oldValue instanceof List) {
eventOldValue = CollectionUtility.arrayList((Collection<?>) oldValue);
eventOldValue = List.copyOf((Collection<?>) oldValue);
}
// fire a copy
List<T> eventNewValue = null;
if (newValue != null) {
eventNewValue = CollectionUtility.arrayList(newValue);
eventNewValue = List.copyOf(newValue);
}
firePropertyChangeImpl(name, eventOldValue, eventNewValue);
return propChanged;
}
return false;
}

public <T> List<T> optimizeList(List<T> newValue) {
if (newValue == null) {
return null;
}
if (newValue.isEmpty()) {
return Collections.emptyList();
}
if (newValue.size() == 1) {
return Collections.singletonList(newValue.getFirst());
}
if (newValue.size() == 2) {
return List.of(newValue.get(0), newValue.get(1));
}
return List.copyOf(newValue);
}

@SuppressWarnings("unchecked")
public <T> List<T> getPropertyList(String name) {
return (List<T>) m_props.get(name);
Expand All @@ -270,6 +289,7 @@ public <T> boolean setPropertySetAlwaysFire(String name, Set<T> newValue) {

private <T> boolean setPropertySet(String name, Set<T> newValue, boolean alwaysFire) {
Object oldValue = m_props.get(name);
newValue = optimizeSet(newValue);
boolean propChanged = setPropertyNoFire(name, newValue);
if (propChanged || alwaysFire) {
Object eventOldValue = null;
Expand All @@ -287,6 +307,23 @@ private <T> boolean setPropertySet(String name, Set<T> newValue, boolean alwaysF
return false;
}

public <T> Set<T> optimizeSet(Set<T> newValue) {
if (newValue == null) {
return null;
}
if (newValue.isEmpty()) {
return Collections.emptySet();
}
if (newValue.size() == 1) {
return Collections.singleton(newValue.iterator().next());
}
if (newValue.size() == 2) {
Iterator<T> it = newValue.iterator();
return Set.of(it.next(), it.next());
}
return Set.copyOf(newValue);
}

@SuppressWarnings("unchecked")
public <T> Set<T> getPropertySet(String name) {
return (Set<T>) m_props.get(name);
Expand Down
Loading