Example usage for javafx.collections ObservableList isEmpty

List of usage examples for javafx.collections ObservableList isEmpty

Introduction

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

Prototype

boolean isEmpty();

Source Link

Document

Returns true if this list contains no elements.

Usage

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

private void updateProjectTabs(ProjectSettings projectSettings) {

    if (selectedIndexListener != null) {
        projectTabPane.getSelectionModel().selectedIndexProperty().removeListener(selectedIndexListener);
    }/*from ww  w .jav  a  2s .c  om*/

    menuTabBindingSourceCode.setSettings(projectSettings, true);
    menuTabBindingHelp.setSettings(projectSettings, false);

    if (projectSettings != null) {
        selectedIndexListener = (obs, oldValue, newValue) -> projectSettings
                .setProperty(PROP_SELECTED_TAB_INDEX, newValue);
        projectTabPane.getSelectionModel().selectedIndexProperty().addListener(selectedIndexListener);

        selectedItemListener = (obs, oldTab, newTab) -> {
            butSaveFile.disableProperty().unbind();
            mnuSaveFile.disableProperty().unbind();
            butSaveFile.setDisable(true);
            mnuSaveFile.setDisable(true);
            if (newTab != null) {
                CodeTabData tabData = getData(newTab);
                Platform.runLater(() -> {
                    BooleanBinding scriptChangedBinding = Bindings.createBooleanBinding(
                            () -> !tabData.isDirty(), tabData.getTextProperty(),
                            tabData.getInitialTextProperty());
                    butSaveFile.disableProperty().bind(scriptChangedBinding);
                    mnuSaveFile.disableProperty().bind(scriptChangedBinding);

                    StringBinding tabTextBinding = Bindings.createStringBinding(() -> {
                        String text = tabData.getTabText();
                        if (tabData.isDirty()) {
                            text = "*" + text;
                        }
                        return text;
                    }, tabData.getTextProperty(), tabData.getInitialTextProperty());
                    newTab.textProperty().bind(tabTextBinding);
                });
            }

            Platform.runLater(() -> {
                menuTabBindingSourceCode.setSettings(projectSettings, true);
                menuTabBindingHelp.setSettings(projectSettings, false);

                butSaveAll.disableProperty().unbind();
                mnuSaveAll.disableProperty().unbind();
                butSaveAll.setDisable(true);
                mnuSaveAll.setDisable(true);

                List<BooleanBinding> saveBindings = new ArrayList<>();
                projectTabPane.getTabs().forEach(tab -> {
                    CodeTabData tabData = getData(tab);
                    saveBindings.add(Bindings.createBooleanBinding(() -> !tabData.isDirty(),
                            tabData.getTextProperty(), tabData.getInitialTextProperty()));
                });
                if (!saveBindings.isEmpty()) {
                    BooleanBinding binding = saveBindings.get(0);
                    for (int i = 1; i < saveBindings.size(); i++) {
                        binding = Bindings.and(binding, saveBindings.get(i));
                    }
                    mnuSaveAll.disableProperty().bind(binding);
                    butSaveAll.disableProperty().bind(binding);
                }
            });
        };
        projectTabPane.getSelectionModel().selectedItemProperty().addListener(selectedItemListener);
    }

    int selectedTabIndex = (projectSettings == null) ? 0
            : projectSettings.getProperty(PROP_SELECTED_TAB_INDEX, 0, false);

    ObservableList<Tab> tabs = projectTabPane.getTabs();
    tabs.clear();

    Tab selectedTab = null;
    List<String> openFiles = getOpenFiles(projectSettings);
    for (int i = 0; i < openFiles.size(); i++) {
        String filePath = openFiles.get(i);
        Tab addedTab = null;
        if (filePath.equals(FILE_ALIAS_SOURCE_CODE)) {
            addedTab = tabSourceCode;
            String projectPath = projectPathProperty.get();
            String tabText = (projectPath == null) ? "Code" : new File(projectPath).getName();
            tabSourceCode.setUserData(new CodeTabData(tabText));
        } else if (filePath.equals(FILE_ALIAS_HELP)) {
            addedTab = tabHelp;
        } else {
            try {
                File file = new File(filePath);
                addedTab = CodeAreaTab.fromFile(file);
                final Tab tab = addedTab;
                tab.setOnCloseRequest(ev -> {
                    if (!tryClose(tab))
                        ev.consume();
                });
            } catch (Exception e) {
                addedTab = null;
            }
        }
        if (addedTab != null) {
            tabs.add(addedTab);
            getData(addedTab).setFilePath(filePath);
            if (i == selectedTabIndex) {
                selectedTab = addedTab;
            }
        }
    }
    if (!tabs.isEmpty()) {
        if (selectedTab == null) {
            selectedTab = tabs.get(0);
        }
        projectTabPane.getSelectionModel().select(null);
        projectTabPane.getSelectionModel().select(selectedTab);
    }
}

From source file:org.eclipse.jubula.rc.javafx.tester.adapter.ListViewAdapter.java

/** {@inheritDoc} **/
public String getText() {
    String result = EventThreadQueuerJavaFXImpl.invokeAndWait("getText", //$NON-NLS-1$
            new Callable<String>() {

                /** {@inheritDoc} **/
                public String call() throws Exception {
                    ObservableList sItems = getRealComponent().getSelectionModel().getSelectedItems();
                    if (!sItems.isEmpty()) {
                        return String.valueOf(sItems.get(0));
                    }/*from   w ww .ja  va2s  .  com*/
                    throw new StepExecutionException("No selection found", //$NON-NLS-1$
                            EventFactory.createActionError(TestErrorEvent.NO_SELECTION));
                }
            });
    return result;
}

From source file:org.pdfsam.ui.selection.multiple.SelectionTable.java

public SelectionTable(String ownerModule, SelectionTableColumn<?>... columns) {
    this.ownerModule = defaultString(ownerModule);
    setEditable(true);//from w  w w .  j a  v  a2  s. com
    getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
    Arrays.stream(columns).forEach(c -> getColumns().add(c.getTableColumn()));
    setColumnResizePolicy(CONSTRAINED_RESIZE_POLICY);
    setTableMenuButtonVisible(true);
    getSelectionModel().getSelectedIndices().addListener((Change<? extends Integer> c) -> {

        ObservableList<? extends Integer> selected = c.getList();
        if (selected.isEmpty()) {
            eventStudio().broadcast(clearSelectionEvent(), ownerModule);
            LOG.trace("Selection cleared for {}", ownerModule);
        } else {
            SelectionChangedEvent newSelectionEvent = select(selected).ofTotalRows(getItems().size());
            eventStudio().broadcast(newSelectionEvent, ownerModule);
            LOG.trace("{} for {}", newSelectionEvent, ownerModule);
        }

    });
    placeHolder.getStyleClass().add("drag-drop-placeholder");
    placeHolder.setDisable(true);
    setPlaceholder(placeHolder);
    setOnDragOver(e -> dragConsume(e, this.onDragOverConsumer()));
    setOnDragEntered(e -> dragConsume(e, this.onDragEnteredConsumer()));
    setOnDragExited(this::onDragExited);
    setOnDragDropped(e -> dragConsume(e, this.onDragDropped()));
    initContextMenu();
    eventStudio().addAnnotatedListeners(this);
}

From source file:org.sleuthkit.autopsy.timeline.ui.AbstractVisualization.java

/** iterate through the list of tick-marks building a two level structure of
 * replacement tick marl labels. (Visually) upper level has most
 * detailed/highest frequency part of date/time. Second level has rest of
 * date/time grouped by unchanging part.
 * eg://from   w  w  w.j a va2s . co m
 *
 *
 * october-30_october-31_september-01_september-02_september-03
 *
 * becomes
 *
 * _________30_________31___________01___________02___________03
 *
 * _________october___________|_____________september___________
 *
 *
 * NOTE: This method should only be invoked on the JFX thread
 */
public synchronized void layoutDateLabels() {

    //clear old labels
    branchPane.getChildren().clear();
    leafPane.getChildren().clear();
    //since the tickmarks aren't necessarily in value/position order,
    //make a clone of the list sorted by position along axis
    ObservableList<Axis.TickMark<X>> tickMarks = FXCollections.observableArrayList(getXAxis().getTickMarks());
    tickMarks.sort(
            (Axis.TickMark<X> t, Axis.TickMark<X> t1) -> Double.compare(t.getPosition(), t1.getPosition()));

    if (tickMarks.isEmpty() == false) {
        //get the spacing between ticks in the underlying axis
        double spacing = getTickSpacing();

        //initialize values from first tick
        TwoPartDateTime dateTime = new TwoPartDateTime(getTickMarkLabel(tickMarks.get(0).getValue()));
        String lastSeenBranchLabel = dateTime.branch;
        //cumulative width of the current branch label

        //x-positions (pixels) of the current branch and leaf labels
        double leafLabelX = 0;

        if (dateTime.branch.equals("")) {
            //if there is only one part to the date (ie only year), just add a label for each tick
            for (Axis.TickMark<X> t : tickMarks) {
                assignLeafLabel(new TwoPartDateTime(getTickMarkLabel(t.getValue())).leaf, spacing, leafLabelX,
                        isTickBold(t.getValue()));

                leafLabelX += spacing; //increment x
            }
        } else {
            //there are two parts so ...
            //initialize additional state 
            double branchLabelX = 0;
            double branchLabelWidth = 0;

            for (Axis.TickMark<X> t : tickMarks) { //for each tick

                //split the label into a TwoPartDateTime
                dateTime = new TwoPartDateTime(getTickMarkLabel(t.getValue()));

                //if we are still on the same branch
                if (lastSeenBranchLabel.equals(dateTime.branch)) {
                    //increment branch width
                    branchLabelWidth += spacing;
                } else {// we are on to a new branch, so ...
                    assignBranchLabel(lastSeenBranchLabel, branchLabelWidth, branchLabelX);
                    //and then update label, x-pos, and width
                    lastSeenBranchLabel = dateTime.branch;
                    branchLabelX += branchLabelWidth;
                    branchLabelWidth = spacing;
                }
                //add the label for the leaf (highest frequency part)
                assignLeafLabel(dateTime.leaf, spacing, leafLabelX, isTickBold(t.getValue()));

                //increment leaf position
                leafLabelX += spacing;
            }
            //we have reached end so add branch label for current branch
            assignBranchLabel(lastSeenBranchLabel, branchLabelWidth, branchLabelX);
        }
    }
    //request layout since we have modified scene graph structure
    requestParentLayout();
}

From source file:org.sleuthkit.autopsy.timeline.ui.AbstractVisualizationPane.java

/**
 * iterate through the list of tick-marks building a two level structure of
 * replacement tick marl labels. (Visually) upper level has most
 * detailed/highest frequency part of date/time. Second level has rest of
 * date/time grouped by unchanging part. eg:
 *
 *
 * october-30_october-31_september-01_september-02_september-03
 *
 * becomes//  www .  j a  v a 2 s .  c om
 *
 * _________30_________31___________01___________02___________03
 *
 * _________october___________|_____________september___________
 *
 *
 * NOTE: This method should only be invoked on the JFX thread
 */
public synchronized void layoutDateLabels() {

    //clear old labels
    branchPane.getChildren().clear();
    leafPane.getChildren().clear();
    //since the tickmarks aren't necessarily in value/position order,
    //make a clone of the list sorted by position along axis
    ObservableList<Axis.TickMark<X>> tickMarks = FXCollections.observableArrayList(getXAxis().getTickMarks());
    tickMarks.sort(
            (Axis.TickMark<X> t, Axis.TickMark<X> t1) -> Double.compare(t.getPosition(), t1.getPosition()));

    if (tickMarks.isEmpty() == false) {
        //get the spacing between ticks in the underlying axis
        double spacing = getTickSpacing();

        //initialize values from first tick
        TwoPartDateTime dateTime = new TwoPartDateTime(getTickMarkLabel(tickMarks.get(0).getValue()));
        String lastSeenBranchLabel = dateTime.branch;
        //cumulative width of the current branch label

        //x-positions (pixels) of the current branch and leaf labels
        double leafLabelX = 0;

        if (dateTime.branch.isEmpty()) {
            //if there is only one part to the date (ie only year), just add a label for each tick
            for (Axis.TickMark<X> t : tickMarks) {
                assignLeafLabel(new TwoPartDateTime(getTickMarkLabel(t.getValue())).leaf, spacing, leafLabelX,
                        isTickBold(t.getValue()));

                leafLabelX += spacing; //increment x
            }
        } else {
            //there are two parts so ...
            //initialize additional state
            double branchLabelX = 0;
            double branchLabelWidth = 0;

            for (Axis.TickMark<X> t : tickMarks) { //for each tick

                //split the label into a TwoPartDateTime
                dateTime = new TwoPartDateTime(getTickMarkLabel(t.getValue()));

                //if we are still on the same branch
                if (lastSeenBranchLabel.equals(dateTime.branch)) {
                    //increment branch width
                    branchLabelWidth += spacing;
                } else {// we are on to a new branch, so ...
                    assignBranchLabel(lastSeenBranchLabel, branchLabelWidth, branchLabelX);
                    //and then update label, x-pos, and width
                    lastSeenBranchLabel = dateTime.branch;
                    branchLabelX += branchLabelWidth;
                    branchLabelWidth = spacing;
                }
                //add the label for the leaf (highest frequency part)
                assignLeafLabel(dateTime.leaf, spacing, leafLabelX, isTickBold(t.getValue()));

                //increment leaf position
                leafLabelX += spacing;
            }
            //we have reached end so add branch label for current branch
            assignBranchLabel(lastSeenBranchLabel, branchLabelWidth, branchLabelX);
        }
    }
    //request layout since we have modified scene graph structure
    requestParentLayout();
}