Example usage for javafx.collections FXCollections observableArrayList

List of usage examples for javafx.collections FXCollections observableArrayList

Introduction

In this page you can find the example usage for javafx.collections FXCollections observableArrayList.

Prototype

public static <E> ObservableList<E> observableArrayList(Collection<? extends E> col) 

Source Link

Document

Creates a new observable array list and adds a content of collection col to it.

Usage

From source file:net.sourceforge.msscodefactory.cfbam.v2_7.CFBamJavaFX.CFBamJavaFXClearTopDepPickerPane.java

public void setJavaFXDataCollection(Collection<ICFBamClearTopDepObj> value) {
    final String S_ProcName = "setJavaFXDataCollection";
    javafxDataCollection = value;// w  w  w .  j  a v a 2  s  .c  o  m
    observableListOfClearTopDep = null;
    if (javafxDataCollection != null) {
        observableListOfClearTopDep = FXCollections.observableArrayList(javafxDataCollection);
        observableListOfClearTopDep.sort(compareClearTopDepByQualName);
    } else {
        observableListOfClearTopDep = FXCollections.observableArrayList();
    }
    if (dataTable != null) {
        dataTable.setItems(observableListOfClearTopDep);
        // Hack from stackoverflow to fix JavaFX TableView refresh issue
        ((TableColumn) dataTable.getColumns().get(0)).setVisible(false);
        ((TableColumn) dataTable.getColumns().get(0)).setVisible(true);
    }
}

From source file:com.bekwam.resignator.ResignatorAppMainViewController.java

@FXML
public void initialize() {

    try {//from   w  w w . jav a  2s. c o m

        miHelp.setAccelerator(KeyCombination.keyCombination("F1"));

        cbType.getItems().add(SigningArgumentsType.JAR);
        cbType.getItems().add(SigningArgumentsType.FOLDER);

        cbType.getSelectionModel().select(SigningArgumentsType.JAR);

        cbType.setConverter(new StringConverter<SigningArgumentsType>() {

            @Override
            public String toString(SigningArgumentsType type) {
                return StringUtils.capitalize(StringUtils.lowerCase(String.valueOf(type)));
            }

            @Override
            public SigningArgumentsType fromString(String type) {
                return Enum.valueOf(SigningArgumentsType.class, StringUtils.upperCase(type));
            }

        });

        activeConfiguration.activeProfileProperty().bindBidirectional(activeProfile.profileNameProperty());
        tfSourceFile.textProperty().bindBidirectional(activeProfile.sourceFileFileNameProperty());
        tfTargetFile.textProperty().bindBidirectional(activeProfile.targetFileFileNameProperty());
        ckReplace.selectedProperty().bindBidirectional(activeProfile.replaceSignaturesProperty());
        cbType.valueProperty().bindBidirectional(activeProfile.argsTypeProperty());

        miSave.disableProperty().bind(needsSave.not());

        tfSourceFile.textProperty().addListener(new WeakInvalidationListener(needsSaveListener));
        tfTargetFile.textProperty().addListener(new WeakInvalidationListener(needsSaveListener));
        ckReplace.selectedProperty().addListener(new WeakInvalidationListener(needsSaveListener));
        cbType.valueProperty().addListener(new WeakInvalidationListener(needsSaveListener));

        lblSource.setText(SOURCE_LABEL_JAR);
        lblTarget.setText(TARGET_LABEL_JAR);
        cbType.getSelectionModel().selectedItemProperty().addListener((ov, old_v, new_v) -> {
            if (new_v == SigningArgumentsType.FOLDER) {
                if (!lblSource.getText().equalsIgnoreCase(SOURCE_LABEL_FOLDER)) {
                    lblSource.setText(SOURCE_LABEL_FOLDER);
                }
                if (!lblSource.getText().equalsIgnoreCase(TARGET_LABEL_FOLDER)) {
                    lblTarget.setText(TARGET_LABEL_FOLDER);
                }
            } else {
                if (!lblSource.getText().equalsIgnoreCase(SOURCE_LABEL_JAR)) {
                    lblSource.setText(SOURCE_LABEL_JAR);
                }
                if (!lblSource.getText().equalsIgnoreCase(TARGET_LABEL_JAR)) {
                    lblTarget.setText(TARGET_LABEL_JAR);
                }
            }
        });

        lvProfiles.getSelectionModel().selectedItemProperty().addListener((ov, old_v, new_v) -> {

            if (new_v == null) { // coming from clearSelection or sort
                return;
            }

            if (needsSave.getValue()) {

                Alert alert = new Alert(Alert.AlertType.CONFIRMATION, "Discard unsaved profile?");
                alert.setHeaderText("Unsaved profile");
                Optional<ButtonType> response = alert.showAndWait();
                if (!response.isPresent() || response.get() != ButtonType.OK) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("[SELECT] discard canceled");
                    }
                    return;
                }
            }

            if (logger.isDebugEnabled()) {
                logger.debug("[SELECT] nv={}", new_v);
            }
            doLoadProfile(new_v);
        });

        lvProfiles.setCellFactory(TextFieldListCell.forListView());

        Task<Void> t = new Task<Void>() {

            @Override
            protected Void call() throws Exception {

                updateMessage("Loading configuration");
                configurationDS.loadConfiguration();

                if (!configurationDS.isSecured()) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("[CALL] config not secured; getting password");
                    }
                    NewPasswordController npc = newPasswordControllerProvider.get();

                    if (logger.isDebugEnabled()) {
                        logger.debug("[INIT TASK] npc id={}", npc.hashCode());
                    }

                    Platform.runLater(() -> {
                        try {
                            npc.showAndWait();
                        } catch (Exception exc) {
                            logger.error("error showing npc", exc);
                        }
                    });

                    synchronized (npc) {
                        try {
                            npc.wait(MAX_WAIT_TIME); // 10 minutes to enter the password
                        } catch (InterruptedException exc) {
                            logger.error("new password operation interrupted", exc);
                        }
                    }

                    if (logger.isDebugEnabled()) {
                        logger.debug("[INIT TASK] npc={}", npc.getHashedPassword());
                    }

                    if (StringUtils.isNotEmpty(npc.getHashedPassword())) {

                        activeConfiguration.setHashedPassword(npc.getHashedPassword());
                        activeConfiguration.setUnhashedPassword(npc.getUnhashedPassword());
                        activeConfiguration.setLastUpdatedDateTime(LocalDateTime.now());
                        configurationDS.saveConfiguration();

                        configurationDS.loadConfiguration();
                        configurationDS.decrypt(activeConfiguration.getUnhashedPassword());

                    } else {

                        Platform.runLater(() -> {
                            Alert noPassword = new Alert(Alert.AlertType.INFORMATION,
                                    "You'll need to provide a password to save your keystore credentials.");
                            noPassword.showAndWait();
                        });

                        return null;
                    }
                } else {

                    PasswordController pc = passwordControllerProvider.get();

                    Platform.runLater(() -> {
                        try {
                            pc.showAndWait();
                        } catch (Exception exc) {
                            logger.error("error showing pc", exc);
                        }
                    });

                    synchronized (pc) {
                        try {
                            pc.wait(MAX_WAIT_TIME); // 10 minutes to enter the password
                        } catch (InterruptedException exc) {
                            logger.error("password operation interrupted", exc);
                        }
                    }

                    Platform.runLater(() -> {

                        if (pc.getStage().isShowing()) { // ended in timeout timeout
                            pc.getStage().hide();
                        }

                        if (pc.wasCancelled() || pc.wasReset() || !pc.doesPasswordMatch()) {

                            if (logger.isDebugEnabled()) {
                                logger.debug("[INIT TASK] was cancelled or the number of retries was exceeded");
                            }

                            String msg = "";
                            if (pc.wasCancelled()) {
                                msg = "You must provide a password to the datastore. Exitting...";
                            } else if (pc.wasReset()) {
                                msg = "Data file removed. Exitting...";
                            } else {
                                msg = "Exceeded maximum number of retries. Exitting...";
                            }

                            Alert alert = new Alert(Alert.AlertType.WARNING, msg);
                            alert.setOnCloseRequest((evt) -> {
                                Platform.exit();
                                System.exit(1);
                            });
                            alert.showAndWait();

                        } else {

                            //
                            // save password for later decryption ops
                            //

                            activeConfiguration.setUnhashedPassword(pc.getPassword());
                            configurationDS.decrypt(activeConfiguration.getUnhashedPassword());

                            //
                            // init profileBrowser
                            //
                            if (logger.isDebugEnabled()) {
                                logger.debug("[INIT TASK] loading profiles from source");
                            }

                            long startTimeMillis = System.currentTimeMillis();

                            final List<String> profileNames = configurationDS.getProfiles().stream()
                                    .map(Profile::getProfileName).sorted((o1, o2) -> o1.compareToIgnoreCase(o2))
                                    .collect(Collectors.toList());

                            final List<String> recentProfiles = configurationDS.getRecentProfileNames();

                            if (logger.isDebugEnabled()) {
                                logger.debug("[INIT TASK] loading profiles into UI");
                            }

                            lvProfiles.setItems(FXCollections.observableArrayList(profileNames));

                            if (CollectionUtils.isNotEmpty(recentProfiles)) {
                                mRecentProfiles.getItems().clear();
                                mRecentProfiles.getItems().addAll(
                                        FXCollections.observableArrayList(recentProfiles.stream().map((s) -> {
                                            MenuItem mi = new MenuItem(s);
                                            mi.setOnAction(recentProfileLoadHandler);
                                            return mi;
                                        }).collect(Collectors.toList())));
                            }

                            //
                            // #31 preload the last active profile
                            //
                            if (StringUtils.isNotEmpty(activeConfiguration.getActiveProfile())) {

                                if (logger.isDebugEnabled()) {
                                    logger.debug("[INIT TASK] preloading last active profile={}",
                                            activeConfiguration.getActiveProfile());
                                }
                                doLoadProfile(activeConfiguration.getActiveProfile());
                            }

                            long endTimeMillis = System.currentTimeMillis();

                            if (logger.isDebugEnabled()) {
                                logger.debug("[INIT TASK] loading profiles took {} ms",
                                        (endTimeMillis - startTimeMillis));
                            }
                        }
                    });
                }

                return null;
            }

            @Override
            protected void succeeded() {
                super.succeeded();
                updateMessage("");
                lblStatus.textProperty().unbind();
            }

            @Override
            protected void cancelled() {
                super.cancelled();
                logger.error("task cancelled", getException());
                updateMessage("");
                lblStatus.textProperty().unbind();
            }

            @Override
            protected void failed() {
                super.failed();
                logger.error("task failed", getException());
                updateMessage("");
                lblStatus.textProperty().unbind();
            }
        };

        lblStatus.textProperty().bind(t.messageProperty());

        new Thread(t).start();

    } catch (Exception exc) {

        logger.error("can't load configuration", exc);

        String msg = "Verify that the user has access to the directory '" + configFile + "' under "
                + System.getProperty("user.home") + ".";

        Alert alert = new Alert(Alert.AlertType.ERROR, msg);
        alert.setHeaderText("Can't load config file");
        alert.showAndWait();

        Platform.exit();
    }
}

From source file:net.sourceforge.msscodefactory.cfbam.v2_7.CFBamJavaFX.CFBamJavaFXClearSubDep1PickerPane.java

public void setJavaFXDataCollection(Collection<ICFBamClearSubDep1Obj> value) {
    final String S_ProcName = "setJavaFXDataCollection";
    javafxDataCollection = value;//from   w  w  w .  j a v a2 s . c o  m
    observableListOfClearSubDep1 = null;
    if (javafxDataCollection != null) {
        observableListOfClearSubDep1 = FXCollections.observableArrayList(javafxDataCollection);
        observableListOfClearSubDep1.sort(compareClearSubDep1ByQualName);
    } else {
        observableListOfClearSubDep1 = FXCollections.observableArrayList();
    }
    if (dataTable != null) {
        dataTable.setItems(observableListOfClearSubDep1);
        // Hack from stackoverflow to fix JavaFX TableView refresh issue
        ((TableColumn) dataTable.getColumns().get(0)).setVisible(false);
        ((TableColumn) dataTable.getColumns().get(0)).setVisible(true);
    }
}

From source file:net.sourceforge.msscodefactory.cfbam.v2_7.CFBamJavaFX.CFBamJavaFXClearSubDep2PickerPane.java

public void setJavaFXDataCollection(Collection<ICFBamClearSubDep2Obj> value) {
    final String S_ProcName = "setJavaFXDataCollection";
    javafxDataCollection = value;//w w  w .j  a  va 2  s  .  c o  m
    observableListOfClearSubDep2 = null;
    if (javafxDataCollection != null) {
        observableListOfClearSubDep2 = FXCollections.observableArrayList(javafxDataCollection);
        observableListOfClearSubDep2.sort(compareClearSubDep2ByQualName);
    } else {
        observableListOfClearSubDep2 = FXCollections.observableArrayList();
    }
    if (dataTable != null) {
        dataTable.setItems(observableListOfClearSubDep2);
        // Hack from stackoverflow to fix JavaFX TableView refresh issue
        ((TableColumn) dataTable.getColumns().get(0)).setVisible(false);
        ((TableColumn) dataTable.getColumns().get(0)).setVisible(true);
    }
}

From source file:net.sourceforge.msscodefactory.cfbam.v2_7.CFBamJavaFX.CFBamJavaFXClearSubDep3PickerPane.java

public void setJavaFXDataCollection(Collection<ICFBamClearSubDep3Obj> value) {
    final String S_ProcName = "setJavaFXDataCollection";
    javafxDataCollection = value;// www .  j a va  2s  .co m
    observableListOfClearSubDep3 = null;
    if (javafxDataCollection != null) {
        observableListOfClearSubDep3 = FXCollections.observableArrayList(javafxDataCollection);
        observableListOfClearSubDep3.sort(compareClearSubDep3ByQualName);
    } else {
        observableListOfClearSubDep3 = FXCollections.observableArrayList();
    }
    if (dataTable != null) {
        dataTable.setItems(observableListOfClearSubDep3);
        // Hack from stackoverflow to fix JavaFX TableView refresh issue
        ((TableColumn) dataTable.getColumns().get(0)).setVisible(false);
        ((TableColumn) dataTable.getColumns().get(0)).setVisible(true);
    }
}

From source file:net.sourceforge.msscodefactory.cfbam.v2_7.CFBamJavaFX.CFBamJavaFXSchemaRefPickerPane.java

public void setJavaFXDataCollection(Collection<ICFBamSchemaRefObj> value) {
    final String S_ProcName = "setJavaFXDataCollection";
    javafxDataCollection = value;//from  ww w .java  2 s.  c o  m
    observableListOfSchemaRef = null;
    if (javafxDataCollection != null) {
        observableListOfSchemaRef = FXCollections.observableArrayList(javafxDataCollection);
        observableListOfSchemaRef.sort(compareSchemaRefByQualName);
    } else {
        observableListOfSchemaRef = FXCollections.observableArrayList();
    }
    if (dataTable != null) {
        dataTable.setItems(observableListOfSchemaRef);
        // Hack from stackoverflow to fix JavaFX TableView refresh issue
        ((TableColumn) dataTable.getColumns().get(0)).setVisible(false);
        ((TableColumn) dataTable.getColumns().get(0)).setVisible(true);
    }
}

From source file:org.virtualAsylum.spriggan.data.Addon.java

public void setTags(String[] tags) {
    this.tags.set(FXCollections.observableArrayList(tags));
}

From source file:org.virtualAsylum.spriggan.data.Addon.java

public void setInstallIgnore(String[] installIgnore) {
    if (installIgnore == null || installIgnore.length == 0) {
        return;/*from   www  .ja v a 2s .c  o m*/
    }
    this.installIgnore.set(FXCollections.observableArrayList(installIgnore));
}

From source file:com.exalttech.trex.ui.views.PacketTableView.java

/**
 * Set table packet data//from w  w  w  .  ja  v  a  2  s  .c o  m
 *
 * @param tableData
 */
public void setPacketData(TableProfile tableData) {
    this.tabledata = tableData;
    numOfStreamLoaded = 0;
    doUpdate = false;
    updateNumberOfEnabledStream();
    streamPacketTableView.setItems(FXCollections.observableArrayList(tableData.getStreamsList()));
}

From source file:de.ifsr.adam.ImageGenerator.java

/**
 * Creates the data list for a pie chart.
 *
 * @param result The result JSONObject you wish to transform
 * @param answerType The answer type JSONObject of the question
 * @return//from   w w  w  . ja  v  a 2  s . c o  m
 */
private ObservableList<PieChart.Data> generateDataPieChart(JSONObject result, JSONObject answerType) {
    ArrayList<PieChart.Data> list = new ArrayList<>();

    try {
        JSONObject answers;
        String[] fieldNames;

        try {
            answers = answerType.getJSONObject("answers");
            fieldNames = JSONObject.getNames(result);
        } catch (NullPointerException e) {
            log.error("Missing JSONObject in result:" + result + " answerType: " + answerType);
            log.debug("", e);
            return FXCollections.observableArrayList(list);
        }

        for (int i = 1; i < fieldNames.length; i++) {//i is 1 at the start to ignore the empty String result in the answers
            String answer = answers.getString(fieldNames[i]);
            Integer value = result.getInt(fieldNames[i]);
            list.add(new PieChart.Data(answer, value));
        }
    } catch (JSONException e) {
        log.error(e);
    }

    return FXCollections.observableArrayList(list);
}