Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
181 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 0 additions & 39 deletions
39
core/src/main/java/com/dooapp/fxform/view/control/map/MapElementBinding.java
This file was deleted.
Oops, something went wrong.
73 changes: 73 additions & 0 deletions
73
core/src/main/java/com/dooapp/fxform/view/control/map/MapElementProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.dooapp.fxform.view.control.map; | ||
|
||
import com.dooapp.fxform.model.Element; | ||
import javafx.beans.property.ListProperty; | ||
import javafx.beans.property.MapProperty; | ||
import javafx.beans.property.ReadOnlyListProperty; | ||
import javafx.beans.property.SimpleListProperty; | ||
import javafx.collections.FXCollections; | ||
import javafx.collections.MapChangeListener; | ||
import javafx.collections.ObservableList; | ||
|
||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* User: Antoine Mischler <antoine@dooapp.com> | ||
* Date: 24/04/15 | ||
* Time: 14:52 | ||
*/ | ||
public class MapElementProvider<K, V> { | ||
|
||
private final ListProperty<Element<V>> elements = new SimpleListProperty<>(FXCollections.observableArrayList()); | ||
|
||
private final MapProperty<K, V> map; | ||
|
||
private final Class<V> valueType; | ||
private final MapChangeListener<K, V> mapChangeListener; | ||
|
||
public MapElementProvider(MapProperty<K, V> map, Class<V> valueType) { | ||
this.map = map; | ||
this.valueType = valueType; | ||
mapChangeListener = change -> { | ||
if (change.wasAdded()) { | ||
if (getElementByKey(change.getKey()) == null) { | ||
elements.add(new MapEntryPropertyElement(map, change.getKey(), valueType)); | ||
} | ||
} else if (change.wasRemoved()) { | ||
elements.remove(getElementByKey(change.getKey())); | ||
} | ||
}; | ||
map.addListener(mapChangeListener); | ||
init(); | ||
} | ||
|
||
private Element getElementByKey(K key) { | ||
Element toRemove = null; | ||
for (Element element : elements) { | ||
if (((MapEntryElement) element).getKey().equals(key)) { | ||
toRemove = element; | ||
break; | ||
} | ||
} | ||
return toRemove; | ||
} | ||
|
||
protected void init() { | ||
elements.addAll(map.keySet().stream() | ||
.map(key -> new MapEntryPropertyElement<>(map, key, valueType)) | ||
.collect(Collectors.toList())); | ||
} | ||
|
||
public ObservableList<Element<V>> getElements() { | ||
return elements.get(); | ||
} | ||
|
||
public ReadOnlyListProperty<Element<V>> elementsProperty() { | ||
return elements; | ||
} | ||
|
||
public void dispose() { | ||
map.removeListener(mapChangeListener); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,7 +54,7 @@ public Node getNode() { | |
|
||
@Override | ||
public void dispose() { | ||
|
||
mapEditorControl.dispose(); | ||
} | ||
}; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters