Example usage for javafx.scene.control TreeTableColumn TreeTableColumn

List of usage examples for javafx.scene.control TreeTableColumn TreeTableColumn

Introduction

In this page you can find the example usage for javafx.scene.control TreeTableColumn TreeTableColumn.

Prototype

public TreeTableColumn(String text) 

Source Link

Document

Creates a TreeTableColumn with the text set to the provided string, with default cell factory, comparator, and onEditCommit implementation.

Usage

From source file:Main.java

@Override
public void start(Stage stage) {
    final Scene scene = new Scene(new Group(), 200, 400);
    Group sceneRoot = (Group) scene.getRoot();

    TreeItem<String> childNode1 = new TreeItem<>("Node 1");
    TreeItem<String> childNode2 = new TreeItem<>("Node 2");
    TreeItem<String> childNode3 = new TreeItem<>("Node 3");

    TreeItem<String> root = new TreeItem<>("Root");
    root.setExpanded(true);/*from  ww  w  .ja  v a  2s . co m*/

    root.getChildren().setAll(childNode1, childNode2, childNode3);

    TreeTableColumn<String, String> column = new TreeTableColumn<>("Column");
    column.setPrefWidth(150);

    column.setCellValueFactory(
            (CellDataFeatures<String, String> p) -> new ReadOnlyStringWrapper(p.getValue().getValue()));

    TreeTableView<String> treeTableView = new TreeTableView<>(root);
    treeTableView.getColumns().add(column);
    sceneRoot.getChildren().add(treeTableView);
    stage.setScene(scene);
    stage.show();
}

From source file:Main.java

@Override
public void start(Stage stage) {
    root.setExpanded(true);// www.j  a v  a2  s . c o  m
    employees.stream().forEach((employee) -> {
        root.getChildren().add(new TreeItem<>(employee));
    });
    Scene scene = new Scene(new Group(), 400, 400);
    Group sceneRoot = (Group) scene.getRoot();

    TreeTableColumn<Employee, String> empColumn = new TreeTableColumn<>("Employee");
    empColumn.setPrefWidth(150);
    empColumn.setCellValueFactory(
            (TreeTableColumn.CellDataFeatures<Employee, String> param) -> new ReadOnlyStringWrapper(
                    param.getValue().getValue().getName()));

    TreeTableColumn<Employee, String> emailColumn = new TreeTableColumn<>("Email");
    emailColumn.setPrefWidth(190);
    emailColumn.setCellValueFactory(
            (TreeTableColumn.CellDataFeatures<Employee, String> param) -> new ReadOnlyStringWrapper(
                    param.getValue().getValue().getEmail()));

    TreeTableView<Employee> treeTableView = new TreeTableView<>(root);
    treeTableView.getColumns().setAll(empColumn, emailColumn);

    treeTableView.setTableMenuButtonVisible(true);

    sceneRoot.getChildren().add(treeTableView);
    stage.setScene(scene);
    stage.show();
}

From source file:jduagui.Controller.java

private TreeTableColumn setNameColumn() {
    TreeTableColumn<File, String> col = new TreeTableColumn<>("Name");
    col.setCellValueFactory((CellDataFeatures<File, String> p) -> {
        File f = p.getValue().getValue();
        if (f.getPath().equals(rootPath))
            return new ReadOnlyStringWrapper(f.getPath());
        else/*from w w  w. j a v  a  2  s  .  c  om*/
            return new ReadOnlyStringWrapper(f.getName());
    });
    return col;
}

From source file:jduagui.Controller.java

private TreeTableColumn setSizeColumn() {
    TreeTableColumn<File, String> col = new TreeTableColumn<>("Size");
    col.setCellValueFactory((CellDataFeatures<File, String> p) -> {
        ReadOnlyStringWrapper wrap;/*from   w ww.  j  a  v  a 2s.  com*/
        File file = p.getValue().getValue();
        String curPath = file.getPath();
        long size = file.length();
        if (file.isDirectory()) {
            if (storageCache.containsKey(curPath)) {
                wrap = new ReadOnlyStringWrapper(getByteSize(storageCache.get(curPath)));
            } else {
                try {
                    size = FileItem.getSize(curPath, subDirs, subFiles);
                    storageCache.put(curPath, size);
                    wrap = new ReadOnlyStringWrapper(getByteSize(size));
                } catch (IOException e) {
                    storageCache.put(curPath, new Long(0));
                    wrap = new ReadOnlyStringWrapper(getByteSize(0));
                }
            }
        } else if (file.isFile()) {
            storageCache.put(curPath, size);
            wrap = new ReadOnlyStringWrapper(getByteSize(size));
        } else {
            storageCache.put(curPath, new Long(0));
            wrap = new ReadOnlyStringWrapper(getByteSize(0));
        }
        return wrap;
    });
    col.setComparator(new sizeComparator());
    return col;
}

From source file:jduagui.Controller.java

private TreeTableColumn setPercentColumn() {
    TreeTableColumn<File, String> col = new TreeTableColumn<>("~Percent");
    col.setCellValueFactory((CellDataFeatures<File, String> p) -> {
        ReadOnlyStringWrapper wrap;/*w  w  w.  ja  v  a  2s .c  o m*/
        File file = p.getValue().getValue();
        String curPath = file.getPath();
        if (curPath.equals(rootPath)) {
            wrap = new ReadOnlyStringWrapper("100.00 %");
        } else {
            if ((storageCache.get(curPath) != null) && (storageCache.get(curPath) > 0)) {
                double percentage = (double) storageCache.get(curPath);
                percentage /= storageCache.get(file.getParent());
                if (percentage == 1.0)
                    wrap = new ReadOnlyStringWrapper("100.00 %");
                else {
                    percentage *= 100.0;
                    wrap = new ReadOnlyStringWrapper(twoDecimals(new BigDecimal(percentage), " %"));
                }
            } else {
                wrap = new ReadOnlyStringWrapper("0.00 %");
            }
        }
        return wrap;
    });
    col.setComparator(new percentComparator());
    return col;
}

From source file:jduagui.Controller.java

private TreeTableColumn setItemColumn() {
    TreeTableColumn<File, String> col = new TreeTableColumn<>("Items");
    col.setCellValueFactory((CellDataFeatures<File, String> p) -> {
        File file = p.getValue().getValue();
        String curPath = file.getPath();
        if (file.isDirectory()) {
            return new ReadOnlyStringWrapper("" + (subDirs.get(curPath) + subFiles.get(curPath)));
        } else/*from   w ww. ja  v a 2s . c  o m*/
            return new ReadOnlyStringWrapper("");
    });
    col.setComparator(new longComparator());
    return col;
}

From source file:jduagui.Controller.java

private TreeTableColumn setDirColumn() {
    TreeTableColumn<File, String> col = new TreeTableColumn<>("Subdirectories");
    col.setCellValueFactory((CellDataFeatures<File, String> p) -> {
        File file = p.getValue().getValue();
        String curPath = file.getPath();
        if (file.isDirectory()) {
            return new ReadOnlyStringWrapper("" + subDirs.get(curPath));
        } else/*w  w w  . j a  va 2  s  .com*/
            return new ReadOnlyStringWrapper("");
    });
    col.setComparator(new longComparator());
    return col;
}

From source file:jduagui.Controller.java

private TreeTableColumn setFileColumn() {
    TreeTableColumn<File, String> col = new TreeTableColumn<>("Files");
    col.setCellValueFactory((CellDataFeatures<File, String> p) -> {
        File file = p.getValue().getValue();
        String curPath = file.getPath();
        if (file.isDirectory()) {
            return new ReadOnlyStringWrapper("" + subFiles.get(curPath));
        } else// ww  w . j  av  a  2 s .  c om
            return new ReadOnlyStringWrapper("");
    });
    col.setComparator(new longComparator());
    return col;
}

From source file:qupath.lib.gui.tma.TMASummaryViewer.java

private void refreshTableData() {

    //      int nn = 0;
    //      double nPositive = 0;
    //      for (TMAEntry entry : entriesBase) {
    //         if (entry.isMissing())
    //            continue;
    //         nPositive += entry.getMeasurementAsDouble("Num Positive");
    //         nn++;
    //      }/* www. j  av  a2s .co  m*/
    //      System.err.println(nPositive + " positive cells across " + nn + " tissue samples");

    Collection<? extends TMAEntry> entries = groupByIDProperty.get() ? createSummaryEntries(entriesBase)
            : entriesBase;

    // Ensure that we don't try to modify a filtered list
    List<TreeTableColumn<TMAEntry, ?>> columns = new ArrayList<>();

    // Add an empty column.
    // Its purpose is to provide the space needed for the little expansion arrows, to avoid 
    // these stealing space from the first interesting column.
    // Note: there's nothing to prevent the user reordering it along with other columns... 
    // but hopefully it looks 'right' enough where it is that few would try to do that
    TreeTableColumn<TMAEntry, String> columnEmpty = new TreeTableColumn<>("  ");
    columnEmpty
            .setCellValueFactory(new Callback<CellDataFeatures<TMAEntry, String>, ObservableValue<String>>() {
                @Override
                public ObservableValue<String> call(CellDataFeatures<TMAEntry, String> p) {
                    return Bindings.createStringBinding(() -> "");
                }
            });
    columnEmpty.setSortable(false);
    columnEmpty.setResizable(false);
    columns.add(columnEmpty);

    // Check if we have any images or overlays
    boolean hasImages = entries.stream().anyMatch(e -> e.hasImage());
    boolean hasOverlay = entries.stream().anyMatch(e -> e.hasOverlay());

    // Add columns to show images, if we have them
    if (hasImages || hasOverlay) {
        TreeTableColumn<TMAEntry, TMAEntry> columnImage = hasImages ? new TreeTableColumn<>("Thumbnail") : null;
        TreeTableColumn<TMAEntry, TMAEntry> columnOverlay = hasOverlay ? new TreeTableColumn<>("Overlay")
                : null;

        if (hasImages) {
            columnImage.setCellValueFactory(
                    new Callback<CellDataFeatures<TMAEntry, TMAEntry>, ObservableValue<TMAEntry>>() {
                        @Override
                        public ObservableValue<TMAEntry> call(CellDataFeatures<TMAEntry, TMAEntry> p) {
                            return p.getValue().valueProperty();
                        }
                    });
            columnImage.setCellFactory(c -> new ImageTableCell(imageCache, false));
            columnImage.maxWidthProperty().bind(maxSmallWidth);
            columnImage.widthProperty().addListener((v, o, n) -> {
                if (n.doubleValue() == columnImage.getPrefWidth())
                    return;
                if (hasOverlay)
                    columnOverlay.setPrefWidth(n.doubleValue());
                table.refresh();
            });
            columns.add(columnImage);
        }

        if (hasOverlay) {
            columnOverlay.setCellValueFactory(
                    new Callback<CellDataFeatures<TMAEntry, TMAEntry>, ObservableValue<TMAEntry>>() {
                        @Override
                        public ObservableValue<TMAEntry> call(CellDataFeatures<TMAEntry, TMAEntry> p) {
                            return p.getValue().valueProperty();
                        }
                    });
            columnOverlay.setCellFactory(c -> new ImageTableCell(imageCache, true));
            columnOverlay.maxWidthProperty().bind(maxSmallWidth);
            columnOverlay.widthProperty().addListener((v, o, n) -> {
                if (n.doubleValue() == columnOverlay.getPrefWidth())
                    return;
                columnImage.setPrefWidth(n.doubleValue());
                if (hasImages)
                    table.refresh();
            });
            columns.add(columnOverlay);
        }
    }

    // Update image availability
    if (hasImages) {
        if (hasOverlay)
            imageAvailability.set(ImageAvailability.BOTH);
        else
            imageAvailability.set(ImageAvailability.IMAGE_ONLY);
    } else if (hasOverlay) {
        imageAvailability.set(ImageAvailability.OVERLAY_ONLY);
    } else
        imageAvailability.set(ImageAvailability.NONE);

    for (String name : model.getAllNames()) {
        if (model.getMeasurementNames().contains(name)) {
            TreeTableColumn<TMAEntry, Number> column = new TreeTableColumn<>(name);
            column.setCellValueFactory(
                    new Callback<CellDataFeatures<TMAEntry, Number>, ObservableValue<Number>>() {
                        @Override
                        public ObservableValue<Number> call(CellDataFeatures<TMAEntry, Number> p) {
                            double value = p.getValue() == null ? Double.NaN
                                    : model.getNumericValue(p.getValue().getValue(), name);
                            return new SimpleDoubleProperty(value);
                        }
                    });
            column.setCellFactory(c -> new NumericTableCell<>());
            columns.add(column);
        } else {
            TreeTableColumn<TMAEntry, Object> column = new TreeTableColumn<>(name);
            column.setCellValueFactory(
                    new Callback<CellDataFeatures<TMAEntry, Object>, ObservableValue<Object>>() {
                        @Override
                        public ObservableValue<Object> call(CellDataFeatures<TMAEntry, Object> p) {
                            return new SimpleObjectProperty<>(p.getValue() == null ? null
                                    : model.getStringValue(p.getValue().getValue(), name));
                        }
                    });
            column.setCellFactory(c -> new BasicTableCell<>());
            columns.add(column);
        }
    }

    // Set the column visibility depending upon whether they were hidden previously
    columns.stream().forEach(c -> c.setVisible(!lastHiddenColumns.contains(c.getText())));

    // Set columns for table
    table.getColumns().setAll(columns);

    // Set new root for table
    TreeItem<TMAEntry> root = new RootTreeItem(entries, combinedPredicate);
    table.setShowRoot(false);
    table.setRoot(root);

    model.refreshList();
}