Skip to content

Commit

Permalink
Begin changing from map to set in observable config
Browse files Browse the repository at this point in the history
  • Loading branch information
Emil Forslund committed Nov 21, 2015
1 parent fa87666 commit 348f578
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
Expand Up @@ -27,7 +27,6 @@
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import static java.util.Objects.requireNonNull;
import java.util.Optional; import java.util.Optional;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Stream; import java.util.stream.Stream;
Expand Down
Expand Up @@ -27,9 +27,10 @@
import static java.util.Objects.requireNonNull; import static java.util.Objects.requireNonNull;
import java.util.function.BiFunction; import java.util.function.BiFunction;
import java.util.function.Function; import java.util.function.Function;
import static java.util.stream.Collectors.toSet;
import java.util.stream.Stream; import java.util.stream.Stream;
import static javafx.collections.FXCollections.observableMap; import static javafx.collections.FXCollections.observableMap;
import javafx.collections.ObservableMap; import javafx.collections.ObservableSet;


/** /**
* *
Expand All @@ -51,6 +52,12 @@ public AbstractParentProperty(Speedment speedment, THIS prototype) {
public final ChildHolder<CHILD> getChildren() { public final ChildHolder<CHILD> getChildren() {
throw new UnsupportedOperationException("This method should not be used."); throw new UnsupportedOperationException("This method should not be used.");
} }

public final CHILD prepare(CHILD child) {
child.setParent(this);
child.setName(child.getInterfaceMainClass().getSimpleName() + "_" + child.hashCode());
return child;
}


@Override @Override
public Stream<Node> traverse() { public Stream<Node> traverse() {
Expand Down Expand Up @@ -88,15 +95,15 @@ protected IllegalArgumentException noChildWithNameException(Class<?> childType,
); );
} }


protected <CHILD extends Child<?>, THIS extends Node & Parent<? super CHILD>> ObservableMap<String, CHILD> copyChildrenFrom(THIS prototype, Class<CHILD> childType, BiFunction<Speedment, CHILD, CHILD> wrapper) { protected <CHILD extends Child<?>, THIS extends Node & Parent<? super CHILD>> ObservableSet<CHILD> copyChildrenFrom(THIS prototype, Class<CHILD> childType, BiFunction<Speedment, CHILD, CHILD> wrapper) {
return observableMap(MapStream return observableSet(
.fromValues(prototype.streamOf(childType), Node::getName) prototype.streamOf(childType)
.mapValue(child -> { .map(child -> {
final CHILD newChild = wrapper.apply(getSpeedment(), child); final CHILD newChild = wrapper.apply(getSpeedment(), child);
newChild.setParent(this); newChild.setParent(this);
return newChild; return newChild;
}) })
.toConcurrentNavigableMap() .collect(toSet())
); );
} }
} }
Expand Up @@ -26,6 +26,7 @@
import com.speedment.internal.core.config.utils.ConfigUtil; import com.speedment.internal.core.config.utils.ConfigUtil;
import com.speedment.stream.MapStream; import com.speedment.stream.MapStream;
import groovy.lang.Closure; import groovy.lang.Closure;
import static java.util.Collections.newSetFromMap;
import static java.util.Objects.requireNonNull; import static java.util.Objects.requireNonNull;
import java.util.Optional; import java.util.Optional;
import java.util.concurrent.ConcurrentSkipListMap; import java.util.concurrent.ConcurrentSkipListMap;
Expand All @@ -37,15 +38,15 @@
import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty; import javafx.beans.property.StringProperty;
import static javafx.collections.FXCollections.observableMap; import static javafx.collections.FXCollections.observableMap;
import javafx.collections.ObservableMap; import javafx.collections.ObservableSet;


/** /**
* *
* @author Emil Forslund * @author Emil Forslund
*/ */
public final class DbmsProperty extends AbstractParentProperty<Dbms, Schema> implements Dbms, ChildHelper<Dbms, Project> { public final class DbmsProperty extends AbstractParentProperty<Dbms, Schema> implements Dbms, ChildHelper<Dbms, Project> {


private final ObservableMap<String, Schema> schemaChildren; private final ObservableSet<Schema> schemaChildren;
private final StringProperty ipAddress; private final StringProperty ipAddress;
private final IntegerProperty port; private final IntegerProperty port;
private final StringProperty username; private final StringProperty username;
Expand All @@ -57,7 +58,7 @@ public final class DbmsProperty extends AbstractParentProperty<Dbms, Schema> imp


public DbmsProperty(Speedment speedment) { public DbmsProperty(Speedment speedment) {
super(speedment); super(speedment);
schemaChildren = observableMap(new ConcurrentSkipListMap<>()); schemaChildren = observableMap(newSetFromMap(new ConcurrentSkipListMap<>()));
ipAddress = new SimpleStringProperty(); ipAddress = new SimpleStringProperty();
port = new SimpleIntegerProperty(); port = new SimpleIntegerProperty();
username = new SimpleStringProperty(); username = new SimpleStringProperty();
Expand Down
Expand Up @@ -18,18 +18,21 @@


import com.speedment.Speedment; import com.speedment.Speedment;
import com.speedment.internal.gui.config.ProjectProperty; import com.speedment.internal.gui.config.ProjectProperty;
import java.io.File;
import javafx.event.EventHandler; import javafx.event.EventHandler;
import javafx.stage.Stage; import javafx.stage.Stage;
import static java.util.Objects.requireNonNull;
import javafx.application.Application; import javafx.application.Application;
import javafx.event.Event; import javafx.event.Event;
import static java.util.Objects.requireNonNull;


/** /**
* *
* @author Emil Forslund * @author Emil Forslund
*/ */
public final class UISession { public final class UISession {


public final static File DEFAULT_GROOVY_LOCATION = new File("src/main/groovy/speedment.groovy");

private final Speedment speedment; private final Speedment speedment;
private final Application application; private final Application application;
private final Stage stage; private final Stage stage;
Expand Down

0 comments on commit 348f578

Please sign in to comment.