Example usage for javafx.collections ObservableList remove

List of usage examples for javafx.collections ObservableList remove

Introduction

In this page you can find the example usage for javafx.collections ObservableList remove.

Prototype

boolean remove(Object o);

Source Link

Document

Removes the first occurrence of the specified element from this list, if it is present (optional operation).

Usage

From source file:com.github.naoghuman.testdata.abclist.service.ExerciseService.java

@Override
protected Task<Void> createTask() {
    return new Task<Void>() {
        {//from  ww w  .  j a v  a2 s.c o m
            updateProgress(0, saveMaxEntities);
        }

        @Override
        protected Void call() throws Exception {
            LoggerFacade.getDefault().deactivate(Boolean.TRUE);

            final StopWatch stopWatch = new StopWatch();
            stopWatch.start();

            final ObservableList<Topic> topics = SqlProvider.getDefault().findAllTopics();
            final int removeMaxTopics = (int) (Double.parseDouble(String.valueOf(topics.size())) * 0.001d);
            for (int counter = removeMaxTopics; counter > 0; counter--) {
                topics.remove(TestdataGenerator.RANDOM.nextInt(topics.size()));
            }
            final int sizeTopics = topics.size();

            final CrudService crudService = DatabaseFacade.getDefault().getCrudService(entityName);
            final ETime[] times = ETime.values();
            final int sizeTimes = times.length;
            long id = -1_000_000_000L + DatabaseFacade.getDefault().getCrudService().count(entityName);
            for (int index = 0; index < saveMaxEntities; index++) {
                final Exercise exercise = ModelProvider.getDefault().getExercise();
                exercise.setChoosenTime((times[TestdataGenerator.RANDOM.nextInt(sizeTimes)]).toString());
                exercise.setConsolidated(false); // TODO later ?
                exercise.setFinishedTime(ExerciseService.this.createGenerationTime());
                exercise.setGenerationTime(ExerciseService.this.createGenerationTime());
                if (exercise.getGenerationTime() > exercise.getFinishedTime()) {
                    final long generationTime = exercise.getGenerationTime();
                    final long finishedTime = exercise.getFinishedTime();
                    exercise.setGenerationTime(finishedTime);
                    exercise.setFinishedTime(generationTime);
                }
                exercise.setId(id++);
                exercise.setReady(TestdataGenerator.RANDOM.nextDouble() > 0.001d); // TODO if ready then add terms

                final long topicId = topics.get(TestdataGenerator.RANDOM.nextInt(sizeTopics)).getId();
                exercise.setTopicId(topicId);

                crudService.create(exercise);
                updateProgress(index, saveMaxEntities);
            }

            LoggerFacade.getDefault().deactivate(Boolean.FALSE);
            stopWatch.split();
            LoggerFacade.getDefault().debug(this.getClass(),
                    "  + " + stopWatch.toSplitString() + " for " + saveMaxEntities + " Exercises."); // NOI18N
            stopWatch.stop();

            return null;
        }
    };
}

From source file:com.cyberlogix.mist6020biometrics.RosterController.java

public void printsListener() {

    long delay = 5 * 1000;
    final long period = 5 * 1000;
    Timer timer = new Timer();
    timer.schedule(new TimerTask() {
        @Override// w  w  w  .j  a v a 2s . c o  m
        public void run() {
            Platform.runLater(new Runnable() {
                @Override
                public void run() {
                    String b64Print = bio.getImage(rosterImage, rosterPbar, rosterPin, new Stage(), period);
                    System.out.println("Print: " + b64Print);
                    try {
                        if (!b64Print.equalsIgnoreCase("error")) {
                            String url = ServerConnect.STUDENTS_URL + "/verify";
                            ServerConnect sc = new ServerConnect();
                            JSONObject req = new JSONObject();
                            req.put("print", b64Print);
                            ServerResponse msg = sc.processRequest(req.toString(), url,
                                    ServerConnect.METHOD_POST);
                            if (msg.getStatusCode() == 200 || msg.getStatusCode() == 201) {
                                ObjectMapper jackson = new ObjectMapper();
                                Student student = jackson.readValue(
                                        msg.getResponse().getJSONObject("payload").toString(), Student.class);
                                //update table
                                int pos = -1;
                                ObservableList<Student> students = tblRoster.getItems();
                                for (int i = 0; i < students.size(); i++) {
                                    if (students.get(i).getId() == student.getId()) {
                                        System.out.println("Student Matched...");
                                        student.setSignedIn("Present");
                                        students.remove(students.get(i));
                                        pos = i;
                                    }
                                }
                                if (pos >= 0) {
                                    students.add(pos, student);
                                }
                                System.out.println("Students Size: " + students.size());
                                tblRoster.setItems(students);

                                //                                    Dialogs.showConfirmDialog(new Stage(), msg.getResponse().getString("message") + " " + student.getName());
                                alertBox.setText(
                                        msg.getResponse().getString("message") + " " + student.getName());
                                alertBox.setStyle("-fx-text-fill: green; -fx-font-weight: bold;");
                            } else {
                                //                                    Dialogs.showErrorDialog(new Stage(), msg.getResponse().getString("message"), "Error " + msg.getStatusCode(), "Error");
                                alertBox.setText(msg.getResponse().getString("message"));
                                alertBox.setStyle("-fx-text-fill: red; -fx-font-weight: bold;");
                            }
                        }

                    } catch (JSONException | IOException e) {
                        UtilHelper.debugTrace(e);
                    }
                }
            });
        }
    }, delay, period);

}

From source file:dpfmanager.shell.interfaces.gui.component.report.ReportsView.java

void refreshTable(TableView tableView) {
    final ObservableList items = tableView.getItems();
    if (items == null || items.size() == 0)
        return;/*from  ww w  .java  2s  .c  o m*/

    Object item = tableView.getItems().get(0);
    items.remove(item);
    Platform.runLater(new Runnable() {
        @Override
        public void run() {
            items.add(0, item);
        }
    });
}

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    BorderPane root = new BorderPane();
    Scene scene = new Scene(root, 400, 250, Color.WHITE);

    GridPane gridpane = new GridPane();
    gridpane.setPadding(new Insets(5));
    gridpane.setHgap(10);//from w w w. j a v  a2 s .c o m
    gridpane.setVgap(10);
    ColumnConstraints column1 = new ColumnConstraints(150, 150, Double.MAX_VALUE);
    ColumnConstraints column2 = new ColumnConstraints(50);
    ColumnConstraints column3 = new ColumnConstraints(150, 150, Double.MAX_VALUE);
    column1.setHgrow(Priority.ALWAYS);
    column3.setHgrow(Priority.ALWAYS);
    gridpane.getColumnConstraints().addAll(column1, column2, column3);

    Label candidatesLbl = new Label("Candidates");
    GridPane.setHalignment(candidatesLbl, HPos.CENTER);
    gridpane.add(candidatesLbl, 0, 0);

    Label selectedLbl = new Label("selected");
    gridpane.add(selectedLbl, 2, 0);
    GridPane.setHalignment(selectedLbl, HPos.CENTER);

    // Candidates
    final ObservableList<String> candidates = FXCollections.observableArrayList("Z", "A", "B", "C", "D");
    final ListView<String> candidatesListView = new ListView<>(candidates);
    gridpane.add(candidatesListView, 0, 1);

    final ObservableList<String> selected = FXCollections.observableArrayList();
    final ListView<String> heroListView = new ListView<>(selected);
    gridpane.add(heroListView, 2, 1);

    Button sendRightButton = new Button(" > ");
    sendRightButton.setOnAction((ActionEvent event) -> {
        String potential = candidatesListView.getSelectionModel().getSelectedItem();
        if (potential != null) {
            candidatesListView.getSelectionModel().clearSelection();
            candidates.remove(potential);
            selected.add(potential);
        }
    });

    Button sendLeftButton = new Button(" < ");
    sendLeftButton.setOnAction((ActionEvent event) -> {
        String s = heroListView.getSelectionModel().getSelectedItem();
        if (s != null) {
            heroListView.getSelectionModel().clearSelection();
            selected.remove(s);
            candidates.add(s);
        }
    });
    VBox vbox = new VBox(5);
    vbox.getChildren().addAll(sendRightButton, sendLeftButton);

    gridpane.add(vbox, 1, 1);
    root.setCenter(gridpane);

    GridPane.setVgrow(root, Priority.ALWAYS);
    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    BorderPane root = new BorderPane();
    Scene scene = new Scene(root, 400, 250, Color.WHITE);

    GridPane gridpane = new GridPane();
    gridpane.setPadding(new Insets(5));
    gridpane.setHgap(10);/*from w  w  w  .j ava2 s  .c  om*/
    gridpane.setVgap(10);

    ColumnConstraints column1 = new ColumnConstraints(150, 150, Double.MAX_VALUE);
    ColumnConstraints column2 = new ColumnConstraints(50);
    ColumnConstraints column3 = new ColumnConstraints(150, 150, Double.MAX_VALUE);

    column1.setHgrow(Priority.ALWAYS);
    column3.setHgrow(Priority.ALWAYS);

    gridpane.getColumnConstraints().addAll(column1, column2, column3);

    // Candidates label
    Label candidatesLbl = new Label("Candidates");
    GridPane.setHalignment(candidatesLbl, HPos.CENTER);
    gridpane.add(candidatesLbl, 0, 0);

    // Heroes label
    Label heroesLbl = new Label("Letters");
    gridpane.add(heroesLbl, 2, 0);
    GridPane.setHalignment(heroesLbl, HPos.CENTER);

    final ObservableList<String> candidates = FXCollections.observableArrayList("A", "B", "C", "D");

    final ListView<String> candidatesListView = new ListView<>(candidates);
    gridpane.add(candidatesListView, 0, 1);

    final ObservableList<String> heroes = FXCollections.observableArrayList();
    final ListView<String> heroListView = new ListView<>(heroes);
    gridpane.add(heroListView, 2, 1);

    Button sendRightButton = new Button(" > ");
    sendRightButton.setOnAction((ActionEvent event) -> {
        String potential = candidatesListView.getSelectionModel().getSelectedItem();
        if (potential != null) {
            candidatesListView.getSelectionModel().clearSelection();
            candidates.remove(potential);
            heroes.add(potential);
        }
    });

    Button sendLeftButton = new Button(" < ");
    sendLeftButton.setOnAction((ActionEvent event) -> {
        String notHero = heroListView.getSelectionModel().getSelectedItem();
        if (notHero != null) {
            heroListView.getSelectionModel().clearSelection();
            heroes.remove(notHero);
            candidates.add(notHero);
        }
    });

    // place the buttons
    VBox vbox = new VBox(5);
    vbox.setAlignment(Pos.CENTER);
    vbox.getChildren().addAll(sendRightButton, sendLeftButton);

    GridPane.setHalignment(vbox, HPos.CENTER);
    gridpane.add(vbox, 1, 1);

    // place the grid
    root.setCenter(gridpane);
    GridPane.setVgrow(root, Priority.ALWAYS);
    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    primaryStage.setTitle("ObservableLists");
    Group root = new Group();
    Scene scene = new Scene(root, 400, 250, Color.WHITE);

    GridPane gridpane = new GridPane();
    gridpane.setPadding(new Insets(5));
    gridpane.setHgap(10);//from  w w w  . j  a v  a 2 s . co m
    gridpane.setVgap(10);

    Label candidatesLbl = new Label("Left");
    GridPane.setHalignment(candidatesLbl, HPos.CENTER);
    gridpane.add(candidatesLbl, 0, 0);

    Label heroesLbl = new Label("Right");
    gridpane.add(heroesLbl, 2, 0);
    GridPane.setHalignment(heroesLbl, HPos.CENTER);

    final ObservableList<String> lefts = FXCollections.observableArrayList("A", "B", "C");
    final ListView<String> leftListView = new ListView<String>(lefts);
    leftListView.setPrefWidth(150);
    leftListView.setPrefHeight(150);

    gridpane.add(leftListView, 0, 1);

    final ObservableList<String> rights = FXCollections.observableArrayList();
    final ListView<String> rightListView = new ListView<String>(rights);
    rightListView.setPrefWidth(150);
    rightListView.setPrefHeight(150);

    gridpane.add(rightListView, 2, 1);

    Button sendRightButton = new Button(">");
    sendRightButton.setOnAction(new EventHandler<ActionEvent>() {
        public void handle(ActionEvent event) {
            String item = leftListView.getSelectionModel().getSelectedItem();
            if (item != null) {
                leftListView.getSelectionModel().clearSelection();
                lefts.remove(item);
                rights.add(item);
            }
        }
    });

    Button sendLeftButton = new Button("<");
    sendLeftButton.setOnAction(new EventHandler<ActionEvent>() {
        public void handle(ActionEvent event) {
            String item = rightListView.getSelectionModel().getSelectedItem();
            if (item != null) {
                rightListView.getSelectionModel().clearSelection();
                rights.remove(item);
                lefts.add(item);
            }
        }
    });

    VBox vbox = new VBox(5);
    vbox.getChildren().addAll(sendRightButton, sendLeftButton);

    gridpane.add(vbox, 1, 1);
    GridPane.setConstraints(vbox, 1, 1, 1, 2, HPos.CENTER, VPos.CENTER);

    root.getChildren().add(gridpane);
    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:org.beryx.viewreka.fxapp.Viewreka.java

public void showFilePane(boolean show, FxProject newProject) {
    ObservableList<Node> items = mainSplitPane.getItems();
    if (show) {//from   www.  j a  v  a  2 s .c  om
        if (!items.contains(fileSplitPane)) {
            items.add(0, fileSplitPane);
        }
        configureMainSplitDivider(project);
    } else {
        items.remove(fileSplitPane);
    }
    mnuToggleFilePane.setText((show ? "Hide" : "Show") + " File Area");
    if (newProject != null) {
        newProject.getProjectSettingsManager().getSettings().setProperty(PROP_FILE_AREA_VISIBLE, show);
    }
}

From source file:aajavafx.Schedule1Controller.java

public ObservableList<CustomerProperty> getUnsignedCustomers() throws IOException, JSONException {
    //Customers customers = new Customers();
    EmployeeSchedule mySchedule = new EmployeeSchedule();
    singleton = Singleton.getInstance();
    Gson gson = new Gson();

    ObservableList<CustomerProperty> customerPropertyCustomersSigned = FXCollections.observableArrayList();
    ObservableList<CustomerProperty> customerPropertyAllCustomers = this.getCustomer();
    JSONObject jo = new JSONObject();

    CredentialsProvider provider = new BasicCredentialsProvider();
    UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("EMPLOYEE", "password");
    provider.setCredentials(AuthScope.ANY, credentials);
    HttpClient client = HttpClientBuilder.create().setDefaultCredentialsProvider(provider).build();
    HttpGet get = new HttpGet("http://localhost:8080/MainServerREST/api/employeeschedule/date/" + getDate());
    HttpResponse response = client.execute(get);
    System.out.println("RESPONSE IS: " + response);

    JSONArray jsonArray = new JSONArray(
            IOUtils.toString(response.getEntity().getContent(), Charset.forName("UTF-8")));
    System.out.println("1 " + jsonArray);

    for (int i = 0; i < jsonArray.length(); i++) {
        jo = (JSONObject) jsonArray.getJSONObject(i);

        mySchedule = gson.fromJson(jo.toString(), EmployeeSchedule.class);

        customerPropertyCustomersSigned.add(new CustomerProperty(mySchedule.getCustomersCuId().getCuId(),
                mySchedule.getCustomersCuId().getCuFirstname(), mySchedule.getCustomersCuId().getCuLastname(),
                mySchedule.getCustomersCuId().getCuPersonnummer()));

    }/* w ww.j a v a2  s  . co  m*/

    for (int i = 0; i < customerPropertyAllCustomers.size(); i++) {

        for (int j = 0; j < customerPropertyCustomersSigned.size(); j++) {

            if (customerPropertyAllCustomers.get(i).getPersonnumer()
                    .equals(customerPropertyCustomersSigned.get(j).getPersonnumer())) {

                customerPropertyAllCustomers.remove(i);
            }
        }
    }

    singleton.setList(customerPropertyAllCustomers);
    return customerPropertyAllCustomers;
}