Skip to content
This repository has been archived by the owner on Jun 11, 2023. It is now read-only.

Commit

Permalink
#57 [api] Extend FXMLController 'configure' feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
Naoghuman committed Mar 10, 2019
1 parent f9d9aab commit 9c7755c
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 7 deletions.
2 changes: 2 additions & 0 deletions release/Release_v0.3.0-PRERELEASE_2019-03-dd_HH-mm.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ and connect them to a controller (called the presenter).
#### Enhancement
#60 [api] Extend FXMLModel with new method 'registerOnAction(String, Consumer'T').
#58 [api] Extend FXMLModel with metadata.
#57 [api] Extend FXMLController 'configure' feature.
#55 [api] Add new method getController(Class'T') to FXMLView.
#50 [api] Enhance FXMLModel.get(Class'T', String) to return an Optional'T'.
#48 [test] Enhance the method DefaultFXMLValidator.requireEndsWith(...).
Expand Down Expand Up @@ -58,6 +59,7 @@ Naoghuman


[//]: # (Issues which will be integrated in this release)
#52 [test] Add new demo 'DemoAllInOnes'.



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
*/
package com.github.naoghuman.lib.fxml.core;

import com.github.naoghuman.lib.fxml.internal.DefaultFXMLValidator;
import java.util.List;
import java.util.Optional;
import javafx.collections.FXCollections;
import javafx.scene.Parent;

/**
Expand All @@ -27,30 +30,71 @@
*/
public abstract class FXMLController {

private Optional<FXMLModel> fxmlModel = Optional.empty();
private final List<FXMLModel> models = FXCollections.observableArrayList();

/**
*
* @since 0.3.0-PRERELEASE
* @version 0.3.0-PRERELEASE
* @author Naoghuman
*/
public void clear() {
this.getModels().clear();
}

/**
*
* @param model
* @since 0.1.0-PRERELEASE
* @version 0.2.0-PRERELEASE
* @version 0.3.0-PRERELEASE
* @author Naoghuman
*/
public void configure(final FXMLModel model) {
fxmlModel = Optional.ofNullable(model);
DefaultFXMLValidator.requireNonNull(model);

this.getModels().add(model);
}

public void configure(final List<FXMLModel> models) {
DefaultFXMLValidator.requireNonNull(models);

this.getModels().addAll(models);
}

/**
*
* @param entityType
* @param entityId
* @return
* @since 0.1.0-PRERELEASE
* @version 0.2.0-PRERELEASE
* @author Naoghuman
*/
public Optional<FXMLModel> getModel() {
public Optional<FXMLModel> getModel(final Class entityType, final Long entityId) {
DefaultFXMLValidator.requireNonNull(entityType);
DefaultFXMLValidator.requireNonNull(entityId);

final Optional<FXMLModel> fxmlModel = models.stream()
.filter(model ->
model.isSameEntityType(entityType)
&& model.isSameEntityId(entityId)
)
.findFirst();

return fxmlModel;
}

/**
*
* @return
* @since 0.3.0-PRERELEASE
* @version 0.3.0-PRERELEASE
* @author Naoghuman
*/
public List<FXMLModel> getModels() {
return models;
}

/**
*
* @return
Expand Down
25 changes: 22 additions & 3 deletions src/main/java/com/github/naoghuman/lib/fxml/core/FXMLModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;

/**
Expand Down Expand Up @@ -62,6 +63,24 @@ public void clear() {
model.clear();
}

/**
*
* @param entityId
* @return
* @since 0.3.0-PRERELEASE
* @version 0.3.0-PRERELEASE
* @author Naoghuman
*/
public boolean isSameEntityId(final Long entityId) {
DefaultFXMLValidator.requireNonNull(entityId);

if (!this.getEntityId().isPresent()) {
return Boolean.FALSE;
}

return Objects.equals(this.getEntityId().get(), entityId);
}

/**
*
* @param type
Expand All @@ -70,14 +89,14 @@ public void clear() {
* @version 0.3.0-PRERELEASE
* @author Naoghuman
*/
public boolean isEntityFromType(final Class type) {
public boolean isSameEntityType(final Class type) {
DefaultFXMLValidator.requireNonNull(type);

if (!entity.isPresent()) {
if (!this.getEntity().isPresent()) {
return Boolean.FALSE;
}

return entity.get().getName().equals(type.getName());
return getEntity().get().getName().equals(type.getName());
}

/**
Expand Down

0 comments on commit 9c7755c

Please sign in to comment.