Skip to content

Commit

Permalink
Merge pull request #124 from yprie/sprint3/categoryCounter
Browse files Browse the repository at this point in the history
Added current interview uses per interview
  • Loading branch information
JeridiOmar authored Apr 2, 2023
2 parents c421001 + 7d6de84 commit 62cdfb5
Show file tree
Hide file tree
Showing 9 changed files with 175 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import models.SchemaCategory;
import models.SchemaProperty;
import javafx.scene.control.MenuItem;
import utils.GlobalVariables;
import utils.ResourceLoader;
import utils.autoSuggestion.strategies.SuggestionStrategy;
import utils.autoSuggestion.strategies.SuggestionStrategyCategory;
Expand All @@ -18,6 +19,7 @@ public class SchemaTreeCategoryController extends SchemaTreeCellController {

private SchemaCategory category;
private SchemaTreeCommandFactory cmdFactory;
private GlobalVariables globalVariables = GlobalVariables.getGlobalVariables();

public SchemaTreeCategoryController(SchemaCategory model, SchemaTreeCommandFactory cmdFactory) {
super(model, cmdFactory);
Expand All @@ -35,10 +37,20 @@ public void initialize(URL url, ResourceBundle resourceBundle) {
super.initialize(url, resourceBundle);

name.textProperty().bind(element.nameProperty());
usesPerInterview.textProperty().bind(Bindings.createStringBinding(() -> {
String s = "";
int currentInterviewUses = this.category.getCurrentInterviewUses();
int nUsesInModelisation = category.numberOfUsesInModelisationProperty().get();
if (nUsesInModelisation > 0) {
s = " " + this.category.getCurrentInterviewUses() + " / ";
}
return s;

}, this.category.currentInterviewUsesProperty()));
complementaryInfo.textProperty().bind(Bindings.createStringBinding(() -> {
String s = "";
int nUses = category.numberOfUsesInModelisationProperty().get();
if(nUses > 0) {
if (nUses > 0) {
s += nUses + " ";
s += Configuration.langBundle.getString(nUses == 1 ? "use" : "uses");
}
Expand Down Expand Up @@ -132,7 +144,7 @@ private void addColorChange() {
optionsMenu.getItems().add(changeColor);
}

public void updateCategoryIcon(String color){
public void updateCategoryIcon(String color) {

switch (color) {
case "ffffff":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public abstract class SchemaTreeCellController implements Initializable {
Label name;

@FXML Label complementaryInfo;

@FXML Label usesPerInterview;
AutoSuggestionsTextField renamingField;

@FXML
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package components.schemaTree.Cell.Visitors;

import models.*;

public class InitTreeElement extends SchemaTreePluggableVisitor{
@Override
public void visit(SchemaTreeRoot element) {
element.foldersProperty().forEach(schemaFolder -> { schemaFolder.accept(this); });
element.categoriesProperty().forEach(schemaCategory -> { schemaCategory.accept(this); });
}

@Override
public void visit(SchemaFolder element) {
element.foldersProperty().forEach(schemaFolder -> { schemaFolder.accept(this); });
element.categoriesProperty().forEach(schemaCategory -> { schemaCategory.accept(this); });
}

@Override
public void visit(SchemaCategory element) {
element.init();
}

@Override
public void visit(SchemaProperty element) {

}

@Override
public void visit(SchemaMomentType element) {

}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package components.schemaTree.Services.categoryUsesCounter;

import components.modelisationSpace.hooks.ModelisationSpaceHook;
import models.Interview;
import models.Moment;
import models.Project;
import models.SchemaCategory;

public class SchemaCategoryUsesCounter {

private Project project;//to be able to spot the interview where the categories is added
private ModelisationSpaceHook modelisationSpaceHook;
private enum CountingMethod { INCREMENT, DECREMENT };

public SchemaCategoryUsesCounter(Project project, ModelisationSpaceHook modelisationSpaceHook) {
this.project=project;
initalize(project);
setupModelisationSpaceHooks(modelisationSpaceHook);
}
Expand All @@ -20,19 +22,24 @@ public void setupModelisationSpaceHooks(ModelisationSpaceHook msh) {
modelisationSpaceHook.addOnConcreteCategoryAdded(cc -> {
SchemaCategory sc = cc.getSchemaCategory();
sc.setNumberOfUsesInModelisation(sc.numberOfUsesInModelisationProperty().get() + 1);
sc.setNumberOfUsesInInterview(this.project.getSelectedInterview(),sc.numberOfUsesInInterviewProperty(this.project.getSelectedInterview()) + 1);
});

modelisationSpaceHook.addOnConcreteCategoryRemoved(cc -> {
SchemaCategory sc = cc.getSchemaCategory();
sc.setNumberOfUsesInModelisation(sc.numberOfUsesInModelisationProperty().get() - 1);
sc.setNumberOfUsesInInterview(this.project.getSelectedInterview(),sc.numberOfUsesInInterviewProperty(this.project.getSelectedInterview()) - 1);

});

modelisationSpaceHook.addOnMomentAdded(moment -> {
countThroughAMoment(moment, CountingMethod.INCREMENT);
//countThroughAMoment(moment, CountingMethod.INCREMENT);
countThroughAMomentInterview(this.project.getSelectedInterview(),moment, CountingMethod.INCREMENT);
});

modelisationSpaceHook.addOnMomentRemoved(moment -> {
countThroughAMoment(moment, CountingMethod.DECREMENT);
//countThroughAMoment(moment, CountingMethod.DECREMENT);
countThroughAMomentInterview(this.project.getSelectedInterview(),moment, CountingMethod.DECREMENT);
});
}

Expand All @@ -43,7 +50,7 @@ private void reinitializeCounters(Project project) {
private void initalize(Project project) {
reinitializeCounters(project);
project.interviewsProperty().forEach(interview -> {
interview.getRootMoment().momentsProperty().forEach(moment -> { countThroughAMoment(moment, CountingMethod.INCREMENT );});
interview.getRootMoment().momentsProperty().forEach(moment -> { countThroughAMomentInterview(interview,moment, CountingMethod.INCREMENT );});
});
}

Expand All @@ -55,4 +62,15 @@ private void countThroughAMoment(Moment m, CountingMethod cm) {
});
m.momentsProperty().forEach(moment -> { countThroughAMoment(moment, cm); });
}
//newer version of the function above to take into consideration uses per interview
private void countThroughAMomentInterview(Interview interview, Moment m, CountingMethod cm) {
m.concreteCategoriesProperty().forEach(concreteCategory -> {
SchemaCategory sc = concreteCategory.getSchemaCategory();
int i = cm == CountingMethod.INCREMENT ? 1 : cm == CountingMethod.DECREMENT ? -1 : 0;
sc.setNumberOfUsesInModelisation(sc.numberOfUsesInModelisationProperty().get() + i);
sc.setNumberOfUsesInInterview(interview,sc.numberOfUsesInInterviewProperty(interview) + i);

});
m.momentsProperty().forEach(moment -> { countThroughAMomentInterview(interview,moment, cm); });
}
}
4 changes: 3 additions & 1 deletion src/main/java/models/Project.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import utils.GlobalVariables;

import java.io.IOException;
import java.io.Serializable;
Expand All @@ -25,7 +26,7 @@ public class Project implements Serializable {
private SimpleObjectProperty<Interview> selectedInterview;

private List<MomentTypeController> momentTypeControllers;

private GlobalVariables globalVariables = GlobalVariables.getGlobalVariables();
public Project(String name, SchemaTreeRoot baseScheme) {
this.name = new SimpleStringProperty(name);
this.schemaTreeRoot = new SimpleObjectProperty<>(baseScheme);
Expand All @@ -36,6 +37,7 @@ public Project(String name, SchemaTreeRoot baseScheme) {
this.selectedInterview = new SimpleObjectProperty<>();

this.momentTypeControllers = new LinkedList<>();
globalVariables.setProject(this);
}

public String getName() { return this.name.get(); }
Expand Down
96 changes: 77 additions & 19 deletions src/main/java/models/SchemaCategory.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package models;

import components.modelisationSpace.category.controllers.ConcreteCategoryController;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableBooleanValue;
import utils.GlobalVariables;
import utils.removable.IRemovable;
import components.schemaTree.Cell.SchemaTreePluggable;
import components.schemaTree.Cell.Utils;
Expand All @@ -12,6 +14,7 @@
import javafx.scene.input.DataFormat;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;

public class SchemaCategory extends SchemaElement implements IRemovable {
Expand All @@ -20,17 +23,23 @@ public class SchemaCategory extends SchemaElement implements IRemovable {

private SimpleBooleanProperty exists;
private ListProperty<SchemaProperty> properties;

private GlobalVariables globalVariables = GlobalVariables.getGlobalVariables();
//Computed values, no need to store them
private SimpleIntegerProperty nbUsesInModelisation;
private SimpleStringProperty color = new SimpleStringProperty("efe4b0");
private ArrayList<ConcreteCategoryController> ListImplements = new ArrayList<>();
private HashMap<Interview, Integer> nbUsesInInterviews;
private SimpleIntegerProperty currentInterviewUses;


public SchemaCategory(String name) {
super(name);
this.exists = new SimpleBooleanProperty(true);
this.properties = new SimpleListProperty<SchemaProperty>(FXCollections.observableList(new LinkedList<SchemaProperty>()));
this.nbUsesInModelisation = new SimpleIntegerProperty(0);
this.nbUsesInInterviews = new HashMap<Interview, Integer>();
this.currentInterviewUses = new SimpleIntegerProperty(0);
globalVariables.getProject().selectedInterviewProperty().addListener(onSelectedInterviewChanges);
}

public SchemaCategory(String name, String color) {
Expand All @@ -39,15 +48,28 @@ public SchemaCategory(String name, String color) {
this.properties = new SimpleListProperty<SchemaProperty>(FXCollections.observableList(new LinkedList<SchemaProperty>()));
this.nbUsesInModelisation = new SimpleIntegerProperty(0);
this.color = new SimpleStringProperty(color);
this.currentInterviewUses = new SimpleIntegerProperty(0);
this.nbUsesInInterviews = new HashMap<Interview, Integer>();

}

public final ObservableList<SchemaProperty> propertiesProperty() { return properties; }
public final ObservableList<SchemaProperty> propertiesProperty() {
return properties;
}

public void init() {
globalVariables.getProject().selectedInterviewProperty().addListener(onSelectedInterviewChanges);
}

@Override
public void setExists(boolean b) { exists.set(b); }
public void setExists(boolean b) {
exists.set(b);
}

@Override
public ObservableBooleanValue existsProperty() { return exists; }
public ObservableBooleanValue existsProperty() {
return exists;
}

@Override
public DataFormat getDataFormat() {
Expand Down Expand Up @@ -76,32 +98,32 @@ public boolean hasChild(SchemaTreePluggable item) {

@Override
public void addChild(SchemaTreePluggable item) {
if(Utils.IsSchemaTreeProperty(item))
addProperty((SchemaProperty)item, -1);
if (Utils.IsSchemaTreeProperty(item))
addProperty((SchemaProperty) item, -1);
else
throw new IllegalArgumentException("(SchemaCategory::addChild) Can't receive this kind of child !");
}

@Override
public void addChildAt(SchemaTreePluggable item, int index) {
if(Utils.IsSchemaTreeProperty(item))
addProperty((SchemaProperty)item, index);
if (Utils.IsSchemaTreeProperty(item))
addProperty((SchemaProperty) item, index);
else
throw new IllegalArgumentException("(SchemaCategory::addChildAt) Can't receive this kind of child !");
}

@Override
public void removeChild(SchemaTreePluggable item) {
if(Utils.IsSchemaTreeProperty(item))
removeProperty((SchemaProperty)item);
if (Utils.IsSchemaTreeProperty(item))
removeProperty((SchemaProperty) item);
else
throw new IllegalArgumentException("(SchemaCategory::removeChild) Can't remove this kind of child !");
}

@Override
public int getChildIndex(SchemaTreePluggable item) {
int r = this.properties.indexOf(item);
if(r == -1)
if (r == -1)
throw new IllegalArgumentException("(SchemaCategory) The provided item is not a child of this element!");
return r;
}
Expand All @@ -116,18 +138,48 @@ public boolean canChangeParent() {
return true;
}

private void addProperty(SchemaProperty p, int index){
if(index == -1)
private void addProperty(SchemaProperty p, int index) {
if (index == -1)
properties.add(p);
else
properties.add(index, p);
}
private void removeProperty(SchemaProperty p){

private void removeProperty(SchemaProperty p) {
properties.remove(p);
}

public void setNumberOfUsesInModelisation(int nbUses) { this.nbUsesInModelisation.set(nbUses); }
public ReadOnlyIntegerProperty numberOfUsesInModelisationProperty() { return this.nbUsesInModelisation; }
public void setNumberOfUsesInModelisation(int nbUses) {
this.nbUsesInModelisation.set(nbUses);
}

public void setNumberOfUsesInInterview(Interview interview, int nbUses) {
this.nbUsesInInterviews.put(interview, nbUses);
if (this.globalVariables.getProject().getSelectedInterview().equals(interview)) {
this.currentInterviewUses.set(nbUses);
}

}

public ReadOnlyIntegerProperty numberOfUsesInModelisationProperty() {
return this.nbUsesInModelisation;
}

public int numberOfUsesInInterviewProperty(Interview interview) {
return this.nbUsesInInterviews.getOrDefault(interview, 0);
}

public int getCurrentInterviewUses() {
return currentInterviewUses.get();
}

public SimpleIntegerProperty currentInterviewUsesProperty() {
return currentInterviewUses;
}

public void setCurrentInterviewUses(int currentInterviewUses) {
this.currentInterviewUses.set(currentInterviewUses);
}


public String getColor() {
Expand All @@ -136,15 +188,21 @@ public String getColor() {

public void setColor(String color) {
this.color.set(color);
for(ConcreteCategoryController c: ListImplements) {
for (ConcreteCategoryController c : ListImplements) {
c.updateColor();
}
}

public void addToControllers(ConcreteCategoryController newController){
public void addToControllers(ConcreteCategoryController newController) {
ListImplements.add(newController);
}
public void removeFromControllers(ConcreteCategoryController Controller){

public void removeFromControllers(ConcreteCategoryController Controller) {
ListImplements.remove(Controller);
}

private final ChangeListener<Interview> onSelectedInterviewChanges = (observableValue, o, t1) -> {
this.nbUsesInInterviews.putIfAbsent(t1, 0);
this.currentInterviewUses.set(this.nbUsesInInterviews.get(t1));
};
}
Loading

0 comments on commit 62cdfb5

Please sign in to comment.