Editor can now send a FileReq and recieve a FileRsp.
This commit is contained in:
parent
edf5d445e5
commit
9caad6b714
6 changed files with 126 additions and 14 deletions
|
|
@ -2,7 +2,6 @@ package com.coder.client.gui.editor;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
|
|
@ -17,12 +16,14 @@ import zutil.log.LogUtil;
|
||||||
import com.coder.client.CoderClient;
|
import com.coder.client.CoderClient;
|
||||||
import com.coder.client.gui.GuiWindow;
|
import com.coder.client.gui.GuiWindow;
|
||||||
import com.coder.client.project.OpenProjectEventHandler;
|
import com.coder.client.project.OpenProjectEventHandler;
|
||||||
import com.coder.client.property.CheckBoxProperty;
|
|
||||||
import com.coder.client.property.CoderClientProperty;
|
import com.coder.client.property.CoderClientProperty;
|
||||||
import com.coder.client.property.ComboBoxProperty;
|
import com.coder.client.property.ComboBoxProperty;
|
||||||
|
import com.coder.client.session.FileRspMsgListener;
|
||||||
import com.coder.client.session.ProjectRspMsgListener;
|
import com.coder.client.session.ProjectRspMsgListener;
|
||||||
import com.coder.client.session.ProjectTypeRspMsgListener;
|
import com.coder.client.session.ProjectTypeRspMsgListener;
|
||||||
import com.coder.server.message.CoderMessage;
|
import com.coder.server.message.CoderMessage;
|
||||||
|
import com.coder.server.message.FileReqMsg;
|
||||||
|
import com.coder.server.message.FileRspMsg;
|
||||||
import com.coder.server.message.ProjectReqMsg;
|
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;
|
||||||
|
|
@ -42,7 +43,7 @@ public class EditorWindow extends GuiWindow {
|
||||||
public static final Logger logger = LogUtil.getLogger();
|
public static final Logger logger = LogUtil.getLogger();
|
||||||
private CoderClient client;
|
private CoderClient client;
|
||||||
|
|
||||||
@FXML private TreeView<String> fileTreeView;
|
@FXML private TreeView<FileTreeItem> fileTreeView;
|
||||||
@FXML private TextArea editTextArea;
|
@FXML private TextArea editTextArea;
|
||||||
@FXML private PropertySheet propertySheet;
|
@FXML private PropertySheet propertySheet;
|
||||||
@FXML private Button compileButton;
|
@FXML private Button compileButton;
|
||||||
|
|
@ -73,12 +74,12 @@ public class EditorWindow extends GuiWindow {
|
||||||
client.showOnStage(EditorWindow.this); //TODO: show "loading project" popup instead
|
client.showOnStage(EditorWindow.this); //TODO: show "loading project" popup instead
|
||||||
|
|
||||||
//handle name and description
|
//handle name and description
|
||||||
fileTreeView.getRoot().setValue(msg.name); //set file tree root name to the project name
|
fileTreeView.getRoot().setValue(new FileTreeDirectory(msg.name)); //set file tree root name to the project name
|
||||||
String projectDescription = msg.description;
|
String projectDescription = msg.description;
|
||||||
|
|
||||||
//handle config
|
//handle config
|
||||||
propertySheet.getItems().clear();
|
propertySheet.getItems().clear();
|
||||||
if(msg.config != null){
|
if(msg.config != null){ //config is an optional parameter
|
||||||
logger.fine("the project has a configuration - populating property sheet");
|
logger.fine("the project has a configuration - populating property sheet");
|
||||||
Enumeration<String> propertyNames = (Enumeration<String>) msg.config.propertyNames();
|
Enumeration<String> propertyNames = (Enumeration<String>) msg.config.propertyNames();
|
||||||
while(propertyNames.hasMoreElements()){ //populate propertySheet with all config elements
|
while(propertyNames.hasMoreElements()){ //populate propertySheet with all config elements
|
||||||
|
|
@ -100,6 +101,7 @@ public class EditorWindow extends GuiWindow {
|
||||||
List<String> fileList = msg.fileList;
|
List<String> fileList = msg.fileList;
|
||||||
fileTreeView.getRoot().getChildren().clear();
|
fileTreeView.getRoot().getChildren().clear();
|
||||||
for(String filePath : fileList){
|
for(String filePath : fileList){
|
||||||
|
String fullPath = filePath;
|
||||||
logger.finer("adding file \""+filePath+"\" to the file tree");
|
logger.finer("adding file \""+filePath+"\" to the file tree");
|
||||||
if(filePath.endsWith("/")){
|
if(filePath.endsWith("/")){
|
||||||
logger.warning("file: \"" + filePath + "\" in file list is a directory and not a file. Currently not supported. Ignoring entry");
|
logger.warning("file: \"" + filePath + "\" in file list is a directory and not a file. Currently not supported. Ignoring entry");
|
||||||
|
|
@ -108,7 +110,7 @@ public class EditorWindow extends GuiWindow {
|
||||||
if(filePath.startsWith("/")){
|
if(filePath.startsWith("/")){
|
||||||
filePath = filePath.substring(1, filePath.length());
|
filePath = filePath.substring(1, filePath.length());
|
||||||
}
|
}
|
||||||
TreeItem<String> tmpParent = fileTreeView.getRoot();
|
TreeItem<FileTreeItem> tmpParent = fileTreeView.getRoot();
|
||||||
String[] filePathSpilt = filePath.split("/");
|
String[] filePathSpilt = filePath.split("/");
|
||||||
for(int i = 0; i < filePathSpilt.length; ++i){
|
for(int i = 0; i < filePathSpilt.length; ++i){
|
||||||
if(i < filePathSpilt.length-1){
|
if(i < filePathSpilt.length-1){
|
||||||
|
|
@ -119,7 +121,7 @@ public class EditorWindow extends GuiWindow {
|
||||||
}else{
|
}else{
|
||||||
logger.finer("adding directory \""+directoryName+"\" to directory \""+tmpParent+"\"");
|
logger.finer("adding directory \""+directoryName+"\" to directory \""+tmpParent+"\"");
|
||||||
}
|
}
|
||||||
TreeItem<String> tmpChild = new TreeItem<String>(directoryName);
|
TreeItem<FileTreeItem> tmpChild = new TreeItem<FileTreeItem>(new FileTreeDirectory(directoryName));
|
||||||
tmpParent.getChildren().add(tmpChild);
|
tmpParent.getChildren().add(tmpChild);
|
||||||
tmpParent = tmpChild;
|
tmpParent = tmpChild;
|
||||||
}else{
|
}else{
|
||||||
|
|
@ -134,12 +136,11 @@ public class EditorWindow extends GuiWindow {
|
||||||
}else{
|
}else{
|
||||||
logger.finer("adding file \""+fileName+"\" to directory \""+tmpParent+"\"");
|
logger.finer("adding file \""+fileName+"\" to directory \""+tmpParent+"\"");
|
||||||
}
|
}
|
||||||
TreeItem<String> tmpChild = new TreeItem<String>(fileName);
|
TreeItem<FileTreeItem> tmpChild = new TreeItem<FileTreeItem>(new FileTreeFile(fileName, fullPath));
|
||||||
tmpParent.getChildren().add(tmpChild);
|
tmpParent.getChildren().add(tmpChild);
|
||||||
tmpParent = tmpChild;
|
tmpParent = tmpChild;
|
||||||
}else{
|
}else{
|
||||||
int index = tmpParent.getChildren().indexOf(fileName);
|
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.");
|
||||||
tmpParent = tmpParent.getChildren().get(index);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -165,6 +166,28 @@ public class EditorWindow extends GuiWindow {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
client.getSessionHandler().addMessageListener(new FileRspMsgListener(){
|
||||||
|
@Override
|
||||||
|
public void messageReceived(FileRspMsg msg) {
|
||||||
|
if(msg.error != null || msg.path == null){
|
||||||
|
if(msg.error != null){
|
||||||
|
logger.severe("recieved error message \""+msg.error+"\" the FileRspMsg");
|
||||||
|
}
|
||||||
|
if(msg.path == null){
|
||||||
|
logger.severe("recieved a file with a null path");
|
||||||
|
setErrorMessage("ERROR: en error occured while loading a file");
|
||||||
|
}else{
|
||||||
|
setErrorMessage("ERROR: en error occured while loading the file: \""+msg.path+"\"");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}else{
|
||||||
|
setErrorMessage("");
|
||||||
|
}
|
||||||
|
logger.fine("recieved file content for file: \""+msg.path+"\"");
|
||||||
|
//TODO: load file content to text area
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
client.getProjectHandler().addprojectEventHandler(new OpenProjectEventHandler() {
|
client.getProjectHandler().addprojectEventHandler(new OpenProjectEventHandler() {
|
||||||
@Override
|
@Override
|
||||||
public void openProject(String projectName) {
|
public void openProject(String projectName) {
|
||||||
|
|
@ -218,16 +241,29 @@ public class EditorWindow extends GuiWindow {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupFileTreeView(){
|
private void setupFileTreeView(){
|
||||||
fileTreeView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<TreeItem<String>>() {
|
fileTreeView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<TreeItem<FileTreeItem>>() {
|
||||||
@Override
|
@Override
|
||||||
public void changed(ObservableValue<? extends TreeItem<String>> item, TreeItem<String> oldValue, TreeItem<String> newValue) {
|
public void changed(ObservableValue<? extends TreeItem<FileTreeItem>> item, TreeItem<FileTreeItem> oldValue, TreeItem<FileTreeItem> newValue) {
|
||||||
if(newValue != fileTreeView.getRoot()){
|
if(newValue != fileTreeView.getRoot()){
|
||||||
System.out.println("INFO: item " + newValue + " selected");
|
FileTreeItem fileTreeItem = newValue.getValue();
|
||||||
|
if(fileTreeItem.isDirectory()){
|
||||||
|
FileTreeDirectory directory = (FileTreeDirectory)fileTreeItem;
|
||||||
|
logger.fine("directory " + directory.getName() + " selected in the file tree");
|
||||||
|
System.out.println();
|
||||||
|
}else{
|
||||||
|
FileTreeFile file = (FileTreeFile)fileTreeItem;
|
||||||
|
logger.fine("file " + file.getName() + " selected in the file tree. The file has the full path: \""+file.getFullPath()+"\"");
|
||||||
|
//sending file request message
|
||||||
|
CoderMessage msg = new CoderMessage();
|
||||||
|
msg.FileReq = new FileReqMsg();
|
||||||
|
msg.FileReq.path = file.getFullPath();
|
||||||
|
client.getSessionHandler().sendMessage(msg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
TreeItem<String> root = new TreeItem<String>("/");
|
TreeItem<FileTreeItem> root = new TreeItem<FileTreeItem>(new FileTreeDirectory("/"));
|
||||||
root.setExpanded(true);
|
root.setExpanded(true);
|
||||||
fileTreeView.setRoot(root);
|
fileTreeView.setRoot(root);
|
||||||
|
|
||||||
|
|
@ -249,6 +285,7 @@ public class EditorWindow extends GuiWindow {
|
||||||
|
|
||||||
propertySheet.getItems().clear();
|
propertySheet.getItems().clear();
|
||||||
|
|
||||||
|
/* EXAMPLE CODE:
|
||||||
ArrayList<String> boards = new ArrayList<String>();
|
ArrayList<String> boards = new ArrayList<String>();
|
||||||
boards.add("UNO");
|
boards.add("UNO");
|
||||||
boards.add("Mega");
|
boards.add("Mega");
|
||||||
|
|
@ -257,6 +294,7 @@ public class EditorWindow extends GuiWindow {
|
||||||
|
|
||||||
CheckBoxProperty p2 = new CheckBoxProperty("Melt?", false);
|
CheckBoxProperty p2 = new CheckBoxProperty("Melt?", false);
|
||||||
propertySheet.getItems().add(p2);
|
propertySheet.getItems().add(p2);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
19
src/com/coder/client/gui/editor/FileTreeDirectory.java
Normal file
19
src/com/coder/client/gui/editor/FileTreeDirectory.java
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
package com.coder.client.gui.editor;
|
||||||
|
|
||||||
|
public class FileTreeDirectory extends FileTreeItem {
|
||||||
|
|
||||||
|
public FileTreeDirectory(String name) {
|
||||||
|
super(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isFile() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isDirectory() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
26
src/com/coder/client/gui/editor/FileTreeFile.java
Normal file
26
src/com/coder/client/gui/editor/FileTreeFile.java
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
package com.coder.client.gui.editor;
|
||||||
|
|
||||||
|
public class FileTreeFile extends FileTreeItem {
|
||||||
|
|
||||||
|
private String fullPath;
|
||||||
|
|
||||||
|
public FileTreeFile(String name, String fullPath) {
|
||||||
|
super(name);
|
||||||
|
this.fullPath = fullPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isFile() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isDirectory() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFullPath(){
|
||||||
|
return this.fullPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
18
src/com/coder/client/gui/editor/FileTreeItem.java
Normal file
18
src/com/coder/client/gui/editor/FileTreeItem.java
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.coder.client.gui.editor;
|
||||||
|
|
||||||
|
public abstract class FileTreeItem {
|
||||||
|
private String name;
|
||||||
|
public FileTreeItem(String name){
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
public String getName(){
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString(){
|
||||||
|
return getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract boolean isFile();
|
||||||
|
public abstract boolean isDirectory();
|
||||||
|
}
|
||||||
7
src/com/coder/client/session/FileRspMsgListener.java
Normal file
7
src/com/coder/client/session/FileRspMsgListener.java
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
package com.coder.client.session;
|
||||||
|
|
||||||
|
import com.coder.server.message.FileRspMsg;
|
||||||
|
|
||||||
|
public interface FileRspMsgListener extends ProjectMessageListener {
|
||||||
|
public void messageReceived(FileRspMsg msg);
|
||||||
|
}
|
||||||
|
|
@ -225,6 +225,10 @@ public class Session extends Thread {
|
||||||
logger.fine("The message contains a ProjectTypeRsp that is forwarded to listener: " + listener);
|
logger.fine("The message contains a ProjectTypeRsp that is forwarded to listener: " + listener);
|
||||||
((ProjectTypeRspMsgListener)listener).messageReceived(msg.ProjectTypeRsp);
|
((ProjectTypeRspMsgListener)listener).messageReceived(msg.ProjectTypeRsp);
|
||||||
}
|
}
|
||||||
|
if(msg.FileRsp != null && listener instanceof FileRspMsgListener){
|
||||||
|
logger.fine("The message contains a FileRsp that is forwarded to listener: " + listener);
|
||||||
|
((FileRspMsgListener)listener).messageReceived(msg.FileRsp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue