diff --git a/avek-gui/sandbox/src/main/java/sandbox/SubjectJsonGen.java b/avek-gui/sandbox/src/main/java/sandbox/SubjectJsonGen.java index 0ea65da..1a69873 100644 --- a/avek-gui/sandbox/src/main/java/sandbox/SubjectJsonGen.java +++ b/avek-gui/sandbox/src/main/java/sandbox/SubjectJsonGen.java @@ -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; @@ -62,7 +62,7 @@ private static String generateSubject() { } public static String generateParameters() throws VerificationException { - ExperimentationResultsMap expRes = new ExperimentationResultsMap(); + ExperimentResultsMap expRes = new ExperimentResultsMap(); { ARangedEnum aEnum = new ARangedEnum<>(ExampleState.VERY_LOW); aEnum.setRange(Arrays.asList(ExampleState.values())); diff --git a/avek-gui/src/main/java/fr/axonic/avek/gui/Main.java b/avek-gui/src/main/java/fr/axonic/avek/gui/Main.java index d5cf03e..4047607 100644 --- a/avek-gui/src/main/java/fr/axonic/avek/gui/Main.java +++ b/avek-gui/src/main/java/fr/axonic/avek/gui/Main.java @@ -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; @@ -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() { diff --git a/avek-gui/src/main/java/fr/axonic/avek/gui/components/filelist/FileListView.java b/avek-gui/src/main/java/fr/axonic/avek/gui/components/filelist/FileListView.java index 521236a..d821ef4 100644 --- a/avek-gui/src/main/java/fr/axonic/avek/gui/components/filelist/FileListView.java +++ b/avek-gui/src/main/java/fr/axonic/avek/gui/components/filelist/FileListView.java @@ -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; @@ -96,14 +95,12 @@ private void onDragExited(DragEvent event) { } private void onAddFiles(List 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) { @@ -111,7 +108,6 @@ private void onAddFiles(List list) { } } - ctm.waitForTasks(); } public ListView getFileList() { diff --git a/avek-gui/src/main/java/fr/axonic/avek/gui/components/results/JellyBean.java b/avek-gui/src/main/java/fr/axonic/avek/gui/components/jellyBeans/JellyBean.java similarity index 83% rename from avek-gui/src/main/java/fr/axonic/avek/gui/components/results/JellyBean.java rename to avek-gui/src/main/java/fr/axonic/avek/gui/components/jellyBeans/JellyBean.java index 7ef41a3..e3f5c85 100644 --- a/avek-gui/src/main/java/fr/axonic/avek/gui/components/results/JellyBean.java +++ b/avek-gui/src/main/java/fr/axonic/avek/gui/components/jellyBeans/JellyBean.java @@ -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; @@ -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. @@ -29,7 +30,7 @@ public class JellyBean extends HBox { private ARangedEnum enumType; private Object expEffect; - private JellyBeansSelector mainController; + private Consumer onDelete; // should be public public JellyBean() { @@ -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(); @@ -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); @@ -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 onDelete) { + this.onDelete = onDelete; + jbCross.setVisible(onDelete != null); + jbCross.setManaged(onDelete != null); + } } diff --git a/avek-gui/src/main/java/fr/axonic/avek/gui/components/jellyBeans/JellyBeanPane.java b/avek-gui/src/main/java/fr/axonic/avek/gui/components/jellyBeans/JellyBeanPane.java new file mode 100644 index 0000000..31ffeed --- /dev/null +++ b/avek-gui/src/main/java/fr/axonic/avek/gui/components/jellyBeans/JellyBeanPane.java @@ -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 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 function) { + this.onRemoveJellyBean = function; + + for(Node n : getChildren()) { + JellyBean jb = (JellyBean)n; + jb.setOnDelete(function==null?null:this::removeJellyBean); + } + } +} diff --git a/avek-gui/src/main/java/fr/axonic/avek/gui/components/results/JellyBeansSelector.java b/avek-gui/src/main/java/fr/axonic/avek/gui/components/jellyBeans/JellyBeansSelector.java similarity index 62% rename from avek-gui/src/main/java/fr/axonic/avek/gui/components/results/JellyBeansSelector.java rename to avek-gui/src/main/java/fr/axonic/avek/gui/components/jellyBeans/JellyBeansSelector.java index 0903965..0a6acc4 100644 --- a/avek-gui/src/main/java/fr/axonic/avek/gui/components/results/JellyBeansSelector.java +++ b/avek-gui/src/main/java/fr/axonic/avek/gui/components/jellyBeans/JellyBeansSelector.java @@ -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; @@ -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; @@ -36,9 +32,9 @@ public class JellyBeansSelector extends VBox { @FXML private Button newExpEffectButton; @FXML - private FlowPane jellyBeansPane; + private JellyBeanPane jellyBeanPane; @FXML - private ComboBox comboBoxJellyBean; + private ComboBox comboBoxJellyBean; private final Set addedEffects; @@ -46,7 +42,6 @@ public class JellyBeansSelector extends VBox { public JellyBeansSelector() { addedEffects = new HashSet<>(); - FXMLLoader fxmlLoader = new FXMLLoader(FXML); fxmlLoader.setRoot(this); fxmlLoader.setController(this); @@ -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(); } @@ -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, ListCell>() { + new Callback, ListCell>() { @Override - public ListCell call(ListView param) { - return new ListCell() { + public ListCell call(ListView param) { + return new ListCell() { @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()); @@ -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 items) { - this.comboBoxJellyBean.setItems(items); + public JellyBeanPane getJellyBeanPane() { + return jellyBeanPane; } } diff --git a/avek-gui/src/main/java/fr/axonic/avek/gui/model/DataBus.java b/avek-gui/src/main/java/fr/axonic/avek/gui/model/DataBus.java new file mode 100644 index 0000000..ac73933 --- /dev/null +++ b/avek-gui/src/main/java/fr/axonic/avek/gui/model/DataBus.java @@ -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 getExperimentParameters() { + String experimentParametersJson = Util.getFileContent("files/parametersFile.json"); + AList 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; + } +} diff --git a/avek-gui/src/main/java/fr/axonic/avek/gui/model/structure/ExperimentationResult.java b/avek-gui/src/main/java/fr/axonic/avek/gui/model/structure/ExperimentResult.java similarity index 80% rename from avek-gui/src/main/java/fr/axonic/avek/gui/model/structure/ExperimentationResult.java rename to avek-gui/src/main/java/fr/axonic/avek/gui/model/structure/ExperimentResult.java index 872edc3..8851095 100644 --- a/avek-gui/src/main/java/fr/axonic/avek/gui/model/structure/ExperimentationResult.java +++ b/avek-gui/src/main/java/fr/axonic/avek/gui/model/structure/ExperimentResult.java @@ -5,11 +5,11 @@ /** * Created by Nathaël N on 07/07/16. */ -public class ExperimentationResult { +public class ExperimentResult { private final ARangedEnum states; private final String name; - public ExperimentationResult(String name, ARangedEnum states) { + public ExperimentResult(String name, ARangedEnum states) { this.states = states; this.name = name; } diff --git a/avek-gui/src/main/java/fr/axonic/avek/gui/model/structure/ExperimentationResultsMap.java b/avek-gui/src/main/java/fr/axonic/avek/gui/model/structure/ExperimentResultsMap.java similarity index 59% rename from avek-gui/src/main/java/fr/axonic/avek/gui/model/structure/ExperimentationResultsMap.java rename to avek-gui/src/main/java/fr/axonic/avek/gui/model/structure/ExperimentResultsMap.java index 86d7f2f..9e87285 100644 --- a/avek-gui/src/main/java/fr/axonic/avek/gui/model/structure/ExperimentationResultsMap.java +++ b/avek-gui/src/main/java/fr/axonic/avek/gui/model/structure/ExperimentResultsMap.java @@ -3,17 +3,18 @@ import fr.axonic.avek.model.base.ARangedEnum; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.List; import java.util.stream.Collectors; /** * Created by Nathaël N on 12/07/16. */ -public class ExperimentationResultsMap extends HashMap { +public class ExperimentResultsMap extends LinkedHashMap { - public List getList() { + public List getList() { return keySet().stream() - .map(s -> new ExperimentationResult(s, get(s))) + .map(s -> new ExperimentResult(s, get(s))) .collect(Collectors.toList()); } } diff --git a/avek-gui/src/main/java/fr/axonic/avek/gui/model/structure/UploadedFile.java b/avek-gui/src/main/java/fr/axonic/avek/gui/model/structure/UploadedFile.java index 9e17de3..eb48c6b 100644 --- a/avek-gui/src/main/java/fr/axonic/avek/gui/model/structure/UploadedFile.java +++ b/avek-gui/src/main/java/fr/axonic/avek/gui/model/structure/UploadedFile.java @@ -1,6 +1,5 @@ package fr.axonic.avek.gui.model.structure; -import fr.axonic.avek.gui.util.ConcurrentTaskManager; import javafx.application.Platform; import org.apache.log4j.Logger; @@ -46,7 +45,7 @@ public void doUpload() throws FileAlreadyExistsException, FileNotFoundException if(uploading) throw new RuntimeException("Upload already started"); - new ConcurrentTaskManager().runLaterOnThread(this::doUploadMultiFiles); + new Thread(this::doUploadMultiFiles).start(); } private boolean uploading = false; @@ -83,7 +82,7 @@ private void doUploadMultiFiles() { uploadedBytes = getSize(); if (listener != null) - new ConcurrentTaskManager().runLaterOnPlatform(listener::run); + Platform.runLater(listener::run); uploading = false; } @@ -170,10 +169,7 @@ public void removeListener() { } public void setUpdateListener(Runnable listener) { - ConcurrentTaskManager ctm = new ConcurrentTaskManager(); - this.listener = listener; - - ctm.runLaterOnPlatform(listener); + Platform.runLater(listener); } } diff --git a/avek-gui/src/main/java/fr/axonic/avek/gui/util/ViewOrchestrator.java b/avek-gui/src/main/java/fr/axonic/avek/gui/util/ViewOrchestrator.java new file mode 100644 index 0000000..be38977 --- /dev/null +++ b/avek-gui/src/main/java/fr/axonic/avek/gui/util/ViewOrchestrator.java @@ -0,0 +1,35 @@ +package fr.axonic.avek.gui.util; + +import fr.axonic.avek.gui.view.AbstractView; + +import java.util.LinkedList; +import java.util.List; + +/** + * Created by Nathaël N on 27/07/16. + */ +public class ViewOrchestrator { + private AbstractView currentView; + private List following; + + public ViewOrchestrator(AbstractView view) { + this.currentView = view; + following = new LinkedList<>(); + } + + public void addFollowing(ViewOrchestrator follow) { + following.add(follow); + } + public List getFollowing() { + return following; + } + + @Override + public String toString() { + return currentView.getClass().getSimpleName(); + } + + public AbstractView getView() { + return currentView; + } +} diff --git a/avek-gui/src/main/java/fr/axonic/avek/gui/view/EstablishEffectView.java b/avek-gui/src/main/java/fr/axonic/avek/gui/view/EstablishEffectView.java index 48e6c39..860bdff 100644 --- a/avek-gui/src/main/java/fr/axonic/avek/gui/view/EstablishEffectView.java +++ b/avek-gui/src/main/java/fr/axonic/avek/gui/view/EstablishEffectView.java @@ -1,10 +1,9 @@ package fr.axonic.avek.gui.view; import fr.axonic.avek.gui.components.MonitoredSystemPane; +import fr.axonic.avek.gui.components.jellyBeans.JellyBeansSelector; import fr.axonic.avek.gui.components.parameters.ParametersPane; -import fr.axonic.avek.gui.components.results.JellyBeansSelector; -import fr.axonic.avek.gui.model.json.Jsonifier; -import fr.axonic.avek.model.MonitoredSystem; +import fr.axonic.avek.gui.model.DataBus; import fr.axonic.avek.model.base.engine.AEntity; import fr.axonic.avek.model.base.engine.AList; import javafx.event.ActionEvent; @@ -29,6 +28,18 @@ public class EstablishEffectView extends AbstractView { protected void onLoad() { logger.info("Loading TreatView..."); super.load(FXML); + + logger.info("Getting monitored system..."); + monitoredSystemPane.setMonitoredSystem(DataBus.getMonitoredSystem()); + + logger.info("Getting experiment parameters..."); + AList list = DataBus.getExperimentParameters(); + for (AEntity ae : list.getEntities()) + paneParameters.addExpParameter(ae); + + logger.info("Getting experiment results..."); + jellyBeansSelector.setJellyBeansChoice(DataBus.getExperimentResults()); + logger.debug("TreatView loaded."); } @@ -36,20 +47,5 @@ protected void onLoad() { void onClicStrategyButton(ActionEvent event) { btnStrategy.setDisable(true); } - - /** Fill experiment monitoredSystemPane informations - * - * @param monitoredSystemJson the MonitoredSystem as a Json String - */ - public void setMonitoredSystem(String monitoredSystemJson) { - monitoredSystemPane.setMonitoredSystem(MonitoredSystem.fromJson(monitoredSystemJson)); - } - - public void setExperimentParameters(String experimentParametersJson) { - AList list = Jsonifier.toAListofAListAndAVar(experimentParametersJson); - - for (AEntity ae : list.getEntities()) - paneParameters.addExpParameter(ae); - } } diff --git a/avek-gui/src/main/java/fr/axonic/avek/gui/view/GeneralizedView.java b/avek-gui/src/main/java/fr/axonic/avek/gui/view/GeneralizedView.java index 0d9155c..0697bd9 100644 --- a/avek-gui/src/main/java/fr/axonic/avek/gui/view/GeneralizedView.java +++ b/avek-gui/src/main/java/fr/axonic/avek/gui/view/GeneralizedView.java @@ -1,10 +1,11 @@ package fr.axonic.avek.gui.view; import fr.axonic.avek.gui.components.MonitoredSystemPane; +import fr.axonic.avek.gui.components.jellyBeans.JellyBeanPane; import fr.axonic.avek.gui.components.parameters.GeneralizedParametersPane; -import fr.axonic.avek.gui.components.results.JellyBeansSelector; -import fr.axonic.avek.gui.model.json.Jsonifier; -import fr.axonic.avek.model.MonitoredSystem; +import fr.axonic.avek.gui.model.DataBus; +import fr.axonic.avek.gui.model.structure.ExperimentResult; +import fr.axonic.avek.gui.model.structure.ExperimentResultsMap; import fr.axonic.avek.model.base.engine.AEntity; import fr.axonic.avek.model.base.engine.AList; import javafx.event.ActionEvent; @@ -23,12 +24,28 @@ public class GeneralizedView extends AbstractView { @FXML private MonitoredSystemPane monitoredSystemPane; @FXML - private JellyBeansSelector jellyBeansSelector; + private JellyBeanPane jellyBeanPane; @Override protected void onLoad() { logger.info("Loading GeneralizedView..."); super.load(FXML); + + logger.info("Getting monitored system..."); + monitoredSystemPane.setMonitoredSystem(DataBus.getMonitoredSystem()); + + logger.info("Getting experiment parameters..."); + AList list = DataBus.getExperimentParameters(); + for (AEntity ae : list.getEntities()) + paneParameters.addExpParameter(ae); + + logger.info("Getting experiment results..."); + ExperimentResultsMap expResMap = + DataBus.getExperimentResults(); + + for(ExperimentResult expRes : expResMap.getList()) + jellyBeanPane.addJellyBean(expRes); + logger.debug("GeneralizedView loaded."); } @@ -37,22 +54,5 @@ void onClicStrategyButton(ActionEvent event) { btnStrategy.setDisable(true); } - /** Fill experiment monitoredSystemPane informations - * - * @param monitoredSystemJson the MonitoredSystem as a Json String - */ - public void setMonitoredSystem(String monitoredSystemJson) { - MonitoredSystem ms = MonitoredSystem.fromJson(monitoredSystemJson); - - monitoredSystemPane.setMonitoredSystem(ms); - } - - - public void setExperimentParameters(String experimentParametersJson) { - AList list = Jsonifier.toAListofAListAndAVar(experimentParametersJson); - - for (AEntity ae : list.getEntities()) - paneParameters.addExpParameter(ae); - } } diff --git a/avek-gui/src/main/java/fr/axonic/avek/gui/view/MainFrame.java b/avek-gui/src/main/java/fr/axonic/avek/gui/view/MainFrame.java index acdd1ce..8483a55 100644 --- a/avek-gui/src/main/java/fr/axonic/avek/gui/view/MainFrame.java +++ b/avek-gui/src/main/java/fr/axonic/avek/gui/view/MainFrame.java @@ -1,5 +1,6 @@ package fr.axonic.avek.gui.view; +import fr.axonic.avek.gui.util.ViewOrchestrator; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; @@ -9,6 +10,7 @@ import java.io.IOException; import java.net.URL; +import java.util.List; /** * Created by Nathaël N on 26/07/16. @@ -22,7 +24,7 @@ public class MainFrame extends BorderPane { private Button btnStrategy; - private AbstractView view; + private ViewOrchestrator orchestrator; public MainFrame() { FXMLLoader fxmlLoader = new FXMLLoader(FXML); @@ -36,32 +38,36 @@ public MainFrame() { } catch (IOException e) { logger.fatal("Impossible to load FXML for MainFrame", e); } - - // TODO Temporary solution - setView(new GeneralizedView()); } @FXML private void onClicStrategyButton(ActionEvent event) { - AbstractView ancientview = view; - StrategySelectionView ssv = new StrategySelectionView(); - setView(ssv); + List orchs = orchestrator.getFollowing(); + if(orchs.size() == 1) { + setView(orchs.get(0)); + } else { + StrategySelectionView ssv = new StrategySelectionView(); + setCenter(ssv); // remove abstract view currently loaded + ssv.load(); - ssv.setAvailableChoices( - ancientview instanceof TreatView?ancientview:new TreatView(), - ancientview instanceof EstablishEffectView?ancientview:new EstablishEffectView(), - ancientview instanceof GeneralizedView?ancientview:new GeneralizedView()); - ssv.setOnCancel(ancientview); - ssv.onSetView(this::setView); + ssv.setAvailableChoices(orchestrator.getFollowing()); + ssv.onSetView(this::setView); - btnStrategy.setDisable(true); + btnStrategy.setDisable(true); + } } - public void setView(AbstractView view) { - setCenter(view); // remove abstract view currently loaded - this.view = view; - view.load(); - btnStrategy.setDisable(false); + public void setView(ViewOrchestrator view) { + this.orchestrator = view; + AbstractView av = view.getView(); + if(av == null) { + onClicStrategyButton(null); + } + else { + setCenter(view.getView()); // remove abstract view currently loaded + view.getView().load(); + btnStrategy.setDisable(false); + } } } diff --git a/avek-gui/src/main/java/fr/axonic/avek/gui/view/StrategySelectionView.java b/avek-gui/src/main/java/fr/axonic/avek/gui/view/StrategySelectionView.java index 8a823f4..53f238b 100644 --- a/avek-gui/src/main/java/fr/axonic/avek/gui/view/StrategySelectionView.java +++ b/avek-gui/src/main/java/fr/axonic/avek/gui/view/StrategySelectionView.java @@ -1,5 +1,6 @@ package fr.axonic.avek.gui.view; +import fr.axonic.avek.gui.util.ViewOrchestrator; import javafx.collections.FXCollections; import javafx.event.ActionEvent; import javafx.fxml.FXML; @@ -7,7 +8,6 @@ import javafx.scene.control.ComboBox; import org.apache.log4j.Logger; -import java.util.ArrayList; import java.util.List; import java.util.function.Consumer; @@ -18,12 +18,9 @@ public class StrategySelectionView extends AbstractView { @FXML private Button submit; @FXML - private Button cancel; - @FXML - private ComboBox comboBox; + private ComboBox comboBox; - private AbstractView onCancelView; - private Consumer onSetViewMethod; + private Consumer onSetViewMethod; @Override protected void onLoad() { @@ -34,42 +31,18 @@ protected void onLoad() { @FXML void onSubmit(ActionEvent event) { - onSetView(comboBox.getValue().view); - } - @FXML - void onCancel(ActionEvent event) { - onSetView(onCancelView); + setView(comboBox.getValue()); } - void setAvailableChoices(AbstractView... views) { - List lpov = new ArrayList<>(); - for(AbstractView av : views) - lpov.add(new PointerOnView(av)); - - comboBox.setItems(FXCollections.observableArrayList(lpov)); - } - void setOnCancel(AbstractView view) { - onCancelView = view; + void setAvailableChoices(List views) { + comboBox.setItems(FXCollections.observableArrayList(views)); } - private void onSetView(AbstractView view) { + private void setView(ViewOrchestrator view) { onSetViewMethod.accept(view); } - void onSetView(Consumer onSetViewMethod) { + void onSetView(Consumer onSetViewMethod) { this.onSetViewMethod = onSetViewMethod; } - - private class PointerOnView { - final AbstractView view; - - private PointerOnView(AbstractView view) { - this.view = view; - } - - @Override - public String toString() { - return view.getClass().getSimpleName(); - } - } } diff --git a/avek-gui/src/main/java/fr/axonic/avek/gui/view/TreatView.java b/avek-gui/src/main/java/fr/axonic/avek/gui/view/TreatView.java index 62c0752..db63b4c 100644 --- a/avek-gui/src/main/java/fr/axonic/avek/gui/view/TreatView.java +++ b/avek-gui/src/main/java/fr/axonic/avek/gui/view/TreatView.java @@ -2,8 +2,7 @@ import fr.axonic.avek.gui.components.MonitoredSystemPane; import fr.axonic.avek.gui.components.parameters.ParametersPane; -import fr.axonic.avek.gui.model.json.Jsonifier; -import fr.axonic.avek.model.MonitoredSystem; +import fr.axonic.avek.gui.model.DataBus; import fr.axonic.avek.model.base.engine.AEntity; import fr.axonic.avek.model.base.engine.AList; import javafx.event.ActionEvent; @@ -26,6 +25,15 @@ public class TreatView extends AbstractView { protected void onLoad() { logger.info("Loading TreatView..."); super.load(FXML); + + logger.info("Getting monitored system..."); + monitoredSystemPane.setMonitoredSystem(DataBus.getMonitoredSystem()); + + logger.info("Getting experiment parameters..."); + AList list = DataBus.getExperimentParameters(); + for (AEntity ae : list.getEntities()) + paneParameters.addExpParameter(ae); + logger.debug("TreatView loaded."); } @@ -33,20 +41,5 @@ protected void onLoad() { void onClicStrategyButton(ActionEvent event) { btnStrategy.setDisable(true); } - - /** Fill experiment monitoredSystemPane informations - * - * @param monitoredSystemJson the MonitoredSystem as a Json String - */ - public void setMonitoredSystem(String monitoredSystemJson) { - monitoredSystemPane.setMonitoredSystem(MonitoredSystem.fromJson(monitoredSystemJson)); - } - - public void setExperimentParameters(String experimentParametersJson) { - AList list = Jsonifier.toAListofAListAndAVar(experimentParametersJson); - - for (AEntity ae : list.getEntities()) - paneParameters.addExpParameter(ae); - } } diff --git a/avek-gui/src/main/resources/css/results/jellyBeanSelector.css b/avek-gui/src/main/resources/css/results/jellyBeanSelector.css index 3ed41c8..b17e8b6 100644 --- a/avek-gui/src/main/resources/css/results/jellyBeanSelector.css +++ b/avek-gui/src/main/resources/css/results/jellyBeanSelector.css @@ -1,4 +1,4 @@ -.jellyBeansPane { +.jellyBeanPane { -fx-background-color: #cea; } diff --git a/avek-gui/src/main/resources/fxml/components/JellyBeansSelector.fxml b/avek-gui/src/main/resources/fxml/components/JellyBeansSelector.fxml index df99fef..cfdb6e3 100644 --- a/avek-gui/src/main/resources/fxml/components/JellyBeansSelector.fxml +++ b/avek-gui/src/main/resources/fxml/components/JellyBeansSelector.fxml @@ -1,8 +1,8 @@ + - @@ -10,5 +10,5 @@ - - + diff --git a/avek-gui/src/test/java/fr/axonic/avek/gui/TestMain.java b/avek-gui/src/test/java/fr/axonic/avek/gui/TestMain.java index b0d6abd..8d88010 100644 --- a/avek-gui/src/test/java/fr/axonic/avek/gui/TestMain.java +++ b/avek-gui/src/test/java/fr/axonic/avek/gui/TestMain.java @@ -1,8 +1,8 @@ package fr.axonic.avek.gui; import fr.axonic.avek.gui.util.ConcurrentTaskManager; -import fr.axonic.avek.gui.util.Util; import fr.axonic.avek.gui.util.UtilForTests; +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.TreatView; @@ -27,28 +27,34 @@ public void start(Stage stage) throws Exception { } @Test - public void mainTest() { + public void mainTest() throws Exception { ConcurrentTaskManager ctm = new ConcurrentTaskManager(); + ViewOrchestrator oNull = new ViewOrchestrator(null); GeneralizedView gView = new GeneralizedView(); - ctm.runLaterOnPlatform(() -> reference.getMainFrame().setView(gView)); - ctm.runLaterOnPlatform(() -> gView.setMonitoredSystem(Util.getFileContent("files/subjectFile.json"))); - ctm.runLaterOnPlatform(() -> gView.setExperimentParameters(Util.getFileContent("files/parametersFile.json"))); - ctm.waitForTasks(); + ViewOrchestrator o3 = new ViewOrchestrator(gView); + o3.addFollowing(oNull); + EstablishEffectView eeView = new EstablishEffectView(); + ViewOrchestrator o2 = new ViewOrchestrator(eeView); + o2.addFollowing(o3); + TreatView tView = new TreatView(); + ViewOrchestrator o1 = new ViewOrchestrator(tView); + o1.addFollowing(o2); + + oNull.addFollowing(o1); + oNull.addFollowing(o2); + oNull.addFollowing(o3); + + ctm.runNowOnPlatform(() -> reference.getMainFrame().setView(oNull)); assertTrue(true); - EstablishEffectView eeView = new EstablishEffectView(); - ctm.runLaterOnPlatform(() -> reference.getMainFrame().setView(eeView)); - ctm.runLaterOnPlatform(() -> eeView.setMonitoredSystem(Util.getFileContent("files/subjectFile.json"))); - ctm.runLaterOnPlatform(() -> eeView.setExperimentParameters(Util.getFileContent("files/parametersFile.json"))); - ctm.waitForTasks(); + ctm.runNowOnPlatform(() -> reference.getMainFrame().setView(o1)); assertTrue(true); - TreatView tView = new TreatView(); - ctm.runLaterOnPlatform(() -> reference.getMainFrame().setView(tView)); - ctm.runLaterOnPlatform(() -> tView.setMonitoredSystem(Util.getFileContent("files/subjectFile.json"))); - ctm.runLaterOnPlatform(() -> tView.setExperimentParameters(Util.getFileContent("files/parametersFile.json"))); - ctm.waitForTasks(); + ctm.runNowOnPlatform(() -> reference.getMainFrame().setView(o2)); + assertTrue(true); + + ctm.runNowOnPlatform(() -> reference.getMainFrame().setView(o3)); assertTrue(true); } } diff --git a/avek-gui/src/test/java/fr/axonic/avek/gui/components/results/TestJellyBeanSelector.java b/avek-gui/src/test/java/fr/axonic/avek/gui/components/jellyBeans/TestJellyBeanSelector.java similarity index 80% rename from avek-gui/src/test/java/fr/axonic/avek/gui/components/results/TestJellyBeanSelector.java rename to avek-gui/src/test/java/fr/axonic/avek/gui/components/jellyBeans/TestJellyBeanSelector.java index e6511e3..9f9b12d 100644 --- a/avek-gui/src/test/java/fr/axonic/avek/gui/components/results/TestJellyBeanSelector.java +++ b/avek-gui/src/test/java/fr/axonic/avek/gui/components/jellyBeans/TestJellyBeanSelector.java @@ -1,12 +1,12 @@ -package fr.axonic.avek.gui.components.results; +package fr.axonic.avek.gui.components.jellyBeans; import com.google.gson.Gson; import fr.axonic.avek.gui.model.sample.ExampleState; -import fr.axonic.avek.gui.model.structure.ExperimentationResult; +import fr.axonic.avek.gui.model.structure.ExperimentResult; +import fr.axonic.avek.gui.model.structure.ExperimentResultsMap; import fr.axonic.avek.gui.util.UtilForTests; import fr.axonic.avek.model.base.ARangedEnum; import fr.axonic.avek.model.verification.exception.VerificationException; -import javafx.collections.FXCollections; import javafx.scene.Scene; import javafx.scene.input.KeyCode; import javafx.scene.layout.Pane; @@ -30,7 +30,7 @@ public class TestJellyBeanSelector extends ApplicationTest { static { UtilForTests.disableGraphics(); } - private Pane jellyBeanPane; + private JellyBeanPane jellyBeanPane; @Override @@ -40,29 +40,28 @@ public void start(Stage stage) throws VerificationException, IOException { stage.setScene(scene); stage.show(); - List experimentationResults = new ArrayList<>(); + ExperimentResultsMap expResMap = new ExperimentResultsMap(); for (int i = 1; i <= 30; i++) { - String s; - { - ExampleState val = ExampleState.values()[0]; - ARangedEnum aEnum = new ARangedEnum<>(val); - //aEnum.setDefaultValue(ExampleState.MEDIUM); - aEnum.setRange(Arrays.asList(ExampleState.values())); - s = new Gson().toJson(aEnum); - } - ARangedEnum be = new Gson().fromJson(s, ARangedEnum.class); - - experimentationResults.add(new ExperimentationResult("AE" + i, be)); + ExampleState val = ExampleState.values()[0]; + ARangedEnum aEnum = new ARangedEnum<>(val); + aEnum.setDefaultValue(ExampleState.MEDIUM); + aEnum.setRange(Arrays.asList(ExampleState.values())); + + expResMap.put("AE" + i, aEnum); } // Fill experiment sample list - jbs.setJellyBeansChoice(FXCollections.observableArrayList(experimentationResults)); - jellyBeanPane = (Pane) jbs.getChildren().get(1); + jbs.setJellyBeansChoice(expResMap); + jellyBeanPane = jbs.getJellyBeanPane(); } @Test public void testSelectItem() { - verifyThat("#jellyBeansPane", hasChildren(0)); + assertEquals(0, jellyBeanPane.getChildren().size()); + + // Try to add 'null' + clickOn("#comboBoxJellyBean") + .push(KeyCode.ENTER); assertEquals(0, jellyBeanPane.getChildren().size()); // Move to 'Effect 5' @@ -75,12 +74,10 @@ public void testSelectItem() { .push(KeyCode.ENTER); // Add 'Effect 5' - verifyThat("#jellyBeansPane", hasChildren(1)); assertEquals(1, jellyBeanPane.getChildren().size()); verifyGoodJellyBean(jellyBeanPane, 0, "AE5"); // Add 'Effect 5' (should do nothing) - verifyThat("#jellyBeansPane", hasChildren(1)); assertEquals(1, jellyBeanPane.getChildren().size()); verifyGoodJellyBean(jellyBeanPane, 0, "AE5"); @@ -92,7 +89,6 @@ public void testSelectItem() { .push(KeyCode.ENTER); // Add 'Effect 7' - verifyThat("#jellyBeansPane", hasChildren(2)); assertEquals(2, jellyBeanPane.getChildren().size()); verifyGoodJellyBean(jellyBeanPane, 0, "AE5"); verifyGoodJellyBean(jellyBeanPane, 1, "AE7"); @@ -104,7 +100,6 @@ public void testSelectItem() { .push(KeyCode.ENTER); // Add 'Effect 5' (should do nothing) - verifyThat("#jellyBeansPane", hasChildren(2)); assertEquals(2, jellyBeanPane.getChildren().size()); verifyGoodJellyBean(jellyBeanPane, 0, "AE5"); verifyGoodJellyBean(jellyBeanPane, 1, "AE7"); @@ -116,7 +111,6 @@ public void testSelectItem() { .push(KeyCode.ENTER); // Add 'Effect 3' - verifyThat("#jellyBeansPane", hasChildren(3)); assertEquals(3, jellyBeanPane.getChildren().size()); verifyGoodJellyBean(jellyBeanPane, 0, "AE5"); verifyGoodJellyBean(jellyBeanPane, 1, "AE7"); diff --git a/avek-gui/src/test/java/fr/axonic/avek/gui/components/jellyBeans/TestJellyBeans.java b/avek-gui/src/test/java/fr/axonic/avek/gui/components/jellyBeans/TestJellyBeans.java new file mode 100644 index 0000000..f3fc412 --- /dev/null +++ b/avek-gui/src/test/java/fr/axonic/avek/gui/components/jellyBeans/TestJellyBeans.java @@ -0,0 +1,118 @@ +package fr.axonic.avek.gui.components.jellyBeans; + +import fr.axonic.avek.gui.model.sample.ExampleState; +import fr.axonic.avek.gui.util.UtilForTests; +import fr.axonic.avek.model.base.ARangedEnum; +import fr.axonic.avek.model.verification.exception.VerificationException; +import javafx.scene.Scene; +import javafx.scene.control.Button; +import javafx.stage.Stage; +import org.junit.Test; +import org.testfx.framework.junit.ApplicationTest; + +import java.io.IOException; +import java.util.*; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +/** + * Created by Nathaël N on 07/07/16. + */ +public class TestJellyBeans extends ApplicationTest { + static { UtilForTests.disableGraphics(); } + + private JellyBean jb; + private Button jbText, jbCross; + + @Override + public void start(Stage stage) throws IOException { + this.jb = new JellyBean(); + + Scene scene = new Scene(jb, 200, 200); + stage.setScene(scene); + stage.show(); + + jbText = (Button) (jb.getChildren().get(0)); + jbCross = (Button) (jb.getChildren().get(1)); + + this.jb.setText("The Text"); + } + + @Test + public void testReadOnly() throws VerificationException { + ARangedEnum are = new ARangedEnum<>(ExampleState.VERY_LOW); + List l = new ArrayList<>(); + Collections.addAll(l, ExampleState.values()); + are.setRange(l); + + this.jb.setStateType(are); + // ReadOnly if not 'setOnDelete' + //this.jb.setOnDelete(this::calledOnDelete); + + assertEquals(ExampleState.VERY_LOW, jb.getState()); + + clickOn(jbText); + assertEquals(ExampleState.VERY_LOW, jb.getState()); + + clickOn(jbText); // Medium + clickOn(jbText); + assertEquals(ExampleState.VERY_LOW, jb.getState()); + + clickOn(jbText); // Very high + clickOn(jbText); // Very Low + clickOn(jbText); // low + clickOn(jbText); + assertEquals(ExampleState.VERY_LOW, jb.getState()); + + // try delete + clickOn(jbCross); + long timeout = Calendar.getInstance().getTimeInMillis()+1_000; // 1s + while(Calendar.getInstance().getTimeInMillis() < timeout + && !calledDelete.contains(jb)) + try{ Thread.sleep(1); } catch(InterruptedException ignored){} + + assertTrue("OnDelete called after 1s", !calledDelete.contains(jb)); + } + + @Test + public void testStateChange() throws VerificationException { + ARangedEnum are = new ARangedEnum<>(ExampleState.VERY_LOW); + List l = new ArrayList<>(); + Collections.addAll(l, ExampleState.values()); + are.setRange(l); + + this.jb.setStateType(are); + this.jb.setOnDelete(this::calledOnDelete); + + assertEquals(ExampleState.VERY_LOW, jb.getState()); + + clickOn(jbText); + assertEquals(ExampleState.LOW, jb.getState()); + + + clickOn(jbText); // Medium + clickOn(jbText); + assertEquals(ExampleState.HIGH, jb.getState()); + + clickOn(jbText); // Very high + clickOn(jbText); // Very Low + clickOn(jbText); // low + clickOn(jbText); + assertEquals(ExampleState.MEDIUM, jb.getState()); + + // try delete + clickOn(jbCross); + long timeout = Calendar.getInstance().getTimeInMillis()+1_000; // 1s + while(Calendar.getInstance().getTimeInMillis() < timeout + && !calledDelete.contains(jb)) + try{ Thread.sleep(1); } catch(InterruptedException ignored){} + + assertTrue("OnDelete not called after 1s", calledDelete.contains(jb)); + } + + private final Set calledDelete = new HashSet<>(); + private void calledOnDelete(JellyBean jellyBean) { + calledDelete.add(jellyBean); + } +} diff --git a/avek-gui/src/test/java/fr/axonic/avek/gui/components/parameters/TestFileList.java b/avek-gui/src/test/java/fr/axonic/avek/gui/components/parameters/TestFileList.java index 61c3de3..36e78c7 100644 --- a/avek-gui/src/test/java/fr/axonic/avek/gui/components/parameters/TestFileList.java +++ b/avek-gui/src/test/java/fr/axonic/avek/gui/components/parameters/TestFileList.java @@ -1,6 +1,7 @@ package fr.axonic.avek.gui.components.parameters; import fr.axonic.avek.gui.components.filelist.FileListView; +import fr.axonic.avek.gui.util.ConcurrentTaskManager; import fr.axonic.avek.gui.util.UtilForTests; import javafx.scene.Scene; import javafx.stage.Stage; @@ -47,29 +48,43 @@ public void after() { } @Test - public void testAddFiles() throws ReflectiveOperationException { + public void testAddFiles() throws Exception { + ConcurrentTaskManager ctm = new ConcurrentTaskManager(); + // Get method FileListView.onAddFiles(File) with authorized use access Method method = FileListView.class.getDeclaredMethod("onAddFiles", List.class); method.setAccessible(true); assertEquals(0, flv.getFileList().getItems().size()); - method.invoke(flv, Collections.singletonList(new File("./temp/toto/titi.txt"))); + ctm.runNowOnPlatform(() -> + method.invoke(flv, + Collections.singletonList( + new File("./temp/toto/titi.txt")))); assertEquals(1, flv.getFileList().getItems().size()); - method.invoke(flv, Collections.singletonList(new File("./temp/toto/tonton.txt"))); + ctm.runNowOnPlatform(() -> + method.invoke(flv, + Collections.singletonList( + new File("./temp/toto/tonton.txt")))); assertEquals(2, flv.getFileList().getItems().size()); // File already added logger.warn("[NOT A WARNING] A deliberate action should show a WARN message\n" + " \"FileListView - File already added\" should following this (Tests)"); - method.invoke(flv, Collections.singletonList(new File("./temp/toto/titi.txt"))); + ctm.runNowOnPlatform(() -> + method.invoke(flv, + Collections.singletonList( + new File("./temp/toto/titi.txt")))); assertEquals(2, flv.getFileList().getItems().size()); // File not found logger.error("[NOT AN ERROR] A deliberate action should show a ERROR message\n" + " \"FileListView - File not found\" should following this (Tests)"); - method.invoke(flv, Collections.singletonList(new File("./temp/toto/ThisIsNotAFile.txt"))); + ctm.runNowOnPlatform(() -> + method.invoke(flv, + Collections.singletonList( + new File("./temp/toto/ThisIsNotAFile.txt")))); assertEquals(2, flv.getFileList().getItems().size()); } diff --git a/avek-gui/src/test/java/fr/axonic/avek/gui/components/parameters/TestGeneralizedParametersPane.java b/avek-gui/src/test/java/fr/axonic/avek/gui/components/parameters/TestGeneralizedParametersPane.java index fcd1153..c4041b1 100644 --- a/avek-gui/src/test/java/fr/axonic/avek/gui/components/parameters/TestGeneralizedParametersPane.java +++ b/avek-gui/src/test/java/fr/axonic/avek/gui/components/parameters/TestGeneralizedParametersPane.java @@ -30,7 +30,7 @@ public void start(Stage stage) throws IOException { } @Test - public void testOnClickHide() { + public void testOnClickHide() throws Exception { ConcurrentTaskManager ctm = new ConcurrentTaskManager(); assertTrue(pp.getComplementaryFilePane().isVisible()); diff --git a/avek-gui/src/test/java/fr/axonic/avek/gui/components/parameters/TestParametersCategory.java b/avek-gui/src/test/java/fr/axonic/avek/gui/components/parameters/TestParametersCategory.java index 43a6a7f..a2e8122 100644 --- a/avek-gui/src/test/java/fr/axonic/avek/gui/components/parameters/TestParametersCategory.java +++ b/avek-gui/src/test/java/fr/axonic/avek/gui/components/parameters/TestParametersCategory.java @@ -15,7 +15,6 @@ import java.io.IOException; import java.util.Date; -import java.util.concurrent.ExecutionException; import static org.junit.Assert.assertEquals; @@ -39,7 +38,7 @@ public void start(Stage stage) throws IOException { } @Test - public void testAddRemoveParameters() throws ExecutionException, InterruptedException { + public void testAddRemoveParameters() throws Exception { System.out.println("CALL"); ConcurrentTaskManager ctm = new ConcurrentTaskManager(); @@ -60,7 +59,7 @@ public void testAddRemoveParameters() throws ExecutionException, InterruptedExce } @Test - public void testDifferentParametersTypes() throws ExecutionException, InterruptedException { + public void testDifferentParametersTypes() throws Exception { ConcurrentTaskManager ctm = new ConcurrentTaskManager(); ctm.runNowOnPlatform(() -> pp.addParameter(new ANumber("LabelText", 42.31))); diff --git a/avek-gui/src/test/java/fr/axonic/avek/gui/components/results/TestJellyBeans.java b/avek-gui/src/test/java/fr/axonic/avek/gui/components/results/TestJellyBeans.java deleted file mode 100644 index 4653c1f..0000000 --- a/avek-gui/src/test/java/fr/axonic/avek/gui/components/results/TestJellyBeans.java +++ /dev/null @@ -1,69 +0,0 @@ -package fr.axonic.avek.gui.components.results; - -import fr.axonic.avek.gui.model.sample.ExampleState; -import fr.axonic.avek.gui.util.UtilForTests; -import fr.axonic.avek.model.base.ARangedEnum; -import fr.axonic.avek.model.verification.exception.VerificationException; -import javafx.scene.Scene; -import javafx.scene.control.Button; -import javafx.stage.Stage; -import org.junit.Test; -import org.testfx.framework.junit.ApplicationTest; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import static org.junit.Assert.assertEquals; - -/** - * Created by Nathaël N on 07/07/16. - */ -public class TestJellyBeans extends ApplicationTest { - static { UtilForTests.disableGraphics(); } - - private JellyBean jb; - private Button jbText; - - @Override - public void start(Stage stage) throws IOException { - this.jb = new JellyBean(); - - Scene scene = new Scene(jb, 200, 200); - stage.setScene(scene); - stage.show(); - - jbText = (Button) (jb.getChildren().get(0)); - jb.setId("thejb"); - jbText.setId("jbtext"); - - this.jb.setText("The Text"); - } - - @Test - public void testStateChange() throws VerificationException { - ARangedEnum are = new ARangedEnum<>(ExampleState.VERY_LOW); - List l = new ArrayList<>(); - Collections.addAll(l, ExampleState.values()); - are.setRange(l); - - this.jb.setStateType(are); - - assertEquals(ExampleState.VERY_LOW, jb.getState()); - - clickOn(jbText); - assertEquals(ExampleState.LOW, jb.getState()); - - - clickOn(jbText); // Medium - clickOn(jbText); - assertEquals(ExampleState.HIGH, jb.getState()); - - clickOn(jbText); // Very high - clickOn(jbText); // Very Low - clickOn(jbText); // low - clickOn(jbText); - assertEquals(ExampleState.MEDIUM, jb.getState()); - } -} diff --git a/avek-gui/src/test/java/fr/axonic/avek/gui/components/subjects/TestSubjectData.java b/avek-gui/src/test/java/fr/axonic/avek/gui/components/subjects/TestSubjectData.java index a37b8ff..bf47317 100644 --- a/avek-gui/src/test/java/fr/axonic/avek/gui/components/subjects/TestSubjectData.java +++ b/avek-gui/src/test/java/fr/axonic/avek/gui/components/subjects/TestSubjectData.java @@ -18,7 +18,6 @@ import java.io.IOException; import java.util.Calendar; -import java.util.concurrent.ExecutionException; import static org.junit.Assert.assertEquals; @@ -43,7 +42,7 @@ public void start(Stage stage) throws IOException { } @Test - public void testMonitoredSystem() throws ExecutionException, InterruptedException { + public void testMonitoredSystem() throws Exception { ConcurrentTaskManager ctm = new ConcurrentTaskManager(); MonitoredSystem ms1 = new MonitoredSystem(42); ms1.addCategory("Category 1"); diff --git a/avek-gui/src/main/java/fr/axonic/avek/gui/util/ConcurrentTaskManager.java b/avek-gui/src/test/java/fr/axonic/avek/gui/util/ConcurrentTaskManager.java similarity index 60% rename from avek-gui/src/main/java/fr/axonic/avek/gui/util/ConcurrentTaskManager.java rename to avek-gui/src/test/java/fr/axonic/avek/gui/util/ConcurrentTaskManager.java index d27620d..481cf7d 100644 --- a/avek-gui/src/main/java/fr/axonic/avek/gui/util/ConcurrentTaskManager.java +++ b/avek-gui/src/test/java/fr/axonic/avek/gui/util/ConcurrentTaskManager.java @@ -25,20 +25,15 @@ public class ConcurrentTaskManager { private final Set running = new HashSet<>(); private final Map threads = new HashMap<>(); - private void run(Runnable r, boolean onPlatform) { + private void run(Runnable r, boolean onPlatform) throws Exception { this.run(() -> {r.run(); return true;}, onPlatform); } - private void run(Callable c, boolean onPlatform) { + private void run(Callable c, boolean onPlatform) throws Exception { if (Thread.currentThread() == platformThread && onPlatform) { - try { - c.call(); - } catch (Exception e) { - logger.error("Exception thrown during task call", e); - } + c.call(); return; } - final FutureTask ft = new FutureTask<>(() -> { int id = ++taskCount; @@ -61,44 +56,37 @@ private void run(Callable c, boolean onPlatform) { running.add(ft); } - public void runNowOnPlatform(Runnable r) { - runNowOnPlatform(() -> {r.run(); return true;}); + public boolean runNowOnPlatform(Runnable r) throws Exception { + return runNowOnPlatform(() -> {r.run(); return true;}); } - public V runNowOnPlatform(Callable c) { - try { - if(Thread.currentThread() == platformThread) - c.call(); + public V runNowOnPlatform(Callable c) throws Exception { + if(Thread.currentThread() == platformThread) + c.call(); - FutureTask ft = new FutureTask<>(c); - Platform.runLater(ft); - return ft.get(); - } catch (Exception e) { - e.printStackTrace(); - } - return null; + FutureTask ft = new FutureTask<>(c); + Platform.runLater(ft); + return ft.get(); } - public void runLaterOnPlatform(Runnable r) { + public void runLaterOnPlatform(Runnable r) throws Exception { run(r, true); } - public void runLaterOnPlatform(Callable c) { + public void runLaterOnPlatform(Callable c) throws Exception { run(c, true); } - public void runLaterOnThread(Runnable r) { + public void runLaterOnThread(Runnable r) throws Exception { run(r, false); } - public void runLaterOnThread(Callable c) { + public void runLaterOnThread(Callable c) throws Exception { run(c, false); } - public void waitForTasks() { - new HashSet<>(running).forEach(this::waitForTask); + public void waitForTasks() throws ExecutionException, InterruptedException { + for(FutureTask ft : running) + waitForTask(ft); } - private void waitForTask(FutureTask ft) { - try { - ft.get(); - } catch (InterruptedException | ExecutionException e) { - logger.error("Future task failed", e); - } + private Object waitForTask(FutureTask ft) throws ExecutionException, InterruptedException { + Object value = ft.get(); running.remove(ft); + return value; } } diff --git a/avek-gui/src/test/java/fr/axonic/avek/gui/view/TestSelectStrategyView.java b/avek-gui/src/test/java/fr/axonic/avek/gui/view/TestSelectStrategyView.java new file mode 100644 index 0000000..2f39481 --- /dev/null +++ b/avek-gui/src/test/java/fr/axonic/avek/gui/view/TestSelectStrategyView.java @@ -0,0 +1,23 @@ +package fr.axonic.avek.gui.view; + +import fr.axonic.avek.gui.util.UtilForTests; +import javafx.scene.Scene; +import javafx.stage.Stage; +import org.testfx.framework.junit.ApplicationTest; + +/** + * Created by Nathaël N on 27/07/16. + */ +public class TestSelectStrategyView extends ApplicationTest { + static { UtilForTests.disableGraphics(); } + + private MainFrame mainFrame; + + @Override + public void start(Stage stage) throws Exception { + mainFrame = new MainFrame(); + + stage.setScene(new Scene(mainFrame, 800, 600)); + stage.show(); + } +}