Java 类javafx.scene.control.cell.TextFieldTreeCell 实例源码

项目:marathonv5    文件:TextFieldTreeViewSample.java   
public TextFieldTreeViewSample() {
    final TreeItem<String> treeRoot = new TreeItem<String>("Root node");
    treeRoot.getChildren().addAll(Arrays.asList(new TreeItem<String>("Child Node 1"), new TreeItem<String>("Child Node 2"),
            new TreeItem<String>("Child Node 3")));

    treeRoot.getChildren().get(2).getChildren().addAll(Arrays.asList(new TreeItem<String>("Child Node 4"),
            new TreeItem<String>("Child Node 5"), new TreeItem<String>("Child Node 6"), new TreeItem<String>("Child Node 7"),
            new TreeItem<String>("Child Node 8"), new TreeItem<String>("Child Node 9"), new TreeItem<String>("Child Node 10"),
            new TreeItem<String>("Child Node 11"), new TreeItem<String>("Child Node 12")));

    final TreeView treeView = new TreeView();
    treeView.setShowRoot(true);
    treeView.setRoot(treeRoot);
    treeRoot.setExpanded(true);
    treeView.setEditable(true);
    treeView.setCellFactory(TextFieldTreeCell.forTreeView());

    getChildren().add(treeView);
}
项目:marathonv5    文件:RFXTreeViewTextFieldTreeCellTest.java   
@Test public void select() {
    @SuppressWarnings("unchecked")
    TreeView<String> treeView = (TreeView<String>) getPrimaryStage().getScene().getRoot().lookup(".tree-view");
    LoggingRecorder lr = new LoggingRecorder();
    Platform.runLater(() -> {
        @SuppressWarnings("unchecked")
        TextFieldTreeCell<String> cell = (TextFieldTreeCell<String>) getCellAt(treeView, 2);
        Point2D point = getPoint(treeView, 2);
        RFXTreeView rfxTreeView = new RFXTreeView(treeView, null, point, lr);
        rfxTreeView.focusGained(rfxTreeView);
        cell.startEdit();
        cell.updateItem("Child node 4 Modified", false);
        cell.commitEdit("Child node 4 Modified");
        rfxTreeView.focusLost(rfxTreeView);
    });
    List<Recording> recordings = lr.waitAndGetRecordings(1);
    Recording recording = recordings.get(0);
    AssertJUnit.assertEquals("recordSelect", recording.getCall());
    AssertJUnit.assertEquals("Child node 4 Modified", recording.getParameters()[0]);
}
项目:Gargoyle    文件:FilesAnalysisComposite.java   
@Override
public TreeCell<V> call(TreeView<V> param) {
    TextFieldTreeCell<V> textFieldTreeCell = new TextFieldTreeCell<V>(treeItemStringConverter) {

        @Override
        public void updateItem(V item, boolean empty) {
            super.updateItem(item, empty);
            if (empty) {
                setGraphic(null);
            } else {
                ObservableList<File> items = item.getItems();
                if (!items.isEmpty()) {
                    File file = items.get(0);
                    setGraphic(new FileIconImageView(file));
                }

            }
        }

    };

    return textFieldTreeCell;
}
项目:Gargoyle    文件:FxControlsTreeItem.java   
public FxControlsTreeItem(TreeView<Node> tv) {
    this.tv = tv;

    tv.setCellFactory(param -> {
        TreeCell<Node> treeCell = new TextFieldTreeCell<Node>(new StringConverter<Node>() {
            @Override
            public String toString(Node n) {
                return getName(n);
            }

            @Override
            public Node fromString(String string) {
                return null;
            }

        });
        return treeCell;
    });

}
项目:marathonv5    文件:RFXTextFieldTreeCell.java   
@SuppressWarnings("unchecked") @Override public String _getValue() {
    TextFieldTreeCell<?> cell = (TextFieldTreeCell<?>) node;
    @SuppressWarnings("rawtypes")
    StringConverter converter = cell.getConverter();
    if (converter != null) {
        return converter.toString(cell.getItem());
    }
    return cell.getItem().toString();
}
项目:Gargoyle    文件:RaxStructureTreeView.java   
public RaxStructureTreeView() {

        setCellFactory(new Callback<TreeView<RaxItem>, TreeCell<RaxItem>>() {

            @Override
            public TreeCell<RaxItem> call(TreeView<RaxItem> param) {

                return new TextFieldTreeCell<>(new StringConverter<RaxItem>() {

                    @Override
                    public String toString(RaxItem object) {
                        if (object == null)
                            return "";
                        return object.getText();
                    }

                    @Override
                    public RaxItem fromString(String string) {
                        return null;
                    }
                });

            }
        });

        setRoot(treeItem);

    }
项目:javafx-dpi-scaling    文件:AdjusterTest.java   
@Test
public void testGetTextFieldTreeCellAdjuster() {
    Adjuster adjuster = Adjuster.getAdjuster(TextFieldTreeCell.class);

    assertThat(adjuster, is(instanceOf(ControlAdjuster.class)));
    assertThat(adjuster.getNodeClass(), is(sameInstance(Control.class)));
}
项目:agile    文件:MainView.java   
public void initialize() {
    NavItem.navs.stream().forEach((ni) -> {
        root.getChildren().add(new TreeItem<>(ni));
    });

    nav2.setCellFactory(new Callback<TreeView<NavItem>, TreeCell<NavItem>>() {

        @Override
        public TreeCell<NavItem> call(TreeView<NavItem> param) {
            return new TextFieldTreeCell<>(new StringConverter<NavItem>() {

                @Override
                public String toString(NavItem object) {
                    return object == null ? "null" : object.getName();
                }

                @Override
                public NavItem fromString(String string) {
                    throw new UnsupportedOperationException();
                }
            });
        }
    });

    nav2.setRoot(root);

    rootGroup.addEventHandler(NavItemEvent.NAV_CHANGED, new EventHandler<NavItemEvent>() {

        @Override
        public void handle(NavItemEvent event) {
            NavItem newItem = event.getNewValue();
            swithBy(newItem);
        }

    });

    splitPane.getStyleClass().add("hidden-splitter");

}
项目:Gargoyle    文件:XMLTreeView.java   
public XMLTreeView() {
    this.setCellFactory(TextFieldTreeCell.forTreeView(new StringConverter<XMLMeta>() {

        @Override
        public String toString(XMLMeta object) {
            if (object == null)
                return "";

            String name = object.getName() == null ? "" : object.getName();
            String text = ValueUtil.isEmpty(object.getText()) ? "" : String.format(" (%s)", object.getText());
            return name.concat(text);

        }

        @Override
        public XMLMeta fromString(String string) {
            return null;
        }
    }));

    this.setShowRoot(false);
    this.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);

    xml.addListener(new ChangeListener<String>() {

        @Override
        public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {

            if (ValueUtil.isEmpty(newValue))
                return;

            TreeItem<XMLMeta> tiRoot = new TreeItem<>();
            XMLTreeView.this.setRoot(tiRoot);
            tiRoot.setExpanded(true);

            try {
                SAXPasrerUtil.getAll(new ByteArrayInputStream(newValue.getBytes()), new XMLTreeHandler(tiRoot));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });

    this.setOnKeyPressed(this::keyOnPressd);
}
项目:Gargoyle    文件:SVNTreeView.java   
/**
 * 컨텍스트 메뉴 등록
 *
 * @작성자 : KYJ
 * @작성일 : 2016. 4. 4.
 */
void addContextMenus() {
    menuNew = new Menu("New");
    menuAddNewLocation = new MenuItem("Repository Location");
    menuDiscardLocation = new MenuItem("Discard Location");
    menuReflesh = new MenuItem("Reflesh");
    menuCheckout = new MenuItem("Checkout");
    menuCopy = new MenuItem("Copy");

    menuSvnGraph = new MenuItem("SVN Graph");
    menuProperties = new MenuItem("Properties");

    menuNew.getItems().add(menuAddNewLocation);

    menuAddNewLocation.setOnAction(this::menuAddNewLocationOnAction);
    menuDiscardLocation.setOnAction(this::menuDiscardLocationOnAction);
    menuCheckout.setOnAction(this::menuCheckoutOnAction);
    menuSvnGraph.setOnAction(this::menuSVNGraphOnAction);
    menuProperties.setOnAction(this::menuPropertiesOnAction);
    menuCopy.setOnAction(this::menuCopyOnAction);
    contextMenuDir = new ContextMenu(menuNew, new SeparatorMenuItem(), menuCheckout, menuCopy, new SeparatorMenuItem(), menuSvnGraph,
            new SeparatorMenuItem(), menuDiscardLocation, menuReflesh, new SeparatorMenuItem(), menuProperties);

    // contextMenuFile = new ContextMenu(menuProperties);
    // setContextMenu(contextMenu);

    // setOnContextMenuRequested(ev -> {
    //
    // Node intersectedNode = ev.getPickResult().getIntersectedNode();
    // if (intersectedNode instanceof TreeCell) {
    // contextMenuDir.show(FxUtil.getWindow(this));
    // }
    //
    // });
    setCellFactory(new Callback<TreeView<SVNItem>, TreeCell<SVNItem>>() {
        @Override
        public TreeCell<SVNItem> call(TreeView<SVNItem> tv) {
            TextFieldTreeCell<SVNItem> textFieldTreeCell = new TextFieldTreeCell<SVNItem>();
            textFieldTreeCell.setContextMenu(contextMenuDir);
            return textFieldTreeCell;
        }
    });

    // 특정 조건에 따른 메뉴 VISIBLE 처리를 정의함.
    contextMenuDir.setOnShown(contextMenuVisibleEvent);
}
项目:factoryfx    文件:FactoryUpdateLogWidget.java   
@Override
public Node createContent() {
    final BorderPane borderPane = new BorderPane();
    factoryLogRootUpdater= root -> {
        TreeView<FactoryLogWidgetTreeData> treeView = new TreeView<>();
        if (factoryLog.root!=null){
            treeView.setRoot(createLogTree(factoryLog.root, System.currentTimeMillis()+5000,new HashMap<>()));
        }
        treeView.setCellFactory(param-> new TextFieldTreeCell<FactoryLogWidgetTreeData>(){
            @Override
            public void updateItem(FactoryLogWidgetTreeData item, boolean empty) {
                super.updateItem(item, empty);
                if (!empty) {
                    setText(item.getText());
                    setGraphic(uniformDesign.createIcon(item.getIcon()));
                }
            }
        });
        final TabPane tabPane = new TabPane();
        tabPane.getStyleClass().add("floating");

        final Tab treeTab = new Tab("Updated Tree");
        treeTab.setContent(treeView);
        tabPane.getTabs().add(treeTab);

        final Tab tableTab = new Tab("Updated Table");
        tableTab.setContent(treeView);
        if (factoryLog.root!=null){
            tableTab.setContent(createTable(factoryLog.root.getListDeep()));
        }
        tabPane.getTabs().add(tableTab);

        final Tab removedTab = new Tab("Removed");
        removedTab.setContent(treeView);
        removedTab.setContent(createTable(factoryLog.removedFactoryLogs));
        tabPane.getTabs().add(removedTab);

        borderPane.setCenter(tabPane);
        final Label totalDuarion = new Label("total update duration: " + (factoryLog.totalDurationNs / 1000000.0) + "ms");
        BorderPane.setMargin(totalDuarion,new Insets(3));
        borderPane.setTop(totalDuarion);
    };
    if (factoryLog!=null) {
        factoryLogRootUpdater.accept(factoryLog);
    }
    return borderPane;
}
项目:Map-Projections    文件:ProjectionSelectionDialog.java   
public ProjectionSelectionDialog() {
    projMap = new HashMap<TreeItem<String>, Projection>();

    final TreeItem<String> root = new TreeItem<String>();
    menu = new TreeView<String>(root);
    menu.setShowRoot(false); //create and configure the TreeView of options
    menu.setPrefWidth(MENU_WIDTH);

    flow = new TextFlow(); //create and configure the description area
    flow.setPrefWidth(TEXT_WIDTH);
    text = new GridPane();
    text.setHgap(10);

    menu.getSelectionModel().selectedItemProperty().addListener((observable, old, now) -> {
            if (projMap.containsKey(now)) //selection callback to describe each projection
                describe(projMap.get(now));
            else if (now != null) {
                describe(null);
            }
        });
    menu.setCellFactory((tView) -> { //factoring cells to detect double-clicks
            final TreeCell<String> cell = new TextFieldTreeCell<String>();
            cell.setOnMouseClicked((event) -> { //on double click, close dialog
                    if (event.getClickCount() >= 2 && projMap.containsKey(cell.getTreeItem())) {
                        this.setResult(projMap.get(cell.getTreeItem()));
                    }
                });
            return cell;
        });

    String[] categories = MapApplication.PROJECTION_CATEGORIES;
    Projection[][] projections = MapApplication.ALL_PROJECTIONS;
    for (int i = 0; i < categories.length; i ++) { //finally, populate the TreeView
        final TreeItem<String> header = new TreeItem<String>(categories[i]);
        root.getChildren().add(header);
        for (int j = 0; j < projections[i].length; j ++) {
            final TreeItem<String> leaf = new TreeItem<String>(projections[i][j].getName());
            projMap.put(leaf, projections[i][j]);
            header.getChildren().add(leaf);
        }
    }

    this.setTitle("Projection selection"); //set general properties for the dialog
    final DialogPane pane = this.getDialogPane();
    pane.setHeaderText("Choose a projection from the list below.");
    pane.getButtonTypes().addAll(new ButtonType[] { ButtonType.OK, ButtonType.CANCEL }); //add buttons
    pane.setContent(new HBox(10, menu, new VBox(10, flow, text)));

    this.setResultConverter((btn) -> { //how to return a result:
            if (btn != null && btn.getButtonData() == ButtonData.OK_DONE) {
                final TreeItem<String> selection =  menu.getSelectionModel().getSelectedItem();
                return projMap.getOrDefault(selection, Projection.NULL_PROJECTION); //return the corresponding projection
            } //or NULL_PROJECTION if the user never chose anything
            else {
                return null;
            }
        });
}
项目:MiscellaneousStudy    文件:EditableTreeViewController.java   
@Override
public void initialize(URL location, ResourceBundle resources) {

    // ルートの子要素を作成
    TreeItem<String> item1 = new TreeItem<String>("Item 1");
    TreeItem<String> item2 = new TreeItem<String>("Item 2");
    TreeItem<String> item3 = new TreeItem<String>("Item 3");
    TreeItem<String> item4 = new TreeItem<String>("Item 4");

    // item4 の子要素
    TreeItem<String> item41 = new TreeItem<String>("Item 4-1");
    TreeItem<String> item42 = new TreeItem<String>("Item 4-2");
    TreeItem<String> item43 = new TreeItem<String>("Item 4-3");

    // item4 に子要素を追加する
    ObservableList<TreeItem<String>> image4tChildren =
            item4.getChildren();
    image4tChildren.add(item41);
    image4tChildren.add(item42);
    image4tChildren.add(item43);

    TreeItem<String> root = new TreeItem<String>("root");
    treeView.setRoot(root);

    // ルート要素に子要素を追加する
    ObservableList<TreeItem<String>> rootChildren =
            root.getChildren();
    rootChildren.add(item1);
    rootChildren.add(item2);
    rootChildren.add(item3);
    rootChildren.add(item4);

    // 子を持つノードを開く
    root.setExpanded(true);
    item4.setExpanded(true);

    // 編集可能にする
    treeView.setEditable(true);
    treeView.setCellFactory(
            (TreeView<String> p) -> {
                TextFieldTreeCell<String> cell = new TextFieldTreeCell<String>();

                // 編集した文字列を、
                // セルが持つデータに反映させるロジックを指定。
                // 今回はテキストフィールドに入力した文字列を
                // そのままセルが持つデータとして使うので、
                // DefaultStringConverter を使用。
                cell.setConverter(new DefaultStringConverter());
                return cell;
            });
}