protected Point2D getPoint(TreeTableView<?> treeTableView, int rowIndex, int columnIndex) { Set<Node> treeTableRowCell = treeTableView.lookupAll(".tree-table-row-cell"); TreeTableRow<?> row = null; for (Node tableRow : treeTableRowCell) { TreeTableRow<?> r = (TreeTableRow<?>) tableRow; if (r.getIndex() == rowIndex) { row = r; break; } } Set<Node> cells = row.lookupAll(".tree-table-cell"); for (Node node : cells) { TreeTableCell<?, ?> cell = (TreeTableCell<?, ?>) node; if (treeTableView.getColumns().indexOf(cell.getTableColumn()) == columnIndex) { Bounds bounds = cell.getBoundsInParent(); Point2D localToParent = cell.localToParent(bounds.getWidth() / 2, bounds.getHeight() / 2); Point2D rowLocal = row.localToScene(localToParent, true); return rowLocal; } } return null; }
protected void handleRowDragDropped(TreeTableRow<T> r, DragEvent ev) { Dragboard db = ev.getDragboard(); if(isAcceptable(db, r)) { int ix = (Integer)db.getContent(JAVA_DATA_FORMAT); TreeItem item = tree.getTreeItem(ix); item.getParent().getChildren().remove(item); getTarget(r).getChildren().add(item); ev.setDropCompleted(true); tree.getSelectionModel().clearSelection(); tree.getSelectionModel().select(item); // FIX focus and selection differ after this ev.consume(); } }
private void onDragOver(final TreeTableRow<GPXLineItem> row, final DragEvent event) { Dragboard db = event.getDragboard(); if (db.getContent(SERIALIZED_MIME_TYPE) != null) { if (!row.isEmpty()) { event.acceptTransferModes(TransferMode.COPY_OR_MOVE); event.consume(); } } else { if (db.hasFiles()) { for (File file:db.getFiles()) { // accept only gpx files if (GPXEditorWorker.GPX_EXT.equals(FilenameUtils.getExtension(file.getName()).toLowerCase())) { event.acceptTransferModes(TransferMode.COPY_OR_MOVE); break; } } } else { event.consume(); } } }
private boolean acceptable(final Dragboard db, final TreeTableRow<GPXLineItem> row) { boolean result = false; if (db.hasContent(SERIALIZED_MIME_TYPE)) { final int index = (Integer) db.getContent(SERIALIZED_MIME_TYPE); //System.out.println("index: " + index + ", row index:" + row.getIndex()); if (!row.isEmpty() && (row.getIndex() != index)) { final TreeItem<GPXLineItem> target = row.getTreeItem(); final GPXLineItem.GPXLineItemType targetType = target.getValue().getType(); final TreeItem<GPXLineItem> item = myTreeTableView.getTreeItem(index); final GPXLineItem.GPXLineItemType itemType = item.getValue().getType(); // don't create loops and only insert on same level or drop on direct parent type result = !isParent(item, target) && (GPXLineItem.GPXLineItemType.isSameTypeAs(targetType, itemType) || GPXLineItem.GPXLineItemType.isParentTypeOf(targetType, itemType)); } } return result; }
/** * Helper method which provides extra logic for extracting the {@link TreeItem} {@link Property} from a * {@link TreeTableCell}, which itself has no {@link TreeItem} property. The {@link TreeItem} {@link Property} we * want to bind can be found in the containing {@link TreeTableRow} instead. * <p> * * @param <T> the type of the item contained in the {@link TreeTableRow} * @param appCtx the {@link ApplicationContext} of the application * @param ctxMenuProperty the {@link ContextMenu} {@link Property} of the {@link TreeTableCell} * @param tableRowProperty the {@link TreeTableRow} {@link Property} of the {@link TreeTableCell} */ private static <T> void bindContextMenuForTreeTableCell(ApplicationContext appCtx, ObjectProperty<ContextMenu> ctxMenuProperty, ReadOnlyObjectProperty<TreeTableRow<T>> tableRowProperty) { tableRowProperty.addListener((property, oldValue, newValue) -> { // If the containing TreeTableRow disappears, unbind the context menu if any if (newValue == null) { ctxMenuProperty.unbind(); return; } // Otherwise, bind the ContextMenu to the TreeItem Property of the containing TreeTable row. bindContextMenu(appCtx, ctxMenuProperty, newValue.treeItemProperty()); }); }
@SuppressWarnings("rawtypes") public TreeTableCell getVisibleCellAt(TreeTableView<?> treeTableView, int row, int column) { Set<Node> lookupAll = getTreeTableCells(treeTableView); TreeTableCell cell = null; for (Node node : lookupAll) { TreeTableCell<?, ?> cell1 = (TreeTableCell<?, ?>) node; TreeTableRow<?> tableRow = cell1.getTreeTableRow(); TreeTableColumn<?, ?> tableColumn = cell1.getTableColumn(); if (tableRow.getIndex() == row && tableColumn == treeTableView.getColumns().get(column)) { cell = cell1; break; } } return cell; }
private void makeSourceRowDraggable(TreeTableRow<? extends SourceEntry> row) { row.setOnDragDetected(event -> { if (selectedEntry == null) { return; } Dragboard dragboard = row.startDragAndDrop(TransferMode.COPY_OR_MOVE); ClipboardContent content = new ClipboardContent(); content.put(DataFormats.source, selectedEntry); dragboard.setContent(content); event.consume(); }); }
private void updateRowStyle(TreeTableRow<T> row) { if (row.getItem() == null) { return; } switch (row.getItem().getNodeClass()) { case Variable: row.pseudoClassStateChanged(OBJECT_CLASS, false); row.pseudoClassStateChanged(METHOD_CLASS, false); row.pseudoClassStateChanged(VARIABLE_CLASS, true); break; case Object: row.pseudoClassStateChanged(VARIABLE_CLASS, false); row.pseudoClassStateChanged(METHOD_CLASS, false); row.pseudoClassStateChanged(OBJECT_CLASS, true); break; case Method: row.pseudoClassStateChanged(VARIABLE_CLASS, false); row.pseudoClassStateChanged(OBJECT_CLASS, false); row.pseudoClassStateChanged(METHOD_CLASS, true); break; default: row.pseudoClassStateChanged(VARIABLE_CLASS, false); row.pseudoClassStateChanged(METHOD_CLASS, false); row.pseudoClassStateChanged(OBJECT_CLASS, false); break; } }
public final Wrap<? extends Node> getNode() { return treeTableViewWrap.as(Parent.class, Node.class). lookup(TreeTableRow.class, new LookupCriteria<TreeTableRow>() { @Override public boolean check(TreeTableRow cntrl) { return cntrl.getItem() != null && cntrl.getTreeItem().equals(getControl()); } @Override public String toString() { return "Node for an item " + getControl().toString(); } }).wrap(); }
protected TreeTableRow<T> rowFactory(TreeTableView<T> view) { TreeTableRow<T> r = new TreeTableRow<T>(); r.addEventHandler(MouseEvent.DRAG_DETECTED, (ev) -> handleRowDragDetected(r, ev)); r.addEventHandler(DragEvent.DRAG_OVER, (ev) -> handleRowDragOver(r, ev)); r.addEventHandler(DragEvent.DRAG_DROPPED, (ev) -> handleRowDragDropped(r, ev)); return r; }
protected boolean isAcceptable(Dragboard db, TreeTableRow<T> row) { if(db.hasContent(JAVA_DATA_FORMAT)) { int index = (Integer)db.getContent(JAVA_DATA_FORMAT); if(row.getIndex() != index) { TreeItem target = getTarget(row); TreeItem item = tree.getTreeItem(index); return !isParent(item, target); } } return false; }
protected TreeItem getTarget(TreeTableRow<T> row) { TreeItem target = tree.getRoot(); if(!row.isEmpty()) { target = row.getTreeItem(); } return target; }
protected void handleRowDragDetected(TreeTableRow<T> r, MouseEvent ev) { if(!r.isEmpty()) { // TODO support multiple selection Dragboard db = r.startDragAndDrop(TransferMode.MOVE); db.setDragView(r.snapshot(null, null)); ClipboardContent cc = new ClipboardContent(); cc.put(JAVA_DATA_FORMAT, r.getIndex()); db.setContent(cc); ev.consume(); } }
protected void handleRowDragOver(TreeTableRow<T> r, DragEvent ev) { Dragboard db = ev.getDragboard(); if(isAcceptable(db, r)) { ev.acceptTransferModes(TransferMode.COPY_OR_MOVE); ev.consume(); } }
/** * Handle mouse clicked event */ private void handleMouseClickedEvent() { TreeTableRow<HexData> selectedRow = (TreeTableRow<HexData>) textField.getParent().getParent(); if (!selectedRow.getTreeItem().getValue().getOffset().contains("-")) { String originalLine = textField.getText(); String selectedHex = textField.getSelectedText().trim(); String replacedHex = showDialog(selectedHex); if (replacedHex != null) { try { textField.replaceSelection(replacedHex.toUpperCase()); String payLoad = hexToASCII(textField.getText()); TreeTableRow<HexData> hexTable = (TreeTableRow<HexData>) textField.getParent().getParent(); TreeItem<HexData> selectedItem = hexTable.getTreeItem(); selectedItem.setValue(new HexData(selectedItem.getValue().getOffset(), textField.getText(), packetParser.formatPayLoad(payLoad))); String originalHex = getPacketHexFromList(); if (selectedItem.getValue().getOffset().contains("-")) { originalHex = originalHex.replaceAll(originalLine.replaceAll(" ", "").replaceAll("\n", ""), textField.getText().replaceAll(" ", "").replaceAll("\n", "")); } byte[] rawdata = DatatypeConverter.parseHexBinary(originalHex); EthernetPacket p = EthernetPacket.newPacket(rawdata, 0, rawdata.length); packetParser.parsePacket(p, packetInfo); treeRoot.getChildren().clear(); setData(packetInfo); } catch (IllegalRawDataException ex) { java.util.logging.Logger.getLogger(PacketHex.class.getName()).log(Level.SEVERE, null, ex); } } } }
/** * Returns a <code>Tab</code> containing a <code>TreeTableView</code> displaying the with the given * <code>root</code>. * * @param root * the root of the tree to display * @return a <code>Tab</code> containing the tree */ static Tab getTreeTableViewTab(TreeItem<TreeDumpNode> root) { TreeTableView<TreeDumpNode> tableView = new TreeTableView<>(root); TreeTableColumn<TreeDumpNode, String> id = new TreeTableColumn<>("ID"); TreeTableColumn<TreeDumpNode, String> label = new TreeTableColumn<>("AST Type"); tableView.setRowFactory(param -> { TreeTableRow<TreeDumpNode> row = new TreeTableRow<>(); TreeDumpNode node = row.getItem(); if (node == null) { return row; } String color = node.getFillColor(); if (color != null) { try { BackgroundFill fill = new BackgroundFill(Color.valueOf(color), CornerRadii.EMPTY, Insets.EMPTY); row.setBackground(new Background(fill)); } catch (IllegalArgumentException e) { LOG.fine(() -> String.format("Could not convert '%s' to a JavaFX Color.", color)); } } return row; }); id.setCellValueFactory(param -> param.getValue().getValue().idProperty()); label.setCellValueFactory(param -> param.getValue().getValue().labelProperty()); tableView.getColumns().setAll(Arrays.asList(label, id)); return new Tab("Tree View", tableView); }
public JFXTreeTableRowSkin(TreeTableRow<T> control) { super(control); if (disclosureWidthMap == null) { try { Field declaredField = getClass().getSuperclass() .getSuperclass() .getDeclaredField("maxDisclosureWidthMap"); declaredField.setAccessible(true); disclosureWidthMap = (Map<Control, Double>) declaredField.get(this); } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException ex) { ex.printStackTrace(); } } getSkinnable().indexProperty().addListener((o, oldVal, newVal) -> { if (newVal.intValue() != -1) { if (newVal.intValue() == expandedIndex) { expandTriggered = true; expandedIndex = -1; } else { expandTriggered = false; } } }); // clear disclosure node indentation after grouping/ungrouping getSkinnable().getTreeTableView().rootProperty().addListener((o, oldVal, newVal) -> { disclosureWidthMap.remove(getSkinnable().getTreeTableView()); }); }
@Override public TreeTableRow<IResource> call(TreeTableView<IResource> param) { TreeTableRow<IResource> row = new TreeTableRow<IResource>() { @Override protected void updateItem(IResource resource, boolean empty) { super.updateItem(resource, empty); if (empty) { this.setTooltip(null); } else { /* Tooltip & Context Menu */ TooltipFactory<IResource> tooltipFactory = new ResourceTooltipFactory(); ResourceContextMenu resourceContextMenu = new ResourceContextMenu(controller.getProject(), resource, controller); this.setTooltip(tooltipFactory.createTooltip(resource)); resourceContextMenu.initMenus(); this.setContextMenu(resourceContextMenu); } } }; /* Drag & Drop */ row.setOnDragDetected(event -> dragAndDrop.dragDetected(event, row)); row.setOnDragOver(event -> dragAndDrop.dragOver(event, row)); row.setOnDragDropped(event -> dragAndDrop.dragDropped(event, row)); /* Properties double-click */ row.setOnMouseClicked(this::handleDoubleClick); return row; }
@Override public TreeTableRow<ITask> call(TreeTableView<ITask> param) { TreeTableRow<ITask> row = new TreeTableRow<ITask>() { @Override protected void updateItem(ITask task, boolean empty) { super.updateItem(task, empty); if (empty) { this.setTooltip(null); this.setContextMenu(null); } else { /* Tooltip & Context Menu */ TooltipFactory<ITask> tooltipFactory = new TaskTooltipFactory(); TaskContextMenu taskContextMenu = new TaskContextMenu(controller.getProject(), task, controller); this.setTooltip(tooltipFactory.createTooltip(task)); taskContextMenu.initMenus(); this.setContextMenu(taskContextMenu); } } }; /* Drag & Drop */ row.setOnDragDetected(event -> dragAndDrop.dragDetected(event, row)); row.setOnDragOver(event -> dragAndDrop.dragOver(event, row)); row.setOnDragDropped(event -> dragAndDrop.dragDropped(event, row)); /* Properties double-click */ row.setOnMouseClicked(this::handleDoubleClick); return row; }
@Override public void dragDropped(DragEvent event, TreeTableRow row) { Dragboard dragboard = event.getDragboard(); if (dragboard.hasContent(SERIALIZED_MIME_TYPE)) { int draggedIndex = (Integer) dragboard.getContent(SERIALIZED_MIME_TYPE); controller.getCommandExecutor().execute(new DragNDropResourceCommand(controller.getProject(), row, draggedIndex)); event.setDropCompleted(true); row.getTreeTableView().getSelectionModel().select(row.getIndex()); event.consume(); } }
public void dragDetected(MouseEvent event, TreeTableRow<?> row) { if (!row.isEmpty()) { Dragboard dragboard = row.startDragAndDrop(TransferMode.MOVE); dragboard.setDragView(row.snapshot(null, null)); ClipboardContent content = new ClipboardContent(); content.put(SERIALIZED_MIME_TYPE, row.getIndex()); dragboard.setContent(content); event.consume(); } }
public void dragOver(DragEvent event, TreeTableRow row) { Dragboard dragboard = event.getDragboard(); if (dragboard.hasContent(SERIALIZED_MIME_TYPE)) { if (row.getIndex() != (Integer) dragboard.getContent(SERIALIZED_MIME_TYPE)) { event.acceptTransferModes(TransferMode.COPY_OR_MOVE); event.consume(); } } }
@Override public void dragDropped(DragEvent event, TreeTableRow row) { Dragboard db = event.getDragboard(); if (db.hasContent(SERIALIZED_MIME_TYPE)) { int draggedIndex = (Integer) db.getContent(SERIALIZED_MIME_TYPE); controller.getCommandExecutor().execute(new DragNDropTaskCommand(controller.getProject(), row, draggedIndex)); event.setDropCompleted(true); row.getTreeTableView().getSelectionModel().select(row.getIndex()); event.consume(); } }
@Test public void testGetTreeTableRowAdjuster() { Adjuster adjuster = Adjuster.getAdjuster(TreeTableRow.class); assertThat(adjuster, is(instanceOf(ControlAdjuster.class))); assertThat(adjuster.getNodeClass(), is(sameInstance(Control.class))); }
/** * Determines where the mouse is in the given row. */ private DroppingMouseLocation getDroppingMouseLocation(TreeTableRow<GroupNodeViewModel> row, DragEvent event) { if ((row.getHeight() * 0.25) > event.getY()) { return DroppingMouseLocation.TOP; } else if ((row.getHeight() * 0.75) < event.getY()) { return DroppingMouseLocation.BOTTOM; } else { return DroppingMouseLocation.CENTER; } }
/** * Sets up UI components to represent the sources that a plugin defines. */ private void setup(Plugin plugin) { plugin.getSourceTypes().forEach(sourceType -> { SourceTreeTable<SourceEntry, ?> tree = new SourceTreeTable<>(); tree.setSourceType(sourceType); tree.setRoot(new TreeItem<>(sourceType.createRootSourceEntry())); tree.setShowRoot(false); tree.setSortPolicy(__ -> { sortTree(tree.getRoot()); return true; }); tree.getSelectionModel().selectedItemProperty().addListener((__, oldItem, newItem) -> { selectedEntry = newItem == null ? null : newItem.getValue(); }); tree.setRowFactory(__ -> { TreeTableRow<SourceEntry> row = new TreeTableRow<>(); makeSourceRowDraggable(row); return row; }); tree.setOnContextMenuRequested(e -> { TreeItem<SourceEntry> selectedItem = tree.getSelectionModel().getSelectedItem(); if (selectedItem == null) { return; } DataSource<?> source = selectedItem.getValue().get(); List<String> componentNames = Components.getDefault().componentNamesForSource(source); if (componentNames.isEmpty()) { // No known components that can show this data return; } ContextMenu menu = new ContextMenu(); componentNames.stream() .map(name -> createShowAsMenuItem(name, source)) .forEach(menu.getItems()::add); menu.show(tree.getScene().getWindow(), e.getScreenX(), e.getScreenY()); }); sourceType.getAvailableSources().addListener((MapChangeListener<String, Object>) change -> { SourceEntry entry = sourceType.createSourceEntryForUri(change.getKey()); if (change.wasAdded()) { tree.updateEntry(entry); } else if (change.wasRemoved()) { tree.removeEntry(entry); } }); sourceType.getAvailableSourceUris().stream() .map(sourceType::createSourceEntryForUri) .forEach(tree::updateEntry); TitledPane titledPane = new TitledPane(sourceType.getName(), tree); sourcePanes.put(plugin, titledPane); sourcesAccordion.getPanes().add(titledPane); sourcesAccordion.setExpandedPane(titledPane); }); // Add widgets to the gallery as well widgetGallery.setWidgets(Components.getDefault().allWidgets().collect(Collectors.toList())); }
@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); } } }); }
public DataTreeNodeRowFactory(Callback<TreeTableView<T>, TreeTableRow<T>> callbackFactory) { this.callbackFactory = callbackFactory; this.subscribedItems = FXCollections.observableSet(new HashSet<T>()); }
private void scrollTo() { TableUtils.scrollToInSingleDimension(treeTableViewWrap, TreeTableRow.class, (TreeTableRow p) -> treeTableViewWrap.getRow(p.getTreeItem()), treeTableViewWrap.getRow(getControl()), treeTableViewWrap.as(Scroll.class).caret(), true); }
public IndexedCell getTreeCell(TreeItem item) { return (TreeTableRow) new TreeTableNodeWrap<>(item, new TreeTableItemWrap<>(Object.class, item, this, null), this, null).getNode().getControl(); }
private void onDragDropped(final TreeTableRow<GPXLineItem> row, final DragEvent event) { Dragboard db = event.getDragboard(); if (db.getContent(SERIALIZED_MIME_TYPE) != null) { if (acceptable(db, row)) { // get dragged item and item drop on to final int draggedIndex = (Integer) db.getContent(SERIALIZED_MIME_TYPE); final int targetIndex = row.getIndex(); final TreeItem<GPXLineItem> draggedItem = myTreeTableView.getTreeItem(draggedIndex); final TreeItem<GPXLineItem> targetItem = myTreeTableView.getTreeItem(targetIndex); final GPXLineItem draggedLineItem = draggedItem.getValue(); final GPXLineItem targetLineItem = targetItem.getValue(); final GPXLineItem.GPXLineItemType draggedType = draggedLineItem.getType(); final GPXLineItem.GPXLineItemType targetType = targetLineItem.getType(); draggedItem.getParent().getChildren().remove(draggedItem); final List<GPXLineItem> draggedList = draggedLineItem.getParent().getChildren(); draggedList.remove(draggedLineItem); draggedLineItem.getParent().setChildren(draggedList); List<GPXLineItem> targetList; if (GPXLineItem.GPXLineItemType.isSameTypeAs(targetType, draggedType)) { // index of dropped item under its parent - thats where we want to place the dragged item before final int childIndex = targetItem.getParent().getChildren().indexOf(targetItem); targetItem.getParent().getChildren().add(childIndex, draggedItem); // update GPXLineItem as well targetList = targetLineItem.getParent().getChildren(); targetList.add(childIndex, draggedLineItem); targetLineItem.getParent().setChildren(targetList); } else { // droppped on parent type - always add in front targetItem.getChildren().add(0, draggedItem); // update GPXLineItem as well targetList = targetLineItem.getChildren(); targetList.add(0, draggedLineItem); targetLineItem.setChildren(targetList); } event.setDropCompleted(true); myTreeTableView.getSelectionModel().clearSelection(); myTreeTableView.getSelectionModel().select(draggedItem); myTreeTableView.refresh(); event.consume(); } } else { boolean success = false; if (db.hasFiles()) { success = true; final List<File> files = new ArrayList<>(); for (File file:db.getFiles()) { // accept only gpx files if (GPXEditorWorker.GPX_EXT.equals(FilenameUtils.getExtension(file.getName()).toLowerCase())) { files.add(file); } } // read and add to list myEditor.parseAndAddFiles(files); } event.setDropCompleted(success); event.consume(); } }
public DragNDropResourceCommand(IProject project, TreeTableRow<IResource> row, int draggedIndex) { this.project = project; this.row = row; this.draggedIndex = draggedIndex; }
public DragNDropTaskCommand(IProject project, TreeTableRow<ITask> row, int draggedIndex) { this.project = project; this.row = row; this.draggedIndex = draggedIndex; }
private static void removePseudoClasses(TreeTableRow<GroupNodeViewModel> row, PseudoClass... pseudoClasses) { for (PseudoClass pseudoClass : pseudoClasses) { row.pseudoClassStateChanged(pseudoClass, false); } }
public abstract void dragDropped(DragEvent event, TreeTableRow row);