mirror of
https://github.com/Akomry/sae302_applicom.git
synced 2025-12-06 11:43:53 +00:00
fix(contextMenu): Passage de l'ancien body à la fenêtre de dialogue, message supprimé plus éditable, changement de la couleur d'un message supprimé
This commit is contained in:
parent
c5bb9d9af2
commit
bd0801eb34
5 changed files with 94 additions and 15 deletions
|
|
@ -204,7 +204,8 @@ public class ChatController implements Initializable {
|
||||||
* @param e L'évènement associé à un clic droit sur la PostListView
|
* @param e L'évènement associé à un clic droit sur la PostListView
|
||||||
*/
|
*/
|
||||||
private void handleContextMenu(ContextMenuEvent e) {
|
private void handleContextMenu(ContextMenuEvent e) {
|
||||||
if (postListView.getSelectionModel().getSelectedItem().getFrom().equals(contact.getLogin())) {
|
Post post = postListView.getSelectionModel().getSelectedItem();
|
||||||
|
if (post.getFrom().equals(contact.getLogin()) && post.isEditable()) {
|
||||||
contextMenu.show(postListView, e.getScreenX(), e.getScreenY());
|
contextMenu.show(postListView, e.getScreenX(), e.getScreenY());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -242,14 +243,18 @@ public class ChatController implements Initializable {
|
||||||
String from = postListView.getSelectionModel().getSelectedItem().getFrom();
|
String from = postListView.getSelectionModel().getSelectedItem().getFrom();
|
||||||
String to = postListView.getSelectionModel().getSelectedItem().getTo();
|
String to = postListView.getSelectionModel().getSelectedItem().getTo();
|
||||||
try {
|
try {
|
||||||
ModifyMessageController controller = showNewStage(i18nBundle.getString("messageEdit"), "modifymessage-view.fxml");
|
ModifyMessageController controller = showModifyMessageStage(
|
||||||
|
i18nBundle.getString("messageEdit"),
|
||||||
Post post = new Post(postUUID, timestamp, from, to, controller.hostTextField.getText());
|
"modifymessage-view.fxml",
|
||||||
client.sendPostEvent(post);
|
postListView.getSelectionModel().getSelectedItem().getBody()
|
||||||
postVector.remove(postListView.getSelectionModel().getSelectedItem());
|
);
|
||||||
postsObservableList.remove(postListView.getSelectionModel().getSelectedItem());
|
if (controller.isOk()) {
|
||||||
postListView.refresh();
|
Post post = new Post(postUUID, timestamp, from, to, controller.hostTextField.getText());
|
||||||
|
client.sendPostEvent(post);
|
||||||
|
postVector.remove(postListView.getSelectionModel().getSelectedItem());
|
||||||
|
postsObservableList.remove(postListView.getSelectionModel().getSelectedItem());
|
||||||
|
postListView.refresh();
|
||||||
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LOGGER.warning("Can't open modify message view!");
|
LOGGER.warning("Can't open modify message view!");
|
||||||
}
|
}
|
||||||
|
|
@ -266,7 +271,9 @@ public class ChatController implements Initializable {
|
||||||
long timestamp = postListView.getSelectionModel().getSelectedItem().getTimestamp();
|
long timestamp = postListView.getSelectionModel().getSelectedItem().getTimestamp();
|
||||||
String from = postListView.getSelectionModel().getSelectedItem().getFrom();
|
String from = postListView.getSelectionModel().getSelectedItem().getFrom();
|
||||||
String to = postListView.getSelectionModel().getSelectedItem().getTo();
|
String to = postListView.getSelectionModel().getSelectedItem().getTo();
|
||||||
client.sendPostEvent(new Post(postUUID, timestamp, from, to, "Ce message a été supprimé."));
|
Post post = new Post(postUUID, timestamp, from, to, "Ce message a été supprimé.");
|
||||||
|
post.setEditable(false);
|
||||||
|
client.sendPostEvent(post);
|
||||||
postVector.remove(postListView.getSelectionModel().getSelectedItem());
|
postVector.remove(postListView.getSelectionModel().getSelectedItem());
|
||||||
postsObservableList.remove(postListView.getSelectionModel().getSelectedItem());
|
postsObservableList.remove(postListView.getSelectionModel().getSelectedItem());
|
||||||
postListView.refresh();
|
postListView.refresh();
|
||||||
|
|
@ -312,6 +319,31 @@ public class ChatController implements Initializable {
|
||||||
return fxmlLoader.getController();
|
return fxmlLoader.getController();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ouvre une fenêtre de modification de message et attend qu'elle se ferme.
|
||||||
|
*
|
||||||
|
* @param title titre de la fenêtre
|
||||||
|
* @param fxmlFileName nom du fichier FXML décrivant l'interface graphique
|
||||||
|
* @param parameter paramètre éventuel au format textuel
|
||||||
|
* @return l'objet contrôleur associé à la fenêtre
|
||||||
|
* @throws IOException si le fichier FXML n'est pas trouvé dans les ressources
|
||||||
|
*/
|
||||||
|
public <T> T showModifyMessageStage(String title, String fxmlFileName, String parameter) throws IOException {
|
||||||
|
FXMLLoader fxmlLoader = new FXMLLoader(ChatApplication.class.getResource(fxmlFileName), i18nBundle);
|
||||||
|
Scene scene = new Scene(fxmlLoader.load());
|
||||||
|
Stage stage = new Stage();
|
||||||
|
ModifyMessageController controller = fxmlLoader.getController();
|
||||||
|
controller.setOldBody(parameter);
|
||||||
|
stage.initModality(Modality.APPLICATION_MODAL);
|
||||||
|
stage.setTitle(title);
|
||||||
|
stage.setResizable(false);
|
||||||
|
stage.setScene(scene);
|
||||||
|
stage.showAndWait();
|
||||||
|
return fxmlLoader.getController();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialise RoomListView avec sa CelFactory et sa liste observable
|
* Initialise RoomListView avec sa CelFactory et sa liste observable
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package rtgre.chat;
|
package rtgre.chat;
|
||||||
|
|
||||||
|
import javafx.application.Platform;
|
||||||
import javafx.event.ActionEvent;
|
import javafx.event.ActionEvent;
|
||||||
import javafx.fxml.Initializable;
|
import javafx.fxml.Initializable;
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
|
|
@ -22,7 +23,24 @@ public class ModifyMessageController implements Initializable {
|
||||||
public Button submitButton;
|
public Button submitButton;
|
||||||
/** Si la vue possède une valeur de retour */
|
/** Si la vue possède une valeur de retour */
|
||||||
private Boolean ok;
|
private Boolean ok;
|
||||||
|
/** Valeur de l'ancien post */
|
||||||
|
private String oldBody = "";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter de oldBody
|
||||||
|
* @return Renvoie le contenu de l'ancien Post
|
||||||
|
*/
|
||||||
|
public String getOldBody() {
|
||||||
|
return oldBody;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter de oldBody
|
||||||
|
* @param oldBody le contenu de l'ancien post
|
||||||
|
*/
|
||||||
|
public void setOldBody(String oldBody) {
|
||||||
|
this.oldBody = oldBody;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialisation du composant graphique
|
* Initialisation du composant graphique
|
||||||
|
|
@ -34,6 +52,7 @@ public class ModifyMessageController implements Initializable {
|
||||||
resetButton.setOnAction(this::onActionReset);
|
resetButton.setOnAction(this::onActionReset);
|
||||||
submitButton.setOnAction(this::onActionSubmit);
|
submitButton.setOnAction(this::onActionSubmit);
|
||||||
hostTextField.setOnAction(this::onActionSubmit);
|
hostTextField.setOnAction(this::onActionSubmit);
|
||||||
|
Platform.runLater(() -> hostTextField.setText(oldBody));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -42,7 +61,7 @@ public class ModifyMessageController implements Initializable {
|
||||||
* @param actionEvent L'évènement associé au clic sur le bouton Reset
|
* @param actionEvent L'évènement associé au clic sur le bouton Reset
|
||||||
*/
|
*/
|
||||||
private void onActionReset(ActionEvent actionEvent) {
|
private void onActionReset(ActionEvent actionEvent) {
|
||||||
hostTextField.setText("");
|
hostTextField.setText(oldBody);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -97,6 +97,9 @@ public class PostListViewCell extends ListCell<Post> {
|
||||||
tf.setBackground(Background.fill(Color.web("#FEE")));
|
tf.setBackground(Background.fill(Color.web("#FEE")));
|
||||||
hBox.setAlignment(Pos.CENTER_LEFT);
|
hBox.setAlignment(Pos.CENTER_LEFT);
|
||||||
}
|
}
|
||||||
|
if (!post.isEditable()) {
|
||||||
|
tf.setBackground(Background.fill(Color.web("#808080")));
|
||||||
|
}
|
||||||
setGraphic(hBox);
|
setGraphic(hBox);
|
||||||
getListView().scrollTo(getListView().getItems().size() - 1);
|
getListView().scrollTo(getListView().getItems().size() - 1);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,8 @@ public class DatabaseApi {
|
||||||
+ " `timestamp` long,"
|
+ " `timestamp` long,"
|
||||||
+ " `from` text,"
|
+ " `from` text,"
|
||||||
+ " `to` text,"
|
+ " `to` text,"
|
||||||
+ " `body` text"
|
+ " `body` text,"
|
||||||
|
+ " `connected` boolean"
|
||||||
+ ");";
|
+ ");";
|
||||||
stmt = con.createStatement();
|
stmt = con.createStatement();
|
||||||
stmt.execute(sql);
|
stmt.execute(sql);
|
||||||
|
|
@ -105,7 +106,7 @@ public class DatabaseApi {
|
||||||
* @return `true` si le post a bien été ajouté, `false` si une erreur est survenue
|
* @return `true` si le post a bien été ajouté, `false` si une erreur est survenue
|
||||||
*/
|
*/
|
||||||
public boolean addPost(Post post) {
|
public boolean addPost(Post post) {
|
||||||
String query = "INSERT INTO posts VALUES (?, ?, ?, ?, ?)";
|
String query = "INSERT INTO posts VALUES (?, ?, ?, ?, ?, ?)";
|
||||||
try {
|
try {
|
||||||
PreparedStatement pstmt = con.prepareStatement(query);
|
PreparedStatement pstmt = con.prepareStatement(query);
|
||||||
pstmt.setString(1, post.getId().toString());
|
pstmt.setString(1, post.getId().toString());
|
||||||
|
|
@ -113,6 +114,7 @@ public class DatabaseApi {
|
||||||
pstmt.setString(3, post.getFrom());
|
pstmt.setString(3, post.getFrom());
|
||||||
pstmt.setString(4, post.getTo());
|
pstmt.setString(4, post.getTo());
|
||||||
pstmt.setString(5, post.getBody());
|
pstmt.setString(5, post.getBody());
|
||||||
|
pstmt.setBoolean(6, post.isEditable());
|
||||||
|
|
||||||
pstmt.executeUpdate();
|
pstmt.executeUpdate();
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,24 @@ public class Post extends Message {
|
||||||
/** Login du contact qui a envoyé ce post */
|
/** Login du contact qui a envoyé ce post */
|
||||||
protected String from;
|
protected String from;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter de `editable`
|
||||||
|
* @return Le post est-il éditable/supprimé ?
|
||||||
|
*/
|
||||||
|
public boolean isEditable() {
|
||||||
|
return editable;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter de `editable`
|
||||||
|
* @param editable Le statut d'éditabilité du message
|
||||||
|
*/
|
||||||
|
public void setEditable(boolean editable) {
|
||||||
|
this.editable = editable;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Post éditable ? */
|
||||||
|
protected boolean editable = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructeur par défaut
|
* Constructeur par défaut
|
||||||
|
|
@ -130,7 +148,8 @@ public class Post extends Message {
|
||||||
.put("timestamp", this.timestamp)
|
.put("timestamp", this.timestamp)
|
||||||
.put("from", this.from)
|
.put("from", this.from)
|
||||||
.put("to", this.to)
|
.put("to", this.to)
|
||||||
.put("body", this.body);
|
.put("body", this.body)
|
||||||
|
.put("editable", this.editable);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -148,12 +167,16 @@ public class Post extends Message {
|
||||||
* @return Le post créé
|
* @return Le post créé
|
||||||
*/
|
*/
|
||||||
public static Post fromJson(JSONObject jsonObject) {
|
public static Post fromJson(JSONObject jsonObject) {
|
||||||
return new Post(
|
Post post = new Post(
|
||||||
UUID.fromString(jsonObject.getString("id")),
|
UUID.fromString(jsonObject.getString("id")),
|
||||||
jsonObject.getLong("timestamp"),
|
jsonObject.getLong("timestamp"),
|
||||||
jsonObject.getString("from"),
|
jsonObject.getString("from"),
|
||||||
jsonObject.getString("to"),
|
jsonObject.getString("to"),
|
||||||
jsonObject.getString("body")
|
jsonObject.getString("body")
|
||||||
);
|
);
|
||||||
|
if (jsonObject.has("editable")) {
|
||||||
|
post.setEditable(jsonObject.getBoolean("editable"));
|
||||||
|
}
|
||||||
|
return post;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue