Adding logic to NewProjectDialog
This commit is contained in:
parent
eb71b4da59
commit
d9c86b44e0
3 changed files with 55 additions and 13 deletions
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -54,6 +80,22 @@ public class NewProjectDialog extends GuiWindow {
|
|||
listener.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@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() {
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue