Java Code Examples for javafx.scene.control.ListView#setOnMouseClicked()

The following examples show how to use javafx.scene.control.ListView#setOnMouseClicked() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: QueryListDialog.java    From constellation with Apache License 2.0 7 votes vote down vote up
static String getQueryName(final Object owner, final String[] queryNames) {
    final Alert dialog = new Alert(Alert.AlertType.CONFIRMATION);

    final ObservableList<String> q = FXCollections.observableArrayList(queryNames);
    final ListView<String> nameList = new ListView<>(q);
    nameList.setCellFactory(p -> new DraggableCell<>());
    nameList.setEditable(false);
    nameList.setOnMouseClicked(event -> {
        if (event.getClickCount() > 1) {
            dialog.setResult(ButtonType.OK);
        }
    });

    dialog.setResizable(false);
    dialog.setTitle("Query names");
    dialog.setHeaderText("Select a query to load.");
    dialog.getDialogPane().setContent(nameList);
    final Optional<ButtonType> option = dialog.showAndWait();
    if (option.isPresent() && option.get() == ButtonType.OK) {
        return nameList.getSelectionModel().getSelectedItem();
    }

    return null;
}
 
Example 2
Source File: QueryListDialog.java    From constellation with Apache License 2.0 6 votes vote down vote up
static String getQueryName(final Object owner, final String[] labels) {
    final Alert dialog = new Alert(Alert.AlertType.CONFIRMATION);
    dialog.setTitle("Saved JDBC parameters");

    final ObservableList<String> q = FXCollections.observableArrayList(labels);
    final ListView<String> labelList = new ListView<>(q);
    labelList.setEditable(false);
    labelList.setOnMouseClicked(event -> {
        if (event.getClickCount() > 1) {
            dialog.setResult(ButtonType.OK);
        }
    });

    dialog.setResizable(false);
    dialog.setHeaderText("Select a parameter set to load.");
    dialog.getDialogPane().setContent(labelList);
    final Optional<ButtonType> option = dialog.showAndWait();
    if (option.isPresent() && option.get() == ButtonType.OK) {
        return labelList.getSelectionModel().getSelectedItem();
    }

    return null;
}
 
Example 3
Source File: NaviSelectDemo.java    From tornadofx-controls with Apache License 2.0 6 votes vote down vote up
/**
 * Select value example. Implement whatever technique you want to change value of the NaviSelect
 */
private void selectEmail(NaviSelect<Email> navi) {
	Stage dialog = new Stage(StageStyle.UTILITY);
	dialog.setTitle("Choose person");
	ListView<Email> listview = new ListView<>(FXCollections.observableArrayList(
		new Email("[email protected]", "John Doe"),
		new Email("[email protected]", "Jane Doe"),
		new Email("[email protected]", "Some Dude")
	));
	listview.setOnMouseClicked(event -> {
		Email item = listview.getSelectionModel().getSelectedItem();
		if (item != null) {
			navi.setValue(item);
			dialog.close();
		}
	});
	dialog.setScene(new Scene(listview));
	dialog.setWidth(navi.getWidth());
	dialog.initModality(Modality.APPLICATION_MODAL);
	dialog.setHeight(100);
	dialog.showAndWait();
}
 
Example 4
Source File: JsonIODialog.java    From constellation with Apache License 2.0 5 votes vote down vote up
/**
 * *
 * Present a dialog allowing user to select an entry from a list of
 * available files.
 *
 * @param names list of filenames to choose from
 * @return the selected element text or null if nothing was selected
 */
public static String getSelection(final String[] names) {
    final Alert dialog = new Alert(Alert.AlertType.CONFIRMATION);
    final ObservableList<String> q = FXCollections.observableArrayList(names);
    final ListView<String> nameList = new ListView<>(q);

    nameList.setCellFactory(p -> new DraggableCell<>());
    nameList.setEditable(false);
    nameList.setOnMouseClicked(event -> {
        if (event.getClickCount() > 1) {
            dialog.setResult(ButtonType.OK);
        }
    });
    ButtonType removeButton = new ButtonType("Remove");
    dialog.getDialogPane().setContent(nameList);
    dialog.getButtonTypes().add(removeButton);
    dialog.setResizable(false);
    dialog.setTitle("Preferences");
    dialog.setHeaderText("Select a preference to load.");

    // The remove button has been wrapped inside the btOk, this has been done because any ButtonTypes added
    // to an alert window will automatically close the window when pressed. 
    // Wrapping it in another button can allow us to consume the closing event and keep the window open.
    final Button btOk = (Button) dialog.getDialogPane().lookupButton(removeButton);
    btOk.addEventFilter(ActionEvent.ACTION, event -> {
        JsonIO.deleteJsonPreference(nameList.getSelectionModel().getSelectedItem());
        q.remove(nameList.getSelectionModel().getSelectedItem());
        nameList.setCellFactory(p -> new DraggableCell<>());
        dialog.getDialogPane().setContent(nameList);
        event.consume();
    });
    final Optional<ButtonType> option = dialog.showAndWait();
    if (option.isPresent() && option.get() == ButtonType.OK) {
        return nameList.getSelectionModel().getSelectedItem();
    }

    return null;
}
 
Example 5
Source File: TemplateListDialog.java    From constellation with Apache License 2.0 4 votes vote down vote up
String getName(final Object owner, final File delimIoDir) {
    final String[] templateLabels = getFileLabels(delimIoDir);

    final Alert dialog = new Alert(Alert.AlertType.CONFIRMATION);

    final TextField label = new TextField();
    label.setPromptText("Template label");

    final ObservableList<String> q = FXCollections.observableArrayList(templateLabels);
    final ListView<String> nameList = new ListView<>(q);
    nameList.setEditable(false);
    nameList.setOnMouseClicked(event -> {
        label.setText(nameList.getSelectionModel().getSelectedItem());
        if (event.getClickCount() > 1) {
            dialog.setResult(ButtonType.OK);
        }
    });

    final HBox prompt = new HBox(new Label("Name: "), label);
    prompt.setPadding(new Insets(10, 0, 0, 0));

    final VBox vbox = new VBox(nameList, prompt);

    dialog.setResizable(false);
    dialog.setTitle("Import template names");
    dialog.setHeaderText(String.format("Select an import template to %s.", isLoading ? "load" : "save"));
    dialog.getDialogPane().setContent(vbox);
    final Optional<ButtonType> option = dialog.showAndWait();
    if (option.isPresent() && option.get() == ButtonType.OK) {
        final String name = label.getText();
        final File f = new File(delimIoDir, FilenameEncoder.encode(name + ".json"));
        boolean go = true;
        if (!isLoading && f.exists()) {
            final String msg = String.format("'%s' already exists. Do you want to overwrite it?", name);
            final Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
            alert.setHeaderText("Import template exists");
            alert.setContentText(msg);
            final Optional<ButtonType> confirm = alert.showAndWait();
            go = confirm.isPresent() && confirm.get() == ButtonType.OK;
        }

        if (go) {
            return name;
        }
    }

    return null;
}