2015-10-20 15:52:23 +00:00
|
|
|
package com.coder.client.gui.selectProject;
|
2015-10-20 14:26:58 +00:00
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.net.URL;
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
import java.util.ResourceBundle;
|
|
|
|
|
import java.util.logging.Logger;
|
|
|
|
|
|
|
|
|
|
import zutil.log.LogUtil;
|
|
|
|
|
|
2015-10-21 14:23:00 +00:00
|
|
|
import javafx.collections.FXCollections;
|
|
|
|
|
import javafx.collections.ObservableList;
|
2015-10-20 14:26:58 +00:00
|
|
|
import javafx.event.ActionEvent;
|
|
|
|
|
import javafx.fxml.FXML;
|
|
|
|
|
import javafx.scene.control.Button;
|
2015-10-21 14:23:00 +00:00
|
|
|
import javafx.scene.control.ListCell;
|
2015-10-20 14:26:58 +00:00
|
|
|
import javafx.scene.control.ListView;
|
|
|
|
|
import javafx.scene.input.KeyCode;
|
|
|
|
|
import javafx.scene.input.KeyEvent;
|
2015-10-21 14:23:00 +00:00
|
|
|
import javafx.util.Callback;
|
2015-10-20 14:26:58 +00:00
|
|
|
|
|
|
|
|
import com.coder.client.gui.GuiWindow;
|
2015-10-21 14:23:00 +00:00
|
|
|
import com.coder.server.message.ProjectListData;
|
2015-10-20 14:26:58 +00:00
|
|
|
|
|
|
|
|
public class SelectProjectDialog extends GuiWindow {
|
|
|
|
|
public static final Logger logger = LogUtil.getLogger();
|
|
|
|
|
private HashSet<SelectProjectDialogListener> listeners;
|
2015-10-21 14:23:00 +00:00
|
|
|
private ObservableList<ProjectListItem> projectList;
|
2015-10-20 14:26:58 +00:00
|
|
|
|
2015-10-21 14:23:00 +00:00
|
|
|
@FXML private ListView<ProjectListItem> projectListView;
|
2015-10-20 14:26:58 +00:00
|
|
|
@FXML private Button newProjectButton;
|
|
|
|
|
@FXML private Button cancelButton;
|
|
|
|
|
@FXML private Button openProjectButton;
|
|
|
|
|
|
|
|
|
|
public SelectProjectDialog() throws IOException {
|
|
|
|
|
super(SelectProjectDialog.class.getResource("SelectProjectDialog.fxml"));
|
|
|
|
|
listeners = new HashSet<SelectProjectDialogListener>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void willShow() {
|
|
|
|
|
for(SelectProjectDialogListener listener : this.listeners){
|
|
|
|
|
listener.willShow();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void initialize(URL fxmlFileLocation, ResourceBundle resources) {
|
2015-10-21 14:23:00 +00:00
|
|
|
projectList = FXCollections.observableArrayList();
|
|
|
|
|
projectListView.setItems(projectList);
|
|
|
|
|
projectListView.setCellFactory(new Callback<ListView<ProjectListItem>, ListCell<ProjectListItem>>(){
|
|
|
|
|
@Override
|
|
|
|
|
public ListCell<ProjectListItem> call(ListView<ProjectListItem> arg0) {
|
|
|
|
|
ListCell<ProjectListItem> cell = new ListCell<ProjectListItem>(){
|
|
|
|
|
@Override
|
|
|
|
|
protected void updateItem(ProjectListItem item, boolean empty){
|
|
|
|
|
super.updateItem(item, empty);
|
|
|
|
|
if(item != null){
|
|
|
|
|
setText(item.toString());
|
|
|
|
|
//setGraphic(null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
return cell;
|
|
|
|
|
}
|
|
|
|
|
});
|
2015-10-20 14:26:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@FXML
|
|
|
|
|
protected void keyPressed(KeyEvent event) {
|
|
|
|
|
if(event.getCode() == KeyCode.ENTER){
|
|
|
|
|
logger.fine("User pressed the ENTER key");
|
|
|
|
|
openProjectButton.fire();
|
|
|
|
|
}else if(event.getCode() == KeyCode.ESCAPE){
|
|
|
|
|
logger.fine("User pressed the ESCAPE key");
|
|
|
|
|
cancelButton.fire();
|
|
|
|
|
}else if(event.getCode() == KeyCode.N && event.isControlDown()){ //CTRL+N
|
|
|
|
|
logger.fine("User pressed CTRL+N");
|
|
|
|
|
newProjectButton.fire();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@FXML
|
|
|
|
|
protected void newProject(ActionEvent event){
|
|
|
|
|
for(SelectProjectDialogListener listener : this.listeners){
|
|
|
|
|
listener.newProject();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@FXML
|
|
|
|
|
protected void cancel(ActionEvent event){
|
|
|
|
|
for(SelectProjectDialogListener listener : this.listeners){
|
|
|
|
|
listener.cancel();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-21 14:23:00 +00:00
|
|
|
@FXML
|
|
|
|
|
protected void refresh(ActionEvent event){
|
|
|
|
|
for(SelectProjectDialogListener listener : this.listeners){
|
|
|
|
|
listener.refresh();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-20 14:26:58 +00:00
|
|
|
@FXML
|
|
|
|
|
protected void openProject(ActionEvent event){
|
|
|
|
|
for(SelectProjectDialogListener listener : this.listeners){
|
|
|
|
|
//TODO: get selected project in the list view
|
|
|
|
|
String selectedProjectName = "project name";
|
|
|
|
|
listener.openProject(selectedProjectName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void addSelectProjectDialogListener(SelectProjectDialogListener listener){
|
|
|
|
|
this.listeners.add(listener);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void clearProjectList(){
|
2015-10-21 14:23:00 +00:00
|
|
|
logger.fine("Clearing project list");
|
2015-10-20 14:26:58 +00:00
|
|
|
//TODO
|
|
|
|
|
}
|
2015-10-21 14:23:00 +00:00
|
|
|
|
|
|
|
|
public void addProjectToList(String projectName, ProjectListData projectData) {
|
|
|
|
|
logger.fine("Adding project \"" + projectName + "\" of type " + projectData.type + "to project list");
|
|
|
|
|
ProjectListItem item = new ProjectListItem(projectName, projectData.type, projectData.description);
|
|
|
|
|
this.projectList.add(item);
|
2015-10-20 14:26:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|