moving logic into a new method in EditorWindow
This commit is contained in:
parent
dfbdbb5bfe
commit
898f1c5884
1 changed files with 85 additions and 76 deletions
|
|
@ -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<String> propertyNames = (Enumeration<String>) 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<String> 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<FileTreeItem> 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<FileTreeItem> tmpChild = new TreeItem<FileTreeItem>(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<FileTreeItem> tmpChild = new TreeItem<FileTreeItem>(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<String> 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<FileTreeItem> 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<FileTreeItem> tmpChild = new TreeItem<FileTreeItem>(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<FileTreeItem> tmpChild = new TreeItem<FileTreeItem>(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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue