Skip to content

Commit

Permalink
DEV refs #11 : Getting data from a <<bus>> (actually class who get js…
Browse files Browse the repository at this point in the history
…on by a static way); Improving tests; JellyBeans can be readOnly
  • Loading branch information
Nathaël NOGUÈS committed Jul 28, 2016
1 parent 8e3b069 commit 84296b5
Show file tree
Hide file tree
Showing 31 changed files with 508 additions and 349 deletions.
4 changes: 2 additions & 2 deletions avek-gui/sandbox/src/main/java/sandbox/SubjectJsonGen.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import fr.axonic.avek.gui.model.json.Jsonifier;
import fr.axonic.avek.gui.model.sample.ExampleState;
import fr.axonic.avek.gui.model.sample.ExampleStateBool;
import fr.axonic.avek.gui.model.structure.ExperimentationResultsMap;
import fr.axonic.avek.gui.model.structure.ExperimentResultsMap;
import fr.axonic.avek.model.MonitoredSystem;
import fr.axonic.avek.model.base.ADate;
import fr.axonic.avek.model.base.ANumber;
Expand Down Expand Up @@ -62,7 +62,7 @@ private static String generateSubject() {
}

public static String generateParameters() throws VerificationException {
ExperimentationResultsMap expRes = new ExperimentationResultsMap();
ExperimentResultsMap expRes = new ExperimentResultsMap();

{ ARangedEnum<ExampleState> aEnum = new ARangedEnum<>(ExampleState.VERY_LOW);
aEnum.setRange(Arrays.asList(ExampleState.values()));
Expand Down
18 changes: 18 additions & 0 deletions avek-gui/src/main/java/fr/axonic/avek/gui/Main.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package fr.axonic.avek.gui;

import fr.axonic.avek.gui.util.ViewOrchestrator;
import fr.axonic.avek.gui.view.EstablishEffectView;
import fr.axonic.avek.gui.view.GeneralizedView;
import fr.axonic.avek.gui.view.MainFrame;
import fr.axonic.avek.gui.view.TreatView;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.stage.Stage;
Expand Down Expand Up @@ -30,6 +34,20 @@ public void start(Stage primaryStage) throws IOException {

primaryStage.show();
logger.debug("MainFrame created.");

ViewOrchestrator oNull = new ViewOrchestrator(null);
ViewOrchestrator o3 = new ViewOrchestrator(new GeneralizedView());
o3.addFollowing(oNull);
ViewOrchestrator o2 = new ViewOrchestrator(new EstablishEffectView());
o2.addFollowing(o3);
ViewOrchestrator o1 = new ViewOrchestrator(new TreatView());
o1.addFollowing(o2);

oNull.addFollowing(o1);
oNull.addFollowing(o2);
oNull.addFollowing(o3);

mainFrame.setView(oNull);
}

MainFrame getMainFrame() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package fr.axonic.avek.gui.components.filelist;

import fr.axonic.avek.gui.model.structure.UploadedFile;
import fr.axonic.avek.gui.util.ConcurrentTaskManager;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.control.Label;
Expand Down Expand Up @@ -96,22 +95,19 @@ private void onDragExited(DragEvent event) {
}

private void onAddFiles(List<File> list) {
ConcurrentTaskManager ctm = new ConcurrentTaskManager();

for (final File f : list) {
UploadedFile uf = new UploadedFile(f);
try {
// Adding to the list on GUI
uf.doUpload();
ctm.runLaterOnPlatform(() -> fileList.getItems().add(uf));
fileList.getItems().add(uf);
} catch (FileNotFoundException e) {
logger.error("File not found: " + f, e);
} catch (FileAlreadyExistsException e) {
logger.warn("File already added: " + f.getName(), e);
}
}

ctm.waitForTasks();
}

public ListView<UploadedFile> getFileList() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package fr.axonic.avek.gui.components.results;
package fr.axonic.avek.gui.components.jellyBeans;

import fr.axonic.avek.gui.util.ConcurrentTaskManager;
import fr.axonic.avek.model.base.ARangedEnum;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
Expand All @@ -12,6 +12,7 @@
import java.io.IOException;
import java.net.URL;
import java.util.List;
import java.util.function.Consumer;

/**
* Created by Nathaël N on 28/06/16.
Expand All @@ -29,7 +30,7 @@ public class JellyBean extends HBox {

private ARangedEnum enumType;
private Object expEffect;
private JellyBeansSelector mainController;
private Consumer<JellyBean> onDelete;

// should be public
public JellyBean() {
Expand All @@ -51,13 +52,22 @@ public JellyBean() {
logger.debug("Added css for JellyBean");
}

@FXML
public void initialize() {
setOnDelete(null);
}

@FXML
public void onClickOnCross(ActionEvent actionEvent) {
mainController.removeJellyBean(this);
onDelete.accept(this);
}

@FXML
public void onClickOnLabel(ActionEvent actionEvent) {
// ReadOnly
if(onDelete == null)
return;

Object beforeEffect = expEffect;

List list = enumType.getRange();
Expand All @@ -69,12 +79,10 @@ public void onClickOnLabel(ActionEvent actionEvent) {
}

private void refreshColor(Object bef, Object aft) {
ConcurrentTaskManager ctm = new ConcurrentTaskManager();

String before = bef.toString().toLowerCase();
String after = aft.toString().toLowerCase();

ctm.runLaterOnPlatform(() -> {
Platform.runLater(() -> {
jbLabel.getStyleClass().remove(before);
jbCross.getStyleClass().remove(before);
jbLabel.getStyleClass().add(after);
Expand Down Expand Up @@ -103,12 +111,14 @@ public String getText() {
return jbLabel.getText();
}

void setMainController(JellyBeansSelector mainController) {
this.mainController = mainController;
}

@Override
public String toString() {
return "JellyBean=" + getState();
}

void setOnDelete(Consumer<JellyBean> onDelete) {
this.onDelete = onDelete;
jbCross.setVisible(onDelete != null);
jbCross.setManaged(onDelete != null);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package fr.axonic.avek.gui.components.jellyBeans;

import fr.axonic.avek.gui.model.structure.ExperimentResult;
import javafx.scene.Node;
import javafx.scene.layout.FlowPane;

import java.util.function.Consumer;

/**
* Created by Nathaël N on 28/07/16.
*/
public class JellyBeanPane extends FlowPane {

private Consumer<String> onRemoveJellyBean;

public void addJellyBean(ExperimentResult choice) {
JellyBean jb2 = new JellyBean();
jb2.setStateType(choice.getStateClass());
jb2.setText(choice.getName());

if(onRemoveJellyBean != null)
jb2.setOnDelete(this::removeJellyBean);

getChildren().add(jb2);
}

private void removeJellyBean(JellyBean jbc) {
getChildren().remove(jbc);
if(onRemoveJellyBean != null)
onRemoveJellyBean.accept(jbc.getText());
}
void onRemoveJellyBean(Consumer<String> function) {
this.onRemoveJellyBean = function;

for(Node n : getChildren()) {
JellyBean jb = (JellyBean)n;
jb.setOnDelete(function==null?null:this::removeJellyBean);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package fr.axonic.avek.gui.components.results;
package fr.axonic.avek.gui.components.jellyBeans;

import fr.axonic.avek.gui.model.json.Jsonifier;
import fr.axonic.avek.gui.model.structure.ExperimentationResult;
import fr.axonic.avek.gui.model.structure.ExperimentationResultsMap;
import fr.axonic.avek.gui.util.Util;
import fr.axonic.avek.gui.model.structure.ExperimentResult;
import fr.axonic.avek.gui.model.structure.ExperimentResultsMap;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.Event;
import javafx.fxml.FXML;
Expand All @@ -14,7 +11,6 @@
import javafx.scene.control.ComboBox;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.VBox;
import javafx.util.Callback;
import org.apache.log4j.Logger;
Expand All @@ -36,17 +32,16 @@ public class JellyBeansSelector extends VBox {
@FXML
private Button newExpEffectButton;
@FXML
private FlowPane jellyBeansPane;
private JellyBeanPane jellyBeanPane;
@FXML
private ComboBox<ExperimentationResult> comboBoxJellyBean;
private ComboBox<ExperimentResult> comboBoxJellyBean;

private final Set<String> addedEffects;

// should be public
public JellyBeansSelector() {
addedEffects = new HashSet<>();


FXMLLoader fxmlLoader = new FXMLLoader(FXML);
fxmlLoader.setRoot(this);
fxmlLoader.setController(this);
Expand All @@ -61,16 +56,11 @@ public JellyBeansSelector() {

this.getStylesheets().add(CSS);
logger.info("Added css for jellyBeanSelector");


// Fill experiment sample list
String results = Util.getFileContent("files/resultEnum1.json");
ExperimentationResultsMap expr = new Jsonifier<>(ExperimentationResultsMap.class).fromJson(results);
setJellyBeansChoice(FXCollections.observableArrayList(expr.getList()));
}

@FXML
protected void initialize() {
jellyBeanPane.onRemoveJellyBean(this::onRemoveJellyBean);
updateJellyBeanChoice();
}

Expand All @@ -84,18 +74,38 @@ void onNewExpEffectClicked(ActionEvent event) {
newExpEffectButton.setDisable(true);
}

private void addJellyBean() {
// Verify if JellyBean already created (this result is already selected)
ExperimentResult choice = comboBoxJellyBean.getValue();
if (choice == null) {
logger.warn("Choice is null");
return;
}
if (addedEffects.contains(choice.getName())) {
logger.warn("Choice already added: "+choice.getName());
return;
}
jellyBeanPane.addJellyBean(comboBoxJellyBean.getValue());
updateJellyBeanChoice();
addedEffects.add(choice.getName());
}
private void onRemoveJellyBean(String effectName) {
addedEffects.remove(effectName);
updateJellyBeanChoice();
}

/**
* Set Combobox entries for already selected sample to 'selectedResult' style, and others to 'notSelectedResult'
* (typically, set selected sample entries in a grey color, and let the others black)
*/
private void updateJellyBeanChoice() {
comboBoxJellyBean.setCellFactory(
new Callback<ListView<ExperimentationResult>, ListCell<ExperimentationResult>>() {
new Callback<ListView<ExperimentResult>, ListCell<ExperimentResult>>() {
@Override
public ListCell<ExperimentationResult> call(ListView<ExperimentationResult> param) {
return new ListCell<ExperimentationResult>() {
public ListCell<ExperimentResult> call(ListView<ExperimentResult> param) {
return new ListCell<ExperimentResult>() {
@Override
public void updateItem(ExperimentationResult item, boolean empty) {
public void updateItem(ExperimentResult item, boolean empty) {
super.updateItem(item, empty);
if (item != null) {
setText(item.getName());
Expand All @@ -109,33 +119,12 @@ public void updateItem(ExperimentationResult item, boolean empty) {
});
}

private void addJellyBean() {
// Verify if JellyBean already created (this result is already selected)
ExperimentationResult choice = comboBoxJellyBean.getValue();
if (choice == null) {
logger.warn("Choice is null");
return;
} else if (addedEffects.contains(choice.getName())) {
logger.warn("Already selected: " + choice);
return;
}

JellyBean jb2 = new JellyBean();
jb2.setStateType(choice.getStateClass());
jb2.setText(choice.getName());
jb2.setMainController(this);
jellyBeansPane.getChildren().add(jb2);
addedEffects.add(choice.getName());
updateJellyBeanChoice();
}

void removeJellyBean(JellyBean jbc) {
addedEffects.remove(jbc.getText());
jellyBeansPane.getChildren().remove(jbc);
updateJellyBeanChoice();
public void setJellyBeansChoice(ExperimentResultsMap exprMap) {
this.comboBoxJellyBean.setItems(
FXCollections.observableArrayList(exprMap.getList()));
}

void setJellyBeansChoice(ObservableList<ExperimentationResult> items) {
this.comboBoxJellyBean.setItems(items);
public JellyBeanPane getJellyBeanPane() {
return jellyBeanPane;
}
}
36 changes: 36 additions & 0 deletions avek-gui/src/main/java/fr/axonic/avek/gui/model/DataBus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package fr.axonic.avek.gui.model;

import fr.axonic.avek.gui.model.json.Jsonifier;
import fr.axonic.avek.gui.model.structure.ExperimentResultsMap;
import fr.axonic.avek.gui.util.Util;
import fr.axonic.avek.model.MonitoredSystem;
import fr.axonic.avek.model.base.engine.AEntity;
import fr.axonic.avek.model.base.engine.AList;

/**
* Created by Nathaël N on 28/07/16.
*/
public class DataBus {

public static MonitoredSystem getMonitoredSystem() {
String monitoredSystemJson = Util.getFileContent("files/subjectFile.json");
return MonitoredSystem.fromJson(monitoredSystemJson);
}

public static AList<AEntity> getExperimentParameters() {
String experimentParametersJson = Util.getFileContent("files/parametersFile.json");
AList<AEntity> list = Jsonifier.toAListofAListAndAVar(experimentParametersJson);

return list;
}

public static ExperimentResultsMap getExperimentResults() {
String experimentResultsJson = Util.getFileContent("files/resultEnum1.json");

ExperimentResultsMap expResMap =
new Jsonifier<>(ExperimentResultsMap.class)
.fromJson(experimentResultsJson);

return expResMap;
}
}
Loading

0 comments on commit 84296b5

Please sign in to comment.