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
|
|
@ -4,6 +4,7 @@ import java.io.IOException;
|
|||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.ResourceBundle;
|
||||
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.ProjectTypeReqMsg;
|
||||
import com.coder.server.message.ProjectTypeRspMsg;
|
||||
import com.coder.server.message.SupportedProperties;
|
||||
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
|
|
@ -94,9 +96,35 @@ public class EditorWindow extends GuiWindow {
|
|||
sessionHandler.addMessageListener(new ProjectTypeRspMsgListener() {
|
||||
@Override
|
||||
public void messageReceived(ProjectTypeRspMsg msg) {
|
||||
for(String type : msg.keySet()){
|
||||
if(type.equals(projectType)){ //the current project type matches the project type in the message
|
||||
//TODO: handle type specific configurations
|
||||
logger.fine("handling a ProjectTypeRspMsg");
|
||||
for(String type : msg.keySet()){ //for all project types in the ProjectTypeRspMsg
|
||||
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();
|
||||
}
|
||||
|
||||
private void sendProjectTypeReqMsg(String type){
|
||||
CoderMessage msg = new CoderMessage();
|
||||
msg.ProjectTypeReq = new ProjectTypeReqMsg();
|
||||
msg.ProjectTypeReq.type = type;
|
||||
sessionHandler.sendMessage(msg);
|
||||
}
|
||||
|
||||
private void setupFileTreeView(){
|
||||
fileTreeView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<TreeItem<FileTreeItem>>() {
|
||||
@Override
|
||||
|
|
@ -221,16 +242,6 @@ public class EditorWindow extends GuiWindow {
|
|||
|
||||
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
|
||||
|
|
@ -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){
|
||||
|
||||
logger.info("loading project \""+projectName+"\"");
|
||||
client.showOnStage(EditorWindow.this); //TODO: show "loading project" popup instead
|
||||
//TODO: show "loading project" popup
|
||||
|
||||
//handle name and description
|
||||
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
|
||||
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{
|
||||
logger.fine("the project has no configuration");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue