154 lines
4.5 KiB
Java
Executable file
154 lines
4.5 KiB
Java
Executable file
package com.coder.client.gui.newProject;
|
|
|
|
import java.io.IOException;
|
|
import java.net.URL;
|
|
import java.util.ResourceBundle;
|
|
import java.util.logging.Logger;
|
|
|
|
import com.coder.server.message.CoderMessage;
|
|
import com.coder.server.message.ProjectTypeReqMsg;
|
|
import com.coder.server.message.ProjectTypeRspMsg;
|
|
import com.coder.server.message.SupportedProperties;
|
|
|
|
import javafx.collections.FXCollections;
|
|
import javafx.collections.ObservableList;
|
|
import javafx.event.ActionEvent;
|
|
import javafx.fxml.FXML;
|
|
import javafx.scene.control.Button;
|
|
import javafx.scene.control.ComboBox;
|
|
import javafx.scene.control.Label;
|
|
import javafx.scene.control.TextField;
|
|
import javafx.scene.input.KeyCode;
|
|
import javafx.scene.input.KeyEvent;
|
|
|
|
import zutil.log.LogUtil;
|
|
|
|
import com.coder.client.CoderClient;
|
|
import com.coder.client.gui.GuiWindow;
|
|
import com.coder.client.session.ProjectTypeRspMsgListener;
|
|
|
|
public class NewProjectDialog extends GuiWindow {
|
|
public static final Logger logger = LogUtil.getLogger();
|
|
private CoderClient client;
|
|
|
|
@FXML private Button createButton;
|
|
@FXML private Button cancelButton;
|
|
@FXML private TextField projectNameTextField;
|
|
@FXML private TextField projectDescriptionTextField;
|
|
@FXML private ComboBox<String> projectTypeComboBox;
|
|
@FXML private Label errorMessageLabel;
|
|
|
|
private ObservableList<String> projectTypeList = null;
|
|
|
|
public NewProjectDialog(CoderClient client) throws IOException {
|
|
super(NewProjectDialog.class.getResource("NewProjectDialog.fxml"));
|
|
projectTypeList = FXCollections.observableArrayList();
|
|
projectTypeComboBox.setItems(projectTypeList);
|
|
this.client = client;
|
|
client.getSessionHandler().addMessageListener(new ProjectTypeRspMsgListener() {
|
|
@Override
|
|
public void messageReceived(final ProjectTypeRspMsg msg) {
|
|
logger.fine("a ProjectTypeRspMsg received");
|
|
for(String typeName : msg.keySet()){
|
|
SupportedProperties typeData = msg.get(typeName);
|
|
addProjectTypeToList(typeName, typeData);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
@Override
|
|
protected void willShow() {
|
|
clearProjectTypeList();
|
|
sendProjectTypeReqMsg();
|
|
|
|
if(errorMessageLabel.getText() == null || errorMessageLabel.getText().isEmpty()){
|
|
projectNameTextField.setText(null);
|
|
projectTypeComboBox.setValue(null);
|
|
createButton.setDisable(true);
|
|
}
|
|
projectNameTextField.requestFocus();
|
|
}
|
|
|
|
@Override
|
|
public void initialize(URL fxmlFileLocation, ResourceBundle resources) {
|
|
setErrorMessage("");
|
|
}
|
|
|
|
private void sendProjectTypeReqMsg(){
|
|
CoderMessage msg = new CoderMessage();
|
|
msg.ProjectTypeReq = new ProjectTypeReqMsg();
|
|
client.getSessionHandler().sendMessage(msg);
|
|
}
|
|
|
|
@FXML
|
|
protected void create(ActionEvent event){
|
|
logger.fine("create button triggered");
|
|
if(projectNameTextField.getText() == null || projectNameTextField.getText().isEmpty()){
|
|
logger.warning("Missing project name");
|
|
return;
|
|
}
|
|
if(projectTypeComboBox.getValue() == null || projectTypeComboBox.getValue().isEmpty()){
|
|
logger.warning("Missing project type");
|
|
return;
|
|
}
|
|
|
|
client.getProjectHandler().triggerCreateNewProject(projectNameTextField.getText(), projectTypeComboBox.getValue(), projectDescriptionTextField.getText());
|
|
}
|
|
|
|
@FXML
|
|
protected void cancel(ActionEvent event){
|
|
logger.fine("cancel button triggered");
|
|
client.getProjectHandler().setProject(null);
|
|
client.getProjectHandler().triggerSelectProject();
|
|
}
|
|
|
|
@FXML
|
|
protected void keyPressed(KeyEvent event){
|
|
enableDisableButton();
|
|
|
|
if(event.getCode().equals(KeyCode.ENTER)){
|
|
createButton.fire();
|
|
}else if(event.getCode().equals(KeyCode.ESCAPE)){
|
|
cancelButton.fire();
|
|
}
|
|
}
|
|
|
|
@FXML
|
|
protected void typeSelection(ActionEvent event){
|
|
enableDisableButton();
|
|
}
|
|
|
|
protected void enableDisableButton(){
|
|
createButton.setDisable(true);
|
|
if(projectNameTextField.getText() != null && !projectNameTextField.getText().isEmpty()){
|
|
if(projectTypeComboBox.getValue() != null && !projectTypeComboBox.getValue().isEmpty()){
|
|
createButton.setDisable(false);
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override
|
|
protected String getTitle() {
|
|
return "New Project";
|
|
}
|
|
|
|
public void addProjectTypeToList(String typeName, SupportedProperties typeData) {
|
|
logger.fine("Adding project type \"" + typeName + "\" to the project type list");
|
|
projectTypeList.add(typeName);
|
|
}
|
|
|
|
public void clearProjectTypeList() {
|
|
projectTypeList.clear();
|
|
}
|
|
|
|
private void setErrorMessage(String errorMsg) {
|
|
errorMessageLabel.setText(errorMsg);
|
|
}
|
|
|
|
@Override
|
|
protected String getDescriptiveName() {
|
|
return "New Project Dialog";
|
|
}
|
|
|
|
}
|