Search in sources :

Example 16 with TreeItem

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;
}
Also used : ObjectProperty(javafx.beans.property.ObjectProperty) CTXMENU_TREE_EXPANDFIRSTONLY(com.insightfullogic.honest_profiler.ports.javafx.util.ResourceUtil.CTXMENU_TREE_EXPANDFIRSTONLY) ReadOnlyObjectProperty(javafx.beans.property.ReadOnlyObjectProperty) CTXMENU_TREE_COLLAPSE(com.insightfullogic.honest_profiler.ports.javafx.util.ResourceUtil.CTXMENU_TREE_COLLAPSE) TreeItem(javafx.scene.control.TreeItem) Node(com.insightfullogic.honest_profiler.core.aggregation.result.straight.Node) ObjectBinding(javafx.beans.binding.ObjectBinding) Property(javafx.beans.property.Property) CTXMENU_TREE_EXPANDFULLY(com.insightfullogic.honest_profiler.ports.javafx.util.ResourceUtil.CTXMENU_TREE_EXPANDFULLY) TreeUtil.expandFully(com.insightfullogic.honest_profiler.ports.javafx.util.TreeUtil.expandFully) ApplicationContext(com.insightfullogic.honest_profiler.ports.javafx.model.ApplicationContext) DialogUtil.showExportDialog(com.insightfullogic.honest_profiler.ports.javafx.util.DialogUtil.showExportDialog) TreeUtil.expandFirstOnly(com.insightfullogic.honest_profiler.ports.javafx.util.TreeUtil.expandFirstOnly) TreeTableRow(javafx.scene.control.TreeTableRow) TreeTableView(javafx.scene.control.TreeTableView) ContextMenu(javafx.scene.control.ContextMenu) TreeTableCell(javafx.scene.control.TreeTableCell) TreeCell(javafx.scene.control.TreeCell) TreeUtil.collapseFully(com.insightfullogic.honest_profiler.ports.javafx.util.TreeUtil.collapseFully) CTXMENU_TREE_EXPORTSUBTREE(com.insightfullogic.honest_profiler.ports.javafx.util.ResourceUtil.CTXMENU_TREE_EXPORTSUBTREE) MenuUtil.addMenuItem(com.insightfullogic.honest_profiler.ports.javafx.util.MenuUtil.addMenuItem) ReportUtil.writeStack(com.insightfullogic.honest_profiler.ports.javafx.util.report.ReportUtil.writeStack) Node(com.insightfullogic.honest_profiler.core.aggregation.result.straight.Node) ContextMenu(javafx.scene.control.ContextMenu)

Example 17 with TreeItem

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();
            }
        }
    });
}
Also used : EventHandler(javafx.event.EventHandler) StageStyle(javafx.stage.StageStyle) RandomAccessFile(java.io.RandomAccessFile) Scheduler(se.light.assembly64.Scheduler) TYPE(se.light.assembly64.model.GuiLocation.TYPE) LoggerFactory(org.slf4j.LoggerFactory) PathService(se.light.assembly64.service.PathService) VBox(javafx.scene.layout.VBox) StringUtils(org.apache.commons.lang3.StringUtils) FileLock(java.nio.channels.FileLock) Application(javafx.application.Application) ArtifactType(se.light.assembly64.model.ArtifactType) LogConfig(se.light.assembly64.LogConfig) ContextMenu(javafx.scene.control.ContextMenu) Type(se.light.assembly64.Support.Type) WindowEvent(javafx.stage.WindowEvent) WorkLocation(se.light.assembly64.model.WorkLocation) Pane(javafx.scene.layout.Pane) Rectangle2D(javafx.geometry.Rectangle2D) MenuItem(javafx.scene.control.MenuItem) ButtonType(se.light.assembly64.fx.GenericMessageDialogController.ButtonType) Set(java.util.Set) Screen(javafx.stage.Screen) Artifact(se.light.assembly64.model.Artifact) LocalStorageUtil(se.light.assembly64.util.LocalStorageUtil) Collectors(java.util.stream.Collectors) TreeView(javafx.scene.control.TreeView) UserService(se.light.assembly64.service.UserService) Platform(javafx.application.Platform) Duration(javafx.util.Duration) List(java.util.List) PlatformInfoService(se.light.assembly64.service.PlatformInfoService) Optional(java.util.Optional) InstallationService(se.light.assembly64.service.InstallationService) Autoupgrade(se.light.assembly64.Autoupgrade) ReturningTask(se.light.assembly64.model.ReturningTask) Scene(javafx.scene.Scene) MouseButton(javafx.scene.input.MouseButton) TreeItem(javafx.scene.control.TreeItem) GuiLocation(se.light.assembly64.model.GuiLocation) MouseEvent(javafx.scene.input.MouseEvent) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) GlobalRepoService(se.light.assembly64.service.GlobalRepoService) GenericMessageDialogController.heroesOnlyFeatureDialog(se.light.assembly64.fx.GenericMessageDialogController.heroesOnlyFeatureDialog) ArrayList(java.util.ArrayList) LatestInstalledItemInfo(se.light.assembly64.model.LatestInstalledItemInfo) ViceService(se.light.assembly64.service.ViceService) UpgradeOptions(se.light.assembly64.Support.UpgradeOptions) FadeTransition(javafx.animation.FadeTransition) GuiUtils(se.light.assembly64.util.GuiUtils) Support(se.light.assembly64.Support) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Support.resolveInstallationExpandedKey(se.light.assembly64.Support.resolveInstallationExpandedKey) DirectoryChooser(javafx.stage.DirectoryChooser) Color(javafx.scene.paint.Color) Analytics(se.light.assembly64.Analytics) Logger(org.slf4j.Logger) MenuBar(javafx.scene.control.MenuBar) ExecutorUtil(se.light.assembly64.util.ExecutorUtil) FileUtils(org.apache.commons.io.FileUtils) ArtifactsService(se.light.assembly64.service.ArtifactsService) File(java.io.File) Menu(javafx.scene.control.Menu) Consumer(java.util.function.Consumer) FileChooser(javafx.stage.FileChooser) ActionEvent(javafx.event.ActionEvent) SelectionMode(javafx.scene.control.SelectionMode) Stage(javafx.stage.Stage) PlatformInfo(se.light.assembly64.model.PlatformInfo) ImageView(javafx.scene.image.ImageView) LocalDBService(se.light.assembly64.service.LocalDBService) ObservableValue(javafx.beans.value.ObservableValue) ChangeListener(javafx.beans.value.ChangeListener) Support.resolveLeafInInstallationExpandedKey(se.light.assembly64.Support.resolveLeafInInstallationExpandedKey) Image(javafx.scene.image.Image) FileChannel(java.nio.channels.FileChannel) Collections(java.util.Collections) LocationAndInstallationStatus(se.light.assembly64.model.LocationAndInstallationStatus) Set(java.util.Set) MouseEvent(javafx.scene.input.MouseEvent) Optional(java.util.Optional) TreeItem(javafx.scene.control.TreeItem) WorkLocation(se.light.assembly64.model.WorkLocation) GuiLocation(se.light.assembly64.model.GuiLocation) Artifact(se.light.assembly64.model.Artifact) LatestInstalledItemInfo(se.light.assembly64.model.LatestInstalledItemInfo) List(java.util.List) ArrayList(java.util.ArrayList) ImageView(javafx.scene.image.ImageView)

Example 18 with TreeItem

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;
    });
}
Also used : DefaultStringConverter(javafx.util.converter.DefaultStringConverter) TreeItem(javafx.scene.control.TreeItem) TreeView(javafx.scene.control.TreeView) TextFieldTreeCell(javafx.scene.control.cell.TextFieldTreeCell)

Example 19 with TreeItem

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();
}
Also used : TreeItem(javafx.scene.control.TreeItem) TreeView(javafx.scene.control.TreeView) Scene(javafx.scene.Scene)

Example 20 with TreeItem

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");
}
Also used : TypeController(controller.controller.TypeController) TreeItem(javafx.scene.control.TreeItem)

Aggregations

TreeItem (javafx.scene.control.TreeItem)76 File (java.io.File)15 TreeView (javafx.scene.control.TreeView)11 ArrayList (java.util.ArrayList)10 List (java.util.List)10 ObjectProperty (javafx.beans.property.ObjectProperty)9 MenuItem (javafx.scene.control.MenuItem)9 SimpleObjectProperty (javafx.beans.property.SimpleObjectProperty)8 Logger (org.slf4j.Logger)8 LoggerFactory (org.slf4j.LoggerFactory)8 ValueUtil (com.kyj.fx.voeditor.visual.util.ValueUtil)7 IOException (java.io.IOException)7 FXCollections (javafx.collections.FXCollections)7 ListChangeListener (javafx.collections.ListChangeListener)7 ObservableList (javafx.collections.ObservableList)7 ActionEvent (javafx.event.ActionEvent)7 ContextMenu (javafx.scene.control.ContextMenu)7 FxUtil (com.kyj.fx.voeditor.visual.util.FxUtil)6 FXML (javafx.fxml.FXML)6 Button (javafx.scene.control.Button)6