Search in sources :

Example 1 with GuiLocation

use of se.light.assembly64.model.GuiLocation in project assembly64fx by freabemania.

the class Main method setupTree.

public static void setupTree() {
    GuiLocation rootsLocations = GuiLocation.builder().id(-1).type(TYPE.ROOT).name("Installations").build();
    ImageView iconR = new ImageView();
    iconR.setFitWidth(40);
    iconR.setFitHeight(20);
    iconR.setImage(ImageResolveService.getInstance().getImage("image-root-base.png"));
    rootItemBase = new TreeItem<GuiLocation>(rootsLocations, iconR);
    rootItemBase.setExpanded(true);
    tree = new TreeView<GuiLocation>(rootItemBase);
    tree.setMinWidth(topContainer.getWidth());
    tree.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
    tree.setOnScrollStarted((event) -> {
        tree.getSelectionModel().clearSelection();
    });
    tree.addEventHandler(MouseEvent.MOUSE_PRESSED, event -> handleMouseClicked(event));
    Image searchImage = new Image(Main.class.getResourceAsStream("button-magnifiersmall.png"), 30, 30, false, false);
    searchView = new ImageView();
    searchView.setImage(searchImage);
    sidifyView = new ImageView();
    sidifyView.setImage(new Image(Main.class.getResourceAsStream("button-sidify.png"), 30, 30, false, false));
    downloadLatestDbView = new ImageView();
    downloadLatestDbView.setImage(new Image(Main.class.getResourceAsStream("button-latestdb.png"), 30, 30, false, false));
    searchView.addEventHandler(MouseEvent.MOUSE_CLICKED, event -> {
        executeIfPremium((Runnable) -> {
            Analytics.sendEvent("application_click", "open_search");
            GuiUtils.showDialog("searchMain.fxml", "Assembly64 search", Artifact.nullArtifact());
        }, "open_search");
    });
    setMagnifierAndSidify();
    treeAndComponents.getChildren().addAll(tree, searchView, sidifyView, downloadLatestDbView);
    topContainer.getChildren().add(treeAndComponents);
}
Also used : GuiLocation(se.light.assembly64.model.GuiLocation) ImageView(javafx.scene.image.ImageView) Image(javafx.scene.image.Image)

Example 2 with GuiLocation

use of se.light.assembly64.model.GuiLocation 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 3 with GuiLocation

use of se.light.assembly64.model.GuiLocation in project assembly64fx by freabemania.

the class Main method handleMouseClicked.

private static void handleMouseClicked(MouseEvent event) {
    tree.setContextMenu(null);
    TreeItem<GuiLocation> selectedItem = tree.getSelectionModel().getSelectedItem();
    if (selectedItem == null || selectedItem.getValue() == null) {
        return;
    }
    if (selectedItem.getValue().getType() == TYPE.ROOT) {
        final ContextMenu contextMenu = new ContextMenu();
        if (userService.getLocations().size() < MAX_INSTALLATIONS) {
            contextMenu.getItems().add(createMenuWithAction(null, "Add new location", Type.ADD_LOCATION, selectedItem.getValue()));
        }
        contextMenu.getItems().add(createMenuWithAction(null, "Locally synced directory", Type.ADD_PRIVATE_DIR, null));
        contextMenu.getItems().add(createMenuWithAction(null, "Install and update all", Type.INSTALL_AND_UPDATE_ALL_LOCATIONS, selectedItem.getValue()));
        contextMenu.getItems().add(createMenuWithAction(null, "Update all", Type.UPDATE_ALL_LOCATIONS, selectedItem.getValue()));
        contextMenu.getItems().add(createMenuWithAction(null, "Refresh view", Type.REFRESH_VIEW, selectedItem.getValue()));
        contextMenu.getItems().add(createMenuWithAction(null, "Reset all views", Type.RESET_ALL_VIEWS, selectedItem.getValue()));
        tree.setContextMenu(contextMenu);
        return;
    }
    if (selectedItem.getValue().getType() == TYPE.INSTALLATION_ROOT) {
        GuiLocation selectedInstallation = selectedItem.getValue();
        if (userService.isInstallationExisting(selectedInstallation.getId())) {
            if (event.getButton() == MouseButton.SECONDARY || event.isControlDown()) {
                final ContextMenu contextMenu = new ContextMenu();
                contextMenu.getItems().add(createMenuWithAction(null, "Update and install all", Type.INSTALLUPDATE_ALL, selectedInstallation));
                contextMenu.getItems().add(createMenuWithAction(null, "Update all", Type.UPDATE_ALL, selectedInstallation));
                contextMenu.getItems().add(createMenuWithAction(null, "Housekeep", Type.HOUSEKEEP, selectedInstallation));
                contextMenu.getItems().add(createMenuWithAction(null, "Set as primary", Type.SET_AS_PRIMARY, selectedInstallation));
                contextMenu.getItems().add(createMenuWithAction(null, "Reset view", Type.RESET_VIEW, selectedInstallation));
                contextMenu.getItems().add(createMenuWithAction(null, "Open folder", Type.OPEN_LOCATION, selectedInstallation));
                contextMenu.getItems().add(createMenuWithAction(null, "Remove location", Type.REMOVE_LOCATION, selectedInstallation));
                tree.setContextMenu(contextMenu);
            } else if (event.getClickCount() == 2) {
                String key = resolveInstallationExpandedKey(selectedInstallation.getId());
                if (localDbService.hasLocalDBSetting(key)) {
                    localDbService.addLocalBooleanDBSetting(key, !localDbService.getBooleanLocalDBSetting(key));
                } else {
                    localDbService.addLocalBooleanDBSetting(key, Boolean.FALSE);
                }
            }
        } else {
            final ContextMenu contextMenu = new ContextMenu();
            contextMenu.getItems().add(createMenuWithAction(null, "Remove location", Type.REMOVE_LOCATION, selectedInstallation));
            tree.setContextMenu(contextMenu);
        }
        return;
    }
    if (selectedItem.getValue().getType() == TYPE.LEAF) {
        if (event.getClickCount() == 2) {
            GuiLocation selectedInstallation = selectedItem.getValue();
            String key = resolveLeafInInstallationExpandedKey(selectedInstallation);
            if (localDbService.hasLocalDBSetting(key)) {
                localDbService.addLocalBooleanDBSetting(key, !localDbService.getBooleanLocalDBSetting(key));
            } else {
                localDbService.addLocalBooleanDBSetting(key, Boolean.FALSE);
            }
        } else if (event.getButton() == MouseButton.SECONDARY || event.isControlDown()) {
            ContextMenu contextMenu = getContextMenu();
            contextMenu.getItems().add(createMenuWithAction(null, "Open folder", Type.OPEN_LEAF_LOCATION, selectedItem.getValue()));
        }
        return;
    }
    if (selectedItem.getValue().getType() == TYPE.INSTALLATION) {
        if (event.getClickCount() == 2) {
            tree.getSelectionModel().clearSelection();
            GuiUtils.showDialog("searchMain.fxml", "Search assemblydb", selectedItem.getValue().getArtifact());
            return;
        } else {
            try {
                if (event.getButton() == MouseButton.SECONDARY || event.isControlDown()) {
                    if (tree.getContextMenu() == null) {
                        tree.setContextMenu(new ContextMenu());
                    }
                    ContextMenu contextMenu = tree.getContextMenu();
                    contextMenu.getItems().clear();
                    GuiLocation selectedInstallation = selectedItem.getValue();
                    List<ActionAndIdHolder> actions = new ArrayList<>();
                    Artifact clickedEntry = selectedInstallation.getArtifact();
                    boolean installed = artifactsService.isInstalled(userService.getLocation(selectedInstallation.getId()).toLocationAndInstallation(), clickedEntry);
                    if (!installed) {
                        actions.add(new ActionAndIdHolder(clickedEntry, Type.INSTALL, selectedInstallation));
                    } else if (artifactsService.needsUpdate(userService.getLocation(selectedInstallation.getId()).toLocationAndInstallation(), clickedEntry)) {
                        actions.add(new ActionAndIdHolder(clickedEntry, Type.UPDATE, selectedInstallation));
                    }
                    boolean containsInstall = actions.stream().filter(item -> item.getType() == Type.INSTALL).findFirst().isPresent();
                    boolean containsUpdate = actions.stream().filter(item -> item.getType() == Type.UPDATE).findFirst().isPresent();
                    if (Support.isRemoteArtifact(clickedEntry) || (Support.isLocalArtifact(clickedEntry) && artifactsService.isPrivateDirAvailable())) {
                        if (containsInstall) {
                            contextMenu.getItems().add(createMenuWithAction(clickedEntry, "Install", Type.INSTALL, selectedInstallation));
                        } else if (containsUpdate) {
                            contextMenu.getItems().add(createMenuWithAction(clickedEntry, "Update", Type.INSTALL, selectedInstallation));
                        }
                    }
                    contextMenu.getItems().add(createMenuWithAction(clickedEntry, "Info", Type.INFO, selectedInstallation));
                    if (installed) {
                        contextMenu.getItems().add(createMenuWithAction(clickedEntry, "Open folder", Type.OPEN, selectedInstallation));
                    }
                    if (Support.isRemoteArtifact(clickedEntry) && artifactsService.isPrivateDirAvailable()) {
                        if (!installed) {
                            contextMenu.getItems().add(createMenuWithAction(clickedEntry, "Hide", Type.HIDE, selectedInstallation));
                        } else {
                            contextMenu.getItems().add(createMenuWithAction(clickedEntry, "Uninstall", Type.UNINSTALL, selectedInstallation));
                            contextMenu.getItems().add(createMenuWithAction(clickedEntry, "Hide & uninstall", Type.HIDE, selectedInstallation));
                        }
                    }
                    if (Support.isRemoteArtifact(clickedEntry) && userService.isPremium()) {
                        contextMenu.getItems().add(createMenuWithAction(clickedEntry, "Search", Type.SEARCH, selectedInstallation));
                    }
                    if (clickedEntry.isMarkedForUpdate()) {
                        if (!clickedEntry.isUpdating()) {
                            contextMenu.getItems().add(createMenuWithAction(clickedEntry, "Cancel", Type.CANCEL_UPDATE, selectedInstallation));
                        }
                    }
                    if (installed && Support.isRemoteArtifact(clickedEntry)) {
                        String baseLocation = Support.appendPathIfMissing(userService.getLocation(selectedInstallation.getId()).toLocationAndInstallation().getLocation()) + clickedEntry.getAbsoluteInstallationPath();
                        File releaseNoteFile = new File(Support.appendPathIfMissing(baseLocation + "/releaselog.json"));
                        ReturningTask<Void> showExtraMenuTask = () -> {
                            if (releaseNoteFile.exists()) {
                                Platform.runLater(() -> {
                                    contextMenu.getItems().add(createMenuWithAction(clickedEntry, "View new entries", Type.SHOW_RELEASES, selectedInstallation, baseLocation));
                                });
                            }
                            return null;
                        };
                        ExecutorUtil.executeAsyncWithRetry(showExtraMenuTask);
                    }
                } else {
                    tree.getSelectionModel().clearSelection();
                }
            } catch (Exception e) {
                LOGGER.error("Exception in mouseclick", e);
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) GuiLocation(se.light.assembly64.model.GuiLocation) ContextMenu(javafx.scene.control.ContextMenu) Artifact(se.light.assembly64.model.Artifact) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File)

Aggregations

GuiLocation (se.light.assembly64.model.GuiLocation)3 File (java.io.File)2 RandomAccessFile (java.io.RandomAccessFile)2 ArrayList (java.util.ArrayList)2 ContextMenu (javafx.scene.control.ContextMenu)2 Image (javafx.scene.image.Image)2 ImageView (javafx.scene.image.ImageView)2 FileChannel (java.nio.channels.FileChannel)1 FileLock (java.nio.channels.FileLock)1 Collections (java.util.Collections)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Consumer (java.util.function.Consumer)1 Collectors (java.util.stream.Collectors)1 FadeTransition (javafx.animation.FadeTransition)1 Application (javafx.application.Application)1 Platform (javafx.application.Platform)1