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);
}
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();
}
}
});
}
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);
}
}
}
}
Aggregations