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

The following examples show how to use javafx.scene.control.ListView#setEditable() . 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: AlertHelper.java    From AsciidocFX with Apache License 2.0 7 votes vote down vote up
public static void showDuplicateWarning(List<String> duplicatePaths, Path lib) {
    Alert alert = new WindowModalAlert(Alert.AlertType.WARNING);

    DialogPane dialogPane = alert.getDialogPane();

    ListView listView = new ListView();
    listView.getStyleClass().clear();
    ObservableList items = listView.getItems();
    items.addAll(duplicatePaths);
    listView.setEditable(false);

    dialogPane.setContent(listView);

    alert.setTitle("Duplicate JARs found");
    alert.setHeaderText(String.format("Duplicate JARs found, it may cause unexpected behaviours.\n\n" +
            "Please remove the older versions from these pair(s) manually. \n" +
            "JAR files are located at %s directory.", lib));
    alert.getButtonTypes().clear();
    alert.getButtonTypes().addAll(ButtonType.OK);
    alert.showAndWait();
}
 
Example 3
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 4
Source File: ViolationCollectionView.java    From pmd-designer with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void initListView(ListView<LiveViolationRecord> view) {

        ControlUtil.makeListViewFitToChildren(view, LIST_CELL_HEIGHT);

        view.setEditable(true);

        DragAndDropUtil.registerAsNodeDragTarget(view, textRange -> {
            LiveViolationRecord record = new LiveViolationRecord();
            record.setRange(textRange);
            record.setExactRange(true);
            getItems().add(record);
        }, getDesignerRoot());

        ControlUtil.makeListViewNeverScrollHorizontal(view);

        // go into normal state on window hide
        ControlUtil.subscribeOnWindow(
            this,
            w -> ReactfxUtil.addEventHandler(w.onHiddenProperty(), evt -> view.edit(-1))
        );

        Label placeholder = new Label("No violations expected in this code");
        placeholder.getStyleClass().addAll("placeholder");
        view.setPlaceholder(placeholder);
        view.setCellFactory(lv -> new ViolationCell());
    }
 
Example 5
Source File: ListConfirmDialog.java    From phoenicis with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Initializes the components used in the {@link ListConfirmDialog}
 */
private void initialise() {
    getDialogPane().getStyleClass().add("list-confirm-dialog");

    final ListView<String> confirmList = new ListView<>(getConfirmItems());
    confirmList.getStyleClass().add("confirm-list");
    confirmList.setEditable(false);

    getDialogPane().setExpandableContent(confirmList);

    // ensure that the dialog resizes correctly when the expanded state changes
    getDialogPane().expandedProperty().addListener(observable -> Platform.runLater(() -> {
        getDialogPane().requestLayout();

        final Window window = getDialogPane().getScene().getWindow();
        window.sizeToScene();
    }));

    // open the confirm list by default
    getDialogPane().setExpanded(true);

    getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
}
 
Example 6
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 7
Source File: PropertyCollectionView.java    From pmd-designer with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private static void initListView(ListView<PropertyDescriptorSpec> view) {

        ControlUtil.makeListViewFitToChildren(view, LIST_CELL_HEIGHT);
        view.setEditable(true);

        ControlUtil.makeListViewNeverScrollHorizontal(view);

        Label placeholder = new Label("No properties yet");
        placeholder.getStyleClass().addAll("placeholder");
        view.setPlaceholder(placeholder);
    }
 
Example 8
Source File: ComboBoxListViewSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public ComboBoxListViewSample() {
    ListView<Object> listView = new ListView<>();
    listView.getItems().addAll(items);
    listView.setEditable(true);
    listView.setCellFactory(ComboBoxListCell.forListView(items));
    getChildren().add(listView);
}
 
Example 9
Source File: TextFieldListViewSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public TextFieldListViewSample() {
    final ListView<String> listView = new ListView<String>();
    listView.setItems(FXCollections.observableArrayList("Row 1", "Row 2", "Long Row 3", "Row 4", "Row 5", "Row 6", "Row 7",
            "Row 8", "Row 9", "Row 10", "Row 11", "Row 12", "Row 13", "Row 14", "Row 15", "Row 16", "Row 17", "Row 18",
            "Row 19", "Row 20"));
    listView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
    listView.setEditable(true);
    listView.setCellFactory(TextFieldListCell.forListView());
    getChildren().add(listView);
}
 
Example 10
Source File: ChoiceBoxListViewSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public ChoiceBoxListViewSample() {
    ListView<Object> listView = new ListView<>();
    listView.getItems().addAll(items);
    listView.setEditable(true);
    listView.setCellFactory(ChoiceBoxListCell.forListView(items));
    getChildren().addAll(listView, new Button("Click me"));
}
 
Example 11
Source File: AlertHelper.java    From AsciidocFX with Apache License 2.0 5 votes vote down vote up
public static Optional<String> showOldConfiguration(List<String> paths) {
    Alert alert = new WindowModalAlert(AlertType.INFORMATION);

    DialogPane dialogPane = alert.getDialogPane();

    ListView listView = new ListView();
    listView.getStyleClass().clear();
    ObservableList items = listView.getItems();
    items.addAll(paths);
    listView.setEditable(false);

    dialogPane.setContent(listView);

    alert.setTitle("Load previous configuration?");
    alert.setHeaderText(String.format("You have configuration files from previous AsciidocFX versions\n\n" +
            "Select the configuration which you want to load configuration \n" +
            "or continue with fresh configuration"));
    alert.getButtonTypes().clear();
    alert.getButtonTypes().addAll(ButtonType.APPLY);
    alert.getButtonTypes().addAll(ButtonType.CANCEL);
    ButtonType buttonType = alert.showAndWait().orElse(ButtonType.CANCEL);

    Object selectedItem = listView.getSelectionModel().getSelectedItem();
    return (buttonType == ButtonType.APPLY) ?
            Optional.ofNullable((String) selectedItem) :
            Optional.empty();
}
 
Example 12
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;
}
 
Example 13
Source File: ConsolidatedDialog.java    From constellation with Apache License 2.0 4 votes vote down vote up
/**
 * A generic multiple matches dialog which can be used to display a
 * collection of ObservableList items
 *
 * @param title The title of the dialog
 * @param observableMap The map of {@code ObservableList} objects
 * @param message The (help) message that will be displayed at the top of
 * the dialog window
 * @param listItemHeight The height of each list item. If you have a single
 * row of text then set this to 24.
 */
public ConsolidatedDialog(String title, Map<String, ObservableList<Container<K, V>>> observableMap, String message, int listItemHeight) {
    final BorderPane root = new BorderPane();
    root.setStyle("-fx-background-color: #DDDDDD;-fx-border-color: #3a3e43;-fx-border-width: 4px;");

    // add a title
    final Label titleLabel = new Label();
    titleLabel.setText(title);
    titleLabel.setStyle("-fx-font-size: 11pt;-fx-font-weight: bold;");
    titleLabel.setAlignment(Pos.CENTER);
    titleLabel.setPadding(new Insets(5));
    root.setTop(titleLabel);

    final Accordion accordion = new Accordion();
    for (String identifier : observableMap.keySet()) {
        final ObservableList<Container<K, V>> objects = observableMap.get(identifier);
        ListView<Container<K, V>> listView = new ListView<>(objects);
        listView.setEditable(false);
        listView.setPrefHeight((listItemHeight * objects.size()));
        listView.getSelectionModel().selectedItemProperty().addListener(event -> {
            listView.getItems().get(0).getKey();
            final Container<K, V> container = listView.getSelectionModel().getSelectedItem();
            if (container != null) {
                selectedObjects.add(new Pair<>(container.getKey(), container.getValue()));
            } else {
                // the object was unselected so go through the selected objects and remove them all because we don't know which one was unselected
                for (Container<K, V> object : listView.getItems()) {
                    selectedObjects.remove(new Pair<>(object.getKey(), object.getValue()));
                }
            }
        });

        final TitledPane titledPane = new TitledPane(identifier, listView);
        accordion.getPanes().add(titledPane);
    }

    final HBox help = new HBox();
    help.getChildren().add(helpMessage);
    help.getChildren().add(new ImageView(UserInterfaceIconProvider.HELP.buildImage(16, ConstellationColor.AZURE.getJavaColor())));
    help.setPadding(new Insets(10, 0, 10, 0));
    helpMessage.setText(message + "\n\nNote: To deselect hold Ctrl when you click.");
    helpMessage.setStyle("-fx-font-size: 11pt;");
    helpMessage.setWrapText(true);
    helpMessage.setPadding(new Insets(5));

    final VBox box = new VBox();
    box.getChildren().add(help);

    // add the multiple matching accordion
    box.getChildren().add(accordion);

    final ScrollPane scroll = new ScrollPane();
    scroll.setContent(box);
    scroll.setFitToWidth(true);
    scroll.setHbarPolicy(ScrollPane.ScrollBarPolicy.AS_NEEDED);
    root.setCenter(scroll);

    final FlowPane buttonPane = new FlowPane();
    buttonPane.setAlignment(Pos.BOTTOM_RIGHT);
    buttonPane.setPadding(new Insets(5));
    buttonPane.setHgap(5);
    root.setBottom(buttonPane);

    useButton = new Button("Continue");
    buttonPane.getChildren().add(useButton);
    accordion.expandedPaneProperty().set(null);

    final Scene scene = new Scene(root);
    fxPanel.setScene(scene);
    fxPanel.setPreferredSize(new Dimension(500, 500));
}
 
Example 14
Source File: PropertyMapView.java    From pmd-designer with BSD 2-Clause "Simplified" License 3 votes vote down vote up
private void initTableView(@NonNull ListView<Pair<PropertyDescriptorSpec, Var<String>>> view) {
    view.setEditable(true);

    //        ControlUtil.makeListViewNeverScrollHorizontal(view);

    view.setCellFactory(lv -> new PropertyMappingListCell());

    ControlUtil.makeListViewFitToChildren(view, LIST_CELL_HEIGHT);
}