Moving state variables from CoderClient to each GUI window.
This commit is contained in:
parent
6db9f94014
commit
eb71b4da59
6 changed files with 107 additions and 112 deletions
|
|
@ -1,9 +1,9 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry excluding="com/coder/client/gui/GUIManager.java|com/coder/client/CoderClient2.java|com/coder/client/LoginDialog.java|com/coder/client/ProjectEditorWindow.java|com/coder/client/ProjectFileTreeModel.java|com/coder/client/LoginCridentials.java|com/coder/client/ProjectSelectDialog.java|com/coder/client/gui/GUI_TEST_MAIN.java" kind="src" path="src"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/ZUtil"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/CoderServer"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/java-8-openjdk-i386"/>
|
||||
<classpathentry kind="lib" path="lib/controlsfx-8.20.9.jar"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/Zutil-java"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
|
|
|||
9
.project
9
.project
|
|
@ -10,15 +10,6 @@
|
|||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
|
||||
<arguments>
|
||||
<dictionary>
|
||||
<key>LaunchConfigHandle</key>
|
||||
<value><project>/.externalToolBuilders/ANT Build.launch</value>
|
||||
</dictionary>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.coder.client;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
|
@ -50,11 +51,6 @@ public class CoderClient extends Application{
|
|||
private NewProjectDialog newProjectDialog;
|
||||
|
||||
//state variables
|
||||
private String serverURL = null;
|
||||
private int serverPort = CoderServer.SERVER_PORT;
|
||||
private String username = null;
|
||||
private char[] password = null; //should only be anything else than null if defined by program argument
|
||||
private String project = null;
|
||||
private GuiWindow projectSelectionWindow = null; //points to the GUI that selected a project for the editor. If any error occurs while creating/loading the project, this is the window we will go back to.
|
||||
|
||||
//services
|
||||
|
|
@ -71,30 +67,6 @@ public class CoderClient extends Application{
|
|||
LogUtil.setGlobalLevel(Level.INFO);
|
||||
LogUtil.setGlobalFormatter(new CompactLogFormatter());
|
||||
|
||||
//parse program arguments
|
||||
Map<String, String> params = this.getParameters().getNamed();
|
||||
for(String key : params.keySet()){
|
||||
String value = params.get(key);
|
||||
if(key.equals("username")){
|
||||
this.username = value;
|
||||
}else if(key.equals("password")){
|
||||
this.password = value.toCharArray();
|
||||
}else if(key.equals("url")){
|
||||
this.serverURL = value;
|
||||
}else if(key.equals("port")){
|
||||
try{
|
||||
this.serverPort = Integer.parseInt(value);
|
||||
}catch(NumberFormatException e){
|
||||
logger.warning("port argument to program is not of a integer type. using default port.");
|
||||
}
|
||||
}else if(key.equals("project")){
|
||||
this.project = value;
|
||||
}
|
||||
}
|
||||
if(this.username == null){ //ignore the password if no username was set
|
||||
this.password = null;
|
||||
}
|
||||
|
||||
//setup GUI elements
|
||||
this.mainStage = mainStage;
|
||||
mainStage.setTitle("CoderClient");
|
||||
|
|
@ -109,6 +81,28 @@ public class CoderClient extends Application{
|
|||
System.exit(1);
|
||||
}
|
||||
|
||||
//parse program arguments
|
||||
Map<String, String> params = this.getParameters().getNamed();
|
||||
for(String key : params.keySet()){
|
||||
String value = params.get(key);
|
||||
if(key.equals("username")){
|
||||
loginDialog.setUsername(value);
|
||||
}else if(key.equals("password")){
|
||||
loginDialog.setPassword(value.toCharArray());
|
||||
}else if(key.equals("url")){
|
||||
selectServerDialog.setServerAddress(value);
|
||||
}else if(key.equals("port")){
|
||||
try{
|
||||
selectServerDialog.setServerPort(Integer.parseInt(value));
|
||||
}catch(NumberFormatException e){
|
||||
logger.warning("port argument to program is not of a integer type. using default port.");
|
||||
selectServerDialog.setServerPort(CoderServer.SERVER_PORT);
|
||||
}
|
||||
}else if(key.equals("project")){
|
||||
selectProjectDialog.setProject(value);
|
||||
}
|
||||
}
|
||||
|
||||
//setup SSDP client
|
||||
try{
|
||||
setupSSDPClient();
|
||||
|
|
@ -118,6 +112,7 @@ public class CoderClient extends Application{
|
|||
}
|
||||
|
||||
//start program logic
|
||||
selectServerDialog.setServerPort(CoderServer.SERVER_PORT);
|
||||
selectServerDialog.showOnStage(mainStage);
|
||||
|
||||
}
|
||||
|
|
@ -135,8 +130,6 @@ public class CoderClient extends Application{
|
|||
}else{
|
||||
logger.severe("could not send a SSDP request since the client is not setup");
|
||||
}
|
||||
selectServerDialog.setServerAddress(serverURL);
|
||||
selectServerDialog.setServerPort(serverPort);
|
||||
}
|
||||
@Override
|
||||
public void exit() {
|
||||
|
|
@ -145,15 +138,13 @@ public class CoderClient extends Application{
|
|||
}
|
||||
@Override
|
||||
public void connect(String address, int port) {
|
||||
serverURL = address;
|
||||
serverPort = port;
|
||||
//connect session
|
||||
session = Session.setupConnection(serverURL, serverPort);
|
||||
session = Session.setupConnection(address, port);
|
||||
if(session == null){
|
||||
logger.warning("Could not setup a connection to " + serverURL + ":" + port);
|
||||
serverURL = null;
|
||||
serverPort = CoderServer.SERVER_PORT;
|
||||
logger.warning("Could not setup a connection to " + address + ":" + port);
|
||||
selectServerDialog.setServerAddress(null);
|
||||
selectServerDialog.setErrorMessage("ERROR: Unable to connect to remote host");
|
||||
loginDialog.setErrorMessage("");
|
||||
selectServerDialog.showOnStage(mainStage);
|
||||
}else{
|
||||
selectServerDialog.setErrorMessage("");
|
||||
|
|
@ -169,6 +160,7 @@ public class CoderClient extends Application{
|
|||
@Override
|
||||
public void run() {
|
||||
selectServerDialog.setErrorMessage("The current session was disconnected");
|
||||
closeCurrentSession();
|
||||
selectServerDialog.showOnStage(mainStage);
|
||||
}
|
||||
});
|
||||
|
|
@ -189,24 +181,20 @@ public class CoderClient extends Application{
|
|||
this.loginDialog.addLoginDialogListener(new LoginDialogListener(){
|
||||
@Override
|
||||
public void willShow() {
|
||||
loginDialog.setUsername(username);
|
||||
loginDialog.setPassword(password);
|
||||
|
||||
}
|
||||
@Override
|
||||
public void cancel() {
|
||||
serverURL = null;
|
||||
serverPort = CoderServer.SERVER_PORT;
|
||||
selectServerDialog.setServerAddress(null);
|
||||
selectServerDialog.showOnStage(mainStage);
|
||||
}
|
||||
@Override
|
||||
public void login(String uname, char[] paswd) {
|
||||
username = uname;
|
||||
password = paswd;
|
||||
public void login(String username, char[] password) {
|
||||
//authenticate session
|
||||
boolean authenticated = session.authenticate(username, password);
|
||||
if(!authenticated){
|
||||
logger.severe("Authentication failed: wrong username or password");
|
||||
password = null;
|
||||
loginDialog.setPassword(null);
|
||||
loginDialog.setErrorMessage("Wrong username or password");
|
||||
selectServerDialog.showOnStage(mainStage);
|
||||
return;
|
||||
|
|
@ -254,20 +242,25 @@ public class CoderClient extends Application{
|
|||
public void run() {
|
||||
if(projectRspMsg.error != null){
|
||||
logger.severe("Server responded on the project request with the following error message: " + projectRspMsg.error);
|
||||
project = null;
|
||||
selectProjectDialog.setProject(null);
|
||||
if(projectSelectionWindow != null){
|
||||
projectSelectionWindow.setErrorMessage("ERROR: " + projectRspMsg.error);
|
||||
projectSelectionWindow.showOnStage(mainStage);
|
||||
return;
|
||||
}else{
|
||||
logger.severe("Undefined error message handler. Unrecoverable state. Terminating");
|
||||
Platform.exit();
|
||||
selectProjectDialog.setErrorMessage("ERROR: " + projectRspMsg.error);
|
||||
selectProjectDialog.showOnStage(mainStage);
|
||||
return;
|
||||
}
|
||||
}else{
|
||||
if(projectSelectionWindow != null){
|
||||
projectSelectionWindow.setErrorMessage("");
|
||||
}
|
||||
ConfigData projectConfig = projectRspMsg.config;
|
||||
String projectDescription = projectRspMsg.description;
|
||||
List<String> projectFileList = projectRspMsg.fileList;
|
||||
String projectName = projectRspMsg.name;
|
||||
String projectType = projectRspMsg.type;
|
||||
//TODO: handle msg
|
||||
}
|
||||
}
|
||||
|
|
@ -295,26 +288,23 @@ public class CoderClient extends Application{
|
|||
@Override
|
||||
public void willShow() {
|
||||
selectProjectDialog.clearProjectList();
|
||||
if(project == null || project.isEmpty()){
|
||||
if(!selectProjectDialog.isProjectSelected()){
|
||||
sendProjectListReq();
|
||||
}
|
||||
selectProjectDialog.setProject(project);
|
||||
}
|
||||
@Override
|
||||
public void open(String selectedProjectName) {
|
||||
projectSelectionWindow = selectProjectDialog;
|
||||
project = selectedProjectName;
|
||||
editorWindow.showOnStage(mainStage);
|
||||
}
|
||||
@Override
|
||||
public void newProject() {
|
||||
project = null;
|
||||
selectProjectDialog.setProject(null);
|
||||
newProjectDialog.showOnStage(mainStage);
|
||||
}
|
||||
@Override
|
||||
public void cancel() {
|
||||
serverURL = null;
|
||||
serverPort = CoderServer.SERVER_PORT;
|
||||
selectServerDialog.setServerAddress(null);
|
||||
selectServerDialog.showOnStage(mainStage);
|
||||
}
|
||||
@Override
|
||||
|
|
@ -348,7 +338,7 @@ public class CoderClient extends Application{
|
|||
public void create(String newProjectName, String projectType) {
|
||||
projectSelectionWindow = newProjectDialog;
|
||||
sendProjectCreateReqMsg(newProjectName, projectType);
|
||||
project = newProjectName;
|
||||
selectProjectDialog.setProject(newProjectName);
|
||||
editorWindow.showOnStage(mainStage);
|
||||
}
|
||||
private void sendProjectTypeReqMsg(){
|
||||
|
|
@ -375,7 +365,7 @@ public class CoderClient extends Application{
|
|||
}
|
||||
@Override
|
||||
public void cancel() {
|
||||
project = null;
|
||||
selectProjectDialog.setProject(null);
|
||||
selectProjectDialog.showOnStage(mainStage);
|
||||
}
|
||||
});
|
||||
|
|
@ -397,9 +387,13 @@ public class CoderClient extends Application{
|
|||
//TODO
|
||||
}
|
||||
private void sendProjectReqMsg(){
|
||||
if(!selectProjectDialog.isProjectSelected()){
|
||||
logger.severe("Cannot send a project request when no project is selected");
|
||||
return;
|
||||
}
|
||||
CoderMessage msg = new CoderMessage();
|
||||
msg.ProjectReq = new ProjectReqMsg();
|
||||
msg.ProjectReq.name = project;
|
||||
msg.ProjectReq.name = selectProjectDialog.getSelectedProject();
|
||||
try {
|
||||
session.send(msg);
|
||||
} catch (IOException e) {
|
||||
|
|
@ -409,7 +403,7 @@ public class CoderClient extends Application{
|
|||
}
|
||||
@Override
|
||||
public void changeProject() {
|
||||
project = null;
|
||||
selectProjectDialog.setProject(null);
|
||||
selectProjectDialog.showOnStage(mainStage);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ public class LoginDialog extends GuiWindow {
|
|||
passwordPasswordField.requestFocus();
|
||||
}else{
|
||||
usernameTextField.requestFocus();
|
||||
passwordPasswordField.setText("");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ public class NewProjectDialog extends GuiWindow {
|
|||
for(NewProjectDialogListener listener : this.listeners){
|
||||
listener.willShow();
|
||||
}
|
||||
//TODO: if(errorMessage == null || errorMessage.isEmpty()){project = ""; type = "";} //keep field data if there is an error
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ public class SelectProjectDialog extends GuiWindow {
|
|||
for(SelectProjectDialogListener listener : this.listeners){
|
||||
listener.willShow();
|
||||
}
|
||||
if(this.projectName != null){
|
||||
if(this.projectName != null && !this.projectName.isEmpty()){
|
||||
openButton.setDisable(false);
|
||||
openButton.fire();
|
||||
}
|
||||
|
|
@ -134,7 +134,7 @@ public class SelectProjectDialog extends GuiWindow {
|
|||
|
||||
@FXML
|
||||
protected void open(ActionEvent event){
|
||||
if(this.projectName == null){
|
||||
if(this.projectName == null || this.projectName.isEmpty()){
|
||||
ProjectListItem selectedItem = projectListView.getSelectionModel().getSelectedItem();
|
||||
projectName = selectedItem.getName();
|
||||
}
|
||||
|
|
@ -174,4 +174,12 @@ public class SelectProjectDialog extends GuiWindow {
|
|||
this.errorLabel.setText(errorMsg);
|
||||
}
|
||||
|
||||
public boolean isProjectSelected() {
|
||||
return this.projectName != null && !this.projectName.isEmpty();
|
||||
}
|
||||
|
||||
public String getSelectedProject() {
|
||||
return this.projectName;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue