Search in sources :

Example 1 with TreeTableRow

use of javafx.scene.control.TreeTableRow in project Gargoyle by callakrsos.

the class CustomSkinConfigView method initialize.

@FXML
public void initialize() {
    ttvIConfig.setRowFactory(new Callback<TreeTableView<ConfigurationTreeItem>, TreeTableRow<ConfigurationTreeItem>>() {

        @Override
        public TreeTableRow<ConfigurationTreeItem> call(TreeTableView<ConfigurationTreeItem> param) {
            TreeTableRow<ConfigurationTreeItem> treeTableRow = new TreeTableRow<>();
            treeTableRow.setOnMouseClicked(ev -> {
                ConfigurationTreeItem item = treeTableRow.getItem();
                selectedItem.set(item);
            });
            return treeTableRow;
        }
    });
    ttcConfig.setCellValueFactory(param -> param.getValue().getValue().itemNameProperty());
    ConfigurationTreeItem root = new ConfigurationTreeItem();
    root.setItemName("Basic");
    {
        ConfigurationLeafNodeItem fontConfigItem = new ConfigurationLeafNodeItem();
        fontConfigItem.setItemName("Font Management");
        fontConfigItem.setContentNode(FontViewComposite.class);
        ConfigurationLeafNodeItem backgroundConfigItem = new ConfigurationLeafNodeItem();
        backgroundConfigItem.setItemName("Color Management");
        backgroundConfigItem.setContentNode(SkinPreviewViewComposite.class);
        root.setChildrens(Arrays.asList(fontConfigItem, backgroundConfigItem));
    }
    TreeItem<ConfigurationTreeItem> createNode = new ConfigItemTreeItem().createNode(root);
    createNode.setExpanded(true);
    ttvIConfig.setRoot(createNode);
    ttvIConfig.setOnMouseClicked(ev -> {
        if (ev.getClickCount() == 2) {
            load(selectedItem.get());
        }
    });
    selectedItem.addListener((oba, o, n) -> {
        btnEdit.setDisable(true);
        if (n instanceof ConfigurationLeafNodeItem) {
            if (((ConfigurationLeafNodeItem) n).getContentNode() != null) {
                btnEdit.setDisable(false);
            }
        }
    });
}
Also used : Button(javafx.scene.control.Button) Arrays(java.util.Arrays) TreeItem(javafx.scene.control.TreeItem) URISyntaxException(java.net.URISyntaxException) LoggerFactory(org.slf4j.LoggerFactory) TreeTableRow(javafx.scene.control.TreeTableRow) Parent(javafx.scene.Parent) TreeTableView(javafx.scene.control.TreeTableView) Callback(javafx.util.Callback) ObjectProperty(javafx.beans.property.ObjectProperty) Logger(org.slf4j.Logger) FontViewComposite(com.kyj.fx.voeditor.visual.component.font.FontViewComposite) FXMLController(com.kyj.fx.voeditor.visual.framework.annotation.FXMLController) ConfigItemTreeItem(com.kyj.fx.voeditor.visual.component.ConfigItemTreeItem) ValueUtil(com.kyj.fx.voeditor.visual.util.ValueUtil) Consumer(java.util.function.Consumer) FXML(javafx.fxml.FXML) FxUtil(com.kyj.fx.voeditor.visual.util.FxUtil) TreeTableColumn(javafx.scene.control.TreeTableColumn) ConfigurationLeafNodeItem(com.kyj.fx.voeditor.visual.main.model.vo.ConfigurationLeafNodeItem) ConfigurationGraphicsNodeItem(com.kyj.fx.voeditor.visual.main.model.vo.ConfigurationGraphicsNodeItem) ConfigurationTreeItem(com.kyj.fx.voeditor.visual.main.model.vo.ConfigurationTreeItem) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) SkinManager(com.kyj.fx.voeditor.visual.momory.SkinManager) BorderPane(javafx.scene.layout.BorderPane) FontViewComposite(com.kyj.fx.voeditor.visual.component.font.FontViewComposite) TreeTableView(javafx.scene.control.TreeTableView) ConfigurationLeafNodeItem(com.kyj.fx.voeditor.visual.main.model.vo.ConfigurationLeafNodeItem) TreeTableRow(javafx.scene.control.TreeTableRow) ConfigurationTreeItem(com.kyj.fx.voeditor.visual.main.model.vo.ConfigurationTreeItem) ConfigItemTreeItem(com.kyj.fx.voeditor.visual.component.ConfigItemTreeItem) FXML(javafx.fxml.FXML)

Example 2 with TreeTableRow

use of javafx.scene.control.TreeTableRow in project jgnash by ccavanaugh.

the class AccountsViewController method getTreeTableRow.

private TreeTableRow<Account> getTreeTableRow() {
    final TreeTableRow<Account> treeTableRow = new TreeTableRow<>();
    treeTableRow.setOnMouseClicked(event -> {
        if (event.getButton().equals(MouseButton.PRIMARY) && event.getClickCount() == 2) {
            if (selectedAccount.get() != null && !selectedAccount.get().isPlaceHolder()) {
                Platform.runLater(AccountsViewController.this::handleZoomAccountAction);
            }
        }
    });
    final ContextMenu rowMenu = new ContextMenu();
    final MenuItem newItem = new MenuItem(resources.getString("Menu.New.Name"));
    newItem.setOnAction(event -> handleNewAccountAction());
    final MenuItem modifyItem = new MenuItem(resources.getString("Menu.Modify.Name"));
    modifyItem.setOnAction(event -> handleModifyAccountAction());
    final MenuItem deleteItem = new MenuItem(resources.getString("Menu.Delete.Name"));
    deleteItem.setOnAction(event -> handleDeleteAccountAction());
    deleteItem.disableProperty().bind(deleteButton.disabledProperty());
    final MenuItem visibilityMenuItem = new MenuItem(resources.getString("Menu.Hide.Name"));
    visibilityMenuItem.setOnAction(event -> handleModifyAccountAction());
    visibilityMenuItem.setOnAction(event -> new Thread(() -> {
        final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
        if (engine != null) {
            engine.toggleAccountVisibility(selectedAccount.get());
        }
    }).start());
    final MenuItem reconcileItem = new MenuItem(resources.getString("Menu.Reconcile.Name"));
    reconcileItem.setOnAction(event -> handleReconcileAction());
    rowMenu.getItems().addAll(newItem, modifyItem, deleteItem, new SeparatorMenuItem(), visibilityMenuItem, new SeparatorMenuItem(), reconcileItem);
    rowMenu.setOnShowing(event -> visibilityMenuItem.setText(selectedAccount.get().isVisible() ? resources.getString("Menu.Hide.Name") : resources.getString("Menu.Show.Name")));
    treeTableRow.contextMenuProperty().bind(Bindings.when(Bindings.isNotNull(treeTableRow.itemProperty())).then(rowMenu).otherwise((ContextMenu) null));
    return treeTableRow;
}
Also used : RootAccount(jgnash.engine.RootAccount) Account(jgnash.engine.Account) ContextMenu(javafx.scene.control.ContextMenu) MenuItem(javafx.scene.control.MenuItem) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) TreeTableRow(javafx.scene.control.TreeTableRow) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) Engine(jgnash.engine.Engine)

Example 3 with TreeTableRow

use of javafx.scene.control.TreeTableRow in project jabref by JabRef.

the class GroupTreeController method initialize.

@FXML
public void initialize() {
    viewModel = new GroupTreeViewModel(stateManager, dialogService, taskExecutor);
    // Set-up groups tree
    groupTree.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
    // Set-up bindings
    Consumer<ObservableList<GroupNodeViewModel>> updateSelectedGroups = (newSelectedGroups) -> newSelectedGroups.forEach(this::selectNode);
    Consumer<List<TreeItem<GroupNodeViewModel>>> updateViewModel = (newSelectedGroups) -> {
        if (newSelectedGroups == null) {
            viewModel.selectedGroupsProperty().clear();
        } else {
            viewModel.selectedGroupsProperty().setAll(newSelectedGroups.stream().map(TreeItem::getValue).collect(Collectors.toList()));
        }
    };
    BindingsHelper.bindContentBidirectional(groupTree.getSelectionModel().getSelectedItems(), viewModel.selectedGroupsProperty(), updateSelectedGroups, updateViewModel);
    viewModel.filterTextProperty().bind(searchField.textProperty());
    groupTree.rootProperty().bind(EasyBind.map(viewModel.rootGroupProperty(), group -> new RecursiveTreeItem<>(group, GroupNodeViewModel::getChildren, GroupNodeViewModel::expandedProperty, viewModel.filterPredicateProperty())));
    // Icon and group name
    mainColumn.setCellValueFactory(cellData -> cellData.getValue().valueProperty());
    mainColumn.setCellFactory(new ViewModelTreeTableCellFactory<GroupNodeViewModel, GroupNodeViewModel>().withText(GroupNodeViewModel::getDisplayName).withIcon(GroupNodeViewModel::getIconCode, GroupNodeViewModel::getColor).withTooltip(GroupNodeViewModel::getDescription));
    // Number of hits
    PseudoClass anySelected = PseudoClass.getPseudoClass("any-selected");
    PseudoClass allSelected = PseudoClass.getPseudoClass("all-selected");
    numberColumn.setCellFactory(new ViewModelTreeTableCellFactory<GroupNodeViewModel, GroupNodeViewModel>().withGraphic(group -> {
        final StackPane node = new StackPane();
        node.getStyleClass().setAll("hits");
        if (!group.isRoot()) {
            BindingsHelper.includePseudoClassWhen(node, anySelected, group.anySelectedEntriesMatchedProperty());
            BindingsHelper.includePseudoClassWhen(node, allSelected, group.allSelectedEntriesMatchedProperty());
        }
        Text text = new Text();
        text.textProperty().bind(group.getHits().asString());
        text.getStyleClass().setAll("text");
        node.getChildren().add(text);
        node.setMaxWidth(Control.USE_PREF_SIZE);
        return node;
    }));
    // Arrow indicating expanded status
    disclosureNodeColumn.setCellValueFactory(cellData -> cellData.getValue().valueProperty());
    disclosureNodeColumn.setCellFactory(new ViewModelTreeTableCellFactory<GroupNodeViewModel, GroupNodeViewModel>().withGraphic(viewModel -> {
        final StackPane disclosureNode = new StackPane();
        disclosureNode.visibleProperty().bind(viewModel.hasChildrenProperty());
        disclosureNode.getStyleClass().setAll("tree-disclosure-node");
        final StackPane disclosureNodeArrow = new StackPane();
        disclosureNodeArrow.getStyleClass().setAll("arrow");
        disclosureNode.getChildren().add(disclosureNodeArrow);
        return disclosureNode;
    }).withOnMouseClickedEvent(group -> event -> group.toggleExpansion()));
    // Set pseudo-classes to indicate if row is root or sub-item ( > 1 deep)
    PseudoClass rootPseudoClass = PseudoClass.getPseudoClass("root");
    PseudoClass subElementPseudoClass = PseudoClass.getPseudoClass("sub");
    // Pseudo-classes for drag and drop
    PseudoClass dragOverBottom = PseudoClass.getPseudoClass("dragOver-bottom");
    PseudoClass dragOverCenter = PseudoClass.getPseudoClass("dragOver-center");
    PseudoClass dragOverTop = PseudoClass.getPseudoClass("dragOver-top");
    groupTree.setRowFactory(treeTable -> {
        TreeTableRow<GroupNodeViewModel> row = new TreeTableRow<>();
        row.treeItemProperty().addListener((ov, oldTreeItem, newTreeItem) -> {
            boolean isRoot = newTreeItem == treeTable.getRoot();
            row.pseudoClassStateChanged(rootPseudoClass, isRoot);
            boolean isFirstLevel = (newTreeItem != null) && (newTreeItem.getParent() == treeTable.getRoot());
            row.pseudoClassStateChanged(subElementPseudoClass, !isRoot && !isFirstLevel);
        });
        row.setDisclosureNode(null);
        row.disclosureNodeProperty().addListener((observable, oldValue, newValue) -> row.setDisclosureNode(null));
        row.contextMenuProperty().bind(EasyBind.monadic(row.itemProperty()).map(this::createContextMenuForGroup).orElse((ContextMenu) null));
        row.setOnDragDetected(event -> {
            TreeItem<GroupNodeViewModel> selectedItem = treeTable.getSelectionModel().getSelectedItem();
            if ((selectedItem != null) && (selectedItem.getValue() != null)) {
                Dragboard dragboard = treeTable.startDragAndDrop(TransferMode.MOVE);
                dragboard.setDragView(row.snapshot(null, null));
                ClipboardContent content = new ClipboardContent();
                content.put(DragAndDropDataFormats.GROUP, selectedItem.getValue().getPath());
                dragboard.setContent(content);
                event.consume();
            }
        });
        row.setOnDragOver(event -> {
            Dragboard dragboard = event.getDragboard();
            if ((event.getGestureSource() != row) && row.getItem().acceptableDrop(dragboard)) {
                event.acceptTransferModes(TransferMode.MOVE, TransferMode.LINK);
                removePseudoClasses(row, dragOverBottom, dragOverCenter, dragOverTop);
                switch(getDroppingMouseLocation(row, event)) {
                    case BOTTOM:
                        row.pseudoClassStateChanged(dragOverBottom, true);
                        break;
                    case CENTER:
                        row.pseudoClassStateChanged(dragOverCenter, true);
                        break;
                    case TOP:
                        row.pseudoClassStateChanged(dragOverTop, true);
                        break;
                }
            }
            event.consume();
        });
        row.setOnDragExited(event -> {
            removePseudoClasses(row, dragOverBottom, dragOverCenter, dragOverTop);
        });
        row.setOnDragDropped(event -> {
            Dragboard dragboard = event.getDragboard();
            boolean success = false;
            if (dragboard.hasContent(DragAndDropDataFormats.GROUP)) {
                String pathToSource = (String) dragboard.getContent(DragAndDropDataFormats.GROUP);
                Optional<GroupNodeViewModel> source = viewModel.rootGroupProperty().get().getChildByPath(pathToSource);
                if (source.isPresent()) {
                    source.get().draggedOn(row.getItem(), getDroppingMouseLocation(row, event));
                    success = true;
                }
            }
            if (dragboard.hasContent(DragAndDropDataFormats.ENTRIES)) {
                TransferableEntrySelection entrySelection = (TransferableEntrySelection) dragboard.getContent(DragAndDropDataFormats.ENTRIES);
                row.getItem().addEntriesToGroup(entrySelection.getSelection());
                success = true;
            }
            event.setDropCompleted(success);
            event.consume();
        });
        return row;
    });
    // Filter text field
    setupClearButtonField(searchField);
}
Also used : PseudoClass(javafx.css.PseudoClass) TreeItem(javafx.scene.control.TreeItem) Control(javafx.scene.control.Control) BindingsHelper(org.jabref.gui.util.BindingsHelper) DialogService(org.jabref.gui.DialogService) StackPane(javafx.scene.layout.StackPane) DragEvent(javafx.scene.input.DragEvent) TreeTableRow(javafx.scene.control.TreeTableRow) TransferMode(javafx.scene.input.TransferMode) Inject(javax.inject.Inject) TextFields(org.controlsfx.control.textfield.TextFields) TreeTableView(javafx.scene.control.TreeTableView) Dragboard(javafx.scene.input.Dragboard) ContextMenu(javafx.scene.control.ContextMenu) Localization(org.jabref.logic.l10n.Localization) Method(java.lang.reflect.Method) RecursiveTreeItem(org.jabref.gui.util.RecursiveTreeItem) ObjectProperty(javafx.beans.property.ObjectProperty) TextField(javafx.scene.control.TextField) MenuItem(javafx.scene.control.MenuItem) AbstractController(org.jabref.gui.AbstractController) Collectors(java.util.stream.Collectors) InvocationTargetException(java.lang.reflect.InvocationTargetException) Consumer(java.util.function.Consumer) FXML(javafx.fxml.FXML) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) Text(javafx.scene.text.Text) TreeTableColumn(javafx.scene.control.TreeTableColumn) TaskExecutor(org.jabref.gui.util.TaskExecutor) List(java.util.List) ActionEvent(javafx.event.ActionEvent) StateManager(org.jabref.gui.StateManager) SelectionMode(javafx.scene.control.SelectionMode) DragAndDropDataFormats(org.jabref.gui.DragAndDropDataFormats) EasyBind(org.fxmisc.easybind.EasyBind) ViewModelTreeTableCellFactory(org.jabref.gui.util.ViewModelTreeTableCellFactory) Optional(java.util.Optional) Log(org.apache.commons.logging.Log) ObservableList(javafx.collections.ObservableList) ClipboardContent(javafx.scene.input.ClipboardContent) LogFactory(org.apache.commons.logging.LogFactory) CustomTextField(org.controlsfx.control.textfield.CustomTextField) PseudoClass(javafx.css.PseudoClass) ViewModelTreeTableCellFactory(org.jabref.gui.util.ViewModelTreeTableCellFactory) ClipboardContent(javafx.scene.input.ClipboardContent) Text(javafx.scene.text.Text) ContextMenu(javafx.scene.control.ContextMenu) RecursiveTreeItem(org.jabref.gui.util.RecursiveTreeItem) ObservableList(javafx.collections.ObservableList) List(java.util.List) ObservableList(javafx.collections.ObservableList) TreeTableRow(javafx.scene.control.TreeTableRow) StackPane(javafx.scene.layout.StackPane) Dragboard(javafx.scene.input.Dragboard) FXML(javafx.fxml.FXML)

Aggregations

TreeTableRow (javafx.scene.control.TreeTableRow)3 Consumer (java.util.function.Consumer)2 ObjectProperty (javafx.beans.property.ObjectProperty)2 FXML (javafx.fxml.FXML)2 ContextMenu (javafx.scene.control.ContextMenu)2 MenuItem (javafx.scene.control.MenuItem)2 SeparatorMenuItem (javafx.scene.control.SeparatorMenuItem)2 TreeItem (javafx.scene.control.TreeItem)2 TreeTableColumn (javafx.scene.control.TreeTableColumn)2 TreeTableView (javafx.scene.control.TreeTableView)2 ConfigItemTreeItem (com.kyj.fx.voeditor.visual.component.ConfigItemTreeItem)1 FontViewComposite (com.kyj.fx.voeditor.visual.component.font.FontViewComposite)1 FXMLController (com.kyj.fx.voeditor.visual.framework.annotation.FXMLController)1 ConfigurationGraphicsNodeItem (com.kyj.fx.voeditor.visual.main.model.vo.ConfigurationGraphicsNodeItem)1 ConfigurationLeafNodeItem (com.kyj.fx.voeditor.visual.main.model.vo.ConfigurationLeafNodeItem)1 ConfigurationTreeItem (com.kyj.fx.voeditor.visual.main.model.vo.ConfigurationTreeItem)1 SkinManager (com.kyj.fx.voeditor.visual.momory.SkinManager)1 FxUtil (com.kyj.fx.voeditor.visual.util.FxUtil)1 ValueUtil (com.kyj.fx.voeditor.visual.util.ValueUtil)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1