jfxtras.labs.scene.control.edittable.triple.TripleEditTable Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jfxtras-labs Show documentation
Show all versions of jfxtras-labs Show documentation
Experimental components for JavaFX 2
The newest version!
package jfxtras.labs.scene.control.edittable.triple;
import java.util.List;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;
import jfxtras.labs.internal.scene.control.skin.edittable.triple.TripleEditTableSkin;
import jfxtras.labs.scene.control.edittable.EditTable;
// TODO - make control instead of HBox?
public abstract class TripleEditTable extends EditTable
{
// initialize tableList with extractor so change listeners fire when properties change.
static private String language = "en";
static private Locale myLocale = new Locale(language);
static private ResourceBundle defaultResources = ResourceBundle.getBundle("jfxtras.labs.scene.control.triple.Bundle", myLocale);
protected final ResourceBundle resources;
protected List> tripleList;
@Override
public void setBeanList(List beanList)
{
super.setBeanList(beanList);
tripleList = beanList.stream()
.map(e -> converter.fromBeanElement(e))
.collect(Collectors.toList());
TripleEditTableSkin tripleEditTableSkin = (TripleEditTableSkin) getSkin();
System.out.println("tripleEditTableSkin:" + tripleEditTableSkin);
if (tripleEditTableSkin != null)
{
ObservableList> tableList = tripleEditTableSkin.getTableList();
tableList.clear();
System.out.println("clear tableList:"+tableList.size() + " " + tripleList);
tableList.addAll(tripleList);
if (tableList.isEmpty())
{
tableList.add(new Triple());
}
}
}
private final Predicate validateValue;
private final String[] alertTexts;
private final String[] nameOptions;
private TripleConverter converter;
protected ListChangeListener> synchBeanItemTripleChangeLister = (ListChangeListener.Change extends Triple> change) ->
{
while (change.next())
{
if (change.wasUpdated())
{
int to = change.getTo();
int from = change.getFrom();
for (int i=from; i t = change.getList().get(i);
// Only save bean item if value isn't null
if (t.getValue() != null)
{
T e = converter.toBeanElement(t);
System.out.println("i:" + i + " " + getBeanList().size());
if (i <= getBeanList().size()-1)
{
System.out.println("changed existing element");
getBeanList().set(i, e);
} else
{
getBeanList().add(e);
System.out.println("new element added");
}
}
}
}
}
};
// CONSTRUCTOR
public TripleEditTable(
Predicate validateValue,
TripleConverter converter,
String[] alertTexts,
String[] nameOptions,
ResourceBundle resources
)
{
super();
this.validateValue = validateValue;
this.converter = converter;
this.alertTexts = alertTexts;
this.nameOptions = nameOptions;
this.resources = (resources == null) ? defaultResources : resources;
}
}