Adding a connection lost event and adding support for recieveing alternative values for a project configuration
This commit is contained in:
parent
898f1c5884
commit
8823e76e85
10 changed files with 77 additions and 33 deletions
|
|
@ -5,6 +5,8 @@ import java.util.HashSet;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
|
|
||||||
import zutil.log.LogUtil;
|
import zutil.log.LogUtil;
|
||||||
|
|
||||||
import com.coder.client.session.ProjectMessageListener;
|
import com.coder.client.session.ProjectMessageListener;
|
||||||
|
|
@ -33,6 +35,7 @@ public class SessionHandler{
|
||||||
|
|
||||||
public boolean setupConnection(String url, int port){
|
public boolean setupConnection(String url, int port){
|
||||||
if(session != null && session.isConnected()){
|
if(session != null && session.isConnected()){
|
||||||
|
logger.fine("setup connection called. there is already an active connection. will terminate the current connection first.");
|
||||||
session.close();
|
session.close();
|
||||||
}
|
}
|
||||||
session = Session.setupConnection(url, port);
|
session = Session.setupConnection(url, port);
|
||||||
|
|
@ -112,15 +115,25 @@ public class SessionHandler{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void triggerAuthenticationCancel() {
|
public void triggerAuthenticationCanceledEvent() {
|
||||||
if(session.isConnected() && !session.isAuthenticated()){
|
if(session.isConnected() && !session.isAuthenticated()){
|
||||||
closeCurrentSession(false);
|
closeCurrentSession(false);
|
||||||
for(SessionEventHandler eventHandler : sessionEventHandlers){
|
for(SessionEventHandler eventHandler : sessionEventHandlers){
|
||||||
eventHandler.sessionAuthenticationCancel();
|
eventHandler.sessionAuthenticationCanceled();
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
logger.warning("Can only cancel a connected but not yet authenticated authentication. ignoring call");
|
logger.warning("Can only cancel a connected but not yet authenticated authentication. ignoring call");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void triggerConnectionLostEvent(){
|
||||||
|
if(session != null){
|
||||||
|
session.close();
|
||||||
|
session = null;
|
||||||
|
for(SessionEventHandler eventHandler : sessionEventHandlers){
|
||||||
|
eventHandler.sessionDisconnected(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
@ -31,6 +32,7 @@ import com.coder.server.message.ProjectReqMsg;
|
||||||
import com.coder.server.message.ProjectRspMsg;
|
import com.coder.server.message.ProjectRspMsg;
|
||||||
import com.coder.server.message.ProjectTypeReqMsg;
|
import com.coder.server.message.ProjectTypeReqMsg;
|
||||||
import com.coder.server.message.ProjectTypeRspMsg;
|
import com.coder.server.message.ProjectTypeRspMsg;
|
||||||
|
import com.coder.server.message.SupportedProperties;
|
||||||
|
|
||||||
import javafx.beans.value.ChangeListener;
|
import javafx.beans.value.ChangeListener;
|
||||||
import javafx.beans.value.ObservableValue;
|
import javafx.beans.value.ObservableValue;
|
||||||
|
|
@ -94,9 +96,35 @@ public class EditorWindow extends GuiWindow {
|
||||||
sessionHandler.addMessageListener(new ProjectTypeRspMsgListener() {
|
sessionHandler.addMessageListener(new ProjectTypeRspMsgListener() {
|
||||||
@Override
|
@Override
|
||||||
public void messageReceived(ProjectTypeRspMsg msg) {
|
public void messageReceived(ProjectTypeRspMsg msg) {
|
||||||
for(String type : msg.keySet()){
|
logger.fine("handling a ProjectTypeRspMsg");
|
||||||
if(type.equals(projectType)){ //the current project type matches the project type in the message
|
for(String type : msg.keySet()){ //for all project types in the ProjectTypeRspMsg
|
||||||
//TODO: handle type specific configurations
|
if(type.equals(projectType)){ //the current project type matches the project type in the message
|
||||||
|
logger.finer("the ProjectTypeRspMsg contins information for the curernt projects type ("+projectType+")");
|
||||||
|
SupportedProperties projectTypeSupportedProperties = msg.get(type); //get list of supported properties
|
||||||
|
for(String propertyName : projectTypeSupportedProperties.keySet()){ //for each property name
|
||||||
|
logger.finer("the project type has a property named \""+propertyName+"\"");
|
||||||
|
List<String> propertyAlternativeValues = projectTypeSupportedProperties.get(propertyName); //get the list of all valid alternative values to the property
|
||||||
|
|
||||||
|
logger.finer("looking for an existing property in the property sheet with the same name");
|
||||||
|
boolean foundProperty = false;
|
||||||
|
for(PropertySheet.Item propertySheetItem : propertySheet.getItems()){ //for all property sheet items in the GUI
|
||||||
|
if(propertySheetItem instanceof ComboBoxProperty){ //if the item is a combo box
|
||||||
|
ComboBoxProperty comboBoxProperty = (ComboBoxProperty) propertySheetItem; //cast to combo box
|
||||||
|
if(comboBoxProperty.getName().equals(propertyName)){ //if combo box property name is the same as the property name
|
||||||
|
logger.finer("the property sheet already contained a property with the same name.");
|
||||||
|
foundProperty = true;
|
||||||
|
logger.finer("adding alternative values to the existing property");
|
||||||
|
comboBoxProperty.setAlternativeValues(propertyAlternativeValues); //add the alternative values
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!foundProperty){
|
||||||
|
logger.finer("the property was not present in the property sheet. adding it.");
|
||||||
|
ComboBoxProperty comboProperty = new ComboBoxProperty(propertyName, null, propertyAlternativeValues);
|
||||||
|
propertySheet.getItems().add(comboProperty);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -169,13 +197,6 @@ public class EditorWindow extends GuiWindow {
|
||||||
client.exit();
|
client.exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendProjectTypeReqMsg(String type){
|
|
||||||
CoderMessage msg = new CoderMessage();
|
|
||||||
msg.ProjectTypeReq = new ProjectTypeReqMsg();
|
|
||||||
msg.ProjectTypeReq.type = type;
|
|
||||||
sessionHandler.sendMessage(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setupFileTreeView(){
|
private void setupFileTreeView(){
|
||||||
fileTreeView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<TreeItem<FileTreeItem>>() {
|
fileTreeView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<TreeItem<FileTreeItem>>() {
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -221,16 +242,6 @@ public class EditorWindow extends GuiWindow {
|
||||||
|
|
||||||
propertySheet.getItems().clear();
|
propertySheet.getItems().clear();
|
||||||
|
|
||||||
/* EXAMPLE CODE:
|
|
||||||
ArrayList<String> boards = new ArrayList<String>();
|
|
||||||
boards.add("UNO");
|
|
||||||
boards.add("Mega");
|
|
||||||
ComboBoxProperty p1 = new ComboBoxProperty("Port", null, boards);
|
|
||||||
propertySheet.getItems().add(p1);
|
|
||||||
|
|
||||||
CheckBoxProperty p2 = new CheckBoxProperty("Melt?", false);
|
|
||||||
propertySheet.getItems().add(p2);
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -251,7 +262,7 @@ public class EditorWindow extends GuiWindow {
|
||||||
private void loadProject(final String projectName, final String projectType, final String projectDescription, final Properties projectConfig, ArrayList<String> projectFileList){
|
private void loadProject(final String projectName, final String projectType, final String projectDescription, final Properties projectConfig, ArrayList<String> projectFileList){
|
||||||
|
|
||||||
logger.info("loading project \""+projectName+"\"");
|
logger.info("loading project \""+projectName+"\"");
|
||||||
client.showOnStage(EditorWindow.this); //TODO: show "loading project" popup instead
|
//TODO: show "loading project" popup
|
||||||
|
|
||||||
//handle name and description
|
//handle name and description
|
||||||
fileTreeView.getRoot().setValue(new FileTreeDirectory(projectName)); //set file tree root name to the project name
|
fileTreeView.getRoot().setValue(new FileTreeDirectory(projectName)); //set file tree root name to the project name
|
||||||
|
|
@ -273,7 +284,12 @@ public class EditorWindow extends GuiWindow {
|
||||||
|
|
||||||
//request alternative values for config of this project type
|
//request alternative values for config of this project type
|
||||||
this.projectType = projectType;
|
this.projectType = projectType;
|
||||||
sendProjectTypeReqMsg(projectType);
|
|
||||||
|
//send ProjectTypeReqMsg for the project type
|
||||||
|
CoderMessage msg = new CoderMessage();
|
||||||
|
msg.ProjectTypeReq = new ProjectTypeReqMsg();
|
||||||
|
msg.ProjectTypeReq.type = projectType;
|
||||||
|
sessionHandler.sendMessage(msg);
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
logger.fine("the project has no configuration");
|
logger.fine("the project has no configuration");
|
||||||
|
|
|
||||||
|
|
@ -58,9 +58,10 @@ public class LoginDialog extends GuiWindow {
|
||||||
@Override
|
@Override
|
||||||
public void sessionAuthenticationFailure() {
|
public void sessionAuthenticationFailure() {
|
||||||
setErrorMessage("Wrong username or password");
|
setErrorMessage("Wrong username or password");
|
||||||
|
passwordPasswordField.setText(null);
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void sessionAuthenticationCancel() {
|
public void sessionAuthenticationCanceled() {
|
||||||
setErrorMessage(null);
|
setErrorMessage(null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -73,9 +74,11 @@ public class LoginDialog extends GuiWindow {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void willShow(){
|
public void willShow(){
|
||||||
passwordPasswordField.setText("");
|
|
||||||
if( (errorLabel.getText() == null || (errorLabel.getText() != null && errorLabel.getText().isEmpty())) && usernameTextField.getText() != null && !usernameTextField.getText().isEmpty()){
|
if( (errorLabel.getText() == null || (errorLabel.getText() != null && errorLabel.getText().isEmpty())) && usernameTextField.getText() != null && !usernameTextField.getText().isEmpty()){
|
||||||
passwordPasswordField.requestFocus();
|
passwordPasswordField.requestFocus();
|
||||||
|
if(passwordPasswordField.getText() != null && !passwordPasswordField.getText().isEmpty()){
|
||||||
|
loginButton.fire();
|
||||||
|
}
|
||||||
}else{
|
}else{
|
||||||
usernameTextField.requestFocus();
|
usernameTextField.requestFocus();
|
||||||
passwordPasswordField.setText("");
|
passwordPasswordField.setText("");
|
||||||
|
|
@ -106,7 +109,7 @@ public class LoginDialog extends GuiWindow {
|
||||||
@FXML
|
@FXML
|
||||||
protected void cancel(ActionEvent event){
|
protected void cancel(ActionEvent event){
|
||||||
logger.fine("cancel button triggered");
|
logger.fine("cancel button triggered");
|
||||||
sessionHandler.triggerAuthenticationCancel();
|
sessionHandler.triggerAuthenticationCanceledEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUsername(String username){
|
public void setUsername(String username){
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,7 @@ public class SelectProjectDialog extends GuiWindow {
|
||||||
|
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void sessionAuthenticationCancel() {
|
public void sessionAuthenticationCanceled() {
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@ import java.util.ResourceBundle;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
|
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.beans.value.ChangeListener;
|
import javafx.beans.value.ChangeListener;
|
||||||
import javafx.beans.value.ObservableValue;
|
import javafx.beans.value.ObservableValue;
|
||||||
|
|
@ -69,6 +71,7 @@ public class SelectServerDialog extends GuiWindow {
|
||||||
logger.info("No reconnection should be performed, reseting server address");
|
logger.info("No reconnection should be performed, reseting server address");
|
||||||
setServerAddress(null);
|
setServerAddress(null);
|
||||||
}else{
|
}else{
|
||||||
|
JOptionPane.showMessageDialog(null, "Connection to server lost. Will try to reconnect.");
|
||||||
setErrorMessage("The current session was disconnected");
|
setErrorMessage("The current session was disconnected");
|
||||||
}
|
}
|
||||||
logger.fine("session disconnected, will show the select server dialog on the main stage");
|
logger.fine("session disconnected, will show the select server dialog on the main stage");
|
||||||
|
|
@ -92,7 +95,7 @@ public class SelectServerDialog extends GuiWindow {
|
||||||
client.showOnStage(SelectServerDialog.this);
|
client.showOnStage(SelectServerDialog.this);
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void sessionAuthenticationCancel() {
|
public void sessionAuthenticationCanceled() {
|
||||||
setServerAddress(null);
|
setServerAddress(null);
|
||||||
setErrorMessage(null);
|
setErrorMessage(null);
|
||||||
logger.fine("session authentication canceled, will show the select server dialog on the main stage");
|
logger.fine("session authentication canceled, will show the select server dialog on the main stage");
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ public abstract class CoderClientProperty<T> implements PropertySheet.Item {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getValue() {
|
public T getValue() {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -29,7 +29,7 @@ public abstract class CoderClientProperty<T> implements PropertySheet.Item {
|
||||||
public boolean isEditable() {
|
public boolean isEditable() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public void setValue(Object value) {
|
public void setValue(Object value) {
|
||||||
|
|
|
||||||
|
|
@ -28,5 +28,12 @@ public class ComboBoxProperty extends CoderClientProperty<String> {
|
||||||
PropertyEditor<?> editor = Editors.createChoiceEditor(this, valueAlternatives);
|
PropertyEditor<?> editor = Editors.createChoiceEditor(this, valueAlternatives);
|
||||||
return editor;
|
return editor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setAlternativeValues(Collection<String> valueAlternatives){
|
||||||
|
this.valueAlternatives = valueAlternatives;
|
||||||
|
if(! valueAlternatives.contains(getValue())){
|
||||||
|
setValue(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
package com.coder.client.session;
|
package com.coder.client.session;
|
||||||
|
|
||||||
public interface ProjectMessageListener {
|
public interface ProjectMessageListener {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ import zutil.log.OutputStreamLogger;
|
||||||
import zutil.parser.json.JSONObjectInputStream;
|
import zutil.parser.json.JSONObjectInputStream;
|
||||||
import zutil.parser.json.JSONObjectOutputStream;
|
import zutil.parser.json.JSONObjectOutputStream;
|
||||||
|
|
||||||
|
import com.coder.client.SessionHandler;
|
||||||
import com.coder.server.message.AuthenticationReqMsg;
|
import com.coder.server.message.AuthenticationReqMsg;
|
||||||
import com.coder.server.message.AuthenticationRspMsg;
|
import com.coder.server.message.AuthenticationRspMsg;
|
||||||
import com.coder.server.message.CoderMessage;
|
import com.coder.server.message.CoderMessage;
|
||||||
|
|
@ -90,6 +91,7 @@ public class Session extends Thread {
|
||||||
}
|
}
|
||||||
logger.fine("the current session will be closed");
|
logger.fine("the current session will be closed");
|
||||||
close();
|
close();
|
||||||
|
SessionHandler.getInstance().triggerConnectionLostEvent();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,6 @@ public interface SessionEventHandler {
|
||||||
|
|
||||||
void sessionDisconnected(boolean tryToEstablishConnection);
|
void sessionDisconnected(boolean tryToEstablishConnection);
|
||||||
|
|
||||||
void sessionAuthenticationCancel();
|
void sessionAuthenticationCanceled();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue