Adding logic to NewProjectDialog

This commit is contained in:
dcollin 2015-10-27 17:01:59 +01:00
parent eb71b4da59
commit d9c86b44e0
3 changed files with 55 additions and 13 deletions

View file

@ -4,10 +4,12 @@
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="159.0" prefWidth="319.0" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1">
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="159.0" prefWidth="382.0" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1">
<children>
<Button fx:id="cancelButton" layoutX="60.0" layoutY="67.0" mnemonicParsing="false" onAction="#cancel" text="cancel" />
<Button fx:id="createButton" defaultButton="true" disable="true" layoutX="195.0" layoutY="67.0" mnemonicParsing="false" onAction="#create" text="create" />
<ComboBox fx:id="projectTypeComboBox" layoutX="160.0" layoutY="21.0" prefHeight="25.0" prefWidth="196.0" promptText="Select a Project Type" />
<Label fx:id="errorMessageLabel" layoutX="71.0" layoutY="111.0" text="Error Message" textFill="RED" />
<TextField fx:id="projectNameTextField" layoutX="11.0" layoutY="21.0" onKeyPressed="#keyPressed" promptText="Project Name" />
</children>
</AnchorPane>

View file

@ -6,9 +6,16 @@ import java.util.HashSet;
import java.util.ResourceBundle;
import java.util.logging.Logger;
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;
@ -21,9 +28,16 @@ public class NewProjectDialog extends GuiWindow {
@FXML private Button createButton;
@FXML private Button cancelButton;
@FXML private TextField projectNameTextField;
@FXML private ComboBox<String> projectTypeComboBox;
@FXML private Label errorMessageLabel;
private ObservableList<String> projectTypeList = null;
public NewProjectDialog() throws IOException {
super(NewProjectDialog.class.getResource("NewProjectDialog.fxml"));
projectTypeList = FXCollections.observableArrayList();
projectTypeComboBox.setItems(projectTypeList);
listeners = new HashSet<NewProjectDialogListener>();
}
@ -32,19 +46,31 @@ 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
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) {
// TODO Auto-generated method stub
errorMessageLabel.setText("");
}
@FXML
protected void create(ActionEvent event){
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;
}
for(NewProjectDialogListener listener : this.listeners){
listener.create("Project Name", "Project Type");
listener.create(projectNameTextField.getText(), projectTypeComboBox.getValue());
}
}
@ -55,6 +81,22 @@ public class NewProjectDialog extends GuiWindow {
}
}
@FXML
protected void keyPressed(KeyEvent event){
if(projectNameTextField.getText() != null && !projectNameTextField.getText().isEmpty()){
if(projectTypeComboBox.getValue() != null && !projectTypeComboBox.getValue().isEmpty()){
createButton.setDisable(false);
}
}
if(event.getCode().equals(KeyCode.ENTER)){
createButton.fire();
}else if(event.getCode().equals(KeyCode.ESCAPE)){
cancelButton.fire();
}
}
//TODO: react to combo box changes
@Override
protected String getTitle() {
return "New Project";
@ -65,19 +107,17 @@ public class NewProjectDialog extends GuiWindow {
}
public void addProjectTypeToList(String typeName, ConfigData typeData) {
// TODO Auto-generated method stub
logger.fine("Adding project type \"" + typeName + "\" to the project type list");
projectTypeList.add(typeName);
}
public void clearProjectTypeList() {
// TODO Auto-generated method stub
projectTypeList.clear();
}
@Override
public void setErrorMessage(String errorMsg) {
// TODO Auto-generated method stub
errorMessageLabel.setText(errorMsg);
}
}

View file

@ -155,7 +155,7 @@ public class SelectProjectDialog extends GuiWindow {
}
public void addProjectToList(String projectName, ProjectListData projectData) {
logger.fine("Adding project \"" + projectName + "\" of type " + projectData.type + "to project list");
logger.fine("Adding project \"" + projectName + "\" of type " + projectData.type + " to the project list");
ProjectListItem item = new ProjectListItem(projectName, projectData.type, projectData.description);
this.projectList.add(item);
}