Refactoring: splitting and renaming listeners
-Splitting ProjectListener into multiple event handlers -Renaming SessionListener to SessionEventHandler -Bug fixes
This commit is contained in:
parent
09d15b4a80
commit
b5e56ca2bf
14 changed files with 132 additions and 115 deletions
|
|
@ -16,7 +16,7 @@ import zutil.log.LogUtil;
|
|||
|
||||
import com.coder.client.CoderClient;
|
||||
import com.coder.client.gui.GuiWindow;
|
||||
import com.coder.client.project.ProjectListener;
|
||||
import com.coder.client.project.OpenProjectEventHandler;
|
||||
import com.coder.client.property.CheckBoxProperty;
|
||||
import com.coder.client.property.CoderClientProperty;
|
||||
import com.coder.client.property.ComboBoxProperty;
|
||||
|
|
@ -66,11 +66,12 @@ public class EditorWindow extends GuiWindow {
|
|||
client.getProjectHandler().setProject(null);
|
||||
return;
|
||||
}else{
|
||||
client.showOnStage(EditorWindow.this);
|
||||
client.getProjectHandler().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(msg.name); //set file tree root name to the project name
|
||||
String projectDescription = msg.description;
|
||||
|
|
@ -93,6 +94,7 @@ public class EditorWindow extends GuiWindow {
|
|||
List<String> fileList = msg.fileList;
|
||||
fileTreeView.getRoot().getChildren().clear();
|
||||
for(String filePath : fileList){
|
||||
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;
|
||||
|
|
@ -101,21 +103,48 @@ public class EditorWindow extends GuiWindow {
|
|||
filePath = filePath.substring(1, filePath.length());
|
||||
}
|
||||
TreeItem<String> tmpParent = fileTreeView.getRoot();
|
||||
for(String fileSplit : filePath.split("/")){
|
||||
if(!tmpParent.getChildren().contains(fileSplit)){
|
||||
logger.finer("adding file/directory \""+fileSplit+"\" to directory \""+tmpParent+"\"");
|
||||
TreeItem<String> tmpChild = new TreeItem<String>(fileSplit);
|
||||
tmpParent = tmpChild;
|
||||
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<String> tmpChild = new TreeItem<String>(directoryName);
|
||||
tmpParent.getChildren().add(tmpChild);
|
||||
tmpParent = tmpChild;
|
||||
}else{
|
||||
int index = tmpParent.getChildren().indexOf(directoryName);
|
||||
tmpParent = tmpParent.getChildren().get(index);
|
||||
}
|
||||
}else{
|
||||
int index = tmpParent.getChildren().indexOf(fileSplit);
|
||||
tmpParent = tmpParent.getChildren().get(index);
|
||||
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<String> tmpChild = new TreeItem<String>(fileName);
|
||||
tmpParent.getChildren().add(tmpChild);
|
||||
tmpParent = tmpChild;
|
||||
}else{
|
||||
int index = tmpParent.getChildren().indexOf(fileName);
|
||||
tmpParent = tmpParent.getChildren().get(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}catch(Exception e){
|
||||
logger.log(Level.FINE, "could not load the project", e);
|
||||
client.getProjectHandler().triggerOpenProjectFailure("ERROR: failure while loading project");
|
||||
logger.log(Level.SEVERE, "exception while load the project", e);
|
||||
client.getProjectHandler().triggerOpenProjectFailureEvent("ERROR: failed to loading project");
|
||||
}
|
||||
|
||||
client.showOnStage(EditorWindow.this);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -130,15 +159,7 @@ public class EditorWindow extends GuiWindow {
|
|||
}
|
||||
});
|
||||
|
||||
client.getProjectHandler().addprojectListener(new ProjectListener() {
|
||||
@Override
|
||||
public void selectProject() {
|
||||
|
||||
}
|
||||
@Override
|
||||
public void openProjectFailed(String errorMsg) {
|
||||
|
||||
}
|
||||
client.getProjectHandler().addprojectEventHandler(new OpenProjectEventHandler() {
|
||||
@Override
|
||||
public void openProject(String projectName) {
|
||||
CoderMessage msg = new CoderMessage();
|
||||
|
|
@ -146,10 +167,6 @@ public class EditorWindow extends GuiWindow {
|
|||
msg.ProjectReq.name = projectName;
|
||||
client.getSessionHandler().sendMessage(msg);
|
||||
}
|
||||
@Override
|
||||
public void createNewProject() {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
|
@ -179,7 +196,7 @@ public class EditorWindow extends GuiWindow {
|
|||
@FXML
|
||||
protected void changeProject(ActionEvent event){
|
||||
client.getProjectHandler().setProject(null);
|
||||
client.getProjectHandler().triggerSelectProject();
|
||||
client.getProjectHandler().triggerSelectProjectEvent();
|
||||
}
|
||||
|
||||
@FXML
|
||||
|
|
@ -204,7 +221,7 @@ public class EditorWindow extends GuiWindow {
|
|||
}
|
||||
});
|
||||
|
||||
TreeItem<String> root = new TreeItem<String>("root");
|
||||
TreeItem<String> root = new TreeItem<String>("/");
|
||||
root.setExpanded(true);
|
||||
fileTreeView.setRoot(root);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue