List of usage examples for javafx.collections ObservableList add
boolean add(E e);
From source file:testclientside.implement.implPerson.java
@Override public ObservableList<Person> select() { ObservableList<Person> listData = FXCollections.observableArrayList(); JSONArray arr;//from www .j a v a2s . c om String jsonStr = Service.ServiceGet("select.php"); if (jsonStr != null) { layoutController.statusConnection = 1; try { JSONObject jsonObj = new JSONObject(jsonStr); arr = jsonObj.getJSONArray("hobi"); for (int i = 0; i < arr.length(); i++) { JSONObject c = arr.getJSONObject(i); Person p = new Person(); p.setId(c.getString("id")); p.setNama(c.getString("nama")); p.setHobi(c.getString("hobi")); listData.add(p); } } catch (JSONException e) { } } else { Platform.runLater(() -> { dialog.dialog(Alert.AlertType.ERROR, "Error Connection To Server"); }); layoutController.statusConnection = 0; } return listData; }
From source file:io.github.moosbusch.permagon.configuration.builder.spi.AbstractPermagonBuilder.java
protected Object putListProperty(String propertyName, Object value) { Object result = null;// w w w . jav a2 s . c o m Object childrenValue = Objects.requireNonNull(get(propertyName)); if (childrenValue instanceof ObservableMap) { ObservableMap propertiesMap = (ObservableMap) childrenValue; Object obj = Objects.requireNonNull(propertiesMap.get(propertyName)); if (obj instanceof ObservableList) { ObservableList childrenValueList = (ObservableList) obj; result = childrenValueList; if ((value instanceof Node) || (value instanceof Tab)) { if (!childrenValueList.contains(value)) { childrenValueList.add(value); properties.put(propertyName, childrenValueList); } } } } return result; }
From source file:memoryaid.SetReminderController.java
@FXML public void buildReminderTableData() throws SQLException { System.out.println("In builddata"); DbConnection db = new DbConnection(); Connection conn = db.connect(); String SQL = "select RId,ReminderName,ReminderType,StartDate,EndDate,ReminderTime from reminders"; ResultSet rs = conn.createStatement().executeQuery(SQL); TableColumn rIdCol = new TableColumn("RId"); rIdCol.setCellValueFactory(new PropertyValueFactory<>("reminderId")); TableColumn reminderNameCol = new TableColumn("ReminderName"); reminderNameCol.setCellValueFactory(new PropertyValueFactory<>("reminderName")); TableColumn reminderTypeCol = new TableColumn("ReminderType"); reminderTypeCol.setCellValueFactory(new PropertyValueFactory<>("reminderType")); TableColumn startDateCol = new TableColumn("StartDate"); startDateCol.setCellValueFactory(new PropertyValueFactory<>("startDate")); TableColumn endDateCol = new TableColumn("EndDate"); endDateCol.setCellValueFactory(new PropertyValueFactory<>("endDate")); TableColumn reminderTimeCol = new TableColumn("ReminderTime"); reminderTimeCol.setCellValueFactory(new PropertyValueFactory<>("reminderTime")); reminderTable.getColumns().add(rIdCol); reminderTable.getColumns().add(reminderNameCol); reminderTable.getColumns().add(reminderTypeCol); reminderTable.getColumns().add(startDateCol); reminderTable.getColumns().add(endDateCol); reminderTable.getColumns().add(reminderTimeCol); ObservableList<Object> data = FXCollections.observableArrayList(); while (rs.next()) { String rId = String.valueOf(rs.getInt("RId")); data.add(new ReminderModel(rId, rs.getString("ReminderName"), rs.getString("ReminderType"), rs.getString("StartDate"), rs.getString("EndDate"), rs.getString("ReminderTime"))); }/* w ww . ja v a 2 s .c om*/ rs.close(); conn.close(); Callback<TableColumn<ReminderModel, String>, TableCell<ReminderModel, String>> cellFactory = ( TableColumn<ReminderModel, String> p) -> new EditingCell(); //Code For Reminder Name update reminderNameCol.setCellValueFactory(new PropertyValueFactory<>("reminderName")); reminderNameCol.setCellFactory(cellFactory); reminderNameCol.setOnEditCommit(new EventHandler<CellEditEvent<ReminderModel, String>>() { @Override public void handle(CellEditEvent<ReminderModel, String> t) { ((ReminderModel) t.getTableView().getItems().get(t.getTablePosition().getRow())) .setReminderName(t.getNewValue()); System.out.println("*******" + t.getNewValue()); ReminderModel selectedItem = (ReminderModel) reminderTable.getSelectionModel().getSelectedItem(); System.out.println(selectedItem); String rIdToUpdate = selectedItem.getReminderId(); Statement stmt = null; DbConnection db = new DbConnection(); Connection conn = db.connect(); try { stmt = conn.createStatement(); String updateSql = "UPDATE Reminders set ReminderName = '" + t.getNewValue() + "'" + "WHERE RId = '" + rIdToUpdate + "'"; stmt.executeUpdate(updateSql); } catch (SQLException ex) { Logger.getLogger(SetReminderController.class.getName()).log(Level.SEVERE, null, ex); } } }); //For ReminderType Column Update reminderTypeCol.setCellValueFactory(new PropertyValueFactory<>("reminderType")); reminderTypeCol.setCellFactory(cellFactory); reminderTypeCol.setOnEditCommit(new EventHandler<CellEditEvent<ReminderModel, String>>() { @Override public void handle(CellEditEvent<ReminderModel, String> t) { ((ReminderModel) t.getTableView().getItems().get(t.getTablePosition().getRow())) .setReminderType(t.getNewValue()); System.out.println("*******" + t.getNewValue()); ReminderModel selectedItem = (ReminderModel) reminderTable.getSelectionModel().getSelectedItem(); System.out.println(selectedItem); String rIdToUpdate = selectedItem.getReminderId(); Statement stmt = null; DbConnection db = new DbConnection(); Connection conn = db.connect(); try { stmt = conn.createStatement(); String updateSql = "UPDATE Reminders set ReminderType = '" + t.getNewValue() + "'" + "WHERE RId = '" + rIdToUpdate + "'"; stmt.executeUpdate(updateSql); } catch (SQLException ex) { Logger.getLogger(SetReminderController.class.getName()).log(Level.SEVERE, null, ex); } } }); //For reminderTime Column Update reminderTimeCol.setCellValueFactory(new PropertyValueFactory<>("reminderTime")); reminderTimeCol.setCellFactory(cellFactory); reminderTimeCol.setOnEditCommit(new EventHandler<CellEditEvent<ReminderModel, String>>() { @Override public void handle(CellEditEvent<ReminderModel, String> t) { ((ReminderModel) t.getTableView().getItems().get(t.getTablePosition().getRow())) .setReminderTime(t.getNewValue()); System.out.println("*******" + t.getNewValue()); ReminderModel selectedItem = (ReminderModel) reminderTable.getSelectionModel().getSelectedItem(); System.out.println(selectedItem); String rIdToUpdate = selectedItem.getReminderId(); Statement stmt = null; DbConnection db = new DbConnection(); Connection conn = db.connect(); try { stmt = conn.createStatement(); String updateSql = "UPDATE Reminders set ReminderTime = '" + t.getNewValue() + "'" + "WHERE RId = '" + rIdToUpdate + "'"; stmt.executeUpdate(updateSql); } catch (SQLException ex) { Logger.getLogger(SetReminderController.class.getName()).log(Level.SEVERE, null, ex); } } }); reminderTable.setItems(data); }
From source file:com.jscriptive.moneyfx.ui.chart.ChartFrame.java
/** * This method is invoked when the monthly in/out button has been toggled * * @param actionEvent//from w ww . ja va 2 s . c om */ public void monthlyInOutToggled(ActionEvent actionEvent) { final CategoryAxis xAxis = new CategoryAxis(); final NumberAxis yAxis = new NumberAxis(); xAxis.setLabel("Month of Year"); yAxis.setLabel("In/Out in Euro"); final BarChart<String, Number> barChart = new BarChart<>(xAxis, yAxis); barChart.setTitle("Monthly in/out"); chartFrame.setCenter(barChart); ToggleButton toggle = (ToggleButton) actionEvent.getTarget(); if (toggle.isSelected()) { Account account = accountCombo.getValue(); String accountLabel = getAccountLabel(account); XYChart.Series<String, Number> inSeries = new XYChart.Series<>(); inSeries.setName("In" + accountLabel); barChart.getData().add(inSeries); XYChart.Series<String, Number> outSeries = new XYChart.Series<>(); outSeries.setName("Out" + accountLabel); barChart.getData().add(outSeries); ValueRange<LocalDate> period = getTransactionOpRange(account, yearCombo.getValue()); if (period.isEmpty()) { return; } ObservableList<String> monthLabels = FXCollections.observableArrayList(); for (LocalDate date = period.from().withDayOfMonth(1); !date.isAfter(period.to()); date = date .plusMonths(1)) { monthLabels.add(getMonthLabel(date.getYear(), date.getMonthValue())); } xAxis.setCategories(monthLabels); Service<Void> service = new Service<Void>() { @Override protected Task<Void> createTask() { return new Task<Void>() { @Override protected Void call() throws Exception { List<TransactionVolume> incomingVolumes = (account == ALL_ACCOUNTS) ? transactionRepository.getMonthlyIncomingVolumes(false) : transactionRepository.getMonthlyIncomingVolumesOfAccount(account, false); if (INTEGER_ZERO.compareTo(yearCombo.getValue()) < 0) { incomingVolumes = incomingVolumes.stream() .filter(v -> v.getYear().equals(yearCombo.getValue())) .sorted((v1, v2) -> v1.getDate().compareTo(v2.getDate())).collect(toList()); } for (TransactionVolume volume : incomingVolumes) { String monthLabel = getMonthLabel(volume.getYear(), volume.getMonth()); XYChart.Data<String, Number> data = new XYChart.Data<>(monthLabel, volume.getVolume()); Platform.runLater(() -> { inSeries.getData().add(data); StackPane barNode = (StackPane) data.getNode(); // TODO make that look nicer Label labelNode = new Label( CurrencyFormat.getInstance().format(volume.getVolume())); labelNode.setPrefWidth(100); labelNode.setAlignment(CENTER_RIGHT); labelNode.setRotate(270); barNode.getChildren().add(labelNode); barNode.addEventHandler(MOUSE_CLICKED, event -> handleMonthlyInOutChartMouseClickEvent( (account == ALL_ACCOUNTS) ? null : account, of(volume.getYear(), volume.getMonth(), 1), event)); }); } List<TransactionVolume> outgoingVolumes = (account == ALL_ACCOUNTS) ? transactionRepository.getMonthlyOutgoingVolumes(false) : transactionRepository.getMonthlyOutgoingVolumesOfAccount(account, false); if (INTEGER_ZERO.compareTo(yearCombo.getValue()) < 0) { outgoingVolumes = outgoingVolumes.stream() .filter(v -> v.getYear().equals(yearCombo.getValue())) .sorted((v1, v2) -> v1.getDate().compareTo(v2.getDate())).collect(toList()); } for (TransactionVolume volume : outgoingVolumes) { String monthLabel = getMonthLabel(volume.getYear(), volume.getMonth()); XYChart.Data<String, Number> data = new XYChart.Data<>(monthLabel, volume.getVolume().abs()); Platform.runLater(() -> { outSeries.getData().add(data); StackPane node = (StackPane) data.getNode(); // TODO make that look nicer Label labelNode = new Label( CurrencyFormat.getInstance().format(volume.getVolume())); labelNode.setPrefWidth(100); labelNode.setAlignment(CENTER_RIGHT); labelNode.setRotate(270); node.getChildren().add(labelNode); node.addEventHandler(MOUSE_CLICKED, event -> handleMonthlyInOutChartMouseClickEvent( (account == ALL_ACCOUNTS ? null : account), volume.getDate(), event)); }); } return null; } }; } }; service.start(); } }
From source file:sonicScream.controllers.CategoryTabControllerTest.java
@Before public void setUp() throws URISyntaxException, IOException { URL location = getClass().getResource("/sonicScream/assets/test"); Path folder = Paths.get(location.toURI()); ObservableList<Script> scriptList = FXCollections.observableArrayList(); Category category = mock(Category.class); when(category.getCategoryScripts()).thenReturn(scriptList); when(category.categoryNameProperty()).thenReturn(new SimpleStringProperty(Constants.CATEGORY_HEROES)); List<Path> paths = FilesEx.listFiles(folder); Script realScript = new Script(paths.get(0), category); Script mockScript = mock(Script.class);//new Script(paths.get(0), category); when(mockScript.getRootNode()).thenReturn(realScript.getRootNode()); when(mockScript.getSimpleTree()).thenReturn(realScript.getSimpleTree()); when(mockScript.getParentCategoryName()).thenReturn(profileName); scriptList.add(mockScript); scriptList.add(mockScript);//w w w .j a va 2 s . co m ArrayList<Category> categories = new ArrayList<>(); categories.add(category); when(profile.getCategories()).thenReturn(categories); profile.getCategories().add(category); controller = new CategoryTabController(profile.getCategories().get(0)); }
From source file:com.ggvaidya.scinames.ui.DatasetDiffController.java
@FXML private void displayComparisonStats(ActionEvent e) { Dataset ds1 = dataset1ComboBox.getValue(); Dataset ds2 = dataset2ComboBox.getValue(); Table<String, Dataset, String> precalc = getComparisonStats(ds1, ds2); ObservableList<TableColumn> cols = comparisonTableView.getColumns(); cols.clear();/*from w w w . j a v a 2 s . c om*/ TableColumn<String, String> rowName = new TableColumn<>(""); rowName.setCellValueFactory(cvf -> new ReadOnlyStringWrapper(cvf.getValue())); cols.add(rowName); for (Dataset ds : Arrays.asList(ds1, ds2)) { TableColumn<String, String> datasetCol = new TableColumn<>(ds.getName()); datasetCol.setCellValueFactory(cvf -> new ReadOnlyStringWrapper(precalc.get(cvf.getValue(), ds))); cols.add(datasetCol); } // The "items" here are just the rows we've calculated. comparisonTableView.setItems(getComparisonStatRowHeaders()); }
From source file:org.jevis.jeconfig.plugin.classes.ClassTree.java
public ObservableList<TreeItem<JEVisClass>> getChildrenList(TreeItem<JEVisClass> item) { if (item == null || item.getValue() == null) { return FXCollections.emptyObservableList(); }//from w w w . ja v a2 s . co m if (_itemChildren.containsKey(item)) { return _itemChildren.get(item); } ObservableList<TreeItem<JEVisClass>> list = FXCollections.observableArrayList(); try { for (JEVisClass child : item.getValue().getHeirs()) { TreeItem<JEVisClass> newItem = buildItem(child); list.add(newItem); } } catch (JEVisException ex) { Logger.getLogger(ClassTree.class.getName()).log(Level.SEVERE, null, ex); } // sortList(list); _itemChildren.put(item, list); return list; }
From source file:com.github.douglasjunior.simpleCSVEditor.FXMLController.java
private ObservableList<CSVRow> readFile(File csvFile) throws IOException { ObservableList<CSVRow> rows = FXCollections.observableArrayList(); Integer maxColumns = 0;// www .ja v a2s . c om try (Reader in = new InputStreamReader(new FileInputStream(csvFile));) { CSVParser parse = csvFormat.parse(in); for (CSVRecord record : parse.getRecords()) { if (maxColumns < record.size()) { maxColumns = record.size(); } CSVRow row = new CSVRow(); for (int i = 0; i < record.size(); i++) { row.getColumns().add(new SimpleStringProperty(record.get(i))); } rows.add(row); } this.numbeColumns = maxColumns; } return rows; }
From source file:com.ggvaidya.scinames.ui.DatasetDiffController.java
private void displayRows(List<DatasetRow> rows) { ObservableList<TableColumn> cols = comparisonTableView.getColumns(); cols.clear();//from w ww. ja v a 2 s .c om List<DatasetColumn> datasetCols = rows.stream().flatMap(row -> row.getColumns().stream()).distinct() .collect(Collectors.toList()); for (DatasetColumn datasetCol : datasetCols) { cols.add(createTableColumnForDatasetColumn(datasetCol.getName(), datasetCol)); } // Add the by-unique before the columns. Function<DatasetRow, String> uniqueMap = getByUniqueMap(); cols.add(0, createTableColumnForDatasetRow("Unique", row -> truncateString(uniqueMap.apply(row), 30))); // Add the dataset after the columns. cols.add(createTableColumnForDatasetRow("Dataset", row -> row.getDataset().getCitation())); comparisonTableView.setItems(FXCollections.observableList(rows)); statusTextField.setText("Displaying " + rows.size() + " rows across " + cols.size() + " columns"); }