Skip to content

Commit

Permalink
gs-reactor: Make gscomponents2 compile
Browse files Browse the repository at this point in the history
It compiles, but edition/creation of links with comboboxes does not work anymore
with this version of the components.
  • Loading branch information
fducroquet committed Nov 11, 2016
1 parent 671b8fa commit fb7bea3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
Expand Up @@ -6,6 +6,7 @@

import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.genericsystem.api.core.ApiStatics;
Expand Down Expand Up @@ -287,11 +288,12 @@ public static class DirectRelationComponentEditor extends InstanceEditorCombobox

@Override
public void init() {
addPostfixBinding(model -> {
Property<List<Property<Context>>> selectedComponents = getComponentsProperty(model);
if (selectedComponents != null)
selectedComponents.getValue().add(getSelectionProperty(model));
});
// TODO: Use datalist to make it work.
// addPostfixBinding(model -> {
// Property<List<Property<Context>>> selectedComponents = getComponentsProperty(model);
// if (selectedComponents != null)
// selectedComponents.getValue().add(getSelectionProperty(model));
// });
}
}

Expand Down Expand Up @@ -391,19 +393,19 @@ public static class LinkAdder extends FlexDiv implements ComponentsDefaults {
public void init() {
createComponentsListProperty();
addPostfixBinding(model -> {
Property<List<Property<Context>>> selectedComponents = getComponentsProperty(model);
ChangeListener<Context> listener = (o, v, nva) -> {
List<Generic> selectedGenerics = selectedComponents.getValue().stream().filter(obs -> obs.getValue() != null).map(obs -> obs.getValue().getGeneric()).filter(gen -> gen != null).collect(Collectors.toList());
if (selectedGenerics.size() + 1 == model.getGeneric().getComponents().size()) {
selectedComponents.getValue().stream().forEach(sel -> sel.setValue(null));
Property<Map<Generic, Property<Serializable>>> selectedComponents = getComponentsProperty(model);
ChangeListener<Serializable> listener = (o, v, nva) -> {
Generic[] selectedGenerics = selectedComponents.getValue().entrySet().stream().filter(obs -> obs.getValue() != null).map(entry -> entry.getKey().getInstance(entry.getValue().getValue())).filter(gen -> gen != null).toArray(Generic[]::new);
if (selectedGenerics.length + 1 == model.getGeneric().getComponents().size()) {
selectedComponents.getValue().values().stream().forEach(sel -> sel.setValue(null));
try {
model.getGenerics()[1].setHolder(model.getGeneric(), null, selectedGenerics.stream().toArray(Generic[]::new));
model.getGenerics()[1].setHolder(model.getGeneric(), null, selectedGenerics);
} catch (RollbackException e) {
e.printStackTrace();
}
}
};
selectedComponents.getValue().forEach(component -> component.addListener(listener));
selectedComponents.getValue().values().forEach(component -> component.addListener(listener));
});
}

Expand All @@ -419,11 +421,11 @@ public static class ComponentAdderSelect extends ComboboxWithEmptyEntry {

@Override
public void init() {
addPostfixBinding(model -> {
Property<List<Property<Context>>> selectedComponents = getComponentsProperty(model);
if (selectedComponents != null)
selectedComponents.getValue().add(getSelectionProperty(model));
});
// addPostfixBinding(model -> {
// Property<Map<Generic, ObservableValue<Serializable>>> selectedComponents = getComponentsProperty(model);
// if (selectedComponents != null)
// selectedComponents.getValue().put(model.getGeneric(), getSelectionString(model));
// });
}
}
}
Expand Down
Expand Up @@ -148,11 +148,11 @@ public void init() {
ConvertedValueDefaults input = getParent().getParent().find(InstanceNameBuilder.class).find(InstanceNameBuilderInput.class);
Generic newInstance = context.getGeneric().setInstance(input.getConvertedValueProperty(context).getValue());
for (Entry<Generic, GenericValueComponents> entry : getGenericValueComponents(context).getValue().entrySet()) {
List<Generic> selectedGenerics = entry.getValue().getComponents().stream().filter(obs -> obs.getValue() != null).map(obs -> obs.getValue().getGeneric()).filter(gen -> gen != null).collect(Collectors.toList());
if (!selectedGenerics.isEmpty() && selectedGenerics.size() + 1 == entry.getKey().getComponents().size())
newInstance.setHolder(entry.getKey(), entry.getValue().getGenericValue().getValue(), selectedGenerics.stream().toArray(Generic[]::new));
Generic[] selectedGenerics = entry.getValue().getComponents().entrySet().stream().filter(entry_ -> entry_.getValue() != null && entry_.getValue().getValue() != null).map(entry_ -> entry_.getKey().setInstance(entry_.getValue().getValue())).filter(gen -> gen != null).toArray(Generic[]::new);
if ((entry.getValue().getGenericValue().getValue() != null || selectedGenerics.length != 0) && selectedGenerics.length + 1 == entry.getKey().getComponents().size())
newInstance.setHolder(entry.getKey(), entry.getValue().getGenericValue().getValue(), selectedGenerics);
entry.getValue().getGenericValue().setValue(null);
entry.getValue().getComponents().stream().forEach(sel -> sel.setValue(null));
entry.getValue().getComponents().values().stream().forEach(sel -> sel.setValue(null));
}
input.getConvertedValueProperty(context).setValue(null);
});
Expand Down

0 comments on commit fb7bea3

Please sign in to comment.