Added delete History feat
This commit is contained in:
parent
4d41dac72d
commit
9226d19848
6 changed files with 75 additions and 1 deletions
|
@ -379,5 +379,26 @@ public class DataBaseAccess {
|
|||
throwables.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteHistory(int id1, int id2) {
|
||||
int idPetit;
|
||||
int idGrand;
|
||||
if (id1 > id2) {
|
||||
idGrand = id1;
|
||||
idPetit = id2;
|
||||
} else {
|
||||
idGrand = id2;
|
||||
idPetit = id1;
|
||||
}
|
||||
String nomTable = "Chat" + idPetit + "_" + idGrand;
|
||||
String preparedQuery = "DROP TABLE " + nomTable;
|
||||
PreparedStatement prSt = null;
|
||||
try {
|
||||
prSt = con.prepareStatement(preparedQuery);
|
||||
prSt.executeUpdate();
|
||||
} catch (SQLException throwables) {
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -469,6 +469,24 @@ ID 2 -> Listening on 6002, sending on 5002, tcpServer on 7002
|
|||
}
|
||||
}
|
||||
|
||||
public void deleteHistory(String remotePseudo) {
|
||||
int remoteId = this.getUserFromPseudo(remotePseudo).getId();
|
||||
for (TCPChatConnection tcpCo : this.listTCPConnection){
|
||||
if (tcpCo.remoteUserId == remoteId){
|
||||
this.listTCPConnection.remove(tcpCo);
|
||||
tcpCo.sendCloseChat();
|
||||
Socket link = tcpCo.getSocket();
|
||||
try {
|
||||
link.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.dbAccess.deleteHistory(remoteId,user.getId());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Classe interne au model pour au bout d'une seconde d'envoi de demande pseudo type 1,
|
||||
|
|
|
@ -92,7 +92,6 @@ public class TCPChatConnection extends Thread{
|
|||
this.support.addPropertyChangeListener("connectionChatClosed",pcl);
|
||||
this.support.addPropertyChangeListener("userDisconnected",pcl);
|
||||
this.support.addPropertyChangeListener("fileReceived",pcl);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -24,6 +24,8 @@ import javafx.scene.control.MenuItem;
|
|||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.input.KeyCode;
|
||||
import javafx.scene.input.KeyEvent;
|
||||
import javafx.scene.layout.*;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.paint.Paint;
|
||||
|
@ -334,6 +336,7 @@ public class ChatWindowController implements Initializable, PropertyChangeListen
|
|||
}
|
||||
});
|
||||
}
|
||||
break;
|
||||
case "fileReceived" :
|
||||
MessageDisplayFile msgFile = tcpCo.getMessageFileReceived();
|
||||
Platform.runLater(new Runnable() {
|
||||
|
@ -400,6 +403,12 @@ public class ChatWindowController implements Initializable, PropertyChangeListen
|
|||
Platform.runLater(mainStage::close);
|
||||
}
|
||||
});
|
||||
mainStage.getScene().setOnKeyPressed(e -> {
|
||||
if (e.getCode() == KeyCode.ENTER) {
|
||||
System.out.println("Fire");
|
||||
this.sendButton.fire();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@FXML
|
||||
|
@ -410,6 +419,7 @@ public class ChatWindowController implements Initializable, PropertyChangeListen
|
|||
|
||||
@FXML
|
||||
void pickFile(ActionEvent event) {
|
||||
File previousFile = this.filePicked;
|
||||
this.fileChooser = new FileChooser();
|
||||
this.filePicked = this.fileChooser.showOpenDialog(this.rootAnchor.getScene().getWindow());
|
||||
if (this.filePicked != null){
|
||||
|
@ -423,11 +433,16 @@ public class ChatWindowController implements Initializable, PropertyChangeListen
|
|||
this.labelFile.setVisible(true);
|
||||
}
|
||||
}
|
||||
else{
|
||||
this.filePicked = previousFile;
|
||||
}
|
||||
this.sendButton.requestFocus();
|
||||
}
|
||||
|
||||
@FXML
|
||||
void removeFile(ActionEvent event) {
|
||||
this.labelFile.setVisible(false);
|
||||
this.filePicked = null;
|
||||
this.sendButton.requestFocus();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package app.insa.clav.UIControllers;
|
|||
import app.insa.clav.Core.DataBaseAccess;
|
||||
import app.insa.clav.Core.Model;
|
||||
import app.insa.clav.Core.Utilisateurs;
|
||||
import com.jfoenix.controls.JFXButton;
|
||||
import com.jfoenix.controls.JFXDrawer;
|
||||
import com.jfoenix.controls.JFXHamburger;
|
||||
import com.jfoenix.controls.JFXListView;
|
||||
|
@ -32,6 +33,7 @@ import java.beans.PropertyChangeListener;
|
|||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.Comparator;
|
||||
import java.util.Optional;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
@ -94,6 +96,9 @@ public class MainWindowController implements PropertyChangeListener, Initializab
|
|||
private MenuItem openChatButton;
|
||||
|
||||
|
||||
@FXML
|
||||
private MenuItem deleteHistoryButton;
|
||||
|
||||
/**
|
||||
* Contructeur. Il crée lui même l'UI (plus tard on mettra quel type de fenetre en argument)
|
||||
*/
|
||||
|
@ -178,4 +183,19 @@ public class MainWindowController implements PropertyChangeListener, Initializab
|
|||
}
|
||||
model.createChatFromLocalRequest(remoteId, remotePseudo);
|
||||
}
|
||||
|
||||
@FXML
|
||||
void deleteHistory(ActionEvent event) {
|
||||
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
|
||||
alert.setTitle("Confirmation Delete History");
|
||||
String remotePseudo = userListView.getFocusModel().getFocusedItem();
|
||||
alert.setHeaderText("Delete history with " + remotePseudo + "?");
|
||||
alert.setContentText("This will also delete it for "+ remotePseudo + "!");
|
||||
Optional<ButtonType> result = alert.showAndWait();
|
||||
|
||||
if (result.isPresent() && result.get() == ButtonType.OK){
|
||||
this.model.deleteHistory(remotePseudo);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
<ContextMenu>
|
||||
<items>
|
||||
<MenuItem fx:id="openChatButton" mnemonicParsing="false" onAction="#openChat" text="Open Chat" />
|
||||
<MenuItem fx:id="deleteHistoryButton" mnemonicParsing="false" onAction="#deleteHistory" text="Delete History" />
|
||||
</items>
|
||||
</ContextMenu>
|
||||
</contextMenu></JFXListView>
|
||||
|
|
Loading…
Reference in a new issue