use of javafx.scene.control.TreeItem in project honest-profiler by jvm-profiling-tools.
the class ContextMenuUtil method getContextMenu.
/**
* Constructs the {@link ContextMenu} for a {@link TreeItem}.
* <p>
* Based on the type of the Object contained in the {@link TreeItem}, menu options can be added.
* <p>
* The following options are always provided : Expand All (selected node and all its descendants), Expand First Only
* (recursively expand only the first child) and Collapse All (collapse the entire subtree).
* <p>
* For {@link Node}s, the menu will (when fixed) add an Export To File option.
* <p>
*
* @param <T> the type of the item contained in the {@link TreeItem}
* @param appCtx the {@link ApplicationContext} of the application
* @param treeItem the {@link TreeItem} for which the {@link ContextMenu} is constructed
* @return the constructed {@link ContextMenu}
*/
private static <T> ContextMenu getContextMenu(ApplicationContext appCtx, TreeItem<T> treeItem) {
ContextMenu menu = new ContextMenu();
addMenuItem(menu.getItems(), appCtx.textFor(CTXMENU_TREE_EXPANDFULLY), info -> expandFully(treeItem));
addMenuItem(menu.getItems(), appCtx.textFor(CTXMENU_TREE_EXPANDFIRSTONLY), info -> expandFirstOnly(treeItem));
addMenuItem(menu.getItems(), appCtx.textFor(CTXMENU_TREE_COLLAPSE), info -> collapseFully(treeItem));
// TODO FIX - ProfileNodes are no longer used.
if (treeItem.getValue() instanceof Node) {
addMenuItem(menu.getItems(), appCtx.textFor(CTXMENU_TREE_EXPORTSUBTREE), info -> showExportDialog(appCtx, menu.getScene().getWindow(), "stack_profile.txt", out -> writeStack(out, (Node) treeItem.getValue())));
}
return menu;
}
use of javafx.scene.control.TreeItem in project assembly64fx by freabemania.
the class Main method refreshTree.
public static void refreshTree() {
Platform.runLater(new Runnable() {
@Override
public void run() {
try {
ProgressbarEnhanced progressBar = (ProgressbarEnhanced) GlobalRepoService.getInstance().get("pbar");
if (progressBar != null) {
topContainer.getChildren().remove(progressBar);
}
rootItemBase.getChildren().clear();
for (WorkLocation location : userService.getLocations()) {
List<Artifact> artifactsDb = artifactsService.getArtifactsDb();
Set<LatestInstalledItemInfo> lastestAdditions = null;
if (location.exists()) {
lastestAdditions = InstallationService.getInstance().resolveLatestInstalledByLocation(location.toLocationAndInstallation());
} else {
lastestAdditions = lastestAdditionsNotFound;
}
ImageView icon = new ImageView();
icon.setFitWidth(20);
icon.setFitHeight(20);
if (location.exists()) {
if (userService.isInstallationPrimary(location.getId())) {
icon.setImage(ImageResolveService.getInstance().getImage("image-root-primary.png"));
} else {
icon.setImage(ImageResolveService.getInstance().getImage("image-root.png"));
}
TreeItem<GuiLocation> rootItem = new TreeItem<GuiLocation>(GuiLocation.builder().id(location.getId()).type(TYPE.INSTALLATION_ROOT).name(Support.removeEndingSlash(location.getPath())).build(), icon);
rootItem.setExpanded(localDbService.getBooleanLocalDBSetting(resolveInstallationExpandedKey(location.getId()), false));
rootItemBase.getChildren().add(rootItem);
TreeItem<GuiLocation> leaf = rootItem;
for (Artifact entry : artifactsDb) {
String node = entry.getPrefix();
if (node != null) {
String[] path = node.split("/");
String leafKey = "";
for (String pathItem : path) {
leafKey += pathItem + "/";
ImageView testIcon = new ImageView();
testIcon.setFitWidth(20);
testIcon.setFitHeight(20);
if (checkIfFolderNeedsUpdate(leafKey, location) && userService.isPremium()) {
testIcon.setImage(ImageResolveService.getInstance().getImage("image-folder-updateneeded.png"));
} else {
testIcon.setImage(ImageResolveService.getInstance().getImage("image-folder.png"));
}
Optional<TreeItem<GuiLocation>> categoryItem = leaf.getChildren().stream().filter(item -> item.getValue().getName() != null && item.getValue().getName().equals(pathItem)).findFirst();
if (!categoryItem.isPresent()) {
TreeItem<GuiLocation> depNode = new TreeItem<GuiLocation>(GuiLocation.builder().id(location.getId()).type(TYPE.LEAF).name(pathItem).leafKey(leafKey).build(), testIcon);
leaf.getChildren().add(depNode);
leaf = depNode;
} else {
leaf = categoryItem.get();
}
leaf.setExpanded(localDbService.getBooleanLocalDBSetting(resolveLeafInInstallationExpandedKey(leaf.getValue()), false));
}
// we're at thre position in the list now with the correct leaf
if (!localDbService.hasLocalDBSetting("exclude_" + location.getId() + "_" + entry.getName())) {
ImageView itemIcon = new ImageView();
itemIcon.setFitWidth(16);
itemIcon.setFitHeight(16);
if (entry.getCurrentInstallingId() != null && entry.getCurrentInstallingId().equals(location.getId())) {
if (entry.isMarkedForUpdate() && !entry.isUpdating()) {
itemIcon.setImage(ImageResolveService.getInstance().getImage("image-waiting.png"));
} else if (entry.isUpdating()) {
itemIcon.setImage(ImageResolveService.getInstance().getImage("image-install2.png"));
}
} else {
if (entry.getHero() && userService.isFreemium()) {
itemIcon.setImage(ImageResolveService.getInstance().getImage("image-notavailable.png"));
} else if (entry.getType() == ArtifactType.LOCAL && !artifactsService.isPrivateDirAvailable()) {
itemIcon.setImage(ImageResolveService.getInstance().getImage("image-notavailable.png"));
} else if (!artifactsService.isInstalled(location.toLocationAndInstallation(), entry)) {
itemIcon.setImage(ImageResolveService.getInstance().getImage("image-notinstalled2bw.png"));
} else if (artifactsService.needsUpdate(location.toLocationAndInstallation(), entry)) {
itemIcon.setImage(ImageResolveService.getInstance().getImage("image-needsupdatebw.png"));
} else {
Optional<LatestInstalledItemInfo> findFirst = lastestAdditions.stream().filter(item -> item.getId().equals(entry.getName())).findFirst();
if (findFirst.isPresent() && userService.isPremium()) {
itemIcon.setImage(ImageResolveService.getInstance().getImage("image-updated-new.png"));
} else {
itemIcon.setImage(ImageResolveService.getInstance().getImage("image-updated2.png"));
}
}
}
TreeItem<GuiLocation> depNode = new TreeItem<GuiLocation>(GuiLocation.builder().id(location.getId()).type(TYPE.INSTALLATION).artifact(entry).build(), itemIcon);
leaf.getChildren().add(depNode);
}
// reset
leaf = rootItem;
}
}
} else {
icon.setImage(ImageResolveService.getInstance().getImage("image-root-invalid.png"));
TreeItem<GuiLocation> rootItem = new TreeItem<GuiLocation>(GuiLocation.builder().id(location.getId()).type(TYPE.INSTALLATION_ROOT).name(Support.removeEndingSlash(location.getPath())).build(), icon);
rootItemBase.getChildren().add(rootItem);
}
}
if (Scheduler.getInstance() != null && Scheduler.getInstance().isWorking() && ProgressControlWrapper.getInstance().isClosed()) {
int height = 25;
progressBar = new ProgressbarEnhanced();
progressBar.setMinWidth(300);
progressBar.setMinHeight(height);
progressBar.addEventHandler(MouseEvent.MOUSE_CLICKED, (MouseEvent event) -> handleMouseClicked2(event));
topContainer.getChildren().add(1, progressBar);
GlobalRepoService.getInstance().put("pbar", progressBar);
tree.setMinHeight(topContainer.getHeight() - menuBar.getHeight() - height);
} else {
tree.setMinHeight(topContainer.getHeight() - menuBar.getHeight());
}
} catch (Exception e) {
LOGGER.error("Unable to refresh view", e);
GenericMessageDialogController.withErrorProps("Ooops", "Unable to refresh view").showAndWait();
}
}
});
}
use of javafx.scene.control.TreeItem in project MiscellaneousStudy by mikoto2000.
the class EditableTreeViewController method initialize.
@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;
});
}
use of javafx.scene.control.TreeItem in project MiscellaneousStudy by mikoto2000.
the class TreeViewSample method start.
@Override
public void start(Stage stage) {
// ルート要素である TreeItem を作成
TreeItem<String> root = new TreeItem<String>("Root Node");
// ルートの子要素を作成
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);
// ルート要素に子要素を追加する
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 にルート要素を指定しながらインスタンス化
TreeView<String> treeView = new TreeView<String>(root);
// シーン作成
Scene scene = new Scene(treeView);
stage.setScene(scene);
stage.setTitle("Tree View Sample");
stage.show();
}
use of javafx.scene.control.TreeItem in project uPMT by coco35700.
the class TypeTreeView method addProperty.
// method used to add a property to the current cell
public void addProperty(Type nt) {
TreeItem<TypeController> newType = new TreeItem<TypeController>();
TypeController tc = new TypeController(nt, getTreeItem().getParent().getValue().getType());
newType.setValue(tc);
getTreeItem().getChildren().add(newType);
this.getTreeItem().setExpanded(true);
// System.out.println("On ajoute une propriete !");
// System.out.println("On a essay� de la renommer");
}
Aggregations