Search in sources :

Example 56 with ObservableList

use of javafx.collections.ObservableList in project org.csstudio.display.builder by kasemir.

the class RulesDialog method createContent.

private SplitPane createContent() {
    final Node rules = createRulesTable();
    final HBox pvs = createPVsTable();
    final HBox exprs = createExpressionsTable();
    // Display PVs of currently selected rule
    rules_table.getSelectionModel().selectedItemProperty().addListener((prop, old, selected) -> {
        selected_rule_item = selected;
        if (selected == null) {
            pvs.setDisable(true);
            exprs.setDisable(true);
            btn_remove_rule.setDisable(true);
            btn_dup_rule.setDisable(true);
            btn_move_rule_up.setDisable(true);
            btn_move_rule_down.setDisable(true);
            btn_show_script.setDisable(true);
            propComboBox.setDisable(true);
            propComboBox.getSelectionModel().select(null);
            valExpBox.setDisable(true);
            pv_items.clear();
            expression_items.clear();
        } else {
            pvs.setDisable(false);
            exprs.setDisable(false);
            final TableViewSelectionModel<RuleItem> model = rules_table.getSelectionModel();
            btn_remove_rule.setDisable(false);
            btn_dup_rule.setDisable(false);
            btn_move_rule_up.setDisable(model.getSelectedIndex() == 0);
            btn_move_rule_down.setDisable(model.getSelectedIndex() == rule_items.size() - 1);
            btn_show_script.setDisable(false);
            propComboBox.setDisable(false);
            propComboBox.getSelectionModel().select(getPropLongString(selected));
            valExpBox.setDisable(false);
            valExpBox.selectedProperty().set(selected.prop_as_expr.get());
            pv_items.setAll(selected.pvs);
            expression_items.setAll(selected.expressions);
            fixupPVs(0);
        }
    });
    // Update PVs of selected rule from PVs table
    final ListChangeListener<PVTableItem> pll = change -> {
        final RuleItem selected = rules_table.getSelectionModel().getSelectedItem();
        if (selected != null)
            selected.pvs = new ArrayList<>(change.getList());
    };
    pv_items.addListener(pll);
    // Update buttons for currently selected PV
    pvs_table.getSelectionModel().selectedItemProperty().addListener((prop, old, selected) -> {
        if (selected == null) {
            btn_rm_pv.setDisable(true);
            btn_move_pv_up.setDisable(true);
            btn_move_pv_down.setDisable(true);
        } else {
            final TableViewSelectionModel<PVTableItem> model = pvs_table.getSelectionModel();
            btn_rm_pv.setDisable(false);
            btn_move_pv_up.setDisable(model.getSelectedIndex() == 0);
            btn_move_pv_down.setDisable(model.getSelectedIndex() == pv_items.size() - 1);
        }
    });
    // Update Expressions of selected rule from Expressions table
    final ListChangeListener<ExprItem<?>> ell = change -> {
        final RuleItem selected = rules_table.getSelectionModel().getSelectedItem();
        if (selected != null)
            selected.expressions = new ArrayList<>(change.getList());
    };
    expression_items.addListener(ell);
    // Update buttons for currently selected expression
    expressions_table.getSelectionModel().selectedItemProperty().addListener((prop, old, selected) -> {
        if (selected == null) {
            btn_rm_exp.setDisable(true);
            btn_move_exp_up.setDisable(true);
            btn_move_exp_down.setDisable(true);
        } else {
            final TableViewSelectionModel<ExprItem<?>> model = expressions_table.getSelectionModel();
            btn_rm_exp.setDisable(false);
            btn_move_exp_up.setDisable(model.getSelectedIndex() == 0);
            btn_move_exp_down.setDisable(model.getSelectedIndex() == expression_items.size() - 1);
        }
    });
    // What is the property id option we are using?
    final Label propLabel = new Label("Property ID:");
    // Show each property with current value
    final ObservableList<String> prop_id_opts = FXCollections.observableArrayList();
    for (PropInfo pi : propinfo_ls) {
        // Property _value_ can be long, ex. points of a polyline
        // Truncate the value that's shown in the combo box
        // to prevent combo from using all screen width.
        String prop_opt = pi.toString();
        if (prop_opt.length() > MAX_PROP_LENGTH)
            prop_opt = prop_opt.substring(0, MAX_PROP_LENGTH) + "...";
        prop_id_opts.add(prop_opt);
    }
    propComboBox = new ComboBox<String>(prop_id_opts);
    propComboBox.setDisable(true);
    propComboBox.getSelectionModel().selectedIndexProperty().addListener((p, o, index) -> {
        // Select property info based on index within combo.
        final int idx = index.intValue();
        if (idx >= 0) {
            final PropInfo prop = propinfo_ls.get(idx);
            if (selected_rule_item.tryUpdatePropID(undo, prop.getPropID()))
                expression_items.setAll(selected_rule_item.expressions);
        }
    });
    propComboBox.setMinHeight(27);
    propComboBox.setMaxWidth(Double.MAX_VALUE);
    HBox.setHgrow(propComboBox, Priority.ALWAYS);
    // TODO: change this to actually manipulate expression objects in the rule
    valExpBox = new CheckBox("Value as Expression");
    valExpBox.setDisable(true);
    valExpBox.selectedProperty().addListener((ov, old_val, new_val) -> {
        if (!selected_rule_item.tryTogglePropAsExpr(undo, new_val))
            logger.log(Level.FINE, "Did not update rule property as expression flag to " + new_val);
        else
            expression_items.setAll(selected_rule_item.expressions);
    });
    final Region spring = new Region();
    HBox.setHgrow(spring, Priority.ALWAYS);
    final HBox props = new HBox(10, propLabel, propComboBox, spring, valExpBox);
    props.setAlignment(Pos.CENTER);
    pvs.setPadding(new Insets(0, 10, 0, 0));
    exprs.setPadding(new Insets(0, 0, 0, 10));
    HBox.setHgrow(pvs, Priority.ALWAYS);
    HBox.setHgrow(exprs, Priority.ALWAYS);
    final Preferences pref = Preferences.userNodeForPackage(RulesDialog.class);
    final double prefRSPDividerPosition = pref.getDouble("rule.content.divider.position", 0.5);
    ruleSplitPane = new SplitPane(pvs, exprs);
    ruleSplitPane.setOrientation(Orientation.HORIZONTAL);
    ruleSplitPane.setDividerPositions(prefRSPDividerPosition);
    ruleSplitPane.setStyle("-fx-background-insets: 0, 0;");
    VBox.setVgrow(ruleSplitPane, Priority.ALWAYS);
    final VBox subitems = new VBox(10, props, ruleSplitPane);
    final VBox rulebox = new VBox(10, rules);
    rulebox.setPadding(new Insets(0, 10, 0, 0));
    subitems.setPadding(new Insets(0, 0, 0, 10));
    VBox.setVgrow(rules, Priority.ALWAYS);
    HBox.setHgrow(subitems, Priority.ALWAYS);
    final double prefWidth = pref.getDouble("content.width", -1);
    final double prefHeight = pref.getDouble("content.height", -1);
    final double prefDividerPosition = pref.getDouble("content.divider.position", 0.3);
    final SplitPane splitPane = new SplitPane(rulebox, subitems);
    splitPane.setOrientation(Orientation.HORIZONTAL);
    splitPane.setDividerPositions(prefDividerPosition);
    if (prefWidth > 0 && prefHeight > 0)
        splitPane.setPrefSize(prefWidth, prefHeight);
    // Select the first rule
    if (!rules_table.getItems().isEmpty()) {
        Platform.runLater(() -> {
            rules_table.getSelectionModel().select(0);
            rules_table.requestFocus();
        });
    } else
        Platform.runLater(() -> btn_add_rule.requestFocus());
    return splitPane;
}
Also used : Button(javafx.scene.control.Button) Pos(javafx.geometry.Pos) UndoableActionManager(org.csstudio.display.builder.util.undo.UndoableActionManager) ScriptPV(org.csstudio.display.builder.model.properties.ScriptPV) LineNumberTableCellFactory(org.csstudio.javafx.LineNumberTableCellFactory) VBox(javafx.scene.layout.VBox) AutoCompletedTableCell(org.csstudio.display.builder.representation.javafx.PVTableItem.AutoCompletedTableCell) RuleInfo(org.csstudio.display.builder.model.rules.RuleInfo) TableHelper(org.csstudio.javafx.TableHelper) ListChangeListener(javafx.collections.ListChangeListener) ComboBox(javafx.scene.control.ComboBox) WidgetProperty(org.csstudio.display.builder.model.WidgetProperty) TableView(javafx.scene.control.TableView) ModelThreadPool(org.csstudio.display.builder.model.util.ModelThreadPool) Pane(javafx.scene.layout.Pane) Orientation(javafx.geometry.Orientation) HBox(javafx.scene.layout.HBox) PVTableItem(org.csstudio.display.builder.representation.javafx.PVTableItem) SplitPane(javafx.scene.control.SplitPane) TextField(javafx.scene.control.TextField) Language(org.csstudio.javafx.SyntaxHighlightedMultiLineInputDialog.Language) PropertyValueFactory(javafx.scene.control.cell.PropertyValueFactory) Collectors(java.util.stream.Collectors) CommonWidgetProperties(org.csstudio.display.builder.model.properties.CommonWidgetProperties) Platform(javafx.application.Platform) Priority(javafx.scene.layout.Priority) List(java.util.List) BooleanProperty(javafx.beans.property.BooleanProperty) Region(javafx.scene.layout.Region) CheckBoxTableCell(javafx.scene.control.cell.CheckBoxTableCell) AutocompleteMenu(org.csstudio.display.builder.representation.javafx.AutocompleteMenu) JFXUtil(org.csstudio.display.builder.representation.javafx.JFXUtil) ObservableList(javafx.collections.ObservableList) DefaultStringConverter(javafx.util.converter.DefaultStringConverter) ExprInfoString(org.csstudio.display.builder.model.rules.RuleInfo.ExprInfoString) StringProperty(javafx.beans.property.StringProperty) ExpressionInfo(org.csstudio.display.builder.model.rules.RuleInfo.ExpressionInfo) TableViewSelectionModel(javafx.scene.control.TableView.TableViewSelectionModel) SyntaxHighlightedMultiLineInputDialog(org.csstudio.javafx.SyntaxHighlightedMultiLineInputDialog) ExprInfoValue(org.csstudio.display.builder.model.rules.RuleInfo.ExprInfoValue) Plugin.logger(org.csstudio.display.builder.editor.Plugin.logger) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) ButtonType(javafx.scene.control.ButtonType) JFXBaseRepresentation(org.csstudio.display.builder.representation.javafx.widgets.JFXBaseRepresentation) FXCollections(javafx.collections.FXCollections) BackingStoreException(java.util.prefs.BackingStoreException) TextFieldTableCell(javafx.scene.control.cell.TextFieldTableCell) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) TableColumn(javafx.scene.control.TableColumn) RulesWidgetProperty(org.csstudio.display.builder.model.properties.RulesWidgetProperty) Messages(org.csstudio.display.builder.representation.javafx.Messages) TableCell(javafx.scene.control.TableCell) Insets(javafx.geometry.Insets) Tooltip(javafx.scene.control.Tooltip) Dialog(javafx.scene.control.Dialog) Label(javafx.scene.control.Label) Node(javafx.scene.Node) CheckBox(javafx.scene.control.CheckBox) Preferences(java.util.prefs.Preferences) TimeUnit(java.util.concurrent.TimeUnit) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) ScriptsDialog(org.csstudio.display.builder.representation.javafx.ScriptsDialog) DialogHelper(org.csstudio.javafx.DialogHelper) Widget(org.csstudio.display.builder.model.Widget) ChangeListener(javafx.beans.value.ChangeListener) PropInfo(org.csstudio.display.builder.model.rules.RuleInfo.PropInfo) HBox(javafx.scene.layout.HBox) Insets(javafx.geometry.Insets) Node(javafx.scene.Node) Label(javafx.scene.control.Label) PropInfo(org.csstudio.display.builder.model.rules.RuleInfo.PropInfo) ExprInfoString(org.csstudio.display.builder.model.rules.RuleInfo.ExprInfoString) SplitPane(javafx.scene.control.SplitPane) PVTableItem(org.csstudio.display.builder.representation.javafx.PVTableItem) Preferences(java.util.prefs.Preferences) CheckBox(javafx.scene.control.CheckBox) Region(javafx.scene.layout.Region) VBox(javafx.scene.layout.VBox)

Example 57 with ObservableList

use of javafx.collections.ObservableList in project bisq-desktop by bisq-network.

the class SpreadViewModel method update.

private void update(ObservableList<OfferBookListItem> offerBookListItems) {
    Map<String, List<Offer>> offersByCurrencyMap = new HashMap<>();
    for (OfferBookListItem offerBookListItem : offerBookListItems) {
        Offer offer = offerBookListItem.getOffer();
        String currencyCode = offer.getCurrencyCode();
        if (!offersByCurrencyMap.containsKey(currencyCode))
            offersByCurrencyMap.put(currencyCode, new ArrayList<>());
        offersByCurrencyMap.get(currencyCode).add(offer);
    }
    spreadItems.clear();
    Coin totalAmount = null;
    for (String currencyCode : offersByCurrencyMap.keySet()) {
        List<Offer> offers = offersByCurrencyMap.get(currencyCode);
        final boolean isFiatCurrency = CurrencyUtil.isFiatCurrency(currencyCode);
        List<Offer> buyOffers = offers.stream().filter(e -> e.getDirection().equals(OfferPayload.Direction.BUY)).sorted((o1, o2) -> {
            long a = o1.getPrice() != null ? o1.getPrice().getValue() : 0;
            long b = o2.getPrice() != null ? o2.getPrice().getValue() : 0;
            if (a != b) {
                if (isFiatCurrency) {
                    return a < b ? 1 : -1;
                } else {
                    return a < b ? -1 : 1;
                }
            }
            return 0;
        }).collect(Collectors.toList());
        List<Offer> sellOffers = offers.stream().filter(e -> e.getDirection().equals(OfferPayload.Direction.SELL)).sorted((o1, o2) -> {
            long a = o1.getPrice() != null ? o1.getPrice().getValue() : 0;
            long b = o2.getPrice() != null ? o2.getPrice().getValue() : 0;
            if (a != b) {
                if (isFiatCurrency) {
                    return a > b ? 1 : -1;
                } else {
                    return a > b ? -1 : 1;
                }
            }
            return 0;
        }).collect(Collectors.toList());
        Price spread = null;
        String percentage = "";
        Price bestSellOfferPrice = sellOffers.isEmpty() ? null : sellOffers.get(0).getPrice();
        Price bestBuyOfferPrice = buyOffers.isEmpty() ? null : buyOffers.get(0).getPrice();
        if (bestBuyOfferPrice != null && bestSellOfferPrice != null) {
            MarketPrice marketPrice = priceFeedService.getMarketPrice(currencyCode);
            // happens again
            try {
                if (isFiatCurrency)
                    spread = bestSellOfferPrice.subtract(bestBuyOfferPrice);
                else
                    spread = bestBuyOfferPrice.subtract(bestSellOfferPrice);
                if (spread != null && marketPrice != null && marketPrice.isPriceAvailable()) {
                    double marketPriceAsDouble = marketPrice.getPrice();
                    final double precision = isFiatCurrency ? Math.pow(10, Fiat.SMALLEST_UNIT_EXPONENT) : Math.pow(10, Altcoin.SMALLEST_UNIT_EXPONENT);
                    BigDecimal marketPriceAsBigDecimal = BigDecimal.valueOf(marketPriceAsDouble).multiply(BigDecimal.valueOf(precision));
                    // We multiply with 10000 because we use precision of 2 at % (100.00%)
                    double result = BigDecimal.valueOf(spread.getValue()).multiply(BigDecimal.valueOf(10000)).divide(marketPriceAsBigDecimal, RoundingMode.HALF_UP).doubleValue() / 10000;
                    percentage = formatter.formatPercentagePrice(result);
                }
            } catch (Throwable t) {
                try {
                    // Don't translate msg. It is just for rare error cases and can be removed probably later if
                    // that error never gets reported again.
                    String msg = "An error occurred at the spread calculation.\n" + "Error msg: " + t.toString() + "\n" + "Details of offer data: \n" + "bestSellOfferPrice: " + bestSellOfferPrice.getValue() + "\n" + "bestBuyOfferPrice: " + bestBuyOfferPrice.getValue() + "\n" + "sellOffer getCurrencyCode: " + sellOffers.get(0).getCurrencyCode() + "\n" + "buyOffer getCurrencyCode: " + buyOffers.get(0).getCurrencyCode() + "\n\n" + "Please copy and paste this data and send it to the developers so they can investigate the issue.";
                    new Popup<>().error(msg).show();
                    log.error(t.toString());
                    t.printStackTrace();
                } catch (Throwable t2) {
                    log.error(t2.toString());
                    t2.printStackTrace();
                }
            }
        }
        totalAmount = Coin.valueOf(offers.stream().mapToLong(offer -> offer.getAmount().getValue()).sum());
        spreadItems.add(new SpreadItem(currencyCode, buyOffers.size(), sellOffers.size(), offers.size(), spread, percentage, totalAmount));
    }
    maxPlacesForAmount.set(formatAmount(totalAmount, false).length());
}
Also used : Altcoin(bisq.core.monetary.Altcoin) GUIUtil(bisq.desktop.util.GUIUtil) Coin(org.bitcoinj.core.Coin) Inject(com.google.inject.Inject) FXCollections(javafx.collections.FXCollections) HashMap(java.util.HashMap) IntegerProperty(javafx.beans.property.IntegerProperty) BSFormatter(bisq.desktop.util.BSFormatter) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) OfferPayload(bisq.core.offer.OfferPayload) ListChangeListener(javafx.collections.ListChangeListener) SimpleIntegerProperty(javafx.beans.property.SimpleIntegerProperty) Map(java.util.Map) CurrencyUtil(bisq.core.locale.CurrencyUtil) RoundingMode(java.math.RoundingMode) Popup(bisq.desktop.main.overlays.popups.Popup) Offer(bisq.core.offer.Offer) OfferBook(bisq.desktop.main.offer.offerbook.OfferBook) Fiat(org.bitcoinj.utils.Fiat) OfferBookListItem(bisq.desktop.main.offer.offerbook.OfferBookListItem) Collectors(java.util.stream.Collectors) ActivatableViewModel(bisq.desktop.common.model.ActivatableViewModel) List(java.util.List) PriceFeedService(bisq.core.provider.price.PriceFeedService) Price(bisq.core.monetary.Price) ObservableList(javafx.collections.ObservableList) MarketPrice(bisq.core.provider.price.MarketPrice) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) Coin(org.bitcoinj.core.Coin) OfferBookListItem(bisq.desktop.main.offer.offerbook.OfferBookListItem) MarketPrice(bisq.core.provider.price.MarketPrice) Offer(bisq.core.offer.Offer) Price(bisq.core.monetary.Price) MarketPrice(bisq.core.provider.price.MarketPrice) ArrayList(java.util.ArrayList) List(java.util.List) ObservableList(javafx.collections.ObservableList)

Example 58 with ObservableList

use of javafx.collections.ObservableList in project DeskChan by DeskChan.

the class OptionsDialog method initCommandsTab1.

/**
 * Creating 'Commands' tab. *
 */
private static void initCommandsTab1() {
    TableView<CommandItem> commandsTable = new TableView<>();
    BorderPane commandTab = new BorderPane();
    commandTab.setCenter(commandsTable);
    commandsTable.setEditable(true);
    commandsTable.setPlaceholder(new Label(Main.getString("commands.empty")));
    // commandsTable.prefHeightProperty().bind(commandTab.heightProperty());
    // Events column
    TableColumn eventCol = new TableColumn(Main.getString("events"));
    eventCol.setCellValueFactory(new PropertyValueFactory<CommandItem, String>("event"));
    List events = CommandsProxy.getEventsList();
    Collections.sort(events);
    eventCol.setCellFactory(ComboBoxTableCell.forTableColumn(new DefaultStringConverter(), FXCollections.observableArrayList(events)));
    eventCol.setOnEditCommit(ev -> {
        TableColumn.CellEditEvent<CommandItem, String> event = (TableColumn.CellEditEvent<CommandItem, String>) ev;
        CommandItem item = event.getTableView().getItems().get(event.getTablePosition().getRow());
        item.setEvent(event.getNewValue());
    });
    eventCol.setMinWidth(120);
    // Commands column
    TableColumn commandCol = new TableColumn(Main.getString("commands"));
    commandCol.setCellValueFactory(new PropertyValueFactory<CommandItem, String>("command"));
    List commands = CommandsProxy.getCommandsList();
    Collections.sort(commands);
    commandCol.setCellFactory(ComboBoxTableCell.forTableColumn(new DefaultStringConverter(), FXCollections.observableArrayList(commands)));
    commandCol.setOnEditCommit(ev -> {
        TableColumn.CellEditEvent<CommandItem, String> event = (TableColumn.CellEditEvent<CommandItem, String>) ev;
        CommandItem item = event.getTableView().getItems().get(event.getTablePosition().getRow());
        item.setCommand(event.getNewValue());
    });
    commandCol.setMinWidth(120);
    // Rules column
    TableColumn ruleCol = new TableColumn(Main.getString("rules"));
    ruleCol.setCellValueFactory(new PropertyValueFactory<CommandItem, String>("rule"));
    ruleCol.setCellFactory(TooltippedTableCell.<CommandItem>forTableColumn());
    ruleCol.setOnEditCommit(ev -> {
        TableColumn.CellEditEvent<CommandItem, String> event = (TableColumn.CellEditEvent<CommandItem, String>) ev;
        CommandItem item = event.getTableView().getItems().get(event.getTablePosition().getRow());
        item.setRule(event.getNewValue());
    });
    ruleCol.setMinWidth(120);
    // Parameters column
    TableColumn msgCol = new TableColumn(Main.getString("parameters"));
    msgCol.setCellValueFactory(new PropertyValueFactory<CommandItem, String>("msgData"));
    msgCol.setCellFactory(TooltippedTableCell.<CommandItem>forTableColumn());
    msgCol.setOnEditCommit(ev -> {
        TableColumn.CellEditEvent<CommandItem, String> event = (TableColumn.CellEditEvent<CommandItem, String>) ev;
        CommandItem item = event.getTableView().getItems().get(event.getTablePosition().getRow());
        item.setMsgData(event.getNewValue());
    });
    msgCol.setMinWidth(120);
    final TreeItem<CommandItem> root = new TreeItem<>();
    // Filling list of commands
    ObservableList<CommandItem> list = FXCollections.observableArrayList();
    for (Map<String, Object> entry : CommandsProxy.getLinksList()) {
        list.add(new CommandItem(entry));
    }
    commandsTable.setItems(list);
    // Setting columns
    commandsTable.getColumns().addAll(eventCol, ruleCol, commandCol, msgCol);
    // 'Delete' button
    Button deleteButton = new Button(Main.getString("delete"));
    deleteButton.setOnAction(event -> {
        if (commandsTable.getSelectionModel().getSelectedIndex() >= 0)
            commandsTable.getItems().remove(commandsTable.getSelectionModel().getSelectedIndex());
    });
    // 'Reset' button
    Button resetButton = new Button(Main.getString("reset"));
    resetButton.setOnAction(event -> {
        CommandsProxy.reset();
        ObservableList<CommandItem> l = FXCollections.observableArrayList();
        for (Map<String, Object> entry : CommandsProxy.getLinksList()) {
            l.add(new CommandItem(entry));
        }
        commandsTable.setItems(l);
    });
    // 'Save' button
    Button saveButton = new Button(Main.getString("save"));
    saveButton.setOnAction(event -> {
        ArrayList<Map<String, Object>> push = new ArrayList<>();
        for (CommandItem item : commandsTable.getItems()) {
            push.add(item.toMap());
        }
        CommandsProxy.setLinks(push);
        CommandsProxy.save();
    });
    // 'Load' button
    Button loadButton = new Button(Main.getString("load"));
    loadButton.setOnAction(event -> {
        CommandsProxy.load();
        ObservableList<CommandItem> l = FXCollections.observableArrayList();
        for (Map<String, Object> entry : CommandsProxy.getLinksList()) {
            l.add(new CommandItem(entry));
        }
        commandsTable.setItems(l);
    });
    // 'Add' button
    Button addButton = new Button(Main.getString("add"));
    addButton.setOnAction(event -> {
        CommandItem item = new CommandItem(CommandsProxy.getEventsList().get(0), CommandsProxy.getCommandsList().get(0), "", "");
        commandsTable.getItems().add(item);
    });
    // Adding buttons to form
    HBox buttons = new HBox(addButton, deleteButton, loadButton, saveButton, resetButton);
    commandTab.setBottom(buttons);
    buttons.setId("controls-bottom-buttons");
    new ControlsPanel(Main.getPluginProxy().getId(), Main.getString("commands"), "commands", ControlsPanel.PanelType.TAB, commandTab).set();
}
Also used : DefaultStringConverter(javafx.util.converter.DefaultStringConverter) ObservableList(javafx.collections.ObservableList) JSONObject(org.json.JSONObject)

Example 59 with ObservableList

use of javafx.collections.ObservableList in project drbookings by DrBookings.

the class EarningsPerDayChartViewController method doChart.

protected void doChart(final List<? extends BookingEntry> allElements) {
    categories.clear();
    mapSeries.clear();
    chart.getData().clear();
    for (int i = 0; i < allElements.size(); i++) {
        final BookingEntry db = allElements.get(i);
        bin.add(db);
        if (bin.stream().map(e -> e.getDate()).collect(Collectors.toSet()).size() >= getBinSize()) {
            flushBin();
        }
    }
    flushBin();
    final ObservableList<String> c = FXCollections.observableArrayList(categories);
    Collections.sort(c);
    xAxis.setCategories(c);
    xAxis.setAutoRanging(true);
}
Also used : BookingSelectionManager(com.github.drbookings.ui.selection.BookingSelectionManager) Initializable(javafx.fxml.Initializable) java.util(java.util) URL(java.net.URL) Series(javafx.scene.chart.XYChart.Series) LoggerFactory(org.slf4j.LoggerFactory) FXCollections(javafx.collections.FXCollections) BinType(com.github.drbookings.model.BinType) Callable(java.util.concurrent.Callable) XYChart(javafx.scene.chart.XYChart) Bindings(javafx.beans.binding.Bindings) Slider(javafx.scene.control.Slider) ListChangeListener(javafx.collections.ListChangeListener) ComboBox(javafx.scene.control.ComboBox) Label(javafx.scene.control.Label) Logger(org.slf4j.Logger) CategoryAxis(javafx.scene.chart.CategoryAxis) Collectors(java.util.stream.Collectors) SettingsManager(com.github.drbookings.model.settings.SettingsManager) FXML(javafx.fxml.FXML) LocalDate(java.time.LocalDate) Entry(java.util.Map.Entry) ObservableValue(javafx.beans.value.ObservableValue) ObservableList(javafx.collections.ObservableList) NumberAxis(javafx.scene.chart.NumberAxis) BookingEntry(com.github.drbookings.ui.BookingEntry) ChangeListener(javafx.beans.value.ChangeListener) ExceptionUnknownType(net.sf.kerner.utils.exception.ExceptionUnknownType) BookingEntry(com.github.drbookings.ui.BookingEntry)

Example 60 with ObservableList

use of javafx.collections.ObservableList in project drbookings by DrBookings.

the class MoneyMonitor method calculateDateToEarnings.

private void calculateDateToEarnings(final ObservableList<? extends RoomBean> list) {
    final List<BookingEntry> selectedBookings = list.stream().flatMap(r -> r.getFilteredBookingEntries().stream()).collect(Collectors.toList());
    dayToNetEarnings.clear();
    for (final BookingEntry rb : selectedBookings) {
        fillDayMap(rb);
        fillMonthYearMap(rb);
    }
    setTotalNetEarnings(dayToNetEarnings.values().stream().mapToDouble(d -> d.doubleValue()).sum());
}
Also used : MapProperty(javafx.beans.property.MapProperty) SimpleMapProperty(javafx.beans.property.SimpleMapProperty) Logger(org.slf4j.Logger) RoomBeanSelectionManager(com.github.drbookings.ui.selection.RoomBeanSelectionManager) LoggerFactory(org.slf4j.LoggerFactory) FXCollections(javafx.collections.FXCollections) DoubleProperty(javafx.beans.property.DoubleProperty) Collectors(java.util.stream.Collectors) RoomBean(com.github.drbookings.ui.beans.RoomBean) List(java.util.List) TreeMap(java.util.TreeMap) ListChangeListener(javafx.collections.ListChangeListener) LocalDate(java.time.LocalDate) Map(java.util.Map) YearMonth(java.time.YearMonth) SimpleDoubleProperty(javafx.beans.property.SimpleDoubleProperty) ObservableList(javafx.collections.ObservableList) BookingEntry(com.github.drbookings.ui.BookingEntry) BookingEntry(com.github.drbookings.ui.BookingEntry)

Aggregations

ObservableList (javafx.collections.ObservableList)77 List (java.util.List)46 ArrayList (java.util.ArrayList)31 Collectors (java.util.stream.Collectors)29 Map (java.util.Map)28 FXCollections (javafx.collections.FXCollections)28 HashMap (java.util.HashMap)21 Node (javafx.scene.Node)20 TableColumn (javafx.scene.control.TableColumn)20 Label (javafx.scene.control.Label)18 Optional (java.util.Optional)17 ActionEvent (javafx.event.ActionEvent)16 FXML (javafx.fxml.FXML)16 TableView (javafx.scene.control.TableView)16 MouseEvent (javafx.scene.input.MouseEvent)16 Logger (org.slf4j.Logger)16 LoggerFactory (org.slf4j.LoggerFactory)16 Button (javafx.scene.control.Button)15 BorderPane (javafx.scene.layout.BorderPane)15 File (java.io.File)14