-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathNewClassController.java
More file actions
78 lines (62 loc) · 2.49 KB
/
NewClassController.java
File metadata and controls
78 lines (62 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package astro.controller;
import astro.constants.ClassKind;
import astro.constants.Extension;
import astro.ui.DialogUtils;
import astro.utils.ClassManager;
import astro.utils.FileManager;
import astro.utils.Intent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.TextField;
import javafx.stage.Stage;
import java.io.File;
import java.net.URL;
import java.util.ResourceBundle;
public class NewClassController implements Initializable {
@FXML private TextField classNameText;
@FXML private ComboBox<String> kindComboBox;
@FXML private Button createButton;
@FXML private Button cancelButton;
@FXML static NewClassController classController;
private String directoryPath;
@Override
public void initialize(URL location, ResourceBundle resources) {
classController = this;
bindComboBoxTypes();
getValuesFromMainView();
createButton.setOnAction(e -> createButtonAction());
cancelButton.setOnAction(e -> cancelButtonAction());
}
private void getValuesFromMainView() {
Intent intent = Intent.getIntent();
directoryPath = intent.getStringValue("CLASS_PATH","");
}
private void bindComboBoxTypes() {
kindComboBox.getItems().addAll("Class", "Interface", "Enum", "Annotation");
kindComboBox.getSelectionModel().select(0);
}
private void createButtonAction() {
String classType = kindComboBox.getSelectionModel().getSelectedItem();
String className = classNameText.getText();
if(className.isEmpty()){
String errorMessage = "Insert Class name first";
DialogUtils.createErrorDialog(DialogUtils.ERROR_DIALOG,null,errorMessage);
return;
}
String fullClassName = (className.endsWith(Extension.JAVA)) ? className : className.concat(Extension.JAVA);
String newClassPath = directoryPath.concat(File.separator).concat(fullClassName);
File source = FileManager.createNewFile(newClassPath);
ClassKind classKind = ClassManager.getClassKind(classType);
FileManager.updateContent(source, ClassManager.getDefaultValueText(className, classKind));
cancelButtonAction();
}
private void cancelButtonAction() {
Stage stage = (Stage) cancelButton.getScene().getWindow();
stage.close();
}
public static NewClassController getInstance(){
return classController;
}
}