From 898f1c58840ebee4a26ee0555c71c0e43dec2e68 Mon Sep 17 00:00:00 2001 From: dcollin Date: Tue, 17 Nov 2015 16:16:29 +0100 Subject: [PATCH] moving logic into a new method in EditorWindow --- .../coder/client/gui/editor/EditorWindow.java | 161 +++++++++--------- 1 file changed, 85 insertions(+), 76 deletions(-) diff --git a/src/com/coder/client/gui/editor/EditorWindow.java b/src/com/coder/client/gui/editor/EditorWindow.java index eac3469..e64afb7 100644 --- a/src/com/coder/client/gui/editor/EditorWindow.java +++ b/src/com/coder/client/gui/editor/EditorWindow.java @@ -2,8 +2,9 @@ package com.coder.client.gui.editor; 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; import java.util.logging.Logger; @@ -78,82 +79,9 @@ public class EditorWindow extends GuiWindow { projectHandler.setProject(msg.name); } - logger.info("loading project \""+msg.name+"\""); - client.showOnStage(EditorWindow.this); //TODO: show "loading project" popup instead - - //handle name and description - fileTreeView.getRoot().setValue(new FileTreeDirectory(msg.name)); //set file tree root name to the project name - String projectDescription = msg.description; - - //handle config - propertySheet.getItems().clear(); - if(msg.config != null){ //config is an optional parameter - logger.fine("the project has a configuration - populating property sheet"); - Enumeration propertyNames = (Enumeration) msg.config.propertyNames(); - while(propertyNames.hasMoreElements()){ //populate propertySheet with all config elements - String propertyName = propertyNames.nextElement(); - String propertyValue = msg.config.getProperty(propertyName); - ComboBoxProperty comboProperty = new ComboBoxProperty(propertyName, propertyValue, null); - propertySheet.getItems().add(comboProperty); - } - - //request alternative values for config of this project type - projectType = msg.type; - sendProjectTypeReqMsg(projectType); - - }else{ - logger.fine("the project has no configuration"); - } + //load project to GUI + loadProject(msg.name, msg.type, msg.description, msg.config, msg.fileList); - //handle file list - List fileList = msg.fileList; - fileTreeView.getRoot().getChildren().clear(); - for(String filePath : fileList){ - String fullPath = filePath; - logger.finer("adding file \""+filePath+"\" to the file tree"); - if(filePath.endsWith("/")){ - logger.warning("file: \"" + filePath + "\" in file list is a directory and not a file. Currently not supported. Ignoring entry"); - continue; - } - if(filePath.startsWith("/")){ - filePath = filePath.substring(1, filePath.length()); - } - TreeItem tmpParent = fileTreeView.getRoot(); - String[] filePathSpilt = filePath.split("/"); - for(int i = 0; i < filePathSpilt.length; ++i){ - if(i < filePathSpilt.length-1){ - String directoryName = filePathSpilt[i]; - if(!tmpParent.getChildren().contains(directoryName)){ - if(tmpParent == fileTreeView.getRoot()){ - logger.finer("adding directory \""+directoryName+"\" to directory \"/\""); - }else{ - logger.finer("adding directory \""+directoryName+"\" to directory \""+tmpParent+"\""); - } - TreeItem tmpChild = new TreeItem(new FileTreeDirectory(directoryName)); - tmpParent.getChildren().add(tmpChild); - tmpParent = tmpChild; - }else{ - int index = tmpParent.getChildren().indexOf(directoryName); - tmpParent = tmpParent.getChildren().get(index); - } - }else{ - String fileName = filePathSpilt[i]; - if(!tmpParent.getChildren().contains(fileName)){ - if(tmpParent == fileTreeView.getRoot()){ - logger.finer("adding file \""+fileName+"\" to directory \"/\""); - }else{ - logger.finer("adding file \""+fileName+"\" to directory \""+tmpParent+"\""); - } - TreeItem tmpChild = new TreeItem(new FileTreeFile(fileName, fullPath)); - tmpParent.getChildren().add(tmpChild); - tmpParent = tmpChild; - }else{ - logger.warning("The project seems to contain two or more files with the same location and name. The file tree presented may be missing files. duplicates not allowed."); - } - } - } - - } }catch(Exception e){ logger.log(Level.SEVERE, "exception while load the project", e); projectHandler.triggerOpenProjectFailureEvent("ERROR: failed to loading project"); @@ -319,5 +247,86 @@ public class EditorWindow extends GuiWindow { public String getDescriptiveName() { return "Editor Window"; } + + private void loadProject(final String projectName, final String projectType, final String projectDescription, final Properties projectConfig, ArrayList projectFileList){ + + logger.info("loading project \""+projectName+"\""); + client.showOnStage(EditorWindow.this); //TODO: show "loading project" popup instead + + //handle name and description + fileTreeView.getRoot().setValue(new FileTreeDirectory(projectName)); //set file tree root name to the project name + + //handle config + propertySheet.getItems().clear(); + if(projectConfig != null){ // projectConfig is an optional parameter + logger.fine("the project has a configuration - populating property sheet"); + Enumeration propertyNames = projectConfig.propertyNames(); + while(propertyNames.hasMoreElements()){ //populate propertySheet with all config elements + Object propertyNameObject = propertyNames.nextElement(); + if(propertyNameObject instanceof String){ + String propertyName = (String)propertyNameObject; + String propertyValue = projectConfig.getProperty(projectName); + ComboBoxProperty comboProperty = new ComboBoxProperty(propertyName, propertyValue, null); + propertySheet.getItems().add(comboProperty); + } + } + + //request alternative values for config of this project type + this.projectType = projectType; + sendProjectTypeReqMsg(projectType); + + }else{ + logger.fine("the project has no configuration"); + } + + //handle file list + fileTreeView.getRoot().getChildren().clear(); + for(String filePath : projectFileList){ + String fullPath = filePath; + logger.finer("adding file \""+filePath+"\" to the file tree"); + if(filePath.endsWith("/")){ + logger.warning("file: \"" + filePath + "\" in file list is a directory and not a file. Currently not supported. Ignoring entry"); + continue; + } + if(filePath.startsWith("/")){ + filePath = filePath.substring(1, filePath.length()); + } + TreeItem tmpParent = fileTreeView.getRoot(); + String[] filePathSpilt = filePath.split("/"); + for(int i = 0; i < filePathSpilt.length; ++i){ + if(i < filePathSpilt.length-1){ + String directoryName = filePathSpilt[i]; + if(!tmpParent.getChildren().contains(directoryName)){ + if(tmpParent == fileTreeView.getRoot()){ + logger.finer("adding directory \""+directoryName+"\" to directory \"/\""); + }else{ + logger.finer("adding directory \""+directoryName+"\" to directory \""+tmpParent+"\""); + } + TreeItem tmpChild = new TreeItem(new FileTreeDirectory(directoryName)); + tmpParent.getChildren().add(tmpChild); + tmpParent = tmpChild; + }else{ + int index = tmpParent.getChildren().indexOf(directoryName); + tmpParent = tmpParent.getChildren().get(index); + } + }else{ + String fileName = filePathSpilt[i]; + if(!tmpParent.getChildren().contains(fileName)){ + if(tmpParent == fileTreeView.getRoot()){ + logger.finer("adding file \""+fileName+"\" to directory \"/\""); + }else{ + logger.finer("adding file \""+fileName+"\" to directory \""+tmpParent+"\""); + } + TreeItem tmpChild = new TreeItem(new FileTreeFile(fileName, fullPath)); + tmpParent.getChildren().add(tmpChild); + tmpParent = tmpChild; + }else{ + logger.warning("The project seems to contain two or more files with the same location and name. The file tree presented may be missing files. duplicates not allowed."); + } + } + } + } + + } }