javafx.scene.control.cell.TextFieldTreeCell Java Examples

The following examples show how to use javafx.scene.control.cell.TextFieldTreeCell. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TextFieldTreeViewSample.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #2
Source File: RFXTreeViewTextFieldTreeCellTest.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
@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]);
}
 
Example #3
Source File: RFXTextFieldTreeCell.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example #4
Source File: ListKMLContentsSample.java    From arcgis-runtime-samples-java with Apache License 2.0 4 votes vote down vote up
@Override
public void start(Stage stage) {

  try {
    // create stack pane and application scene
    StackPane stackPane = new StackPane();
    Scene fxScene = new Scene(stackPane);

    // set title, size, and add scene to stage
    stage.setTitle("List KML Contents Sample");
    stage.setWidth(800);
    stage.setHeight(700);
    stage.setScene(fxScene);
    stage.show();

    // create a map and add it to the map view
    ArcGISScene scene = new ArcGISScene(Basemap.createImageryWithLabels());
    sceneView = new SceneView();
    sceneView.setArcGISScene(scene);

    // load a KML dataset from a local KMZ file and show it as an operational layer
    File kmzFile = new File(System.getProperty("data.dir"), "./samples-data/kml/esri_test_data.kmz");
    KmlDataset kmlDataset = new KmlDataset(kmzFile.getAbsolutePath());
    KmlLayer kmlLayer = new KmlLayer(kmlDataset);
    scene.getOperationalLayers().add(kmlLayer);

    // create a tree view to list the contents of the KML dataset
    TreeView<KmlNode> kmlTree = new TreeView<>();
    kmlTree.setMaxSize(300, 400);
    TreeItem<KmlNode> root = new TreeItem<>(null);
    kmlTree.setRoot(root);
    kmlTree.setShowRoot(false);

    // when the dataset is loaded, recursively build the tree view with KML nodes starting with the root node(s)
    kmlDataset.addDoneLoadingListener(() -> kmlDataset.getRootNodes().forEach(kmlNode -> {
      TreeItem<KmlNode> kmlNodeTreeItem = buildTree(new TreeItem<>(kmlNode));
      root.getChildren().add(kmlNodeTreeItem);
    }));

    // show the KML node in the tree view with its name and type
    kmlTree.setCellFactory(param -> new TextFieldTreeCell<>(new StringConverter<KmlNode>() {

      @Override
      public String toString(KmlNode node) {
        String type = null;
        if (node instanceof KmlDocument) {
          type = "KmlDocument";
        } else if (node instanceof KmlFolder) {
          type = "KmlFolder";
        } else if (node instanceof KmlGroundOverlay) {
          type = "KmlGroundOverlay";
        } else if (node instanceof KmlScreenOverlay) {
          type = "KmlScreenOverlay";
        } else if (node instanceof KmlPlacemark) {
            type = "KmlPlacemark";
        }
        return node.getName() + " - " + type;
      }

      @Override
      public KmlNode fromString(String string) {
        return null; //not needed
      }
    }));

    // when a tree item is selected, zoom to its node's extent (if it has one)
    kmlTree.getSelectionModel().selectedItemProperty().addListener(o -> {
      TreeItem<KmlNode> selectedTreeItem = kmlTree.getSelectionModel().getSelectedItem();
      KmlNode selectedNode = selectedTreeItem.getValue();
      Envelope nodeExtent = selectedNode.getExtent();
      if (nodeExtent != null && !nodeExtent.isEmpty()) {
        sceneView.setViewpointAsync(new Viewpoint(nodeExtent));
      }
    });

    // add the map view to stack pane
    stackPane.getChildren().addAll(sceneView, kmlTree);
    StackPane.setAlignment(kmlTree, Pos.TOP_LEFT);
    StackPane.setMargin(kmlTree, new Insets(10));
  } catch (Exception e) {
    // on any error, display the stack trace.
    e.printStackTrace();
  }
}