2015-10-23 13:44:11 +00:00
|
|
|
package com.coder.client.gui.newProject;
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.net.URL;
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
import java.util.ResourceBundle;
|
|
|
|
|
import java.util.logging.Logger;
|
|
|
|
|
|
2015-11-04 23:37:54 +01:00
|
|
|
import com.coder.server.message.SupportedProperties;
|
2015-10-27 17:01:59 +01:00
|
|
|
import javafx.collections.FXCollections;
|
|
|
|
|
import javafx.collections.ObservableList;
|
2015-10-23 13:44:11 +00:00
|
|
|
import javafx.event.ActionEvent;
|
|
|
|
|
import javafx.fxml.FXML;
|
|
|
|
|
import javafx.scene.control.Button;
|
2015-10-27 17:01:59 +01:00
|
|
|
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;
|
2015-10-23 13:44:11 +00:00
|
|
|
|
|
|
|
|
import zutil.log.LogUtil;
|
|
|
|
|
|
|
|
|
|
import com.coder.client.gui.GuiWindow;
|
|
|
|
|
|
|
|
|
|
public class NewProjectDialog extends GuiWindow {
|
|
|
|
|
public static final Logger logger = LogUtil.getLogger();
|
|
|
|
|
private HashSet<NewProjectDialogListener> listeners;
|
|
|
|
|
|
|
|
|
|
@FXML private Button createButton;
|
|
|
|
|
@FXML private Button cancelButton;
|
2015-10-27 17:01:59 +01:00
|
|
|
@FXML private TextField projectNameTextField;
|
2015-11-04 12:56:20 +01:00
|
|
|
@FXML private TextField projectDescriptionTextField;
|
2015-10-27 17:01:59 +01:00
|
|
|
@FXML private ComboBox<String> projectTypeComboBox;
|
|
|
|
|
@FXML private Label errorMessageLabel;
|
|
|
|
|
|
|
|
|
|
private ObservableList<String> projectTypeList = null;
|
2015-10-23 13:44:11 +00:00
|
|
|
|
|
|
|
|
public NewProjectDialog() throws IOException {
|
|
|
|
|
super(NewProjectDialog.class.getResource("NewProjectDialog.fxml"));
|
2015-10-27 17:01:59 +01:00
|
|
|
projectTypeList = FXCollections.observableArrayList();
|
|
|
|
|
projectTypeComboBox.setItems(projectTypeList);
|
2015-10-23 13:44:11 +00:00
|
|
|
listeners = new HashSet<NewProjectDialogListener>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void willShow() {
|
|
|
|
|
for(NewProjectDialogListener listener : this.listeners){
|
|
|
|
|
listener.willShow();
|
|
|
|
|
}
|
2015-10-27 17:01:59 +01:00
|
|
|
if(errorMessageLabel.getText() == null || errorMessageLabel.getText().isEmpty()){
|
|
|
|
|
projectNameTextField.setText(null);
|
|
|
|
|
projectTypeComboBox.setValue(null);
|
|
|
|
|
createButton.setDisable(true);
|
|
|
|
|
}
|
|
|
|
|
projectNameTextField.requestFocus();
|
2015-10-23 13:44:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void initialize(URL fxmlFileLocation, ResourceBundle resources) {
|
2015-10-27 17:01:59 +01:00
|
|
|
errorMessageLabel.setText("");
|
2015-10-23 13:44:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@FXML
|
|
|
|
|
protected void create(ActionEvent event){
|
2015-10-27 17:01:59 +01:00
|
|
|
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;
|
|
|
|
|
}
|
2015-10-23 13:44:11 +00:00
|
|
|
for(NewProjectDialogListener listener : this.listeners){
|
2015-11-04 12:56:20 +01:00
|
|
|
listener.create(projectNameTextField.getText(), projectTypeComboBox.getValue(), projectDescriptionTextField.getText());
|
2015-10-23 13:44:11 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@FXML
|
|
|
|
|
protected void cancel(ActionEvent event){
|
|
|
|
|
for(NewProjectDialogListener listener : this.listeners){
|
|
|
|
|
listener.cancel();
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-11-02 16:55:48 +01:00
|
|
|
|
|
|
|
|
|
2015-10-27 17:01:59 +01:00
|
|
|
@FXML
|
|
|
|
|
protected void keyPressed(KeyEvent event){
|
2015-11-02 16:55:48 +01:00
|
|
|
enableDisableButton();
|
|
|
|
|
|
2015-10-27 17:01:59 +01:00
|
|
|
if(event.getCode().equals(KeyCode.ENTER)){
|
|
|
|
|
createButton.fire();
|
|
|
|
|
}else if(event.getCode().equals(KeyCode.ESCAPE)){
|
|
|
|
|
cancelButton.fire();
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-11-04 12:56:20 +01:00
|
|
|
|
2015-11-02 16:55:48 +01:00
|
|
|
@FXML
|
|
|
|
|
protected void typeSelection(ActionEvent event){
|
|
|
|
|
enableDisableButton();
|
|
|
|
|
}
|
2015-11-04 12:56:20 +01:00
|
|
|
|
2015-11-02 16:55:48 +01:00
|
|
|
protected void enableDisableButton(){
|
|
|
|
|
createButton.setDisable(true);
|
|
|
|
|
if(projectNameTextField.getText() != null && !projectNameTextField.getText().isEmpty()){
|
|
|
|
|
if(projectTypeComboBox.getValue() != null && !projectTypeComboBox.getValue().isEmpty()){
|
|
|
|
|
createButton.setDisable(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-10-23 13:44:11 +00:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected String getTitle() {
|
|
|
|
|
return "New Project";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void addNewProjectDialogListener(NewProjectDialogListener newProjectDialogListener) {
|
|
|
|
|
this.listeners.add(newProjectDialogListener);
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-04 23:37:54 +01:00
|
|
|
public void addProjectTypeToList(String typeName, SupportedProperties typeData) {
|
2015-10-27 17:01:59 +01:00
|
|
|
logger.fine("Adding project type \"" + typeName + "\" to the project type list");
|
|
|
|
|
projectTypeList.add(typeName);
|
2015-10-23 13:44:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void clearProjectTypeList() {
|
2015-10-27 17:01:59 +01:00
|
|
|
projectTypeList.clear();
|
2015-10-23 13:44:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void setErrorMessage(String errorMsg) {
|
2015-10-27 17:01:59 +01:00
|
|
|
errorMessageLabel.setText(errorMsg);
|
2015-10-23 13:44:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|