com.jfoenix.controls.datamodels.treetable.RecursiveTreeObject Java Examples

The following examples show how to use com.jfoenix.controls.datamodels.treetable.RecursiveTreeObject. 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: Simulator.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
/** Sets simulator text table. */
private void setSymbolTable() {
  ArrayList<String> symFiles = new ArrayList<String>(Globals.local.keySet());
  Collections.sort(symFiles);
  ObservableList<SymbolItem> list = FXCollections.observableArrayList();
  for (String file : symFiles) {
    list.add(new SymbolItem(FS.toFile(file)));
    ArrayList<SymbolItem> other = new ArrayList<>();
    for (String name : Globals.local.get(file).labels()) {
      other.add(new SymbolItem(name, Globals.local.get(file).getSymbol(name).getAddress()));
    }
    Collections.sort(other);
    other.forEach(e -> list.add(e));
  }
  Platform.runLater(() -> symbolTable.setRoot(new RecursiveTreeItem<>(list, RecursiveTreeObject::getChildren)));
}
 
Example #2
Source File: Simulator.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
/** Updates cache organization. */
private void updateCacheOrganization() {
  Platform.runLater(() -> {
    blockSize.setText(String.format("%d", program.getState().memory().cache().getBlockSize()));
    numBlocks.setText(String.format("%d", program.getState().memory().cache().getNumBlocks()));
    assoc.setText(String.format("%d", program.getState().memory().cache().getAssociativity()));
    cacheSize.setText(String.format("%d", program.getState().memory().cache().getCacheSize()));
    ObservableList<CacheItem> clist = FXCollections.observableArrayList();
    int size = program.getState().memory().cache().getNumBlocks();
    for (int i = 0; i < size; i++) {
      CacheItem item = new CacheItem(i);
      program.getState().memory().cache().addObserver(item);
      clist.add(item);
    }
    accesses.setText("0");
    hits.setText("0");
    hitRate.setText("0.00");
    cacheTable.setRoot(new RecursiveTreeItem<>(clist, RecursiveTreeObject::getChildren));
    cacheTable.refresh();
  });
}
 
Example #3
Source File: JFXTreeTableCellSkin.java    From JFoenix with Apache License 2.0 6 votes vote down vote up
private void updateDisclosureNode() {
    Node disclosureNode = ((JFXTreeTableCell<S, T>) getSkinnable()).getDisclosureNode();
    if (disclosureNode != null) {
        TreeItem<S> item = getSkinnable().getTreeTableRow().getTreeItem();
        final S value = item == null ? null : item.getValue();
        boolean disclosureVisible = value != null
                                    && !item.isLeaf()
                                    && value instanceof RecursiveTreeObject
                                    && ((RecursiveTreeObject) value).getGroupedColumn() == getSkinnable().getTableColumn();
        disclosureNode.setVisible(disclosureVisible);
        if (!disclosureVisible) {
            getChildren().remove(disclosureNode);
        } else if (disclosureNode.getParent() == null) {
            getChildren().add(disclosureNode);
            disclosureNode.toFront();
        } else {
            disclosureNode.toBack();
        }
        if (disclosureNode.getScene() != null) {
            disclosureNode.applyCss();
        }
    }
}
 
Example #4
Source File: GenericEditableTreeTableCell.java    From JFoenix with Apache License 2.0 6 votes vote down vote up
/**
 * only allows editing for items that are not grouped
 *
 * @return whether the item is grouped or not
 */
private boolean checkGroupedColumn() {
    boolean allowEdit = true;
    if (getTreeTableRow().getTreeItem() != null) {
        Object rowObject = getTreeTableRow().getTreeItem().getValue();
        if (rowObject instanceof RecursiveTreeObject && rowObject.getClass() == RecursiveTreeObject.class) {
            allowEdit = false;
        } else {
            // check grouped columns in the tableview
            if (getTableColumn() instanceof JFXTreeTableColumn && ((JFXTreeTableColumn) getTableColumn()).isGrouped()) {
                // make sure that the object is a direct child to a group node
                if (getTreeTableRow().getTreeItem().getParent() != null &&
                    getTreeTableRow().getTreeItem().getParent().getValue().getClass() == RecursiveTreeObject.class) {
                    allowEdit = false;
                }
            }
        }
    }
    return allowEdit;
}
 
Example #5
Source File: JFXTreeTableView.java    From JFoenix with Apache License 2.0 6 votes vote down vote up
@Override
public int getTreeItemLevel(TreeItem<?> node) {
    final TreeItem<?> root = getRoot();
    if (node == null) {
        return -1;
    }
    if (node == root) {
        return 0;
    }
    int level = 0;
    TreeItem<?> parent = node.getParent();
    while (parent != null) {
        level++;
        if (parent == root) {
            break;
        }
        // handle group nodes
        if (parent.getValue() != null
            && parent.getValue() instanceof RecursiveTreeObject
            && ((RecursiveTreeObject<?>) parent.getValue()).getGroupedColumn() != null) {
            level--;
        }
        parent = parent.getParent();
    }
    return level;
}
 
Example #6
Source File: DetailPCController.java    From FlyingAgent with Apache License 2.0 5 votes vote down vote up
private void loadDataToNetworkTable(NetworkInformation networkInformation) {
    ObservableList<NetworkTable> networkTableData = FXCollections.observableArrayList();

    /* This data add below just for testing */
    for (Network network : networkInformation.getNetworkList()) {
        networkTableData.add(new NetworkTable(network.getName(), network.getIpAddress(), network.getMacAddress()));
    }

    TreeItem treeItem = new RecursiveTreeItem<>(networkTableData, RecursiveTreeObject::getChildren);
    try {
        tableNetwork.setRoot(treeItem);
    } catch (Exception e) {
        System.err.println("Exception in tree item of network table !");
    }
}
 
Example #7
Source File: ScanAllController.java    From FlyingAgent with Apache License 2.0 5 votes vote down vote up
private void loadDataToNetworkTable(NetworkInformation networkInformation) {
    ObservableList<NetworkTable> networkTableData = FXCollections.observableArrayList();

    /* This data add below just for testing */
    for (Network network : networkInformation.getNetworkList()) {
        networkTableData.add(new NetworkTable(network.getName(), network.getIpAddress(), network.getMacAddress()));
    }

    TreeItem treeItem = new RecursiveTreeItem<>(networkTableData, RecursiveTreeObject::getChildren);
    try {
        tableNetwork.setRoot(treeItem);
    } catch (Exception e) {
        System.err.println("Exception in tree item of network table !");
    }
}
 
Example #8
Source File: RecursiveTreeItem.java    From JFoenix with Apache License 2.0 5 votes vote down vote up
/**
 * creates recursive tree item from a data list
 *
 * @param dataList of values
 * @param func     is the callback used to retrieve the children of the current tree item
 */
public RecursiveTreeItem(ObservableList<T> dataList, Callback<RecursiveTreeObject<T>, ObservableList<T>> func) {
    RecursiveTreeObject<T> root = new RecursiveTreeObject<>();
    root.setChildren(dataList);
    this.childrenFactory = func;
    init(root);
}
 
Example #9
Source File: JFXTreeTableColumn.java    From JFoenix with Apache License 2.0 5 votes vote down vote up
/**
 * validates the value of the tree item,
 * this method also hides the column value for the grouped nodes
 *
 * @param param tree item
 * @return true if the value is valid else false
 */
public final boolean validateValue(CellDataFeatures<S, T> param) {
    Object rowObject = param.getValue().getValue();
    return !((rowObject instanceof RecursiveTreeObject && rowObject.getClass() == RecursiveTreeObject.class)
             || (param.getTreeTableView() instanceof JFXTreeTableView
                 && ((JFXTreeTableView<?>) param.getTreeTableView()).getGroupOrder().contains(this)
                 // make sure the node is a direct child to a group node
                 && param.getValue().getParent() != null
                 && param.getValue().getParent().getValue() != null
                 && param.getValue().getParent().getValue().getClass() == RecursiveTreeObject.class
             ));
}
 
Example #10
Source File: JFXTreeTableColumn.java    From JFoenix with Apache License 2.0 5 votes vote down vote up
/**
 * @param param tree item
 * @return the data represented by the tree item
 */
public final ObservableValue<T> getComputedValue(CellDataFeatures<S, T> param) {
    Object rowObject = param.getValue().getValue();
    if (rowObject instanceof RecursiveTreeObject) {
        RecursiveTreeObject<?> item = (RecursiveTreeObject<?>) rowObject;
        if (item.getGroupedColumn() == this) {
            return new ReadOnlyObjectWrapper(item.getGroupedValue());
        }
    }
    return null;
}
 
Example #11
Source File: JFXTreeTableView.java    From JFoenix with Apache License 2.0 4 votes vote down vote up
private void buildGroupedRoot(Map<?, ?> groupedItems, RecursiveTreeItem parent, int groupIndex) {
    boolean setRoot = false;
    if (parent == null) {
        parent = new RecursiveTreeItem<>(new RecursiveTreeObject(), RecursiveTreeObject::getChildren);
        setRoot = true;
    }

    for (Map.Entry<?, ?> entry : groupedItems.entrySet()) {
        Object key = entry.getKey();
        RecursiveTreeObject groupItem = new RecursiveTreeObject<>();
        groupItem.setGroupedValue(key);
        groupItem.setGroupedColumn(groupOrder.get(groupIndex));

        RecursiveTreeItem node = new RecursiveTreeItem<>(groupItem, RecursiveTreeObject::getChildren);
        // TODO: need to be removed once the selection issue is fixed
        node.expandedProperty().addListener((o, oldVal, newVal) -> {
            getSelectionModel().clearSelection();
        });

        parent.originalItems.add(node);
        parent.getChildren().add(node);

        Object children = entry.getValue();
        if (children instanceof List) {
            node.originalItems.addAll((List) children);
            node.getChildren().addAll((List) children);
        } else if (children instanceof Map) {
            buildGroupedRoot((Map) children, node, groupIndex + 1);
        }
        groupItem.setChildren(node.getChildren());
        if (groupedRootConsumer != null) {
            groupedRootConsumer.accept(key, groupItem);
        }
    }

    // update ui
    if (setRoot) {
        final RecursiveTreeItem<S> newParent = parent;
        JFXUtilities.runInFX(() -> {
            ArrayList<TreeTableColumn<S, ?>> sortOrder = new ArrayList<>();
            sortOrder.addAll(getSortOrder());
            internalSetRoot = true;
            setRoot(newParent);
            internalSetRoot = false;
            getSortOrder().addAll(sortOrder);
            getSelectionModel().select(0);
        });
    }
}
 
Example #12
Source File: JfxTableEditor.java    From milkman with MIT License 4 votes vote down vote up
public void setItems(List<T> items, Comparator<T> comparator) {
		List<RecursiveWrapper<T>> wrappedItems = items.stream().map(i -> new RecursiveWrapper<>(i)).collect(Collectors.toList());
		obsWrappedItems = FXCollections.observableList(wrappedItems);
		if (comparator != null) {
			FXCollections.sort(obsWrappedItems, (ra, rb) -> comparator.compare(ra.getData(), rb.getData()));
		}
		
		
		obsWrappedItems.addListener(new ListChangeListener<RecursiveWrapper<T>>() {

			@Override
			public void onChanged(Change<? extends RecursiveWrapper<T>> c) {
				//forward removals:
				if (!c.next())
					return;
				
				if (c.wasRemoved()) {
					for(var ri : c.getRemoved()) {
						items.remove(ri.getData());
					}
				}
				
				if (c.wasAdded()) {
					RecursiveWrapper<T> newEntry = c.getAddedSubList().get(0);
					items.add(newEntry.getData());
				}
			}
		});
		
		final TreeItem<RecursiveWrapper<T>> root = new RecursiveTreeItem<>(obsWrappedItems, RecursiveTreeObject::getChildren); 
		table.setRoot(root);
		
		Platform.runLater(() -> {
			table.resizeColumns();
		});
		
		//register double-click listener for empty rows, to add a new instance
//		this.setRowFactory(view -> {
//		    TableRow<T> row = new TableRow<T>();
//		    row.setOnMouseClicked(event -> {
//			    if (row.isEmpty() && (event.getClickCount() == 2)) {
//			        T myItem = newItemCreator.get();
//			        getItems().add(myItem);
//			    } 
//			});
//		    return row;
//		});
		
		//we cant click on row if there is no row, so we have to register another event handler
		//for when the table is empty
//		this.setOnMouseClicked(event -> {
//		    if (getItems().isEmpty() && (event.getClickCount() == 2)) {
//		        T myItem = newItemCreator.get();
//		        getItems().add(myItem);
//		    } 
//		});
		
	}
 
Example #13
Source File: JFXTreeTableView.java    From JFoenix with Apache License 2.0 4 votes vote down vote up
public void setGroupedRootConsumer(BiConsumer<Object, RecursiveTreeObject> groupedRootConsumer) {
    this.groupedRootConsumer = groupedRootConsumer;
}
 
Example #14
Source File: JFXTreeTableView.java    From JFoenix with Apache License 2.0 4 votes vote down vote up
public BiConsumer<Object, RecursiveTreeObject> getGroupedRootConsumer() {
    return groupedRootConsumer;
}
 
Example #15
Source File: JFXTreeTableRow.java    From JFoenix with Apache License 2.0 4 votes vote down vote up
protected boolean isGroupItem(T item) {
    return item != null && item instanceof RecursiveTreeObject
           && item.getClass() == RecursiveTreeObject.class;
}
 
Example #16
Source File: RecursiveTreeItem.java    From JFoenix with Apache License 2.0 4 votes vote down vote up
private void init(RecursiveTreeObject<T> value) {

        addChildrenListener(value);

        valueProperty().addListener(observable -> {
            if (getValue() != null) {
                addChildrenListener(getValue());
            }
        });

        predicate.addListener(observable -> {
            filteredItems.setPredicate(child -> {
                // Set the predicate of child items to force filtering
                if (child instanceof RecursiveTreeItem) {
                    if (!((RecursiveTreeItem) child).originalItems.isEmpty()) {
                        RecursiveTreeItem<T> filterableChild = (RecursiveTreeItem<T>) child;
                        filterableChild.setPredicate(predicate.get());
                    }
                }
                // If there is no predicate, keep this tree item
                if (predicate.get() == null) {
                    return true;
                }
                // If there are children, keep this tree item
                if (child.getChildren().size() > 0) {
                    return true;
                }
                // If its a group node keep this item if it has children
                if (child.getValue() instanceof RecursiveTreeObject &&
                    child.getValue().getClass() == RecursiveTreeObject.class) {
                    return child.getChildren().size() != 0;
                }
                // Otherwise ask the TreeItemPredicate
                return predicate.get().test(child);
            });
        });

        this.filteredItems.predicateProperty().addListener(observable ->
            JFXUtilities.runInFXAndWait(() -> {
                getChildren().clear();
                getChildren().setAll(filteredItems);
            }));
    }
 
Example #17
Source File: Simulator.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
/** Sets simulator text table. */
private void setText() {
  tlist = FXCollections.observableArrayList();
  int pc = Data.TEXT;
  for (Statement stmt : program.statements()) {
    int code = stmt.code().bits();
    String basic = Globals.iset.get(stmt.mnemonic()).disassemble(stmt.code());
    // get source line
    String source = null;
    File file = stmt.getFile();
    int line = stmt.getLine();
    if (line > 0) {
      try {
        // get source from file
        source = FS.getLine(file, line);
        // use basic code if necessary
        source = (source == null) ? basic : source;
        // remove comments
        source = source.replaceAll("[;#].*", "");
        // normalize whitespace (tabs, spaces)
        source = source.replaceAll("( |\t)+", " ");
        // normalize commas
        source = source.replaceAll("( )?,( )?", ", ");
        // remove labels
        source = source.replaceAll("[a-zA-Z_]([a-zA-Z0-9_]*(\\.[a-zA-Z0-9_]+)?):", "");
        // trim whitespace
        source = source.trim();
      } catch (IOException e) {
        source = basic;
      }
    } else {
      source = basic;
    }
    boolean bkpt = basic.indexOf("ebreak") >= 0;
    StatementItem item = new StatementItem(bkpt, pc, code, basic, source);
    tlist.add(item);
    if (bkpt) {
      breakpoints.put(pc, true);
    } else {
      final int addr = pc;
      item.bkptProperty().addListener((e, o, n) -> {
        if (n) {
          breakpoints.put(addr, true);
        } else {
          breakpoints.remove(addr);
        }
      });
    }
    pc += Data.WORD_LENGTH;
  }
  Platform.runLater(() -> textTable.setRoot(new RecursiveTreeItem<>(tlist, RecursiveTreeObject::getChildren)));
}
 
Example #18
Source File: RecursiveTreeItem.java    From JFoenix with Apache License 2.0 2 votes vote down vote up
/**
 * creates recursive tree item for a specified value and a graphic node
 *
 * @param value   of the tree item
 * @param graphic node
 * @param func    is the callback used to retrieve the children of the current tree item
 */
public RecursiveTreeItem(final T value, Node graphic, Callback<RecursiveTreeObject<T>, ObservableList<T>> func) {
    super(value, graphic);
    this.childrenFactory = func;
    init(value);
}
 
Example #19
Source File: RecursiveTreeItem.java    From JFoenix with Apache License 2.0 2 votes vote down vote up
/**
 * creates recursive tree item for a specified value
 *
 * @param value of the tree item
 * @param func  is the callback used to retrieve the children of the current tree item
 */
public RecursiveTreeItem(final T value, Callback<RecursiveTreeObject<T>, ObservableList<T>> func) {
    this(value, null, func);
}
 
Example #20
Source File: RecursiveTreeItem.java    From JFoenix with Apache License 2.0 2 votes vote down vote up
/**
 * creates empty recursive tree item
 *
 * @param func is the callback used to retrieve the children of the current tree item
 */
public RecursiveTreeItem(Callback<RecursiveTreeObject<T>, ObservableList<T>> func) {
    this(null, null, func);
}