Ajout de la suppressions de capteur

master
Noé GARNIER 2 years ago
parent 439e8c54bb
commit 42b600fcf9

@ -4,7 +4,7 @@
<?import javafx.scene.control.*?> <?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?> <?import javafx.scene.layout.*?>
<GridPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="373.0" prefWidth="277.0" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="view.MainWindow"> <GridPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="373.0" prefWidth="314.0" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="view.MainWindow">
<columnConstraints> <columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" /> <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints> </columnConstraints>
@ -24,7 +24,13 @@
</GridPane.margin> </GridPane.margin>
</Button> </Button>
<Button fx:id="btnAjouterZone" mnemonicParsing="false" onAction="#clickButtonAjouterZone" text="Ajouter CapteurZone" GridPane.halignment="CENTER" GridPane.rowIndex="1" /> <Button fx:id="btnAjouterZone" mnemonicParsing="false" onAction="#clickButtonAjouterZone" text="Ajouter CapteurZone" GridPane.halignment="CENTER" GridPane.rowIndex="1" />
<!-- <Button fx:id="btnVoir" mnemonicParsing="false" onAction="#clickButtonVoir" disable="true" text="Voir" GridPane.rowIndex="1" />--> <Button fx:id="btnVoir" disable="true" mnemonicParsing="false" onAction="#clickButtonVoir" text="Voir" GridPane.halignment="CENTER" GridPane.rowIndex="1" GridPane.valignment="TOP">
<!-- <Button fx:id="btnSupprimer" mnemonicParsing="false" onAction="#clickButtonVoir" text="Supprimer" GridPane.halignment="RIGHT" GridPane.rowIndex="1" />--> <GridPane.margin>
<Insets right="110.0" top="10.0" />
</GridPane.margin></Button>
<Button fx:id="btnSupprimer" disable="true" mnemonicParsing="false" onAction="#clickButtonSupprimer" text="Supprimer" GridPane.halignment="CENTER" GridPane.rowIndex="1" GridPane.valignment="TOP">
<GridPane.margin>
<Insets left="140.0" top="10.0" />
</GridPane.margin></Button>
</children> </children>
</GridPane> </GridPane>

@ -75,5 +75,13 @@
<Insets left="35" /> <Insets left="35" />
</GridPane.margin> </GridPane.margin>
</Label> </Label>
<Button fx:id="btnVoir" disable="true" mnemonicParsing="false" onAction="#clickButtonVoir" text="Voir" GridPane.halignment="CENTER" GridPane.rowIndex="5">
<GridPane.margin>
<Insets right="110.0" />
</GridPane.margin></Button>
<Button fx:id="btnSupprimer" disable="true" mnemonicParsing="false" onAction="#clickButtonSupprimer" text="Supprimer" GridPane.halignment="CENTER" GridPane.rowIndex="5">
<GridPane.margin>
<Insets left="140.0" />
</GridPane.margin></Button>
</children> </children>
</fx:root> </fx:root>

@ -4,7 +4,7 @@
<?import javafx.scene.control.*?> <?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?> <?import javafx.scene.layout.*?>
<GridPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="373.0" prefWidth="277.0" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="view.MainWindow"> <GridPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="373.0" prefWidth="314.0" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="view.MainWindow">
<columnConstraints> <columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" /> <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints> </columnConstraints>
@ -24,7 +24,13 @@
</GridPane.margin> </GridPane.margin>
</Button> </Button>
<Button fx:id="btnAjouterZone" mnemonicParsing="false" onAction="#clickButtonAjouterZone" text="Ajouter CapteurZone" GridPane.halignment="CENTER" GridPane.rowIndex="1" /> <Button fx:id="btnAjouterZone" mnemonicParsing="false" onAction="#clickButtonAjouterZone" text="Ajouter CapteurZone" GridPane.halignment="CENTER" GridPane.rowIndex="1" />
<!-- <Button fx:id="btnVoir" mnemonicParsing="false" onAction="#clickButtonVoir" disable="true" text="Voir" GridPane.rowIndex="1" />--> <Button fx:id="btnVoir" disable="true" mnemonicParsing="false" onAction="#clickButtonVoir" text="Voir" GridPane.halignment="CENTER" GridPane.rowIndex="1" GridPane.valignment="TOP">
<!-- <Button fx:id="btnSupprimer" mnemonicParsing="false" onAction="#clickButtonVoir" text="Supprimer" GridPane.halignment="RIGHT" GridPane.rowIndex="1" />--> <GridPane.margin>
<Insets right="110.0" top="10.0" />
</GridPane.margin></Button>
<Button fx:id="btnSupprimer" disable="true" mnemonicParsing="false" onAction="#clickButtonSupprimer" text="Supprimer" GridPane.halignment="CENTER" GridPane.rowIndex="1" GridPane.valignment="TOP">
<GridPane.margin>
<Insets left="140.0" top="10.0" />
</GridPane.margin></Button>
</children> </children>
</GridPane> </GridPane>

@ -32,6 +32,10 @@ public class DetailZoneWindow extends Visualisateur{
@FXML @FXML
private Button btnAjouter; private Button btnAjouter;
@FXML @FXML
private Button btnVoir;
@FXML
private Button btnSupprimer;
@FXML
private ListView<CapteurAbstrait> listView; private ListView<CapteurAbstrait> listView;
public DetailZoneWindow(CapteurZone capteurZone) throws IOException { public DetailZoneWindow(CapteurZone capteurZone) throws IOException {
@ -78,16 +82,8 @@ public class DetailZoneWindow extends Visualisateur{
}); });
listView.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> { listView.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
try { btnVoir.setDisable(false);
if (lesCapteurs.get(listView.getSelectionModel().getSelectedIndex()).getClass().getSimpleName().equals("CapteurZone")) { btnSupprimer.setDisable(false);
DetailZoneWindow Dzw = new DetailZoneWindow((CapteurZone) lesCapteurs.get(listView.getSelectionModel().getSelectedIndex()));
}
else{
DetailWindow Dw = new DetailWindow((Capteur) lesCapteurs.get(listView.getSelectionModel().getSelectedIndex()));
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}); });
lesCapteurs.addAll(capteurZone.getLesCapteurs()); lesCapteurs.addAll(capteurZone.getLesCapteurs());
@ -104,7 +100,52 @@ public class DetailZoneWindow extends Visualisateur{
lesCapteurs.add(c); lesCapteurs.add(c);
} }
@FXML
private void clickButtonSupprimer() throws Exception{
CapteurAbstrait c = lesCapteurs.get(listView.getSelectionModel().getSelectedIndex());
listView.getItems().remove(listView.getSelectionModel().getSelectedIndex());
if (lesCapteurs.size() == 0) {
btnVoir.setDisable(true);
btnSupprimer.setDisable(true);
}
update();
}
@FXML
private void clickButtonVoir() throws Exception{
try {
if (lesCapteurs.get(listView.getSelectionModel().getSelectedIndex()).getClass().getSimpleName().equals("CapteurZone")) {
DetailZoneWindow Dzw = new DetailZoneWindow((CapteurZone) lesCapteurs.get(listView.getSelectionModel().getSelectedIndex()));
}
else{
DetailWindow Dw = new DetailWindow((Capteur) lesCapteurs.get(listView.getSelectionModel().getSelectedIndex()));
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override @Override
public void update() { public void update() {
lesCapteurs = listView.getItems();
listView.setCellFactory(new Callback<ListView<CapteurAbstrait>, ListCell<CapteurAbstrait>>() {
@Override
public ListCell<CapteurAbstrait> call(ListView<CapteurAbstrait> capteurListView) {
return new ListCell<CapteurAbstrait>(){
@Override
public void updateItem(CapteurAbstrait value, boolean empty) {
super.updateItem(value, empty);
if (value != null) {
textProperty().bind(new SimpleStringProperty(this, "", "")
.concat("[")
.concat(value.getId())
.concat("] ")
.concat(value.getNom())
.concat(" : ")
.concat(value.getTemperature().asString("%.2f°C")));
}
}
};
}
});
} }
} }

@ -54,18 +54,8 @@ public class MainWindow extends Visualisateur{
}); });
listView.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> { listView.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
// btnVoir.setDisable(false); btnVoir.setDisable(false);
// btnSupprimer.setDisable(false); btnSupprimer.setDisable(false);
try {
if (lesCapteurs.get(listView.getSelectionModel().getSelectedIndex()).getClass().getSimpleName().equals("CapteurZone")) {
DetailZoneWindow Dzw = new DetailZoneWindow((CapteurZone) lesCapteurs.get(listView.getSelectionModel().getSelectedIndex()));
}
else{
DetailWindow Dw = new DetailWindow((Capteur) lesCapteurs.get(listView.getSelectionModel().getSelectedIndex()));
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}); });
Capteur capteur1 = new Capteur("Capteur Réaliste", new GenerateurRealiste()); Capteur capteur1 = new Capteur("Capteur Réaliste", new GenerateurRealiste());
@ -91,28 +81,52 @@ public class MainWindow extends Visualisateur{
CapteurZone c = new CapteurZone("Nouveau Capteur Zone", new ArrayList<Capteur>()); CapteurZone c = new CapteurZone("Nouveau Capteur Zone", new ArrayList<Capteur>());
lesCapteurs.add(c); lesCapteurs.add(c);
} }
// @FXML @FXML
// private void clickButtonSupprimer() throws Exception{ private void clickButtonSupprimer() throws Exception{
// CapteurAbstrait c = lesCapteurs.get(listView.getSelectionModel().getSelectedIndex()); CapteurAbstrait c = lesCapteurs.get(listView.getSelectionModel().getSelectedIndex());
// lesCapteurs.remove(c); listView.getItems().remove(listView.getSelectionModel().getSelectedIndex());
// listView.getItems().remove(c); if (lesCapteurs.size() == 0) {
// listView.refresh(); btnVoir.setDisable(true);
// } btnSupprimer.setDisable(true);
// @FXML }
// private void clickButtonVoir() throws Exception{ update();
// try { }
// if (lesCapteurs.get(listView.getSelectionModel().getSelectedIndex()).getClass().getSimpleName().equals("CapteurZone")) { @FXML
// DetailZoneWindow Dzw = new DetailZoneWindow((CapteurZone) lesCapteurs.get(listView.getSelectionModel().getSelectedIndex())); private void clickButtonVoir() throws Exception{
// } try {
// else{ if (lesCapteurs.get(listView.getSelectionModel().getSelectedIndex()).getClass().getSimpleName().equals("CapteurZone")) {
// DetailWindow Dw = new DetailWindow((Capteur) lesCapteurs.get(listView.getSelectionModel().getSelectedIndex())); DetailZoneWindow Dzw = new DetailZoneWindow((CapteurZone) lesCapteurs.get(listView.getSelectionModel().getSelectedIndex()));
// } }
// } catch (IOException e) { else{
// throw new RuntimeException(e); DetailWindow Dw = new DetailWindow((Capteur) lesCapteurs.get(listView.getSelectionModel().getSelectedIndex()));
// } }
// } } catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override @Override
public void update() { public void update() {
listView.refresh(); lesCapteurs = listView.getItems();
listView.setCellFactory(new Callback<ListView<CapteurAbstrait>, ListCell<CapteurAbstrait>>() {
@Override
public ListCell<CapteurAbstrait> call(ListView<CapteurAbstrait> capteurListView) {
return new ListCell<CapteurAbstrait>(){
@Override
public void updateItem(CapteurAbstrait value, boolean empty) {
super.updateItem(value, empty);
if (value != null) {
textProperty().bind(new SimpleStringProperty(this, "", "")
.concat("[")
.concat(value.getId())
.concat("] ")
.concat(value.getNom())
.concat(" : ")
.concat(value.getTemperature().asString("%.2f°C")));
}
}
};
}
});
} }
} }

Loading…
Cancel
Save