Implemented SSDP client and is now using graphical list cells in ListViews
This commit is contained in:
parent
120dded24f
commit
34cf5865fe
16 changed files with 428 additions and 86 deletions
|
|
@ -4,10 +4,13 @@ import java.io.IOException;
|
|||
import java.net.URL;
|
||||
import java.util.HashSet;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import zutil.log.LogUtil;
|
||||
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.event.ActionEvent;
|
||||
|
|
@ -17,6 +20,8 @@ import javafx.scene.control.ListCell;
|
|||
import javafx.scene.control.ListView;
|
||||
import javafx.scene.input.KeyCode;
|
||||
import javafx.scene.input.KeyEvent;
|
||||
import javafx.scene.input.MouseButton;
|
||||
import javafx.scene.input.MouseEvent;
|
||||
import javafx.util.Callback;
|
||||
|
||||
import com.coder.client.gui.GuiWindow;
|
||||
|
|
@ -30,7 +35,9 @@ public class SelectProjectDialog extends GuiWindow {
|
|||
@FXML private ListView<ProjectListItem> projectListView;
|
||||
@FXML private Button newProjectButton;
|
||||
@FXML private Button cancelButton;
|
||||
@FXML private Button openProjectButton;
|
||||
@FXML private Button openButton;
|
||||
|
||||
private String projectName = null;
|
||||
|
||||
public SelectProjectDialog() throws IOException {
|
||||
super(SelectProjectDialog.class.getResource("SelectProjectDialog.fxml"));
|
||||
|
|
@ -42,6 +49,11 @@ public class SelectProjectDialog extends GuiWindow {
|
|||
for(SelectProjectDialogListener listener : this.listeners){
|
||||
listener.willShow();
|
||||
}
|
||||
if(this.projectName != null){
|
||||
openButton.setDisable(false);
|
||||
openButton.fire();
|
||||
}
|
||||
openButton.setDisable(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -51,32 +63,41 @@ public class SelectProjectDialog extends GuiWindow {
|
|||
projectListView.setCellFactory(new Callback<ListView<ProjectListItem>, ListCell<ProjectListItem>>(){
|
||||
@Override
|
||||
public ListCell<ProjectListItem> call(ListView<ProjectListItem> arg0) {
|
||||
System.out.println("cell factory");
|
||||
ListCell<ProjectListItem> cell = new ListCell<ProjectListItem>(){
|
||||
@Override
|
||||
protected void updateItem(ProjectListItem item, boolean empty){
|
||||
System.out.println("update item: " + item);
|
||||
super.updateItem(item, empty);
|
||||
if(empty){
|
||||
setText("");
|
||||
setGraphic(null);
|
||||
}
|
||||
if(item != null){
|
||||
setText(item.toString());
|
||||
//setGraphic(null);
|
||||
}
|
||||
}
|
||||
};
|
||||
return cell;
|
||||
try {
|
||||
return new ProjectListCell();
|
||||
} catch (IOException e) {
|
||||
logger.log(Level.SEVERE, "could not crate a ProjectListCell instance", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
projectListView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<ProjectListItem>() {
|
||||
@Override
|
||||
public void changed(ObservableValue<? extends ProjectListItem> observable, ProjectListItem oldValue, ProjectListItem vewValue) {
|
||||
if(observable.getValue() != null){
|
||||
logger.fine("ProjectListItem [" + observable.getValue() + "] selected in the project list");
|
||||
openButton.setDisable(false);
|
||||
}else{
|
||||
openButton.setDisable(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@FXML
|
||||
protected void mouseClickedOnList(MouseEvent event){
|
||||
if(event.getButton().equals(MouseButton.PRIMARY)){
|
||||
if(event.getClickCount() == 2){ //if doublecklick
|
||||
openButton.fire();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
protected void keyPressed(KeyEvent event) {
|
||||
if(event.getCode() == KeyCode.ENTER){
|
||||
logger.fine("User pressed the ENTER key");
|
||||
openProjectButton.fire();
|
||||
openButton.fire();
|
||||
}else if(event.getCode() == KeyCode.ESCAPE){
|
||||
logger.fine("User pressed the ESCAPE key");
|
||||
cancelButton.fire();
|
||||
|
|
@ -108,11 +129,15 @@ public class SelectProjectDialog extends GuiWindow {
|
|||
}
|
||||
|
||||
@FXML
|
||||
protected void openProject(ActionEvent event){
|
||||
protected void open(ActionEvent event){
|
||||
if(this.projectName == null){
|
||||
ProjectListItem selectedItem = projectListView.getSelectionModel().getSelectedItem();
|
||||
projectName = selectedItem.getName();
|
||||
}
|
||||
for(SelectProjectDialogListener listener : this.listeners){
|
||||
//TODO: get selected project in the list view
|
||||
String selectedProjectName = "project name";
|
||||
listener.openProject(selectedProjectName);
|
||||
if(projectName != null){
|
||||
listener.open(projectName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -133,7 +158,11 @@ public class SelectProjectDialog extends GuiWindow {
|
|||
|
||||
@Override
|
||||
protected String getTitle() {
|
||||
return "Select Project";
|
||||
return "Open Project";
|
||||
}
|
||||
|
||||
public void setProject(String project) {
|
||||
this.projectName = project;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue