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:com.ucu.seguridad.views.AbstractFxmlView.java

/**
 * Scene Builder creates for each FXML document a root container. This method omits the root container (e.g.
 * {@link AnchorPane}) and gives you the access to its first child.
 *
 * @return the first child of the {@link AnchorPane}
 *///w w w.  j  av  a2 s.  c  om
public Node getViewWithoutRootContainer() {

    ObservableList<Node> children = getView().getChildrenUnmodifiable();
    if (children.isEmpty()) {
        return null;
    }

    return children.listIterator().next();
}

From source file:com.github.douglasjunior.simpleCSVEditor.FXMLController.java

@FXML
private void onAbrirActionEvent(ActionEvent event) {
    File csvFile = null;/* w w  w  .ja v  a2  s. c  o  m*/
    try {
        if (!saved) {
            Alert a = new Alert(Alert.AlertType.CONFIRMATION, "", ButtonType.YES, ButtonType.NO);
            a.setHeaderText("Deseja descartar as alteraes??");
            a.initOwner(root.getScene().getWindow());
            Optional<ButtonType> result = a.showAndWait();
            if (result.get() != ButtonType.YES) {
                return;
            }
        }
        csvFile = openFileChooser();
        if (csvFile == null || !csvFile.exists()) {
            throw new FileNotFoundException("O arquivo selecionado no existe!");
        }
        ObservableList<CSVRow> rows = readFile(csvFile);
        if (rows == null || rows.isEmpty()) {
            throw new FilerException("O arquivo selecionado est vazio!");
        }
        updateTable(rows);
        this.file = csvFile;
        setSaved();
    } catch (Exception ex) {
        ex.printStackTrace();
        Alert d = new Alert(Alert.AlertType.ERROR);
        d.setHeaderText(
                "Ooops, no foi possvel abrir o arquivo " + (csvFile != null ? csvFile.getName() : "."));
        d.setContentText(ex.getMessage());
        d.setTitle("Erro");
        d.initOwner(root.getScene().getWindow());
        d.show();
    }
}

From source file:com.ggvaidya.scinames.tabulardata.TabularDataViewController.java

/**
 * Initializes the controller class.//from  www .j  a va  2  s  . c o  m
 */
public void initialize() {
    tableView.itemsProperty().addListener((ObservableValue observable, Object oldValue, Object newValue) -> {
        ObservableList<Object> list;

        if (ObservableList.class.isAssignableFrom(newValue.getClass())) {
            list = (ObservableList<Object>) newValue;

            if (list.isEmpty()) {
                statusTextField.setText("Table contains an empty list.");
            } else {
                Object example = list.get(0);
                statusTextField.setText("Table contains " + list.size() + " items of " + example.getClass());
            }

        } else {
            statusTextField.setText("Table contains " + newValue);
        }
    });
}

From source file:com.ubershy.streamsis.project.CuteProject.java

/**
 * Validates list with Actors/SisScenes. <br>
 * Throws exceptions if something is wrong telling programmer about errors he made.
 *
 * @param list/*from  w  w w  .  j ava 2s  .  c  o  m*/
 *            the list with Actors or SisScenes
 */
private <T> void validateListOfActorsOrSisScenes(ObservableList<T> list) {
    if (list.isEmpty()) {
        return;
    }
    if (list.contains(null)) {
        throw new RuntimeException("One of the elements in list is null");
    }
    String elementType = null;
    Object firstElement = list.get(0);
    if (firstElement instanceof Actor) {
        elementType = "Actor";
    }
    if (firstElement instanceof SisScene) {
        elementType = "SisScene";
    }
    if (elementType == null) {
        throw new RuntimeException("This method only checks lists of Actors or SisScenes");
    }

    ArrayList<String> names = new ArrayList<String>();
    for (T element : list) {
        String name = ((CuteElement) element).getElementInfo().getName();
        if (name != null) {
            names.add(name);
        } else {
            throw new RuntimeException(elementType + " has null name");
        }
    }
    HashSet<String> uniqueNames = new HashSet<String>(names);
    if (names.size() != uniqueNames.size()) {
        throw new RuntimeException("Some of " + elementType + "s don't have unique names");
    }
}

From source file:edu.kit.trufflehog.model.configdata.FilterDataModelTest.java

/**
 * <p>//w  w w.jav  a 2  s .  c  om
 *     Tests the remove functionality of the database by adding 100 randomly generated FilterInputs and removing
 *     them again, making sure the database is up-to-date along the way.
 * </p>
 *
 * @throws Exception Passes any errors that occurred during the test on
 */
// FIXME fix this test, it randomly fails (Database file locked)
@Test
public void testRemoveFilterFromDatabase() throws Exception {
    List<FilterInput> filterInputs = new ArrayList<>();
    int size = (int) (Math.random() * 100);

    // Add X FilterInputs into the database
    for (int i = 0; i < size; i++) {
        FilterInput filterInput = generateRandomFilterInput();
        filterInputs.add(filterInput);
        filterDataModel.addFilterToDatabaseAsynchronous(filterInput);
    }

    // Wait for all threads to finish
    Thread.sleep(1000);

    // Retrieve them
    filterDataModel = new FilterDataModel(fileSystem);
    ObservableList<FilterInput> filterInputFromDB = filterDataModel.getAllFilters();

    Map<String, FilterInput> filterInputMap = new HashMap<>();

    filterInputFromDB.stream().forEach(fIn -> filterInputMap.put(fIn.getName(), fIn));

    // Make sure we could retrieve them all correctly
    for (FilterInput filterInput : filterInputs) {
        assertEquals(true, filterInputMap.containsKey(filterInput.getName()));
    }

    // Delete them
    filterInputFromDB.forEach((value) -> filterDataModel.removeFilterFromDatabaseAsynchronous(value));

    // Wait for all threads to finish
    Thread.sleep(5000);

    // Retrieve them
    filterDataModel = new FilterDataModel(fileSystem);
    filterInputFromDB = filterDataModel.getAllFilters();

    // Make sure none were found
    assertEquals(true, filterInputFromDB.isEmpty());
}

From source file:com.github.drbookings.ui.controller.MainController.java

private LocalDate getSelectedDate() {
    ObservableList<DateBean> selectedDate = tableView.getSelectionModel().getSelectedItems();
    if (logger.isDebugEnabled()) {
        logger.debug("Selected date: " + selectedDate);
    }/*ww w. j ava2  s .  c  o  m*/
    LocalDate selectedDate2;
    if (selectedDate == null || selectedDate.isEmpty()) {
        selectedDate2 = LocalDate.now();
    } else {
        selectedDate2 = selectedDate.get(0).getDate();
    }
    return selectedDate2;
}

From source file:com.exalttech.trex.ui.views.importPcap.ImportedPacketTableView.java

/**
 * Validate stream names/*from w  w w  .  ja  va  2  s  .  c  om*/
 *
 * @return
 */
private boolean validateStreamNames() {

    ObservableList<Integer> duplicateIndexesList = FXCollections.observableArrayList();
    duplicateRowNamesMap.clear();
    // validate saved stream names
    for (ImportPcapTableData tableData : tableDataList) {
        if (tableData.isSelected()) {
            // comparing with existing streams
            if ((existingNamesList.contains(tableData.getName())
                    || Util.isNullOrEmpty(tableData.getName().trim()))) {
                addDuplicateIndex(duplicateIndexesList, tableData);
            }
            // compairing with other streams in list
            if (duplicateRowNamesMap.get(tableData.getName()) != null) {
                // name is duplicate
                addDuplicateIndex(duplicateIndexesList, tableData);
                addDuplicateIndex(duplicateIndexesList, duplicateRowNamesMap.get(tableData.getName()));
            } else {
                // add existing names in imported table
                duplicateRowNamesMap.put(tableData.getName(), tableData);
            }
        }
    }

    highlightedRowFactory.getRowsToHighlight().setAll(duplicateIndexesList);
    boolean validNames = true;
    if (!duplicateIndexesList.isEmpty()) {
        validNames = false;
        Alert alert = Util.getAlert(Alert.AlertType.ERROR);
        alert.setContentText(
                "Some packet names (highlighted in red) have the same names of exisiting packets !");
        alert.showAndWait();
    }
    return validNames;
}

From source file:io.github.mzmine.modules.plots.msspectrum.MsSpectrumPlotWindowController.java

public void handleContextMenuShowing(ContextMenuEvent event) {

    // Calculate the m/z value of the clicked point
    final double clickedX = event.getX();
    XYPlot plot = chartNode.getChart().getXYPlot();
    Rectangle2D chartArea = chartNode.getRenderingInfo().getPlotInfo().getDataArea();
    RectangleEdge axisEdge = plot.getDomainAxisEdge();
    ValueAxis domainAxis = plot.getDomainAxis();
    final double clickedMz = domainAxis.java2DToValue(clickedX, chartArea, axisEdge);
    final double clickedMzWithShift = Math.abs(clickedMz - mzShift.get());

    // Update the m/z shift menu item
    DecimalFormat mzFormat = MZmineCore.getConfiguration().getMZFormat();
    setToMenuItem.setText("Set to " + mzFormat.format(clickedMz) + " m/z");
    setToMenuItem.setUserData(clickedMz);

    // Update the Show XIC menu item
    showXICMenuItem.setText("Show XIC of " + mzFormat.format(clickedMzWithShift) + " m/z");
    showXICMenuItem.setUserData(clickedMzWithShift);

    // Update the MS/MS menu
    findMSMSMenu.setText("Find MS/MS of " + mzFormat.format(clickedMzWithShift) + " m/z");
    final ObservableList<MenuItem> msmsItems = findMSMSMenu.getItems();
    msmsItems.clear();/*www .  j  av  a 2s . c o m*/
    MZmineProject project = MZmineCore.getCurrentProject();
    for (RawDataFile file : project.getRawDataFiles()) {
        scans: for (MsScan scan : file.getScans()) {
            if (scan.getMsFunction().getMsLevel() == 1)
                continue;
            for (IsolationInfo isolation : scan.getIsolations()) {
                if (!isolation.getIsolationMzRange().contains(clickedMzWithShift))
                    continue;
                String menuLabel = MsScanUtils.createSingleLineMsScanDescription(scan, isolation);
                MenuItem msmsItem = new MenuItem(menuLabel);
                msmsItem.setOnAction(e -> MsSpectrumPlotModule.showNewSpectrumWindow(scan));
                msmsItems.add(msmsItem);
                continue scans;
            }
        }
    }
    if (msmsItems.isEmpty()) {
        MenuItem noneItem = new MenuItem("None");
        noneItem.setDisable(true);
        msmsItems.add(noneItem);
    }

    // Update the Remove... menu
    final ObservableList<MenuItem> rmItems = removeDatasetMenu.getItems();
    rmItems.clear();
    for (MsSpectrumDataSet dataset : datasets) {
        MenuItem msmsItem = new MenuItem(dataset.getName());
        msmsItem.setOnAction(e -> datasets.remove(dataset));
        rmItems.add(msmsItem);
    }
    removeDatasetMenu.setDisable(rmItems.isEmpty());

}

From source file:de.bayern.gdi.gui.Controller.java

private void setCrsAndExtent(WFSMeta.Feature feature) {
    wmsWfsMapHandler.setExtend(feature.getBBox());
    ArrayList<String> list = new ArrayList<>();
    list.add(feature.getDefaultCRS());/*from  w w w  .  j a va2s  .  c  o m*/
    list.addAll(feature.getOtherCRSs());
    ObservableList<CRSModel> crsList = FXCollections.observableArrayList();
    for (String crsStr : list) {
        try {
            String newcrsStr = crsStr;
            String seperator = null;
            if (newcrsStr.contains("::")) {
                seperator = "::";
            } else if (newcrsStr.contains("/")) {
                seperator = "/";
            }
            if (seperator != null) {
                newcrsStr = "EPSG:" + newcrsStr.substring(newcrsStr.lastIndexOf(seperator) + seperator.length(),
                        newcrsStr.length());
            }
            CoordinateReferenceSystem crs = CRS.decode(newcrsStr);
            CRSModel crsm = new CRSModel(crs);
            crsm.setOldName(crsStr);
            crsList.add(crsm);
        } catch (FactoryException e) {
            log.error(e.getMessage(), e);
        }
    }
    if (!crsList.isEmpty()) {
        this.referenceSystemChooser.setItems(crsList);
        CRSModel crsm = crsList.get(0);
        try {
            CoordinateReferenceSystem initCRS = CRS.decode(INITIAL_CRS_DISPLAY);
            CRSModel initCRSM = new CRSModel(initCRS);
            for (int i = 0; i < crsList.size(); i++) {
                if (crsList.get(i).equals(initCRSM)) {
                    crsm = crsList.get(i);
                    break;
                }
            }
        } catch (FactoryException e) {
            log.error(e.getMessage(), e);
        }
        this.referenceSystemChooser.setValue(crsm);
    }
}

From source file:de.bayern.gdi.gui.Controller.java

/**
 * Sets the Service Types./*from  w w w .  ja v  a  2s.c om*/
 */
public void setServiceTypes() {
    if (dataBean.isWebServiceSet()) {
        switch (dataBean.getServiceType()) {
        case WFS_ONE:
        case WFS_TWO:
            boolean isWfs2 = WFS_TWO.equals(dataBean.getServiceType());
            ObservableList<ItemModel> types = collectServiceTypes(isWfs2);
            addStoredQueries(types);
            serviceTypeChooser.getItems().retainAll();
            serviceTypeChooser.setItems(types);
            serviceTypeChooser.setValue(types.get(0));
            chooseType(serviceTypeChooser.getValue());
            break;
        case ATOM:
            List<Atom.Item> items = dataBean.getAtomService().getItems();
            ObservableList<ItemModel> opts = FXCollections.observableArrayList();
            List<FeaturePolygon> polygonList = new ArrayList<>();
            //Polygons are always epsg:4326
            // (http://www.georss.org/gml.html)
            try {
                ReferencedEnvelope extendATOM = null;
                CoordinateReferenceSystem atomCRS = CRS.decode(ATOM_CRS_STRING);
                Geometry all = null;
                for (Atom.Item i : items) {
                    opts.add(new AtomItemModel(i));
                    FeaturePolygon polygon = new FeaturePolygon(i.getPolygon(), i.getTitle(), i.getID(),
                            atomCRS);
                    polygonList.add(polygon);
                    all = all == null ? i.getPolygon() : all.union(i.getPolygon());
                }
                if (wmsAtomMapHandler != null) {
                    if (all != null) {
                        extendATOM = new ReferencedEnvelope(all.getEnvelopeInternal(), atomCRS);
                        wmsAtomMapHandler.setExtend(extendATOM);
                    }
                    wmsAtomMapHandler.drawPolygons(polygonList);
                }
            } catch (FactoryException e) {
                log.error(e.getMessage(), e);
            }
            serviceTypeChooser.getItems().retainAll();
            serviceTypeChooser.setItems(opts);
            if (!opts.isEmpty()) {
                serviceTypeChooser.setValue(opts.get(0));
                chooseType(serviceTypeChooser.getValue());
            }
            break;
        default:
        }
    }
}